1import{r as s,j as e}from"./react-vendor-C6y0N-UU.js";import{a as Z,b as $}from"./router-BuhIhnD8.js";import{C as g,a as j,B as L,q as V,r as W,t as X,L as b,I as N,s as w,n as y}from"./index-CnpPKFhq.js";import{L as T}from"./icons-2-BVzGyqgJ.js";import{c0 as Y}from"./icons-7-Bui2Uquv.js";import{E as v,Z as A,H as D}from"./icons-3-BrmsbS4V.js";import{bG as z}from"./icons-4-B7e-xXFY.js";import{ak as I}from"./icons-1-BkWJxPhL.js";import"./query-DeOE_qRu.js";import"./ui-utils--X5BZniO.js";import"./supabase-CvSt4Gf_.js";import"./icons-0-ZQxtvqGv.js";import"./icons-core-DW9tYJLE.js";import"./icons-5-B1da48r5.js";import"./icons-6-i_x7JPbL.js";function J(t){return{minLength:t.length>=8,hasUpper:/[A-Z]/.test(t),hasNumber:/[0-9]/.test(t),hasSpecial:/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(t)}}function he(){const[t]=Z(),o=$(),i=t.get("token"),[R,c]=s.useState(!0),[k,q]=s.useState(null),[C,m]=s.useState(null),[n,F]=s.useState(""),[d,O]=s.useState(""),[p,U]=s.useState(!1),[f,_]=s.useState(!1),[S,P]=s.useState(!1),[B,G]=s.useState(!1),r=s.useMemo(()=>J(n),[n]),E=r.minLength&&r.hasUpper&&r.hasNumber&&r.hasSpecial,u=n===d&&d.length>0;s.useEffect(()=>{async function l(){if(!i){m("No setup token provided. Please use the link from your approval email."),c(!1);return}const{data:a,error:h}=await w.from("reseller_setup_tokens").select("*").eq("token",i).maybeSingle();if(h||!a){m("Invalid setup token. Please check your approval email for the correct link."),c(!1);return}if(a.used){m("This setup link has already been used. If you've already created your account, please log in."),c(!1);return}if(new Date(a.expires_at)<new Date){m("This setup link has expired. Please contact [email protected] for a new link."),c(!1);return}q(a),c(!1)}l()},[i]);const H=async l=>{if(l.preventDefault(),!(!E||!u||!i)){P(!0);try{const{data:a,error:h}=await w.functions.invoke("reseller-setup-account",{body:{token:i,password:n}});if(h)throw new Error(h.message||"Setup failed");if(a?.error)throw new Error(a.error);G(!0),y.success("Account created! Signing you in...");const{error:M}=await w.auth.signInWithPassword({email:k.email,password:n});M?(y.error("Account created but auto-login failed. Please log in manually."),setTimeout(()=>o("/login"),2e3)):setTimeout(()=>o("/reseller-dashboard"),1500)}catch(a){y.error(a.message||"Failed to create account")}finally{P(!1)}}};return R?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(T,{className:"h-8 w-8 animate-spin text-primary"})}):C?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsx(g,{className:"max-w-md w-full",children:e.jsxs(j,{className:"py-12 text-center",children:[e.jsx(Y,{className:"h-12 w-12 mx-auto mb-4 text-amber-500"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Setup Link Issue"}),e.jsx("p",{className:"text-muted-foreground text-sm mb-6",children:C}),e.jsx(L,{onClick:()=>o("/login"),variant:"outline",children:"Go to Login"})]})})}):B?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsx(g,{className:"max-w-md w-full",children:e.jsxs(j,{className:"py-12 text-center",children:[e.jsx(v,{className:"h-12 w-12 mx-auto mb-4 text-emerald-500"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Account Created!"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Redirecting to your reseller dashboard..."})]})})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs(g,{className:"max-w-md w-full",children:[e.jsxs(V,{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-primary/10 flex items-center justify-center mx-auto mb-3",children:e.jsx(z,{className:"h-6 w-6 text-primary"})}),e.jsx(W,{className:"text-xl",children:"Set Up Your Reseller Account"}),e.jsx(X,{children:"Create your login credentials to access your reseller dashboard"})]}),e.jsx(j,{children:e.jsxs("form",{onSubmit:H,className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Email"}),e.jsx(N,{value:k?.email||"",disabled:!0,className:"bg-muted"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This is the email from your application"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"password",type:p?"text":"password",value:n,onChange:l=>F(l.target.value),placeholder:"Create a strong password",className:"pr-10"}),e.jsx("button",{type:"button",onClick:()=>U(!p),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:p?e.jsx(A,{className:"h-4 w-4"}):e.jsx(I,{className:"h-4 w-4"})})]})]}),n.length>0&&e.jsxs("div",{className:"space-y-1.5 rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Password requirements"}),e.jsx(x,{met:r.minLength,label:"At least 8 characters"}),e.jsx(x,{met:r.hasUpper,label:"One uppercase letter"}),e.jsx(x,{met:r.hasNumber,label:"One number"}),e.jsx(x,{met:r.hasSpecial,label:"One special character (!@#$...)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"confirm",children:"Confirm Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"confirm",type:f?"text":"password",value:d,onChange:l=>O(l.target.value),placeholder:"Re-enter your password",className:"pr-10"}),e.jsx("button",{type:"button",onClick:()=>_(!f),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:f?e.jsx(A,{className:"h-4 w-4"}):e.jsx(I,{className:"h-4 w-4"})})]}),d.length>0&&!u&&e.jsxs("p",{className:"text-xs text-destructive flex items-center gap-1",children:[e.jsx(D,{className:"h-3 w-3"})," Passwords do not match"]}),u&&e.jsxs("p",{className:"text-xs text-emerald-500 flex items-center gap-1",children:[e.jsx(v,{className:"h-3 w-3"})," Passwords match"]})]}),e.jsx(L,{type:"submit",className:"w-full",disabled:!E||!u||S,children:S?e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"h-4 w-4 animate-spin mr-2"}),"Creating Account..."]}):"Create Account & Sign In"})]})})]})})}function x({met:t,label:o}){return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[t?e.jsx(v,{className:"h-3.5 w-3.5 text-emerald-500 shrink-0"}
1):e.jsx(D,{className:"h-3.5 w-3.5 text-muted-foreground/50 shrink-0"}),e.jsx("span",{className:t?"text-foreground":"text-muted-foreground",children:o})]})}export{he 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.