1import{e as se,af as ne,w as re,_ as ie,r,b7 as p,s as I,b8 as oe,j as e,b as O,x as le,m as ce,C as ue,B as y,L as me,a as m,S as L,z as A,D as E,F as P,G as _,M as W,I as v,b9 as B}from"./index-BemFr6U8.js";import{M as F}from"./map-pin-DMYbbIU0.js";import{L as de}from"./lock-DP5hQLSN.js";const T=["United Kingdom","Ireland","United States","Canada","Australia","New Zealand","France","Germany","Netherlands","Spain","Italy","Portugal","Belgium","Switzerland","Sweden","Norway","Denmark","Finland","Poland","United Arab Emirates","Singapore","Hong Kong","India","South Africa","Other"],h=c=>`waddyado_b2b_country_${c.slice(0,16)}`,q=(c,j)=>c instanceof Error?c.message:j;function fe(){const c=se(),[j]=ne(),a=j.get("token")??"",{user:b,isLoading:w,refreshProfile:U}=re(),{toast:o}=ie(),[n,K]=r.useState(null),[x,R]=r.useState(""),[g,G]=r.useState(""),[$,H]=r.useState(""),[l,N]=r.useState(""),[J,S]=r.useState(!0),[M,V]=r.useState(!1),[f,D]=r.useState(!1),[C,Z]=r.useState(!1),[z,d]=r.useState(null),Q=!!b,X=r.useMemo(()=>n!=null&&n.company_name?`Join ${n.company_name} on Waddyado`:"Activate your Waddyado account",[n==null?void 0:n.company_name]);r.useEffect(()=>{if(!a){d("This activation link is missing an invite token."),S(!1);return}p(a);let t=!0;return S(!0),I.functions.invoke("b2b-claim-invite",{body:{action:"lookup",token:a}}).then(({data:s,error:i})=>{if(!t)return;if(i||s!=null&&s.error){d((s==null?void 0:s.error)||(i==null?void 0:i.message)||"Invite not found.");return}const u=s.invite;K(u),R(u.email)}).finally(()=>{t&&S(!1)}),()=>{t=!1}},[a]);const k=r.useCallback(async t=>{if(a){D(!0),d(null);try{const{data:s,error:i}=await I.functions.invoke("b2b-claim-invite",{body:{action:"claim",token:a,country:t}});if(i||s!=null&&s.error)throw new Error((s==null?void 0:s.error)||(i==null?void 0:i.message)||"Could not activate invite");localStorage.removeItem(h(a)),oe(),await U(),o({title:"Account activated",description:"Letâs personalise your experience."}),c("/onboarding",{replace:!0})}catch(s){d(q(s,"Could not activate your invite."))}finally{D(!1)}}},[c,U,o,a]);r.useEffect(()=>{if(!a||!b||w||f||C)return;const t=localStorage.getItem(h(a));t&&k(t)},[a,b,w,f,C,k]);const Y=async t=>{if(t.preventDefault(),!n)return;const s=x.trim().toLowerCase();if(s!==n.email.toLowerCase()){o({title:"Use the invited email address",description:`This invite was issued to ${n.email}.`,variant:"destructive"});return}if(g.length<8){o({title:"Password too short",description:"Use at least 8 characters.",variant:"destructive"});return}if(g!==$){o({title:"Passwords do not match",variant:"destructive"});return}if(!l){o({title:"Select your country",variant:"destructive"});return}V(!0),d(null);try{localStorage.setItem(h(a),l),p(a);const i=B(a),{error:u}=await I.auth.signUp({email:s,password:g,options:{emailRedirectTo:`${window.location.origin}/auth/callback?returnTo=${encodeURIComponent(i)}`,data:{first_name:n.first_name,last_name:n.last_name,signup_source:"b2b_invite"}}});if(u)throw u;Z(!0),o({title:"Check your inbox",description:"Verify your email to finish activating your account."})}catch(i){const u=q(i,"Could not create your account.");if(/already registered|already exists|user already/i.test(u)){localStorage.setItem(h(a),l),p(a),o({title:"Account already exists",description:"Log in to activate your company access."});const ae=new URLSearchParams({returnTo:B(a),email:s});c(`/login?${ae.toString()}`);return}localStorage.removeItem(h(a)),d(u)}finally{V(!1)}},ee=async t=>{if(t.preventDefault(),!l){o({title:"Select your country",variant:"destructive"});return}await k(l)},te=t=>{if(t.preventDefault(),!l){o({title:"Select your country",variant:"destructive"});return}localStorage.setItem(h(a),l),p(a);const s=new URLSearchParams({returnTo:B(a),email:x});c(`/login?${s.toString()}`)};return w||J||f?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(O,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"p-6 flex justify-center",children:e.jsx(le,{size:"lg"})}),e.jsx("main",{className:"flex justify-center px-4 pb-16",children:e.jsx(ce.div,{initial:{opacity:0,y:16}
1,animate:{opacity:1,y:0},className:"w-full max-w-md",children:e.jsx("div",{className:"bg-card rounded-xl border border-border p-7 sm:p-9 shadow-sm",children:C?e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(ue,{className:"w-12 h-12 text-primary mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Check your email"}),e.jsxs("p",{className:"text-sm text-muted-foreground leading-relaxed",children:["We sent a verification link to ",e.jsx("strong",{children:x}),". Open it to finish activating your company account."]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground mb-3 leading-tight",children:X}),e.jsx("p",{className:"text-sm text-muted-foreground mb-7 leading-relaxed",children:"Create your login, confirm your country, then verify your email."}),z&&e.jsx("div",{className:"bg-destructive/10 text-destructive rounded-md px-3 py-2 text-sm mb-5",children:z}),!a||!n?e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:"This activation link is invalid or expired. Ask your Waddyado administrator for a fresh invite."}),e.jsx(y,{asChild:!0,variant:"outline",className:"w-full",children:e.jsx(me,{to:"/login",children:"Back to login"})})]}):Q?e.jsxs("form",{onSubmit:ee,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"country",className:"mb-2 flex items-center gap-2",children:[e.jsx(F,{className:"w-3.5 h-3.5"})," Country"]}),e.jsxs(L,{value:l,onValueChange:N,children:[e.jsx(A,{id:"country",className:"h-11 px-4",children:e.jsx(E,{placeholder:"Select your country"})}),e.jsx(P,{children:T.map(t=>e.jsx(_,{value:t,children:t},t))})]})]}),e.jsx(y,{type:"submit",className:"w-full h-11",disabled:f,children:"Finish activation"})]}):n.account_exists?e.jsxs("form",{onSubmit:te,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"email",className:"mb-2 flex items-center gap-2",children:[e.jsx(W,{className:"w-3.5 h-3.5"})," Email"]}),e.jsx(v,{id:"email",type:"email",autoComplete:"email",readOnly:!0,value:x,className:"h-11 px-4"})]}),e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"country-existing",className:"mb-2 flex items-center gap-2",children:[e.jsx(F,{className:"w-3.5 h-3.5"})," Country"]}),e.jsxs(L,{value:l,onValueChange:N,children:[e.jsx(A,{id:"country-existing",className:"h-11 px-4",children:e.jsx(E,{placeholder:"Select your country"})}),e.jsx(P,{children:T.map(t=>e.jsx(_,{value:t,children:t},t))})]})]}),e.jsx(y,{type:"submit",className:"w-full h-11 mt-2",children:"Log in to activate account"})]}):e.jsxs("form",{onSubmit:Y,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"email",className:"mb-2 flex items-center gap-2",children:[e.jsx(W,{className:"w-3.5 h-3.5"})," Email"]}),e.jsx(v,{id:"email",type:"email",autoComplete:"email",required:!0,value:x,onChange:t=>R(t.target.value),className:"h-11 px-4"})]}),e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"password",className:"mb-2 flex items-center gap-2",children:[e.jsx(de,{className:"w-3.5 h-3.5"})," Create password"]}),e.jsx(v,{id:"password",type:"password",autoComplete:"new-password",required:!0,minLength:8,value:g,onChange:t=>G(t.target.value),placeholder:"At least 8 characters",className:"h-11 px-4"})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"confirm",className:"mb-2",children:"Confirm password"}),e.jsx(v,{id:"confirm",type:"password",autoComplete:"new-password",required:!0,minLength:8,value:$,onChange:t=>H(t.target.value),className:"h-11 px-4"})]}),e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"country",className:"mb-2 flex items-center gap-2",children:[e.jsx(F,{className:"w-3.5 h-3.5"})," Country"]}),e.jsxs(L,{value:l,onValueChange:N,children:[e.jsx(A,{id:"country",className:"h-11 px-4",children:e.jsx(E,{placeholder:"Select your country"})}),e.jsx(P,{children:T.map(t=>e.jsx(_,{value:t,children:t},t))})]})]}),e.jsx(y,{type:"submit",className:"w-full h-11 mt-2",disabled:M,children:M?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"w-4 h-4 mr-2 animate-spin"})," Creating account..."]}):"Register & verify email"})]})]})})})})]})}export{fe 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.