---
import type { GetStaticPaths } from "astro";
import { type CollectionEntry, getCollection } from "astro:content";
import GameLayout from "@layouts/GameLayout.astro";
import { PUBLISH_DRAFTS } from "astro:env/server";

type Props = CollectionEntry<"games">;

type Params = {
  slug: CollectionEntry<"games">["slug"];
};

export const getStaticPaths: GetStaticPaths = async () => {
  const games = await getCollection("games");
  return games
    .filter((game) => import.meta.env.DEV || PUBLISH_DRAFTS || !game.data.isDraft)
    .map((game) => ({
      params: { slug: game.slug } satisfies Params,
      props: game satisfies Props,
    }));
};

const game = Astro.props;
const { Content } = await game.render();
---

<GameLayout {...game.data}>
  <Content />
</GameLayout>
