"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _tslib = require("tslib");

var React = _interopRequireWildcard(require("react"));

var _mobxReact = require("mobx-react");

var _checkbox = _interopRequireDefault(require("../../../lib/checkbox"));

var _radio = _interopRequireDefault(require("../../../lib/radio"));

var _excluded = ["type", "rowIndex"];

var SelectionBox = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(SelectionBox, _React$Component);

  var _super = (0, _createSuper2["default"])(SelectionBox);

  function SelectionBox(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, SelectionBox);
    _this = _super.call(this, props);
    _this.state = {
      checked: _this.getCheckState(props)
    };
    return _this;
  } // eslint-disable-next-line class-methods-use-this


  (0, _createClass2["default"])(SelectionBox, [{
    key: "getCheckState",
    value: function getCheckState(props) {
      var defaultSelection = props.defaultSelection,
          rowIndex = props.rowIndex,
          store = props.store;
      var selectionDirty = store.selectionDirty,
          selectedRowKeys = store.selectedRowKeys;
      var checked = false;

      if (selectionDirty) {
        checked = selectedRowKeys.indexOf(rowIndex) >= 0;
      } else {
        checked = selectedRowKeys.indexOf(rowIndex) >= 0 || defaultSelection.indexOf(rowIndex) >= 0;
      }

      return checked;
    }
  }, {
    key: "render",
    value: function render() {
      var checked = this.getCheckState(this.props);
      var _this$props = this.props,
          type = _this$props.type,
          rowIndex = _this$props.rowIndex,
          rest = (0, _objectWithoutProperties2["default"])(_this$props, _excluded);

      if (type === 'radio') {
        return /*#__PURE__*/React.createElement(_radio["default"], (0, _extends2["default"])({
          checked: checked,
          value: rowIndex
        }, rest));
      }

      return /*#__PURE__*/React.createElement(_checkbox["default"], (0, _extends2["default"])({
        checked: checked
      }, rest));
    }
  }]);
  return SelectionBox;
}(React.Component);

SelectionBox = (0, _tslib.__decorate)([_mobxReact.observer], SelectionBox);
var _default = SelectionBox;
exports["default"] = _default;
//# sourceMappingURL=SelectionBox.js.map
