import { prisma } from "@/lib/prisma"; import { notFound } from "next/navigation"; import Link from "next/link"; import Navigation from "@/components/Navigation"; interface PageProps { params: { id: string; }; } export default async function MatchDetailPage({ params }: PageProps) { const { id } = await params; const matchId = parseInt(id, 10); if (isNaN(matchId)) { notFound(); } // Fetch match with all player data const match = await prisma.match.findUnique({ where: { id: matchId }, include: { team1P1: true, team1P2: true, team2P1: true, team2P2: true, event: true, eloSnapshots: { include: { player: true, }, orderBy: { playerId: "asc", }, }, }, }); if (!match) { notFound(); } // Calculate Elo changes from snapshots const eloChanges: { [playerId: number]: number } = {}; match.eloSnapshots.forEach((snapshot) => { eloChanges[snapshot.playerId] = snapshot.ratingChange; }); return (
{/* Header */}

Match #{match.id}

← All Matches
{match.event && (

Part of{" "} {match.event.name}

)}
{/* Match Diagram */}

Match Setup

{/* Table Square - Larger with more padding */}
{/* Top: Team 1 Player 1 */}

{match.team1P1.name}

Elo: {match.team1P1.currentElo} {eloChanges[match.team1P1.id] !== undefined && ( = 0 ? "text-green-600 ml-1" : "text-red-600 ml-1"}> ({eloChanges[match.team1P1.id] >= 0 ? "+" : ""}{eloChanges[match.team1P1.id]}) )}

Team 1
{/* Bottom: Team 2 Player 2 */}
Team 2

{match.team2P2.name}

Elo: {match.team2P2.currentElo} {eloChanges[match.team2P2.id] !== undefined && ( = 0 ? "text-green-600 ml-1" : "text-red-600 ml-1"}> ({eloChanges[match.team2P2.id] >= 0 ? "+" : ""}{eloChanges[match.team2P2.id]}) )}

{/* Left: Team 1 Player 2 */}

{match.team1P2.name}

Elo: {match.team1P2.currentElo} {eloChanges[match.team1P2.id] !== undefined && ( = 0 ? "text-green-600" : "text-red-600"}> ({eloChanges[match.team1P2.id] >= 0 ? "+" : ""}{eloChanges[match.team1P2.id]}) )}

{/* Right: Team 2 Player 1 */}

{match.team2P1.name}

Elo: {match.team2P1.currentElo} {eloChanges[match.team2P1.id] !== undefined && ( = 0 ? "text-green-600" : "text-red-600"}> ({eloChanges[match.team2P1.id] >= 0 ? "+" : ""}{eloChanges[match.team2P1.id]}) )}

{/* Score in Center */}

{match.team1Score}

Team 1

{match.team2Score}

Team 2

{/* Legend */}
Team 1
Team 2
{/* Match Details */}

Match Details

Match ID
{match.id}
{match.playedAt && (
Date Played
{new Date(match.playedAt).toLocaleDateString()}
)} {match.event && (
Tournament
{match.event.name}
)}
Match Type
{match.isCasual ? "Casual" : "Tournament"}
{/* Elo Changes */}

Elo Changes

{/* Team 1 */}

Team 1

{match.team1P1.name} = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.team1P1.id] >= 0 ? "+" : ""}{eloChanges[match.team1P1.id]}
{match.team1P2.name} = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.team1P2.id] >= 0 ? "+" : ""}{eloChanges[match.team1P2.id]}
{/* Team 2 */}

Team 2

{match.team2P1.name} = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.team2P1.id] >= 0 ? "+" : ""}{eloChanges[match.team2P1.id]}
{match.team2P2.name} = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.team2P2.id] >= 0 ? "+" : ""}{eloChanges[match.team2P2.id]}
); }