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

export function initDevicesSensorView(addClassToAll,removeClassToAll,injectSwitchWizzardSvg){return new(Backbone.View.extend({template:_.template(document.getElementById("sensor-wizard-modal-template").innerHTML),el:"#sensorWizardModal",initialize:function(){this.el.innerHTML=this.template(),this.service=null,this.modalTitle=this.el.querySelector(".modal-title"),this.modalBody=this.el.querySelector(".fade-in .modal-body"),this.modalFooter=this.el.querySelector(".modal-footer"),this.fadeIn=this.el.querySelector(".fade-in"),this.fadeOut=this.el.querySelector(".fade-out"),this.addClassToAll=addClassToAll,this.removeClassToAll=removeClassToAll,this.listenTo(app.sensors,"add",this.sensorsAdd),this.listenTo(app.sensors,"change",this.sensorsChanged)},events:{"click [data-btn-ev]:not(.disabled)":function(ev){const elem=ev.currentTarget;var dataEv=elem.getAttribute("data-btn-ev");if(""===dataEv)throw new Error("missing data-btn-ev attribute value");elem.hasAttribute("data-vendor")&&(app.session.vendor=elem.getAttribute("data-vendor")),this.service.send(dataEv)}},sensorsAdd:function(model){this.service.send({type:"DEVICE_ADDED",device:model})},addClass:function(data){let elemList=this.el.querySelectorAll(data.identifier);this.addClassToAll(elemList,data.c)},removeClass:function(data){let elemList=this.el.querySelectorAll(data.identifier);this.removeClassToAll(elemList,data.c)},showPage:function(pageContent){if(pageContent.trans){const newScript=document.createElement("script"),inlineScript=document.createTextNode(pageContent.trans.innerHTML);newScript.appendChild(inlineScript),document.body.appendChild(newScript)}0==this.checkIOS&&(this.fadeIn.style.opacity="0",this.fadeOut.innerHTML=this.fadeIn.innerHTML),this.fadeIn.classList.remove("animate-prev"),this.fadeIn.classList.remove("animate-next"),this.fadeOut.classList.remove("animate-prev"),this.fadeOut.classList.remove("animate-next"),pageContent.body&&(this.modalBody.innerHTML=pageContent.body.innerHTML),pageContent.title&&(this.modalTitle.innerHTML=pageContent.title.innerHTML),pageContent.footer&&(this.modalFooter.innerHTML=pageContent.footer.innerHTML);let images=this.el.querySelectorAll("img[data-svgInject='sensorWizzardSvg']")||[];injectSwitchWizzardSvg(images).catch(err=>{console.log(err)}).then(()=>{this.fadeIn.style.opacity="1";if(window.innerWidth<=416){let progress=this.el.querySelector(".modal-header .progress-bar-wizard");if(progress&&progress.classList.add("running"),null===this.lastClick||1==this.checkIOS)return;"BTN_PREV_PRESSED"===this.lastClick?(this.fadeIn.classList.add("animate-prev"),this.fadeOut.classList.add("animate-prev")):(this.fadeIn.classList.add("animate-next"),this.fadeOut.classList.add("animate-next"))}else{let progress=this.el.querySelector(".modal-footer .progress-bar-wizard");progress&&progress.classList.add("running")}})}}))};