<script setup lang="ts">
import type { HeaderPrep, RefSearchNav } from '~/components/pub/nav/types'

const data = ref([])

const refSearchNav: RefSearchNav = {
  onClick: () => {
    // open filter modal
  },
  onInput: (_val: string) => {
    // filter patient list
  },
  onClear: () => {
    // clear url param
  },
}

const isLoading = reactive({
  dataListLoading: false,
})

const recId = ref<number>(0)
const recAction = ref<string>('')
const recItem = ref<any>(null)

const headerPrep: HeaderPrep = {
  title: 'Dokter',
  icon: 'i-lucide-network',
  addNav: {
    label: 'Tambah',
    onClick: () => navigateTo('/doctor/add'),
  },
}


async function getDoctorList() {
  isLoading.dataListLoading = true

  const resp = await xfetch('/api/v1/doctor')
  if (resp.success) {
    data.value = (resp.body as Record<string, any>).data
  }

  isLoading.dataListLoading = false
}

onMounted(() => {
  getDoctorList()
})

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

<template>
  <PubNavHeaderPrep :prep="{ ...headerPrep }" :ref-search-nav="refSearchNav" />
  <AppDoctorList v-if="!isLoading.dataListLoading" :data="data" />
</template>
