<script setup lang="ts">
// Types & Consts
import type { Permission } from '~/models/role'
import { permissions } from '~/const/page-permission/ambulatory'

// Helpers
import { usePageChecker } from "~/lib/page-checker"

// Pubs
import Error from '~/components/pub/my-ui/error/error.vue'

// Apps
import Content from '~/components/content/encounter/list.vue'

const { getRouteTitle, getPageAccess } = usePageChecker()

// Page meta
definePageMeta({
  middleware: ['rbac'],
  roles: ['emp|reg', 'emp|nur', 'emp|doc', 'emp|miw', 'emp|thr', 'emp|nut', 'emp|pha', 'emp|lab'],
  title: 'Daftar Kunjungan',
  contentFrame: 'cf-full-width',
})

useHead({
  title: () => `${getRouteTitle()}`,
})

// Define common things
const route = useRoute()

// Preps role checking
const roleAccess: Record<string, Permission[]> = permissions[route.path] || {}
const hasAccess = getPageAccess(roleAccess, 'read')
const canCreate = getPageAccess(roleAccess, 'create')
const canRemove = getPageAccess(roleAccess, 'delete')

// User info
const { user } = useUserStore()
const subClassCode = user.unit_code == 'rehab' ? 'rehab' : 'reg'
</script>

<template>
  <div>
    <div v-if="hasAccess">
      <Content
        class-code="ambulatory"
        :sub-class-code="subClassCode"
        :can-create="canCreate"
        :can-delete="canRemove"
      />
    </div>
    <Error
      v-else
      :status-code="403"
    />
  </div>
</template>
