import { notFound } from 'next/navigation';
import { getEventsList, getEventBySlug } from '@/services/server/events';
import EventDetailsView from '@/components/events/EventDetailsView';

export const dynamic = 'force-dynamic';
export const revalidate = 0;

export default async function EventDetailsPage({ params }: { params: Promise<{ slug: string }> }) {
    const { slug } = await params;
    const decodedSlug = decodeURIComponent(slug);
    const eventItem = await getEventBySlug(decodedSlug);

    if (!eventItem) {
        return notFound();
    }

    // Pass related events as well
    const allEvents = await getEventsList();
    const relatedEvents = allEvents
        .filter(e => e.slug !== decodedSlug && e.id !== decodedSlug)
        .slice(0, 3);

    return <EventDetailsView event={eventItem} relatedEvents={relatedEvents} />;
}
