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

// 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/entry.vue'

const { getParamsId, getRouteTitle, getPageAccess } = usePageChecker()

definePageMeta({
  middleware: ['rbac'],
  roles: ['emp|reg'],
  title: 'Edit Kunjungan',
  contentFrame: 'cf-full-width',
})

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

// Preps role checking
const roleAccess: Record<string, Permission[]> = permissions['/emergency/encounter/[id]/edit'] || {}
const hasAccess = getPageAccess(roleAccess, 'update')
const encounterId = getParamsId()
</script>

<template>
  <div v-if="hasAccess">
    <Content
      :id="encounterId"
      class-code="emergency"
      sub-class-code="emg"
      form-type="edit"
    />
  </div>
  <Error
    v-else
    :status-code="403"
  />
</template>
