import{c as g,g as d,a as p,u as v,i,b as f,t as x}from"./web.4OCuPnM3.js";import{T as u,F as w}from"./toast.BAoR90zK.js";import{a as S,g as b}from"./errors.BxTAJicR.js";import{n as L}from"./router.BaxLfCzj.js";var N=x('<form method=post class="grid gap-5 md:gap-10 max-w-sm mx-auto"><!$><!/><!$><!/><div class="flex flex-wrap justify-center mt-5"><button type=submit class="bg-blue-950 rounded-lg text-white p-2 w-[10rem]">'),C=x("<small class=ms-auto><a href=/dashboard/forgot-password class=text-blue-950>Forgot password?");const k=()=>{const[$,t]=g(!1),[n,m]=g();let o;const _=async e=>{e.preventDefault(),t(!0),m();try{const a=new FormData(o),{data:s,error:r}=await S.login(a);if(t(!1),m(r),await u.fire({icon:r?"error":"success",title:r?"Failed":"Successful",text:s?.message??r?.fields?"":r?.message}),!r)return console.log({data:s}),o.reset(),L("/dashboard")}catch(a){console.log({error:a}),await u.fire({icon:"error",title:"Error",text:a.message})}finally{t(!1)}};return(()=>{var e=d(N),a=e.firstChild,[s,r]=p(a.nextSibling),h=s.nextSibling,[c,y]=p(h.nextSibling),E=c.nextSibling,F=E.firstChild;return v(l=>o=l,e),e.addEventListener("submit",l=>_(l)),i(e,f(w,{name:"email",label:"Email",type:"email",placeholder:"Email",className:"grow",error:()=>b(["email"],n())}),s,r),i(e,f(w,{name:"password",type:"password",label:"Password",placeholder:"Password",className:"grow",get hint(){return d(C)},error:()=>b(["password"],n())}),c,y),i(F,()=>$()?"...loading":"Login"),e})()};export{k as LoginForm};
