1import{j as e}from"./vendor-motion-CPxq9Xvn.js";import{r as d}from"./vendor-i18n-CO3kK2bH.js";import{a5 as F,u as P,a6 as K,a7 as f,C as b,S as M,I as O,f as w,l as D,B as E,X as T,aa as H,K as L}from"./index-CFAvyuXu.js";import{P as Q}from"./pix-qr-image-D45mJvPS.js";import{W as R}from"./wand-sparkles-BFRdHggN.js";import{D as X}from"./download-B7FtiUYJ.js";import"./vendor-react-CQmBMThG.js";const v=s=>(s/100).toLocaleString("pt-BR",{style:"currency",currency:"BRL"});function G(s){const[,r]=d.useState(0);if(d.useEffect(()=>{if(!s)return;const a=setInterval(()=>r(j=>j+1),1e3);return()=>clearInterval(a)},[s]),!s)return null;const l=new Date(s).getTime()-Date.now();if(l<=0)return null;const m=Math.floor(l/864e5),x=Math.floor(l%864e5/36e5),i=Math.floor(l%36e5/6e4),p=Math.floor(l%6e4/1e3);return m>0?`${m}d ${x}h ${i}min`:`${String(x).padStart(2,"0")}:${String(i).padStart(2,"0")}:${String(p).padStart(2,"0")}`}function te(){const{token:s}=F(),[r,l]=d.useState(null),[m,x]=d.useState(!1),[i,p]=d.useState(null),a=P({queryKey:["/api/downsell",s],queryFn:async()=>{const t=await fetch(`/api/downsell/${s}`);if(!t.ok){const n=await t.json().catch(()=>({}));throw new Error(n?.message||`http_${t.status}`)}return t.json()},enabled:!!s,retry:!1}),j=a.data?.status==="active",$=P({queryKey:["/api/downsell",s,"status"],queryFn:async()=>{const t=await fetch(`/api/downsell/${s}/status`);return t.ok?t.json():{paid:!1}},enabled:!!s&&!!r,refetchInterval:3e3}).data?.paid===!0||a.data?.status==="redeemed";d.useEffect(()=>{if(i)return;const t=a.data?.selectedBookId;t&&p(t)},[a.data?.selectedBookId,i]);const c=K({mutationFn:async()=>{const t=await fetch(`/api/downsell/${s}/prepare`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i?{bookId:i}:{})}),n=await t.json();if(!t.ok)throw new Error(n?.message||"Falha ao preparar pagamento.");return n},onSuccess:t=>{l({brCode:t.brCode,imageUrl:t.qrCodeImage})}}),y=G(a.data?.expiresAt||null),q=d.useMemo(()=>a.data?Math.round((1-a.data.priceCents/a.data.anchorCents)*100):40,[a.data]);function z(){r?.brCode&&navigator.clipboard.writeText(r.brCode).then(()=>{x(!0),setTimeout(()=>x(!1),2500)})}if(a.isLoading)return e.jsx(u,{children:e.jsxs("div",{className:"flex items-center justify-center py-20 text-muted-foreground",children:[e.jsx(f,{className:"w-5 h-5 animate-spin mr-2"})," Carregando ofertaâ¦"]})});if(a.isError||!a.data)return e.jsx(u,{children:e.jsx(A,{title:"Oferta indisponÃvel",subtitle:"Este link pode ter expirado ou não é mais válido. Acesse sua conta SÃBHIA BOOKS para continuar seu livro."})});const o=a.data,g=o.books||[],h=g.find(t=>t.id===i)||null,k=h?.title||o.bookTitle,S=h?.subtitle??o.bookSubtitle,C=h?.author??o.author,I=h?.coverImage??o.coverImage,B=g.length>1;if($)return e.jsx(u,{children:e.jsxs("div",{className:"max-w-md mx-auto text-center py-12 px-6","data-testid":"downsell-paid",children:[e.jsx("div",{className:"w-20 h-20 mx-auto rounded-full bg-emerald-500/15 flex items-center justify-center mb-4 ring-4 ring-emerald-500/10",children:e.jsx(b,{className:"w-10 h-10 text-emerald-400"})}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:"Pagamento confirmado!"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-6 leading-relaxed",children:["Estamos gerando ",e.jsx("strong",{className:"text-foreground",children:o.bookTitle})," agora mesmo. Em poucos minutos você recebe no seu e-mail o link de acesso ao livro completo, pronto pra ler e exportar."]}),e.jsxs("div",{className:"inline-flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(f,{className:"w-3.5 h-3.5 animate-spin"})," Geração em andamentoâ¦"]})]})});if(!j){const t={redeemed:{title:"Seu livro já foi criado",subtitle:"Esta oferta já foi utilizada. Acesse sua conta SÃBHIA BOOKS para ver seu livro."},expired:{title:"Oferta expirada",subtitle:"Esta condição especial encerrou. Seu planejamento continua salvo na sua conta SÃBHIA BOOKS."},unsubscribed:{title:"Oferta encerrada",subtitle:"Você optou por não receber esta oferta. Seu planejamento continua salvo na sua conta."}},n=t[o.status]||t.expired;return e.jsx(u,{children:e.jsx(A,{title:n.title,subtitle:n.subtitle})})}return e.jsx(u,{children:e.jsx("div",{className:"max-w-md mx-auto px-4 md:px-0",children:e.jsxs("div",{className:"rounded-2xl bg-gradient-to-br from-zinc-900/80 to-zinc-950 border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/5 flex items-center gap-2",children:[e.jsx(M,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-xs uppercase font-bold tracking-wider text-primary/80",children:"Condição especial pra você"})]}),e.jsxs("div",{className:"px-5 py-5 flex gap-4 items-center border-b border-white/5",children:[e.jsx("div",{className:"shrink-0 w-20 h-28 rounded-lg overflow-hidden bg-white/[0.04] border border-white/10 flex items-center justify-center",children:I?e.jsx(O,{src:I,alt:k,priority:!0,widths:[200,260,320,400,520],sizes:"(max-width: 768px) 70vw, 320px",className:"w-full h-full object-cover","data-testid":"img-cover"}):e.jsx(w,{className:"w-7 h-7 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground mb-1",children:B?"Livro selecionado pra gerar":"Seu livro está pronto pra nascer"}),e.jsx("h1",{className:"text-lg font-bold leading-tight truncate","data-testid":"text-book-title",children:k}),S&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:S}),C&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:["por ",C]})]})]}),B&&e.jsxs("div",{className:"px-5 py-5 border-b border-white/5",children:[e.jsx("div",{className:"text-sm font-semibold mb-1",children:"Qual livro você quer gerar?"}),e.jsx("div",{className:"text-xs text-muted-foreground mb-3",children:"Você tem mais de um planejamento pronto. Toque no livro certo antes de pagar."}),e.jsx("div",{className:"space-y-2.5",children:g.map(t=>{const n=t.id===i;return e.jsxs("button",{type:"button",onClick:()=>p(t.id),className:`w-full flex gap-3 items-center text-left p-2.5 rounded-xl border transition-colors ${n?"border-primary bg-primary/10 ring-1 ring-primary/30":"border-white/10 bg-white/[0.02] hover:bg-white/[0.05]"}`,"data-testid":`button-select-book-${t.id}`,children:[e.jsx("div",{className:"shrink-0 w-12 h-16 rounded-md overflow-hidden bg-white/[0.04] border border-white/10 flex items-center justify-center",children:t.coverImage?e.jsx(O,{src:t.coverImage,alt:t.title,widths:[96,128,160,200],sizes:"120px",className:"w-full h-full object-cover"}):e.jsx(w,{className:"w-5 h-5 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-semibold leading-tight line-clamp-2",children:t.title}),t.subtitle&&e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5 truncate",children:t.subtitle})]}),e.jsx("div",{className:"shrink-0",children:n?e.jsx(b,{className:"w-5 h-5 text-primary"}):e.jsx("div",{className:"w-5 h-5 rounded-full border border-white/20"})})]},t.id)})})]}),e.jsxs("div",{className:"px-5 py-5 text-center border-b border-white/5",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground line-through","data-testid":"text-anchor-price",children:v(o.anchorCents)}),e.jsxs("span",{className:"text-[11px] font-bold px-2 py-0.5 rounded-full bg-emerald-500/15 text-emerald-300",children:["-",q,"%"]})]}),e.jsx("div",{className:"text-4xl font-extrabold text-primary leading-none","data-testid":"text-price",children:v(o.priceCents)}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:"pagamento único via PIX"}),y&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-1.5 text-xs text-amber-300/90","data-testid":"text-countdown",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," Expira em ",y]})]}),e.jsxs("div",{className:"px-5 py-4 space-y-2.5 border-b border-white/5",children:[e.jsx(N,{icon:e.jsx(R,{className:"w-4 h-4"}),text:"Livro completo gerado pela IA editorial SÃBHIA"}),e.jsx(N,{icon:e.jsx(w,{className:"w-4 h-4"}),text:"Todos os capÃtulos escritos a partir do seu plano"}),e.jsx(N,{icon:e.jsx(X,{className:"w-4 h-4"}),text:"Pronto pra ler e exportar em PDF, EPUB e DOCX"})]}),e.jsxs("div",{className:"px-5 py-5 min-h-[120px]",children:[!r&&e.jsx(E,{onClick:()=>c.mutate(),disabled:c.isPending,className:"w-full h-12 text-base font-bold bg-primary hover:bg-primary/90","data-testid":"button-generate-pix",children:c.isPending?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"w-4 h-4 mr-2 animate-spin"})," Gerando PIXâ¦"]}):e.jsxs(e.Fragment,{children:["Gerar meu livro por ",v(o.priceCents)]})}),c.isError&&e.jsxs("div",{className:"text-center py-4 text-sm text-rose-300",children:[e.jsx(T,{className:"w-4 h-4 inline mr-1"}),c.error?.message||"Falha ao preparar pagamento.",e.jsx("div",{children:e.jsx(E,{size:"sm",variant:"outline",className:"mt-3",onClick:()=>c.mutate(),children:"Tentar de novo"})})]}),r&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"bg-white p-3 rounded-xl mx-auto w-48 h-48 flex items-center justify-center",children:e.jsx(Q,{brCode:r.brCode,qrCodeImage:r.imageUrl,className:"w-full h-full object-contain",testId:"downsell-pix-qr"})}),e.jsx("div",{className:"text-center text-xs text-muted-foreground",children:"Abra o app do seu banco, escaneie o QR ou copie o código."}),e.jsxs("button",{onClick:z,className:"w-full p-3 rounded-lg bg-white/[0.03] border border-white/10 hover:bg-white/[0.06] text-xs font-mono break-all flex items-center justify-between gap-2","data-testid":"button-copy-brcode",children:[e.jsx("span",{className:"truncate",children:r.brCode}),e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 text-primary",children:[m?e.jsx(b,{className:"w-3.5 h-3.5"}):e.jsx(H,{className:"w-3.5 h-3.5"}),m?"Copiado":"Copiar"]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-[10px] text-muted-foreground pt-1",children:[e.jsx(f,{className:"w-3 h-3 animate-spin"}),"Aguardando confirmação do bancoâ¦"]})]})]}),e.jsxs("div",{className:"px-5 py-3 bg-white/[0.015] border-t border-white/5 flex items-center justify-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(L,{className:"w-3 h-3"})," Pagamento seguro · SÃBHIA BOOKS"]})]})})})}function N({icon:s,text:r}){return e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx("span",{className:"shrink-0 mt-0.5 text-primary",children:s}
1),e.jsx("span",{className:"text-foreground/90 leading-snug",children:r})]})}function u({children:s}){return e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-zinc-950 via-zinc-900 to-zinc-950 text-foreground",children:[e.jsx("header",{className:"py-6 border-b border-white/5",children:e.jsx("div",{className:"max-w-md mx-auto px-4 flex items-center justify-center",children:e.jsxs("span",{className:"font-serif text-xl tracking-tight",children:["SÃBHIA ",e.jsx("span",{className:"font-light text-muted-foreground",children:"BOOKS"})]})})}),e.jsx("main",{className:"py-8",children:s}),e.jsx("footer",{className:"py-6 text-center text-[10px] text-muted-foreground",children:"© SÃBHIA Books · Pagamento processado com segurança"})]})}function A({title:s,subtitle:r}){return e.jsxs("div",{className:"max-w-md mx-auto text-center py-12 px-6",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-full bg-rose-500/10 flex items-center justify-center mb-4",children:e.jsx(T,{className:"w-7 h-7 text-rose-400"})}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r})]})}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.