import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; 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: { player1P1: true, player1P2: true, player2P1: true, player2P2: 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.player1P1?.name}

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

Team 1
{/* Bottom: Team 1 Player 2 - teammate opposite Top */}
Team 1

{match.player1P2?.name}

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

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

{match.player2P1?.name}

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

{/* Right: Team 2 Player 2 - teammate opposite Left */}

{match.player2P2?.name}

Elo: {match.player2P2?.currentElo} {match.player2P2 && eloChanges[match.player2P2.id] !== undefined && ( = 0 ? "text-green-600" : "text-red-600"}> ({eloChanges[match.player2P2.id] >= 0 ? "+" : ""}{eloChanges[match.player2P2.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.player1P1?.name} {match.player1P1 && ( = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.player1P1.id] >= 0 ? "+" : ""}{eloChanges[match.player1P1.id]} )}
{match.player1P2?.name} {match.player1P2 && ( = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.player1P2.id] >= 0 ? "+" : ""}{eloChanges[match.player1P2.id]} )}
{/* Team 2 */}

Team 2

{match.player2P1?.name} {match.player2P1 && ( = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.player2P1.id] >= 0 ? "+" : ""}{eloChanges[match.player2P1.id]} )}
{match.player2P2?.name} {match.player2P2 && ( = 0 ? "text-green-600" : "text-red-600"}> {eloChanges[match.player2P2.id] >= 0 ? "+" : ""}{eloChanges[match.player2P2.id]} )}
); }