import { prisma } from "@/lib/prisma" import Navigation from "@/components/Navigation" import Link from "next/link" import { notFound, redirect } from "next/navigation" import { canManageTournament, canDeleteTournament } from "@/lib/permissions" import { getTournamentStatus } from "@/lib/tournamentUtils" import { DeleteTournamentButton } from "@/components/DeleteTournamentButton" interface PageProps { params: { id: string } } export default async function TournamentDetailPage({ params }: PageProps) { // Next.js 16 requires awaiting params const { id } = await params const tournamentId = parseInt(id, 10) if (isNaN(tournamentId)) { notFound() } // Check if user can manage this tournament const permission = await canManageTournament(tournamentId) if (!permission.allowed) { redirect("/auth/login") } // Check if user can delete this tournament const deletePermission = await canDeleteTournament(tournamentId) let tournament = await prisma.event.findUnique({ where: { id: tournamentId }, include: { participants: { include: { player: true, }, }, teams: { include: { player1: true, player2: true, }, }, rounds: { include: { bracketMatchups: { include: { team1: { include: { player1: true, player2: true, }, }, team2: { include: { player1: true, player2: true, }, }, match: true, }, }, }, }, }, }) if (!tournament) { notFound() } // Update tournament status based on event date const calculatedStatus = getTournamentStatus(tournament.eventDate); if (tournament.status !== calculatedStatus) { tournament = await prisma.event.update({ where: { id: tournamentId }, data: { status: calculatedStatus }, include: { participants: { include: { player: true, }, }, teams: { include: { player1: true, player2: true, }, }, rounds: { include: { bracketMatchups: { include: { team1: { include: { player1: true, player2: true, }, }, team2: { include: { player1: true, player2: true, }, }, match: true, }, }, }, }, }, }); } const matches = await prisma.match.findMany({ where: { eventId: tournamentId }, include: { team1P1: true, team1P2: true, team2P1: true, team2P2: true, }, orderBy: { playedAt: "desc" }, }) const matchCount = matches.length return (
{/* Breadcrumb */} {/* Tournament Header */}

{tournament.name}

{tournament.format} - {tournament.status}

{tournament.eventDate && (

{new Date(tournament.eventDate).toLocaleDateString()}

)}
{permission.allowed && ( <> Edit Enter Results Export CSV {deletePermission.allowed && ( )} )}
{/* Quick Stats */}

Participants

{tournament.participants.length}

Teams

{tournament.teams.length}

Rounds

{tournament.rounds.length}

Matches

{matches.length}

{/* Tabs */}
{/* Content */}
{/* Participants Section */}

Participants ({tournament.participants.length})

{tournament.participants.length > 0 ? (
{tournament.participants.map((participant) => (
{participant.player.name}
))}
) : (

No participants registered yet.

)}
{/* Teams Section */}

Teams ({tournament.teams.length})

{tournament.teams.length > 0 ? (
{tournament.teams.map((team) => (

{team.player1.name} + {team.player2.name}

{team.teamName}

))}
) : (

No teams created yet.

)}
{/* Recent Matches Section */}

Recent Matches ({matches.length})

{matches.length > 0 ? (
{matches.slice(0, 10).map((match) => (

{match.playedAt?.toLocaleDateString()}

{match.team1P1.name} + {match.team1P2.name} vs{" "} {match.team2P1.name} + {match.team2P2.name}

match.team2Score ? 'text-green-600' : match.team1Score < match.team2Score ? 'text-red-600' : 'text-gray-600' }`}> {match.team1Score} - match.team1Score ? 'text-green-600' : match.team2Score < match.team1Score ? 'text-red-600' : 'text-gray-600' }`}> {match.team2Score}
))}
) : (

No matches recorded yet.

)}
) }