// @ts-check
import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import react from "@astrojs/react";
import node from "@astrojs/node";
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { tags } from './src/lib/db/schema.ts';

// Load tags from database for sidebar
const sqlite = new Database('./data.db');
const db = drizzle(sqlite);
const tagsList = db.select().from(tags).all();

const vocabList = [
  {
    label: "Index",
    link: `/vocabulary`,
  },
].concat(
  tagsList.map((tag) => ({
    label: tag.name.charAt(0).toUpperCase() + tag.name.slice(1),
    link: `/vocabulary/${tag.name}`,
  })),
);

// 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: "Add Vocabulary",
          link: "/edit/add-vocab",
        },
        {
          label: "Learn",
          link: "/learn",
        },
      ],
      components: {
        PageSidebar: "@/components/PageSidebar.astro",
      },
    }),
    react(),
  ],

  adapter: node({
    mode: "standalone",
  }),
});
