1import{r as a,j as e,L as v,a as d,aF as g,aG as b,y as L}from"./index-C3pbI8Cv.js";import{C as T,L as y}from"./card-wcC-T8Jy.js";import{S as B}from"./shield-check-DLufP_1e.js";import{C as M}from"./circle-alert-BjtMnj02.js";function I(){const[i,r]=a.useState("loading"),[N,S]=a.useState(""),[m,C]=a.useState(null),[u,k]=a.useState(null),[A,c]=a.useState(""),[o,E]=a.useState(""),[p,P]=a.useState(""),[h,x]=a.useState(!1),[f,n]=a.useState("");a.useEffect(()=>{document.title="Activate your account â Mental Edge";let t=document.querySelector('meta[name="robots"]');t||(t=document.createElement("meta"),t.setAttribute("name","robots"),document.head.appendChild(t)),t.setAttribute("content","noindex, nofollow");const s=new URLSearchParams(window.location.search).get("token")||"";if(S(s),!s){r("invalid"),c("This activation link is missing its token. Ask your admin to send a new one.");return}fetch(`/api/admin/activate?token=${encodeURIComponent(s)}`,{credentials:"include"}).then(async j=>{const l=await j.json().catch(()=>({}));j.ok&&l.success?(C(l.data?.email||null),k(l.data?.name||null),r("valid")):(r("invalid"),c(l.error||"This activation link is invalid or has expired."))}).catch(()=>{r("invalid"),c("We couldn't reach the server. Please try again.")})},[]);async function w(){if(n(""),o.length<8){n("Password must be at least 8 characters.");return}if(o!==p){n("Passwords don't match.");return}x(!0);try{const t=await fetch("/api/admin/activate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({token:N,password:o})}),s=await t.json().catch(()=>({}));t.ok&&s.success?r("done"):n(s.error||"Could not activate your account.")}catch{n("We couldn't reach the server. Please try again.")}finally{x(!1)}}return e.jsx("div",{className:"min-h-screen bg-[#0B0A1A] flex items-center justify-center px-4 py-12",children:e.jsxs(T,{className:"w-full max-w-md bg-[#15122E] border-purple-800/50 p-8",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-14 h-14 rounded-2xl bg-gradient-to-br from-purple-600 to-cyan-500 mb-4",children:e.jsx(B,{className:"w-7 h-7 text-white"})}),e.jsx("h1",{className:"text-xl font-bold text-white",children:"Mental Edge Sales Center"}),e.jsx("p",{className:"text-sm text-purple-300/70 mt-1",children:"Activate your account"})]}),i==="loading"&&e.jsx("div",{className:"flex justify-center py-10","data-testid":"status-loading",children:e.jsx(y,{className:"w-6 h-6 text-purple-400 animate-spin"})}),i==="invalid"&&e.jsxs("div",{className:"text-center py-6","data-testid":"status-invalid",children:[e.jsx(M,{className:"w-10 h-10 text-red-400 mx-auto mb-3"}),e.jsx("p",{className:"text-purple-200 text-sm leading-relaxed",children:A}),e.jsx(v,{href:"/admin",children:e.jsx(d,{variant:"ghost",className:"mt-5 text-purple-300 hover:text-white","data-testid":"link-go-login",children:"Go to login"})})]}),i==="valid"&&e.jsxs("div",{className:"space-y-4","data-testid":"form-activate",children:[e.jsxs("p",{className:"text-sm text-purple-200",children:[u?`Welcome, ${u}! `:"Welcome! ",m&&e.jsxs(e.Fragment,{children:["Set a password for ",e.jsx("span",{className:"text-cyan-300",children:m}),"."]})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-purple-200",children:"New password"}),e.jsx(b,{type:"password",value:o,onChange:t=>E(t.target.value),placeholder:"At least 8 characters",className:"mt-1 bg-[#0B0A1A] border-purple-900/50 text-white","data-testid":"input-new-password"})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-purple-200",children:"Confirm password"}),e.jsx(b,{type:"password",value:p,onChange:t=>P(t.target.value),placeholder:"Re-enter password",className:"mt-1 bg-[#0B0A1A] border-purple-900/50 text-white","data-testid":"input-confirm-password",onKeyDown:t=>t.key==="Enter"&&w()})]}),f&&e.jsx("p",{className:"text-sm text-red-400","data-testid":"text-form-error",children:f}),e.jsx(d,{onClick:w,disabled:h,className:"w-full bg-gradient-to-r from-purple-600 to-blue-600 hover:from-purple-700 hover:to-blue-700","data-testid":"button-activate",children:h?e.jsx(y,{className:"w-4 h-4 animate-spin"}):"Activate & set password"})]}),i==="done"&&e.jsxs("div",{className:"text-center py-6","data-testid":"status-done",children:[e.jsx(L,{className:"w-10 h-10 text-emerald-400 mx-auto mb-3"}),e.jsx("p",{className:"text-white font-medium",children:"Your account is ready!"}),e.jsx("p",{className:"text-purple-300/70 text-sm mt-1",children:"Sign in with your email and new password."}),e.jsx(v,{href:"/admin",children:e.jsx(d,{className:"mt-5 bg-gradient-to-r from-purple-600 to-blue-600 hover:from-purple-700 hover:to-blue-700","data-testid":"button-go-login",children:"Go to login"})})]})]})})}export{I 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.