import _extends from"babel-runtime/helpers/extends";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";var __rest=this&&this.__rest||function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)t.indexOf(o[s])<0&&(r[o[s]]=e[o[s]])}return r};import*as React from"react";import Checkbox from"../checkbox";import Radio from"../radio";var SelectionBox=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.state={checked:r.getCheckState(e)},r}return _inherits(t,e),_createClass(t,[{key:"componentDidMount",value:function(){this.subscribe()}},{key:"componentWillUnmount",value:function(){this.unsubscribe&&this.unsubscribe()}},{key:"subscribe",value:function(){var e=this,t=this.props.store;this.unsubscribe=t.subscribe(function(){var t=e.getCheckState(e.props);e.setState({checked:t})})}},{key:"getCheckState",value:function(e){var t=e.store,r=e.defaultSelection,o=e.rowIndex;return t.getState().selectionDirty?t.getState().selectedRowKeys.indexOf(o)>=0:t.getState().selectedRowKeys.indexOf(o)>=0||r.indexOf(o)>=0}},{key:"render",value:function(){var e=this.props,t=e.type,r=e.rowIndex,o=__rest(e,["type","rowIndex"]),s=this.state.checked;return"radio"===t?React.createElement(Radio,_extends({checked:s,value:r},o)):React.createElement(Checkbox,_extends({checked:s},o))}}]),t}(React.Component);export default SelectionBox;