import { Metadata, ResolvingMetadata } from "next";
import { notFound } from "next/navigation";
import {
  EventPageView,
  loadEventPageProps,
} from "@/components/events/EventPageView";
import { getSeoMetadata } from "@/lib/seo";

export async function generateStaticParams() {
  // Prerender nothing at build time; render and cache on first request
  return [];
}

type Params = Promise<{ slug: string }>;

export async function generateMetadata(
  { params }: { params: Params },
  parent: ResolvingMetadata
): Promise<Metadata | null> {
  const { slug } = await params;
  const props = await loadEventPageProps({ slug });
  if (!props) return null;
  return getSeoMetadata(props.event, parent);
}

export default async function Page({ params }: { params: Params }) {
  const { slug } = await params;
  const props = await loadEventPageProps({ slug });
  if (!props) return notFound();
  return <EventPageView {...props} />;
}
