'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { useLanguage } from '@/context/LanguageContext'; import { eventsApi, Event } from '@/lib/api'; import { formatPrice, formatDateLong, formatTime } from '@/lib/utils'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import { CalendarIcon, MapPinIcon } from '@heroicons/react/24/outline'; interface NextEventSectionProps { initialEvent?: Event | null; } export default function NextEventSection({ initialEvent }: NextEventSectionProps) { const { t, locale } = useLanguage(); const [nextEvent, setNextEvent] = useState(initialEvent ?? null); const [loading, setLoading] = useState(!initialEvent); useEffect(() => { // Skip fetch if we already have server-provided data if (initialEvent !== undefined) return; eventsApi.getNextUpcoming() .then(({ event }) => setNextEvent(event)) .catch(console.error) .finally(() => setLoading(false)); }, [initialEvent]); const formatDate = (dateStr: string) => formatDateLong(dateStr, locale as 'en' | 'es'); const fmtTime = (dateStr: string) => formatTime(dateStr, locale as 'en' | 'es'); if (loading) { return (
); } if (!nextEvent) { return (

{t('home.nextEvent.noEvents')}

{t('home.nextEvent.stayTuned')}

); } return (

{locale === 'es' && nextEvent.titleEs ? nextEvent.titleEs : nextEvent.title}

{locale === 'es' ? (nextEvent.shortDescriptionEs || nextEvent.descriptionEs || nextEvent.shortDescription || nextEvent.description) : (nextEvent.shortDescription || nextEvent.description)}

{formatDate(nextEvent.startDatetime)}
{fmtTime(nextEvent.startDatetime)}
{nextEvent.location}
{nextEvent.price === 0 ? t('events.details.free') : formatPrice(nextEvent.price, nextEvent.currency)} {!nextEvent.externalBookingEnabled && (

{nextEvent.availableSeats} {t('events.details.spotsLeft')}

)}
); }