1import{r as i,j as e,N as T,O as F,Q as G,B as k}from"./index-XrERYidG.js";import{u as L}from"./useServerFn-RaV1yPZd.js";import{saveCampaignSpend as B,deleteCampaignSpend as O,getLeadConversionsReport as V}from"./lead-conversions.functions-jmXMl-3J.js";const p=i.forwardRef(({className:l,type:s,...t},m)=>e.jsx("input",{type:s,className:T("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",l),ref:m,...t}));p.displayName="Input";var z=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],U=z.reduce((l,s)=>{const t=F(`Primitive.${s}`),m=i.forwardRef((f,h)=>{const{asChild:j,...o}=f,u=j?t:s;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(u,{...o,ref:h})});return m.displayName=`Primitive.${s}`,{...l,[s]:m}},{}),H="Label",_=i.forwardRef((l,s)=>e.jsx(U.label,{...l,ref:s,onMouseDown:t=>{t.target.closest("button, input, select, textarea")||(l.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));_.displayName=H;var A=_;const K=G("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),x=i.forwardRef(({className:l,...s},t)=>e.jsx(A,{ref:t,className:T(K(),l),...s}));x.displayName=A.displayName;const Q=[7,30,90];function Z(){const l=L(V),[s,t]=i.useState(""),[m,f]=i.useState(30),[h,j]=i.useState("0"),[o,u]=i.useState(null),[w,g]=i.useState(null),[y,b]=i.useState(!1);async function v(a=m,S=h){b(!0),g(null);try{const N=await l({data:{password:s,days:a,ticket:Number(S)||0}});N.ok?u(N.report):(u(null),g("Senha inválida."))}catch{g("Não foi possÃvel carregar o relatório agora.")}finally{b(!1)}}return e.jsxs("main",{className:"mx-auto max-w-6xl px-4 pt-28 pb-20 sm:px-6 lg:px-8",children:[e.jsxs("h1",{className:"text-3xl font-bold tracking-tight",children:["Relatório de ",e.jsx("span",{className:"gradient-text",children:"leads por campanha"})]}),e.jsx("p",{className:"mt-2 max-w-2xl text-muted-foreground",children:"Cada lead enviado pelo site é gravado com UTMs, click IDs (fbclid, gclid, ttclid) e a origem resolvida. Use a senha interna para consultar."}),e.jsxs("form",{className:"mt-8 flex flex-wrap items-end gap-3",onSubmit:a=>{a.preventDefault(),v()},children:[e.jsxs("div",{className:"w-64",children:[e.jsx(x,{htmlFor:"report-password",children:"Senha interna"}),e.jsx(p,{id:"report-password",type:"password",autoComplete:"current-password",value:s,onChange:a=>t(a.target.value),className:"mt-1"})]}),e.jsx("div",{className:"flex gap-2",children:Q.map(a=>e.jsxs(k,{type:"button",variant:m===a?"default":"outline",onClick:()=>{f(a),o&&v(a)},children:[a," dias"]},a))}),e.jsxs("div",{className:"w-40",children:[e.jsx(x,{htmlFor:"report-ticket",children:"Ticket médio (R$)"}),e.jsx(p,{id:"report-ticket",type:"number",min:0,step:"0.01",value:h,onChange:a=>j(a.target.value),className:"mt-1"})]}),e.jsx(k,{type:"submit",disabled:!s||y,className:"gradient-primary text-white",children:y?"Carregando...":"Ver relatório"})]}),w&&e.jsx("p",{className:"mt-4 text-sm text-destructive",children:w}),o&&e.jsxs("div",{className:"mt-10 space-y-10",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{className:"text-foreground",children:o.total})," leads nos últimos ",o.days," dias."]}),e.jsx(q,{report:o}),e.jsx(J,{password:s,report:o,onChanged:()=>{v()}}),e.jsx(D,{title:"Por campanha (utm_campaign)",rows:o.byCampaign}),e.jsx(D,{title:"Por origem resolvida",rows:o.bySource}),e.jsx(D,{title:"Por formulário",rows:o.byForm}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Ãltimos leads"}),e.jsx("div",{className:"mt-3 overflow-x-auto rounded-xl border border-white/10",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-white/5 text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx(n,{children:"Data"}),e.jsx(n,{children:"Nome"}),e.jsx(n,{children:"Contato"}),e.jsx(n,{children:"Origem"}),e.jsx(n,{children:"Campanha"}),e.jsx(n,{children:"Click ID"}),e.jsx(n,{children:"Entrada"})]})}),e.jsx("tbody",{children:o.leads.map(a=>e.jsxs("tr",{className:"border-t border-white/5",children:[e.jsx(r,{children:new Date(a.created_at).toLocaleStr
1ing("pt-BR")}),e.jsx(r,{children:a.name??"â"}),e.jsxs(r,{children:[e.jsx("div",{children:a.email??"â"}),e.jsx("div",{className:"text-muted-foreground",children:a.phone??""})]}),e.jsxs(r,{children:[e.jsx("div",{children:a.resolved_source}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a.attribution_method})]}),e.jsxs(r,{children:[e.jsx("div",{children:a.utm_campaign??"â"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:[a.utm_source,a.utm_medium,a.utm_content].filter(Boolean).join(" / ")})]}),e.jsx(r,{className:"max-w-[180px] truncate",children:a.fbclid?`fbclid: ${a.fbclid}`:a.gclid?`gclid: ${a.gclid}`:"â"}),e.jsx(r,{children:a.landing_path??"â"})]},a.id))})]})})]})]})]})}const c=l=>l.toLocaleString("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:2});function C({label:l,value:s,hint:t}){return e.jsxs("div",{className:"rounded-xl border border-white/10 bg-white/5 p-4",children:[e.jsx("div",{className:"text-xs uppercase text-muted-foreground",children:l}),e.jsx("div",{className:"mt-1 text-2xl font-semibold",children:s}),t&&e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t})]})}function q({report:l}){const s=l.performance;return e.jsxs("section",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"CPA e ROAS por campanha"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Investimento do perÃodo cruzado com os leads gravados. Leads por plataforma são contados pelo click ID (fbclid, gclid/wbraid/gbraid, ttclid, oppref) com fallback em utm_source."}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(C,{label:"Investimento total",value:c(s.spendTotal),hint:`Meta ${c(s.spendMeta)} · Google ${c(s.spendGoogle)} · Extra ${c(s.spendExtra)}`}),e.jsx(C,{label:"Leads",value:String(s.leads)}),e.jsx(C,{label:"CPA geral",value:s.cpa===null?"â":c(s.cpa)}),e.jsx(C,{label:"ROAS geral",value:s.roas===null?"â":`${s.roas.toFixed(2)}x`,hint:s.ticket>0?`Receita estimada ${c(s.revenue)} (ticket ${c(s.ticket)})`:"Informe o ticket médio para o ROAS"})]}),s.spendSemCampanha>0&&e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:[c(s.spendSemCampanha)," de investimento sem campanha definida ficam agrupados em â(sem campanha)â."]}),e.jsx("div",{className:"mt-4 overflow-x-auto rounded-xl border border-white/10",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-white/5 text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx(n,{children:"Campanha"}),e.jsx(n,{children:"Leads"}),e.jsx(n,{children:"Meta"}),e.jsx(n,{children:"Google"}),e.jsx(n,{children:"TikTok"}),e.jsx(n,{children:"ChatGPT"}),e.jsx(n,{children:"Sem click ID"}),e.jsx(n,{children:"Investimento"}),e.jsx(n,{children:"CPA"}),e.jsx(n,{children:"ROAS"})]})}),e.jsx("tbody",{children:s.campaigns.length===0?e.jsx("tr",{children:e.jsx(r,{className:"text-muted-foreground",children:"Sem dados no perÃodo."})}):s.campaigns.map(t=>e.jsxs("tr",{className:"border-t border-white/5",children:[e.jsx(r,{children:t.campaign}),e.jsx(r,{children:t.leads}),e.jsx(r,{children:t.leadsMeta}),e.jsx(r,{children:t.leadsGoogle}),e.jsx(r,{children:t.leadsTikTok}),e.jsx(r,{children:t.leadsChatGpt}),e.jsx(r,{children:t.leadsSemClickId}),e.jsxs(r,{children:[e.jsx("div",{children:c(t.spendTotal)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["M ",c(t.spendMeta)," · G ",c(t.spendGoogle)," · E ",c(t.spendExtra)]})]}),e.jsx(r,{children:t.cpa===null?"â":c(t.cpa)}),e.jsx(r,{children:t.roas===null?"â":`${t.roas.toFixed(2)}x`})]},t.campaign))})]})})]})}const I=[{key:"meta",label:"Meta"},{key:"google",label:"Google"},{key:"extra",label:"Extra"}
1];function J({password:l,report:s,onChanged:t}){const m=L(B),f=L(O),h=new Date().toISOString().slice(0,10),[j,o]=i.useState("meta"),[u,w]=i.useState(""),[g,y]=i.useState(h),[b,v]=i.useState(h),[a,S]=i.useState(""),[N,P]=i.useState(!1),[$,R]=i.useState(null);async function E(){P(!0),R(null);try{(await m({data:{password:l,channel:j,campaign:u,period_start:g,period_end:b,amount:Number(a)||0}})).ok?(S(""),t()):R("Senha inválida.")}catch{R("Não foi possÃvel salvar o investimento.")}finally{P(!1)}}return e.jsxs("section",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Investimentos (Meta, Google e extras)"}),e.jsxs("form",{className:"mt-3 flex flex-wrap items-end gap-3",onSubmit:d=>{d.preventDefault(),E()},children:[e.jsxs("div",{children:[e.jsx(x,{htmlFor:"spend-channel",children:"Canal"}),e.jsx("select",{id:"spend-channel",value:j,onChange:d=>o(d.target.value),className:"mt-1 h-10 rounded-md border border-input bg-background px-3 text-sm",children:I.map(d=>e.jsx("option",{value:d.key,children:d.label},d.key))})]}),e.jsxs("div",{className:"w-56",children:[e.jsx(x,{htmlFor:"spend-campaign",children:"Campanha (utm_campaign)"}),e.jsx(p,{id:"spend-campaign",value:u,placeholder:"vazio = geral",onChange:d=>w(d.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(x,{htmlFor:"spend-start",children:"InÃcio"}),e.jsx(p,{id:"spend-start",type:"date",value:g,onChange:d=>y(d.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(x,{htmlFor:"spend-end",children:"Fim"}),e.jsx(p,{id:"spend-end",type:"date",value:b,onChange:d=>v(d.target.value),className:"mt-1"})]}),e.jsxs("div",{className:"w-32",children:[e.jsx(x,{htmlFor:"spend-amount",children:"Valor (R$)"}),e.jsx(p,{id:"spend-amount",type:"number",min:0,step:"0.01",value:a,onChange:d=>S(d.target.value),className:"mt-1"})]}),e.jsx(k,{type:"submit",disabled:N||!a,children:N?"Salvando...":"Adicionar"})]}),$&&e.jsx("p",{className:"mt-2 text-sm text-destructive",children:$}),s.spends.length>0&&e.jsx("div",{className:"mt-4 overflow-x-auto rounded-xl border border-white/10",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-white/5 text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx(n,{children:"Canal"}),e.jsx(n,{children:"Campanha"}),e.jsx(n,{children:"PerÃodo"}),e.jsx(n,{children:"Valor"}),e.jsx(n,{children:"Ação"})]})}),e.jsx("tbody",{children:s.spends.map(d=>e.jsxs("tr",{className:"border-t border-white/5",children:[e.jsx(r,{children:I.find(M=>M.key===d.channel)?.label??d.channel}),e.jsx(r,{children:d.campaign||"(geral)"}),e.jsxs(r,{children:[new Date(`${d.period_start}T12:00:00`).toLocaleDateString("pt-BR")," â"," ",new Date(`${d.period_end}T12:00:00`).toLocaleDateString("pt-BR")]}),e.jsx(r,{children:c(d.amount)}),e.jsx(r,{children:e.jsx(k,{type:"button",variant:"outline",size:"sm",onClick:async()=>{await f({data:{password:l,id:d.id}}),t()},children:"Remover"})})]},d.id))})]})})]})}function D({title:l,rows:s}){return e.jsxs("section",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:l}),s.length===0?e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Nenhum lead no perÃodo."}):e.jsx("div",{className:"mt-3 overflow-x-auto rounded-xl border border-white/10",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-white/5 text-xs uppercase text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx(n,{children:"Chave"}),e.jsx(n,{children:"Leads"}),e.jsx(n,{children:"Campanhas distintas"}),e.jsx(n,{children:"Ãltimo lead"})]})}),e.jsx("tbody",{children:s.map(t=>e.jsxs("tr",{className:"border-t border-white/5",children:[e.jsx(r,{children:t.key}),e.jsx(r,{children:t.total}),e.jsx(r,{children:t.campaigns}),e.jsx(r,{children:t.lastAt?new Date(t.lastAt).toLocaleString("pt-BR"):"â"})]},t.key))})]})})]})}function n({children:l}){return e.jsx("th",{className:"px-3 py-2 font-medium",children:l})}function r({children:l,className:s=""}){return e.jsx("td",{className:`px-3 py-2 align-top ${s}`,children:l})}export{Z as component}; 2//# sourceMappingURL=relatorio-leads-C_3RgEiC.js.map
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.