---
import Layout from "@layouts/Layout.astro";
import { getCollection } from "astro:content";
import { useTranslatedPath } from "@i18n/utils";

const tp = useTranslatedPath(Astro);

const collections = ["blog", "photos", "projects"];

const posts = await Promise.all(
  collections.map((collection) => {
    return getCollection(collection, {
      fields: ["slug", "title", "date", "tags"],
    });
  }),
);

const tags = new Set();

posts.flat().forEach((post) => {
  if (!post.data?.tags) return;
  post.data.tags.forEach((tag) => {
    tags.add(tag.toLowerCase());
  });
});

const _tags = [...tags.values()];
---

<Layout title="Max Richter">
  <article>
    <h1>Tags</h1>
    <div class="flex flex-col gap-2">
      {
        _tags.map((t) => {
          return <a href={tp("/tag/" + t)}>{t}</a>;
        })
      }
    </div>
  </article>
</Layout>
