import { notFound } from "next/navigation";
import { Suspense } from "react";
import type { Metadata } from "next";

import { AdminPermissionGate } from "@/components/admin/admin-permission-gate";
import { AdminLoadingState } from "@/components/admin/admin-loading-state";
import { PRD_REPORTS_PAGE_ACCESS_ANY } from "@/lib/admin-prd";
import { buildPageMetadata } from "@/lib/page-metadata";
import { ReportsConsole } from "@/modules/reports/reports-console";
import type { ReportCategory } from "@/modules/reports/reports-definitions";

export const metadata: Metadata = buildPageMetadata("reports", "title");

const VALID_CATEGORIES = new Set<ReportCategory>(["profit", "wallet", "risk", "audit"]);

export default async function AdminReportsCategoryPage({
  params,
}: {
  params: Promise<{ category: string }>;
}) {
  const { category } = await params;
  if (!VALID_CATEGORIES.has(category as ReportCategory)) {
    notFound();
  }

  return (
    <AdminPermissionGate requiredAny={PRD_REPORTS_PAGE_ACCESS_ANY}>
      <Suspense fallback={<AdminLoadingState minHeight="12rem" />}>
        <ReportsConsole initialCategory={category as ReportCategory} />
      </Suspense>
    </AdminPermissionGate>
  );
}