"use strict";

exports.__esModule = true;
exports.default = exports.GetTranslateFromContext = exports.GetSkinFromContext = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _defaultsDeep2 = _interopRequireDefault(require("lodash/fp/defaultsDeep"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _proptypes = require("../../util/proptypes");
var _webContext = _interopRequireWildcard(require("./web-context"));
exports.WebContext = _webContext.default;
exports.useWebContext = _webContext.useWebContext;
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const DEFAULT_SKIN = {
  common: {
    good: '#24b694',
    bad: '#ed1c24',
    primary: '#00B0FF',
    life: '#ed1c24',
    brand: '#00B0FF',
    primaryAdd1: '#B3E5FC',
    primaryAdd2: '#0091EA',
    primaryAdd3: '#0277BD',
    primaryAdd4: '#015798',
    xtraLightGrey: '#FAFAFA',
    light: '#ECEFF1',
    medium: '#90A4AE',
    dark: '#546E7A',
    grey: '#607D8B',
    orangeAdd: '#FF7043',
    orange: '#FFA000',
    positive: '#3EC483',
    lightGreen: '#66BB6A',
    negative: '#F73F52',
    battle: '#FFE100',
    white: '#FFFFFF',
    black: '#14171A'
  }
};
const mergeSkin = (skin = {}) => (0, _defaultsDeep2.default)(DEFAULT_SKIN, skin);
const historyShape = _propTypes.default.shape({
  createHref: _propTypes.default.func,
  push: _propTypes.default.func
});
const skinShape = _propTypes.default.shape({
  common: _propTypes.default.objectOf(_proptypes.ColorPropType),
  images: _propTypes.default.shape({
    'logo-mobile': _proptypes.SrcPropType,
    logo: _proptypes.SrcPropType,
    'logo-email': _proptypes.SrcPropType,
    login: _proptypes.SrcPropType
  }),
  icons: _propTypes.default.objectOf(_proptypes.HexPropType),
  mod: _propTypes.default.objectOf(_proptypes.ColorPropType),
  courses: _propTypes.default.arrayOf(_proptypes.ColorPropType),
  texts: _propTypes.default.objectOf(_proptypes.ColorPropType)
});
const translateShape = _propTypes.default.func;
class Provider extends _react.default.Component {
  static childContextTypes = {
    history: historyShape,
    skin: skinShape,
    translate: translateShape,
    Vimeo: _propTypes.default.object
  };
  static getDerivedStateFromProps(props) {
    const {
      history,
      skin,
      translate
    } = props;
    return {
      history,
      skin: mergeSkin(skin),
      translate
    };
  }
  constructor(props, context) {
    super(props, context);
    const {
      history,
      skin,
      translate,
      Vimeo
    } = props;
    // eslint-disable-next-line react/no-unused-state
    this.state = {
      history,
      skin: mergeSkin(skin),
      translate,
      Vimeo
    };
  }
  getChildContext() {
    return this.state;
  }
  render() {
    const {
      children
    } = this.props;
    return _react.default.Children.only(children);
  }
}
Provider.propTypes = process.env.NODE_ENV !== "production" ? {
  history: historyShape,
  skin: skinShape,
  translate: translateShape,
  children: _propTypes.default.node.isRequired,
  Vimeo: _propTypes.default.shape({
    common: _propTypes.default.func
  })
} : {};
const GetSkinFromContext = legacyContext => {
  const context = (0, _webContext.useWebContext)();
  const legacySkin = (0, _get2.default)('skin', legacyContext);
  const skin = (0, _getOr2.default)(legacySkin, 'skin', context);
  return skin;
};
exports.GetSkinFromContext = GetSkinFromContext;
const GetTranslateFromContext = legacyContext => {
  const context = (0, _webContext.useWebContext)();
  const legacyTranslate = (0, _get2.default)('translate', legacyContext);
  const translate = (0, _getOr2.default)(legacyTranslate, 'translate', context);
  return translate;
};
exports.GetTranslateFromContext = GetTranslateFromContext;
var _default = exports.default = Provider;
//# sourceMappingURL=index.js.map