import React, { useEffect, useRef } from 'react'; import { LyricLine } from '../types'; interface LyricsPanelProps { lyrics: LyricLine[]; currentTime: number; } const LyricsPanel: React.FC = ({ lyrics, currentTime }) => { const containerRef = useRef(null); const activeIndex = lyrics.findIndex((line, i) => { const nextLine = lyrics[i + 1]; return currentTime >= line.time && (!nextLine || currentTime < nextLine.time); }); useEffect(() => { if (activeIndex !== -1 && containerRef.current) { const activeElement = containerRef.current.children[activeIndex] as HTMLElement; if (activeElement) { // Calculate scroll position to center the active element const containerHeight = containerRef.current.clientHeight; const elementTop = activeElement.offsetTop; const elementHeight = activeElement.clientHeight; containerRef.current.scrollTo({ top: elementTop - containerHeight / 2 + elementHeight / 2, behavior: 'smooth' }); } } }, [activeIndex]); if (lyrics.length === 0) { return (

No lyrics available for this track.

); } return (
{lyrics.map((line, index) => { const isActive = index === activeIndex; return (
{line.text}
); })}
); }; export default LyricsPanel;