import type { SearchParams } from 'nuqs/server';
import PageContainer from '@/components/layout/page-container';
import { requireSuperAdminDashboardAccess } from '@/lib/auth/page-guards';
import { searchParamsCache } from '@/lib/searchparams';
import PermissionTemplateListing from '@/features/permission-management/components/permission-template-listing';
import { PermissionTemplateFormSheetTrigger } from '@/features/permission-management/components/permission-template-form-sheet';

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

type PageProps = {
  searchParams: Promise<SearchParams>;
};

export default async function PermissionTemplatesPage(props: PageProps) {
  await requireSuperAdminDashboardAccess();

  const searchParams = await props.searchParams;
  searchParamsCache.parse(searchParams);

  return (
    <PageContainer
      pageTitle='Permission Templates'
      pageDescription='จัดการชุดสิทธิ์ต้นแบบของแต่ละองค์กรแบบ permission-first'
      pageHeaderAction={<PermissionTemplateFormSheetTrigger />}
    >
      <PermissionTemplateListing />
    </PageContainer>
  );
}
