"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_checkbox=require("../checkbox"),_checkbox2=_interopRequireDefault(_checkbox),_dropdown=require("../dropdown"),_dropdown2=_interopRequireDefault(_dropdown),_menu=require("../menu"),_menu2=_interopRequireDefault(_menu),_icon=require("../icon"),_icon2=_interopRequireDefault(_icon),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var SelectionCheckboxAll=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var r=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.handleSelectAllChagne=function(e){var t=e.target.checked;r.props.onSelect(t?"all":"removeAll",0,null)},r.defaultSelections=e.hideDefaultSelections?[]:[{key:"all",text:e.locale.selectAll,onSelect:function(){}},{key:"invert",text:e.locale.selectInvert,onSelect:function(){}}],r.state={checked:r.getCheckState(e),indeterminate:r.getIndeterminateState(e)},r}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"componentDidMount",value:function(){this.subscribe()}},{key:"componentWillReceiveProps",value:function(e){this.setCheckState(e)}},{key:"componentWillUnmount",value:function(){this.unsubscribe&&this.unsubscribe()}},{key:"subscribe",value:function(){var e=this,t=this.props.store;this.unsubscribe=t.subscribe(function(){e.setCheckState(e.props)})}},{key:"checkSelection",value:function(e,t,r){var n=this.props,i=n.store,c=n.getCheckboxPropsByItem,l=n.getRecordKey;return("every"===t||"some"===t)&&(r?e[t](function(e,t){return c(e,t).defaultChecked}):e[t](function(e,t){return 0<=i.getState().selectedRowKeys.indexOf(l(e,t))}))}},{key:"setCheckState",value:function(e){var t=this.getCheckState(e),r=this.getIndeterminateState(e);t!==this.state.checked&&this.setState({checked:t}),r!==this.state.indeterminate&&this.setState({indeterminate:r})}},{key:"getCheckState",value:function(e){var t=e.store,r=e.data;return!!r.length&&(t.getState().selectionDirty?this.checkSelection(r,"every",!1):this.checkSelection(r,"every",!1)||this.checkSelection(r,"every",!0))}},{key:"getIndeterminateState",value:function(e){var t=e.store,r=e.data;return!!r.length&&(t.getState().selectionDirty?this.checkSelection(r,"some",!1)&&!this.checkSelection(r,"every",!1):this.checkSelection(r,"some",!1)&&!this.checkSelection(r,"every",!1)||this.checkSelection(r,"some",!0)&&!this.checkSelection(r,"every",!0))}},{key:"renderMenus",value:function(e){var r=this;return e.map(function(e,t){return React.createElement(_menu2.default.Item,{key:e.key||t},React.createElement("div",{onClick:function(){r.props.onSelect(e.key,t,e.onSelect)}},e.text))})}},{key:"render",value:function(){var e=this.props,t=e.disabled,r=e.prefixCls,n=e.selections,i=e.getPopupContainer,c=this.state,l=c.checked,a=c.indeterminate,s=r+"-selection",o=null;if(n){var u=Array.isArray(n)?this.defaultSelections.concat(n):this.defaultSelections,h=React.createElement(_menu2.default,{className:s+"-menu",selectedKeys:[]},this.renderMenus(u));o=0<u.length?React.createElement(_dropdown2.default,{overlay:h,getPopupContainer:i},React.createElement("div",{className:s+"-down"},React.createElement(_icon2.default,{type:"down"}))):null}return React.createElement("div",{className:s},React.createElement(_checkbox2.default,{className:(0,_classnames2.default)((0,_defineProperty3.default)({},s+"-select-all-custom",o)),checked:l,indeterminate:a,disabled:t,onChange:this.handleSelectAllChagne}),o)}}]),t}(React.Component);exports.default=SelectionCheckboxAll,module.exports=exports.default;