import { useEffect, useState } from 'react'; import { useGame } from '../context/GameContext'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faTrophy, faHome, faRedo, faChartLine } from '@fortawesome/free-solid-svg-icons'; import YouTubeEmbed from './YouTubeEmbed'; import { getDisplayName } from '../utils/playerUtils'; const ResultsScreen = () => { const { lobby, currentPlayer, leaveLobby } = useGame(); const [showBattleHistory, setShowBattleHistory] = useState(false); const [confetti, setConfetti] = useState(true); // Gewinner-Informationen const winner = lobby?.finalWinner; const winnerVideoId = getYouTubeId(winner?.youtubeLink); // Konfetti-Effekt für die Siegerfeier useEffect(() => { if (confetti) { // Konfetti-Animation erstellen const createConfetti = () => { const confettiContainer = document.createElement('div'); confettiContainer.className = 'confetti'; // Zufällige Position, Größe und Farbe const left = Math.random() * 100; const colors = ['#f94144', '#f3722c', '#f8961e', '#f9c74f', '#90be6d', '#43aa8b', '#577590']; const color = colors[Math.floor(Math.random() * colors.length)]; const size = Math.random() * 0.7 + 0.3; // Zwischen 0.3 und 1rem const rotation = Math.random() * 360; // Zufällige Rotation const duration = Math.random() * 3 + 2; // Zwischen 2 und 5 Sekunden confettiContainer.style.left = `${left}%`; confettiContainer.style.backgroundColor = color; confettiContainer.style.width = `${size}rem`; confettiContainer.style.height = `${size * 0.6}rem`; confettiContainer.style.transform = `rotate(${rotation}deg)`; confettiContainer.style.animation = `confetti-fall ${duration}s linear forwards`; document.querySelector('.results-screen').appendChild(confettiContainer); // Nach Animation entfernen setTimeout(() => { confettiContainer.remove(); }, duration * 1000); }; // Mehrere Konfetti-Stücke erstellen const confettiInterval = setInterval(() => { for (let i = 0; i < 5; i++) { createConfetti(); } }, 200); // Konfetti nach einiger Zeit stoppen setTimeout(() => { clearInterval(confettiInterval); setConfetti(false); }, 10000); return () => { clearInterval(confettiInterval); }; } }, [confetti]); // YouTube-Video-ID aus Link extrahieren function getYouTubeId(url) { if (!url) return null; const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/; const match = url.match(regExp); return (match && match[2].length === 11) ? match[2] : null; } // Find the submitter from the player list const findSubmitter = (submitterId) => { if (!lobby || !lobby.players) return null; return lobby.players.find(player => player.id === submitterId); }; if (!winner) { return (

Ergebnisse werden berechnet...

); } // Find the player who submitted the winning song const submitter = findSubmitter(winner.submittedBy); return (

Gewinner!

{winner.title}

von {winner.artist}

Eingereicht von: {submitter ? getDisplayName(submitter, lobby, currentPlayer) : (lobby?.settings?.hidePlayerNames ? 'Anonymer Spieler' : winner.submittedByName)}

{winnerVideoId ? (
) : (
)}
{showBattleHistory && (

Kampfverlauf

{lobby?.battles?.map((battle, index) => { const isWinner = (battle.song1.id === battle.winner); const song1VideoId = getYouTubeId(battle.song1?.youtubeLink); const song2VideoId = battle.song2 ? getYouTubeId(battle.song2.youtubeLink) : null; // Find the players who submitted the songs const song1Submitter = findSubmitter(battle.song1?.submittedBy); const song2Submitter = battle.song2 ? findSubmitter(battle.song2?.submittedBy) : null; // Freilos-Runden behandeln const isByeRound = battle.bye === true || !battle.song2; return (

Runde {battle.round + 1}, Kampf {index + 1} {isByeRound ? "(Automatisches Weiterkommen)" : ""}

{battle.song1.title}

{battle.song1.artist}

{battle.song1Votes} Stimmen {!lobby?.settings?.hidePlayerNames && ( Eingereicht von: {song1Submitter ? getDisplayName(song1Submitter, lobby, currentPlayer) : battle.song1?.submittedByName || 'Unbekannt'} )}
{isByeRound ? 'FREILOS' : 'VS'}
{battle.song2 ? (
{battle.song2.title}

{battle.song2.artist}

{battle.song2Votes} Stimmen {!lobby?.settings?.hidePlayerNames && ( Eingereicht von: {song2Submitter ? getDisplayName(song2Submitter, lobby, currentPlayer) : battle.song2?.submittedByName || 'Unbekannt'} )}
) : (
Automatisches Freilos

Kein Gegner

)}
); })}
)}
); }; export default ResultsScreen;