import { loader } from "fumadocs-core/source";
import { docs } from "@/.source";
import { createOpenAPI, attachFile } from "fumadocs-openapi/server";
import icons from "./icons";
import { createElement } from "react";
import { TbBrandReact, TbBrandTypescript } from "react-icons/tb";

const add_icons = {
   TypeScript: TbBrandTypescript,
   React: TbBrandReact,
};

export const source = loader({
   baseUrl: "/",
   source: docs.toFumadocsSource(),
   pageTree: {
      // adds a badge to each page item in page tree
      attachFile,
   },
   icon(icon) {
      if (!icon) {
         // You may set a default icon
         return;
      }
      if (icon in icons) return createElement(icons[icon as keyof typeof icons]);
   },
});

export const openapi = createOpenAPI();
