"use client" import { useEffect, useState } from "react" import { useParams } from "next/navigation" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { ArrowLeft, MapPin, Calendar, Music, Star } from "lucide-react" import Link from "next/link" import { getApiUrl } from "@/lib/api-config" interface Venue { id: number name: string city: string state: string country: string capacity: number | null notes: string | null } interface Show { id: number slug?: string date: string tour?: { name: string } vertical?: { name: string; slug: string } performances?: any[] } // ... (skipping to render loop) { shows.map((show) => (
{new Date(show.date).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })} {show.vertical && ( {show.vertical.name} )}
{show.tour?.name && (
{show.tour.name}
)}
{show.performances?.length || 0} songs
)) } export default function VenueDetailPage() { const params = useParams() const slug = params.slug as string const [venue, setVenue] = useState(null) const [shows, setShows] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { async function fetchData() { try { // Fetch venue const venueRes = await fetch(`${getApiUrl()}/venues/${slug}`) if (!venueRes.ok) { if (venueRes.status === 404) { setError("Venue not found") } else { setError("Failed to load venue") } return } const venueData = await venueRes.json() setVenue(venueData) // Fetch shows at this venue using numeric ID const showsRes = await fetch(`${getApiUrl()}/shows/?venue_id=${venueData.id}&limit=100`) if (showsRes.ok) { const showsEnvelope = await showsRes.json() const showsData = showsEnvelope.data || [] // Sort by date descending showsData.sort((a: Show, b: Show) => new Date(b.date).getTime() - new Date(a.date).getTime() ) setShows(showsData) } } catch (err) { console.error("Error fetching venue:", err) setError("Failed to load venue") } finally { setLoading(false) } } fetchData() }, [slug]) if (loading) { return (
) } if (error || !venue) { return (

{error || "Venue not found"}

) } return (
{/* Header */}

{venue.name}

{venue.city}{venue.state ? `, ${venue.state}` : ""}, {venue.country}

{shows.length}
{shows.length === 1 ? "show" : "shows"}
{/* Shows List */} Shows at {venue.name} {shows.length > 0 ? (
{shows.map((show) => (
{new Date(show.date).toLocaleDateString("en-US", { weekday: "short", year: "numeric", month: "short", day: "numeric" })} {show.vertical && ( {show.vertical.name} )}
{show.tour && ( {show.tour.name} )} {show.performances && show.performances.length > 0 && ( {show.performances.length} )}
))}
) : (

No shows recorded at this venue yet.

)}
{/* Sidebar */}
{/* Venue Details */} Venue Details
Location {venue.city}{venue.state ? `, ${venue.state}` : ""}
{venue.country}
{venue.capacity && (
Capacity {venue.capacity.toLocaleString()}
)}
Total Shows {shows.length}
{shows.length > 0 && ( <>
First Show {new Date(shows[shows.length - 1].date).toLocaleDateString()}
Last Show {new Date(shows[0].date).toLocaleDateString()}
)} {venue.notes && (

{venue.notes}

)}
{/* Quick Stats */} {shows.length > 0 && ( Quick Stats
{shows.length}
Shows
{shows.reduce((acc, s) => acc + (s.performances?.length || 0), 0)}
Performances
)}
) }