'use client'; import React from 'react'; import { motion } from 'framer-motion'; import { Player } from '@/lib/types'; interface GameOverProps { winner: Player | null; players: Player[]; currentPlayerId: string | null; rematchRequests: string[]; onPlayAgain: () => void; onRequestRematch: () => void; onLeave: () => void; isAIGame: boolean; } export function GameOver({ winner, players, currentPlayerId, rematchRequests, onPlayAgain, onRequestRematch, onLeave, isAIGame }: GameOverProps) { const hasRequestedRematch = currentPlayerId ? rematchRequests.includes(currentPlayerId) : false; const otherPlayersRequested = rematchRequests.filter(id => id !== currentPlayerId); const waitingForOthers = hasRequestedRematch && otherPlayersRequested.length < players.length - 1; return (
{winner ? '🏆' : '🤝'}

{winner ? 'Game Over!' : 'Game Blocked!'}

{winner && (

{winner.name} wins!

)}

Final Scores

{players .sort((a, b) => { const scoreA = a.tiles.reduce((sum, t) => sum + t.left + t.right, 0); const scoreB = b.tiles.reduce((sum, t) => sum + t.left + t.right, 0); return scoreA - scoreB; }) .map((player, index) => { const score = player.tiles.reduce((sum, t) => sum + t.left + t.right, 0); const isWinner = player.id === winner?.id; const hasRequestedRematchPlayer = rematchRequests.includes(player.id); return (
{isWinner && 👑}
{player.name} {hasRequestedRematchPlayer && !isAIGame && ( Wants rematch )}
{player.tiles.length} tiles remaining
{score}
); })}
{isAIGame ? ( Play Again ) : ( {hasRequestedRematch ? (waitingForOthers ? 'Waiting for others...' : 'Starting rematch...') : 'Request Rematch' } )} Leave Game
); }