/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/typedef, jsdoc/require-jsdoc, jsdoc/require-param-type, jsdoc/require-returns-type, jsdoc/require-returns, jsdoc/tag-lines, spellcheck/spell-checker */
/**
 * VegaModuleLoader provides a lazy loading mechanism for Vega's public API modules.
 *
 * Instead of eagerly injecting all modules into `globalThis` at startup (as `vega.esm.js`
 * does for backward compatibility), consumers can use the lean entry (`vega-lean.esm.js`)
 * which registers only `VegaModuleLoader` on `globalThis`, then load modules on demand:
 *
 * ```js
 * const VegaThemeManager = await VegaModuleLoader.load('VegaThemeManager');
 * ```
 *
 * This results in significantly smaller initial bundle sizes for vanilla JS consumers
 * who only need a subset of Vega's public API modules.
 *
 * VegaModuleLoader is available in ALL entry points (full browser, lean browser,
 * and framework loaders), so it can be used alongside eager injection too.
 *
 * ⚠ AUTO-GENERATED — do not edit manually.
 *   Source of truth: src/global/scripts/vanilla-js-global-setup.ts
 *   Generator:       scripts/generate-vega-module-loader.js
 *   Re-generate:     yarn generate:module-loader
 */
/**
 * Registry mapping module names to their dynamic import factories.
 * Each factory returns a Promise that resolves to the module's exported value.
 * The dynamic `import()` calls enable Rollup code-splitting — modules are
 * only loaded when `VegaModuleLoader.load()` is called.
 */
const MODULE_REGISTRY = {
  VegaLoader: () => import('../../helpers/loading-indicator/vega-loader-controller').then(m => m.VegaLoader),
  VegaNotify: () => import('../../helpers/notify/vega-notify-controller').then(m => m.VegaNotify),
  VegaThemeManager: () => import('../../helpers/theme/theme-manager').then(m => m.VegaThemeManager),
  setVegaLogLevel: () => import('../../utils/log').then(m => m.setVegaLogLevel),
  VegaDialog: () => import('../../helpers/dialog/vega-dialog-controller').then(m => m.VegaDialog),
  VegaEventManager: () => import('../../helpers/event-manager/vega-event-manager').then(m => m.default),
  VegaIconManager: () => import('../../helpers/icon/icon-manager').then(m => m.VegaIconManager),
  VegaZIndexManager: () => import('../../helpers/zindex/vega-z-index-manager').then(m => m.default),
  ValidCreditCardNumberRule: () => import('../../helpers/validator/rules/valid-credit-card-number-rule').then(m => m.ValidCreditCardNumberRule),
  waitForVega: () => import('../../helpers/common/wait-for-vega-handler').then(m => m.waitForVega),
  VegaSkeletonLoader: () => import('../../helpers/skeleton-loader/vega-skeleton-loader-controller').then(m => m.VegaSkeletonLoader),
  VegaTranslation: () => import('../../helpers/translation/translation').then(m => m.VegaTranslation),
  VegaTranslationResourceEN: () => import('../../helpers/translation/locales/en').then(m => m.default),
  VegaRTEContent: () => import('../../components/vega-rich-text-editor/dto/content-state').then(m => m.VegaRTEContent),
  VegaRTETokenExtension: () => import('../../components/vega-rich-text-editor/extensions/tokens/token-extension').then(m => m.VegaRTETokenExtension),
  VegaRTELanguageExtension: () => import('../../components/vega-rich-text-editor/extensions/languages/language-extension').then(m => m.VegaRTELanguageExtension),
  VegaRTEPresetToolbarItems: () => import('../../components/vega-rich-text-editor/constants/constant').then(m => m.VegaRTEPresetToolbarItems),
  VegaRTEFunctionExtension: () => import('../../components/vega-rich-text-editor/extensions/functions/function-extension').then(m => m.VegaRTEFunctionExtension),
  VegaRTETableExtension: () => import('../../components/vega-rich-text-editor/extensions/table/table-extension').then(m => m.VegaRTETableExtension),
  setVegaNonce: () => import('../../helpers/csp/vega-nonce-manager').then(m => m.setVegaNonce),
  VegaValidationRules: () => import('../../helpers/validator/public-rules'),
  FeatureFlag: () => import('../../helpers/feature-control/feature-flag-controller').then(m => m.FeatureFlag),
};
const moduleCache = new Map();
export const VegaModuleLoader = {
  /**
   * Lazily load a Vega module by name.
   *
   * @param moduleName - The name of the module to load (e.g. 'VegaThemeManager')
   * @returns A Promise that resolves to the module's value
   *
   * @example
   * ```js
   * const VegaThemeManager = await VegaModuleLoader.load('VegaThemeManager');
   * VegaThemeManager.applyBranding('gp');
   * ```
   */
  async load(moduleName) {
    var _a;
    // Check cache first
    if (moduleCache.has(moduleName)) {
      return moduleCache.get(moduleName);
    }
    // Check if already available on globalThis (backward compat with full entry).
    // Guard against the browser's "named access on the Window object" feature,
    // which auto-exposes DOM elements with an `id` as `window[id]` properties.
    // E.g. `<vega-button id="VegaThemeManager">` would make
    // `window.VegaThemeManager` return the DOM element instead of the module.
    // Uses nodeType === 1 instead of instanceof Element for cross-environment
    // compatibility (Stencil mock-doc, jsdom, browser).
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    if (globalThis[moduleName] !== undefined && ((_a = globalThis[moduleName]) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1) {
      moduleCache.set(moduleName, globalThis[moduleName]);
      return globalThis[moduleName];
    }
    const factory = MODULE_REGISTRY[moduleName];
    if (!factory) {
      throw new Error(`VegaModuleLoader: Unknown module "${moduleName}". ` +
        `Available modules: ${Object.keys(MODULE_REGISTRY).join(', ')}`);
    }
    const module = await factory();
    moduleCache.set(moduleName, module);
    return module;
  },
  /**
   * Returns the list of all available module names that can be loaded.
   */
  getAvailableModules() {
    return Object.keys(MODULE_REGISTRY);
  },
};
