---
import ArchivePanel from "@components/ArchivePanel.astro";
import I18nKey from "@i18n/i18nKey";
import { i18n } from "@i18n/translation";
import MainGridLayout from "@layouts/MainGridLayout.astro";
import { getSortedPosts } from "@utils/content-utils";

export async function getStaticPaths() {
  const posts = await getSortedPosts();

  const allTags = posts.reduce((acc, post) => {
    post.data.tags?.forEach(tag => acc.add(tag));
    return acc;
  }, new Set());

  const allTagsArray = Array.from(allTags);

  return allTagsArray.map(tag => {
    return {
      params: {
        tag: tag,
      },
    };
  });
}

const { tag } = Astro.params as { tag: string };
---

<MainGridLayout title={i18n(I18nKey.archive)} description={i18n(I18nKey.archive)}>
    <ArchivePanel tags={[tag]}></ArchivePanel>
</MainGridLayout>
