import _defineProperty from"babel-runtime/helpers/defineProperty";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";import*as React from"react";import*as ReactDOM from"react-dom";import classNames from"classnames";import Animate from"rc-animate";import PureRenderMixin from"rc-util/es/PureRenderMixin";import Checkbox from"../checkbox";import Search from"./search";import Item from"./item";import triggerEvent from"../_util/triggerEvent";function noop(){}function isRenderResultPlainObject(e){return e&&!React.isValidElement(e)&&"[object Object]"===Object.prototype.toString.call(e)}var TransferList=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.handleSelect=function(e){var t=r.props.checkedKeys.some(function(t){return t===e.key});r.props.handleSelect(e,!t)},r.handleFilter=function(e){r.props.handleFilter(e),e.target.value&&(r.triggerScrollTimer=window.setTimeout(function(){var e=ReactDOM.findDOMNode(r).querySelectorAll(".dt-transfer-list-content")[0];e&&triggerEvent(e,"scroll")},0))},r.handleClear=function(){r.props.handleClear()},r.matchFilter=function(e,t){var n=r.props,a=n.filter,o=n.filterOption;return o?o(a,t):e.indexOf(a)>=0},r.renderItem=function(e){var t=r.props.render,n=(void 0===t?noop:t)(e),a=isRenderResultPlainObject(n);return{renderedText:a?n.value:n,renderedEl:a?n.label:n}},r.state={mounted:!1},r}return _inherits(t,e),_createClass(t,[{key:"componentDidMount",value:function(){var e=this;this.timer=window.setTimeout(function(){e.setState({mounted:!0})},0)}},{key:"componentWillUnmount",value:function(){clearTimeout(this.timer),clearTimeout(this.triggerScrollTimer)}},{key:"shouldComponentUpdate",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return PureRenderMixin.shouldComponentUpdate.apply(this,t)}},{key:"getCheckStatus",value:function(e){var t=this.props.checkedKeys;return 0===t.length?"none":e.every(function(e){return t.indexOf(e.key)>=0})?"all":"part"}},{key:"render",value:function(){var e=this,t=this.props,r=t.prefixCls,n=t.dataSource,a=t.titleText,o=t.checkedKeys,l=t.lazy,i=t.body,s=void 0===i?noop:i,c=t.footer,m=void 0===c?noop:c,d=t.showSearch,p=t.style,u=t.filter,h=t.searchPlaceholder,f=t.notFoundContent,v=t.itemUnit,y=t.itemsUnit,b=t.onScroll,C=m(_extends({},this.props)),R=s(_extends({},this.props)),g=classNames(r,_defineProperty({},r+"-with-footer",!!C)),k=[],x=[],E=n.map(function(t){var n=e.renderItem(t),a=n.renderedText,i=n.renderedEl;if(u&&u.trim()&&!e.matchFilter(a,t))return null;x.push(t),t.disabled||k.push(t);var s=o.indexOf(t.key)>=0;return React.createElement(Item,{key:t.key,item:t,lazy:l,renderedText:a,renderedEl:i,checked:s,prefixCls:r,onClick:e.handleSelect})}),S=n.length>1?y:v,_=d?React.createElement("div",{className:r+"-body-search-wrapper"},React.createElement(Search,{prefixCls:r+"-search",onChange:this.handleFilter,handleClear:this.handleClear,placeholder:h,value:u})):null,T=R||React.createElement("div",{className:d?r+"-body "+r+"-body-with-search":r+"-body"},_,React.createElement(Animate,{component:"ul",componentProps:{onScroll:b},className:r+"-content",transitionName:this.state.mounted?r+"-content-item-highlight":"",transitionLeave:!1},E),React.createElement("div",{className:r+"-body-not-found"},f)),N=C?React.createElement("div",{className:r+"-footer"},C):null,O=this.getCheckStatus(k),P="all"===O,w=React.createElement(Checkbox,{checked:P,indeterminate:"part"===O,onChange:function(){return e.props.handleSelectAll(k,P)}});return React.createElement("div",{className:g,style:p},React.createElement("div",{className:r+"-header"},w,React.createElement("span",{className:r+"-header-selected"},React.createElement("span",null,(o.length>0?o.length+"/":"")+x.length," ",S),React.createElement("span",{className:r+"-header-title"},a))),T,N)}}]),t}(React.Component);export default TransferList;TransferList.defaultProps={dataSource:[],titleText:"",showSearch:!1,render:noop,lazy:{}};