'use client'; import type { Color } from 'chess.js'; import { BotAvatar, HumanAvatar } from './Avatars'; import { IconDownload, IconX } from './icons'; import { RESULT_SCORE, reasonText, type GameResult } from '../core/chess'; interface Props { result: GameResult; playerColor: Color; /** The engine played both sides: name the winner by color. */ selfPlay: boolean; onRematch: () => void; onNewGame: () => void; onDownload: () => void; onClose: () => void; } export default function GameOverModal({ result, playerColor, selfPlay, onRematch, onNewGame, onDownload, onClose }: Props) { const aborted = result.reason === 'abort'; const title = aborted ? 'Game aborted' : result.winner === null ? 'Draw' : selfPlay ? `${result.winner === 'w' ? 'White' : 'Black'} won` : result.winner === playerColor ? 'You won' : 'ChessTransformer won'; const score = RESULT_SCORE(result).replace('1/2', '½').replace('1/2', '½'); const [left, right] = playerColor === 'w' ? score.split('-') : score.split('-').reverse(); return (
e.stopPropagation()} >

{title}

{reasonText(result)}

{!aborted ? (
{selfPlay ? : } {left} – {right}
) : null}
{!aborted ? ( ) : null}
); }