"use client" import { useEffect, useState } from "react" import Link from "next/link" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { useAuth } from "@/contexts/auth-context" import { getApiUrl } from "@/lib/api-config" interface Vertical { id: number name: string slug: string description: string | null } interface Preference { vertical_id: number tier: string } export function TieredBandList({ initialVerticals }: { initialVerticals: Vertical[] }) { const [verticals, setVerticals] = useState(initialVerticals) const [preferences, setPreferences] = useState([]) const { token, isAuthenticated } = useAuth() const [loading, setLoading] = useState(false) // Default headliners for guests const defaultHeadliners = ["phish", "grateful-dead", "dead-and-company", "billy-strings", "goose"] useEffect(() => { if (isAuthenticated && token) { setLoading(true) fetch(`${process.env.NEXT_PUBLIC_API_URL || "https://api.fediversion.org"}/verticals/preferences/me`, { headers: { Authorization: `Bearer ${token}` } }) .then(res => { if (res.ok) return res.json() return [] }) .then((data: any[]) => { // Map response to preference format const prefs = data.map(p => ({ vertical_id: p.vertical_id, tier: p.tier || "main_stage" })) setPreferences(prefs) }) .catch(err => console.error("Failed to fetch preferences", err)) .finally(() => setLoading(false)) } }, [isAuthenticated, token]) // Determine tiers let headliners: Vertical[] = [] let others: Vertical[] = [] if (isAuthenticated && preferences.length > 0) { // User has preferences const headlinerIds = preferences.filter(p => p.tier === "headliner").map(p => p.vertical_id) const subscribedIds = preferences.map(p => p.vertical_id) headliners = verticals.filter(v => headlinerIds.includes(v.id)) others = verticals.filter(v => !headlinerIds.includes(v.id)) // If user has NO headliners set but HAS preferences, maybe show their top priority? // Or just defaults. if (headliners.length === 0) { // Fallback to top 3 priority? // For now, let's mix in defaults if empty? No, respect user choice. // If they selected bands but no headliners, all are "others" (Touring Acts). } // Optionally filter "others" to only show subscribed bands? // The requirement says "Main Stage: Standard following". // "Supporting: Hidden unless relevant". // Let's show subscribed bands as "Your Bands" and others as "Discover". // But for simple "Tiered Band Preferences" UI, let's keep it simple: // Headliners = Tier 'headliner' // Touring Acts = Everyone else (or just subscribed 'main_stage'?) // Let's show All Bands but prioritize Headliners. } else { // Guest or no prefs headliners = verticals.filter(v => defaultHeadliners.includes(v.slug)) others = verticals.filter(v => !defaultHeadliners.includes(v.slug)) } return (
{/* Headliners */} {headliners.length > 0 && (

{isAuthenticated && preferences.length > 0 ? "Your Headliners" : "Headliners"}

{headliners.map((vertical) => ( ))}
)} {/* Other Acts */} {others.length > 0 && (

Touring Acts

{others.map((vertical) => ( ))}
)}
) } function VerticalCard({ vertical, featured = false }: { vertical: Vertical, featured?: boolean }) { return ( {vertical.name} {featured && ( )} {featured && vertical.description && ( {vertical.description} )} {featured && (
Shows Setlists Stats
)}
) }