<script setup lang="ts">
import type { DataTableLoader } from '~/components/pub/base/data-table/type'
import type { Summary } from '~/components/pub/base/summary-card/type'
import type { HeaderPrep, RefSearchNav } from '~/components/pub/custom-ui/data/types'
import { Calendar, Hospital, UserCheck, UsersRound } from 'lucide-vue-next'
import SummaryCard from '~/components/pub/base/summary-card/summary-card.vue'
import Dialog from '~/components/pub/base/modal/dialog.vue'
import Header from '~/components/pub/custom-ui/nav-header/prep.vue'
import Filter from '~/components/pub/custom-ui/nav-header/filter.vue'

const data = ref([])
const isLoading = reactive<DataTableLoader>({
  summary: false,
  isTableLoading: false,
})
const recId = ref<number>(0)
const recAction = ref<string>('')
const recItem = ref<any>(null)
const isFormEntryDialogOpen = ref(false)

const hreaderPrep: HeaderPrep = {
  title: 'Kunjungan',
  icon: 'i-lucide-users',
  addNav: {
    label: 'Tambah',
    onClick: () => navigateTo('/rehab/encounter/add'),
  },
}

const refSearchNav: RefSearchNav = {
  onClick: () => {
    // open filter modal
    isFormEntryDialogOpen.value = true
    console.log(' 1open filter modal')
  },
  onInput: (_val: string) => {
    // filter patient list
  },
  onClear: () => {
    // clear url param
  },
}

// Loading state management

async function getPatientList() {
  isLoading.isTableLoading = true
  const resp = await xfetch('/api/v1/patient')
  if (resp.success) {
    data.value = (resp.body as Record<string, any>).data
  }
  isLoading.isTableLoading = false
}

onMounted(() => {
  getPatientList()
})

provide('rec_id', recId)
provide('rec_action', recAction)
provide('rec_item', recItem)
provide('table_data_loader', isLoading)
</script>

<template>
  <Header :prep="{ ...hreaderPrep }" :ref-search-nav="refSearchNav" />
  <div class="my-4 rounded-md border p-4">
    <Filter :ref-search-nav="refSearchNav" />
    <div class="my-4 flex flex-1 flex-col gap-4 md:gap-8">
      <AppEncounterList :data="data" />
    </div>

    <Dialog v-model:open="isFormEntryDialogOpen" title="Tambah Divisi" size="lg" prevent-outside>
      <AppEncounterFilter />
    </Dialog>
    <!-- <Pagination :pagination-meta="paginationMeta" @page-change="handlePageChange" /> -->
  </div>
</template>
