"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _App = _interopRequireDefault(require("~/App"));

var _lodash = _interopRequireDefault(require("lodash"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireWildcard(require("react"));

var _reactHotLoader = require("react-hot-loader");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class Reactant extends _react.Component {
  constructor(props) {
    var _class, _temp;

    super();

    const childContextTypes = _lodash.default.reduce(props.context, (context, value, key) => {
      let type = typeof value;
      if (_lodash.default.isArray(value)) type = 'array';
      if (type === 'function') type = 'func';
      context[key] = _propTypes.default[type].isRequired;
      return context;
    }, {});

    const ReactantContext = (_temp = _class = class ReactantContext extends _react.Component {
      getChildContext() {
        return _lodash.default.reduce(childContextTypes, (context, value, key) => {
          context[key] = props.context[key];
          return context;
        }, {});
      }

      render() {
        return _react.default.createElement(_App.default, this.props);
      }

    }, _class.childContextTypes = childContextTypes, _temp);
    this.ReactantContext = ReactantContext;
  }

  render() {
    const ReactantContext = this.ReactantContext;
    return _react.default.createElement(ReactantContext, this.props);
  }

}

Reactant.propTypes = {
  context: _propTypes.default.object.isRequired
};

var _default = (0, _reactHotLoader.hot)(module)(Reactant);

exports.default = _default;