text: this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,n,o,i,s,a,r,p,d,l){"use strict";var u=function(e){babelHelpers.inherits(t,e);function t(){var e;var o=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,t);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,o));s.Dom.addClass(e.layout,"landing-ui-form-cards");e.type="cards";e.code=o.code;e.id="".concat(e.code.replace(".",""),"-").concat(s.Text.getRandom());e.presets=o.presets;e.childForms=new n.FormCollection;e.presetForm=new n.FormCollection;e.sync=o.sync;e.forms=o.forms;e.wheelEventName=window.onwheel?"wheel":"mousewheel";e.onFormRemove=e.onFormRemove.bind(babelHelpers.assertThisInitialized(e));e.onAddCardClick=e.onAddCardClick.bind(babelHelpers.assertThisInitialized(e));e.onMouseWheel=e.onMouseWheel.bind(babelHelpers.assertThisInitialized(e));e.onDragEnd=e.onDragEnd.bind(babelHelpers.assertThisInitialized(e));e.addButton=e.createAddButton();e.draggable=new r.Draggable({container:e.body,draggable:".landing-ui-form-cards-item",dragElement:".landing-ui-form-card-item-header-drag",type:r.Draggable.MOVE});e.draggable.subscribe("end",e.onDragEnd);setTimeout(function(){e.value=e.serialize()});e.adjustLastFormState();s.Dom.append(e.addButton.layout,e.footer);return e}babelHelpers.createClass(t,[{key:"createAddButton",value:function e(){return new BX.Landing.UI.Button.BaseButton("add-card-".concat(s.Text.getRandom()),{className:"landing-ui-card-add-button",text:o.Loc.getMessage("LANDING_CARDS_FORM_ADD_BUTTON"),onClick:this.onAddCardClick})}},{key:"onFormRemove",value:function e(t){this.childForms.remove(t.getTarget());this.sortForms();this.adjustLastFormState()}},{key:"onDragEnd",value:function e(){var t=this;setTimeout(function(){t.sortForms()})}},{key:"sortForms",value:function e(){var t=babelHelpers.toConsumableArray(this.body.children);this.childForms.sort(function(e,n){var o=parseInt(t.indexOf(e.wrapper));var i=parseInt(t.indexOf(n.wrapper));return o<i?-1:1});this.childForms.forEach(function(e,t){var n=e.selector.split("@"),o=babelHelpers.slicedToArray(n,1),i=o[0];e.selector="".concat(i,"@").concat(t)})}},{key:"addChildForm",value:function e(t){this.childForms.add(t);t.subscribe("onRemove",this.onFormRemove);s.Dom.append(t.wrapper,this.body);this.adjustLastFormState()}},{key:"addPresetForm",value:function e(t){this.presetForm.add(t);t.wrapper.hidden=true;s.Dom.append(t.wrapper,this.body);this.adjustLastFormState()}},{key:"onAddCardClick",value:function e(){if(s.Type.isPlainObject(this.presets)&&Object.keys(this.presets).length>0){this.showPresetsPopup()}else{this.addEmptyCard()}}},{key:"onPresetItemClick",value:function e(t){var n=this.presets[t];var o=this.presetForm.find(function(e){return e.preset.id===t}).clone();o.selector="".concat(o.selector.split("@")[0],"@").concat(this.childForms.length);o.oldIndex=this.childForms.length;o.preset=s.Runtime.clone(n);o.preset.id=t;this.addChildForm(o);this.adjustLastFormState();this.popup.close();if(s.Type.isPlainObject(n.values)){o.fields.forEach(function(e){var t=e.selector.split("@")[0];if(t in n.values){e.setValue(n.values[t]);if(e instanceof l.TextField){BX.fireEvent(e.input,"input")}}if(s.Type.isArray(n.disallow)){var o=!!n.disallow.find(function(e){return t===e});if(o){e.layout.hidden=true}}})}}},{key:"showPresetsPopup",value:function e(){var t=this;if(!this.popup){this.popup=new BX.PopupMenuWindow({id:"catalog_blocks_list",bindElement:this.addButton.layout,items:Object.keys(this.presets).map(function(e){return{html:t.presets[e].name,className:"landing-ui-form-cards-preset-popup-item menu-popup-no-icon",onclick:t.onPresetItemClick.bind(t,e)}}),autoHide:true,maxHeight:176,minHeight:87});s.Event.bind(this.popup.popupWindow.popupContainer,"mouseover",this.onMouseOver.bind(this));s.Event.bind(this.popup.popupWindow.popupContainer,"mouseleave",this.onMouseLeave.bind(this));var n=p.PageObject.getRootWindow();s.Event.bind(n.document,"click",this.onDocumentClick.bind(this));s.Dom.append(this.popup.popupWindow.popupContainer,this.addButton.layout.closest(".landing-ui-panel-content-body-content"))}if(this.popup.popupWindow.isShown()){this.popup.popupWindow.close()}else{this.popup.popupWindow.show()}this.adjustPopupPosition()}},{key:"onMouseOver",value:function e(){var t=this.popup.popupWindow.getPopupContainer();s.Event.bind(t,this.wheelEventName,this.onMouseWheel,true);s.Event.bind(t,"touchmove",this.onMouseWheel,true)}},{key:"onMouseLeave",value:function e(){var t=this.popup.popupWindow.getPopupContainer();s.Event.unbind(t,this.wheelEventName,this.onMouseWheel,true);s.Event.unbind(t,"touchmove",this.onMouseWheel,true)}},{key:"onMouseWheel",value:function e(t){var n=this;t.stopPropagation();t.preventDefault();var o=i.Content.getDeltaFromEvent(t);var s=this.popup.popupWindow.getContentContainer(),a=s.scrollTop;requestAnimationFrame(function(){n.popup.popupWindow.contentContainer.scrollTop=a-o.y})}},{key:"onDocumentClick",value:function e(){if(this.popup.popupWindow){this.popup.popupWindow.close()}}},{key:"adjustPopupPosition",value:function e(){var t=this;if(this.popup.popupWindow){requestAnimationFrame(function(){var e=t.addButton.layout.closest(".landing-ui-panel-content-body-content");var n=BX.Landing.Utils.offsetTop(t.addButton.layout,e);var o=BX.Landing.Utils.offsetLeft(t.addButton.layout,e);var i=t.addButton.layout.getBoundingClientRect();var s=t.popup.popupWindow.popupContainer.getBoundingClientRect();var a=14;t.popup.popupWindow.popupContainer.style.top="".concat(n+i.height+a,"px");t.popup.popupWindow.popupContainer.style.left="".concat(o-s.width/2+i.width/2,"px");t.popup.popupWindow.setAngle({offset:83,position:"top"})})}}},{key:"addEmptyCard",value:function e(){var t=s.Runtime.clone(this.childForms[0].data);var n="".concat(t.selector.split("@")[0],"@").concat(this.childForms.length);t.selector=n;var o=this.childForms[0].clone(t);o.oldIndex=this.childForms.length;o.selector=n;o.fields.forEach(function(e){return e.reset()});this.addChildForm(o);this.adjustLastFormState()}},{key:"getVisibleForms",value:function e(){return babelHelpers.toConsumableArray(this.body.children).filter(function(e){return!e.hidden})}},{key:"adjustLastFormState",value:function e(){var t=this.getVisibleForms();if(t.length===1){s.Dom.addClass(t[0],"landing-ui-disallow-remove");return}babelHelpers.toConsumableArray(t).forEach(function(e){s.Dom.removeClass(e,"landing-ui-disallow-remove")})}},{key:"serialize",value:function e(){return this.childForms.map(function(e){return e.serialize()})}},{key:"getIndexesMap",value:function e(){return this.childForms.reduce(function(e,t,n){return babelHelpers.objectSpread({},e,babelHelpers.defineProperty({},n,t.oldIndex))},{})}},{key:"getUsedPresets",value:function e(){return this.childForms.reduce(function(e,t){if(s.Type.isPlainObject(t.preset)){var n=t.selector.split("@"),o=babelHelpers.slicedToArray(n,2),i=o[1];e[i]=t.preset.id}return e},{})}},{key:"isChanged",value:function e(){return JSON.stringify(this.value)!==JSON.stringify(this.serialize())}}]);return t}(t.BaseForm);e.CardsForm=u})(this.BX.Landing.UI.Form=this.BX.Landing.UI.Form||{},BX.Landing.UI.Form,BX.Landing.UI.Collection,BX.Landing,BX.Landing.UI.Panel,BX,BX.Landing.UI.Form,BX.UI.DragAndDrop,BX.Landing,BX.Event,BX.Landing.UI.Field);
  //# sourceMappingURL=cardsform.bundle.map.js