import { createContext } from 'react';
import defaultConfig from '../../../uikit.config.json';
export const ConfigContext = /*#__PURE__*/createContext({
  preferred_theme: 'default',
  globalTheme: {},
  excludes: [],
  getConfig: () => ({}),
  getUiKitConfig: () => ({}),
  getDefaultConfig: () => ({})
});
export const ConfigProvider = ({
  children,
  configs
}) => {
  const getConfig = id => {
    const value = configs.customizations[id];
    return value;
  };
  const getDefaultConfig = id => {
    const value = defaultConfig.customizations[id];
    return value;
  };
  const getPossibleIDs = ({
    page,
    component,
    element
  }) => {
    if (!component && !element) return [`${page}/*/*`];
    if (!element) return [`${page}/${component}/*`, `*/${component}/*`];
    return [`${page}/${component}/${element}`, `${page}/*/${element}`, `*/${component}/${element}`, `*/*/${element}`];
  };
  const getCorrectConfig = possibleIDs => {
    const correctId = possibleIDs.find(id => !!configs.customizations[id]);
    const correctConfig = configs.customizations[correctId];
    if (correctConfig) return correctConfig;
    return undefined;
  };
  const getUiKitConfig = ({
    page,
    component,
    element
  }) => {
    const possibleIDs = getPossibleIDs({
      page,
      component,
      element
    });
    const correctConfig = getCorrectConfig(possibleIDs);
    return correctConfig;
  };
  const globalTheme = configs.theme;
  const excludes = configs.excludes;
  const preferred_theme = configs.preferred_theme;
  return /*#__PURE__*/React.createElement(ConfigContext.Provider, {
    value: {
      preferred_theme,
      globalTheme,
      excludes,
      getConfig,
      getUiKitConfig,
      getDefaultConfig
    }
  }, children);
};
//# sourceMappingURL=ConfigProvider.js.map