1import{u as z,j as s}from"./vendor-query-skQMsM6X.js";import{r as w}from"./vendor-react-DyYvSSk1.js";import{aJ as U,r as I,v as V,x as A,y as B,z as q,p as K,at as d,au as m,av as h,ax as j,ak as u,ab as E,b as M}from"./index-BGwtrXIa.js";import{T as N,a as g,b as r,c as n,d as p,e as t}from"./table-DnRDtd-j.js";import{aR as P}from"./vendor-ui-CCmu0bzQ.js";import"./vendor-supabase-BfoV2C50.js";const $=[{v:7,l:"7 dias"},{v:30,l:"30 dias"},{v:90,l:"90 dias"},{v:365,l:"1 ano"}],J=[{v:"all",l:"Todos"},{v:"signup_only",l:"Só cadastrou (sem sessão real)"},{v:"no_ai",l:"Nunca usou IA"},{v:"no_voice",l:"Nunca usou voz"},{v:"returned",l:"Voltou (â¥2 dias)"}],x=(a,f)=>f>0?(a/f*100).toFixed(1)+"%":"â",v=a=>a?new Date(a).toLocaleString("pt-BR"):"â",Q=a=>new Date(a).toLocaleDateString("pt-BR");function ts(){var S,k,C,T,F,D,R;const[a,f]=w.useState(90),[_,W]=w.useState("all"),i=z({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-funnel-metrics",a],queryFn:async()=>{const{data:e,error:l}=await M.rpc("admin_get_funnel_metrics",{p_days:a});if(l)throw l;return e}}),c=z({staleTime:6e4,refetchOnWindowFocus:!1,queryKey:["admin-user-activity",a,_],queryFn:async()=>{const{data:e,error:l}=await M.rpc("admin_get_user_activity_matrix",{p_days:a,p_limit:500,p_offset:0,p_filter:_});if(l)throw l;return e}}),o=(S=i.data)==null?void 0:S.funnel,b=w.useMemo(()=>o?[{key:"signed_up",label:"Cadastrou",n:o.signed_up},{key:"opened_editor",label:"Abriu o editor",n:o.opened_editor},{key:"first_interaction",label:"1ª interação real",n:o.first_interaction},{key:"used_ai",label:"Usou IA (â¥1)",n:o.used_ai},{key:"used_voice",label:"Usou voz (â¥1)",n:o.used_voice},{key:"returned",label:"Voltou (â¥2 dias)",n:o.returned}]:[],[o]),y=(o==null?void 0:o.signed_up)??0;return s.jsx(U,{children:s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold text-foreground font-mono",children:"Funil & Retenção"}),s.jsxs("p",{className:"text-muted-foreground mt-1 font-mono text-sm",children:["Fonte: sessões do editor (",s.jsx("code",{children:"editor_sessions"}),", telemetria v3 â histórico completo) · janela = últimos ",a,' dias. Definição diferente da aba "Saúde do Produto" (eventos), então os números não batem entre as duas.']})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(I,{value:String(a),onValueChange:e=>f(Number(e)),children:[s.jsx(V,{className:"w-36 font-mono text-xs",children:s.jsx(A,{})}),s.jsx(B,{children:$.map(e=>s.jsx(q,{value:String(e.v),children:e.l},e.v))})]}),s.jsx(K,{variant:"ghost",size:"icon",onClick:()=>{i.refetch(),c.refetch()},children:s.jsx(P,{className:`h-4 w-4 ${i.isFetching?"animate-spin":""}`})})]})]}),s.jsxs(d,{children:[s.jsx(m,{children:s.jsx(h,{className:"font-mono text-base",children:"Funil de ativação"})}),s.jsx(j,{children:i.isLoading?s.jsx(u,{className:"h-48 w-full"}):s.jsx("div",{className:"space-y-2",children:b.map((e,l)=>{const H=y>
10?Math.max(4,e.n/y*100):0,O=l===0?e.n:b[l-1].n,L=l===0?null:x(e.n,O);return s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-48 text-sm font-mono text-muted-foreground",children:e.label}),s.jsxs("div",{className:"flex-1 bg-muted/40 rounded h-8 relative overflow-hidden",children:[s.jsx("div",{className:"h-full bg-primary/80 rounded transition-all",style:{width:`${H}%`}}),s.jsxs("span",{className:"absolute inset-0 flex items-center px-3 text-xs font-mono font-semibold",children:[e.n," · ",x(e.n,y)," do topo"]})]}),s.jsx("div",{className:"w-28 text-right text-xs font-mono",children:L?s.jsxs(E,{variant:"outline",children:["â ",L]}):s.jsx("span",{className:"text-muted-foreground",children:"base"})})]},e.key)})})})]}),s.jsxs(d,{children:[s.jsx(m,{children:s.jsx(h,{className:"font-mono text-base",children:"Retenção por cohort semanal"})}),s.jsx(j,{children:i.isLoading?s.jsx(u,{className:"h-40 w-full"}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs(N,{children:[s.jsx(g,{children:s.jsxs(r,{children:[s.jsx(n,{className:"font-mono text-xs",children:"Semana"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Cadastros"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"D1"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"D7"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"D30"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Só cadastro"})]})}),s.jsx(p,{children:(((k=i.data)==null?void 0:k.cohorts)??[]).map(e=>s.jsxs(r,{children:[s.jsx(t,{className:"font-mono text-xs",children:Q(e.cohort_week)}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.signups}),s.jsxs(t,{className:"font-mono text-xs text-right",children:[e.d1," ",s.jsxs("span",{className:"text-muted-foreground",children:["(",x(e.d1,e.signups),")"]})]}),s.jsxs(t,{className:"font-mono text-xs text-right",children:[e.d7," ",s.jsxs("span",{className:"text-muted-foreground",children:["(",x(e.d7,e.signups),")"]})]}),s.jsxs(t,{className:"font-mono text-xs text-right",children:[e.d30," ",s.jsxs("span",{className:"text-muted-foreground",children:["(",x(e.d30,e.signups),")"]})]}),s.jsxs(t,{className:"font-mono text-xs text-right",children:[e.signup_only," ",s.jsxs("span",{className:"text-muted-foreground",children:["(",x(e.signup_only,e.signups),")"]})]})]},e.cohort_week))})]})})})]}),s.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[s.jsxs(d,{children:[s.jsx(m,{children:s.jsx(h,{className:"font-mono text-base",children:"Sessões por origem"})}),s.jsx(j,{children:i.isLoading?s.jsx(u,{className:"h-32 w-full"}):s.jsxs(N,{children:[s.jsx(g,{children:s.jsxs(r,{children:[s.jsx(n,{className:"font-mono text-xs",children:"source"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"sessões"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"usuários"})]})}),s.jsx(p,{children:(((C=i.data)==null?void 0:C.sources)??[]).map(e=>s.jsxs(r,{children:[s.jsx(t,{className:"font-mono text-xs",children:e.source}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.sessions}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.users})]},e.source))})]})})]}),s.jsxs(d,{children:[s.jsx(m,{children:s.jsx(h,{className:"font-mono text-base",children:"Sessões por tipo"})}),s.jsx(j,{children:i.isLoading?s.jsx(u,{className:"h-32 w-full"}):s.jsxs(N,{children:[s.jsx(g,{children:s.jsxs(r,{children:[s.jsx(n,{className:"font-mono text-xs",children:"kind"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"sessões"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"usuários"})]})}),s.jsx(p,{children:(((T=i.data)==null?void 0:T.kinds)??[]).map(e=>s.jsxs(r,{children:[s.jsx(t,{className:"font-mono text-xs",children:e.kind}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.sessions}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.users})]},e.kind))})]})})]})]}),s.jsxs(d,{children:[s.jsxs(m,{className:"flex flex-row items-center justify-between space-y-0",children:[s.jsx(h,{className:"font-mono text-base",children:"Matriz de usuários"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(I,{value:_,onValueChange:W,children:[s.jsx(V,{className:"w-64 font-mono text-xs",children:s.jsx(A,{})}),s.jsx(B,{children:J.map(e=>s.jsx(q,{value:e.v,children:e.l},e.v))})]}),s.jsxs(E,{variant:"outline",className:"font-mono text-xs",children:[((F=c.data)==null?void 0:F.total)??0," usuários"]})]})]}),s.jsx(j,{children:c.isLoading?s.jsx(u,{className:"h-64 w-full"}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs(N,{children:[s.jsx(g,{children:s.jsxs(r,{children:[s.jsx(n,{className:"font-mono text-xs",children:"Usuário"}),s.jsx(n,{className:"font-mono text-xs",children:"Cadastro"}),s.jsx(n,{className:"font-mono text-xs",children:"1ª sessão"}),s.jsx(n,{className:"font-mono text-xs",children:"1ª interação"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Sessões"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Dias ativos"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Edits"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"IA"}),s.jsx(n,{className:"font-mono text-xs text-right",children:"Voz"}),s.jsx(n,{className:"font-mono text-xs",children:"Ãltima atividade"})]})}),s.jsxs(p,{children:[(((D=c.data)==null?void 0:D.rows)??[]).map(e=>s.jsxs(r,{children:[s.jsxs(t,{className:"font-mono text-xs",children:[s.jsx("div",{className:"font-semibold",children:e.full_name||"â"}),s.jsx("div",{className:"text-muted-foreground",children:e.email}),e.crm&&s.jsxs("div",{className:"text-muted-foreground",children:["CRM ",e.crm,"/",e.uf]})]}),s.jsx(t,{className:"font-mono text-xs",children:v(e.signed_up_at)}),s.jsx(t,{className:"font-mono text-xs",children:v(e.first_session_at)}),s.jsx(t,{className:"font-mono text-xs",children:v(e.first_interaction_at)}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.total_sessions}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.active_days}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.edits}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.ai_used}),s.jsx(t,{className:"font-mono text-xs text-right",children:e.voice_used}),s.jsx(t,{className:"font-mono text-xs",children:v(e.last_activity_at)})]},e.user_id)),(((R=c.data)==null?void 0:R.rows)??[]).length===0&&s.jsx(r,{children:s.jsx(t,{colSpan:10,className:"text-center text-muted-foreground font-mono text-xs py-8",children:"Nenhum usuário nesse filtro."})})]})]})})})]})]})})}export{ts 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.