import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir, addPlugin, addTypeTemplate } from '@nuxt/kit';

const module$1 = defineNuxtModule({
  meta: {
    name: "@ramathibodi/nuxt-commons",
    configKey: "nuxt-commons",
    compatibility: {
      nuxt: "^4.3.1"
    }
  },
  // Default configuration options of the Nuxt module
  defaults: {
    // default empty, will use fallback if not provided
  },
  async setup(_options, _nuxt) {
    const resolver = createResolver(import.meta.url);
    addComponentsDir({
      path: resolver.resolve("runtime/components"),
      pathPrefix: true,
      global: true
    });
    addImportsDir(resolver.resolve("runtime/composables/**"));
    addImportsDir(resolver.resolve("runtime/utils/**"));
    addPlugin({
      src: resolver.resolve("runtime/plugins/permission")
    });
    addPlugin({
      src: resolver.resolve("runtime/plugins/dialogManager"),
      mode: "client"
    });
    addPlugin({
      src: resolver.resolve("runtime/plugins/clientConfig"),
      mode: "client"
    });
    addPlugin({
      src: resolver.resolve("runtime/plugins/default"),
      mode: "client"
    });
    const typeFiles = ["modules", "alert", "menu", "graphqlOperation", "formDialog", "dialogManager", "permission", "clientConfig", "bridge"];
    for (const file of typeFiles) {
      addTypeTemplate({
        src: resolver.resolve(`runtime/types/${file}.d.ts`),
        filename: `types/${file}.d.ts`
      });
    }
    const runtimeConfig = _nuxt.options.runtimeConfig.public["nuxt-commons"] || {};
    _nuxt.options.runtimeConfig.public["nuxt-commons"] = {
      ...runtimeConfig,
      ..._options
    };
    const publicConfig = _nuxt.options.runtimeConfig.public;
    if (publicConfig.IDEMPOTENCY_HEADER == null) {
      publicConfig.IDEMPOTENCY_HEADER = "Idempotency-Key";
    }
    if (publicConfig.IDEMPOTENCY_ENABLED == null) {
      publicConfig.IDEMPOTENCY_ENABLED = true;
    }
    _nuxt.options.vite.optimizeDeps ||= {};
    _nuxt.options.vite.optimizeDeps.include ||= [];
    _nuxt.options.vite.optimizeDeps.include.push("painterro");
    _nuxt.options.vite.optimizeDeps.include.push("print-js");
    _nuxt.options.vite.optimizeDeps.include.push("gql-query-builder");
    _nuxt.options.vite.optimizeDeps.include.push("exif-rotate-js");
    _nuxt.options.vite.optimizeDeps.include.push("localstorage-slim");
  }
});

export { module$1 as default };
