import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"

import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getRoles } from "@/modules/rbac/data-access"
import { RoleManagementView } from "@/modules/rbac/components/role-management-view"

export async function generateMetadata(): Promise<Metadata> {
  const t = await getTranslations("rbac")
  return {
    title: `${t("roles.title")} - Next_Edu`,
    description: t("roles.description"),
  }
}

export const dynamic = "force-dynamic"

export default async function AdminRolesPage(): Promise<JSX.Element> {
  await requirePermission(Permissions.ROLE_READ)

  const roles = await getRoles()

  return (
    <div className="flex h-full flex-col space-y-6 p-8">
      <div>
        <h1 className="text-2xl font-bold tracking-tight">Role Management</h1>
        <p className="text-muted-foreground text-sm">
          Create custom roles and manage permission assignments.
        </p>
      </div>

      <RoleManagementView roles={roles} />
    </div>
  )
}
