1import{u as w,j as s}from"./vendor-query-Cuv1FQk6.js";import{r as y}from"./vendor-react-qWEbcnl5.js";import{C as j}from"./card-nIfhOB9l.js";import{T as k,a as q,b as S}from"./tabs-DkS0y07O.js";import{T as d,a as m,b as n,c as i,d as h,e as a}from"./table-8EHVE-Kn.js";import{G as T,p as c}from"./useAdminGrowth-Cg4wtTSq.js";import{s as P}from"./index-zfWpKczA.js";import{c as E,a as A}from"./vendor-icons-CQPDGG0w.js";import"./vendor-radix-C88Ak59v.js";import"./vendor-supabase-C_eKbu-8.js";import"./vendor-recharts-D60XYxEx.js";import"./vendor-helmet-OKLD9pxQ.js";function F(l,o=!0){return w({queryKey:["admin-marketing-overview",l],enabled:o,staleTime:5*60*1e3,queryFn:async()=>{const{data:t,error:g}=await P.rpc("admin_marketing_overview",{p_days:T[l]});if(g)throw g;return t}})}const R=[{value:"14d",label:"14 dias"},{value:"30d",label:"30 dias"},{value:"90d",label:"90 dias"},{value:"180d",label:"180 dias"}];function p({label:l,value:o,hint:t}){return s.jsxs(j,{className:"p-4 md:p-5",children:[s.jsx("p",{className:"text-2xl md:text-3xl font-bold tracking-tight text-foreground",children:o}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:l}),s.jsx("p",{className:"text-xs text-muted-foreground/80 mt-1",children:t})]})}function u({title:l,description:o,children:t}){return s.jsxs(j,{className:"p-4 md:p-5",children:[s.jsxs("div",{className:"mb-3",children:[s.jsx("h3",{className:"text-sm font-semibold",children:l}),s.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:o})]}),s.jsx("div",{className:"overflow-x-auto",children:t})]})}function K(){const[l,o]=y.useState("30d"),{data:t,isLoading:g,isError:C}=F(l),$=T[l],_=y.useMemo(()=>{if(!t)return[];const e=[],x=[...t.pages??[]].filter(r=>r.form_starts>=30).map(r=>({...r,rate:c(r.conversions,r.form_starts)})).sort((r,b)=>r.rate-b.rate)[0];x&&e.push(`${x.path}: ${x.form_starts} pessoas começaram o formulário e só ${x.conversions} concluÃram (${x.rate}%). Vale encurtar o formulário ou reforçar o que a pessoa recebe.`);const N=[...t.entry_pages??[]].filter(r=>r.sessions>=50).map(r=>({...r,rate:c(r.converted_sessions,r.sessions)})).sort((r,b)=>b.rate-r.rate)[0];N&&e.push(`Quem entra por ${N.path} converte ${N.rate}% das visitas â é a porta de entrada com melhor retorno para receber mais tráfego.`);const v=(t.pages??[]).filter(r=>r.cta_views>=100&&r.conversions===0);v.length&&e.push(`${v.length} página(s) com bastante visualização de chamada e nenhuma conversão no perÃodo (ex.: ${v[0].path}).`);const f=(t.submissions??[]).filter(r=>r.submissions>0&&r.deals===0);return f.length&&e.push(`${f.length} página(s) geraram cadastros que ainda não viraram negócio no funil (ex.: ${f[0].path}).`),e},[t]);return s.jsxs("section",{className:"space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:"Marketing do site"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"Por onde as pessoas entram, onde convertem e quais formulários funcionam."})]}),s.jsx(k,{value:l,onValueChange:e=>o(e),children:s.jsx(q,{children:R.map(e=>s.jsx(S,{value:e.value,className:"text-xs",children:e.label},e.value))})})]}),C?s.jsxs(j,{className:"p-5 flex items-center gap-2 text-sm text-muted-foreground",children:[s.jsx(E,{className:"h-4 w-4"}),"Não foi possÃvel carregar os dados de marketing agora."]}):g||!t?s.jsx(j,{className:"p-8 flex items-center justify-center text-muted-foreground",children:s.jsx(A,{className:"h-5 w-5 animate-spin"})}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[s.jsx(p,{label:"Visitas com atividade",value:String(t.totals.sessions),hint:`Ãltimos ${$} dias`}),s.jsx(p,{label:"Formulários iniciados",value:String(t.totals.form_starts),hint:`${t.totals.abandons} abandonados`}),s.jsx(p,{label:"Conversões",value:String(t.totals.conversions),hint:`${c(t.totals.conversions,t.totals.form_starts)}% de quem começou`}),s.jsx(p,{label:"Cliques no WhatsApp",value:String(t.totals.whatsapp_clicks),hint:"Contato direto pelo site"})]}),_.length>0&&s.jsxs(j,{className:"p-4 md:p-5",children:[s.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Ideias de melhoria"}),s.jsx("ul",{className:"space-y-1.5 text-sm text-muted-foreground list-disc pl-4",children:_.map(e=>s.jsx("li",{children:e},e))})]}),s.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[s.jsx(u,{title:"Páginas que mais convertem",description:"InÃcio de formulário x conversões por página",children:s.jsxs(d,{children:[s.jsx(m,{children:s.jsxs(n,{children:[s.jsx(i,{className:"text-xs",children:"Página"}),s.jsx(i,{className:"text-xs text-right",children:"Chamadas vistas"}),s.jsx(i,{className:"text-xs text-right",children:"Iniciaram"}),s.jsx(i,{className:"text-xs text-right",children:"Converteram"}),s.jsx(i,{className:"text-xs text-right",children:"Taxa"})]})}),s.jsx(h,{children:t.pages.slice(0,15).map(e=>s.jsxs(n,{className:"h-8",children:[s.jsx(a,{className:"text-xs font-medium",children:e.path}),s.jsx(a,{className:"text-xs text-right",children:e.cta_views}),s.jsx(a,{className:"text-xs text-right",children:e.form_starts}),s.jsx(a,{className:"text-xs text-right",children:e.conversions}),s.jsxs(a,{className:"text-xs text-right",children:[c(e.conversions,e.form_starts),"%"]})]},e.path))})]})}),s.jsx(u,{title:"Por qual página entrou",description:"Primeira página da visita e quanto dela vira conversão",children:s.jsxs(d,{children:[s.jsx(m,{children:s.jsxs(n,{children:[s.jsx(i,{className:"text-xs",children:"Entrada"}),s.jsx(i,{className:"text-xs text-right",children:"Visitas"}),s.jsx(i,{className:"text-xs text-right",children:"Converteram"}),s.jsx(i,{className:"text-xs text-right",children:"Taxa"})]})}),s.jsx(h,{children:t.entry_pages.slice(0,15).map(e=>s.jsxs(n,{className:"h-8",children:[s.jsx(a,{className:"text-xs font-medium",children:e.path}),s.jsx(a,{className:"text-xs text-right",children:e.sessions}),s.jsx(a,{className:"text-xs text-right",children:e.converted_sessions}),s.jsxs(a,{className:"text-xs text-right",children:[c(e.converted_sessions,e.sessions),"%"]})]},e.path))})]})}),s.jsx(u,{title:"Por qual página converteu",description:"Página onde o contato foi enviado",children:s.jsxs(d,{children:[s.jsx(m,{children:s.jsxs(n,{children:[s.jsx(i,{className:"text-xs",children:"Página"}),s.jsx(i,{className:"text-xs text-right",children:"Conversões"})]})}),s.jsx(h,{children:t.conversion_pages.length===0?s.jsx(n,{children:s.jsx(a,{colSpan:2,className:"text-xs text-muted-foreground",children:"Nenhuma conversão registrada no perÃodo."})}):t.conversion_pages.slice(0,15).map(e=>s.jsxs(n,{className:"h-8",children:[s.jsx(a,{className:"text-xs font-medium",children:e.path}),s.jsx(a,{className:"text-xs text-right",children:e.conversions})]},e.path))})]})}),s.jsx(u,{title:"Formulários",description:"Quanto cada formulário inicia, conclui e abandona",children:s.jsxs(d,{children:[s.jsx(m,{children:s.jsxs(n,{children:[s.jsx(i,{className:"text-xs",children:"Formulário"}),s.jsx(i,{className:"text-xs text-right",children:"Iniciados"}),s.jsx(i,{className:"text-xs text-right",children:"Enviados"}),s.jsx(i,{className:"text-xs text-right",children:"Abandonos"}),s.jsx(i,{className:"text-xs text-right",children:"Taxa"})]})}),s.jsx(h,{children:t.forms.slice(0,12).map(e=>s.jsxs(n,{className:"h-8",children:[s.jsx(a,{className:"text-xs font-medium",children:e.form_key}),s.jsx(a,{className:"text-xs text-right",children:e.starts}),s.jsx(a,{className:"text-xs text-right",children:e.submits}),s.jsx(a,{className:"text-xs text-right",children:e.abandons}),s.jsxs(a,{className:"text-xs text-right",children:[c(e.submits,e.starts),"%"]})]},e.form_key))})]})})]}),s.jsx(u,{title:"Cadastros recebidos",description:"Contatos enviados pelo site e quantos viraram negócio no funil",children:s.jsxs(d,{children:[s.jsx(m,{children:s.jsxs(n,{children:[s.jsx(i,{className:"text-xs",children:"Página"}),s.jsx(i,{className:"text-xs",children:"Formulário / variante"}),s.jsx(i,{className:"text-xs text-right",children:"Cadastros"}),s.jsx(i,{className:"text-xs text-right",children:"Viraram negócio"})]})}),s.jsx(h,{children:t.submissions.length===0?s.jsx(n,{children:s.jsx(a,{colSpan:4,className:"text-xs text-muted-foreground",children:"Nenhum cadastro no perÃodo."})}):t.submissions.map(e=>s.jsxs(n,{className:"h-8",children:[s.jsx(a,{className:"text-xs font-medium",children:e.path}),s.jsx(a,{className:"text-xs",children:e.variant}),s.jsx(a,{className:"text-xs text-right",children:e.submissions}),s.jsx(a,{className:"text-xs text-right",children:e.deals})]},`${e.path}-${e.variant}`))})]})})]})]})}export{K as AdminMarketingPanel};
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.