import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import { PureComponent } from 'react';
export var WithProviders = /*#__PURE__*/function (_PureComponent) {
  _inherits(WithProviders, _PureComponent);
  var _super = _createSuper(WithProviders);
  function WithProviders(props) {
    var _this;
    _classCallCheck(this, WithProviders);
    _this = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this), "handleProvider", function (name, provider) {
      _this.setState(function (_ref) {
        var providers = _ref.providers;
        return {
          providers: _objectSpread(_objectSpread({}, providers), {}, _defineProperty({}, name, provider))
        };
      });
    });
    var _providers = {};
    _this.props.providers.forEach(function (name) {
      _providers[name] = undefined;
    });
    _this.state = {
      providers: _providers
    };
    return _this;
  }
  _createClass(WithProviders, [{
    key: "UNSAFE_componentWillMount",
    value: function UNSAFE_componentWillMount() {
      var _this2 = this;
      var _this$props = this.props,
        providers = _this$props.providers,
        providerFactory = _this$props.providerFactory;
      providers.forEach(function (name) {
        providerFactory.subscribe(name, _this2.handleProvider);
      });
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      var _this3 = this;
      var _this$props2 = this.props,
        providers = _this$props2.providers,
        providerFactory = _this$props2.providerFactory;
      providers.forEach(function (name) {
        providerFactory.unsubscribe(name, _this3.handleProvider);
      });
    }
  }, {
    key: "render",
    value: function render() {
      var state = this.state,
        props = this.props;
      var renderNode = props.renderNode;
      return renderNode(state.providers);
    }
  }]);
  return WithProviders;
}(PureComponent);
_defineProperty(WithProviders, "displayName", 'WithProviders');