import React, { useEffect, useRef, useState } from 'react'; import { useAudio } from '../../context/AudioContext'; import { Mic2, AlignLeft } from 'lucide-react'; export const LyricsPanel: React.FC = () => { const { currentTrack, currentTime, seek, duration } = useAudio(); const scrollRef = useRef(null); const [autoScroll, setAutoScroll] = useState(true); // Auto-scroll logic useEffect(() => { if (autoScroll && scrollRef.current && currentTrack?.lyrics) { const activeIndex = currentTrack.lyrics.findIndex( (line: { time: number; text: string }, i: number) => { return ( currentTime >= line.time && (i === currentTrack.lyrics!.length - 1 || currentTime < currentTrack.lyrics![i + 1].time) ); }, ); if (activeIndex !== -1) { const element = scrollRef.current.children[activeIndex] as HTMLElement; if (element) { element.scrollIntoView({ behavior: 'smooth', block: 'center' }); } } } }, [currentTime, currentTrack, autoScroll]); if (!currentTrack?.lyrics) { return (

No lyrics available

); } return (
setAutoScroll(false)} onMouseLeave={() => setAutoScroll(true)} >
{currentTrack.lyrics.map( (line: { time: number; text: string }, i: number) => { const isActive = currentTime >= line.time && (i === currentTrack.lyrics!.length - 1 || currentTime < currentTrack.lyrics![i + 1].time); return (

seek((line.time / duration) * 100)} > {line.text}

); }, )}
); };