import{f as v,W as b,_ as C,r as q,b as h,H as k,w as x,J as S,K,M as o,n as e,P as c,Q as p,u,S as f,R as _,$ as y}from"./vue-BhpnMDi9.js";import{_ as A}from"./PasswordField.vue_vue_type_script_setup_true_lang-DGUuFj94.js";import{e as T,P as U,i as $,j as B,Q as F,k as M,V as R,a as E,n as I,p as N}from"./index-ChuS1rKu.js";import{V as O}from"./VForm-DyhOXLXH.js";import{V as P}from"./VContainer-CgO7mktY.js";import"./vuetify-BI39WAG5.js";const z=v({__name:"Login",setup(Q){const{t:a}=T(),w=b(),t=C(),i=U(),n=q({username:"",password:""}),m=h(!1),V={username:[r=>!!r||a("login.rules.username_required")],password:[r=>!!r||a("login.rules.password_required")]};async function d(){if(!m.value)return;const r=await i.login(n.username,n.password);if(i.isAuthenticated)y.success(a("login.success")),g();else{let s=a("login.error");r.status!==200&&(s+=`
Error code: ${r.status} (${r.data})`),y.error(s)}}function g(){t.query.redirect?w.push(t.query.redirect):w.push({name:"dashboard"})}return k(async()=>{t.query.username&&t.query.password&&await i.login(t.query.username,t.query.password)}),x(()=>{i.isAuthenticated&&g()}),(r,s)=>(K(),S(P,{class:"fill-height"},{default:o(()=>[e($,{class:"mx-auto",rounded:"lg","min-width":"250"},{default:o(()=>[e(B,null,{default:o(()=>[c(p(u(a)("login.title")),1)]),_:1}),e(F,null,{default:o(()=>[c(p(u(a)("login.subtitle")),1)]),_:1}),e(M,null,{default:o(()=>[e(O,{modelValue:m.value,"onUpdate:modelValue":s[2]||(s[2]=l=>m.value=l),onSubmit:f(d,["prevent"])},{default:o(()=>[e(R,{id:"username",modelValue:n.username,"onUpdate:modelValue":s[0]||(s[0]=l=>n.username=l),name:"username",autocomplete:"username","aria-autocomplete":"username",label:u(a)("login.username"),autofocus:"",rules:V.username,variant:"outlined",onKeydown:_(f(d,["prevent"]),["enter"])},{prepend:o(()=>[e(E,{color:"accent",icon:"mdi-account"})]),_:1},8,["modelValue","label","rules","onKeydown"]),e(A,{id:"password",modelValue:n.password,"onUpdate:modelValue":s[1]||(s[1]=l=>n.password=l),autocomplete:"current-password","aria-autocomplete":"current-password",label:u(a)("login.password"),rules:V.password,"prepend-icon":"mdi-lock",variant:"outlined",onKeydown:_(f(d,["prevent"]),["enter"])},null,8,["modelValue","label","rules","onKeydown"])]),_:1},8,["modelValue"])]),_:1}),e(I,null,{default:o(()=>[e(N,{variant:"elevated",block:"",color:"accent",onClick:d},{default:o(()=>[c(p(u(a)("login.submit")),1)]),_:1})]),_:1})]),_:1})]),_:1}))}});export{z as default};
