import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,r as n}from"./markdown-Biq8ujIZ.js";import{n as r}from"./AuthContext-V1-i7Jro.js";import{n as i,r as a}from"./validation-BXKsijXe.js";import{M as o,N as s,Ot as c}from"./index-B3ZlwJ0J.js";import{t as l}from"./Alert-DgQ1Y_9i.js";import{t as u}from"./OAuthButtons-BhALYwt0.js";var d=e(t(),1),f=n();function p(){let{signIn:e}=r(),[t,n]=(0,d.useState)(``),[p,h]=(0,d.useState)(``),[g,_]=(0,d.useState)(!1),[v,y]=(0,d.useState)(``),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)(!1);async function w(n){if(n.preventDefault(),y(``),x(!1),!i(t))return y(`Please enter a valid email address.`);if(!p)return y(`Please enter your password.`);C(!0);let r=await e(t.trim(),p);r.success||(C(!1),r.code===`email-unverified`&&x(!0),y(r.error??`Sign-in failed.`))}return(0,f.jsxs)(a,{title:`Welcome back`,subtitle:`Sign in to continue your study streak.`,footer:(0,f.jsxs)(f.Fragment,{children:[`New here?`,` `,(0,f.jsx)(c,{to:`/signup`,className:`font-medium text-brand-600 hover:underline`,children:`Create an account`})]}),children:[(0,f.jsxs)(`form`,{onSubmit:w,className:`space-y-4`,children:[v&&(0,f.jsx)(l,{tone:`error`,children:v}),b&&(0,f.jsx)(l,{tone:`info`,children:`Didn’t get the email? Check spam, or sign up again to resend the verification link.`}),(0,f.jsx)(o,{label:`Email`,name:`email`,type:`email`,autoComplete:`email`,placeholder:`you@example.com`,value:t,onChange:e=>n(e.target.value)}),(0,f.jsx)(o,{label:`Password`,name:`password`,type:g?`text`:`password`,autoComplete:`current-password`,placeholder:`••••••••`,value:p,onChange:e=>h(e.target.value),trailing:(0,f.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`px-2 text-xs font-medium text-text-muted hover:text-text`,children:g?`Hide`:`Show`})}),(0,f.jsx)(`div`,{className:`flex justify-end`,children:(0,f.jsx)(c,{to:`/forgot-password`,className:`text-sm text-brand-600 hover:underline`,children:`Forgot password?`})}),(0,f.jsx)(s,{type:`submit`,fullWidth:!0,loading:S,children:`Sign in`})]}),(0,f.jsx)(m,{}),(0,f.jsx)(u,{onError:y})]})}function m(){return(0,f.jsxs)(`div`,{className:`my-6 flex items-center gap-3 text-xs text-text-muted`,children:[(0,f.jsx)(`span`,{className:`h-px flex-1 bg-border`}),`or continue with`,(0,f.jsx)(`span`,{className:`h-px flex-1 bg-border`})]})}export{p as default};