import { TeamChat } from "@/components/team-chat"

export default async function TeamChatPage({
  params,
  searchParams,
}: {
  params: Promise<{ id: string; teamId: string }>
  searchParams: Promise<{ org?: string; name?: string; team?: string }>
}) {
  const { id, teamId } = await params
  const { org, name, team } = await searchParams
  const tournamentName = name?.trim() || "Turnering"
  const teamName = team?.trim() || "Laget"

  // Samme grunn som de andre turnering-undersidene: API-et krever
  // organization_id på alle team-scopede endepunkter (RLS, se ADR-001/003).
  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>
    )
  }

  return (
    <TeamChat
      organizationId={org}
      tournamentId={id}
      teamId={teamId}
      teamName={teamName}
      tournamentName={tournamentName}
    />
  )
}
