/*! phoscon-app 2024-05-27 */

export function initDevicesThermostatsView(addClassToAll,removeClassToAll,injectSwitchWizzardSvg){return new Promise((response,reject)=>{return response(new(Backbone.View.extend({template:_.template(document.getElementById("thermostat-wizard-modal-template").innerHTML),el:"#thermostatWizardModal",initialize:function(){this.el.innerHTML=this.template(),this.modalBody=this.el.querySelector(".fade-in .modal-body"),this.modalTitle=this.el.querySelector(".modal-title"),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.service=null,this.lastClick=null,this.touch=!1,this.checkIOS=iOS()},events:{"click [data-btn-ev]:not(.disabled)":function(ev){const elem=ev.currentTarget,dataEv=elem.getAttribute("data-btn-ev");let aFunc=this.el.querySelector(".active-func");if(aFunc&&aFunc.classList.remove("active-func"),elem.hasAttribute("data-vendor")&&(app.session.vendor=elem.getAttribute("data-vendor")),elem.hasAttribute("data-product")&&(app.session.product=elem.getAttribute("data-product")),elem.hasAttribute("data-swid")&&(app.session.swid=elem.getAttribute("data-swid")),""===dataEv)throw new Error("missing data-btn-ev attribute value");this.lastClick=dataEv,console.log(dataEv),this.service.send(dataEv)}},render:function(){return this},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),app.session.vendor&&this.el.querySelectorAll(".fade-in .vendor").forEach(el=>el.innerText=app.session.vendor),app.session.product&&this.el.querySelectorAll(".fade-in .product-name").forEach(el=>el.innerText=app.session.product);let images=this.el.querySelectorAll("img[data-svgInject='thermostatWizzardSvg']")||[];injectSwitchWizzardSvg(images).catch(err=>{console.log(err)}).then(()=>{if(this.fadeIn.style.opacity="1",screenMax(SCREEN_MAX_WIDTH_PHONE_LANDSCAPE)&&isThisPortrait()){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")}})},thermostatClicked:function(model){if(1==_.size(model.changed)&&model.changed.lastupdated||model.changed.buttonevent){let btnEvent=model.get("buttonevent");setActiveTarget(btnEvent,this.el),this.service.send("THERMOSTAT_BTN_PRESSED")}},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)}})))})};function iOS(){return!(!navigator.platform||!["iPad Simulator","iPhone Simulator","iPad","iPhone","MacIntel","Mac68K","MacPPC"].includes(navigator.platform))}