'use client'; import { useEffect, useState } from 'react'; import AudioPlayer from './AudioPlayer'; import GuessInput from './GuessInput'; import { useGameState } from '../lib/gameState'; interface GameProps { dailyPuzzle: { id: number; audioUrl: string; songId: number; } | null; } const UNLOCK_STEPS = [2, 4, 7, 11, 16, 30]; export default function Game({ dailyPuzzle }: GameProps) { const { gameState, addGuess } = useGameState(); const [hasWon, setHasWon] = useState(false); const [hasLost, setHasLost] = useState(false); const [shareText, setShareText] = useState('Share Result'); useEffect(() => { if (gameState && dailyPuzzle) { setHasWon(gameState.isSolved); setHasLost(gameState.isFailed); } }, [gameState, dailyPuzzle]); if (!dailyPuzzle) return
Loading puzzle...
; if (!gameState) return
Loading state...
; const handleGuess = (song: any) => { if (song.id === dailyPuzzle.songId) { addGuess(song.title, true); setHasWon(true); } else { addGuess(song.title, false); if (gameState.guesses.length + 1 >= 6) { setHasLost(true); } } }; const unlockedSeconds = UNLOCK_STEPS[Math.min(gameState.guesses.length, 5)]; const handleShare = () => { let emojiGrid = ''; const totalGuesses = 6; // Build the grid for (let i = 0; i < totalGuesses; i++) { if (i < gameState.guesses.length) { // If this was the winning guess (last one and won) if (hasWon && i === gameState.guesses.length - 1) { emojiGrid += '🟩'; } else { // Wrong or skipped emojiGrid += '⬛'; } } else { // Unused attempts emojiGrid += '⬜'; } } const speaker = hasWon ? '🔉' : '🔇'; const text = `Hördle #${dailyPuzzle.id}\n\n${speaker}${emojiGrid}\n\n#Hördle #Music\n\nhttps://hoerdle.elpatron.me`; navigator.clipboard.writeText(text).then(() => { setShareText('Copied!'); setTimeout(() => setShareText('Share Result'), 2000); }); }; return (

Hördle #{dailyPuzzle.id}

Attempt {gameState.guesses.length + 1} / 6 {unlockedSeconds}s unlocked
{gameState.guesses.map((guess, i) => { const isCorrect = hasWon && i === gameState.guesses.length - 1; return (
#{i + 1} {isCorrect ? 'Correct!' : guess}
); })}
{!hasWon && !hasLost && ( <> )} {hasWon && (

You won!

Come back tomorrow for a new song.

)} {hasLost && (

Game Over

The song was hidden.

)}
); }