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 (
Eingereicht von: {submitter ? getDisplayName(submitter, lobby, currentPlayer) : (lobby?.settings?.hidePlayerNames ? 'Anonymer Spieler' : winner.submittedByName)}
{battle.song1.artist}
{battle.song1Votes} Stimmen {!lobby?.settings?.hidePlayerNames && ( Eingereicht von: {song1Submitter ? getDisplayName(song1Submitter, lobby, currentPlayer) : battle.song1?.submittedByName || 'Unbekannt'} )}{battle.song2.artist}
{battle.song2Votes} Stimmen {!lobby?.settings?.hidePlayerNames && ( Eingereicht von: {song2Submitter ? getDisplayName(song2Submitter, lobby, currentPlayer) : battle.song2?.submittedByName || 'Unbekannt'} )}Kein Gegner