import { PrintStartlist } from "@/components/print-startlist"

export default async function PrintStartlistPage({
  params,
  searchParams,
}: {
  params: Promise<{ id: string }>
  searchParams: Promise<{ org?: string; roundId?: string; sessionId?: string; paper?: string; orientation?: string }>
}) {
  const { id } = await params
  const { org, roundId, sessionId, paper, orientation } = await searchParams

  if (!org) {
    return (
      <main className="flex min-h-[100dvh] flex-col items-center justify-center gap-2 bg-background px-5 text-center">
        <p className="text-sm font-medium text-destructive">
          Mangler organisasjon i lenken. Gå tilbake til dashbordet og prøv igjen.
        </p>
      </main>
    )
  }

  const validSizes = ["A4", "Letter", "A3", "A2"] as const
  const initialSize = (validSizes as readonly string[]).includes(paper ?? "") ? (paper as (typeof validSizes)[number]) : "A4"

  return (
    <PrintStartlist
      organizationId={org}
      tournamentId={id}
      roundId={roundId}
      sessionId={sessionId}
      initialSize={initialSize}
      initialOrientation={orientation === "landscape" ? "landscape" : "portrait"}
    />
  )
}
