AUI.add("liferay-input-move-boxes",(e=>{const t=Liferay.Util,o="inputmoveboxes",r=e.Component.create({ATTRS:{leftBoxMaxItems:1/0,leftReorder:{},rightBoxMaxItems:1/0,rightReorder:{},strings:{LEFT_MOVE_DOWN:"",LEFT_MOVE_UP:"",MOVE_LEFT:"",MOVE_RIGHT:"",RIGHT_MOVE_DOWN:"",RIGHT_MOVE_UP:""}},HTML_PARSER:{leftReorder:e=>e.hasClass("left-reorder"),rightReorder:e=>e.hasClass("right-reorder")},NAME:o,prototype:{_afterMoveClick(e){const t=this,o=e.domEvent.target.ancestor(".btn",!0);if(o){const e=o.get("className");let r=t._leftBox,n=t._rightBox,l=!t.get("rightReorder");-1!==e.indexOf("move-left")&&(r=t._rightBox,n=t._leftBox,l=!t.get("leftReorder")),t._moveItem(r,n,l),t._toggleReorderToolbars()}},_afterOrderClick(e,t){const o=this,r=e.domEvent.target.ancestor(".btn",!0);if(r){let e=1;-1!==r.get("className").indexOf("reorder-up")&&(e=0),r.attr("disabled")||o._orderItem(t,e)}},_initToggleBtn(e){e&&this._toggleBtnState(e,!0)},_moveItem(t,r,n){const l=this;t=e.one(t),r=e.one(r);const i=t.get("selectedIndex");let s;if(i>=0){const e=t.all("option");s=e.item(i),e.each((e=>{e.get("selected")&&r.append(e)}))}s&&""!==s.text()&&!0===n&&l.sortBox(r),Liferay.fire(o+":moveItem",{fromBox:t,toBox:r})},_onSelectChange(e){this._toggleBtnMove(e),this._toggleBtnSort(e.currentTarget)},_onSelectFocus(e,t){this._toggleBtnMove(e),t.attr("selectedIndex","-1")},_orderItem(e,o){t.reorder(e,o),this._toggleBtnSort(e)},_renderBoxes(){const e=this,t=e.get("contentBox");e._leftBox=t.one(".left-selector"),e._rightBox=t.one(".right-selector")},_renderButtons(){const t=this,o=t.get("contentBox"),r=t.get("strings"),n=o.one(".move-arrow-buttons");if(n){const o=new e.Toolbar({children:[["normal","vertical",{cssClass:"move-right",icon:"angle-right",on:{click(e){e.domEvent.preventDefault()}},title:r.MOVE_RIGHT},{cssClass:"move-left",icon:"angle-left",on:{click(e){e.domEvent.preventDefault()}},title:r.MOVE_LEFT}]]});o.get("toolbarRenderer").TEMPLATES.icon=Liferay.Util.getLexiconIconTpl("{cssClass}"),o.render(n),t._moveToolbar=o}const l={children:[[{cssClass:"reorder-up",icon:"angle-up",on:{click(e){e.domEvent.preventDefault()}}},{cssClass:"reorder-down",icon:"angle-down",on:{click(e){e.domEvent.preventDefault()}}}]]};if(t.get("leftReorder")){const n=o.one(".left-selector-column");l.children[0][0].title=r.LEFT_MOVE_UP,l.children[0][1].title=r.LEFT_MOVE_DOWN,t._leftReorderToolbar=new e.Toolbar(l).render(n)}if(t.get("rightReorder")){const n=o.one(".right-selector-column");l.children[0][0].title=r.RIGHT_MOVE_UP,l.children[0][1].title=r.RIGHT_MOVE_DOWN,t._rightReorderToolbar=new e.Toolbar(l).render(n)}t._toggleReorderToolbars(),t._initToggleBtn(o.one(".reorder-down")),t._initToggleBtn(o.one(".reorder-up")),t._initToggleBtn(o.one(".move-left")),t._initToggleBtn(o.one(".move-right"))},_toggleBtnMove(e){const t=this,o=e.target,r=o.get("options").getDOMNodes().filter((e=>e.selected)),n=o===t._rightBox?"left":"right",l=t["_".concat(n,"Box")],i=t.get("".concat(n,"BoxMaxItems")),s=t.get("contentBox");t._toggleBtnState(s.one(".move-".concat(n)),l.get("length")+r.length>i)},_toggleBtnSort(e){const t=this,o=t.get("contentBox"),r=o.one(".reorder-down"),n=o.one(".reorder-up"),l=t._leftBox,i=t._rightBox;if(e&&r&&n){const o=e.get("length"),s=e.get("options").getDOMNodes().filter((e=>e.selected)).map((e=>e.index));let g=!1,c=!1;if(e===l){const e=!o,t=!s.length,r=s.includes(0),n=s.includes(o-1);c=r||t||e,g=n||t||e}else e===i&&(g=!0,c=!1);t._toggleBtnState(r,g),t._toggleBtnState(n,c)}},_toggleBtnState(e,o){t.toggleDisabled(e,o)},_toggleReorderToolbar(e,t){const o=t.all("option").size()>1;e.toggle(o)},_toggleReorderToolbars(){const e=this,t=e.get("contentBox");if(e.get("leftReorder")){const o=t.one(".left-selector-column");e._toggleReorderToolbar(e._leftReorderToolbar,o)}if(e.get("rightReorder")){const o=t.one(".right-selector-column");e._toggleReorderToolbar(e._rightReorderToolbar,o)}},bindUI(){const t=this,o=t._leftReorderToolbar;o&&o.after("click",e.rbind("_afterOrderClick",t,t._leftBox));const r=t._rightReorderToolbar;r&&r.after("click",e.rbind("_afterOrderClick",t,t._rightBox)),t._moveToolbar.on("click",t._afterMoveClick,t),t._leftBox.after("change",e.bind("_onSelectChange",t)),t._leftBox.on("focus",e.rbind("_onSelectFocus",t,t._rightBox)),t._rightBox.after("change",e.bind("_onSelectChange",t)),t._rightBox.on("focus",e.rbind("_onSelectFocus",t,t._leftBox))},renderUI(){this._renderBoxes(),this._renderButtons()},sortBox(t){const o=[],r=t.all("option");for(let e=0;e<r.size();e++)o[e]=[r.item(e).val(),r.item(e).text()];o.sort(((e,t)=>(e=e[1].toLowerCase())>(t=t[1].toLowerCase())?1:e<t?-1:0));const n=e.one(t);n.all("option").remove(!0),o.forEach((e=>{n.append('<option value="'+e[0]+'">'+e[1]+"</option>")}))}}});Liferay.InputMoveBoxes=r}),"",{requires:["aui-base","aui-toolbar"]});
//# sourceMappingURL=input_move_boxes.js.map