import { defineConfig } from "astro/config";
import starlight from "@astrojs/starlight";
import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code";
import themeJson from "./src/styles/theme.json";
import darkThemeJson from "./src/styles/theme-dark.json";
import mermaid from "astro-mermaid";

import { navigation } from "./src/components/navigation.ts";

const sakuraDreams = ExpressiveCodeTheme.fromJSONString(
  JSON.stringify(themeJson)
);
const sakuraDreamsDark = ExpressiveCodeTheme.fromJSONString(
  JSON.stringify(darkThemeJson)
);

export default defineConfig({
  site: "https://docs.nhcarrigan.com",
  integrations: [
    mermaid(),
    starlight({
      components: {
        Footer: "./src/components/Footer.astro",
        ThemeProvider: "./src/components/ThemeProvider.astro",
      },
      title: "NHCarrigan Docs",
      sidebar: navigation,
      tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4 },
      description:
        "This site contains all of the documentation related to NHCarrigan, its Policies, and its Projects.",
      editLink: {
        baseUrl: "https://git.nhcarrigan.com/nhcarrigan/docs/_edit/main/",
        label: "Edit this page on Naomi's Self-hosted Git instance",
      },
      lastUpdated: true,
      social: [
        { icon: 'github', label: 'GitHub', href: 'https://git.nhcarrigan.com' },
        { icon: 'discord', label: 'Discord', href: 'https://chat.nhcarrigan.com' },
        { icon: 'blueSky', label: 'Bluesky', href: 'https://bsky.app/profile/nhcarrigan.com' },
        { icon: 'linkedin', label: 'LinkedIn', href: 'https://www.linkedin.com/company/nhcarrigan/' },
        { icon: 'twitter', label: 'Twitter', href: 'https://x.com/nhcarrigan1' },
        { icon: 'email', label: 'Email', href: 'mailto:contact@nhcarrigan.com' },
      ],
      logo: {
        src: "./public/logo.png",
        alt: "NHCarrigan Logo",
        replacesTitle: true
      },
      head: [
        {
          tag: "script",
          attrs: {
            type: "text/javascript",
            id: "analytics",
            src: "https://analytics.nhcarrigan.com/js/pa-YUXAn1vhhRttySUAw_LMN.js",
            defer: true,
          },
        },
        {
          tag: "script",
          content:`
  window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};
  plausible.init({
    customProperties: {
      domain: "docs.nhcarrigan.com",
      page: document.querySelector("title")?.innerText ?? "Unknown Docs Page",
      path: window.location.pathname,
    },
  })
          `
        },
        {
          tag: "script",
          attrs: {
            type: "text/javascript",
            id: "trees",
            src: "https://widgets.tree-nation.com/js/widgets/v1/widgets.min.js?v=1.0",
            defer: true,
          },
        },
        {
          tag: "link",
          attrs: {
            rel: "icon",
            href: "./public/logo.png",
          },
        },
        {
          tag: "script",
          attrs: {
            type: "text/javascript",
            src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3569924701890974",
            async: true,
            crossorigin: "anonymous",
          },
        },
        {
          tag: "meta",
          attrs: {
            property: "og:image",
            content: "https://cdn.nhcarrigan.com/og-image.png"
          }
        }
      ],
      customCss: ["./src/styles/style.css", "./src/fonts/font-face.css"],
      expressiveCode: {
        themes: [sakuraDreams, sakuraDreamsDark],
      },
    }),
  ],
});
