---
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()

  // タグを集めるための Set の型を指定
  const allTags = posts.reduce<Set<string>>((acc, post) => {
    // biome-ignore lint/complexity/noForEach: <explanation>
    post.data.tags.forEach(tag => acc.add(tag))
    return acc
  }, new Set())

  const allTagsArray = Array.from(allTags)

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

const tag = Astro.params.tag as string
---

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