<script lang="ts">
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory.ts'

export interface FieldErrorTextBaseProps extends PolymorphicProps {}
export interface FieldErrorTextProps
  extends
    FieldErrorTextBaseProps,
    /**
     * @vue-ignore
     */
    HTMLAttributes {}
</script>

<script setup lang="ts">
import { ark } from '../factory.ts'
import { useFieldContext } from './use-field-context.ts'
import { useForwardExpose } from '../../utils/use-forward-expose.ts'

defineProps<FieldErrorTextProps>()
const field = useFieldContext()

useForwardExpose()
</script>

<template>
  <ark.span v-if="field.invalid" v-bind="field.getErrorTextProps()" :as-child="asChild">
    <slot />
  </ark.span>
</template>
