"use client" import { useEffect, useState } from "react" import { useParams, useRouter } from "next/navigation" import { ArrowLeft, Play, ChevronDown, ChevronUp } from "lucide-react" import { useSettingsStore } from "@/store/settings-store" import { usePlayerStore } from "@/store/player-store" import { Sidebar } from "@/components/app/sidebar" import { PlayerBar } from "@/components/app/player-bar" import { MobileNav } from "@/components/app/mobile-nav" import { TrackList } from "@/components/app/track-list" import { AlbumCard } from "@/components/app/album-card" import { LoadingSpinner } from "@/components/app/loading-spinner" import { EmptyState } from "@/components/app/empty-state" import { Button } from "@/components/ui/button" import { useArtist } from "@/hooks/use-artist" import { topTracksToPlayerTracks } from "@/lib/api" export default function ArtistPage() { const params = useParams() const router = useRouter() const theme = useSettingsStore((state) => state.theme) const { loadAndPlayQueue } = usePlayerStore((state) => state.actions) const [isBioExpanded, setIsBioExpanded] = useState(false) const artistId = Number.parseInt(params.id as string) const { artist, isLoading, error } = useArtist(artistId) useEffect(() => { if (theme !== "custom") { document.documentElement.setAttribute("data-theme", theme) } else { document.documentElement.removeAttribute("data-theme") } document.documentElement.classList.add("dark") }, [theme]) const handlePlayTopTracks = () => { if (artist && artist.top_tracks.length > 0) { const tracks = topTracksToPlayerTracks(artist.top_tracks, artist.name.display) loadAndPlayQueue(tracks, 0) } } const handleAlbumClick = (albumId: string) => { router.push(`/album/${albumId}`) } if (isLoading) { return (
) } if (error || !artist) { return (
) } const topTracks = topTracksToPlayerTracks(artist.top_tracks, artist.name.display) const bioText = artist.biography?.content || "" const bioLines = bioText.split("\n").filter((line) => line.trim()) const shouldTruncate = bioLines.length > 3 const displayBio = shouldTruncate && !isBioExpanded ? bioLines.slice(0, 3).join("\n") : bioText return (

Artist

{artist.name.display}

{bioText && (

{displayBio}

{shouldTruncate && !isBioExpanded && (
)}
{shouldTruncate && ( )}
)}
{topTracks.length > 0 && (

Top Tracks

)} {artist.releases.map((release) => { if (release.items.length === 0) return null return (

{release.type}s {release.has_more && (Top)}

{release.items.map((item) => ( handleAlbumClick(item.id)} /> ))}
) })}
) }