<script setup lang="ts">
import type { FormErrors } from '~/types/error'
import Select from '~/components/pub/my-ui/form/select.vue'
import { cn } from '~/lib/utils'

import * as DE from '~/components/pub/my-ui/doc-entry'

const props = defineProps<{
  fieldName?: string
  label?: string
  errors?: FormErrors
  class?: string
  selectClass?: string
  fieldGroupClass?: string
  labelClass?: string
  isRequired?: boolean
  placeholder?: string
}>()

const {
  fieldName = 'maritalStatus',
  label = 'Status Pernikahan',
  errors,
  class: containerClass,
  labelClass,
  placeholder = 'Pilih',
} = props

const maritalStatusOptions = [
  { label: 'Tidak Diketahui', value: 'TIDAK_DIKETAHUI' },
  { label: 'Belum Kawin', value: 'BELUM_KAWIN' },
  { label: 'Kawin', value: 'KAWIN' },
  { label: 'Cerai Hidup', value: 'CERAI_HIDUP' },
  { label: 'Cerai Mati', value: 'CERAI_MATI' },
]
</script>

<template>
  <DE.Cell :class="cn('select-field-group', fieldGroupClass, containerClass)">
    <DE.Label
      :label-for="fieldName"
      :class="cn('select-field-label', labelClass)"
      :is-required="isRequired"
    >
      {{ label }}
    </DE.Label>
    <DE.Field
      :id="fieldName"
      :errors="errors"
      :class="cn('select-field-wrapper')"
    >
      <FormField
        v-slot="{ componentField }"
        :name="fieldName"
      >
        <FormItem>
          <FormControl>
            <Select
              :id="fieldName"
              v-bind="componentField"
              :items="maritalStatusOptions"
              :placeholder="placeholder"
              :preserve-order="true"
              :class="
                cn(
                  'text-sm transition-all duration-200 focus:outline-none focus:ring-1 focus:ring-black focus:ring-offset-0',
                  selectClass,
                )
              "
            />
          </FormControl>
          <FormMessage />
        </FormItem>
      </FormField>
    </DE.Field>
  </DE.Cell>
</template>
