<script setup lang="ts">
import type { FormErrors } from '~/types/error'
import { toTypedSchema } from '@vee-validate/zod'
import FieldGroup from '~/components/pub/my-ui/form/field-group.vue'
import Field from '~/components/pub/my-ui/form/field.vue'
import Label from '~/components/pub/my-ui/form/label.vue'
import Select from '~/components/pub/my-ui/form/select.vue'
import { Form } from '~/components/pub/ui/form'
import InputBase from '~/components/pub/my-ui/form/input-base.vue'
import { cn } from '~/lib/utils'

interface InstallationFormData {
  name: string
  code: string
  encounterClassCode: string
}

const props = defineProps<{
  schema: any
  initialValues?: Partial<InstallationFormData>
}>()

const emit = defineEmits<{
  submit: [values: InstallationFormData, resetForm: () => void]
  reset: [resetForm: () => void]
}>()

// Form submission handler
function onSubmitForm(values: any, { resetForm }: { resetForm: () => void }) {
  emit('submit', values, resetForm)
}

// Form cancel handler
function onResetForm({ resetForm }: { resetForm: () => void }) {
  emit('reset', resetForm)
}
</script>

<template>
  <Form
    v-slot="{ handleSubmit, resetForm }"
    as=""
    keep-values
    :initial-values="initialValues"
  >
    <form id="entry-form" @submit="handleSubmit($event, (values) => onSubmitForm(values, { resetForm }))">
      <div class="mb-5 border-b border-b-slate-300 pb-7 text-lg xl:text-xl">
        <div class="flex flex-col justify-between">
          <InputBase
            field-name="patientName"
            label="Nama Pasien"
            placeholder="Nama Pasien"
          />
          <InputBase
            field-name="cardNumber"
            label="Nomor Kartu"
            placeholder="Nomor Kartu"
          />
          <InputBase
            field-name="sepNumber"
            label="Nomor SEP"
            placeholder="Nomor SEP"
          />
        </div>
      </div>
     
      <div class="my-2 flex items-center gap-3 justify-end">
        <Button @click="onResetForm" variant="secondary">Reset</Button>
        <Button @click="onSubmitForm">Terapkan</Button>
      </div>
    </form>
  </Form>
</template>
