const { componentsThemeManager } = require('./helpers/themeHelpers');

const components = import.meta.webpackContext('./components', {
  recursive: true,
  regExp: /index.js$/,
  mode: 'lazy',
  chunkName: '[request]',
  prefetch: true,
});

// all components must be in a folder with the component name, and have an index.js file
// e.g. ./descope-button/index.js
module.exports = components.keys().reduce((acc, key) => {
  // eslint-disable-next-line no-useless-escape
  const componentName = key.replace(/.*?([^\/]+)\/index\.js$/, '$1');

  if (componentName.endsWith('-internal')) {
    return acc;
  }

  acc[componentName] = () => components(key);

  return acc;
}, {});

module.exports.componentsThemeManager = componentsThemeManager;

/* INJECT_COMPONENTS */
