1import{c as L,u as P,W as D,r as d,j as e,B as g,b as p}from"./index-Dehqc7cc.js";import{s as m,m as R,U as T}from"./client-Bw6Mo37w.js";import{I as f}from"./input-BOOoKITO.js";import{B as U}from"./badge-Gmj_ZuIH.js";import{L as b}from"./loader-circle--H6bi8Cp.js";import{C as B}from"./circle-x-CyVTnSf0.js";import{C as q}from"./clock-Cux2o9Pn.js";import{C as W}from"./circle-check-big-DQ0O4iaU.js";import{S as H}from"./shield-check-b6CO3m3U.js";import{S as M}from"./shield-CgFpKd93.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const G=L("MailCheck",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]]),O="https://eventlab.com",v={admin:{label:"Admin",icon:H},moderator:{label:"Moderator",icon:M},user:{label:"Viewer",icon:T}};function te(){const{token:l}=P(),h=D(),[c,n]=d.useState("loading"),[i,j]=d.useState(null),[F,S]=d.useState(""),[x,C]=d.useState(""),[N,k]=d.useState(""),E=async s=>{var t;for(let r=0;r<12;r+=1){const{data:{session:a}}=await m.auth.getSession();if(((t=a==null?void 0:a.user)==null?void 0:t.id)===s)return a;await new Promise(o=>window.setTimeout(o,150))}throw new Error("Sign-in did not finish. Please try the invite link again.")},w=async(s,t)=>{const r=t||i;if(!r){n("invalid");return}try{n("completing"),await E(s);const{error:a}=await m.rpc("accept_team_invite",{_invite_token:r.invite_token??l});if(a)throw a;n("accepted"),p.success("Welcome to the team!"),window.setTimeout(()=>h("/admin"),2e3)}catch(a){p.error(a.message||"Failed to accept invitation"),n("valid")}},I=async()=>{var a,o;const{data:{session:s}}=await m.auth.getSession(),{data:t,error:r}=await m.from("team_invites").select("*").eq("invite_token",l).eq("status","pending").maybeSingle();if(r||!t){n("invalid");return}if(new Date(t.expires_at)<new Date){n("expired");return}if(j(t),S(t.email),((o=(a=s==null?void 0:s.user)==null?void 0:a.email)==null?void 0:o.toLowerCase())===t.email.toLowerCase()){await w(s.user.id,t);return}n("valid")},A=async s=>{if(s.preventDefault(),x.length<6){p.error("Password must be at least 6 characters");return}if(x!==N){p.error("Passwords do not match");return}n("creating");try{const{data:t,error:r}=await m.auth.signUp({email:i.email,password:x,options:{emailRedirectTo:`${O}/admin/accept-invite/${l}`}});if(r){if(r.message.includes("already registered")||r.message.includes("already been registered")){const{data:a,error:o}=await m.auth.signInWithPassword({email:i.email,password:x});if(o)throw o;if(!a.user)throw new Error("Failed to sign in");await w(a.user.id,i);return}throw r}if(!t.user)throw new Error("Failed to create account");if(!t.session){n("confirm_email");return}await w(t.user.id,i)}catch(t){p.error(t.message||"Failed to create account"),n("valid")}};d.useEffect(()=>{const t=new URLSearchParams(window.location.hash.substring(1)).get("type");if(t!=="signup"&&t!=="email")return;const{data:{subscription:r}}=m.auth.onAuthStateChange(async(a,o)=>{if(!(!o||!l)&&(a==="SIGNED_IN"||a==="TOKEN_REFRESHED"||a==="INITIAL_SESSION")){r.unsubscribe();const{data:u}=await m.from("team_invites").select("*").eq("invite_token",l).maybeSingle();if(!u){n("invalid");return}if(u.status==="accepted"){n("accepted"),window.setTimeout(()=>h("/admin"),2e3);return}if(u.status==="pending"){j(u),await w(o.user.id,u);return}n("invalid")}});return()=>r.unsubscribe()},[h,l]),d.useEffect(()=>{if(!l){n("invalid");return}new URLSearchParams(window.location.hash.substring(1)).get("type")||I()},[l]);const y=i&&v[i.role]||v.user,_=y.icon;return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#060e1a] p-4",children:e.jsxs(R.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"bg-[#0A2540]/80 backdrop-blur-xl rounded-2xl border border-white/[0.08] p-8 w-full max-w-md",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-[#39FF14] to-[#00D4FF] flex items-center justify-center text-[#0A2540] font-black text-sm",children:"EL"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-white text-xl font-bold",children:"Join EventLab"}),e.jsx("p",{className:"text-white/40 text-xs",children:"Accept your team invitation"})]})]}),c==="loading"&&e.jsxs("div",{className:"flex flex-col items-center py-12 gap-3",children:[e.jsx(b,{className:"h-8 w-8 animate-spin text-[#39FF14]"}),e.jsx("p",{className:"text-white/50 text-sm",children:"Verifying invitation..."})]}),c==="completing"&&e.jsxs("div",{className:"flex flex-col items-center py-12 gap-3",children:[e.jsx(b,{className:"h-8 w-8 animate-spin text-[#39FF14]"}),e.jsx("p",{className:"text-white/50 text-sm",children:"Setting up your account..."})]}),c==="invalid"&&e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3 text-center",children:[e.jsx(B,{className:"h-12 w-12 text-red-400"}),e.jsx("h2",{className:"text-white font-semibold text-lg",children:"Invalid Invitation"}),e.jsx("p",{className:"text-white/50 text-sm",children:"This invite link is invali
6d or has already been used."}),e.jsx(g,{onClick:()=>h("/"),className:"mt-4 bg-white/10 text-white hover:bg-white/20",children:"Go to Homepage"})]}),c==="expired"&&e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3 text-center",children:[e.jsx(q,{className:"h-12 w-12 text-[#FF8C00]"}),e.jsx("h2",{className:"text-white font-semibold text-lg",children:"Invitation Expired"}),e.jsx("p",{className:"text-white/50 text-sm",children:"This invite has expired. Please ask your admin to send a new one."}),e.jsx(g,{onClick:()=>h("/"),className:"mt-4 bg-white/10 text-white hover:bg-white/20",children:"Go to Homepage"})]}),c==="confirm_email"&&e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3 text-center",children:[e.jsx(G,{className:"h-12 w-12 text-[#00D4FF]"}),e.jsx("h2",{className:"text-white font-semibold text-lg",children:"Check Your Email"}),e.jsxs("p",{className:"text-white/50 text-sm",children:["We've sent a confirmation email to ",e.jsx("strong",{className:"text-white/70",children:i==null?void 0:i.email}),". Click the link in the email to confirm your account and complete your setup."]}),e.jsx("p",{className:"text-white/30 text-xs mt-2",children:"After confirming, you'll be redirected back here automatically."})]}),c==="accepted"&&e.jsxs("div",{className:"flex flex-col items-center py-8 gap-3 text-center",children:[e.jsx(W,{className:"h-12 w-12 text-[#39FF14]"}),e.jsx("h2",{className:"text-white font-semibold text-lg",children:"Welcome to the Team!"}),e.jsx("p",{className:"text-white/50 text-sm",children:"Redirecting you to the admin dashboard..."})]}),(c==="valid"||c==="creating")&&i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white/[0.03] border border-white/[0.08] rounded-xl p-4 mb-6",children:[e.jsx("p",{className:"text-white/50 text-xs mb-2",children:"You've been invited as:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(U,{className:"bg-[#39FF14]/20 text-[#39FF14] border border-[#39FF14]/30",children:[e.jsx(_,{className:"h-3.5 w-3.5 mr-1"}),y.label]}),e.jsxs("span",{className:"text-white/40 text-xs",children:["for ",i.email]})]}),Array.isArray(i.permissions)&&e.jsxs("p",{className:"text-white/30 text-xs mt-2",children:["Access to ",i.permissions.length," section",i.permissions.length!==1?"s":""]})]}),e.jsxs("form",{onSubmit:A,className:"space-y-3",children:[e.jsx(f,{type:"email",value:F,disabled:!0,className:"bg-white/5 border-white/10 text-white/50"}),e.jsx(f,{type:"password",placeholder:"Create password (min 6 chars)",value:x,onChange:s=>C(s.target.value),required:!0,minLength:6,className:"bg-white/5 border-white/10 text-white placeholder:text-white/30"}),e.jsx(f,{type:"password",placeholder:"Confirm password",value:N,onChange:s=>k(s.target.value),required:!0,className:"bg-white/5 border-white/10 text-white placeholder:text-white/30"}),e.jsx(g,{type:"submit",disabled:c==="creating",className:"w-full bg-[#39FF14] text-[#0A2540] hover:bg-[#39FF14]/90 font-semibold",children:c==="creating"?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"h-4 w-4 mr-2 animate-spin"})," Creating account..."]}):"Accept Invitation & Join"})]})]})]})})}export{te 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.