import { notFound } from "next/navigation"; import { createClient } from "@/lib/supabase/server"; import { MatchActions } from "./match-actions"; import { GlassCard } from "@/components/ui/glass-card"; import { TeamBadge } from "@/components/teams/TeamBadge"; export default async function MatchPage({ params, }: { params: Promise<{ leagueId: string; competitionId: string; matchId: string }>; }) { const { leagueId, competitionId, matchId } = await params; const supabase = await createClient(); const { data: { user }, } = await supabase.auth.getUser(); const { data: match } = await supabase .from("matches") .select( `*, home:home_team_id(id, name, logo_path), away:away_team_id(id, name, logo_path)` ) .eq("id", matchId) .single(); if (!match) notFound(); const home = match.home as { id: string; name: string; logo_path: string | null }; const away = match.away as { id: string; name: string; logo_path: string | null }; const { data: submissions } = await supabase .from("match_result_submissions") .select("*, teams(name)") .eq("match_id", matchId); const { data: signatures } = await supabase .from("match_signatures") .select("team_id, teams(name)") .eq("match_id", matchId); let userTeamId: string | null = null; if (user) { const { data: tm } = await supabase .from("team_members") .select("team_id") .eq("user_id", user.id) .in("team_id", [home.id, away.id]) .limit(1) .single(); userTeamId = tm?.team_id ?? null; } const { data: isLeagueManager } = user ? await supabase .from("competition_league_managers") .select("id") .eq("competition_id", competitionId) .eq("user_id", user.id) .maybeSingle() : { data: null }; return (

{match.status === "completed" ? `${match.home_score} – ${match.away_score}` : "vs"}

{match.status.replace(/_/g, " ")}

{match.venue && (

{match.venue}

)}
    {signatures?.map((s) => (
  • ✓ {(s.teams as { name: string })?.name} signed
  • ))} {(!signatures || signatures.length === 0) && (
  • No signatures yet
  • )}
    {submissions?.map((s) => (
  • {(s.teams as { name: string })?.name}: {s.home_score}–{s.away_score}
  • ))} {(!submissions || submissions.length === 0) && (
  • No submissions yet
  • )}
); }