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

Release Date

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

{album.label && (

Label

{album.label.name}

)} {album.songs && album.songs.length > 0 && (

Total Duration

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

)}

Tracks

{album.songs?.length || 0} songs

) }