import { PlaylistHeader } from '@/components/PlaylistHeader' import { TrackList } from '@/components/TrackList' interface PageProps { params: Promise<{ id: string }> } async function getPlaylist(id: string) { const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/playlists/${id}`, { cache: 'no-store', }) if (!res.ok) throw new Error('Playlist not found') const data = await res.json() return data.playlist } export default async function PlaylistPage({ params }: PageProps) { const { id } = await params const playlist = await getPlaylist(id) // Calculate total duration from songs const totalDuration = playlist.songs?.reduce((acc: number, item: any) => { const song = item.song || item return acc + (song.duration || 0) }, 0) || 0 // Transform playlist songs for TrackList const tracks = playlist.songs?.map((item: any, index: number) => { const song = item.song || item return { id: song.id, title: song.title, artistName: song.artist?.name || 'Unknown Artist', duration: song.duration || 0, plays: song.plays, position: item.position || index + 1 } }) || [] return (
{/* Track List */} {tracks.length > 0 ? (
) : (

This playlist is empty

Add some songs to get started

)} {/* Playlist Info */} {playlist.description && (

Description

{playlist.description}

)}

Created

{new Date(playlist.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}

Songs

{playlist.songs?.length || 0} tracks

{playlist.songs && playlist.songs.length > 0 && (

Total Duration

{Math.floor(playlist.songs.reduce((acc: number, song: any) => acc + song.duration, 0) / 60)} minutes

)}
) }