"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Star } from "lucide-react" import { getApiUrl } from "@/lib/api-config" import { useAuth } from "@/contexts/auth-context" interface RatePerformanceProps { performanceId: number performanceDate: string venue: string currentRating?: number onRatingSubmit?: () => void } export function RatePerformanceDialog({ performanceId, performanceDate, venue, currentRating, onRatingSubmit }: RatePerformanceProps) { const [rating, setRating] = useState(currentRating || 0) const [open, setOpen] = useState(false) const [loading, setLoading] = useState(false) const { user } = useAuth() const handleRate = async () => { if (!user) return setLoading(true) const token = localStorage.getItem("token") try { const res = await fetch(`${getApiUrl()}/social/ratings`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, body: JSON.stringify({ performance_id: performanceId, score: rating }) }) if (res.ok) { setOpen(false) if (onRatingSubmit) onRatingSubmit() } } catch (e) { console.error(e) } finally { setLoading(false) } } // If not logged in, just show static star or nothing? // We'll let Button trigger login flow or disabled. if (!user) { return ( ) } return ( Rate Performance {performanceDate} at {venue} {[1, 2, 3, 4, 5].map((star) => ( setRating(star)} className={`p-1 transition-transform hover:scale-110 focus:outline-none ${rating >= star ? "text-yellow-500" : "text-muted-foreground/30 hover:text-yellow-500/70" }`} > = star ? "fill-current" : ""}`} /> ))} {rating > 0 ? `${rating} Stars` : "Tap to rate"} {loading ? "Submitting..." : "Submit Rating"} ) }