import { CustomerPageShell } from "@/app/customer/_components/customer-page-shell"

import { PibReportView } from "./_components/pib-report-view"
import { CUSTOMER_ROUTE_KEYS } from "@/config/customer-route-keys";
import { ReportPageGuard } from "@/app/customer/[tenant]/reports/_shared/components/report-page-guard";
import { getCustomerSessionContext } from "@/lib/frontend-auth/server";

/**
 * PIB Advisory pivot report (live Overall Summary + pib_class buckets).
 */
type PageProps = { params: Promise<{ tenant: string }> };

export default async function PibReportPage({ params }: PageProps) {
  const { tenant } = await params;
  // getCustomerSessionContext is React-cache()-deduped per request, so this is free
  // alongside ReportPageGuard's own internal fetch of the same session.
  const session = await getCustomerSessionContext(tenant);
  return (
    <CustomerPageShell>
      <ReportPageGuard tenant={tenant} routeKeys={CUSTOMER_ROUTE_KEYS.pibReport} label="PIB Report">
        <PibReportView allowedRoutes={session.permissions.routes} />
      </ReportPageGuard>
    </CustomerPageShell>
  )
}
