1import{b as e,c as s,r as a,j as i}from"./vendor-react-BH6F5oQJ.js";import{C as t,m as r,M as n,N as l,O as d,f as c,G as o,s as m,D as p}from"./index-dRqPaCFl.js";import{L as u}from"./label-RVODh2pd.js";import{A as x,a as h}from"./alert-Bi7u5HD8.js";import{H as j,I as v}from"./vendor-icons-CaI5__By.js";import{o as f,s as w}from"./types-BnfuoFvn.js";import"./vendor-ui-B4WC06Sp.js";import"./vendor-query-CC4VRGyP.js";import"./vendor-supabase-COwyE4EW.js";const g=f({email:w().email("Invalid email address"),password:w().min(8,"Password must be at least 8 characters"),confirmPassword:w(),displayName:w().min(2,"Name must be at least 2 characters")}).refine(e=>e.password===e.confirmPassword,{message:"Passwords do not match",path:["confirmPassword"]}),y=()=>{const f=e(),[w]=s(),[y,N]=a.useState(""),[b,k]=a.useState(""),[P,_]=a.useState(""),[S,C]=a.useState(""),[R,q]=a.useState(!1),[E,F]=a.useState(!0),[I,A]=a.useState(!1),[T,Y]=a.useState(""),[D,L]=a.useState(null),G=w.get("token");a.useEffect(()=>{(async()=>{if(G)try{const{data:e,error:s}=await m.rpc("validate_invitation_token",{p_token:G}),a=null==e?void 0:e[0];s||!a?(p({title:"Invalid invitation",description:"This invitation link is invalid, expired, or has already been used.",variant:"destructive"}),A(!1)):(A(!0),Y(a.email),N(a.email),L(a.role))}catch(e){A(!1)}finally{F(!1)}else F(!1)})()},[G]);return E?i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsx(t,{className:"w-full max-w-md",children:i.jsx(r,{className:"pt-6",children:i.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[i.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary"}),i.jsx("p",{className:"text-muted-foreground",children:"Validating invitation..."})]})})})}):G&&I?i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs(t,{className:"w-full max-w-md",children:[i.jsxs(n,{className:"space-y-1",children:[i.jsx("div",{className:"flex items-center justify-center mb-4",children:i.jsx(v,{className:"h-8 w-8 text-primary"})}),i.jsx(l,{className:"text-2xl text-center",children:"Admin Registration"}),i.jsx(d,{className:"text-center",children:"Complete your registration to request admin access"})]}),i.jsxs(r,{children:[i.jsx(x,{className:"mb-4",children:i.jsxs(h,{children:["You're registering with: ",i.jsx("strong",{children:T}),D&&i.jsxs(i.Fragment,{children:[" ","as ",i.jsx("strong",{children:D})]})]})}),i.jsxs("form",{onSubmit:async e=>{e.preventDefault(),q(!0);try{const e=g.safeParse({email:y,password:b,confirmPassword:P,displayName:S});if(!e.success){const s=e.error.errors.map(e=>e.message).join(", ");throw new Error(s)}if(!G)throw new Error("No valid invitation token");const s=`${window.location.origin}/admin/pending-approval`,{data:a,error:i}=await m.auth.signUp({email:e.data.email,password:e.data.password,options:{emailRedirectTo:s,data:{display_name:e.data.displayName}}});if(i)throw i;if(a.user){const{error:s}=await m.rpc("consume_invitation_token",{p_token:G,p_user_id:a.user.id,p_display_name:e.data.displayName});if(s)throw s}p({title:"Registration submitted",description:"Your registration is pending admin approval. You will be notified via email once approved."}),setTimeout(()=>{f("/admin/pending-approval")},2e3)}catch(s){p({title:"Error",description:s.message||"Registration failed. Please contact support.",variant:"destructive"})}finally{q(!1)}},className:"space-y-4",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsx(u,{htmlFor:"displayName",children:"Full name"}),i.jsx(o,{id:"displayName",type:"text",placeholder:"Your name",value:S,onChange:e=>C(e.target.value),required:!0})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx(u,{htmlFor:"email",children:"Email"}),i.jsx(o,{id:"email",type:"email",value:y,disabled:!0,className:"bg-muted"})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx(u,{htmlFor:"password",children:"Password"}),i.jsx(o,{id:"password",type:"password",placeholder:"Enter password",value:b,onChange:e=>k(e.target.value),required:!0})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx(u,{htmlFor:"confirmPassword",children:"Confirm password"}),i.jsx(o,{id:"confirmPassword",type:"password",placeholder:"Repeat password",value:P,onChange:e=>_(e.target.value),required:!0})]}),i.jsx(c,{type:"submit",className:"w-full",disabled:R,children:R?"Registering...":"Register"}),i.jsxs("div",{className:"text-center text-sm text-muted-foreground",children:["Already have an account?"," ",i.jsx(c,{variant:"link",className:"p-0",onClick:()=>
1f("/admin/login"),children:"Sign in"})]})]})]})]})}):i.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background p-4",children:i.jsxs(t,{className:"w-full max-w-md",children:[i.jsxs(n,{className:"space-y-1",children:[i.jsx("div",{className:"flex items-center justify-center mb-4",children:i.jsx(j,{className:"h-8 w-8 text-destructive"})}),i.jsx(l,{className:"text-2xl text-center",children:"Invalid Invitation"}),i.jsx(d,{className:"text-center",children:"Admin registration requires a valid invitation link"})]}),i.jsxs(r,{children:[i.jsxs(x,{variant:"destructive",children:[i.jsx(j,{className:"h-4 w-4"}),i.jsx(h,{children:"This page is only accessible via invitation link. Please contact a super admin to request access."})]}),i.jsx("div",{className:"mt-6 text-center",children:i.jsx(c,{variant:"outline",onClick:()=>f("/admin/login"),children:"Return to Login"})})]})]})})};export{y 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.