import { usePlayerStore } from '../store/playerStore'; import { useUIStore } from '@/stores/ui'; import { cn } from '@/lib/utils'; import { X, GripVertical, ListMusic, Sparkles } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { EmptyState } from '@/components/ui/empty-state'; import { useQuery } from '@tanstack/react-query'; import { useAuthStore } from '@/features/auth/store/authStore'; import { tracksApi } from '@/services/api/tracks'; import { getHLSMasterPlaylistURL } from '@/features/streaming/services/hlsService'; import type { Track as PlayerTrack } from '../types'; import type { Track as ApiTrack } from '@/features/tracks/types/track'; interface PlayerQueueProps { isOpen: boolean; onClose: () => void; currentTrackId?: string; onPlay: (track: any) => void; } function mapApiTrackToPlayerTrack(t: ApiTrack): PlayerTrack { const apiTrack = t as ApiTrack & { stream_manifest_url?: string; cover_art_path?: string }; return { id: t.id, title: t.title, artist: t.artist, duration: t.duration ?? 0, url: apiTrack.stream_manifest_url ?? getHLSMasterPlaylistURL(t.id), cover: apiTrack.cover_art_path, genre: t.genre, like_count: t.like_count, }; } export function PlayerQueue({ isOpen, onClose, onPlay }: PlayerQueueProps) { const { queue, currentIndex, removeFromQueue, clearQueue } = usePlayerStore(); const { sidebarOpen } = useUIStore(); const isAuthenticated = useAuthStore((s) => s.isAuthenticated); const { data: recommendations = [], isLoading: recommendationsLoading } = useQuery({ queryKey: ['track-recommendations'], queryFn: () => tracksApi.getRecommendations({ limit: 10 }), enabled: isOpen && isAuthenticated && queue.length === 0, staleTime: 60_000, }); const playerTracks = recommendations.map(mapApiTrackToPlayerTrack); if (!isOpen) return null; return (
{/* Header */}

Play Queue

{queue.length} Tracks
{/* Content */}
{queue.length === 0 ? (
{playerTracks.length > 0 ? ( <>

À écouter ensuite

{playerTracks.map((track) => (
onPlay(track)} >

{track.title}

{track.artist}

))}

Cliquez pour lire

) : recommendationsLoading ? (
Chargement des suggestions…
) : ( } title="Your queue is empty" description="Add tracks to keep the vibe going." size="sm" className="border-0 shadow-none bg-transparent" /> )}
) : (
{queue.map((track, index) => { const isCurrent = index === currentIndex; const isPast = index < currentIndex; return (
{/* Drag Handle (Simulated) */}
{/* Number/Status */}
{isCurrent ? (
) : ( index + 1 )}
{/* Info */}
!isCurrent && onPlay(track)} >

{track.title}

{track.artist}

{/* Actions */}
); })}
)}
{/* Backdrop for explicit dismissal on mobile if needed */}
); }