import { CustomerPageShell } from "@/app/customer/_components/customer-page-shell";
import { ErrorBanner } from "@/components/shared/error-banner";
import { getCustomerSessionContext } from "@/lib/frontend-auth/server";

import { PerformanceSummaryView } from "./_components/performance-summary-report/performance-summary-view";
import { PERFORMANCE_SUMMARY_PERMISSION } from "./_lib/performance-summary-route";

type PageProps = { params: Promise<{ tenant: string }> };

export default async function PerformanceSummaryReportPage({ params }: PageProps) {
  const { tenant } = await params;
  const session = await getCustomerSessionContext(tenant);
  const permissionDenied =
    session.user != null && !session.permissions.routes.includes(PERFORMANCE_SUMMARY_PERMISSION);

  return (
    <CustomerPageShell>
      {permissionDenied ? (
        <ErrorBanner message="Permission denied for the Performance Summary Report." />
      ) : (
        <PerformanceSummaryView />
      )}
    </CustomerPageShell>
  );
}
