PageSourceSearch

https://sabhia.ai/assets/produto-detalhe-wpMuf866.js

js sabhia.ai collected 2026-10-05 12:33:27 UTC 35,412 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-motion-CPxq9Xvn.js";import{r as j}from"./vendor-i18n-CO3kK2bH.js";import{az as U,u as K,ai as E,a3 as P,a6 as z,a7 as w,a as H,ax as J,a9 as k,as as T,ak as q,aC as B,ap as D,aa as G,aG as I,Y as F,G as M,C as X,aU as Y}from"./index-CFAvyuXu.js";import{P as W}from"./pay-shell-C8S5C5vF.js";import{A as Z}from"./arrow-left-DY50GvQQ.js";import{B as O}from"./ban-M9IapYQ1.js";import{L as ee}from"./layers-B-zOJ8Vr.js";import{R as te}from"./rotate-ccw-yv6DhBa4.js";import{W as A}from"./webhook-1iLIbvwP.js";import{C as se}from"./circle-alert-CixghSwT.js";import{P as ae}from"./pencil-DB7EhnQs.js";import{T as ie}from"./trash-2-BF2rPJAw.js";import"./vendor-react-CQmBMThG.js";import"./layout-dashboard-pnVssBCT.js";function C(r){return(r/100).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function ne(r){return new Date(r).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"})}const Q=[{id:"sale.paid",label:"Venda Paga",desc:"Dispara ao confirmar o pagamento"},{id:"sale.refused",label:"Venda Recusada",desc:"Pagamento recusado pelo gateway"},{id:"sale.refunded",label:"Venda Reembolsada",desc:"Reembolso processado"},{id:"sale.waiting",label:"Aguardando Pagamento",desc:"Cobrança gerada, aguardando confirmação"},{id:"sale.chargeback",label:"Chargeback",desc:"Contestação de pagamento"}];function re({productId:r,editing:o,onClose:u}){const b=E(),{toast:x}=P(),[c,m]=j.useState({name:o?.name??"Webhook",endpointUrl:o?.endpoint_url??"",events:o?.events??["sale.paid"],active:o?.active??!0}),l=a=>{m(h=>({...h,events:h.events.includes(a)?h.events.filter(d=>d!==a):[...h.events,a]}))},p=z({mutationFn:async()=>{const a=o?`/api/sabhia-pay/products/${r}/webhooks/${o.id}`:`/api/sabhia-pay/products/${r}/webhooks`,d=await fetch(a,{method:o?"PUT":"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(c)});if(!d.ok)throw new Error(await d.text());return d.json()},onSuccess:()=>{b.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${r}/webhooks`]}),x({title:o?"Webhook atualizado!":"Webhook criado!"}),u()},onError:a=>x({title:"Erro",description:a.message,variant:"destructive"})});return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm p-4","data-testid":"modal-webhook-form",children:e.jsxs("div",{className:"bg-[#0e0a1a] border border-violet-400/20 rounded-2xl w-full max-w-md 
1shadow-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-white/5 sticky top-0 bg-[#0e0a1a] z-10",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(A,{className:"w-4 h-4 text-violet-400"}),e.jsx("h2",{className:"text-base font-semibold text-white",children:o?"Editar webhook":"Adicionar webhook"})]}),e.jsx("button",{onClick:u,className:"text-zinc-500 hover:text-white transition","data-testid":"button-close-webhook-modal",children:e.jsx(F,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:a=>{a.preventDefault(),c.events.length!==0&&p.mutate()},className:"p-6 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Nome do webhook"}),e.jsx("input",{value:c.name,onChange:a=>m(h=>({...h,name:a.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition",placeholder:"Ex.: Entrega Kiwify, Plataforma X...",required:!0,"data-testid":"input-webhook-name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"URL do endpoint"}),e.jsx("input",{type:"url",value:c.endpointUrl,onChange:a=>m(h=>({...h,endpointUrl:a.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition font-mono text-xs placeholder-zinc-600",placeholder:"https://plataforma.com/api/webhook",required:!0,"data-testid":"input-webhook-url"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-3 block",children:"Quando disparar"}),e.jsx("div",{className:"space-y-2",children:Q.map(a=>e.jsxs("label",{className:k("flex items-start gap-3 p-3 rounded-xl border cursor-pointer transition-all",c.events.includes(a.id)?"border-violet-400/40 bg-violet-500/10":"border-white/8 hover:border-white/15 bg-white/[0.02]"),"data-testid":`checkbox-event-${a.id}`,children:[e.jsx("div",{className:k("w-4 h-4 rounded border flex items-center justify-center shrink-0 mt-0.5 transition-all",c.events.includes(a.id)?"bg-violet-500 border-violet-400":"border-white/20 bg-transparent"),children:c.events.includes(a.id)&&e.jsx(D,{className:"w-2.5 h-2.5 text-white"})}),e.jsx("input",{type:"checkbox",className:"sr-only",checked:c.events.includes(a.id),onChange:()=>l(a.id)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-white",children:a.label}),e.jsx("p",{className:"text-[11px] text-zinc-500 mt-0.5",children:a.desc})]}),a.id==="sale.paid"&&e.jsx("span",{className:"text-[10px] text-emerald-400 bg-emerald-400/10 px-1.5 py-0.5 rounded shrink-0",children:"ativo"})]},a.id))}),c.events.length===0&&e.jsx("p",{className:"text-xs text-red-400 mt-2",children:"Selecione pelo menos um evento."})]}),e.jsxs("div",{className:"flex gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:u,className:"flex-1 px-4 py-2.5 rounded-xl border border-white/10 text-sm text-zinc-400 hover:text-white transition","data-testid":"button-cancel-webhook",children:"Cancelar"}),e.jsxs("button",{type:"submit",disabled:p.isPending||c.events.length===0,className:"flex-1 px-4 py-2.5 rounded-xl bg-gradient-to-r from-violet-600 to-fuchsia-500 text-white font-semibold text-sm hover:opacity-90 transition disabled:opacity-50 flex items-center justify-center gap-2","data-testid":"button-save-webhook",children:[p.isPending&&e.jsx(w,{className:"w-4 h-4 animate-spin"}),o?"Salvar alterações":"Criar webhook"]})]})]})]})})}function oe({productId:r}){const o=E(),{toast:u}=P(),[b,x]=j.useState(!1),[c,m]=j.useState(null),[l,p]=j.useState(null),[a,h]=j.useState(null),[d,y]=j.useState({}),{data:g,isLoading:i}=K({queryKey:[`/api/sabhia-pay/products/${r}/webhooks`],staleTime:3e4}),f=z({mutationFn:async t=>{const n=await fetch(`/api/sabhia-pay/products/${r}/webhooks/${t}`,{method:"DELETE",credentials:"include"});if(!n.ok&&n.status!==204)throw new Error("Falha ao excluir")},onSuccess:()=>{o.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${r}/webhooks`]}),h(null),u({title:"Webhook removido."})},onError:()=>u({title:"Erro ao remover webhook",variant:"destructive"})}),_=z({mutationFn:async t=>{const n=await fetch(`/api/sabhia-pay/products/${r}/webhooks/${t}/toggle`,{method:"PATCH",credentials:"include"});if(!n.ok)throw new Error("Falha ao alterar");return n.json()},onSuccess:()=>{o.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${r}/webhooks`]})},onError:()=>u({title:"Erro ao alterar webhook",variant:"destructive"})}),S=async t=>{p(t.id),y(n=>({...n,[t.id]:null}));try{const v=await(await fetch(`/api/sabhia-pay/products/${r}/webhooks/${t.id}/test`,{method:"POST",credentials:"include"})).json(),R=!!(v.ok&&v.status>=200&&v.status<300);y(V=>({...V,[t.id]:{ok:R,status:v.status??0,responseBody:v.responseBody}})),u(R?{title:"Teste enviado com sucesso!",description:`Seu servidor respondeu ${v.status} ✓`}:{title:`Endpoint respondeu ${v.status||"sem resposta"}`,description:v.responseBody?`Erro: ${String(v.responseBody).slice(0,120)}`:v.status?"Verifique a URL e se o servidor está aceitando POST.":"Servidor inacessível ou timeout de 8s.",variant:"destructive"}),o.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${r}/webhooks`]})}catch{y(n=>({...n,[t.id]:{ok:!1,status:0}})),u({title:"Erro ao enviar teste",description:"Não foi possível alcançar o endpoint.",variant:"destructive"})}finally{p(null)}},$=t=>Q.find(n=>n.id===t)?.label??t,L=t=>{if(!t.last_fired_at)return e.jsx("span",{className:"text-[10px] text-zinc-600 bg-zinc-800/50 px-1.5 py-0.5 rounded",children:"Nunca disparado"});const n=(t.last_status??0)>=200&&(t.last_status??0)<300;return e.jsx("span",{className:k("text-[10px] px-1.5 py-0.5 rounded font-medium",n?"text-emerald-400 bg-emerald-400/10":"text-red-400 bg-red-400/10"),
1children:n?`✓ ${t.last_status}`:`✗ ${t.last_status??"erro"}`})},s=t=>{const n=t.last_status??0,v=(t.last_response_body??"").toLowerCase();return!t.endpoint_url.includes("digiwork.club")||n===0?null:n===404?"⚠ Webhook não encontrado no DigiWork. Recrie o webhook no DigiWork Admin e atualize esta URL.":n===400&&v.includes("campos obrigatórios")?"⚙ Configure o mapeamento no DigiWork: idTransacao → idTransacao · nomeCliente → nomeCliente · emailCliente → emailCliente · telefoneCliente → telefoneCliente":n===400?"⚠ DigiWork rejeitou o payload (400). Verifique o mapeamento de variáveis no DigiWork Admin.":n>=500?"⚠ Erro interno no DigiWork (5xx). Tente novamente mais tarde.":null},N=g?.webhooks??[];return e.jsxs("div",{"data-testid":"section-product-webhooks",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-white flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4 text-violet-400"}),"Webhooks de Entrega",N.length>0&&e.jsx("span",{className:"text-[11px] font-normal text-zinc-500 bg-white/5 px-1.5 py-0.5 rounded-full",children:N.length})]}),e.jsxs("button",{onClick:()=>{m(null),x(!0)},className:"inline-flex items-center gap-1.5 text-xs text-violet-400 hover:text-violet-300 border border-violet-400/20 hover:border-violet-400/40 px-3 py-1.5 rounded-lg transition bg-violet-500/[0.04] hover:bg-violet-500/10","data-testid":"button-add-webhook",children:[e.jsx(T,{className:"w-3.5 h-3.5"})," Adicionar webhook"]})]}),i?e.jsx("div",{className:"flex items-center justify-center h-20",children:e.jsx(w,{className:"w-5 h-5 animate-spin text-violet-400/50"})}):N.length===0?e.jsxs("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] p-8 text-center",children:[e.jsx(A,{className:"w-8 h-8 text-zinc-700 mx-auto mb-3"}),e.jsx("p",{className:"text-zinc-400 text-sm font-medium",children:"Nenhum webhook configurado"}),e.jsx("p",{className:"text-zinc-600 text-xs mt-1 mb-4 max-w-xs mx-auto",children:"Conecte plataformas de entrega. A cada venda paga, o webhook dispara automaticamente."}),e.jsxs("button",{onClick:()=>{m(null),x(!0)},className:"inline-flex items-center gap-1.5 text-sm text-violet-400 hover:text-violet-300","data-testid":"button-first-webhook",children:[e.jsx(T,{className:"w-3.5 h-3.5"})," Criar primeiro webhook"]})]}):e.jsx("div",{className:"space-y-3",children:N.map(t=>e.jsx("div",{className:k("rounded-xl border p-4 transition-all",t.active?"border-violet-400/15 bg-violet-500/[0.04]":"border-white/5 bg-white/[0.01] opacity-60"),"data-testid":`card-webhook-${t.id}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-white",children:t.name}),!t.active&&e.jsx("span",{className:"text-[10px] text-zinc-500 bg-zinc-800/60 px-1.5 py-0.5 rounded",children:"inativo"}),L(t),t.fire_count>0&&e.jsxs("span",{className:"text-[10px] text-zinc-600",children:[t.fire_count," disparo",t.fire_count!==1?"s":""]})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("code",{className:"text-xs text-zinc-400 font-mono truncate max-w-[280px]",children:t.endpoint_url})}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:(Array.isArray(t.events)?t.events:[]).map(n=>e.jsx("span",{className:"text-[10px] text-violet-300 bg-violet-500/10 border border-violet-400/15 px-1.5 py-0.5 rounded",children:$(n)},n))}),!d[t.id]&&t.last_status&&t.last_status>=400&&(()=>{const n=s(t);return e.jsxs("div",{className:"mt-1.5 space-y-1.5",children:[n&&e.jsx("div",{className:"rounded-lg bg-amber-950/40 border border-amber-500/25 px-2.5 py-2",children:e.jsx("p",{className:"text-[10px] text-amber-300 leading-relaxed",children:n})}),t.last_response_body&&e.jsxs("div",{className:"rounded-lg bg-red-950/30 border border-red-500/15 px-2.5 py-1.5",children:[e.jsx("p",{className:"text-[10px] text-zinc-500 font-medium mb-0.5",children:"Resposta do servidor:"}),e.jsx("code",{className:"text-[10px] text-red-300/70 break-all font-mono",children:t.last_response_body.slice(0,300)})]})]})})(),d[t.id]!==void 0&&d[t.id]!==null&&e.jsxs("div",{className:"flex flex-col gap-1.5 pt-1",children:[e.jsxs("div",{className:k("flex items-center gap-1.5 text-[11px] font-medium",d[t.id].ok?"text-emerald-400":"text-red-400"),children:[d[t.id].ok?e.jsx(X,{className:"w-3.5 h-3.5"}):e.jsx(se,{className:"w-3.5 h-3.5"}),d[t.id].ok?`Teste OK — servidor respondeu ${d[t.id].status}`:d[t.id].status?`Falha — servidor respondeu ${d[t.id].status}`:"Falha — sem resposta (timeout ou URL inacessível)"]}),!d[t.id].ok&&(()=>{const n=d[t.id],v=s({...t,last_status:n.status,last_response_body:n.responseBody});return e.jsxs(e.Fragment,{children:[v&&e.jsx("div",{className:"rounded-lg bg-amber-950/40 border border-amber-500/25 px-2.5 py-2",children:e.jsx("p",{className:"text-[10px] text-amber-300 leading-relaxed",children:v})}),n.responseBody&&e.jsxs("div",{className:"rounded-lg bg-red-950/30 border border-red-500/15 px-2.5 py-1.5",children:[e.jsx("p",{className:"text-[10px] text-zinc-500 font-medium mb-0.5",children:"Resposta do servidor:"}),e.jsx("code",{className:"text-[10px] text-red-300/70 break-all font-mono",children:n.responseBody.slice(0,300)})]})]})})()]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{onClick:()=>_.mutate(t.id),disabled:_.isPending,className:k("px-2.5 py-1.5 rounded-lg text-xs font-medium transition",t.active?"text-zinc-400 hover:text-white hover:bg-white/5":"text-violet-400 hover:text-violet-300 hover:bg-violet-500/10"),title:t.active?"Desativar":"Ativar","data-testid":`button-toggle-wh-${t.id}`,children:t.active?"Desativar":"Ativar"}),e.jsxs("button",{onClick:()=>S(t),disabled:l===t.id,className:"inline-flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-medium text-emerald-400/80 hover:text-emerald-400 hover:bg-emerald-400/10 border border-emerald-400/20 transition disabled:opacity-50","data-testid":`button-test-wh-${t.id}`,children:[l===t.id?e.jsx(w,{className:"w-3 h-3 animate-spin"}):e.jsx(Y,{className:"w-3 h-3"}),l===t.id?"Enviando…":"Testar"]}),e.jsx("button",{onClick:()=>{m(t),x(!0)},className:"p-2 rounded-lg hover:bg-white/5 text-zinc-500 hover:text-white transition",title:"Editar","data-testid":`button-edit-wh-${t.id}`,children:e.jsx(ae,{className:"w-4 h-4"})}),a===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>f.mutate(t.id),className:"text-[11px] text-red-400 hover:text-red-300 px-2 py-1 rounded-lg hover:bg-red-400/10 transition","data-testid":`button-confirm-delete-wh-${t.id}`,children:"Confirmar"}),e.jsx("button",{onClick:()=>h(null),className:"text-[11px] text-zinc-500 px-2 py-1 rounded-lg hover:bg-white/5 transition","data-testid":`button-cancel-delete-wh-${t.id}`,children:"Cancelar"})]}):e.jsx("button",{onClick:()=>h(t.id),className:"p-2 rounded-lg hover:bg-white/5 text-zinc-600 hover:text-red-400 transition",title:"Remover","data-testid":`button-delete-wh-${t.id}`,children:e.jsx(ie,{className:"w-4 h-4"})})]})]})},t.id))}),b&&e.jsx(re,{productId:r,editing:c,onClose:()=>{x(!1),m(null)}})]})}function le({product:r,productId:o}){const u=E(),{toast:b}=P(),x=!!r.is_order_bump,[c,m]=j.useState(((r.bump_price_cents??r.price_cents)/100).toFixed(2)),[l,p]=j.useState(r.bump_anchor_cents!=null?(r.bump_anchor_cents/100).toFixed(2):""),[a,h]=j.useState(((r.bump_credit_amount_cents??0)/100).toFixed(2)),d=()=>u.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${o}`]}),y=z({mutationFn:async i=>{const f=await fetch(`/api/sabhia-pay/products/${o}/order-bump`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({isOrderBump:i})});if(!f.ok)throw new Error(await f.text());return f.json()},onSuccess:i=>{d();const f=i?.product;f?.bump_price_cents!=null&&m((f.bump_price_cents/100).toFixed(2)),b({title:f?.is_order_bump?"Disponível como order bump":"Removido dos order bumps"})},onError:i=>b({title:"Erro ao atualizar",description:i?.message,variant:"destructive"})}),g=z({mutationFn:async()=>{const i=await fetch(`/api/sabhia-pay/products/${o}/order-bump`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({bumpPriceCents:Math.max(0,Math.round(parseFloat(c.replace(",","."))*100||0)),bumpAnchorCents:l.trim()===""?null:Math.max(0,Math.round(parseFloat(l.replace(",","."))*100||0)),bumpCreditAmountCents:Math.max(0,Math.round(parseFloat(a.replace(",","."))*100||0))})});if(!i.ok)throw new Error(await i.text());return i.json()},onSuccess:()=>{d(),b({title:"Configuração do bump salva"})},onError:i=>b({title:"Erro ao salvar",description:i?.message,variant:"destructive"})});return e.jsxs("div",{"data-testid":"section-product-order-bump",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-white flex items-center gap-2",children:[e.jsx(M,{className:"w-4 h-4 text-violet-400"}),"Order Bump — Sábhia Educa"]}),e.jsxs("button",{onClick:()=>y.mutate(!x),disabled:y.isPending,className:k("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium border transition disabled:opacity-50",x?"text-emerald-300 bg-emerald-500/10 border-emerald-400/30 hover:bg-emerald-500/20":"text-zinc-400 border-white/10 hover:text-white hover:bg-white/5"),"data-testid":"button-toggle-order-bump",children:[y.isPending&&e.jsx(w,{className:"w-3.5 h-3.5 animate-spin"}),x?"Disponível como bump":"Disponibilizar como bump"]})]}),x?e.jsxs("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] p-5 space-y-4","data-testid":"panel-order-bump-config",children:[e.jsxs("p",{className:"text-xs text-zinc-500 leading-relaxed",children:["Preço, preço-âncora e crédito abaixo valem ",e.jsx("span",{className:"text-zinc-300 font-medium",children:"somente para o bump"})," — o preço normal do produto (",C(r.price_cents),") não muda. Em quais cursos aparece, pausa/retomada e ordem de exibição ficam no admin da Sábhia Educa."]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Preç
1o do bump (R$)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:c,onChange:i=>m(i.target.value),className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition","data-testid":"input-bump-price"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Preço-âncora (opcional)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:l,onChange:i=>p(i.target.value),placeholder:"De R$...",className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white placeholder-zinc-600 focus:outline-none focus:border-violet-400/50 transition","data-testid":"input-bump-anchor"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Crédito concedido (R$)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:a,onChange:i=>h(i.target.value),className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition","data-testid":"input-bump-credit"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>g.mutate(),disabled:g.isPending,className:"inline-flex items-center gap-2 bg-gradient-to-r from-violet-600 to-fuchsia-500 text-white px-4 py-2 rounded-xl font-semibold text-sm disabled:opacity-50 hover:opacity-90 transition","data-testid":"button-save-order-bump",children:[g.isPending&&e.jsx(w,{className:"w-4 h-4 animate-spin"}),"Salvar"]})})]}):e.jsxs("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] p-8 text-center",children:[e.jsx(M,{className:"w-8 h-8 text-zinc-700 mx-auto mb-3"}),e.jsx("p",{className:"text-zinc-400 text-sm font-medium",children:"Este produto não aparece como order bump"}),e.jsx("p",{className:"text-zinc-600 text-xs mt-1 max-w-sm mx-auto",children:"Ative para disponibilizar este produto como oferta complementar no checkout de cursos da Sábhia Educa. Título, descrição e imagem exibidos são os deste produto."})]})]})}function de({product:r,onClose:o}){const u=E(),{toast:b}=P(),[x,c]=j.useState({name:r.name,amountCents:(r.price_cents/100).toFixed(2),notes:""}),m=z({mutationFn:async()=>{const l=await fetch(`/api/sabhia-pay/products/${r.id}/links`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({name:x.name,amountCents:Math.round(parseFloat(x.amountCents.replace(",","."))*100),notes:x.notes||null})});if(!l.ok)throw new Error(await l.text());return l.json()},onSuccess:l=>{u.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${r.id}`]}
1),u.invalidateQueries({queryKey:["/api/sabhia-pay/stats"]}),b({title:"Link criado!",description:`/${l.link.slug}`}),o()},onError:l=>b({title:"Erro",description:l.message,variant:"destructive"})});return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 backdrop-blur-sm p-4","data-testid":"modal-create-link",children:e.jsxs("div",{className:"bg-[#0e0a1a] border border-violet-400/20 rounded-2xl w-full max-w-md shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-white/5",children:[e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Criar link de venda"}),e.jsx("button",{onClick:o,className:"text-zinc-500 hover:text-white transition",children:e.jsx(F,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:l=>{l.preventDefault(),m.mutate()},className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Nome do link"}),e.jsx("input",{value:x.name,onChange:l=>c(p=>({...p,name:l.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition",required:!0,"data-testid":"input-link-name"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Valor (R$)"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-zinc-500 text-sm",children:"R$"}),e.jsx("input",{type:"number",step:"0.01",min:"1",value:x.amountCents,onChange:l=>c(p=>({...p,amountCents:l.target.value})),className:"w-full bg-white/5 border border-white/10 rounded-xl pl-9 pr-3.5 py-2.5 text-sm text-white focus:outline-none focus:border-violet-400/50 transition",required:!0,"data-testid":"input-link-price"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-400 mb-1.5 block",children:"Observações internas"}),e.jsx("textarea",{value:x.notes,onChange:l=>c(p=>({...p,notes:l.target.value})),rows:2,className:"w-full bg-white/5 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white placeholder-zinc-600 focus:outline-none focus:border-violet-400/50 transition resize-none",placeholder:"Campanha de Natal, turma #3...","data-testid":"input-link-notes"})]}),e.jsxs("div",{className:"flex gap-3 pt-1",children:[e.jsx("button",{type:"button",onClick:o,className:"flex-1 px-4 py-2.5 rounded-xl border border-white/10 text-sm text-zinc-400 hover:text-white transition","data-testid":"button-cancel-link",children:"Cancelar"}),e.jsxs("button",{type:"submit",disabled:m.isPending,className:"flex-1 px-4 py-2.5 rounded-xl bg-gradient-to-r from-violet-600 to-fuchsia-500 text-white font-semibold text-sm hover:opacity-90 transition disabled:opacity-50 flex items-center justify-center gap-2","data-testid":"button-create-link",children:[m.isPending&&e.jsx(w,{className:"w-4 h-4 animate-spin"}),"Gerar link"]})]})]})]})})}function ke(){const[,r]=U("/pay/produtos/:id"),o=r?.id,[u,b]=j.useState(!1),[x,c]=j.useState(null),{data:m,isLoading:l}=K({queryKey:[`/api/sabhia-pay/products/${o}`],enabled:!!o}),p=E(),{toast:a}=P(),[h,d]=j.useState(null),y=(s,N)=>{navigator.clipboard.writeText(`${window.location.origin}/pay/${s}`),c(N),setTimeout(()=>c(null),2e3)},g=z({mutationFn:async({id:s,status:N})=>{const t=await fetch(`/api/sabhia-pay/links/${s}/status`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:N})});if(!t.ok)throw new Error("Falha");return t.json()},onSuccess:(s,N)=>{p.invalidateQueries({queryKey:[`/api/sabhia-pay/products/${o}`]}),p.invalidateQueries({queryKey:["/api/sabhia-pay/links"]}),d(null),a({title:N.status==="disabled"?"Link desativado":"Link reativado"})},onError:()=>a({title:"Erro ao atualizar o link",variant:"destructive"})});if(l||!m)return e.jsx(W,{children:e.jsx("div",{className:"flex items-center justify-center h-60",children:e.jsx(w,{className:"w-6 h-6 animate-spin text-violet-400"})})});const{product:i,links:f,recentSales:_}=m,S=f.filter(s=>s.status==="active"),$=f.filter(s=>s.status!=="active"),L=s=>e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>y(s.slug,s.id),className:"p-2 rounded-lg hover:bg-white/5 transition text-zinc-400 hover:text-white",title:"Copiar link","data-testid":`button-copy-link-${s.id}`,children:x===s.id?e.jsx(D,{className:"w-4 h-4 text-emerald-400"}):e.jsx(G,{className:"w-4 h-4"})}),e.jsx("a",{href:`/pay/${s.slug}`,target:"_blank",rel:"noopener noreferrer",className:"p-2 rounded-lg hover:bg-white/5 transition text-zinc-400 hover:text-white",title:"Abrir checkout","data-testid":`button-open-link-${s.id}`,children:e.jsx(I,{className:"w-4 h-4"})}),s.status==="active"?h===s.id?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>g.mutate({id:s.id,status:"disabled"}),disabled:g.isPending,className:"p-2 rounded-lg bg-rose-500/15 text-rose-300 hover:bg-rose-500/25 transition disabled:opacity-50",title:"Confirmar desativação","data-testid":`button-confirm-deactivate-link-${s.id}`,children:g.isPending?e.jsx(w,{className:"w-4 h-4 animate-spin"}):e.jsx(D,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>d(null),className:"p-2 rounded-lg hover:bg-white/5 transition text-zinc-400 hover:text-white",title:"Cancelar","data-testid":`button-cancel-deactivate-link-${s.id}`,children:e.jsx(F,{className:"w-4 h-4"})})]}):e.jsx("button",{onClick:()=>
1d(s.id),className:"p-2 rounded-lg hover:bg-rose-500/10 transition text-zinc-400 hover:text-rose-300",title:"Desativar link","data-testid":`button-deactivate-link-${s.id}`,children:e.jsx(O,{className:"w-4 h-4"})}):e.jsxs("button",{onClick:()=>g.mutate({id:s.id,status:"active"}),disabled:g.isPending,className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-emerald-500/15 text-emerald-300 hover:bg-emerald-500/25 transition text-xs font-medium disabled:opacity-50",title:"Reativar link","data-testid":`button-reactivate-link-${s.id}`,children:[g.isPending?e.jsx(w,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(te,{className:"w-3.5 h-3.5"}),"Reativar"]})]});return e.jsxs(W,{children:[e.jsxs("div",{className:"p-6 max-w-5xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx(H,{href:"/pay/produtos",children:e.jsxs("button",{className:"flex items-center gap-1.5 text-sm text-zinc-500 hover:text-white mb-4 transition","data-testid":"link-back-products",children:[e.jsx(Z,{className:"w-4 h-4"})," Produtos"]})}),e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl overflow-hidden bg-violet-500/15 flex items-center justify-center border border-violet-400/20 shrink-0",children:i.image_url?e.jsx("img",{src:i.image_url,alt:i.name,className:"w-full h-full object-cover"}):e.jsx(J,{className:"w-7 h-7 text-violet-400"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h1",{className:"text-xl font-bold text-white",children:i.name}),e.jsx("span",{className:k("text-[10px] px-2 py-0.5 rounded-full font-medium",i.status==="active"?"bg-emerald-500/15 text-emerald-400":"bg-zinc-700/50 text-zinc-400"),children:i.status==="active"?"Ativo":"Arquivado"})]}),i.description&&e.jsx("p",{className:"text-sm text-zinc-500 mt-0.5",children:i.description}),e.jsx("p",{className:"text-lg font-bold text-violet-300 mt-1",children:C(i.price_cents)})]})]}),e.jsxs("button",{onClick:()=>b(!0),className:"inline-flex items-center gap-2 bg-gradient-to-r from-violet-600 to-fuchsia-500 text-white px-4 py-2 rounded-xl font-semibold text-sm shadow-lg shadow-violet-900/30 hover:opacity-90 transition-opacity","data-testid":"button-create-link-header",children:[e.jsx(T,{className:"w-4 h-4"})," Criar Link de Venda"]})]})]}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-white mb-3 flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4 text-violet-400"}),"Links de Venda (",S.length,")"]}),f.length===0?e.jsxs("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] p-8 text-center",children:[e.jsx(q,{className:"w-8 h-8 text-zinc-700 mx-auto mb-3"}),e.jsx("p",{className:"text-zinc-500 text-sm",children:"Nenhum link gerado ainda"}),e.jsxs("button",{onClick:()=>b(!0),className:"mt-3 text-sm text-violet-400 hover:text-violet-300 flex items-center gap-1 mx-auto","data-testid":"button-first-link",children:[e.jsx(T,{className:"w-3.5 h-3.5"})," Criar primeiro link"]})]}):e.jsxs("div",{className:"space-y-3",children:[S.length===0&&e.jsx("div",{className:"rounded-xl border border-violet-400/10 bg-violet-500/[0.03] p-6 text-center",children:e.jsx("p",{className:"text-zinc-500 text-sm",children:"Nenhum link ativo. Crie um novo ou reative um abaixo."})}),S.map(s=>e.jsxs("div",{className:"rounded-xl border border-violet-400/10 bg-violet-500/[0.03] p-4 flex items-center gap-4 flex-wrap","data-testid":`card-link-${s.id}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-white truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsxs("code",{className:"text-xs text-violet-300 bg-violet-500/10 px-2 py-0.5 rounded",children:["/pay/",s.slug]}),e.jsx("span",{className:"text-xs text-zinc-500",children:C(s.amount_cents)}),e.jsx("span",{className:"text-xs text-zinc-600",children:"·"}),e.jsxs("span",{className:"text-xs text-zinc-500",children:[s.paid_count," vendas"]}),e.jsx("span",{className:"text-xs text-zinc-600",children:"·"}),e.jsx("span",{className:"text-xs text-emerald-400",children:C(Number(s.revenue_cents))})]})]}),L(s)]},s.id)),$.length>0&&e.jsxs("div",{className:"pt-2",children:[e.jsxs("p",{className:"text-xs font-medium text-zinc-500 mb-2 flex items-center gap-1.5",children:[e.jsx(O,{className:"w-3.5 h-3.5"})," Inativos (",$.length,")"]}),e.jsx("div",{className:"space-y-3",children:$.map(s=>e.jsxs("div",{className:"rounded-xl border border-white/5 bg-white/[0.02] p-4 flex items-center gap-4 flex-wrap opacity-60","data-testid":`card-link-${s.id}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm font-medium text-zinc-300 truncate",children:s.name}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide font-semibold text-zinc-400 bg-white/5 px-1.5 py-0.5 rounded","data-testid":`badge-inactive-${s.id}`,children:"inativo"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsxs("code",{className:"text-xs text-zinc-400 bg-white/5 px-2 py-0.5 rounded",children:["/pay/",s.slug]}),e.jsx("span",{className:"text-xs text-zinc-500",children:C(s.amount_cents)}),e.jsx("span",{className:"text-xs text-zinc-600",children:"·"}),e.jsxs("span",{className:"text-xs text-zinc-500",children:[s.paid_count," vendas"]})]})]}),L(s)]},s.id))})]})]})]}),o&&e.jsx(le,{product:i,productId:Number(o)}),o&&e.jsx(oe,{productId:Number(o)}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold text-white mb-3 flex items-center gap-2",children:[e.jsx(B,{className:"w-4 h-4 text-violet-400"}),"Vendas Recentes (",_.length,")"]}),_.length===0?e.jsxs("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] p-8 text-center",children:[e.jsx(B,{className:"w-8 h-8 text-zinc-700 mx-auto mb-3"}),e.jsx("p",{className:"text-zinc-500 text-sm",children:"Nenhuma venda ainda para este produto"})]}):e.jsx("div",{className:"rounded-2xl border border-violet-400/10 bg-violet-500/[0.03] overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/5",children:[e.jsx("th",{className:"text-left text-xs text-zinc-500 px-4 py-3 font-medium",children:"Cliente"}),e.jsx("th",{className:"text-left text-xs text-zinc-500 px-4 py-3 font-medium hidden sm:table-cell",children:"Método"}),e.jsx("th",{className:"text-right text-xs text-zinc-500 px-4 py-3 font-medium",children:"Valor"}),e.jsx("th",{className:"text-right text-xs text-zinc-500 px-4 py-3 font-medium hidden md:table-cell",children:"Data"})]})}),e.jsx("tbody",{className:"divide-y divide-white/[0.03]",children:_.map(s=>{const N=s.canonical_amount_cents??s.total_amount_cents??s.amount_cents,t=s._classification==="canonical_bumped";return e.jsxs("tr",{className:"hover:bg-white/[0.02] transition","data-testid":`row-sale-${s.id}`,children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("p",{className:"text-sm text-white",children:s.customer_name||"—"}),e.jsx("p",{className:"text-xs text-zinc-500",children:s.customer_email})]}),e.jsx("td",{className:"px-4 py-3 hidden sm:table-cell",children:e.jsx("span",{className:"text-xs text-zinc-400 capitalize",children:s.payment_method==="pix"?"PIX":s.payment_method==="card"||s.payment_method==="credit_card"?`Cartão ${s.installments&&s.installments>1?`${s.installments}x`:""}`:"—"})}),e.jsxs("td",{className:"px-4 py-3 text-right",children:[e.jsx("span",{className:"text-sm font-semibold text-emerald-400",children:C(N)}),t&&e.jsx("div",{className:"flex justify-end mt-0.5",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-violet-400/80 bg-violet-500/10 border border-violet-400/20 px-1.5 py-0.5 rounded",title:`Inclui bump(s): base ${C(s.amount_cents)} + complementos`,children:[e.jsx(ee,{className:"w-2.5 h-2.5"}),"+bumps"]})})]}),e.jsx("td",{className:"px-4 py-3 text-right hidden md:table-cell",children:e.jsx("span",{className:"text-xs text-zinc-500",children:ne(s.created_at)})})]},s.id)})})]})})]})]}),u&&i&&e.jsx(de,{product:i,onClose:()=>b(!1)})]})}export{ke 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.