import { HydrationBoundary, dehydrate } from '@tanstack/react-query';
import PageContainer from '@/components/layout/page-container';
import { requireSuperAdminDashboardAccess } from '@/lib/auth/page-guards';
import { getQueryClient } from '@/lib/query-client';
import { permissionCatalogQueryOptions } from '@/features/permission-management/api/queries';
import { PermissionMatrix } from '@/features/permission-management/components/permission-matrix';

export const metadata = {
  title: 'Dashboard: Permission Matrix'
};

export default async function PermissionMatrixPage() {
  await requireSuperAdminDashboardAccess();

  const queryClient = getQueryClient();
  await queryClient.fetchQuery(permissionCatalogQueryOptions());

  return (
    <PageContainer
      pageTitle='Permission Matrix'
      pageDescription='ดู permission catalog แบบ grouped ตาม module และ action'
    >
      <HydrationBoundary state={dehydrate(queryClient)}>
        <PermissionMatrix />
      </HydrationBoundary>
    </PageContainer>
  );
}
