import { h } from 'preact'; import { useState } from 'preact/hooks'; import styles from './GameDetail.module.css'; import type { Game, EndlosGame } from '../types/game'; interface GameDetailProps { game: Game | undefined; onFinishGame: () => void; onUpdateScore: (player: number, change: number) => void; onUpdateGame?: (game: EndlosGame) => void; onUndo?: () => void; onForfeit?: () => void; onBack: () => void; } /** * Game detail view for a single game. */ const GameDetail = ({ game, onFinishGame, onUpdateScore, onUpdateGame, onUndo, onForfeit, onBack }: GameDetailProps) => { if (!game) return null; const handleScoreUpdate = (playerIndex: number, change: number) => { onUpdateScore(playerIndex, change); // Silent update; toast notifications removed }; const isCompleted = game.status === 'completed'; const playerNames = [game.player1, game.player2, game.player3].filter(Boolean); const scores = [game.score1, game.score2, game.score3].filter((_, i) => playerNames[i]); return (
{game.gameType}{game.raceTo ? ` | Race to ${game.raceTo}` : ''}
{playerNames.map((name, idx) => { const currentScore = scores[idx]; const progressPercentage = game.raceTo ? Math.min((currentScore / game.raceTo) * 100, 100) : 0; return (
{name} {(() => { const order = (game as any).breakOrder as number[] | undefined; const breakerIdx = (game as any).currentBreakerIdx as number | undefined; if (order && typeof breakerIdx === 'number' && order[breakerIdx] === idx + 1) { return ; } return null; })()}
!isCompleted && onUpdateScore(idx + 1, 1)} onKeyDown={(e) => { if (!isCompleted && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); onUpdateScore(idx + 1, 1); } }} role="button" tabIndex={isCompleted ? -1 : 0} aria-label={`Aktueller Punktestand für ${name}: ${scores[idx]}. Klicken oder Enter drücken zum Erhöhen.`} > {scores[idx]} {/* +/- buttons removed per issue #29. Tap score to +1; use Undo to revert. */}
); })}
{onUndo && ( )}
); }; export default GameDetail;