/*! phoscon-app 2023-07-31 */

import{serviceSend}from"./settings-gateway-machine.js";import{states,events}from"./settings-gateway-constants.js";import{removeClassFromAll}from"./settings-gateway-functions.js";export const RenameHandlerView=Backbone.View.extend({template:_.template(document.getElementById("rename-gateway-template").innerHTML),el:"#renameGatewayModal",initialize:function(){this.el.innerHTML=this.template(app.config),this.nameInput=this.el.querySelector("#inputRenameGateway"),this.prevBtn=this.el.querySelector(".btn-prev"),this.nextBtn=this.el.querySelector(".btn-next")},events:{"input #inputRenameGateway":"changeName","click .form-control-feedback":"changeName","click .btn-next":function(){serviceSend(events.NEXT_PRESSED)},"click .btn-prev":function(){serviceSend(events.CLOSE_PRESSED)},"click .close":function(){serviceSend(events.CLOSE_PRESSED)}},render:function(){return this},show:function(){this.el.classList.add("show")},hide:function(){this.el.classList.remove("show")},changeName:_.debounce(function(){serviceSend(events.NAME_CHANGED)},400),isValidInputName:function(){if(this.nameInput.value.length>0&&this.nameInput.value!==app.config.get("name"))return!0},setName:function(){let name=app.config.get("name");name&&(this.nameInput.value=name)},getName:function(){return this.nameInput?this.nameInput.value:void 0},page1:function(){let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page1"]').classList.add("active-page"),this.nextBtn.innerText=translate("btn_rename"),this.prevBtn.innerText=translate("btn_cancel"),this.nameInput.focus()},page1Valid:function(){this.nextBtn.classList.remove("disabled")},page1Invalid:function(){this.nextBtn.classList.add("disabled")}});