import type { Config, RecComponent, RecStrFuncComponent, RecStrFuncUnknown } from '~/components/pub/my-ui/data-table'
import { defineAsyncComponent } from 'vue'
import type { GeneralConsent } from '~/models/general-consent'

type SmallDetailDto = any

const action = defineAsyncComponent(() => import('~/components/pub/my-ui/data/dropdown-action-ud.vue'))
export const config: Config = {
  cols: [{ width: 100 }, {}, {}, {}, { width: 50 }],
  headers: [
    [
      { label: 'Tanggal' },
      { label: 'Anggota Keluarga' },
      { label: 'Penanggung Jawab' },
      { label: 'Pemberi Informasi' },
      { label: 'Saksi 1' },
      { label: 'Saksi 2' },
      { label: '' },
    ],
  ],
  keys: ['date', 'relatives', 'responsible', 'informant', 'witness1', 'witness2', 'action'],
  delKeyNames: [
    { key: 'data', label: 'Tanggal' },
    { key: 'dstDoctor.name', label: 'Dokter' },
  ],
  parses: {
    date(rec) {
      const recX = rec as GeneralConsent
      return recX?.createdAt?.substring(0, 10) || '-'
    },
    relatives(rec) {
      const recX = rec as GeneralConsent
      const parsed = JSON.parse(recX?.value || '{}')
      return parsed?.relatives?.join(', ') || '-'
    },
    responsible(rec) {
      const recX = rec as GeneralConsent
      const parsed = JSON.parse(recX?.value || '{}')
      return parsed?.responsible || '-'
    },
    informant(rec) {
      const recX = rec as GeneralConsent
      const parsed = JSON.parse(recX?.value || '{}')
      return parsed?.informant || '-'
    },
    witness1(rec) {
      const recX = rec as GeneralConsent
      const parsed = JSON.parse(recX?.value || '{}')
      return parsed?.witness1 || '-'
    },
    witness2(rec) {
      const recX = rec as GeneralConsent
      const parsed = JSON.parse(recX?.value || '{}')
      return parsed?.witness2 || '-'
    },
    action(rec, idx) {
      const res: RecComponent = {
        idx,
        rec: rec as object,
        component: action,
        props: {
          size: 'sm',
        },
      }
      return res
    },
  },
  components: {
    action(rec, idx) {
      const res: RecComponent = {
        idx,
        rec: rec as object,
        component: action,
        props: {
          size: 'sm',
        },
      }
      return res
    },
  } as RecStrFuncComponent,
  htmls: {} as RecStrFuncUnknown,
}
