<script setup lang="ts">
import type { Permission } from '~/models/role'
import { permissions } from '~/const/page-permission/ambulatory'
import Error from '~/components/pub/my-ui/error/error.vue'

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

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',
})

// Preps role checking
const roleAccess: Record<string, Permission[]> = permissions['/outpatient/encounter'] || {}
const { checkRole, hasReadAccess } = useRBAC()

// Check if user has access to this page
const hasAccess = checkRole(roleAccess)
if (!hasAccess) {
  navigateTo('/403')
}

// Define permission-based computed properties
const canRead = hasReadAccess(roleAccess)

// Page needs
const route = useRoute()
useHead({
  title: () => route.meta.title as string,
})
</script>

<template>
  <div>
    <div v-if="canRead">
      <Content
        class-code="ambulatory"
        sub-class-code="chemo"
        type="encounter"
      />
    </div>
    <Error
      v-else
      :status-code="403"
    />
  </div>
</template>
