'use client' import { useQuery, gql } from '@/lib/graphql/hooks' import { use, useEffect } from 'react' import Link from 'next/link' import { TeamFlag } from '@/components/team-flag' import { MatchCard } from '@/components/match-card' import { LiveBadge } from '@/components/live-badge' const TOURNAMENT_QUERY = gql` query Tournament($year: Int!) { tournament(year: $year) { year host winner runnerUp thirdPlace fourthPlace totalGoals matchesCount teamsCount avgGoalsPerGame topScorers(limit: 10) { playerName goals penalties ownGoals team { name iso2 slug } } matches { id year round group date time isLive isQualiPlayoff scoreFt scoreHt scoreEt scoreP team1 { id name iso2 slug } team2 { id name iso2 slug } goals { playerName minute minuteOffset isPenalty isOwnGoal team { id } } } } groupStandings(year: $year) { groupName pos played won drawn lost goalsFor goalsAgainst goalDiff pts team { id name iso2 slug } } } ` interface MatchData { id: number; year: number; round: string; group?: string | null date?: string | null; time?: string | null; isLive: boolean; isQualiPlayoff: boolean scoreFt?: number[] | null; scoreHt?: number[] | null; scoreEt?: number[] | null; scoreP?: number[] | null team1: { id: number; name: string; iso2?: string | null; slug: string } team2: { id: number; name: string; iso2?: string | null; slug: string } goals: Array<{ playerName: string; minute?: number | null; minuteOffset?: number | null; isPenalty: boolean; isOwnGoal: boolean; team: { id: number } }> } interface Standing { groupName: string; pos?: number | null played: number; won: number; drawn: number; lost: number goalsFor: number; goalsAgainst: number; goalDiff: number; pts: number team: { id: number; name: string; iso2?: string | null; slug: string } } function GoalList({ match }: { match: MatchData }) { if (!match.goals?.length) return null const t1Goals = match.goals.filter(g => !g.isOwnGoal ? g.team.id === match.team1.id : g.team.id !== match.team1.id) const t2Goals = match.goals.filter(g => !g.isOwnGoal ? g.team.id === match.team2.id : g.team.id !== match.team2.id) const renderGoal = (g: MatchData['goals'][0]) => `${g.playerName} ${g.minute ?? ''}${g.minuteOffset ? `+${g.minuteOffset}` : ''}'${g.isPenalty ? ' (P)' : g.isOwnGoal ? ' (OG)' : ''}` return (
{t.host}