1import{r as a,j as n}from"./react-DPgN3sVp.js";import{a5 as y,a6 as v,e as U,a0 as Y,aM as z,V as L,S as G,b as H,B as h,L as J}from"./index-DsyO9LCw.js";import{T as Q,i as R,a as p}from"./TurnstileWidget-CsYiZ95q.js";import{I as P}from"./input-D2V3Hdl-.js";import{L as B}from"./label-D2f3wDqo.js";import"./supabase-JOBST33U.js";import"./tanstack-query-kdKQZfpc.js";const X=y({method:"POST"}).handler(v("a85d6e8a98d921cd24e92784db8760ac4aa50f9b85f80d538fce3f1eb91cb724")),Z=y({method:"POST"}).handler(v("9153edc6205e8894a6cb994d1884f6ffb1f4db774b280e07e8e444acfc719a90")),$=y({method:"POST"}).handler(v("e92855947cae016a13e8d6fa4b210ab347a059e2ad930c57303e3cd0fdac2134"));function le(){const x=U(),F=Y(),{redirect:o,mode:I}=z.useSearch(),[t,_]=a.useState(I==="forgot"?"forgot":"signin"),[l,M]=a.useState(""),[f,W]=a.useState(""),k=a.useRef(null),d=a.useRef(null),[ee,m]=a.useState(null);function c(){if(d.current=null,R()){m(p);return}m(null),k.current?.reset()}function u(e){_(e),i(null),c()}const[S,r]=a.useState(!1),[b,i]=a.useState(null),j=l.trim().length>0,g=t==="signin"?j&&f.length>0:j;a.useEffect(()=>{L.auth.getSession().then(({data:e})=>{e.session&&x({to:o})})},[x,o]);async function N(e){r(!0),i(null);try{const s=await X({data:{email:l,password:f,turnstileToken:e}}),{error:E}=await L.auth.setSession({access_token:s.access_token,refresh_token:s.refresh_token});if(E){i(E.message),c();return}F.invalidate(),x({to:o})}catch(s){i(s instanceof Error?s.message:"Sign-in failed"),c()}finally{r(!1)}}async function C(e){r(!0),i(null);try{await $({data:{email:l,turnstileToken:e,redirect:o}}),u("forgot-sent")}catch(s){i(s instanceof Error?s.message:"Could not send reset email"),c()}finally{r(!1)}}async function T(e){r(!0),i(null);try{await Z({data:{email:l,turnstileToken:e,redirect:o}}),u("magic-link-sent")}catch(s){i(s instanceof Error?s.message:"Could not send sign-in link"),c()}finally{r(!1)}}const q=a.useCallback(e=>{m(e);const s=d.current;if(s){if(!e){d.current=null,r(!1),i("Please complete the security check"),c();return}d.current=null,s==="signin"?N(e):s==="forgot"?C(e):T(e)}},[l,f,o]);function w(e){if(R()){e==="signin"?N(p):e==="forgot"?C(p):T(p);return}d.current=e,i(null),r(!0),m(null),k.current?.execute()}function D(e){e.preventDefault(),g&&w("signin")}function O(e){e.preventDefault(),g&&w("forgot")}function V(e){e.preventDefault(),g&&w("magic-link")}const A=t==="signin"?"Sign in":t==="forgot"?"Reset password":t==="magic-link"?"Email sign-in link":"Check your email",K=t==="signin"?"Admin and verified school staff access.":t==="forgot"?"We will email you a link to set a new password.":t==="magic-link"?"We will email you a one-click link to open the school portal â no password needed.":t==="magic-link-sent"?"If an account exists for that address, your sign-in link is on the way.":"If an account exists for that address, reset instructions are on the way.";return n.jsx(G,{children:n.jsxs("section",{className:"mx-auto flex max-w-md flex-col gap-6 px-4 py-16 sm:px-6",children:[n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:A}),n.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:K})]}),n.jsx(H,{className:"p-6",children:t==="forgot-sent"||t==="magic-link-sent"?n.jsxs("div",{className:"space-y-4",children:[n.jsx("p",{className:"text-sm text-muted-foreground",children:t==="magic-link-sent"?"Look for an email from SchoolFinder with a link to open your portal. The link expires after a short time. Check spam if you do not see it within a few minutes.":"Look for an email from SchoolFinder with a link to choose a new password. The link expires after a short time. Check spam if you do not see it within a few minutes."}),n.jsx(h,{type:"button",variant:"outline",className:"w-full",onClick:()=>u("signin"),children:"Back to sign in"})]}):n.jsxs("form",{onSubmit:t==="signin"?D:t==="magic-link"?V:O,className:"space-y-4",children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(B,{htmlFor:"email",children:"Email"}),n.jsx(P,{id:"email",type:"email",autoComplete:"email",required:!0,value:l,onCh
1ange:e=>M(e.target.value)})]}),t==="signin"&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx(B,{htmlFor:"password",children:"Password"}),n.jsx("button",{type:"button",className:"text-xs text-primary hover:underline",onClick:()=>u("forgot"),children:"Forgot password?"})]}),n.jsx(P,{id:"password",type:"password",autoComplete:"current-password",required:!0,value:f,onChange:e=>W(e.target.value)})]}),n.jsx(Q,{ref:k,mode:"invisible",onToken:q},t),b&&n.jsx("p",{className:"text-sm text-destructive",children:b}),n.jsx(h,{type:"submit",className:"w-full",disabled:S||!g,children:S?t==="signin"?"Signing inâ¦":"Sendingâ¦":t==="signin"?"Sign in":t==="magic-link"?"Email me a sign-in link":"Send reset link"}),t==="signin"&&n.jsx(h,{type:"button",variant:"outline",className:"w-full",onClick:()=>u("magic-link"),children:"Email me a sign-in link instead"}),(t==="forgot"||t==="magic-link")&&n.jsx(h,{type:"button",variant:"ghost",className:"w-full",onClick:()=>u("signin"),children:"Back to sign in"})]})}),n.jsx("p",{className:"text-center text-xs text-muted-foreground",children:n.jsx(J,{to:"/",className:"hover:text-foreground",children:"â Back to home"})})]})})}export{le as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.