'use client'; import { useState, useRef, useEffect } from 'react'; interface AudioPlayerProps { src: string; unlockedSeconds: number; // 2, 4, 7, 11, 16, 30 (or full length) onPlay?: () => void; } export default function AudioPlayer({ src, unlockedSeconds, onPlay }: AudioPlayerProps) { const audioRef = useRef(null); const [isPlaying, setIsPlaying] = useState(false); const [progress, setProgress] = useState(0); useEffect(() => { if (audioRef.current) { audioRef.current.pause(); audioRef.current.currentTime = 0; setIsPlaying(false); setProgress(0); } }, [src, unlockedSeconds]); const togglePlay = () => { if (!audioRef.current) return; if (isPlaying) { audioRef.current.pause(); } else { audioRef.current.play(); onPlay?.(); } setIsPlaying(!isPlaying); }; const handleTimeUpdate = () => { if (!audioRef.current) return; const current = audioRef.current.currentTime; const percent = (current / unlockedSeconds) * 100; setProgress(Math.min(percent, 100)); if (current >= unlockedSeconds) { audioRef.current.pause(); audioRef.current.currentTime = 0; setIsPlaying(false); setProgress(0); } }; return (