import { useRef } from 'react' import { Button } from '@/components/ui/button' import { Card } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { useMusicPlayer } from '@/contexts/MusicPlayerContext' import { Play, Pause, Square, SkipBack, SkipForward, Volume2, VolumeX, Repeat, Repeat1, Shuffle, List, Maximize2, Minimize2, Minus, ArrowRightToLine, ExternalLink, Download, Globe } from 'lucide-react' import { formatDuration } from '@/lib/format-duration' export function MusicPlayer() { const { isPlaying, currentTime, duration, volume, isMuted, playMode, currentTrack, playlist, currentTrackIndex, isMinimized, isUltraMinimized, showPlaylist, togglePlayPause, stop, previousTrack, nextTrack, seekTo, setVolume, toggleMute, setPlayMode, playTrack, toggleMaximize, toggleUltraMinimize, togglePlaylistVisibility, } = useMusicPlayer() const progressBarRef = useRef(null) // Show player if there's a playlist, even if no current track is playing if (playlist.length === 0) { return null } const handleVolumeChange = (e: React.ChangeEvent) => { const newVolume = parseFloat(e.target.value) setVolume(newVolume) } const handleProgressClick = (e: React.MouseEvent) => { if (progressBarRef.current) { const rect = progressBarRef.current.getBoundingClientRect() const clickX = e.clientX - rect.left const percentage = clickX / rect.width const newTime = percentage * duration seekTo(newTime) } } const getPlayModeIcon = () => { switch (playMode) { case 'loop-playlist': return case 'loop-one': return case 'random': return case 'single': return default: return } } const handlePlayModeToggle = () => { const modes = ['continuous', 'loop-playlist', 'loop-one', 'random', 'single'] as const const currentIndex = modes.indexOf(playMode) const nextIndex = (currentIndex + 1) % modes.length setPlayMode(modes[nextIndex]) } const progressPercentage = (currentTime / duration) * 100 // Ultra-minimized view - only essential controls if (isUltraMinimized) { return (
) } if (isMinimized) { return ( {/* Thumbnail */} {currentTrack?.thumbnail && (
{currentTrack.title}
)}
{/* Track info */}
{(currentTrack?.file_url || currentTrack?.service_url) && ( {currentTrack?.file_url && ( window.open(currentTrack.file_url, '_blank')}> Open File )} {currentTrack?.service_url && ( window.open(currentTrack.service_url, '_blank')}> Open Service )} )}

{currentTrack?.title || 'No track selected'}

{currentTrack?.artist && (

{currentTrack.artist}

)}
{/* Progress bar */}
{formatDuration(currentTime)} {formatDuration(duration)}
{/* Main controls */}
{/* Secondary controls */}
{/* Volume control */}
{/* Playlist */} {showPlaylist && ( <>

Playlist

{playlist.map((track, index) => (
playTrack(index)} >

{track.title}

{track.artist && (

{track.artist}

)}
{formatDuration(track.duration)}
))}
)}
) } // Maximized view - overlay return ( {/* Header */}

Music Player

{/* Main player area */}
{/* Large thumbnail */} {currentTrack?.thumbnail && (
{currentTrack.title}
)} {/* Track info */}
{(currentTrack?.file_url || currentTrack?.service_url) && ( {currentTrack?.file_url && ( window.open(currentTrack.file_url, '_blank')}> Open File )} {currentTrack?.service_url && ( window.open(currentTrack.service_url, '_blank')}> Open Service )} )}

{currentTrack?.title || 'No track selected'}

{currentTrack?.artist && (

{currentTrack.artist}

)}
{/* Progress bar */}
{formatDuration(currentTime)} {formatDuration(duration)}
{/* Main controls */}
{/* Secondary controls */}
{/* Volume control */}
{/* Playlist sidebar */}

Playlist

{playlist.map((track, index) => (
playTrack(index)} >

{track.title}

{track.artist && (

{track.artist}

)}
{formatDuration(track.duration)}
))}
) }