import { ApiImage } from "@/components/shared/ApiImage"; import { Calendar, MapPin } from "lucide-react"; import { ContactButton } from "@/components/events/ContactButton"; import { CampusBadge } from "@/components/shared/CampusFilter"; type Event = { id: string; title: string; description?: string; startDate: string; endDate: string; registrationDeadline?: string | null; goLiveAt?: string; price: number; picture?: string; isSoldOut?: boolean; waitlistEnabled?: boolean; requiresRegistration?: boolean; contactName?: string | null; contactPhone?: string | null; contactEmail?: string | null; location?: string | null; // Set by GET /api/events while an early-bird tier is still running. earlyBirdEndsAt?: string | null; scheduleType?: "single" | "sessions"; sessions?: EventSession[]; registrationClosesAt?: string; campus?: { id: string; name: string; slug: string; colour: string | null } | null; }; import { formatDateTimeRange } from "@/lib/date"; import { registrationClosesAt, scheduleSummary } from "@/lib/sessions"; import type { EventSession } from "@/types"; export const EventCard = ({ event }: { event: Event }) => { const dateRange = scheduleSummary(event) || formatDateTimeRange(event.startDate, event.endDate); const now = new Date(); const goLive = event.goLiveAt ? new Date(event.goLiveAt) : null; // Multi-day events close when the first session starts (or later with late joining). const closesAt = registrationClosesAt(event); const registrationOpen = event.requiresRegistration !== false && !(goLive && now < goLive) && now < closesAt; const showEarlyBird = !!event.earlyBirdEndsAt && registrationOpen && !event.isSoldOut; return (
{showEarlyBird && ( )} {showEarlyBird && ( Early bird pricing until {new Date(event.earlyBirdEndsAt!).toLocaleDateString("en-GB", { day: "numeric", month: "long" })}. )} {event.picture ? ( ) : (
)}

{event.title}

{dateRange}

{event.location && (

{event.location}

)}

{event.description}

View details {(() => { if (event.requiresRegistration === false) { return ( ); } const notYetOpen = goLive ? now < goLive : false; const closed = now >= closesAt; if (notYetOpen) { return ( ); } if (closed) { return ( ); } if (event.isSoldOut && event.waitlistEnabled) { // Sold out with a waitlist: send them to the event page to join it. return ( Sold out — join waitlist ); } if (event.isSoldOut) { return ( ); } return ( Register{event.price > 0 ? ` - R${event.price.toFixed(2)}` : ""} ); })()}
); };