import _extends from "@babel/runtime/helpers/extends";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
export var passedWithSelectedIdsPropsTypes = {
  selectedIds: PropTypes.object.isRequired,
  onSelectId: PropTypes.func.isRequired,
  onSelectIds: PropTypes.func.isRequired,
  onClearSelectedIds: PropTypes.func.isRequired,
  onUpdateSelectedIds: PropTypes.func.isRequired
};
export var withSelectedIds = function withSelectedIds(Component) {
  var _class, _temp;

  return _temp = _class =
  /*#__PURE__*/
  function (_React$PureComponent) {
    _inheritsLoose(_class, _React$PureComponent);

    function _class() {
      var _this;

      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;

      _defineProperty(_assertThisInitialized(_this), "state", {
        selectedIds: {}
      });

      _defineProperty(_assertThisInitialized(_this), "handleClearSelectedIds", function () {
        _this.setState({
          selectedIds: {}
        });
      });

      _defineProperty(_assertThisInitialized(_this), "handleUpdateSelectedIds", function (selectedIds) {
        _this.setState({
          selectedIds: selectedIds
        });
      });

      _defineProperty(_assertThisInitialized(_this), "handleSelectId", function (id, isSelected) {
        var selectedIds = Object.assign({}, _this.state.selectedIds);

        if (isSelected) {
          selectedIds[id] = true;
        } else {
          delete selectedIds[id];
        }

        _this.setState({
          selectedIds: selectedIds
        });
      });

      _defineProperty(_assertThisInitialized(_this), "handleSelectIds", function (ids, isSelected) {
        if (isSelected === void 0) {
          isSelected = true;
        }

        var selectedIds = Object.assign({}, _this.state.selectedIds);
        ids.forEach(function (id) {
          if (isSelected) {
            selectedIds[id] = true;
          } else {
            delete selectedIds[id];
          }
        });

        _this.setState({
          selectedIds: selectedIds
        });
      });

      return _this;
    }

    var _proto = _class.prototype;

    _proto.getSelectedIdsProps = function getSelectedIdsProps() {
      return {
        selectedIds: this.state.selectedIds,
        onSelectId: this.handleSelectId,
        onSelectIds: this.handleSelectIds,
        onClearSelectedIds: this.handleClearSelectedIds,
        onUpdateSelectedIds: this.handleUpdateSelectedIds
      };
    };

    _proto.render = function render() {
      return React.createElement(Component, _extends({}, this.getSelectedIdsProps(), this.props));
    };

    return _class;
  }(React.PureComponent), _defineProperty(_class, "displayName", "WithSelectedIds(" + (Component.displayName || Component.name || 'Component') + ")"), _temp;
};