/*! phoscon-app 2024-02-26 */

export const getSwitchWizardView=(c,subs)=>new Promise((resolve,reject)=>{resolve(new(Backbone.View.extend({el:"#switchEditorModal",initialize:function(){this.service=null,this.views=[],this.c=c,this.hf=this.c.helperFuncs,subs.forEach(view=>{let v=new view(this.c);this.views.push(v)}),this.swView=this.views[0],this.btnView=this.views[1],this.funcView=this.views[2],this.gmView=this.views[3],this.gmiView=this.views[4],this.prevBtn=this.el.querySelector(".modal-footer .btn-prev"),this.nextBtn=this.el.querySelector(".modal-footer .btn-next"),this.nextBtnPhone=this.el.querySelector(".modal-body .mq-phone.btn-next"),this.headInfo=this.el.querySelector(".page-name small"),this.headLine=this.el.querySelector(".page-name span"),this.modalFooter=this.el.querySelector(".modal-footer"),this.sceneOption=this.el.querySelector('.subfunc[data-oid="callScene"]'),this.effectOption=this.el.querySelector('.subfunc[data-oid="callEffect"]'),this.listenTo(app,"switchButtonClicked",this.swClicked)},isModalOpen:function(){return $("#"+this.el.id).is(":visible")},openModal:function(){$("#"+this.el.id).modal("show")},closeModal:function(){$("#"+this.el.id).modal("hide")},setHeadAndBottom:function(page,sw){switch(this.nextBtn.classList.remove("btn-warning"),this.modalFooter.classList.remove("warning"),this.nextBtn.innerText=translate("btn_next"),page){case c.States.PAGE_SWITCHES:this.prevBtn.classList.add("hidden"),this.nextBtn.classList.add("disabled"),this.headInfo.innerText=translate("txt_switchEditor"),this.headLine.innerText=translate("txt_selectSwitch");break;case c.States.PAGE_BUTTONS:this.prevBtn.classList.remove("hidden"),this.nextBtn.classList.add("disabled"),this.nextBtnPhone.classList.add("disabled"),this.headInfo.innerText=sw.get("name")||translate("link_switches"),this.headLine.innerText=translate("txt_selectBtn");break;case c.States.PAGE_FUNCTIONS:this.nextBtn.classList.add("disabled"),this.nextBtnPhone.classList.add("disabled"),this.headInfo.innerText=sw.get("name")||translate("link_switches"),this.headLine.innerText=translate("txt_selectActionForBtn"),this.funcView.disableNextBtn(),this.nextBtn.innerText=translate("btn_apply");break;case c.States.PAGE_GROUPMODE:this.headInfo.innerText=translate("txt_switchEditor"),this.headLine.innerText=translate("select_mode");break;case c.States.PAGE_GROUPMODEINFO:this.headInfo.innerText=translate("txt_switchEditor"),this.headLine.innerText=translate("basic_func_warn"),this.nextBtn.classList.add("btn-warning"),this.nextBtn.innerText=translate("btn_apply")}},enableNextBtn:function(){this.nextBtn.classList.remove("disabled"),this.nextBtnPhone.classList.remove("disabled"),this.funcView.enableNextBtn()},events:{"click [data-btn-ev]:not(.disabled):not(.scene):not(.light-chain-effect)":function(ev){let item=ev.currentTarget,sendEv=item.getAttribute("data-btn-ev"),input=item.querySelector("input");item.getAttribute("data-oid");input&&(input.checked=!0),sendEv="FUNC_PRESSED"==sendEv?"SUBFUNC_MODAL_PRESSED":sendEv,this.service&&sendEv&&this.service.send({type:sendEv,item:item})},"click .light-chain-effect:not(.disabled)":function(ev){let item=ev.currentTarget;app.session.eid=item.getAttribute("data-effect")||void 0,this.effectOption.click(),this.c.helperFuncs.siblings(item).forEach(i=>i.classList.remove("active-effect")),item.classList.add("active-effect")}},swClicked:function(model){let swid=model.get("id"),item=this.el.querySelector('.switch[data-swid="'+swid+'"]'),sendEv=item.getAttribute("data-btn-ev");this.service&&sendEv&&this.service.send({type:sendEv,item:item})}})))});