1import{r as t,j as e,u as ie,a as oe,c as le,b as ce,d as ue,N as de,L as me,s as H}from"./index-oMFu1KO1.js";import{u as v,A as Y}from"./AuthCard-D530l2A0.js";import{P as fe}from"./PasswordField-DnMS5t46.js";import{S as pe}from"./StrengthMeter-Cn5Ld-Rl.js";import{G as he,A as xe,a as ge}from"./errorMap-CfZRwlNt.js";import{i as z,T as ye}from"./turnstile-BGfW0B8s.js";import{r as ve,s as we}from"./nextRedirect-Bg2qndnN.js";import{o as be,s as w}from"./schemas-CMLUtXL5.js";function je({checked:b,onChange:x,error:p,disabled:g}){const l=t.useRef(null);return t.useEffect(()=>{const a=l.current;if(!a)return;const c=()=>x(a.checked);return a.addEventListener("change",c),()=>a.removeEventListener("change",c)},[x]),e.jsxs("div",{children:[e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:12,cursor:g?"default":"pointer",color:"var(--md-sys-color-on-surface)"},children:[e.jsx("span",{style:{display:"inline-flex",paddingTop:2,flexShrink:0},children:e.jsx("md-checkbox",{ref:a=>{l.current=a},...b&&{checked:!0},...g&&{disabled:!0},"aria-describedby":p?"terms-err":void 0,"touch-target":"wrapper"})}),e.jsxs("span",{className:"yo-body-medium",style:{lineHeight:"24px"},children:["I have read and agree to the"," ",e.jsx("a",{href:"/terms",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--md-sys-color-primary)"},children:"Terms of Use"})," ","and"," ",e.jsx("a",{href:"/privacy",target:"_blank",rel:"noopener noreferrer",style:{color:"var(--md-sys-color-primary)"},children:"Privacy Policy"}),"."]})]}),p?e.jsx("p",{id:"terms-err",role:"alert","aria-live":"polite",className:"yo-body-small",style:{marginTop:6,marginLeft:36,color:"var(--md-sys-color-error)"},children:p}):null]})}const Se=be({first_name:w().trim().min(1,"First name is required").max(60,"Keep it under 60 characters"),last_name:w().trim().min(1,"Last name is required").max(60,"Keep it under 60 characters"),email:w().trim().toLowerCase().email("Enter a valid email").max(254),password:w().min(12,"Use at least 12 characters")}),J=1e4;function Ne(){var C,R,E;ie({title:"Sign up",description:"Create a Youth Opportunities account."}),oe();const b=le(),[x]=ce(),{session:p,loading:g}=ue(),l=t.useRef(null),a=t.useRef(null),c=t.useRef(null),y=t.useRef(null),_=t.useRef(null),[Q,X]=t.useState(""),[Z,ee]=t.useState(0),[k,re]=t.useState(!1),[u,d]=t.useState(!1),[i,m]=t.useState({}),[te,se]=t.useState(null),[f,j]=t.useState(0),[T,P]=t.useState(null);v(l,i.first_name),v(a,i.last_name),v(c,i.email),v(y,i.password),t.useEffect(()=>{const r=ve(window.location.search);r&&we(r)},[]),t.useEffect(()=>{if(f<=0)return;const r=window.setTimeout(()=>j(o=>Math.max(0,o-1)),1e3);return()=>window.clearTimeout(r)},[f]),t.useEffect(()=>{var r;window.innerWidth>=768&&((r=l.current)==null||r.focus())},[]);const S=t.useMemo(()=>Object.entries(i).filter(([r,o])=>o&&r!=="form").length+(i.form?1:0),[i]);if(g)return null;if(p){const r=x.get("next");return e.jsx(de,{to:r&&r.startsWith("/")?r:"/",replace:!0})}async function ae(r){var I,U,M,A,D,O,q,B,W,F,V,$,G,K;if(r.preventDefault(),u||f>0)return;if((I=_.current)!=null&&I.value){se("[email protected]");return}m({});const o=Se.safeParse({first_name:((U=l.current)==null?void 0:U.value)??"",last_name:((M=a.current)==null?void 0:M.value)??"",email:((A=c.current)==null?void 0:A.value)??"",password:((D=y.current)==null?void 0:D.value)??""}),s={};if(!o.success){const n=o.error.flatten().fieldErrors;s.first_name=(O=n.first_name)==null?void 0:O[0],s.last_name=(q=n.last_name)==null?void 0:q[0],s.email=(B=n.email)==null?void 0:B[0],s.password=(W=n.password)==null?void 0:W[0]}if(o.success&&(o.data.password.toLowerCase()===o.data.email.toLowerCase()&&(s.password="Pick a stronger password â it can't match your email."),Z<3&&(s.password=s.password??"Pick a stronger password.")),k||(s.terms="Please agree to continue."),Object.values(s).some(Boolean)){m(s),s.first_name?(F=l.current)==null||F.focus():s.last_name?(V=a.current)==null||V.focus():s.email?($=c.current)==null||$.focus():s.password&&((G=y.current)==null||G.focus());return}if(d(!0),z()){if(!T){m({form:"Please complete the verification challenge."}),d(!1);return}try{const{data:n,error:ne}=await H.functions.invoke("verify-turnstile",{body:{token:T}});if(ne||!(n!=null&&n.ok)){m({form:"Verification failed. Please try again."}),d(!1);return}}catch{m({form:"Couldn't verify the challenge. Please try again."}),d(!1);return}}const h=o.data,{data:L,error:N}=await H.auth.signUp({email:h.email,password:h.password,options:{data:{first_name:h.first_name,last_name:h.last_name},emailRedirectTo:`${window.location.origin}/auth/callback`}});if(N){const n=ge(N);m({[n.field]:n.message}),d(!1),j(Math.ceil(J/1e3));return}if(L.user&&((K=L.user.identities)==null?void 0:K.length)===0){m({email:"An account with this email already exists. Sign in or reset your password."}),d(!1),j(Math.ceil(J/1e3));return}d(!1),b(`/auth/verify-email?email=${encodeURIComponent(h.email)}`,{replace:!0})}return te?e.jsx(Y,{title:"Check your email",description:"We've sent you a confirmation link.",children:e.jsx("div",{})}
1):e.jsxs(Y,{title:"Sign up",footer:e.jsxs("p",{className:"yo-body-medium",children:["Already have an account?"," ",e.jsx(me,{to:"/auth/sign-in",style:{color:"var(--md-sys-color-primary)"},children:"Sign in"})]}),children:[S>0?e.jsx("div",{role:"status","aria-live":"polite",className:"yo-body-small",style:{marginBottom:12,padding:"8px 12px",borderRadius:8,background:"var(--md-sys-color-error-container)",color:"var(--md-sys-color-on-error-container)"},children:S===1?"1 field needs attention.":`${S} fields need attention.`}):null,e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:16},children:[e.jsx(he,{}),e.jsx(xe,{})]}),e.jsxs("form",{onSubmit:ae,noValidate:!0,style:{display:"flex",flexDirection:"column",gap:16,scrollPaddingBottom:"33vh"},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"absolute",left:"-9999px",width:1,height:1,overflow:"hidden"},children:e.jsxs("label",{children:["Don't fill this in",e.jsx("input",{ref:_,type:"text",name:"website",tabIndex:-1,autoComplete:"off"})]})}),e.jsxs("div",{style:{display:"grid",gap:16,gridTemplateColumns:"1fr 1fr"},children:[e.jsx("md-outlined-text-field",{ref:r=>{l.current=r},label:"First name",name:"first_name",autocomplete:"given-name",required:!0,...u&&{disabled:!0}}),e.jsx("md-outlined-text-field",{ref:r=>{a.current=r},label:"Last name",name:"last_name",autocomplete:"family-name",required:!0,...u&&{disabled:!0}})]}),e.jsx("md-outlined-text-field",{ref:r=>{c.current=r},label:"Email",type:"email",name:"email",autocomplete:"email",inputMode:"email",required:!0,...u&&{disabled:!0}}),e.jsxs("div",{children:[e.jsx(fe,{ref:y,label:"Password",name:"password",autocomplete:"new-password",minLength:12,required:!0,disabled:u,onInput:X}),e.jsx("div",{style:{marginTop:8},children:e.jsx(pe,{password:Q,userInputs:[((C=c.current)==null?void 0:C.value)??"",((R=l.current)==null?void 0:R.value)??"",((E=a.current)==null?void 0:E.value)??""],onScore:ee})})]}),e.jsx(je,{checked:k,onChange:re,error:i.terms,disabled:u}),z()?e.jsx(ye,{onToken:P,onExpire:()=>P(null)}):null,i.form?e.jsx("p",{role:"alert",className:"yo-body-small",style:{color:"var(--md-sys-color-error)"},children:i.form}):null,e.jsx("md-filled-button",{type:"submit",style:{width:"100%",marginTop:8},...(u||f>0)&&{disabled:!0},children:u?"Creating accountâ¦":f>0?`Try again in ${f}sâ¦`:"Create account"})]})]})}export{Ne as default};
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.