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

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

const route = useRoute()

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

const roleAccess: PagePermission = PAGE_PERMISSIONS['/rehab/encounter']

const { checkRole, getPagePermissions } = useRBAC()

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

// Define permission-based computed properties
const pagePermission = getPagePermissions(roleAccess)
const callbackUrl = route.query['return-path'] as string | undefined
</script>

<template>
  <div>
    <div v-if="pagePermission.canRead">
      <ContentSurgeryReportEntry :callback-url="callbackUrl" />
    </div>
    <Error v-else :status-code="403" />
  </div>
</template>
