'use client'; import { useState, useEffect } from 'react'; import { lastFmAPI } from '@/lib/lastfm-api'; import { Button } from '@/components/ui/button'; import { ChevronDown, ChevronUp, ExternalLink } from 'lucide-react'; interface ArtistBioProps { artistName: string; } export function ArtistBio({ artistName }: ArtistBioProps) { const [bio, setBio] = useState(''); const [loading, setLoading] = useState(false); const [expanded, setExpanded] = useState(false); const [lastFmUrl, setLastFmUrl] = useState(''); useEffect(() => { const fetchArtistInfo = async () => { if (!lastFmAPI.isAvailable()) return; setLoading(true); try { const artistInfo = await lastFmAPI.getArtistInfo(artistName); if (artistInfo?.bio?.summary) { // Clean up the bio text (remove HTML tags and Last.fm links) let cleanBio = artistInfo.bio.summary .replace(/<[^>]*>/g, '') // Remove HTML tags .replace(/\s+/g, ' ') // Normalize whitespace .trim(); // Remove the "Read more on Last.fm" part cleanBio = cleanBio.replace(/Read more on Last\.fm.*$/i, '').trim(); setBio(cleanBio); setLastFmUrl(`https://www.last.fm/music/${encodeURIComponent(artistName)}`); } } catch (error) { console.error('Failed to fetch artist bio:', error); } finally { setLoading(false); } }; fetchArtistInfo(); }, [artistName]); if (!lastFmAPI.isAvailable() || loading || !bio) { return null; } const shouldTruncate = bio.length > 300; const displayBio = shouldTruncate && !expanded ? bio.substring(0, 300) + '...' : bio; return (

About

{displayBio}

{shouldTruncate && ( )} {lastFmUrl && ( )}
); }