import { h } from 'preact'; import modalStyles from '@lib/ui/Modal.module.css'; import styles from './GameCompletionModal.module.css'; import type { Game } from '@lib/domain/types'; interface GameCompletionModalProps { open: boolean; game: Game | null; onConfirm: () => void; onClose: () => void; onRematch: () => void; } /** * Modal shown when a game is completed. */ const GameCompletionModal = ({ open, game, onConfirm, onClose, onRematch }: GameCompletionModalProps) => { if (!open || !game) return null; const playerNames = [game.player1, game.player2, game.player3].filter(Boolean); const scores = [game.score1, game.score2, game.score3].filter((_, i) => playerNames[i]); let maxScore, winners, winnerText; if (game.forfeitedBy) { winnerText = `${game.winner} hat gewonnen, da ${game.forfeitedBy} aufgegeben hat.`; } else { maxScore = Math.max(...scores); winners = playerNames.filter((name, idx) => scores[idx] === maxScore); winnerText = winners.length > 1 ? `Unentschieden zwischen ${winners.join(' und ')}` : `${winners[0]} hat gewonnen!`; } return ( ); }; export default GameCompletionModal;