'use strict';

var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };

var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

/**
 * Higher-order component form of connectToStores
 */

var _React = require('react');

var React = _interopRequire(_React);

var _instanceMethods$staticProperties = require('./reactComponentMethods');

var _assign = require('object-assign');

var assign = _interopRequire(_assign);

module.exports = function (BaseComponent, stores, stateGetter) {
  var ConnectedComponent = (function (_React$Component) {
    var _class = function ConnectedComponent(props, context) {
      _classCallCheck(this, _class);

      _React$Component.call(this, props, context);

      this.initialize();

      this.state = this.connectToStores(stores, stateGetter);
    };

    _inherits(_class, _React$Component);

    _class.prototype.render = function render() {
      return React.createElement(BaseComponent, _extends({}, this.state, this.props));
    };

    return _class;
  })(React.Component);

  assign(ConnectedComponent.prototype, _instanceMethods$staticProperties.instanceMethods);

  assign(ConnectedComponent, _instanceMethods$staticProperties.staticProperties);

  return ConnectedComponent;
};