import{a as c,r,k as d}from"./init-Ck7wRxmZ.js";import{l as h}from"./theme-BfDtj5yE.js";let p=c({setup(){h();const s=r(""),t=r(!1),e=r(!1),a=r(!1),i={error:s,success:t,loading:e,savePassword:a,passwordData:{username:"",password:""}},n=localStorage.getItem("login");if(n)try{const{username:o,password:l}=JSON.parse(n);a.value=!0,i.passwordData={username:o,password:l}}catch(o){console.error("Reading saved password failed!",o)}return i},methods:{login(){this.error=null,this.loading=!0,this.savePassword||localStorage.removeItem("login"),fetch("./api/login",{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify(this.passwordData)}).then(s=>{if(this.loading=!1,s.status===200){this.success=!0,this.savePassword&&localStorage.setItem("login",JSON.stringify(this.passwordData));const t=new URL(window.location),e=t.searchParams.get("redir"),a=t.hash;e&&e.startsWith(".")?location.href=e+a:location.href="./"+a}else throw s.status===401?new Error("Please check your username and password"):new Error(`Server returned ${s.status}`)}).catch(s=>{this.error=`Login failed: ${s.message}`})}}});d(p);
