<script setup lang="ts">
const data = ref([])

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

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

const hreaderPrep: HeaderPrep = {
  title: 'Pasien',
  icon: 'bi bi-journal-check',
  addNav: {
    label: 'Tambah',
    onClick: () => navigateTo('/patient/add'),
  },
}

// NOTE: example api
async function getPatientList() {
  const resp = await xfetch('/api/v1/patient')
  console.log('data patient', resp)
  if (resp.success) {
    data.value = (resp.body as Record<string, any>)['data']
  }
}

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

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

<template>
  <PubNavHeaderPrep :prep="{ ...hreaderPrep }" :ref-search-nav="refSearchNav" icon="i-lucide-add" />
  <div>
    <AppPatientList :data="data" />
  </div>
</template>
