import React, { useState, useRef, useEffect } from 'react'; import { usePlayerStore } from '../store/playerStore'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { Slider } from '@/components/ui/slider'; import { Tooltip } from '@/components/ui/tooltip'; import { ChevronDown, Heart, MoreHorizontal, Share2, Mic2, AlignLeft } from 'lucide-react'; import { PlayPauseButton } from './PlayPauseButton'; // We might reuse or inline for consistent style import { NextPreviousButtons } from './NextPreviousButtons'; import { RepeatShuffleButtons } from './RepeatShuffleButtons'; interface PlayerExpandedProps { isOpen: boolean; onClose: () => void; currentTime: number; duration: number; onSeek: (time: number) => void; player: any; // Using the player hook object } export function PlayerExpanded({ isOpen, onClose, currentTime, duration, onSeek, player }: PlayerExpandedProps) { const { currentTrack } = usePlayerStore(); const [showLyrics, setShowLyrics] = useState(false); const [autoScrollLyrics, setAutoScrollLyrics] = useState(true); const lyricsScrollRef = useRef(null); if (!isOpen || !currentTrack) return null; const lyrics = currentTrack.lyrics; const formatTime = (seconds: number) => { if (!seconds && seconds !== 0) return '0:00'; const m = Math.floor(seconds / 60); const s = Math.floor(seconds % 60); return `${m}:${s.toString().padStart(2, '0')}`; }; // Auto-scroll lyrics to active line useEffect(() => { if (!autoScrollLyrics || !lyrics?.length || !lyricsScrollRef.current) return; const activeIndex = lyrics.findIndex( (line, i) => currentTime >= line.time && (i === lyrics.length - 1 || currentTime < lyrics[i + 1].time) ); if (activeIndex >= 0) { const el = lyricsScrollRef.current.children[activeIndex] as HTMLElement; el?.scrollIntoView({ behavior: 'smooth', block: 'center' }); } }, [currentTime, lyrics, autoScrollLyrics]); return (
{/* Dynamic Background */}
{/* Header */}
Following the Signal
{/* Main Content */}
{/* Left: Album Art */}
{currentTrack.title}
{/* Right: Info & Controls */}

{currentTrack.title}

{currentTrack.artist}

{/* Progress */}
onSeek(val[0])} max={duration || 100} step={0.1} className="py-2" />
{formatTime(currentTime)} {formatTime(duration)}
{/* Controls */}
{/* Todo: Reuse or reimplement buttons with larger sizes */}
player.isPlaying ? player.pause() : player.resume()} size="xl" // We need to support 'xl' maybe or modify the component className="scale-125" /> {/* Wait, NextPrevious contains both buttons. I was using it wrong above. */}
{/* Lyrics Panel (when toggled and track has lyrics) */} {showLyrics && (
setAutoScrollLyrics(false)} onMouseLeave={() => setAutoScrollLyrics(true)} >
{lyrics?.length ? (
{lyrics.map((line, i) => { const isActive = currentTime >= line.time && (i === lyrics.length - 1 || currentTime < lyrics[i + 1].time); return (

onSeek(line.time)} > {line.text}

); })}
) : (

No lyrics available for this track.

)}
)}
); }