import{d as S,u as j,a as C,r as m,b as B,t as a,c as P,o as V,e as y,f as l,g as i,h as o,w as r,i as q,j as e,k as D,l as F,m as R,n as b,N as g,p as N,q as U,s as _,v as z,x as A}from"./index-a0da86f0.js";import{_ as K}from"./logo-a60c622a.js";import{I as L}from"./iconify-56cbf3ff.js";import{_ as M}from"./_plugin-vue_export-helper-c27b6911.js";const T={class:"login-container"},E={class:"login-card"},J={class:"login-header"},G={class:"logo"},H=["alt"],O={class:"title"},Q={key:0,class:"login-footer"},W=S({__name:"Login",setup(X){const f=F(),u=j(),c=C(),h=m(),d=m(!1),v=m(!1),n=B({username:"",password:""}),x={username:[{required:!0,message:a("Please enter username"),trigger:"blur"}],password:[{required:!0,message:a("Please enter password"),trigger:"blur"},{min:6,message:a("Password must be at least 6 characters"),trigger:"blur"}]},w=async()=>{var t;try{await((t=h.value)==null?void 0:t.validate()),d.value=!0;const s=await c.login(n.username,n.password);s.success?(u.success(a("Login successful")),f.push("/")):u.error(s.error||a("Login failed"))}catch(s){console.error("Login error:",s),u.error(a("Login failed, please check username and password"))}finally{d.value=!1}},k=P(()=>localStorage.getItem("appName")||"Jingrow");return V(async()=>{if(await c.initAuth(),c.isLoggedIn){f.push("/");return}try{const t=await fetch("/jingrow/server-config");if(t.ok){const s=await t.json();s.success&&s.jingrow_server_url==="https://cloud.jingrow.com"&&(v.value=!0)}}catch(t){console.error("Failed to get server config:",t)}}),(t,s)=>{const I=R("router-link");return b(),y("div",T,[l("div",E,[l("div",J,[l("div",G,[l("img",{src:K,alt:k.value,width:"48",height:"48"},null,8,H)]),l("h1",O,i(k.value),1)]),o(e(z),{ref_key:"formRef",ref:h,model:n,rules:x,size:"medium","show-label":!1,onKeyup:q(w,["enter"])},{default:r(()=>[o(e(g),{path:"username"},{default:r(()=>[o(e(N),{value:n.username,"onUpdate:value":s[0]||(s[0]=p=>n.username=p),placeholder:e(a)("Username"),"input-props":{autocomplete:"username"}},{prefix:r(()=>[o(e(L),{icon:"tabler:user"})]),_:1},8,["value","placeholder"])]),_:1}),o(e(g),{path:"password"},{default:r(()=>[o(e(N),{value:n.password,"onUpdate:value":s[1]||(s[1]=p=>n.password=p),type:"password",placeholder:e(a)("Password"),"input-props":{autocomplete:"current-password"},"show-password-on":"click"},{prefix:r(()=>[o(e(L),{icon:"tabler:lock"})]),_:1},8,["value","placeholder"])]),_:1}),o(e(g),null,{default:r(()=>[o(e(U),{type:"primary",size:"large",block:"",loading:d.value,onClick:w,class:"brand-button"},{default:r(()=>[_(i(e(a)("Login")),1)]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"]),v.value?(b(),y("div",Q,[o(e(A),{depth:"3"},{default:r(()=>[_(i(e(a)("Don't have an account?"))+" ",1),o(I,{to:"/signup",class:"signup-link"},{default:r(()=>[_(i(e(a)("Sign up")),1)]),_:1})]),_:1})])):D("",!0)])])}}});const se=M(W,[["__scopeId","data-v-b343e094"]]);export{se as default};
