---
import BarcampPage from "../../../components/BarcampPage.astro";
import EventPage from "../../../components/EventPage.astro";
import { getEventByParams, getEventPageEntries, yearPathEvents } from "../../../data/events";

export function getStaticPaths() {
  return yearPathEvents.flatMap((event) =>
    getEventPageEntries(event)
      .filter((pageEntry) => pageEntry.type !== "overview")
      .map((pageEntry) => ({
        params: {
          year: event.year,
          slug: event.slug,
          page: pageEntry.id,
        },
        props: {
          event,
          pageEntry,
        },
      })),
  );
}

const { event, pageEntry } = Astro.props;

if (!event || !pageEntry) {
  const { year, slug } = Astro.params;
  const fallbackEvent = getEventByParams(year!, slug!);
  if (!fallbackEvent) return Astro.redirect("/");
}
---

{event.slug === "barcamp" ? <BarcampPage event={event} pageEntry={pageEntry} /> : <EventPage event={event} pageEntry={pageEntry} />}
