1import{ar as q,$ as R,r as a,j as e,ad as N,a6 as l,s as y,aa as o}from"./index-CEqNdWMB.js";import{L as d}from"./label-MzaZtEZW.js";import{L as b}from"./loader-circle-CSZF46_Z.js";import{C as T}from"./circle-x-4Dtqh7eE.js";import{C as D}from"./circle-check-big-ChHJte_B.js";const M=()=>{const[C]=q(),m=R(),r=C.get("token")||"",[S,u]=a.useState(!0),[i,k]=a.useState(null),[x,h]=a.useState(""),[f,P]=a.useState(""),[p,v]=a.useState(""),[n,E]=a.useState(""),[g,A]=a.useState(""),[j,w]=a.useState(!1),[L,F]=a.useState(!1);a.useEffect(()=>{if(!r){h("No invite token provided"),u(!1);return}(async()=>{const{data:s,error:c}=await y.functions.invoke("validate-admin-invite",{body:{token:r}});c||!(s!=null&&s.valid)?h("This invite link is invalid or has expired."):(k({email:s.email,role:s.role}),s.email&&v(s.email)),u(!1)})()},[r]);const I=async t=>{if(t.preventDefault(),n!==g){o({title:"Passwords do not match",variant:"destructive"});return}if(n.length<8){o({title:"Password must be at least 8 characters",variant:"destructive"});return}w(!0);const{data:s,error:c}=await y.functions.invoke("accept-admin-invite",{body:{token:r,email:p,password:n,display_name:f}});if(c||s!=null&&s.error){o({title:(s==null?void 0:s.error)||"Failed to create account",variant:"destructive"}),w(!1);return}F(!0),o({title:"Account created! Redirecting to loginâ¦"}),setTimeout(()=>m("/admin/login"),2e3)};return S?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsx(b,{className:"h-8 w-8 text-primary animate-spin"})}):x||!i?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsxs("div",{className:"max-w-md w-full mx-4 p-8 bg-background rounded-2xl shadow-lg text-center space-y-4",children:[e.jsx(T,{className:"h-12 w-12 text-destructive mx-auto"}),e.jsx("h1",{className:"font-display text-xl font-semibold text-foreground",children:"Invalid Invite"}),e.jsx("p",{className:"text-muted-foreground",children:x||"This invite link is invalid or has expired."}),e.jsx(N,{variant:"outline",onClick:()=>m("/admin/login"),children:"Go to Login"})]})}):L?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsxs("div",{className:"max-w-md w-full mx-4 p-8 bg-background rounded-2xl shadow-lg text-center space-y-4",children:[e.jsx(D,{className:"h-12 w-12 text-green-600 mx-auto"}),e.jsx("h1",{className:"font-display text-xl font-semibold text-foreground",children:"Account Created!"}),e.jsx("p",{className:"text-muted-foreground",children:"Redirecting to loginâ¦"})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsxs("div",{className:"max-w-md w-full mx-4 p-8 bg-background rounded-2xl shadow-lg space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-2xl font-bold text-foreground",children:"Join the Admin Team"}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:["You've been invited as ",e.jsx("span",{className:"font-medium capitalize text-foreground",children:i.role})]})]}),e.jsxs("form",{onSubmit:I,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(d,{htmlFor:"displayName",children:"Display Name"}),e.jsx(l,{id:"displayName",value:f,onChange:t=>P(t.target.value),placeholder:"Your name",required:!0})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"email",children:"Email"}),e.jsx(l,{id:"email",type:"email",value:p,onChange:t=>v(t.target.value),placeholder:"[email protected]",disabled:!!i.email,required:!0}),i.email&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Email is locked to the invite"})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"password",children:"Password"}),e.jsx(l,{id:"password",type:"password",value:n,onChange:t=>E(t.target.value),placeholder:"Min 8 characters",minLength:8,required:!0})]}),e.jsxs("div",{children:[e.jsx(d,{htmlFor:"confirmPassword",children:"Confirm Password"}),e.jsx(l,{id:"confirmPassword",type:"password",value:g,onChange:t=>A(t.target.value),placeholder:"Repeat password",required:!0})]}),e.jsx(N,{type:"submit",className:"w-full",disabled:j,children:j?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"mr-2 h-4 w-4 animate-spin"})," Creating Accountâ¦"]}):"Create Account"})]})]})})};export{M 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.