<script lang="ts">
import type { ItemProps } from '@zag-js/steps'
import type { HTMLAttributes } from 'vue'
import type { PolymorphicProps } from '../factory.ts'

export interface StepsItemBaseProps extends ItemProps, PolymorphicProps {}
export interface StepsItemProps
  extends
    StepsItemBaseProps,
    /**
     * @vue-ignore
     */
    HTMLAttributes {}
</script>

<script setup lang="ts">
import { computed } from 'vue'
import { useForwardExpose } from '../../utils/use-forward-expose.ts'
import { ark } from '../factory.ts'
import { useStepsContext } from './use-steps-context.ts'
import { StepsItemProvider } from './use-steps-item-context.ts'
import { StepsItemPropsProvider } from './use-steps-item-props-context.ts'

const props = defineProps<StepsItemProps>()
const steps = useStepsContext()
const itemState = computed(() => steps.value.getItemState(props))

StepsItemPropsProvider(props)
StepsItemProvider(itemState)

useForwardExpose()
</script>

<template>
  <ark.div v-bind="steps.getItemProps(props)" :as-child="asChild">
    <slot />
  </ark.div>
</template>
