import { notFound } from "next/navigation";
import { Role } from "@prisma/client";
import { AdminDashboard, type AdminSection } from "@/components/admin-dashboard";
import { requirePageRole } from "@/server/security/page-auth";

const validSections: AdminSection[] = ["overview", "players", "kyc", "support", "trading", "sport-promos", "bonus", "finance"];

export default async function AdminSectionPage({ params }: { params: Promise<{ section: string }> }) {
  const { section } = await params;

  if (!validSections.includes(section as AdminSection)) {
    notFound();
  }

  const allowedRoles =
    section === "kyc"
      ? [Role.KYC_ANALYST, Role.ADMIN, Role.SUPER_ADMIN]
      : section === "support"
        ? [Role.SUPPORT, Role.ADMIN, Role.SUPER_ADMIN]
        : [Role.ADMIN, Role.SUPER_ADMIN];
  await requirePageRole(allowedRoles);

  return <AdminDashboard section={section as AdminSection} />;
}
