1import{aI as I,r as i,i as U,at as H,u as M,j as e,L as A,t as o,q as R,ah as z,R as B,U as w}from"./index-Dm8RZsL9.js";import{E as V}from"./eye-off-BR9QyHvV.js";import{E as J}from"./eye-BQaoAMPw.js";const G=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,W=/^(70[1-8]|80[2-9]|81[0-8]|90[1-9]|91[0-8])\d{7}$/,K=B({name:w().trim().min(2,"Enter your name").max(80),email:w().trim().email("Enter a valid email").max(255),phone:w().trim().regex(W,"Enter a valid Nigerian phone (e.g. 8012345678)"),password:w().min(8,"At least 8 characters").max(72)});async function C(l,m){const d=await fetch(`${z}${l}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}),s=await d.json().catch(()=>({}));if(!d.ok||s?.success===!1)throw new Error(s?.error||s?.message||`Request failed (${d.status})`);return s?.data??s}function Z(){const{redirect:l,ref:m,mode:d}=I.useSearch(),[s,h]=i.useState(d==="signup"||m?"signup":"signin"),[x,u]=i.useState("email"),p=U(),g=H(),{isAuthenticated:P}=M(),b=l&&l.startsWith("/")&&!l.startsWith("//")?l:"/",k=m?.trim()||null;i.useEffect(()=>{P&&p({to:b})},[P,p,b]);const[O,$]=i.useState(!1);async function L(a){a.preventDefault();const r=new FormData(a.currentTarget),n=String(r.get("password")??"");if(!n)return o.error("Enter your password");const f={password:n};if(x==="email"){const t=String(r.get("emailOrPhone")??"").trim();if(!G.test(t))return o.error("Enter a valid email");f.email=t}else{const t=String(r.get("emailOrPhone")??"").replace(/\D/g,""),c=t.startsWith("0")?t.slice(1):t.startsWith("234")?t.slice(3):t;if(!W.test(c))return o.error("Enter a valid Nigerian phone");f.phone_number=`+234${c}`}$(!0);try{const t=await C("/auth/sign-in",f);R({user:t.user,tokens:{access_token:t.tokens?.access_token??t.access_token,refresh_token:t.tokens?.refresh_token??t.refresh_token,stream_token:t.tokens?.stream_token??t.stream_token}}),o.success(`Welcome back, ${t.user.name?.split(" ")[0]??""}!`),g.invalidate(),p({to:b})}catch(t){o.error(t.message)}finally{$(!1)}}const[v,S]=i.useState("form"),[E,D]=i.useState(null),[_,T]=i.useState(""),[y,j]=i.useState(!1);async function q(a){a.preventDefault();const r=new FormData(a.currentTarget),n=String(r.get("phone")??"").replace(/\D/g,""),f=n.startsWith("0")?n.slice(1):n.startsWith("234")?n.slice(3):n,t=K.safeParse({name:r.get("name"),email:r.get("email"),phone:f,password:r.get("password")});if(!t.success)return o.error(t.error.issues[0].message);j(!0);try{const c={name:t.data.name,email:t.data.email,phone_number:`+234${t.data.phone}`,password:t.data.password,referral_code:k};await C("/auth/initialize-registration",c),D(c),S("otp"),o.success("We sent a 6-digit code to your phone")}catch(c){o.error(c.message)}finally{j(!1)}}async function F(a){if(a.preventDefault(),!!E){if(_.length!==6)return o.error("Enter the 6-digit code");j(!0);try{const r=await C("/auth/sign-up",{...E,otp_code:_}),n=r.tokens??r;R({user:r.user,tokens:{access_token:n.access_token,refresh_token:n.refresh_token,stream_token:n.stream_token}}),o.success("Welcome to Havyn!"),g.invalidate(),p({to:b})}catch(r){o.error(r.message)}finally{j(!1)}}}return e.jsx("div",{className:"min-h-[calc(100vh-180px)] grid place-items-center px-4 py-10",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s==="signin"?"Welcome back":v==="form"?"Create your account":"Verify your phone"}),e.jsx("p",{className:"mt-1.5 text-sm text-muted-foreground",children:s==="signin"?"Sign in to your Havyn account":v==="form"?"Join Nigeria's peer-to-peer marketplace":`Enter the 6-digit code sent to ${E?.phone_number}`})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 shadow-soft",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-1 rounded-full bg-muted p-1 mb-6",children:[e.jsx("button",{type:"button",onClick:()=>{h("signin"),S("form")},className:`rounded-full py-2 text-sm font-semibold transition ${s==="signin"?"bg-background shadow-sm":"text-muted-foreground"}`,children:"Sign in"}),e.jsx("button",{type:"button",onClick:()=>h("signup"),className:`rounded-full py-2 text-sm font-semibold transition ${s==="signup"?"bg-background shadow-sm":"text-muted-foreground"}`,children:"Create account"})]}),s==="signin"?e.jsxs("form",{onSubmit:L,className:"space-y-4",children:[x==="email"?e.jsxs("label",{className:"block",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground
1/80",children:"Email"}),e.jsx("button",{type:"button",onClick:()=>u("phone"),className:"text-xs font-semibold text-primary hover:text-primary/80 transition",children:"Use phone instead"})]}),e.jsx("input",{name:"emailOrPhone",type:"email",placeholder:"[email protected]",autoComplete:"email",required:!0,className:"mt-1.5 w-full rounded-xl border border-border bg-background px-4 py-2.5 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/20"})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground/80",children:"Phone number"}),e.jsx("button",{type:"button",onClick:()=>u("email"),className:"text-xs font-semibold text-primary hover:text-primary/80 transition",children:"Use email instead"})]}),e.jsxs("div",{className:"mt-1.5 flex rounded-xl border border-border bg-background overflow-hidden transition focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/20",children:[e.jsx("select",{disabled:!0,className:"bg-muted/60 px-3 py-2.5 text-sm font-medium text-foreground outline-none border-r border-border cursor-default",children:e.jsx("option",{children:"ð³ð¬ +234"})}),e.jsx("input",{name:"emailOrPhone",type:"tel",placeholder:"8131588335",autoComplete:"tel",required:!0,className:"flex-1 bg-transparent px-4 py-2.5 text-sm outline-none placeholder:text-muted-foreground"})]}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Enter your number without the leading 0."})]}),e.jsx(N,{label:"Password",name:"password",type:"password",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",autoComplete:"current-password",togglePassword:!0}),e.jsx("div",{className:"flex justify-end -mt-2",children:e.jsx(A,{to:"/forgot-password",className:"text-xs font-semibold text-primary hover:text-primary/80 transition",children:"Forgot password?"})}),e.jsx("button",{type:"submit",disabled:O,className:"w-full rounded-full brand-gradient py-3 text-sm font-semibold text-primary-foreground shadow-soft hover:opacity-95 transition disabled:opacity-60",children:O?"Signing in...":"Sign in"})]}):v==="form"?e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[k&&e.jsxs("div",{className:"rounded-xl border border-primary/30 bg-primary/5 px-3 py-2 text-xs text-foreground/80",children:["Referral code applied: ",e.jsx("span",{className:"font-semibold text-primary",children:k})]}),e.jsx(N,{label:"Full name",name:"name",placeholder:"Ada Okeke",autoComplete:"name"}),e.jsx(N,{label:"Email",name:"email",type:"email",placeholder:"[email protected]",autoComplete:"email"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-foreground/80",children:"Phone number"}),e.jsxs("div",{className:"mt-1.5 flex rounded-xl border border-border bg-background overflow-hidden transition focus-within:border-primary focus-within:ring-2 focus-within:ring-primary/20",children:[e.jsx("select",{disabled:!0,className:"bg-muted/60 px-3 py-2.5 text-sm font-medium text-foreground outline-none border-r border-border cursor-default",children:e.jsx("option",{children:"ð³ð¬ +234"})}),e.jsx("input",{name:"phone",type:"tel",placeholder:"8012345678",autoComplete:"tel",required:!0,className:"flex-1 bg-transparent px-4 py-2.5 text-sm outline-none placeholder:text-muted-foreground"})]}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Enter your number without the leading 0."})]}),e.jsx(N,{label:"Password",name:"password",type:"password",placeholder:"At least 8 characters",autoComplete:"new-password",togglePassword:!0}),e.jsx("button",{type:"submit",disabled:y,className:"w-full rounded-full brand-gradient py-3 text-sm font-semibold text-primary-foreground shadow-soft hover:opacity-95 transition disabled:opacity-60",children:y?"Sending code...":"Continue"}),e.jsx("p",{className:"text-[11px] text-muted-foreground text-center leading-relaxed",children:"By creating an account you agree to Havyn's terms and privacy policy."})]}):e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground
1/80",children:"6-digit code"}),e.jsx("input",{inputMode:"numeric",maxLength:6,value:_,onChange:a=>T(a.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"123456",className:"mt-1.5 w-full rounded-xl border border-border bg-background px-4 py-3 text-center text-lg tracking-[0.5em] font-bold outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/20"})]}),e.jsx("button",{type:"submit",disabled:y,className:"w-full rounded-full brand-gradient py-3 text-sm font-semibold text-primary-foreground shadow-soft disabled:opacity-60",children:y?"Verifying...":"Verify & create account"}),e.jsx("button",{type:"button",onClick:()=>S("form"),className:"w-full text-xs text-muted-foreground hover:text-foreground",children:"â Back to details"})]})]}),e.jsx("p",{className:"mt-6 text-center text-sm text-muted-foreground",children:e.jsx(A,{to:"/",className:"hover:text-foreground transition",children:"â Back to browsing"})})]})})}function N({label:l,name:m,type:d="text",placeholder:s,autoComplete:h,togglePassword:x}){const[u,p]=i.useState(!1),g=x?u?"text":"password":d;return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground/80",children:l}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx("input",{name:m,type:g,placeholder:s,autoComplete:h,required:!0,className:"w-full rounded-xl border border-border bg-background px-4 py-2.5 text-sm outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/20 pr-10"}),x&&e.jsx("button",{type:"button",onClick:()=>p(!u),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition",children:u?e.jsx(V,{size:18}):e.jsx(J,{size:18})})]})]})}export{Z 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.