---
import { type CollectionEntry, getEntry, getEntries } from "astro:content";
import PublishedContentLayout from "./PublishedContentLayout.astro";
import { t } from "../i18n";
import Authors from "../components/Authors.astro";
import Prose from "../components/Prose.astro";
import UserComponent from "../components/UserComponent.astro";

type Props = CollectionEntry<"games">["data"];

const { props } = Astro;
const prev = props.prev && (await getEntry(props.prev));
const next = props.next && (await getEntry(props.next));
const series = props.series && (await getEntry(props.series));
const authorsList = await getEntries(props.authors);
const relatedStories = (await getEntries(props.relatedStories)).filter((story) => !story.data.isDraft);
const relatedGames = (await getEntries(props.relatedGames)).filter((game) => !game.data.isDraft);
---

<PublishedContentLayout
  publishedContentType="game"
  title={props.title}
  lang={props.lang}
  isDraft={props.isDraft}
  pubDate={props.pubDate}
  description={props.description}
  summary={undefined}
  tags={props.tags}
  thumbnail={props.thumbnail}
  thumbnailWidth={props.thumbnailWidth}
  thumbnailHeight={props.thumbnailHeight}
  copyrightedCharacters={props.copyrightedCharacters}
  series={series}
  prev={prev && !prev.data.isDraft
    ? { link: `/games/${prev.slug}`, title: t(props.lang, "game/previous_game", prev.data.title) }
    : undefined}
  next={next && !next.data.isDraft
    ? { link: `/games/${next.slug}`, title: t(props.lang, "game/next_game", next.data.title) }
    : undefined}
  relatedStories={relatedStories}
  relatedGames={relatedGames}
  posts={props.posts}
  labelReturnTo={{ title: t(props.lang, "game/return_to_games"), link: "/games" }}
  labelPreviousContent={t(props.lang, "game/previous_game_aria_label")}
  labelNextContent={t(props.lang, "game/next_game_aria_label")}
  labelTitleSection={t(props.lang, "game/title_aria_label")}
  labelInformationSection={t(props.lang, "game/information_aria_label")}
  labelArticleSection={t(props.lang, "game/article_aria_label")}
>
  <meta
    slot="head"
    property="og:description"
    content={t(props.lang, "game/warnings", props.platforms, props.contentWarning)}
  />
  <Fragment slot="section-information">
    <Authors lang={props.lang}>
      {
        authorsList.map((author) => (
          <UserComponent rel="author nofollow" class="p-author" user={author} lang={props.lang} />
        ))
      }
    </Authors>
    <div id="platforms">
      <p>{t(props.lang, "game/platforms", props.platforms)}</p>
    </div>
  </Fragment>
  <div slot="section-content-warning" id="content-warning">
    <p>{props.contentWarning}</p>
  </div>
  <Fragment slot="section-article">
    <Prose>
      <slot />
    </Prose>
  </Fragment>
</PublishedContentLayout>