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