1import{j as e}from"./vendor-motion-CPxq9Xvn.js";import{r,u as T}from"./vendor-i18n-CO3kK2bH.js";import{a5 as L,a1 as D,a7 as k,B as m,A as f,ao as P,dI as E,aF as g}from"./index-CFAvyuXu.js";import{C as R}from"./circle-check-big-DgyOZTvd.js";import{C as j}from"./circle-x-DhBMAj3Y.js";import{L as p}from"./log-in-BWcU6fvU.js";import"./vendor-react-CQmBMThG.js";function Q(){const{token:x}=L(),[,c]=D(),[l,s]=r.useState("verifying"),[q,w]=r.useState("/dashboard"),[v,C]=r.useState(null),[F,u]=r.useState(""),h=r.useRef(x),N=r.useRef(!1),o=r.useRef(null),{t}=T("auth"),n=()=>{window.history.replaceState(null,"","/magic-login")};return r.useEffect(()=>{x&&(h.current=x)},[x]),r.useEffect(()=>{const d=h.current;if(!d){s("invalid");return}if(N.current)return;N.current=!0;async function a(){try{const b=E({token:d}),y=await fetch("/api/auth/magic-verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(b)}),i=await y.json();y.ok&&i.success?(n(),s("success"),w(i.redirectPath||"/dashboard"),i.user&&(g.removeQueries({predicate:S=>S.queryKey[0]!=="/api/auth/me"}),g.setQueryData(["/api/auth/me"],i.user)),o.current=setTimeout(()=>{c(i.redirectPath||"/dashboard")},1200)):i.reason==="expired"?(n(),s("expired"),i.phone&&C(i.phone)):i.reason==="used"?(n(),s("used")):i.reason==="invalid"?(n(),s("invalid")):(s("error"),u(i.message||""))}catch{s("error"),u(t("magicConnectionError","Erro de conexão. Verifique sua internet e tente novamente."))}}return a(),()=>{o.current&&clearTimeout(o.current)}},[c,t]),e.jsx("div",{className:"flex min-h-[100dvh] items-center justify-center bg-[#0a0e17] px-4 py-8 pb-[calc(env(safe-area-inset-bottom)+2rem)]",children:e.jsxs("div",{className:"w-full max-w-lg space-y-6 break-words text-center",children:[l==="verifying"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-teal-500/10 border border-teal-500/20 flex items-center justify-center",children:e.jsx(k,{className:"w-10 h-10 text-teal-400 animate-spin"})}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-teal-400/5 animate-ping"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-verifying",children:t("magicVerifying","Entrando na sua conta...")}),e.jsx("p",{className:"text-white/50 text-sm",children:t("magicVerifyingDesc","Aguarde um instante enquanto confirmamos seu acesso.")})]})]}),l==="success"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center",children:e.jsx(R,{className:"w-10 h-10 text-emerald-400"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-success",children:t("magicSuccess","Acesso confirmado!")}),e.jsx("p",{className:"text-white/50 text-sm",children:t("magicSuccessDesc","Redirecionando para sua conta...")})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx(k,{className:"w-5 h-5 text-teal-400 animate-spin"})})]}),l==="expired"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:e.jsx(j,{className:"w-10 h-10 text-amber-400"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-expired",children:t("magicExpired","Link expirado")}),e.jsx("p",{className:"text-white/50 text-sm",children:t("magicExpiredDesc","Este link de acesso direto expirou. Por segurança, os links funcionam por apenas 10 minutos.")})]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-2xl p-5 text-left space-y-3",children:[e.jsx("p",{className:"text-xs text-white/40 uppercase tracking-wider font-medium",children:t("magicWhatToDo","O que fazer agora")}),e.jsx("p",{className:"text-sm text-white/70",children:t("magicExpiredInstructions","Faça login normalmente com seu e-mail ou WhatsApp, ou peça um novo link de acesso.")})]}),e.jsxs(m,{onClick:()=>c(v?`/login?phone=${v}
1&method=whatsapp`:"/login"),className:"w-full h-12 bg-teal-600 hover:bg-teal-500 text-white font-semibold rounded-xl text-sm","data-testid":"button-login-from-magic-expired",children:[e.jsx(p,{className:"w-4 h-4 mr-2"}),t("magicLoginBtn","Fazer login"),e.jsx(f,{className:"w-4 h-4 ml-2"})]})]}),l==="used"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-amber-500/10 border border-amber-500/20 flex items-center justify-center",children:e.jsx(j,{className:"w-10 h-10 text-amber-400"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-used",children:t("magicUsed","Link já utilizado")}),e.jsx("p",{className:"text-white/50 text-sm",children:t("magicUsedDesc","Este link de acesso já foi utilizado anteriormente. Por segurança, cada link funciona uma única vez.")})]}),e.jsxs("div",{className:"bg-white/5 border border-white/10 rounded-2xl p-5 text-left space-y-3",children:[e.jsx("p",{className:"text-xs text-white/40 uppercase tracking-wider font-medium",children:t("magicWhatToDo","O que fazer agora")}),e.jsx("p",{className:"text-sm text-white/70",children:t("magicUsedInstructions","Faça login normalmente ou solicite um novo link de acesso ao suporte.")})]}),e.jsxs(m,{onClick:()=>c("/login"),className:"w-full h-12 bg-teal-600 hover:bg-teal-500 text-white font-semibold rounded-xl text-sm","data-testid":"button-login-from-magic-used",children:[e.jsx(p,{className:"w-4 h-4 mr-2"}),t("magicLoginBtn","Fazer login"),e.jsx(f,{className:"w-4 h-4 ml-2"})]})]}),l==="invalid"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-red-500/10 border border-red-500/20 flex items-center justify-center",children:e.jsx(j,{className:"w-10 h-10 text-red-400"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-invalid",children:t("magicInvalid","Link inválido")}),e.jsx("p",{className:"text-white/50 text-sm",children:t("magicInvalidDesc","Este link de acesso não é válido. Verifique se o link está correto ou solicite um novo.")})]}),e.jsxs(m,{onClick:()=>c("/login"),className:"w-full h-12 bg-teal-600 hover:bg-teal-500 text-white font-semibold rounded-xl text-sm","data-testid":"button-login-from-magic-invalid",children:[e.jsx(p,{className:"w-4 h-4 mr-2"}),t("magicLoginEmailWhatsapp","Fazer login com e-mail ou WhatsApp"),e.jsx(f,{className:"w-4 h-4 ml-2"})]})]}),l==="error"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-red-500/10 border border-red-500/20 flex items-center justify-center",children:e.jsx(j,{className:"w-10 h-10 text-red-400"})})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-white","data-testid":"text-magic-error",children:t("magicError","Algo deu errado")}),e.jsx("p",{className:"text-white/50 text-sm",children:F||t("magicConnectionError","Não foi possÃvel completar o acesso. Tente novamente.")})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs(m,{onClick:()=>{h.current?(s("verifying"),fetch("/api/auth/magic-verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(E({token:h.current}))}).then(async d=>{const a=await d.json();d.ok&&a.success?(n(),s("success"),w(a.redirectPath||"/dashboard"),a.user&&(g.removeQueries({predicate:b=>b.queryKey[0]!=="/api/auth/me"}),g.setQueryData(["/api/auth/me"],a.user)),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>c(a.redirectPath||"/dashboard"),1200)):a.reason==="expired"?(n(),s("expired")):a.reason==="used"?(n(),s("used")):a.reason==="invalid"?(n(),s("invalid")):(s("error"),u(a.message||""))}).catch(()=>{s("error"),u(t("magicConnectionError","Erro de conexão. Verifique sua internet e tente novamente."))})):s("invalid")},variant:"outline",className:"w-full h-12 border-white/10 text-white hover:bg-white/5 rounded-xl text-sm","data-testid":"button-retry-magic",children:[e.jsx(P,{className:"w-4 h-4 mr-2"}),t("magicRetry","Tentar novamente")]}),e.jsxs(m,{onClick:()=>
1c("/login"),className:"w-full h-12 bg-teal-600 hover:bg-teal-500 text-white font-semibold rounded-xl text-sm","data-testid":"button-login-from-magic-error",children:[e.jsx(p,{className:"w-4 h-4 mr-2"}),t("magicLoginManual","Fazer login manualmente"),e.jsx(f,{className:"w-4 h-4 ml-2"})]})]})]}),e.jsxs("p",{className:"text-[11px] text-white/20",children:[t("magicSecureFooter","Ambiente Seguro ⢠Sábhia Books")," © ",new Date().getFullYear()]})]})})}export{Q 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.