import { remarkInstall } from "fumadocs-docgen";
import { defineConfig, defineDocs, frontmatterSchema, metaSchema } from "fumadocs-mdx/config";
import { transformerTwoslash } from "fumadocs-twoslash";
import { createFileSystemTypesCache } from "fumadocs-twoslash/cache-fs";
import { rehypeCodeDefaultOptions } from "fumadocs-core/mdx-plugins";
import { remarkAutoTypeTable } from "fumadocs-typescript";

// You can customise Zod schemas for frontmatter and `meta.json` here
// see https://fumadocs.vercel.app/docs/mdx/collections#define-docs
export const docs = defineDocs({
   docs: {
      schema: frontmatterSchema,
   },
   meta: {
      schema: metaSchema,
   },
});

export default defineConfig({
   mdxOptions: {
      remarkPlugins: [remarkInstall, remarkAutoTypeTable],
      rehypeCodeOptions: {
         lazy: true,
         experimentalJSEngine: true,
         langs: ["ts", "js", "html", "tsx", "mdx"],
         themes: {
            light: "light-plus",
            dark: "dark-plus",
         },
         transformers: [
            ...(rehypeCodeDefaultOptions.transformers ?? []),
            transformerTwoslash({
               typesCache: createFileSystemTypesCache(),
            }),
         ],
      },
   },
});
