'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _class, _temp;

var _App = require('~/App');

var _App2 = _interopRequireDefault(_App);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

let Reactant = (_temp = _class = class Reactant extends _react.Component {

  constructor(props) {
    var _class2, _temp2;

    super();
    const childContextTypes = _lodash2.default.reduce(props.context, (context, value, key) => {
      let type = typeof value;
      if (_lodash2.default.isArray(value)) type = 'array';
      if (type === 'function') type = 'func';
      context[key] = _propTypes2.default[type].isRequired;
      return context;
    }, {});
    const ReactantContext = (_temp2 = _class2 = class ReactantContext extends _react.Component {

      getChildContext() {
        return _lodash2.default.reduce(childContextTypes, (context, value, key) => {
          context[key] = props.context[key];
          return context;
        }, {});
      }

      render() {
        return _react2.default.createElement(_App2.default, this.props);
      }
    }, _class2.childContextTypes = childContextTypes, _temp2);
    this.ReactantContext = ReactantContext;
  }

  render() {
    const ReactantContext = this.ReactantContext;

    return _react2.default.createElement(ReactantContext, this.props);
  }
}, _class.propTypes = {
  context: _propTypes2.default.object.isRequired
}, _temp);
exports.default = (0, _reactHotLoader.hot)(module)(Reactant);