import { Fragment, useState, type CSSProperties } from 'react' import { type GameState } from '../types' import { computeRunningTotals, isGameOver } from '../game/scoring' import PageFrame from '../components/PageFrame' import PrimaryButton from '../components/PrimaryButton' import styles from './ScoreSheet.module.css' interface Props { game: GameState onScoreRound: () => void onNewGame: () => void onEditRound: (i: number) => void } export default function ScoreSheet({ game, onScoreRound, onNewGame, onEditRound }: Props) { const [confirmingNewGame, setConfirmingNewGame] = useState(false) const totals = computeRunningTotals(game.rounds) const gameOver = isGameOver(totals) const lastTotals = totals[totals.length - 1] ?? [] const winnerIndex = gameOver ? lastTotals.indexOf(Math.max(...lastTotals)) : -1 const newGameButton = ( ) const confirmOverlay = (

End this game?

) return ( setConfirmingNewGame(true) : onScoreRound}> {gameOver ? 'New Game' : 'Score Round'} } >
{game.players.map((name, j) => (
{name}
))} {game.rounds.map((roundScores, i) => (
Round {i + 1}
{roundScores.map((score, j) => (
{score}
))} {i > 0 && ( <>
{totals[i].map((total, j) => (
{total}
))} )} ))}
) }