'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 } from '@/lib/utils'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import { CalendarIcon, MapPinIcon } from '@heroicons/react/24/outline'; export default function NextEventSection() { const { t, locale } = useLanguage(); const [nextEvent, setNextEvent] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { eventsApi.getNextUpcoming() .then(({ event }) => setNextEvent(event)) .catch(console.error) .finally(() => setLoading(false)); }, []); const formatDate = (dateStr: string) => { return new Date(dateStr).toLocaleDateString(locale === 'es' ? 'es-ES' : 'en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }); }; const formatTime = (dateStr: string) => { return new Date(dateStr).toLocaleTimeString(locale === 'es' ? 'es-ES' : 'en-US', { hour: '2-digit', minute: '2-digit', }); }; 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)}
{formatTime(nextEvent.startDatetime)}
{nextEvent.location}
{nextEvent.price === 0 ? t('events.details.free') : formatPrice(nextEvent.price, nextEvent.currency)} {!nextEvent.externalBookingEnabled && (

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

)}
); }