import type { Config } from '~/components/pub/my-ui/data-table'
import type { Patient } from '~/models/patient'
import { defineAsyncComponent } from 'vue'

const action = defineAsyncComponent(() => import('~/components/pub/my-ui/data/dropdown-action-duvp.vue'))
const statusBadge = defineAsyncComponent(() => import('./_common/verify-badge.vue'))

export const config: Config = {
  cols: [{}, {}, {}, {}, {width: 140}, {width: 3},],

  headers: [
    [
      { label: 'Tgl Pemeriksaan' },
      { label: 'Anamnesa' },
      { label: 'Permintaan Terapi' },
      { label: 'Program' },
      { label: 'Status' },
      { label: 'Action' },
    ],
  ],

  keys: ['anamnesis', 'anamnesis', 'anamnesis', 'anamnesis', 'status', 'action'],

  parses: {
    birth_date: (rec: unknown): unknown => {
      const { person } = rec as Patient

      if (typeof person.birthDate == 'object' && person.birthDate) {
        return (person.birthDate as Date).toLocaleDateString('id-ID')
      } else if (typeof person.birthDate == 'string') {
        return (person.birthDate as string).substring(0, 10)
      }
      return person.birthDate
    },
  },

  components: {
    action(rec, idx) {
      return {
        idx,
        rec: rec as object,
        component: action,
      }
    },
    status(rec, idx) {
      return {
        idx,
        rec: rec as object,
        component: statusBadge,
      }
    },
  },
}
