---
import TagComponent from "~/components/astro/tag.astro"
import { langs } from "~/i18n/ui"
import { getPostsByLocale } from "~/utils"

export interface Props {
  posts: any
  tag: string
}

export async function getStaticPaths() {
  const paths = await Promise.all(
    langs.map(async (lang) => {
      const posts = await getPostsByLocale(lang)
      const uniqueTags = [
        ...new Set(posts.flatMap((post: any) => post.data.tags || [])),
      ]

      return uniqueTags.map((tag) => ({
        params: { tag, lang },
        props: {
          posts,
          tag,
        },
      }))
    }),
  )

  return paths.flat()
}
---

<TagComponent {...Astro.props} />
