<script setup lang="ts">
import * as DE from '~/components/pub/my-ui/doc-entry';
import type { PaginationMeta } from '~/components/pub/my-ui/pagination/pagination.type'
import Nav from '~/components/pub/my-ui/nav-footer/ca-ed-su.vue'

import type { Prescription } from '~/models/prescription';
import PrescriptionItem from '~/components/app/prescription-item/list.vue';

interface Props {
  data: Prescription[]
  paginationMeta: PaginationMeta
}
const props = defineProps<Props>()

const emit = defineEmits<{
  cancel: [data: any]
  edit: [data: any],
  submit: [data: any]
}>()

function navClick(type: 'cancel' | 'edit' | 'submit', data: Prescription): void {
  if (type === 'cancel') {
    emit('cancel', data)
  } else if (type === 'edit') {
    emit('edit', data)
  } else if (type === 'submit') {
    emit('submit', data)
  }
}
</script>

<template>
  <div v-if="data.length == 0" class="p-10 text-center">
    <div class="mb-4 xl:mb-5">Belum Ada Data</div>
  </div>
  <template v-for="item, idx in data">
    <div :class="'text-sm 2xl:text-base font-semibold ' + (item.status_code == 'new' ? 'mb-2' : 'mb-2')">
      Order #{{ data.length - idx }} - {{ item.issuedAt?.substring(0, 10) || item.createdAt?.substring(0, 10) }} - {{ item.status_code }}
    </div>
    <DE.Block mode="preview" :col-count="7" class="!mb-3">
      <DE.Cell :col-span="3">
        <DE.Label :class="'font-semibold ' + (item.status_code == 'new' ? 'pt-2' : '')">DPJP</DE.Label>
        <DE.Field :class="item.status_code == 'new' ? 'pt-2' : ''">
          {{ item.doctor?.employee?.person?.name || '-' }}
        </DE.Field>
      </DE.Cell>
      <DE.Cell :col-span="3">
        <DE.Label :class="'font-semibold ' + (item.status_code == 'new' ? 'pt-2' : '')">PPDS</DE.Label>
        <DE.Field :class="item.status_code == 'new' ? 'pt-2' : ''">
          ...........
        </DE.Field>
      </DE.Cell>
      <div class="flex justify-end" >
        <Nav
          v-if="item.status_code == 'new'"
          :small-mode="true"
          :default-class="'flex gap-1'"
          @click="(type) => { navClick(type, item) }"
        />
      </div>
    </DE.Block>
    <PrescriptionItem :data="item.items || []" class="mb-10" />
    <!-- <div v-if="idx < data.length - 1" class="my-8 -mx-4 border-t border-t-slate-300" /> -->
  </template>
</template>
