"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ConfigProvider = exports.ConfigContext = void 0;
var _react = require("react");
var _uikitConfig = _interopRequireDefault(require("../../../uikit.config.json"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ConfigContext = exports.ConfigContext = /*#__PURE__*/(0, _react.createContext)({
  preferred_theme: 'default',
  globalTheme: {},
  excludes: [],
  getConfig: () => ({}),
  getUiKitConfig: () => ({}),
  getDefaultConfig: () => ({})
});
const ConfigProvider = ({
  children,
  configs
}) => {
  const getConfig = id => {
    const value = configs.customizations[id];
    return value;
  };
  const getDefaultConfig = id => {
    const value = _uikitConfig.default.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);
};
exports.ConfigProvider = ConfigProvider;
//# sourceMappingURL=ConfigProvider.js.map