import e,{Component as t}from"react";import{classNames as o,ObjectUtils as r,DomHandler as n}from"primereact/utils";import{Ripple as i}from"primereact/ripple";import{Button as s}from"primereact/button";function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var o=0;oe.length)&&(t=e.length);for(var o=0,r=new Array(t);o=0;n--){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(i===o.length-1)break;var s=o[i+1];o[i+1]=o[i],o[i]=s}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"down"}),this.movedDown=!0}}},{key:"moveBottom",value:function(e){var t=this.props.selection;if(t&&t.length){for(var o=T(this.props.list),n=t.length-1;n>=0;n--){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(i===o.length-1)break;var s=o.splice(i,1)[0];o.push(s)}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"bottom"})}}},{key:"render",value:function(){var t=!this.props.selection.length,r=o("p-picklist-buttons",this.props.className);return e.createElement("div",{className:r},e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-up",onClick:this.moveUp}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-double-up",onClick:this.moveTop}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-down",onClick:this.moveDown}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-double-down",onClick:this.moveBottom}))}}]),f}();function D(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var L=function(n){h(f,t);var i,a,u=(i=f,a=D(),function(){var e,t=d(i);if(a){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return l(this,f),(t=u.call(this,e)).moveRight=t.moveRight.bind(p(t)),t.moveAllRight=t.moveAllRight.bind(p(t)),t.moveLeft=t.moveLeft.bind(p(t)),t.moveAllLeft=t.moveAllLeft.bind(p(t)),t}return c(f,[{key:"moveRight",value:function(e){var t=this.props.sourceSelection;if(r.isNotEmpty(t)){for(var o=T(this.props.target),n=T(this.props.source),i=0;i1&&void 0!==arguments[1]?arguments[1]:1,o=e.getElementsByClassName("p-highlight");r.isNotEmpty(o)&&n.scrollInView(e,-1===t?o[0]:o[o.length-1])}},{key:"onSelectionChange",value:function(e,t,o){o?o(e):this.setState(m({},t,e.value)),r.isNotEmpty(this.state.sourceSelection)&&"targetSelection"===t?this.setState({sourceSelection:[]}):r.isNotEmpty(this.state.targetSelection)&&"sourceSelection"===t&&this.setState({targetSelection:[]})}},{key:"componentDidUpdate",value:function(){this.reorderedListElement&&(this.handleScrollPosition(this.reorderedListElement,this.reorderDirection),this.reorderedListElement=null,this.reorderDirection=null)}},{key:"render",value:function(){var t=this,r=o("p-picklist p-component",this.props.className),n=this.getSourceSelection(),i=this.getTargetSelection();return e.createElement("div",{id:this.props.id,className:r,style:this.props.style},this.props.showSourceControls&&e.createElement(N,{list:this.props.source,selection:n,onReorder:this.onSourceReorder,className:"p-picklist-source-controls",dataKey:this.props.dataKey}),e.createElement(K,{ref:function(e){return t.sourceListElement=e},list:this.props.source,selection:n,onSelectionChange:function(e){return t.onSelectionChange(e,"sourceSelection",t.props.onSourceSelectionChange)},itemTemplate:this.props.itemTemplate,header:this.props.sourceHeader,style:this.props.sourceStyle,className:"p-picklist-source-wrapper",listClassName:"p-picklist-source",metaKeySelection:this.props.metaKeySelection,tabIndex:this.props.tabIndex,dataKey:this.props.dataKey}),e.createElement(L,{onTransfer:this.onTransfer,source:this.props.source,target:this.props.target,sourceSelection:n,targetSelection:i,dataKey:this.props.dataKey}),e.createElement(K,{ref:function(e){return t.targetListElement=e},list:this.props.target,selection:i,onSelectionChange:function(e){return t.onSelectionChange(e,"targetSelection",t.props.onTargetSelectionChange)},itemTemplate:this.props.itemTemplate,header:this.props.targetHeader,style:this.props.targetStyle,className:"p-picklist-target-wrapper",listClassName:"p-picklist-target",metaKeySelection:this.props.metaKeySelection,tabIndex:this.props.tabIndex,dataKey:this.props.dataKey}),this.props.showTargetControls&&e.createElement(N,{list:this.props.target,selection:i,onReorder:this.onTargetReorder,className:"p-picklist-target-controls",dataKey:this.props.dataKey}))}}]),f}();m(A,"defaultProps",{id:null,source:null,target:null,sourceHeader:null,targetHeader:null,style:null,className:null,sourceStyle:null,targetStyle:null,sourceSelection:null,targetSelection:null,showSourceControls:!0,showTargetControls:!0,metaKeySelection:!0,tabIndex:0,dataKey:null,itemTemplate:null,onChange:null,onMoveToSource:null,onMoveAllToSource:null,onMoveToTarget:null,onMoveAllToTarget:null,onSourceSelectionChange:null,onTargetSelectionChange:null});export{A as PickList};