<script setup lang="ts">
import { FieldError as ShadcnFieldError } from '@/components/core/field';
import { computed, useSlots, type Slots } from 'vue';
import type { UiFieldErrorProps } from './types';

defineOptions({
  name: 'UiFieldError',
});

const props = defineProps<UiFieldErrorProps>();

const slots: Slots = useSlots();
const hasDefaultSlotContent = computed<boolean>(
  () => (slots.default?.({}).length ?? 0) > 0,
);
</script>

<template>
  <ShadcnFieldError :errors="props.errors">
    <slot v-if="hasDefaultSlotContent" />
  </ShadcnFieldError>
</template>
