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

definePageMeta({
  middleware: ['rbac'],
  roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
  title: 'Daftar Kempterapi',
  contentFrame: 'cf-full-width',
})

const route = useRoute()

useHead({
  title: () => route.meta.title as string,
})

const roleAccess: Record<string, Permission[]> = permissions['/chemotherapy'] || {}

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)
</script>

<template>
  <div>
    <div v-if="canRead">
      <ContentChemotherapyList />
    </div>
    <Error v-else :status-code="403" />
  </div>
</template>
