import type {
  Col,
  KeyLabel,
  RecComponent,
  RecStrFuncComponent,
  RecStrFuncUnknown,
  Th,
} from '~/components/pub/custom-ui/data/types'
import { defineAsyncComponent } from 'vue'

type SmallDetailDto = any

const action = defineAsyncComponent(() => import('~/components/pub/custom-ui/data/dropdown-action-ud.vue'))

export const cols: Col[] = [
  { width: 100 },
  { },
  { },
  { },
  { width: 50 },
]

export const header: Th[][] = [
  [
    { label: 'Id' },
    { label: 'Nama' },
    { label: 'Kode' },
    { label: 'Instalasi' },
    { label: '' },
  ],
]

export const keys = [
  'id',
  'firstName',
  'cellphone',
  'birth_place',
  'action',
]

export const delKeyNames: KeyLabel[] = [
  { key: 'code', label: 'Kode' },
  { key: 'name', label: 'Nama' },
]

export const funcParsed: RecStrFuncUnknown = {
  name: (rec: unknown): unknown => {
    const recX = rec as SmallDetailDto
    return `${recX.frontTitle} ${recX.name}  ${recX.endTitle}`.trim()
  },
  identity_number: (rec: unknown): unknown => {
    const recX = rec as SmallDetailDto
    if (recX.identity_number?.substring(0, 5) === 'BLANK') {
      return '(TANPA NIK)'
    }
    return recX.identity_number
  },
  inPatient_itemPrice: (rec: unknown): unknown => {
    const recX = rec as SmallDetailDto
    return Number(recX.inPatient_itemPrice.price).toLocaleString('id-ID')
  },
  outPatient_itemPrice: (rec: unknown): unknown => {
    const recX = rec as SmallDetailDto
    return Number(recX.outPatient_itemPrice.price).toLocaleString('id-ID')
  },
}

export const funcComponent: RecStrFuncComponent = {
  action(rec, idx) {
    const res: RecComponent = {
      idx,
      rec: rec as object,
      component: action,
      props: {
        size: 'sm',
      },
    }
    return res
  },
}

export const funcHtml: RecStrFuncUnknown = {
  patient_address(_rec) {
    return '-'
  },
}
