import { prisma } from "@/lib/prisma" import Navigation from "@/components/Navigation" import Link from "next/link" import { notFound } from "next/navigation" interface PageProps { params: { id: string } } export default async function PlayerProfilePage({ params }: PageProps) { const playerId = parseInt(params.id) const player = await prisma.player.findUnique({ where: { id: playerId }, }) if (!player) { notFound() } // Get partnership stats separately const partnershipStats = await prisma.partnershipStat.findMany({ where: { OR: [ { player1Id: playerId }, { player2Id: playerId }, ], }, include: { player1: true, player2: true, }, orderBy: { gamesPlayed: "desc" }, }) // Use direct player stats for overall statistics (more accurate and consistent with rankings page) const totalGames = player.gamesPlayed const totalWins = player.wins const winRate = totalGames > 0 ? ((totalWins / totalGames) * 100).toFixed(1) : "0.0" // Get best partnership const bestPartnership = partnershipStats.reduce((best, stat) => { if (stat.gamesPlayed < 3) return best // Need at least 3 games for partnership to be meaningful const currentRate = stat.wins / stat.gamesPlayed const bestRate = best ? best.wins / best.gamesPlayed : 0 return currentRate > bestRate ? stat : best }, null as (typeof partnershipStats[0] | null)) return (
{/* Player Header */}
{player.name.charAt(0).toUpperCase()}

{player.name}

Member since {new Date(player.createdAt).toLocaleDateString()}

{/* Stats Grid */}

Current Elo

{player.currentElo}

Total Games

{totalGames}

Win Rate

{winRate}%

Best Partner

{bestPartnership ? (bestPartnership.player1Id === player.id ? bestPartnership.player2.name : bestPartnership.player1.name) : "N/A"}

{/* Partnership Performance */}

Partnership Performance

{partnershipStats.length === 0 ? (

No partnership data available yet.

) : (
{partnershipStats.map((stat) => { const partner = stat.player1Id === player.id ? stat.player2 : stat.player1 const winRate = stat.gamesPlayed > 0 ? ((stat.wins / stat.gamesPlayed) * 100).toFixed(1) : "0.0" return ( ) })}
Partner Games Win Rate ELO Change Last Played
{partner.name} {stat.gamesPlayed} {winRate}% = 0 ? 'text-green-600' : 'text-red-600' }`}> {stat.totalEloChange >= 0 ? '+' : ''}{stat.totalEloChange} {stat.lastPlayed ? new Date(stat.lastPlayed).toLocaleDateString() : "N/A"}
)}
) }