import{L as a,m as i,u as o,a as l,C as n,R as u,n as c,b as d}from"./index-009d300e.js";const m=a.get("Login"),p={data(){return{username:"",password:"",rememberMe:!1,error_text:"",error_type:"error",showPsw:!1,error:!1,valid_login:!0,rules:{required(t){return!!t||"This field is required."}}}},computed:{...i(o,{darkMode:t=>t.ui.darkMode}),internalDarkMode:{get(){return this.darkMode},set(t){this.setDarkMode(t)}}},watch:{error:function(t){t&&setTimeout(function(){this.error=!1},5e3)}},mounted(){if(this.isLocalStorageSupported()){const t=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):null,e=!!localStorage.getItem("logged");t&&t.rememberMe?(this.username=t.username||this.username,this.password=t.password||this.password,this.rememberMe=t.rememberMe,e&&this.login(!0)):localStorage.removeItem("user")}else this.error=!0,this.error_type="error",this.error_text="Local storage not supported"},methods:{...l(o,["setDarkMode"]),isLocalStorageSupported(){const t="test",e=window.localStorage;try{return e.setItem(t,"1"),e.removeItem(t),!0}catch{return!1}},async login(t){if(!this.isLocalStorageSupported()){this.error=!0,this.error_type="error",this.error_text="Local storage not supported";return}if(t===!0||this.$refs.form.validate())try{let e={username:this.username,password:this.password};const r=await n.login(e);r.success?(e=Object.assign(e,r.user),e.rememberMe=this.rememberMe,localStorage.setItem("user",JSON.stringify(e)),localStorage.setItem("logged","true"),o().onUserLogged(e),this.$route.params.nextUrl!=null?this.$router.push(this.$route.params.nextUrl):this.$router.push(u.main)):(r.message&&(this.error=!0),this.error_type="error",this.error_text=r.message)}catch(e){m.error(e),this.error=!0,this.error_type="error",this.error_text=e.message}}}};var g=function(){var e=this,r=e._self._c;return r("v-container",{staticClass:"pa-0 background",attrs:{fluid:"","fill-height":""}},[r("v-col",{staticClass:"pa-0 fill-height",attrs:{elevation:"12",cols:"12"}},[r("v-card",{staticClass:"mx-auto",class:e.$vuetify.breakpoint.smAndDown?"":"ml-10",attrs:{width:e.$vuetify.breakpoint.smAndDown?"100%":"500",height:"100%",tile:""}},[r("v-card-title",{},[r("v-avatar",{staticStyle:{"border-radius":"0"},attrs:{size:"40px"}},[r("img",{attrs:{src:d,alt:"Logo"}})]),r("v-toolbar-title",{staticStyle:{"margin-left":"20px"}},[e._v("Z-Wave JS UI")])],1),r("v-card-text",[r("v-form",{ref:"form",attrs:{id:"login-form","lazy-validation":""},on:{submit:function(s){return s.preventDefault(),e.login.apply(null,arguments)}},model:{value:e.valid_login,callback:function(s){e.valid_login=s},expression:"valid_login"}},[r("v-text-field",{attrs:{required:"",rules:[e.rules.required],autocomplete:"","prepend-icon":"person",name:"username",label:"Username",type:"text"},model:{value:e.username,callback:function(s){e.username=typeof s=="string"?s.trim():s},expression:"username"}}),r("v-text-field",{attrs:{required:"",rules:[e.rules.required],"prepend-icon":"lock",name:"password",label:"Password",autocomplete:"",type:e.showPsw?"text":"password","append-icon":e.showPsw?"visibility":"visibility_off"},on:{"click:append":function(s){e.showPsw=!e.showPsw}},model:{value:e.password,callback:function(s){e.password=s},expression:"password"}}),r("v-checkbox",{attrs:{"prepend-icon":"null",name:"rememberMe","hide-details":"",label:"Remember Me"},model:{value:e.rememberMe,callback:function(s){e.rememberMe=s},expression:"rememberMe"}}),r("v-checkbox",{attrs:{"prepend-icon":"null","hide-details":"","persistent-hint":"",label:"Dark mode"},model:{value:e.internalDarkMode,callback:function(s){e.internalDarkMode=s},expression:"internalDarkMode"}})],1)],1),r("v-card-actions",{staticClass:"justify-center"},[r("v-btn",{staticClass:"mb-6",staticStyle:{"min-width":"150px",margin:"10px"},attrs:{color:"primary",rounded:"",type:"submit",form:"login-form"}},[e._v("Login")])],1),r("v-alert",{attrs:{dismissible:"",type:e.error_type},model:{value:e.error,callback:function(s){e.error=s},expression:"error"}},[e._v(e._s(e.error_text))])],1)],1)],1)},f=[],h=c(p,g,f,!1,null,"dfd26ade",null,null);const v=h.exports;export{v as default};
