import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{O as t,k as n}from"./vendor-markdown-DngssFHR.js";import{u as r}from"./vendor-react-Cts2Wj-s.js";import{Q as i,X as a,Y as o,i as s,nt as c,q as l,rt as u}from"./vendor-mui-Ckcy4Lfd.js";import"./vendor-md-editor-DC6xr_29.js";var d=e(n(),1),f=t();function p(){let[e]=r(),t=e.get(`returnUrl`)||`/`,n=t.startsWith(`/`)&&!t.startsWith(`//`)?t:`/`,[p,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(!1);return(0,f.jsx)(i,{sx:{display:`flex`,alignItems:`center`,justifyContent:`center`,minHeight:`100vh`},children:(0,f.jsx)(o,{sx:{maxWidth:400,width:`100%`,mx:2},children:(0,f.jsxs)(l,{children:[(0,f.jsx)(c,{variant:`h5`,gutterBottom:!0,align:`center`,children:`Graph Memory`}),(0,f.jsx)(c,{variant:`body2`,color:`text.secondary`,gutterBottom:!0,align:`center`,children:`Sign in to continue`}),(0,f.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!(!p.trim()||!h)){b(!0),v(``);try{let e=await fetch(`/api/auth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({email:p.trim(),password:h})});if(e.ok){window.location.href=`/ui`+n;return}else v((await e.json().catch(()=>({error:`Login failed`}))).error||`Login failed`)}catch{v(`Connection failed`)}finally{b(!1)}}},children:[(0,f.jsx)(s,{fullWidth:!0,label:`Email`,type:`email`,value:p,onChange:e=>m(e.target.value),margin:`normal`,autoFocus:!0}),(0,f.jsx)(s,{fullWidth:!0,label:`Password`,type:`password`,value:h,onChange:e=>g(e.target.value),margin:`normal`}),_&&(0,f.jsx)(u,{severity:`error`,sx:{mt:1},children:_}),(0,f.jsx)(a,{fullWidth:!0,variant:`contained`,type:`submit`,disabled:y||!p.trim()||!h,sx:{mt:2},children:y?`Signing in...`:`Sign In`})]})]})})})}export{p as default};