/*! phoscon-app 2024-08-14 */

import{serviceSend}from"./settings-gateway-machine.js";import{states,events}from"./settings-gateway-constants.js";import{removeClassFromAll}from"./settings-gateway-functions.js";export const ChangePasswordHandlerView=Backbone.View.extend({template:_.template(document.getElementById("change-password-gateway-template").innerHTML),el:"#changePasswordGatewayModal",initialize:function(){this.el.innerHTML=this.template(app.config),this.passwordInput=this.el.querySelector("#oldPwInput"),this.confirmOldPw=this.el.querySelector("#oldPwInfo"),this.newPwInput=this.el.querySelector("#newPwInput"),this.confirmNewPwInput=this.el.querySelector("#confirmPwInput"),this.confirmNewPwInfo=this.el.querySelector("#changePwError"),this.prevBtn=this.el.querySelector(".btn-prev"),this.nextBtn=this.el.querySelector(".btn-next"),this.footer=this.el.querySelector(".modal-footer")},events:{"input #oldPwInput":"changePassword","click .form-control-feedback":"changePassword","input #newPwInput, #confirmPwInput":"changePassword","click .btn-next":function(){serviceSend(events.NEXT_PRESSED)},"click .btn-prev":function(){serviceSend(events.CANCEL_PRESSED)},"click .close":function(){serviceSend(events.CLOSE_PRESSED)}},render:function(){return this},show:function(){this.el.classList.add("show"),this.passwordInput.value="",this.newPwInput.value="",this.confirmNewPwInput.value="",this.confirmOldPw.innerHTML="&nbsp;"},hide:function(){this.el.classList.remove("show")},isValidInputOldPw:function(){return this.passwordInput.value.length>0},changePassword:_.debounce(function(){this.confirmOldPw.innerHTML="&nbsp;",this.confirmNewPwInfo.innerHTML="&nbsp;",serviceSend(events.PASSWORD_CHANGED)},400),getPassword:function(){return this.passwordInput?this.passwordInput.value:void 0},getNewPasswords:function(){return{password1:this.newPwInput.value,password2:this.confirmNewPwInput.value}},page1:function(){this.nextBtn.innerText=translate("text_next"),this.nextBtn.classList.add("disabled"),this.footer.classList.remove("success"),this.footer.classList.remove("danger"),this.nextBtn.classList.remove("btn-danger"),this.prevBtn.classList.remove("hidden"),this.prevBtn.innerText=translate("btn_cancel");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page1"]').classList.add("active-page"),this.passwordInput.focus()},page1Valid:function(){this.nextBtn.classList.remove("disabled")},page1Invalid:function(){this.nextBtn.classList.add("disabled")},showOldPwInfo:function(ev){ev===events.OLD_PW_FAIL?this.confirmOldPw.textContent=translate("text_wrong_pw"):ev===events.GENERAL_FAIL&&(this.confirmOldPw.textContent=translate("text_service_not_available"))},page2:function(){this.nextBtn.innerText=translate("text_next"),this.nextBtn.classList.add("disabled"),this.prevBtn.innerText=translate("btn_cancel");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="page2"]').classList.add("active-page"),this.newPwInput.focus()},page2Valid:function(){this.nextBtn.classList.remove("disabled")},page2Invalid:function(translateId){this.nextBtn.classList.add("disabled"),translateId&&(this.confirmNewPwInfo.innerHTML=translate(translateId))},showNewPwInfo:function(){this.confirmNewPwInfo.innerHTML=translate("text_service_not_available")},pageSuccess:function(){this.prevBtn.classList.add("hidden"),this.nextBtn.innerText=translate("text_done"),this.footer.classList.add("success");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="pageSuccess"]').classList.add("active-page")},pageError:function(){this.prevBtn.classList.add("hidden"),this.nextBtn.innerText=translate("text_okay"),this.footer.classList.add("danger"),this.nextBtn.classList.add(".btn-danger");let elemList=this.el.querySelectorAll(".page");removeClassFromAll(elemList,"active-page"),this.el.querySelector('[data-page="pageError"]').classList.add("active-page")}});