"use client" import { useState, useEffect } from "react" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Play, ExternalLink, Video, Music } from "lucide-react" import { getApiUrl } from "@/lib/api-config" interface VideoItem { id: number url: string title: string | null description: string | null platform: string video_type: string duration_seconds: number | null thumbnail_url: string | null external_id: string | null } interface VideoGalleryProps { bandSlug?: string showId?: number songId?: number limit?: number title?: string } function extractYouTubeId(url: string): string | null { const patterns = [ /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]{11})/, ] for (const pattern of patterns) { const match = url.match(pattern) if (match) return match[1] } return null } function getThumbnailUrl(video: VideoItem): string { if (video.thumbnail_url) return video.thumbnail_url if (video.platform === "youtube") { const videoId = extractYouTubeId(video.url) if (videoId) return `https://img.youtube.com/vi/${videoId}/mqdefault.jpg` } return "/placeholder-video.jpg" } export function VideoGallery({ bandSlug, showId, songId, limit = 12, title = "Videos" }: VideoGalleryProps) { const [videos, setVideos] = useState([]) const [loading, setLoading] = useState(true) const [selectedVideo, setSelectedVideo] = useState(null) useEffect(() => { async function fetchVideos() { try { let endpoint = "" if (bandSlug) { endpoint = `${getApiUrl()}/videos/by-band/${bandSlug}?limit=${limit}` } else if (showId) { endpoint = `${getApiUrl()}/videos/by-show/${showId}` } else if (songId) { endpoint = `${getApiUrl()}/videos/by-song/${songId}` } else { endpoint = `${getApiUrl()}/videos/?limit=${limit}` } const res = await fetch(endpoint) if (res.ok) { const data = await res.json() setVideos(data) } } catch (error) { console.error("Failed to fetch videos:", error) } finally { setLoading(false) } } fetchVideos() }, [bandSlug, showId, songId, limit]) if (loading) { return (

{[...Array(4)].map((_, i) => (
))}
) } if (videos.length === 0) { return null // Don't show empty section } return (

{/* Video modal */} {selectedVideo && (
setSelectedVideo(null)} >
e.stopPropagation()}>
{selectedVideo.platform === "youtube" && (