"use client" import { useEffect, useState } from "react" import { useAuth } from "@/contexts/auth-context" import { useRouter } from "next/navigation" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Badge } from "@/components/ui/badge" import { Search, Edit, Save, X, Mic2 } from "lucide-react" import { getApiUrl } from "@/lib/api-config" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog" import { Label } from "@/components/ui/label" interface Artist { id: number name: string slug: string bio: string | null image_url: string | null notes: string | null } export default function AdminArtistsPage() { const { user, token, loading: authLoading } = useAuth() const router = useRouter() const [artists, setArtists] = useState([]) const [loading, setLoading] = useState(true) const [search, setSearch] = useState("") const [editingArtist, setEditingArtist] = useState(null) const [saving, setSaving] = useState(false) useEffect(() => { if (authLoading) return if (!user) { router.push("/login") return } if (user.role !== "admin") { router.push("/") return } fetchArtists() }, [user, router, authLoading]) const fetchArtists = async () => { if (!token) return try { const res = await fetch(`${getApiUrl()}/admin/artists?limit=1000`, { headers: { Authorization: `Bearer ${token}` } }) if (res.ok) setArtists(await res.json()) } catch (e) { console.error("Failed to fetch artists", e) } finally { setLoading(false) } } const updateArtist = async () => { if (!token || !editingArtist) return setSaving(true) try { const res = await fetch(`${getApiUrl()}/admin/artists/${editingArtist.id}`, { method: "PATCH", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, body: JSON.stringify({ bio: editingArtist.bio, image_url: editingArtist.image_url, notes: editingArtist.notes }) }) if (res.ok) { fetchArtists() setEditingArtist(null) } } catch (e) { console.error("Failed to update artist", e) } finally { setSaving(false) } } const filteredArtists = artists.filter(a => a.name.toLowerCase().includes(search.toLowerCase()) ) if (loading) { return (
{[1, 2, 3].map(i =>
)}
) } return (

Artist Management

setSearch(e.target.value)} className="pl-9" />
{filteredArtists.map(artist => ( ))}
Artist Bio Image Actions

{artist.name}

{artist.slug}

{artist.bio ? ( Has Bio ) : ( No Bio )} {artist.image_url ? ( Has Image ) : ( No Image )}
{filteredArtists.length === 0 && (
No artists found
)}
setEditingArtist(null)}> Edit Artist: {editingArtist?.name} {editingArtist && (