<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
  placeholder?: string
  errors?: FormErrors
  class?: string
  selectClass?: string
  fieldGroupClass?: string
  labelClass?: string
  isRequired?: boolean
}>()

const {
  fieldName = 'language',
  label = 'Bahasa',
  placeholder = 'Pilih preferensi bahasa',
  errors,
  class: containerClass,
  selectClass,
  fieldGroupClass,
  labelClass,
} = props

const langOptions = [
  { label: 'Bahasa Indonesia', value: 'id', priority: 1 },
  { label: 'Bahasa Jawa', value: 'jawa' },
  { label: 'Bahasa Sunda', value: 'sunda' },
  { label: 'Bahasa Bali', value: 'bali' },
  { label: 'Bahasa Jaksel', value: 'jaksel' },
  { label: 'Bahasa Inggris', value: 'en' },
  { label: 'Tidak Diketahui', value: 'unknown', priority: 100 },
]
</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="langOptions"
              :placeholder="placeholder"
              :preserve-order="false"
              :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>
