// @ts-check
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import YAML from "yaml";
import fs from "fs";
import react from "@astrojs/react";

const vocabListFile = fs.readFileSync("src/vocab_list.yaml", "utf8");
const vocabListJson = YAML.parse(vocabListFile);
const categories = vocabListJson.map(
  (/** @type {{ slug: string }} */ category) => category.slug,
);

const vocabList = [
  {
    label: "Index",
    link: `/vocabulary`,
  },
].concat(
  categories.map((/** @type {string} */ category) => ({
    label: category.charAt(0).toUpperCase() + category.slice(1),
    link: `/vocabulary/${category}`,
  })),
);

// https://astro.build/config
export default defineConfig({
  vite: {
    resolve: {
      alias: {
        "@": "/src",
      },
    },
  },
  integrations: [
    starlight({
      title: "हिंदकी",
      customCss: [
        // Path to your custom CSS file
        "./src/styles/custom.css",
      ],
      sidebar: [
        {
          label: "Home",
          link: "/",
        },
        {
          label: "About Me",
          link: "/about-me",
        },
        {
          label: "Grammar",
          autogenerate: { directory: "grammar" },
        },
        {
          label: "Vocabulary",
          items: vocabList,
        },
        {
          label: "Culture",
          autogenerate: { directory: "culture" },
        },
        {
          label: "How I Built This",
          autogenerate: { directory: "how-i-built-this" },
        },
        {
          label: "Edit YAML",
          link: "/edit",
        },
      ],
    }),
    react(),
  ],
});
