1import{j as t}from"./vendor-query-CniT1WJL.js";import{u as te,e as ae,r as g,L as w}from"./vendor-react-69GsFwrV.js";import{f as se,g as v,o as re,b as f,s as i}from"./vendor-forms-q6h4WU-p.js";import{u as ne,s as oe,a as q,r as D,L as c,I as m,S as ie,b as ce,c as le,d as me,e as de,f as ue,B as he,g as pe,o as ge,v as xe,h as U,i as ye,j as je,k as ve,p as $,l as fe,m as Ne}from"./index-KjAD5lCC.js";import{P as be,a as we}from"./PasswordStrength-CIBKcPci.js";import{F as Ce}from"./vendor-ui-Ad3ANzF6.js";const Se="vp-pending-signup-intent-v2",ke=["vp-pending-mkt-optin","vp-pending-phone"];function Pe(r){r.removeItem(Se);for(const o of ke)r.removeItem(o)}const Oe=["Academic researcher","Lab / institutional researcher","Clinical professional","Graduate / PhD student","Biotech / industry","Other"],Te=["Metabolic","Recovery & Tissue","Cognitive","Longevity","Body Composition"];function Ie(r){if(!r)return!1;const o=new Date(r);if(Number.isNaN(o.getTime()))return!1;const d=new Date;let u=d.getFullYear()-o.getFullYear();const x=d.getMonth()-o.getMonth();return(x<0||x===0&&d.getDate()<o.getDate())&&u--,u>=21}const Ae=re({firstName:i().trim().min(1,"First name is required"),lastName:i().trim().min(1,"Last name is required"),email:i().email("Valid email required"),password:i().min(8,"At least 8 characters"),confirmPassword:i().min(1,"Re-enter your password to confirm"),dateOfBirth:i().min(1,"Date of birth is required").refine(Ie,"You must be 21 or older"),researcherRole:i().min(1,"Tell us how you'll use VidaPeps"),referralCode:i().trim().optional(),consent:f().refine(r=>r===!0,"You must confirm to continue"),marketingOptIn:f().optional(),phone:i().trim().optional().refine(r=>!r||r.replace(/\D/g,"").length>=10,"Enter a valid phone number (at least 10 digits)"),smsOptIn:f().optional(),smsMarketingOptIn:f().optional()}).refine(r=>r.password===r.confirmPassword,{message:"Passwords do not match",path:["confirmPassword"]}).refine(r=>!r.smsOptIn||(r.phone??"").trim().length>0,{message:"Add a phone number to opt in to texts",path:["smsOptIn"]}).refine(r=>!r.smsMarketingOptIn||(r.phone??"").trim().length>0,{message:"Add a phone number to opt in to texts",path:["smsMarketingOptIn"]});function qe(){const{refetch:r}=ne(),[,o]=te(),{toast:d}=Ne(),u=ae(),x=new URLSearchParams(u),h=oe(x.get("redirect"),"/products"),C=q(u),[S,Y]=g.useState([]),[k,P]=g.useState(!1),[O,N]=g.useState(null),s=se({validators:{onChange:Ae},defaultValues:{email:"",password:"",confirmPassword:"",firstName:"",lastName:"",dateOfBirth:"",researcherRole:"",referralCode:D()??"",consent:!1,marketingOptIn:!1,phone:"",smsOptIn:!1,smsMarketingOptIn:!1},onSubmit:async({value:e})=>{await J(e)}}),T=v(s.store,e=>e.values.password),_=v(s.store,e=>e.values.confirmPassword),I=v(s.store,e=>e.values.referralCode),A=v(s.store,e=>e.values.phone),[R,y]=g.useState("unknown");g.useEffect(()=>{const e=(I??"").trim();if(!e){y("unknown");return}y("checking");const a=setTimeout(()=>{(async()=>{try{const p=await(await fetch(`/api/referrals/validate/${encodeURIComponent(e)}`)).json();y(p.valid===!0?"valid":"invalid")}catch{y("unknown")}})()},400);return()=>clearTimeout(a)},[I]);const G=e=>Y(a=>a.includes(e)?a.filter(n=>n!==e):[...a,e]),J=async e=>{P(!0);try{const a=q(typeof window>"u"?u:window.location.search),n=a&&pe(a)?a:null,p=a?ge(a):null,b=n?h:p??h,z=xe({redirectTo:b,oauthContinuation:n}),F=e.firstName.trim(),B=e.lastName.trim(),H=`${F} ${B}`,{data:K,error:V}=await U.signUp.email({email:e.email,password:e.password,name:H,firstName:F,lastName:B,dateOfBirth:e.dateOfBirth,callbackURL:z});if(V){const l=ye(V);if(l.kind==="email-typo"){N(l.description),document.querySelector('[data-testid="input-email"]')?.focus();return}if(l.kind==="account-recovery"){o(je({email:e.email,redirectTo:b,oauthContinuation:n}));return}d({title:l.title,description:l.description,variant:"destructive"});return}await r();const E=(await U.getSession()).data,M=K?.token,W=e.email.trim().toLowerCase(),Q=typeof E?.user?.email=="string"?E.user.email.trim().toLowerCase():"",X=typeof M=="string"&&M.trim().length>0&&Q===W,Z=e.email,ee=e.referralCode?.trim()||D()||void 0;if(X){ve();let l=!1;try{l=(await fetch("/api/users/me/onboarding",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({dateOfBirth:e.dateOfBirth,researcherRole:e.researcherRole,researchAreas:S,consent:!0,referralCode:ee,marketingOptIn:e.marketingOptIn===!0})})).ok}catch{}try{localStorage.setItem("pv-gate-ok","1")}catch{}const L=(e.phone??"").trim();if(L)try{const j=await fetch("/api/users/me/profile",{method:"PATCH",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({phone:L})});j.ok&&e.smsOptIn===!0&&await $({consentType:"sms_transactional",action:"granted",channel:"signup",disclosureSnapshot:"Send me account & security texts (login codes, password resets, payment approvals, support replies). Consent is o
1ptional and never required to use Vida. Reply STOP to cancel. Msg & data rates may apply. See our SMS Policy: /policies/sms-messaging."}).catch(()=>{}),j.ok&&e.smsMarketingOptIn===!0&&await $({consentType:"sms_marketing",action:"granted",channel:"signup",disclosureSnapshot:"Send me product, event & community texts (new drops, restock alerts, events, offers). Consent is optional and never required to use Vida. Reply STOP to cancel. Msg & data rates may apply. See our SMS Policy: /policies/sms-messaging."}).catch(()=>{}),j.ok&&await fetch("/api/users/me/phone/send-otp",{method:"POST",credentials:"include"}).catch(()=>{})}catch{}if(d({title:"Welcome to VidaPeps",description:l?"You earned 250 Vida Points ($5 in research credit).":"Your researcher account is ready."}),n){window.location.assign(`/api/auth/oauth2/authorize?${n}`);return}if(p){window.location.assign(p);return}o(`/verify-email?redirect=${encodeURIComponent(h)}`)}else{try{localStorage.setItem("pv-gate-ok","1"),Pe(localStorage)}catch{}d({title:"Check your email to continue",description:"Check your inbox if a verification message arrives. Otherwise sign in with an existing method."}),o(fe({email:Z,redirectTo:b,oauthContinuation:n}))}}finally{P(!1)}};return t.jsx("div",{className:"min-h-[70vh] flex items-center justify-center px-4 py-8",children:t.jsxs("div",{className:"w-full max-w-sm",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("div",{className:"inline-flex items-center justify-center bg-vida-mint-soft rounded-pill p-3 mb-3",children:t.jsx(Ce,{className:"w-7 h-7 text-vida-green-700","aria-hidden":"true"})}),t.jsx("h1",{className:"font-display text-t2 text-ink",children:"Create Account"}),t.jsx("p",{className:"text-ink-3 text-sm mt-1",children:"Join VidaPeps: one quick step for researchers"})]}),t.jsx("div",{className:"vp-glass rounded-card p-6",children:t.jsxs("form",{onSubmit:e=>{e.preventDefault(),e.stopPropagation(),N(null),s.handleSubmit()},className:"space-y-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsx(s.Field,{name:"firstName",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{htmlFor:e.name,children:"First Name"}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-firstname",autoComplete:"given-name",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"lastName",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{htmlFor:e.name,children:"Last Name"}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-lastname",autoComplete:"family-name",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})})]}),t.jsx(s.Field,{name:"email",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{htmlFor:e.name,children:"Email"}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-email",type:"email",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>{N(null),e.handleChange(a.target.value)}}),O?t.jsx("p",{className:"text-danger text-sm",role:"alert",children:O}):null,(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"password",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{htmlFor:e.name,children:"Password"}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-password",type:"password",autoComplete:"new-password",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),t.jsx(be,{value:T??""}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"confirmPassword",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{htmlFor:e.name,children:"Confirm password"}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-confirm-password",type:"password",autoComplete:"new-password",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),t.jsx(we,{password:T??"",confirm:_??""}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"dateOfBirth",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsxs(c,{htmlFor:e.name,children:["Date of birth"," ",t.jsx("span",{className:"text-muted-foreground font-normal",children:"(21+ required)"})]}),t.jsx(m,{id:e.name,name:e.name,type:"date","data-testid":"input-dob",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"researcherRole",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(c,{children:"How are you using VidaPeps?"}),t.jsxs(ie,{value:e.state.value??"",onValueChange:a=>e.handleChange(a),children:[t.jsx(ce,{"data-testid":"select-role",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring",children:t.jsx(le,{placeholder:"Select your roleâ¦"})}),t.jsx(me,{children:Oe.map(a=>t.jsx(de,{value:a,children:a},a))})]}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsxs("div",{children:[t.jsxs("p",{className:"text-sm font-medium mb-2",children:["Primary research areas"," ",t.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),t.jsx("div",{className:"flex flex-wrap gap-2",children:Te.map(e=>t.jsx("button",{type:"button",onClick:()=>G(e),className:ue("text-xs px-3 py-1.5 rounded-full border transition-colors",S.includes(e)?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-secondary"),children:e},e))})]}),t.jsx(s.Field,{name:"referralCode",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsxs(c,{htmlFor:e.name,children:["Referral code"," ",t.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),t.jsx(m,{id:e.name,name:e.name,"data-testid":"input-referral-code",placeholder:"e.g. PV0042",autoCapitalize:"characters",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Invited by a colleague? Enter their code and you'll both earn 250 Vida Points ($5 in research credit) when your first order of $50+ is paid."}),R==="valid"&&t.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:"Code found. You're both eligible for the referral reward."}),R==="invalid"&&t.jsx("p",{className:"text-xs text-amber-600 dar
1k:text-amber-400",children:"We can't find that code. Check for a typo or leave it blank; you can also enter one later from your account."}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"consent",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:!!e.state.value,onChange:a=>e.handleChange(a.target.checked),"data-testid":"checkbox-consent",className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),t.jsx("span",{className:"text-xs text-muted-foreground leading-snug",children:"I confirm I am a qualified researcher purchasing for in-vitro / laboratory research only, not for human or veterinary use."})]}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}),t.jsx(s.Field,{name:"marketingOptIn",children:e=>t.jsx("div",{className:"space-y-2",children:t.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:!!e.state.value,onChange:a=>e.handleChange(a.target.checked),"data-testid":"checkbox-marketing-optin",className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),t.jsx("span",{className:"text-xs text-muted-foreground leading-snug",children:"Send me new-compound drops, restock alerts and Vida Points offers by email. A couple of emails a month, unsubscribe anytime."})]})})}),t.jsx(s.Field,{name:"phone",children:e=>t.jsxs("div",{className:"space-y-2",children:[t.jsxs(c,{htmlFor:e.name,children:["Mobile number"," ",t.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),t.jsx(m,{id:e.name,name:e.name,type:"tel",autoComplete:"tel-national",placeholder:"+1 (555) 000-0000","data-testid":"input-phone",value:e.state.value??"",onBlur:e.handleBlur,onChange:a=>e.handleChange(a.target.value)}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"For account security texts (login codes, password resets, payment approvals) and support, and, if you choose, product & community texts. Never required to create an account."})]})}),t.jsx(s.Field,{name:"smsOptIn",children:e=>{const a=(A??"").trim().length===0;return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:!!e.state.value,onChange:n=>e.handleChange(n.target.checked),disabled:a,"data-testid":"checkbox-sms-optin",className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),t.jsxs("span",{className:"text-xs text-muted-foreground leading-snug",children:["Send me account & security texts (login codes, password resets, payment approvals, support replies). Consent is"," ",t.jsx("strong",{children:"optional and never required"})," to use Vida. Reply STOP to cancel. Msg & data rates may apply. See our"," ",t.jsx("a",{href:"/policies/sms-messaging",className:"text-primary hover:underline",children:"SMS Policy"}),"."]})]}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}}),t.jsx(s.Field,{name:"smsMarketingOptIn",children:e=>{const a=(A??"").trim().length===0;return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:!!e.state.value,onChange:n=>e.handleChange(n.target.checked),disabled:a,"data-testid":"checkbox-sms-marketing-optin",className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),t.jsxs("span",{className:"text-xs text-muted-foreground leading-snug",children:["Send me product, event & community texts (new drops, restock alerts, events, offers). Consent is optional and never required to use Vida. Reply STOP to cancel. Msg & data rates may apply. See our"," ",t.jsx("a",{href:"/policies/sms-messaging",className:"text-primary hover:underline",children:"SMS Policy"}),"."]})]}),(e.state.meta.isTouched||s.state.submissionAttempts>0)&&e.state.meta.errors.length>0?t.jsx("p",{className:"text-danger text-sm",children:String(e.state.meta.errors[0]?.message??e.state.meta.errors[0])}):null]})}}),t.jsxs("p",{className:"text-[11px] leading-snug text-muted-foreground",children:["By creating an account, you agree to our"," ",t.jsx(w,{href:"/legal/terms",className:"text-primary hover:underline",children:"Terms of Service"})," ","and"," ",t.jsx(w,{href:"/legal/privacy",className:"text-primary hover:underline",children:"Privacy Policy"}),". Consent to texts is optional and never required to purchase."]}),t.jsx(he,{type:"submit",className:"w-full",disabled:k,"data-testid":"button-register",children:k?"Creating accountâ¦":"Create Account"})]})}),t.jsxs("p",{className:"text-center text-sm text-muted-foreground mt-4",children:["Already have an account?"," ",t.jsx(w,{href:C?`/login?${C}`:`/login${h!=="/products"?`?redirect=${encodeURIComponent(h)}`:""}`,className:"text-primary hover:underline font-medium","data-testid":"link-login",children:"Sign in"})]})]})})}export{qe 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.