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

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

// 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) => {
  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 */
