text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var React = _interopRequireWildcard(require("react"));
  
  var _classnames = _interopRequireDefault(require("classnames"));
  
  var _reactLifecyclesCompat = require("react-lifecycles-compat");
  
  var _checkbox = _interopRequireDefault(require("../checkbox"));
  
  var _dropdown = _interopRequireDefault(require("../dropdown"));
  
  var _menu = _interopRequireDefault(require("../menu"));
  
  var _icon = _interopRequireDefault(require("../icon"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  function _extends() { _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; }; return _extends.apply(this, arguments); }
  
  function checkSelection(_ref) {
    var store = _ref.store,
        getCheckboxPropsByItem = _ref.getCheckboxPropsByItem,
        getRecordKey = _ref.getRecordKey,
        data = _ref.data,
        type = _ref.type,
        byDefaultChecked = _ref.byDefaultChecked;
    return byDefaultChecked ? data[type](function (item, i) {
      return getCheckboxPropsByItem(item, i).defaultChecked;
    }) : data[type](function (item, i) {
      return store.getState().selectedRowKeys.indexOf(getRecordKey(item, i)) >= 0;
    });
  }
  
  function getIndeterminateState(props) {
    var store = props.store,
        data = props.data;
  
    if (!data.length) {
      return false;
    }
  
    var someCheckedNotByDefaultChecked = checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'some',
      byDefaultChecked: false
    })) && !checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'every',
      byDefaultChecked: false
    }));
    var someCheckedByDefaultChecked = checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'some',
      byDefaultChecked: true
    })) && !checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'every',
      byDefaultChecked: true
    }));
  
    if (store.getState().selectionDirty) {
      return someCheckedNotByDefaultChecked;
    }
  
    return someCheckedNotByDefaultChecked || someCheckedByDefaultChecked;
  }
  
  function getCheckState(props) {
    var store = props.store,
        data = props.data;
  
    if (!data.length) {
      return false;
    }
  
    if (store.getState().selectionDirty) {
      return checkSelection(_extends(_extends({}, props), {
        data: data,
        type: 'every',
        byDefaultChecked: false
      }));
    }
  
    return checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'every',
      byDefaultChecked: false
    })) || checkSelection(_extends(_extends({}, props), {
      data: data,
      type: 'every',
      byDefaultChecked: true
    }));
  }
  
  var SelectionCheckboxAll =
  /*#__PURE__*/
  function (_React$Component) {
    _inherits(SelectionCheckboxAll, _React$Component);
  
    function SelectionCheckboxAll(props) {
      var _this;
  
      _classCallCheck(this, SelectionCheckboxAll);
  
      _this = _possibleConstructorReturn(this, _getPrototypeOf(SelectionCheckboxAll).call(this, props));
      _this.state = {
        checked: false,
        indeterminate: false
      };
  
      _this.handleSelectAllChange = function (e) {
        var checked = e.target.checked;
  
        _this.props.onSelect(checked ? 'all' : 'removeAll', 0, null);
      };
  
      _this.defaultSelections = props.hideDefaultSelections ? [] : [{
        key: 'all',
        text: props.locale.selectAll
      }, {
        key: 'invert',
        text: props.locale.selectInvert
      }];
      return _this;
    }
  
    _createClass(SelectionCheckboxAll, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        this.subscribe();
      }
    }, {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        if (this.unsubscribe) {
          this.unsubscribe();
        }
      }
    }, {
      key: "setCheckState",
      value: function setCheckState(props) {
        var checked = getCheckState(props);
        var indeterminate = getIndeterminateState(props);
        this.setState(function (prevState) {
          var newState = {};
  
          if (indeterminate !== prevState.indeterminate) {
            newState.indeterminate = indeterminate;
          }
  
          if (checked !== prevState.checked) {
            newState.checked = checked;
          }
  
          return newState;
        });
      }
    }, {
      key: "subscribe",
      value: function subscribe() {
        var _this2 = this;
  
        var store = this.props.store;
        this.unsubscribe = store.subscribe(function () {
          _this2.setCheckState(_this2.props);
        });
      }
    }, {
      key: "renderMenus",
      value: function renderMenus(selections) {
        var _this3 = this;
  
        return selections.map(function (selection, index) {
          return React.createElement(_menu["default"].Item, {
            key: selection.key || index
          }, React.createElement("div", {
            onClick: function onClick() {
              _this3.props.onSelect(selection.key, index, selection.onSelect);
            }
          }, selection.text));
        });
      }
    }, {
      key: "render",
      value: function render() {
        var _this$props = this.props,
            disabled = _this$props.disabled,
            prefixCls = _this$props.prefixCls,
            selections = _this$props.selections,
            getPopupContainer = _this$props.getPopupContainer;
        var _this$state = this.state,
            checked = _this$state.checked,
            indeterminate = _this$state.indeterminate;
        var selectionPrefixCls = "".concat(prefixCls, "-selection");
        var customSelections = null;
  
        if (selections) {
          var newSelections = Array.isArray(selections) ? this.defaultSelections.concat(selections) : this.defaultSelections;
          var menu = React.createElement(_menu["default"], {
            className: "".concat(selectionPrefixCls, "-menu"),
            selectedKeys: []
          }, this.renderMenus(newSelections));
          customSelections = newSelections.length > 0 ? React.createElement(_dropdown["default"], {
            overlay: menu,
            getPopupContainer: getPopupContainer
          }, React.createElement("div", {
            className: "".concat(selectionPrefixCls, "-down")
          }, React.createElement(_icon["default"], {
            type: "down"
          }))) : null;
        }
  
        return React.createElement("div", {
          className: selectionPrefixCls
        }, React.createElement(_checkbox["default"], {
          className: (0, _classnames["default"])(_defineProperty({}, "".concat(selectionPrefixCls, "-select-all-custom"), customSelections)),
          checked: checked,
          indeterminate: indeterminate,
          disabled: disabled,
          onChange: this.handleSelectAllChange
        }), customSelections);
      }
    }], [{
      key: "getDerivedStateFromProps",
      value: function getDerivedStateFromProps(props, state) {
        var checked = getCheckState(props);
        var indeterminate = getIndeterminateState(props);
        var newState = {};
  
        if (indeterminate !== state.indeterminate) {
          newState.indeterminate = indeterminate;
        }
  
        if (checked !== state.checked) {
          newState.checked = checked;
        }
  
        return newState;
      }
    }]);
  
    return SelectionCheckboxAll;
  }(React.Component);
  
  (0, _reactLifecyclesCompat.polyfill)(SelectionCheckboxAll);
  var _default = SelectionCheckboxAll;
  exports["default"] = _default;
  //# sourceMappingURL=SelectionCheckboxAll.js.map
  