import{Bt as e,Dr as t,Fr as n,Ft as r,Gn as i,Ir as a,Jn as o,L as s,Lr as c,Lt as l,M as u,Nt as d,Pt as f,Qn as p,Vt as m,Xn as h,Yn as g,Zn as _,br as v,c as y,dn as b,dr as x,er as S,fr as C,l as w,rr as T,sn as E,t as D,tn as O,tr as k,un as A,ur as j,v as M,vr as N}from"./index-BROmIau2.js";import{t as P}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as F}from"./VChip-BD6Q-0ta.js";import{t as I}from"./VAlert-B-sPsp2c.js";var L=b({...A(),...w()},`VForm`),R=E()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:r,emit:i}){let o=y(e),s=t();function c(e){e.preventDefault(),o.reset()}function l(e){let t=e,n=o.validate();t.then=n.then.bind(n),t.catch=n.catch.bind(n),t.finally=n.finally.bind(n),i(`submit`,t),t.defaultPrevented||n.then(({valid:e})=>{e&&s.value?.submit()}),t.preventDefault()}return O(()=>g(`form`,{ref:s,class:n([`v-form`,e.class]),style:a(e.style),novalidate:!0,onReset:c,onSubmit:l},[r.default?.({get errors(){return o.errors.value},get isDisabled(){return o.isDisabled.value},get isReadonly(){return o.isReadonly.value},get isValidating(){return o.isValidating.value},get isValid(){return o.isValid.value},get items(){return o.items.value},validate:o.validate,reset:o.reset,resetValidation:o.resetValidation})])),M(o,s)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=P(T({__name:`LoginPage`,setup(n){let y=e(),b=m(),w=d(),T=t(``),E=t(``),O=t(``),A=t(!1),M=t(!1),P=t(``),L=t(!1),H=t(0),U=t(null),W=t([]),G=t(0),K=null,q=o(()=>W.value.length===0?``:W.value[G.value]);async function J(){try{let e=await l.get(`/settings/bing-wallpapers`);e?.urls?.length&&(W.value=e.urls,G.value=Math.floor(Math.random()*e.urls.length))}catch{}}function Y(){K&&clearInterval(K),!(W.value.length<=1)&&(K=setInterval(()=>{G.value=(G.value+1)%W.value.length},36e5))}j(async()=>{await J(),Y()}),x(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=t(Date.now()),Z=null,Q=o(()=>{if(!U.value)return 0;let e=new Date(U.value).getTime()-X.value;return Math.max(0,Math.ceil(e/6e4))});N(U,e=>{Z&&=(clearInterval(Z),null),e&&(Z=setInterval(()=>{X.value=Date.now()},3e4))});async function $(){if(!T.value||!E.value){P.value=`请输入用户名和密码`;return}M.value=!0,P.value=``;try{await w.login(T.value,E.value,L.value?O.value:void 0);let e=y.query.redirect||`/`;b.push(e)}catch(e){e instanceof r?(L.value=!0,P.value=e.message):e instanceof f?e.status===429?(U.value=new Date(Date.now()+900*1e3).toISOString(),P.value=`登录尝试过多，账户已锁定 15 分钟`):(H.value++,P.value=e.message):P.value=`网络错误，请重试`}finally{M.value=!1}}return(e,t)=>(C(),p(`div`,z,[g(`div`,{class:`wallpaper-bg`,style:a({backgroundImage:`url(${q.value})`})},null,4),t[6]||=g(`div`,{class:`wallpaper-overlay`},null,-1),g(`div`,B,[k(u,{elevation:`0`,rounded:`xl`,class:`login-card pa-10`,border:``},{default:v(()=>[P.value?(C(),h(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":t[0]||=e=>P.value=``,rounded:`lg`,variant:`tonal`},{default:v(()=>[S(c(P.value),1)]),_:1})):_(``,!0),U.value?(C(),h(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:v(()=>[S(` 账户已锁定，请 `+c(Q.value)+` 分钟后重试 `,1)]),_:1})):_(``,!0),k(R,{onSubmit:i($,[`prevent`])},{default:v(()=>[k(D,{modelValue:T.value,"onUpdate:modelValue":t[1]||=e=>T.value=e,label:`用户名`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-account-outline`,disabled:M.value,class:`mb-4`,autocomplete:`username`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`disabled`]),k(D,{modelValue:E.value,"onUpdate:modelValue":t[2]||=e=>E.value=e,label:`密码`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-lock-outline`,"append-inner-icon":A.value?`mdi-eye`:`mdi-eye-off`,type:A.value?`text`:`password`,"onClick:appendInner":t[3]||=e=>A.value=!A.value,disabled:M.value,class:`mb-4`,autocomplete:`current-password`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`append-inner-icon`,`type`,`disabled`]),L.value?(C(),h(D,{key:0,modelValue:O.value,"onUpdate:modelValue":t[4]||=e=>O.value=e,label:`TOTP 验证码`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-shield-key-outline`,disabled:M.value,class:`mb-4`,autocomplete:`one-time-code`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`disabled`])):_(``,!0),k(s,{type:`submit`,color:`primary`,variant:`flat`,block:``,size:`large`,loading:M.value,disabled:!!U.value,rounded:`lg`,class:`mt-2`,height:`48`},{default:v(()=>[...t[5]||=[S(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(C(),p(`div`,V,[k(F,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:v(()=>[S(` 已失败 `+c(H.value)+` 次 `,1)]),_:1})])):_(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};