"use client"; import { useEffect } from "react"; import { useRouter } from "next/navigation"; import { Card } from "@/components/ui/Card"; import { Button } from "@/components/ui/Button"; import { EmptyState } from "@/components/ui/EmptyState"; import { useAudio } from "@/lib/audio-context"; import { useAuth } from "@/lib/auth-context"; import { useToast } from "@/lib/toast-context"; import { api } from "@/lib/api"; import { cn } from "@/utils/cn"; import { Music, Play, X, GripVertical, Trash2, ListMusic, ChevronUp, ChevronDown, } from "lucide-react"; export default function QueuePage() { const router = useRouter(); const { isAuthenticated } = useAuth(); const { queue, currentTrack, currentIndex, playTracks, removeFromQueue } = useAudio(); const { toast } = useToast(); useEffect(() => { if (!isAuthenticated) { router.push("/login"); } }, [isAuthenticated, router]); const handleClearQueue = () => { // Clear queue by playing an empty array playTracks([], 0); toast.success("Queue cleared"); }; const handleRemoveTrack = (index: number) => { removeFromQueue(index); toast.success("Removed from queue"); }; const handlePlayFromQueue = (index: number) => { playTracks(queue, index); toast.success("Playing from queue"); }; const handleMoveUp = (index: number) => { if (index <= currentIndex + 1) return; // Can't move past current track const newQueue = [...queue]; [newQueue[index], newQueue[index - 1]] = [ newQueue[index - 1], newQueue[index], ]; playTracks(newQueue, currentIndex); }; const handleMoveDown = (index: number) => { if (index >= queue.length - 1 || index <= currentIndex) return; const newQueue = [...queue]; [newQueue[index], newQueue[index + 1]] = [ newQueue[index + 1], newQueue[index], ]; playTracks(newQueue, currentIndex); }; if (!isAuthenticated) { return null; } // Split queue into current, next up, and previous const previousTracks = queue.slice(0, currentIndex); const nextTracks = queue.slice(currentIndex + 1); return (
{/* Header */}

Queue

{queue.length} track {queue.length !== 1 ? "s" : ""} in queue

{queue.length > 0 && ( )}
{/* Empty State */} {queue.length === 0 && ( } title="No tracks in queue" description="Start playing music to see your queue here" action={{ label: "Browse Library", onClick: () => router.push("/library"), }} /> )} {/* Now Playing */} {currentTrack && (

Now Playing

{currentTrack.album?.coverArt ? ( {currentTrack.album.title} ) : (
)}

{currentTrack.title}

{currentTrack.artist?.name}

{currentTrack.album?.title}

{currentTrack.duration ? `${Math.floor( currentTrack.duration / 60 )}:${(currentTrack.duration % 60) .toString() .padStart(2, "0")}` : ""}
)} {/* Next Up */} {nextTracks.length > 0 && (

Next Up ({nextTracks.length})

{nextTracks.map((track, idx) => { const queueIndex = currentIndex + 1 + idx; return (
{/* Drag Handle */} {/* Album Art */}
{track.album?.coverArt ? ( {track.album.title} ) : (
)}
{/* Track Info */}

{track.title}

{track.artist?.name}

{/* Duration */}
{track.duration ? `${Math.floor( track.duration / 60 )}:${(track.duration % 60) .toString() .padStart(2, "0")}` : ""}
{/* Actions */}
); })}
)} {/* Previously Played */} {previousTracks.length > 0 && (

Previously Played ({previousTracks.length})

{previousTracks.map((track, idx) => (
{/* Album Art */}
{track.album?.coverArt ? ( {track.album.title} ) : (
)}
{/* Track Info */}

{track.title}

{track.artist?.name}

{/* Duration */}
{track.duration ? `${Math.floor( track.duration / 60 )}:${(track.duration % 60) .toString() .padStart(2, "0")}` : ""}
))}
)}
); }