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

import{serviceSend}from"./settings-gateway-machine.js";import{states,events}from"./settings-gateway-constants.js";import{removeClassFromAll}from"./settings-gateway-functions.js";export const ChangeChannelModalHandlerView=Backbone.View.extend({template:_.template(document.getElementById("change-zigbee-channel-template").innerHTML),el:"#changeZigBeeChannelModal",initialize:function(){this.el.innerHTML=this.template(app.config),this.prevBtn=this.el.querySelector(".btn-prev"),this.nextBtn=this.el.querySelector(".btn-next"),this.close=this.el.querySelector(".close"),this.modalFooter=this.el.querySelector(".modal-footer"),this.oldChannel=0,this.newChannel=0,this.listenTo(app.config,"change:zigbeechannel",this.setNetworkId)},events:{"click .btn-next":function(){serviceSend(events.NEXT_PRESSED)},"click .btn-cancel":function(){serviceSend(events.CANCEL_PRESSED)},"click .close":function(){serviceSend(events.CLOSE_PRESSED)},"click .btn-channel":"channelPressed"},render:function(){return this},show:function(){this.el.classList.add("show")},hide:function(){this.el.classList.remove("show")},getWishChannel:function(){return this.newChannel},setChannelBtn:function(){let elemList=this.el.querySelectorAll(".btn-channel");if(removeClassFromAll(elemList,"btn-primary"),this.oldChannel=app.config.get("zigbeechannel")||0,this.oldChannel){const channelBtn=this.el.querySelector('[data-channel="'+this.oldChannel+'"]');channelBtn&&channelBtn.classList.add("btn-primary")}},channelPressed:function(ev){if(this.newChannel=ev.currentTarget.getAttribute("data-channel"),!this.newChannel)return;let elemList=this.el.querySelectorAll(".btn-channel");removeClassFromAll(elemList,"btn-primary"),this.el.querySelector('[data-channel="'+this.newChannel+'"]').classList.add("btn-primary"),serviceSend({type:events.CHANNEL_PRESSED,activeChannel:this.newChannel})},isChannelBtnChanged:function(channel){return channel!=this.oldChannel},isChannelChanged:function(channel){return channel!=this.oldChannel},page1:function(){this.nextBtn.textContent=translate("text_change_anyway"),this.prevBtn.textContent=translate("btn_cancel"),this.prevBtn.classList.add("btn-cancel"),this.prevBtn.classList.remove("hidden"),this.nextBtn.classList.remove("disabled"),this.nextBtn.classList.add("btn-danger"),this.modalFooter.classList.add("danger"),this.modalFooter.classList.remove("success");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page1"]').classList.add("active-page")},page2:function(){this.nextBtn.classList.add("disabled"),this.setChannelBtn();let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page2"]').classList.add("active-page")},page2Valid:function(){this.nextBtn.classList.remove("disabled")},page2Invalid:function(){this.nextBtn.classList.add("disabled")},page3:function(){this.nextBtn.classList.add("invisible"),this.prevBtn.classList.add("hidden"),this.close.classList.add("hidden"),this.nextBtn.classList.remove("btn-danger"),this.modalFooter.classList.remove("danger"),this.modalFooter.classList.remove("success"),this.nextBtn.textContent=translate("text_done");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page3"]').classList.add("active-page")},page3Success:function(){this.nextBtn.classList.remove("invisible"),this.prevBtn.classList.add("hidden"),this.nextBtn.classList.remove("btn-danger"),this.close.classList.remove("hidden"),this.modalFooter.classList.remove("danger"),this.modalFooter.classList.add("success"),this.nextBtn.textContent=translate("text_done");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page3Success"]').classList.add("active-page")},page3Error:function(){this.nextBtn.classList.remove("invisible"),this.prevBtn.classList.add("hidden"),this.nextBtn.classList.add("btn-danger"),this.modalFooter.classList.add("danger"),this.close.classList.remove("hidden"),this.modalFooter.classList.remove("success"),this.nextBtn.textContent=translate("text_okay");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page3Error"]').classList.add("active-page")}});