import { readdirSync } from 'node:fs';
import { defineNuxtModule, createResolver, addVitePlugin, extendViteConfig, addPlugin, addComponent, addImports } from '@nuxt/kit';
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import TailwindCSS from '@tailwindcss/vite';

const EXPOSED_UI_FOLDERS = [
  "alert-dialog",
  "badge",
  "breadcrumb",
  "button",
  "button-group",
  "calendar",
  "checkbox",
  "collapsible",
  "color-picker",
  "command",
  "context-menu",
  "date-picker",
  "date-range-picker",
  "dialog",
  "drawer",
  "dropdown-menu",
  "field",
  "input",
  "input-group",
  "label",
  "markdown",
  "native-select",
  "navigation-menu",
  "number-field",
  "popover",
  "progress",
  "range-calendar",
  "scroll-area",
  "select",
  "separator",
  "sheet",
  "sidebar",
  "skeleton",
  "switch",
  "tabs",
  "textarea",
  "toggle",
  "toggle-group",
  "tooltip"
];
const module$1 = defineNuxtModule({
  meta: {
    name: "shwfed",
    configKey: "shwfed"
  },
  moduleDependencies: {
    "@nuxt/fonts": {
      version: "^0.14.0",
      defaults: {
        providers: {
          google: false,
          googleicons: false
        },
        families: [
          { name: "Noto Sans", provider: "bunny" },
          { name: "Noto Sans SC", provider: "bunny" },
          { name: "Noto Sans JP", provider: "bunny" },
          { name: "Fira Mono", provider: "bunny" }
        ]
      }
    }
  },
  setup(_options, nuxt) {
    const resolver = createResolver(import.meta.url);
    const resolvedConfig = {
      git: {
        commit: process.env.GIT_COMMIT,
        branch: process.env.GIT_LOCAL_BRANCH
      },
      ci: {
        job: process.env.JOB_NAME,
        build: process.env.BUILD_NUMBER ? Number.parseInt(process.env.BUILD_NUMBER) : void 0
      }
    };
    nuxt.options.runtimeConfig.public.shwfed = resolvedConfig;
    addVitePlugin(VueI18nPlugin({
      ssr: true
    }));
    addVitePlugin(TailwindCSS());
    nuxt.options.css.push(resolver.resolve("./runtime/style.css"));
    nuxt.options.css.push("vue-sonner/style.css");
    extendViteConfig((config) => {
      config.optimizeDeps ||= {};
      config.optimizeDeps.include ||= [];
      config.optimizeDeps.include.push(
        "reka-ui",
        "reka-ui/namespaced",
        "vue-sonner",
        "@tanstack/vue-table",
        "@tanstack/vue-virtual",
        "effect",
        "fx-fetch",
        "@vueuse/core",
        "date-fns",
        "@date-fns/tz",
        "class-variance-authority",
        "vue-i18n",
        "markdown-it",
        "@iconify/vue",
        "clsx",
        "tailwind-merge",
        "@atlaskit/pragmatic-drag-and-drop/combine",
        "@atlaskit/pragmatic-drag-and-drop/element/adapter",
        "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item",
        "@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source",
        "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview",
        "vaul-vue",
        "dot-prop",
        "@internationalized/date",
        "reka-ui/date",
        "@unovis/ts",
        "@unovis/vue",
        "@codemirror/commands",
        "@codemirror/language",
        "@codemirror/state",
        "@codemirror/view",
        "@lezer/highlight",
        "@number-flow/vue"
      );
    });
    addPlugin(resolver.resolve("./runtime/plugins/i18n"));
    addComponent({
      name: "ShwfedApp",
      filePath: resolver.resolve("./runtime/components/app.vue")
    });
    addComponent({
      name: "ShwfedConfig",
      filePath: resolver.resolve("./runtime/components/config/index.vue")
    });
    for (const folder of EXPOSED_UI_FOLDERS) {
      const folderPath = resolver.resolve(`./runtime/components/ui/${folder}`);
      for (const file of readdirSync(folderPath)) {
        if (!file.endsWith(".vue")) continue;
        const baseName = file.slice(0, -".vue".length);
        addComponent({
          name: `ShwfedUi${baseName}`,
          filePath: `${folderPath}/${file}`
        });
      }
    }
    addImports([
      // Type-only auto-import: hosts binding `<ShwfedConfig v-model:config>`
      // get `PageConfigValue` globally without reaching into `runtime/`.
      { name: "PageConfigValue", from: resolver.resolve("./runtime/components/config/schema"), type: true },
      // `provideCELContext` lets the host app inject CEL variables (e.g. an
      // auth token) into the config-driven components.
      { name: "provideCELContext", from: resolver.resolve("./runtime/utils/cel-context") },
      // `md` lets the host app author Markdown text (with shared trimming /
      // de-indenting) for config-driven components; `Markdown` is its type.
      { name: "md", from: resolver.resolve("./runtime/share/markdown") },
      { name: "Markdown", from: resolver.resolve("./runtime/share/markdown"), type: true }
    ]);
  }
});

export { module$1 as default };
