text: (function(){"use strict";BX.namespace("BX.Main.ui");BX.namespace("BX.Main.ui.block");BX.Main.ui.select=function(t,e){this.params=null;this.node=null;this.items=null;this.value=null;this.tabindex=null;this.classSearchButton=null;this.classClearButton="";this.classSquareRemove="main-ui-square-delete";this.classSquareText="main-ui-square-item";this.classSquareIcon="main-ui-item-icon";this.classPopup="main-ui-select-inner";this.classShow="main-ui-popup-fast-show-animation";this.classClose="main-ui-popup-fast-close-animation";this.classInput="main-ui-square-search-item";this.classMenuItem="main-ui-select-inner-item";this.classLegend="main-ui-select-inner-item-legend";this.classMenuItemText="main-ui-select-inner-item-element";this.classMenuMultiItemText="main-ui-select-inner-label";this.classMenuItemChecked="main-ui-checked";this.classSquare="main-ui-square";this.classSquareContainer="main-ui-square-container";this.classTextValueNode="main-ui-select-name";this.classMultiSelect="main-ui-multi-select";this.classSelect="main-ui-select";this.classValueDelete="main-ui-control-value-delete";this.classValueDeleteItem="main-ui-control-value-delete-item";this.classSquareSelected="main-ui-square-selected";this.classPopupItemSelected="main-ui-select-inner-item-selected";this.classHide="main-ui-hide";this.classFocus="main-ui-focus";this.classDisableScroll="main-ui-disable-scroll";this.classScroll="main-ui-mac-scroll";this.marginForEachLevel=10;this.popup=null;this.popupItems=null;this.isShown=false;this.isMulti=false;this.input=null;this.init(t,e)};BX.Main.ui.select.prototype={init:function(t,e){var s,i,a;if(BX.type.isDomNode(t)){this.node=t}try{e=e||JSON.parse(BX.data(t,"params"))}catch(t){}if(BX.type.isPlainObject(e)){this.params=e;this.classSearchButton=this.prepareParam("classSearchButton");this.classClearButton=this.prepareParam("classClearButton");this.classSquareRemove=this.prepareParam("classSquareRemove");var n=BX.prop.getString(this.params,"classPopup","");if(n!==""){this.classPopup+=" "+n}this.isMulti=this.prepareParam("isMulti")}s=this.getPopup();i=this.getInput();a=s.popupContainer;t=this.getNode();BX.bind(i,"blur",BX.delegate(this._onBlur,this));BX.bind(i,"focus",BX.delegate(this._onFocus,this));BX.bind(i,"keydown",BX.delegate(this._onKeyDown,this));BX.bind(i,"input",BX.delegate(this._onInput,this));BX.bind(a,"click",BX.delegate(this._onPopupClick,this));BX.bind(t,"click",BX.delegate(this._onControlClick,this));this.controlValueDeleteButton()},controlValueDeleteButton:function(){if(this.isMulti){if(!this.getDataValue().length){BX.addClass(this.getValueDeleteButton(),this.classHide)}else{BX.removeClass(this.getValueDeleteButton(),this.classHide)}}},getValueDeleteButton:function(){if(!BX.type.isDomNode(this.valueDeleteButton)){this.valueDeleteButton=BX.findChild(this.getNode(),{className:this.classValueDelete},true,false)}return this.valueDeleteButton},_onInput:function(t){var e=t.currentTarget;clearTimeout(this.inputTimer);this.inputTimer=setTimeout(function(){e.value=""},1e3);this.selectPopupItemBySubstring(e.value)},_onKeyDown:function(t){var e=t.currentTarget;var s,i;if(this.isMulti){if(BX.hasClass(e,this.classInput)){s=this.getLastSquare();if(e.value.length===0&&t.code==="Backspace"){if(BX.type.isDomNode(s)){if(this.isSelected(s)){i=JSON.parse(BX.data(s,"item"));this.unselectItem(i)}else{this.selectSquare(s)}}}else{this.unselectSquare(s)}}}if(t.code==="ArrowDown"){this.selectNextPopupItem();e.value=""}if(t.code==="ArrowUp"){this.selectPrevPopupItem();e.value=""}if(t.code==="Enter"){this.selectSelectedItem();t.stopPropagation();e.value=""}},selectPopupItemBySubstring:function(t){t=t.toLowerCase();var e=this.getPopupItems();var s=false;this.unselectAllPopupItems();e.forEach(function(e){if(!s&&e.innerText.toLowerCase().indexOf(t)===0){s=true;BX.addClass(e,this.classPopupItemSelected);this.selectedItem=e;this.adjustScroll()}},this)},selectSelectedItem:function(){if(BX.type.isDomNode(this.selectedItem)){BX.fireEvent(this.selectedItem,"mousedown");this.selectNextPopupItem()}},unselectAllPopupItems:function(){var t=this.getPopupItems();if(BX.type.isArray(t)){t.forEach(function(t){BX.removeClass(t,this.classPopupItemSelected)},this)}},resetPopupScroll:function(){var t=this.getPopup();var e=t.contentContainer.parentNode;BX.scrollTop(e,0)},selectNextPopupItem:function(){var t=this.getPopupItems();var e,s;if(BX.type.isArray(t)){e=t.filter(function(t){return BX.hasClass(t,this.classPopupItemSelected)},this);e=e.length>0?e[0]:null}if(BX.type.isDomNode(e)){s=BX.nextSibling(e);if(!BX.type.isDomNode(s)){s=t[0]}BX.removeClass(e,this.classPopupItemSelected)}else{s=t[0]}this.selectedItem=s;BX.addClass(s,this.classPopupItemSelected);this.adjustScroll(false)},selectPrevPopupItem:function(){var t=this.getPopupItems();var e,s;if(BX.type.isArray(t)){e=t.filter(function(t){return BX.hasClass(t,this.classPopupItemSelected)},this);e=e.length>0?e[0]:null}if(BX.type.isDomNode(e)){s=BX.previousSibling(e);if(!BX.type.isDomNode(s)){s=t[t.length-1]}BX.removeClass(e,this.classPopupItemSelected)}else{s=t[t.length-1]}this.selectedItem=s;BX.addClass(s,this.classPopupItemSelected);this.adjustScroll(true)},adjustScroll:function(t){var e=this.getPopup().contentContainer.parentNode;var s=BX.pos(this.selectedItem);var i=BX.pos(e);var a=BX.scrollTop(e);if(!t){if(s.bottom>i.bottom){a=a+(s.bottom-i.bottom);BX.scrollTop(e,a)}if(s.top<i.top){a=a-s.bottom;BX.scrollTop(e,a)}}else{if(s.top<i.top){a=a-(i.top-s.top);BX.scrollTop(e,a)}if(s.bottom>i.bottom){a=a+(s.bottom-i.bottom);BX.scrollTop(e,a)}}},isSelected:function(t){return BX.hasClass(t,this.classSquareSelected)},selectSquare:function(t){BX.addClass(t,this.classSquareSelected)},unselectSquare:function(t){BX.removeClass(t,this.classSquareSelected)},getLastSquare:function(){var t=this.getSquares();var e;if(BX.type.isArray(t)&&t.length){e=t[t.length-1]}return e},_onMenuItemClick:function(t){t.stopPropagation();t.preventDefault();var e=t.currentTarget;var s,i;if(!this.isLegend(e)){try{s=JSON.parse(BX.data(e,"item"))}catch(t){}if(this.isMulti){i=this.getSquare(s);if(!BX.type.isDomNode(i)){this.selectItem(s)}else{this.unselectItem(s)}this.adjustPopupPosition();this.inputFocus()}else{this.uncheckAllItems();this.checkItem(e);this.updateDataValue(s);this.updateValue(s);this.closePopup();this.inputBlur()}BX.onCustomEvent(window,"UI::Select::change",[this,s]);this.controlValueDeleteButton()}},selectItem:function(t){var e=this.getPopupItem(t);this.addSquare(t);if(BX.type.isDomNode(e)){this.checkItem(e)}this.addMultiValue(t)},unselectItem:function(t){var e=this.getSquare(t);var s=this.getPopupItem(t);this.removeSquare(e);this.uncheckItem(s);this.removeMultiValue(t)},uncheckAllItems:function(){var t=this.getPopupItems();if(BX.type.isArray(t)){t.forEach(this.uncheckItem,this)}},addMultiValue:function(t){var e=this.getDataValue();if(BX.type.isArray(e)){e.push(t);this.updateDataValue(e)}},removeMultiValue:function(t){var e=this.getDataValue();if(BX.type.isArray(e)&&e.length){e=e.filter(function(e){return e.VALUE!==t.VALUE&&e.NAME!==t.NAME},this);this.updateDataValue(e)}},getPopupItems:function(){if(!BX.type.isArray(this.popupItems)){var t=this.getPopup().popupContainer;this.popupItems=BX.findChild(t,{class:this.classMenuItem},true,true)}return this.popupItems},getPopupItem:function(t){var e=this.getPopupItems();var s;var i=(e||[]).filter(function(e){s=JSON.parse(BX.data(e,"item"));return t.VALUE===s.VALUE&&t.NAME===s.NAME});return BX.type.isArray(i)&&i.length>0?i[0]:null},checkItem:function(t){if(!BX.hasClass(t,this.classMenuItemChecked)){BX.addClass(t,this.classMenuItemChecked)}},uncheckItem:function(t){if(BX.hasClass(t,this.classMenuItemChecked)){BX.removeClass(t,this.classMenuItemChecked)}},updateDataValue:function(t){var e=this.getNode();e.dataset.value=JSON.stringify(t);this.controlValueDeleteButton()},getDataValue:function(){var t=this.getNode();var e;try{e=JSON.parse(BX.data(t,"value"))}catch(t){}if(!BX.type.isPlainObject(e)&&!BX.type.isArray(e)){e=this.isMulti?[]:{}}return e},getTextValueNode:function(){var t=this.getNode();return BX.findChild(t,{class:this.classTextValueNode},true,false)},updateValue:function(t){var e=this.getTextValueNode();BX.html(e,BX.util.htmlspecialchars(t.NAME))},adjustPopupPosition:function(){var t=this.getPopup();var e=BX.pos(this.getNode());e.forceBindPosition=true;t.adjustPosition(e)},_onControlClick:function(t){var e=t.target;if(!BX.hasClass(e,this.classValueDelete)&&!BX.hasClass(e,this.classValueDeleteItem)){if(BX.hasClass(e,this.classSquareRemove)){var s=e.parentNode;var i=JSON.parse(BX.data(s,"item"));this.unselectItem(i)}else{if(t&&t.type==="click"){if(!this.getPopup().isShown()){this.inputFocus()}else{this.inputBlur()}}}}else{var a=this.getSquares();(a||[]).forEach(function(t){i=JSON.parse(BX.data(t,"item"));this.unselectItem(i)},this);this.getInput().value="";return false}},inputBlur:function(){var t=this.getInput();if(BX.type.isDomNode(t)){this.getInput().blur()}else{this._onBlur()}},inputFocus:function(){var t=this.getInput();if(BX.type.isDomNode(t)){if(document.activeElement!==t){t.focus()}}},_onPopupClick:function(){this.inputFocus()},_onFocus:function(){var t=this.getPopup();if(!t.isShown()){this.showPopup()}},_onBlur:function(){this.closePopup()},getInput:function(){if(!BX.type.isDomNode(this.input)){this.input=BX.findChild(this.getNode(),{class:this.classInput},true,false)}return this.input},getSquares:function(){return BX.findChild(this.getSquareContainer(),{class:this.classSquare},true,true)},getSquare:function(t){var e=this.getSquares();var s,i;if(!BX.type.isPlainObject(t)){try{t=JSON.parse(t)}catch(t){}}s=(e||[]).filter(function(e){try{i=JSON.parse(BX.data(e,"item"))}catch(t){i={}}return i.VALUE===t.VALUE&&i.NAME===t.NAME});return s.length?s[0]:null},removeSquare:function(t){var e;if(BX.type.isDomNode(t)){e=t}else{e=this.getSquare(data)}BX.remove(e);this.adjustPopupPosition()},createItem:function(t){var e,s;s=BX.create("div",{props:{className:this.classMenuItem},attrs:{"data-item":JSON.stringify(t)}});if("LEGEND"in t&&t.LEGEND===true){BX.addClass(s,this.classLegend)}if("DEPTH"in t){var i=parseInt(t.DEPTH);i=BX.type.isNumber(i)?i*this.marginForEachLevel:0;BX.style(s,"margin-left",i+"px")}if(!this.isMulti){e=BX.create("div",{props:{className:this.classMenuItemText},html:BX.util.htmlspecialchars(t.NAME)})}else{e=BX.create("div",{props:{className:this.classMenuMultiItemText},html:BX.util.htmlspecialchars(t.NAME)})}BX.append(e,s);return s},isLegend:function(t){return BX.hasClass(t,this.classLegend)},createSquare:function(t){if(!BX.type.isPlainObject(t)){try{t=JSON.parse(t)}catch(t){}}var e=BX.create("span",{props:{className:this.classSquare}});e.dataset.item=JSON.stringify(t);var s=BX.create("span",{props:{className:this.classSquareText},html:BX.util.htmlspecialchars(t.NAME)});var i=BX.create("span",{props:{className:[this.classSquareIcon,this.classSquareRemove].join(" ")}});BX.append(s,e);BX.append(i,e);return e},getSquareContainer:function(){if(!BX.type.isDomNode(this.squareContainer)){this.squareContainer=BX.findChild(this.getNode(),{class:this.classSquareContainer},true,false)}return this.squareContainer},addSquare:function(t){var e=this.getSquareContainer();var s=this.createSquare(t);BX.append(s,e)},closePopup:function(){var t=this.getPopup();var e=t.popupContainer;var s=parseFloat(BX.style(e,"animation-duration"));var i=this;if(!BX.hasClass(document.documentElement,"bx-ie")){BX.removeClass(e,this.classShow);BX.addClass(e,this.classClose);if(BX.type.isNumber(s)){s=s*1e3}setTimeout(function(){t.close();i.inputBlur()},s)}else{setTimeout(function(){t.close()})}BX.removeClass(this.getNode(),this.classFocus);this.unselectAllPopupItems();this.resetPopupScroll()},getNode:function(){return this.node},showPopup:function(){var t=this.getPopup();var e=t.popupContainer;var s,i,a,n;if(!t.isShown()){setTimeout(function(){this.adjustPopupPosition();t.show()}.bind(this));if(!BX.hasClass(document.documentElement,"bx-ie")){BX.removeClass(e,this.classClose);BX.addClass(e,this.classShow)}BX.addClass(this.getNode(),this.classFocus);if(this.isMulti){s=this.getSquares();(s||[]).forEach(function(t){i=JSON.parse(BX.data(t,"item"));this.checkItem(this.getPopupItem(i))},this)}else{a=this.getPopupItem(this.getDataValue());n=BX.pos(a,e);BX.scrollTop(e,n.top);this.checkItem(a)}if(!this.trackMouse&&this.getPopupItemsCount()>5){BX.addClass(e,this.classScroll);BX.bind(e,"mouseenter",BX.delegate(this._onMouseOver,this));BX.bind(e,"mouseleave",BX.delegate(this._onMouseOut,this));this.trackMouse=true}}},_onMouseOver:function(){var t=this.getPopup().popupContainer;var e=BX.height(t);var s=BX.height(BX.firstChild(t));var i=s-e;t.onmousewheel=function(t){if(t.deltaY<0&&this.scrollTop<=0||t.deltaY>0&&this.scrollTop>=i){t.preventDefault()}}},_onMouseOut:function(){var t=this.getPopup().popupContainer;t.onmousewheel=null},getItems:function(){var t=BX.data(this.getNode(),"items");if(!BX.type.isArray(this.items)){if(!BX.type.isArray(t)){this.items=JSON.parse(t)}else{this.items=t}}return this.items},getPopup:function(){if(!this.popup){this.popup=this.createPopup(this.getItems())}return this.popup},createPopupItems:function(t){var e=BX.create("div");var s;if(this.isMulti){BX.addClass(e,"popup-multiselect-content")}else{BX.addClass(e,"popup-select-content")}t.forEach(function(t){s=this.createItem(t);BX.append(s,e);BX.bind(s,"mousedown",BX.delegate(this._onMenuItemClick,this))},this);return e},createPopup:function(t){var e,s,i;if(BX.type.isArray(t)&&!this.popup){s=BX.pos(this.getNode());this.popup=new BX.PopupWindow("main-filter-control-popup",this.getNode(),{autoHide:false,offsetTop:2,offsetLeft:0,lightShadow:true,closeIcon:false,closeByEsc:false,noAllPaddings:true,zIndex:2e3});BX.style(this.popup.popupContainer,"width",s.width+"px");BX.addClass(this.popup.popupContainer,this.classPopup);i=this.createPopupItems(t);this.popup.setContent(i)}return this.popup},getPopupItemsCount:function(){var t;if(!this.popupItemsCount){t=this.getPopupItems();this.popupItemsCount=BX.type.isArray(t)?t.length:0}return this.popupItemsCount},prepareParam:function(t){return t in this.params?this.params[t]:this[t]},getParams:function(){return this.params}};BX.Main.ui.block["main-ui-square"]=function(t){return{block:"main-ui-square",attrs:{"data-item":"item"in t?JSON.stringify(t.item):""},content:[{block:"main-ui-square-item",content:"name"in t?t.name:""},{block:"main-ui-square-delete",mix:["main-ui-item-icon"]}]}};BX.Main.ui.block["main-ui-multi-select"]=function(t){var e,s,i,a,n;var u=[];var l=BX.type.isPlainObject(t.attrs)?t.attrs:{};l=BX.util.objectMerge({},l,{"data-name":t.name,"data-params":JSON.stringify(t.params),"data-items":JSON.stringify(t.items),"data-value":JSON.stringify(t.value)});if("value"in t&&BX.type.isArray(t.value)){u=t.value.map(function(t){return{block:"main-ui-square",name:"NAME"in t?t.NAME:"",item:t}},this)}e={block:"main-ui-multi-select",mix:["main-ui-control"],attrs:l,content:[]};i={block:"main-ui-square-container",tag:"span",content:u};n={block:"main-ui-square-search",tag:"span",content:{block:"main-ui-square-search-item",tag:"input",attrs:{type:"text",tabindex:"tabindex"in t?t.tabindex:"",placeholder:"placeholder"in t?t.placeholder:""}}};e.content.push(i);e.content.push(n);if("valueDelete"in t&&t.valueDelete===true){a={block:"main-ui-control-value-delete",mix:["main-ui-hide"],tag:"span",content:{block:"main-ui-control-value-delete-item"}};e.content.push(a)}return e};BX.Main.ui.block["main-ui-select"]=function(t){var e,s,i,a;var n=BX.type.isPlainObject(t.attrs)?t.attrs:{};n=BX.util.objectMerge({},n,{"data-name":t.name,"data-params":JSON.stringify(t.params),"data-items":JSON.stringify(t.items),"data-value":JSON.stringify(t.value)});e={block:"main-ui-select",mix:["main-ui-control"],attrs:n,content:[]};s={block:"main-ui-select-name",tag:"span",content:"value"in t&&BX.type.isPlainObject(t.value)?t.value.NAME:""};i={block:"main-ui-square-search",tag:"span",content:{block:"main-ui-square-search-item",tag:"input",attrs:{type:"text",tabindex:t.tabindex}}};if("valueDelete"in t&&t.valueDelete===true){a={block:"main-ui-control-value-delete",content:{block:"main-ui-control-value-delete-item",tag:"span"}}}e.content.push(s);e.content.push(i);if(BX.type.isPlainObject(a)){e.content.push(a)}return e}})();
  //# sourceMappingURL=core_ui_select.map.js