import { Check, HelpCircle, X, Loader2 } from 'lucide-react'; import { LoginArea } from '@/components/auth/LoginArea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useToast } from '@/hooks/useToast'; import { useEventRsvps, useRsvp } from '@/hooks/useEventRsvps'; import { eventCoord } from '@/hooks/useEventRsvps'; import { cn } from '@/lib/utils'; import type { RsvpStatus, SkateEvent } from '@/lib/types'; const OPTIONS: { status: RsvpStatus; label: string; shortLabel: string; icon: typeof Check; activeClass: string; }[] = [ { status: 'accepted', label: "I'm Going", shortLabel: 'Going', icon: Check, activeClass: 'bg-green-500 border-green-500 text-black', }, { status: 'tentative', label: 'Interested', shortLabel: 'Maybe', icon: HelpCircle, activeClass: 'bg-[#ccff00] border-[#ccff00] text-black', }, { status: 'declined', label: "Can't make it", shortLabel: "Can't", icon: X, activeClass: 'bg-red-500/80 border-red-500 text-white', }, ]; /** * NIP-52 RSVP control. A segmented Going / Interested / Can't-make-it toggle * that publishes (or replaces) the user's RSVP. Tapping the active option again * is a no-op. Logged-out users see a login prompt instead. */ export function RsvpButtons({ event, className }: { event: SkateEvent; className?: string }) { const { user } = useCurrentUser(); const { toast } = useToast(); const coord = eventCoord(event); const { myRsvp, myStatus, goingCount, tentativeCount } = useEventRsvps(coord); const { mutateAsync: rsvp, isPending } = useRsvp(); const isHost = user?.pubkey === event.pubkey; if (!user) { return (

Are you going?{' '} Log in to RSVP.

); } const handleClick = async (status: RsvpStatus) => { if (status === myStatus || isPending) return; try { await rsvp({ event, status, existingIdentifier: myRsvp?.identifier, }); const msg = status === 'accepted' ? "You're going! 🛹" : status === 'tentative' ? 'Marked as interested.' : 'Marked as not going.'; toast({ title: msg }); } catch (err) { toast({ title: 'Could not RSVP', description: err instanceof Error ? err.message : 'Please try again.', variant: 'destructive', }); } }; return (
{isHost && (

You're hosting this — but you can still set your status.

)}
{OPTIONS.map(({ status, label, shortLabel, icon: Icon, activeClass }) => { const active = myStatus === status; return ( ); })}
{(goingCount > 0 || tentativeCount > 0) && (

{goingCount} going {tentativeCount > 0 && ( <> {' · '} {tentativeCount} interested )}

)}
); }