PageSourceSearch

https://wafly.io/assets/AdminClients-C1xjtg5G.js

js wafly.io collected 2026-10-05 02:40:33 UTC 33,467 bytes, 11 lines download raw bytes

1import{e as xe,u as Pe,r as h,j as e,B as N,M as Y,I as Te,_ as Be,f as le,S as Z}from"./index-CcfyUbhu.js";import{U as Q,H as F,L as Re,K as ue,I as J,a as pe,T as ie}from"./Layout-Cqb3e_Sy.js";import{C as y,a as C}from"./card-BII9Dvbz.js";import{B as b}from"./badge-CQLlXhon.js";import{S as $e}from"./switch-DWHi-M6E.js";import{S as k}from"./skeleton-DuJD7gyb.js";import{D as De,a as Fe,b as Ee,c as _e,d as qe}from"./dialog-BvXjh0TP.js";import{S as Oe,a as ze,b as Ge,c as Ue,d as Ve}from"./select-DLz4vT6X.js";import{a as oe,u as We,i as He,j as Qe,k as Ke,b as Xe,e as Ye,l as Ze,m as Je,n as es,o as ss,p as as,q as ts}from"./use-admin-BOZEeIR6.js";import{A as E}from"./activity-DO4AZ95V.js";import{S as _}from"./smartphone-BS6Jj_9w.js";import{S as ns}from"./search-Bd8Xwkhn.js";import{R as rs}from"./refresh-cw-MhyTejAZ.js";import{M as he}from"./mail-8tKVbLmq.js";import{C as ge}from"./chevron-left-BFggGQV-.js";import{C as ls}from"./circle-x-CCQZaQRi.js";import{T as A}from"./triangle-alert-B8Ve8n5z.js";import{G as z}from"./gift-BLHDi92q.js";import{R as is,X as os,Y as ce,F as cs,B as ds,L as ms}from"./generateCategoricalChart-CwHHDmvc.js";import{C as xs,a as us}from"./ComposedChart-DW-BAITe.js";import{I as fe}from"./inbox-CrDBe29K.js";import{W as ps}from"./wifi-cR8PUr27.js";import{W as hs}from"./wifi-off-AiE_yGeY.js";import"./separator-DAWqHvnE.js";import"./shield-BJKF7xps.js";import"./index-BdQq_4o_.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const gs=xe("MoonStar",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9",key:"4ay0iu"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const je=xe("Phone",[["path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",key:"foiqr5"}]]);function be(s,r){return(s.status??"active")==="suspended"?{key:"suspended",label:"Suspenso",icon:ls,cls:"bg-destructive/15 text-destructive border-destructive/30"}:s.instanceCount===0?{key:"never",label:"Sem instância",icon:gs,cls:"bg-muted text-muted-foreground border-border"}:r===void 0?{key:"loading",label:"…",icon:E,cls:"bg-muted text-muted-foreground border-border"}:r?{key:"active",label:"Ativo",icon:E,cls:"bg-success/15 text-success border-success/30"}:{key:"idle",label:"Sem uso (7d)",icon:A,cls:"bg-amber-500/15 text-amber-600 border-amber-500/30"}}function fs(s){const r=[];if(s.paidInstances>0&&r.push(`${s.paidInstances} paga${s.paidInstances>1?"s":""}`),(s.compedInstances??0)>0&&r.push(`${s.compedInstances} cortesia${s.compedInstances>1?"s":""}`),s.trialInstances>0&&r.push(`${s.trialInstances} trial${s.trialInstances>1?"s":""}`),r.length===0)return null;const a=s.paidInstances>0;return{label:r.join(" · "),icon:a?J:z,cls:a?"bg-success/15 text-success border-success/30":"bg-blue-500/15 text-blue-600 border-blue-500/30"}}function js(s){return s.billingDrift?{label:`Stripe cobra ${s.subscriptionQuantity} × pagas ${s.paidInstances}`,icon:A,cls:"bg-destructive/15 text-destructive border-destructive/30"}:null}const bs=["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"],vs=new Set(["chatgpt.com","claude.ai","gemini","perplexity.ai","copilot","grok","deepseek","poe","you.com","phind","mistral","meta.ai","qwen"]);function Ns(s){const[r,a]=(s||"").split("-");return`${bs[Number(a)-1]??a}/${(r??"").slice(2)}`}function K(s){return s?{organic_search:"Busca orgânica",direct:"Direto",indication:"Indicação",meta:"Meta",instagram:"Instagram","chatgpt.com":"ChatGPT","claude.ai":"Claude",gemini:"Gemini","perplexity.ai":"Perplexity",copilot:"Microsoft Copilot",grok:"Grok",deepseek:"DeepSeek",poe:"Poe","you.com":"You.com",phind:"Phind",mistral:"Mistral / Le Chat","meta.ai":"Meta AI",qwen:"Qwen",google_organic:"Google orgânico",duckduckgo:"DuckDuckGo",bing_organic:"Bing orgânico",international_mx:"Internacional · México",international_co:"Internacional · Colômbia",international_cl:"Internacional · Chile",international_za:"Internacional · África do Sul"}[s]??s:"Não identificada"}const H=20;function X(s){return new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"short",year:"numeric"})}function ys(s){return X(`${s}T12:00:00`)}function de(s){return new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"short"})}function Cs(s){return(s||"?").trim().split(/\s+/).slice(0,2).map(a=>{var o;return((o=a[0])==null?void 0:o.toUpperCase())??""}).join("")||"?"}function la(){const s=Pe(),[r,a]=h.useState(1),[o,l]=h.useState(""),[c,d]=h.useState(""),[x,u]=h.useState("all"),[m,p]=h.useState("all"),[g,f]=h.useState("all"),[j,t]=h.useState("all"),[i,$]=h.useState("all"),[S,D]=h.useState("recent"),[ve,ee]=h.useState(null),se=h.useRef(null),{data:L,isLoading:G,error:Ne,refetch:ye,isFetching:U}=oe({page:r,limit:H,search:o||void 0,partner:x,status:m,billing:g,health:j,source:i,sort:S}),{data:v}=We(),{data:V}=oe({page:1,limit:1,partner:"partner"}),{data:Ce}=He(),W=(L==null?void 0:L.data)??[],Se=W.map(n=>n.id),{data:M}=Qe(Se,7),P=L==null?void 0:L.pagination,w=(P==null?void 0:P.total)??0,ae=(P==null?void 0:P.pages)??1,we=w===0?0:(r-1)*H+1,Ie=Math.min(r*H,w),te=()=>{l(c.trim()),a(1)},T=n=>I=>{n(I),a(1)},ke=x!=="all"||m!=="all"||g!=="all"||j!=="all"||i!=="all"||S!=="recent"||o!=="",Ae=()=>{u("all"),p("all"),f("all"),t("all"),$("all"),D("recent"),l(""),d(""),a(1)},Le=()=>{var n;f("expiring"),a(1),(n=se.current)==null||n.scrollIntoView({behavior:"smooth",block:"start"})},Me=[{label:"Total de Clientes",value:(v==null?void 0:v.users.total)??"—",icon:Q},{label:"Novos este mês",value:(v==null?void 0:v.users.newThisMonth)??"—",icon:E},{label:"Instâncias",value:(v==null?void 0:v.instances.total)??"—",icon:_},{label:"Parceiros",value:(V==null?void 0:V.pagination.total)??"—",icon:F}];return e.jsxs(Re,{children:[e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-semibold mb-2 text-foreground",children:"Gestão de Clientes"}),e.jsxs("p",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Clientes reais da plataforma"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(N,{variant:"outline",onClick:()=>s("/admin/lifecycle"),children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Lifecycle"]}),e.jsxs(N,{variant:"outline",onClick:()=>
11s("/admin/dashboard"),children:[e.jsx(E,{className:"w-4 h-4 mr-2"}),"Dashboard Admin"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:Me.map(n=>e.jsx(y,{className:"border",children:e.jsxs(C,{className:"p-5 flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary/10",children:e.jsx(n.icon,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-semibold",children:n.value}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n.label})]})]})},n.label))}),e.jsx(ks,{onExpiringClick:Le}),e.jsx(Ls,{}),e.jsx(Ms,{}),e.jsx(y,{className:"border",ref:se,children:e.jsxs(C,{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ns,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Te,{placeholder:"Buscar por nome, e-mail ou empresa...",className:"pl-10",value:c,onChange:n=>d(n.target.value),onKeyDown:n=>n.key==="Enter"&&te()})]}),e.jsx(N,{onClick:te,children:"Buscar"}),e.jsx(N,{variant:"outline",size:"icon",onClick:()=>ye(),disabled:U,children:e.jsx(rs,{className:`w-4 h-4 ${U?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-6 gap-3",children:[e.jsx(B,{label:"Saúde",value:j,onChange:T(t),options:[{value:"all",label:"Todas"},{value:"active",label:"Ativo (msg 7d)"},{value:"idle",label:"Sem uso (7d)"},{value:"never",label:"Sem instância"}]}),e.jsx(B,{label:"Cobrança",value:g,onChange:T(f),options:[{value:"all",label:"Todas"},{value:"trial",label:"Trial"},{value:"paid",label:"Pago"},{value:"expiring",label:"Trial vencendo (≤3d)"}]}),e.jsx(B,{label:"Origem",value:i,onChange:T($),options:[{value:"all",label:"Todas"},...(Ce??[]).map(n=>({value:n,label:K(n)}))]}),e.jsx(B,{label:"Tipo",value:x,onChange:T(u),options:[{value:"all",label:"Todos"},{value:"partner",label:"Parceiros"},{value:"regular",label:"Regulares"}]}),e.jsx(B,{label:"Status",value:m,onChange:T(p),options:[{value:"all",label:"Qualquer"},{value:"active",label:"Ativos"},{value:"suspended",label:"Suspensos"}]}),e.jsx(B,{label:"Ordenar por",value:S,onChange:T(D),options:[{value:"recent",label:"Mais recentes"},{value:"oldest",label:"Mais antigos"},{value:"lastLogin",label:"Último login"}]})]}),ke&&e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:G||U?"Filtrando…":`${w} cliente${w!==1?"s":""} com os filtros aplicados`}),e.jsxs(N,{variant:"ghost",size:"sm",onClick:Ae,children:[e.jsx(Be,{className:"w-4 h-4 mr-1"}),"Limpar filtros"]})]})]})}),Ne&&e.jsx(y,{className:"border-destructive/50",children:e.jsx(C,{className:"p-6 text-center text-destructive",children:"Erro ao carregar clientes. Tente novamente."})}),G?e.jsx("div",{className:"space-y-4",children:Array.from({length:5}).map((n,I)=>e.jsx(k,{className:"h-32 w-full rounded-xl"},I))}):W.length===0?e.jsx(y,{children:e.jsx(C,{className:"p-12 text-center text-muted-foreground",children:"Nenhum cliente encontrado."})}):e.jsx("div",{className:"space-y-4",children:W.map(n=>{var ne,re;const I=be(n,(ne=M==null?void 0:M[n.id])==null?void 0:ne.active),q=fs(n),O=js(n);return e.jsx(y,{className:"border hover:border-primary/40 transition-colors cursor-pointer",onClick:()=>ee(n),children:e.jsx(C,{className:"p-6",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4 flex-1 min-w-0",children:[e.jsx("div",{className:"hidden sm:flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary font-semibold",children:Cs(n.name||n.email)}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold truncate",children:n.name||n.email}),e.jsxs(b,{variant:"outline",className:I.cls,children:[e.jsx(I.icon,{className:"w-3 h-3 mr-1"}),I.label]}),q&&e.jsxs(b,{variant:"outline",className:q.cls,children:[e.jsx(q.icon,{className:"w-3 h-3 mr-1"}),q.label]}),O&&e.jsxs(b,{variant:"outline",className:O.cls,title:"Quantity da assinatura no Stripe difere das instâncias pagas — conferir cobrança",children:[e.jsx(O.icon,{className:"w-3 h-3 mr-1"}),O.label]}),n.isPartner&&e.jsxs(b,{variant:"outline",className:"border-primary/40 text-primary",children:[e.jsx(F,{className:"w-3 h-3 mr-1"}),"Parceiro"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(he,{className:"w-4 h-4"}),n.email]}),n.company&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(F,{className:"w-4 h-4"}),n.company]}),n.phone&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(je,{className:"w-4 h-4"}),n.phone]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(_,{className:"w-4 h-4"}),n.activeInstances,"/",n.instanceCount," conectadas"]}),e.jsxs("span",{children:["Cadastro: ",X(n.createdAt)]}),n.source&&e.jsxs("span",{title:n.rawSource?`Valor original: ${n.rawSource}`:void 0,children:["Origem: ",K(n.source)]}),n.landingPage&&n.landingPage!=="(sem landing page)"&&e.jsxs("span",{className:"max-w-sm truncate",title:n.landingPage,children:["Landing: ",n.landingPage]}),n.utmContent&&e.jsxs("span",{children:["CTA: ",n.utmContent]}
11),n.lastLoginAt&&e.jsxs("span",{children:["Login: ",X(n.lastLoginAt)]}),e.jsx(Ss,{lastMessageAt:(re=M==null?void 0:M[n.id])==null?void 0:re.lastMessageAt}),e.jsx(ws,{client:n})]})]})]}),e.jsx(Bs,{client:n})]})})},n.id)})}),!G&&w>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 pt-2",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Mostrando ",we,"–",Ie," de ",w," cliente",w!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(N,{variant:"outline",size:"sm",disabled:r<=1,onClick:()=>a(n=>n-1),children:[e.jsx(ge,{className:"w-4 h-4 mr-1"}),"Anterior"]}),e.jsxs("span",{className:"text-sm text-muted-foreground px-2",children:["Página ",r," de ",ae]}),e.jsxs(N,{variant:"outline",size:"sm",disabled:r>=ae,onClick:()=>a(n=>n+1),children:["Próxima",e.jsx(ue,{className:"w-4 h-4 ml-1"})]})]})]})]}),e.jsx(Ps,{client:ve,onClose:()=>ee(null)})]})}function B({label:s,value:r,onChange:a,options:o}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:s}),e.jsxs(Oe,{value:r,onValueChange:l=>a(l),children:[e.jsx(ze,{className:"h-9",children:e.jsx(Ge,{})}),e.jsx(Ue,{children:o.map(l=>e.jsx(Ve,{value:l.value,children:l.label},l.value))})]})]})}function Ss({lastMessageAt:s}){return s===void 0?null:s===null?e.jsx("span",{className:"text-muted-foreground",children:"Nunca usou"}):e.jsxs("span",{children:["Último uso: ",ys(s)]})}function ws({client:s}){if(!s.nextTrialExpiry||s.trialInstances===0)return null;const r=s.nextTrialExpiry,a=Date.now(),o=r<=a,l=!o&&r-a<=3*24*60*60*1e3;return e.jsx("span",{className:o?"text-destructive font-medium":l?"text-amber-600 font-medium":void 0,children:o?`Trial venceu ${de(r)}`:`Trial até ${de(r)}`})}function Is(){const{data:s,isLoading:r}=ts(),[a,o]=h.useState(!1),l=s??[];return r||l.length===0?null:e.jsxs("div",{className:"mt-4 rounded-lg border border-destructive/30 bg-destructive/5",children:[e.jsxs("button",{className:"w-full flex items-center justify-between gap-2 p-3 text-sm font-medium text-destructive",onClick:()=>o(c=>!c),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(A,{className:"w-4 h-4"}),l.length," trial(s) vencido(s) elegível(is) ao corte — revisar antes de ativar"]}),a?e.jsx(ge,{className:"w-4 h-4 rotate-90"}):e.jsx(ue,{className:"w-4 h-4 rotate-90"})]}),a&&e.jsx("div",{className:"border-t border-destructive/20 divide-y divide-border max-h-72 overflow-y-auto",children:l.map(c=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:c.name||c.email||"—"}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[c.email,c.email?" · ":"",e.jsx("span",{className:"font-mono",children:c.instance})]})]}),e.jsx(b,{variant:"outline",className:"bg-muted text-muted-foreground border-border shrink-0",children:c.billingStatus||"null"})]},c.instance))})]})}const me=s=>(s||0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"});function ks({onExpiringClick:s}){const{data:r,isLoading:a}=Ke(),{data:o}=Xe(),{data:l}=Ye(),c=(r==null?void 0:r.activeTrials)??0,d=(r==null?void 0:r.expiringSoon)??0,x=(r==null?void 0:r.stripePaying)??0,u=((o==null?void 0:o.mrr)??0)/100,m=(l==null?void 0:l.totalPaidInstances)??0,p=(l==null?void 0:l.totalProjectedAmount)??0;return e.jsx(y,{className:"border",children:e.jsxs(C,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(z,{className:"w-5 h-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Conversão Trial → Pago"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"(snapshot atual)"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:[e.jsx(z,{className:"w-3.5 h-3.5"})," Em trial agora"]}),a?e.jsx(k,{className:"h-7 w-12"}):e.jsx("p",{className:"text-2xl font-semibold text-blue-600",children:c.toLocaleStr
11ing("pt-BR")})]}),e.jsxs("button",{type:"button",onClick:s,className:"rounded-lg border p-4 text-left transition-colors hover:border-amber-500/50 hover:bg-amber-500/5",title:"Ver quem são na lista",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:[e.jsx(A,{className:"w-3.5 h-3.5"})," Vencendo (≤3d)"]}),a?e.jsx(k,{className:"h-7 w-12"}):e.jsx("p",{className:"text-2xl font-semibold text-amber-600",children:d.toLocaleString("pt-BR")}),e.jsx("p",{className:"text-xs text-amber-600/80 mt-1 underline underline-offset-2",children:"ver quem são →"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-lg border border-success/20 bg-success/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium mb-1",children:[e.jsx(pe,{className:"w-4 h-4 text-success"})," Via Stripe"]}),e.jsxs("p",{className:"text-2xl font-semibold text-success",children:[me(u),e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:" /mês"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[e.jsxs(le,{to:"/admin/instances?billing=stripe&billingStatus=active",className:"underline underline-offset-2 hover:text-success font-medium",children:[x.toLocaleString("pt-BR")," instância(s) ativa(s)"]})," · MRR real do Stripe"]})]}),e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-primary/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium mb-1",children:[e.jsx(F,{className:"w-4 h-4 text-primary"})," Via Parceiro"]}),e.jsxs("p",{className:"text-2xl font-semibold text-primary",children:[me(p),e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:" /mês"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[e.jsxs(le,{to:"/admin/instances?billing=partner",className:"underline underline-offset-2 hover:text-primary font-medium",children:[m.toLocaleString("pt-BR")," instância(s)"]})," · cobrança manual"]})]})]}),d>0&&e.jsxs("p",{className:"text-xs text-amber-600 mt-3 flex items-center gap-1.5",children:[e.jsx(A,{className:"w-3.5 h-3.5"}),d," trial(s) vencendo em até 3 dias — janela pra empurrar a conversão."]}),e.jsx(Is,{})]})})}const As=[{days:7,label:"7 dias"},{days:30,label:"30 dias"},{days:90,label:"90 dias"},{days:0,label:"Geral"}];function Ls(){const[s,r]=h.useState(30),{data:a,isLoading:o}=Ze(s),l=[{label:"Cadastraram",icon:Q,value:(a==null?void 0:a.signups)??0},{label:"Criaram instância",icon:_,value:(a==null?void 0:a.createdInstance)??0},{label:"Conectaram o WhatsApp",icon:_,value:(a==null?void 0:a.connectedInstance)??0},{label:"Enviaram/receberam a 1ª mensagem",icon:Z,value:(a==null?void 0:a.sentFirstMessage)??0},{label:"Viraram pagantes",icon:J,value:(a==null?void 0:a.paying)??0}],c=(a==null?void 0:a.signups)??0,d=(a==null?void 0:a.matureSignups)??0,x=(a==null?void 0:a.maturePaying)??0,u=d>0?Math.round(x/d*100):0,m=a==null?void 0:a.medianDaysToFirstMessage,p=(a==null?void 0:a.acquisition)??[],g=p.filter(t=>t.channel==="organic_search").reduce((t,i)=>({signups:t.signups+i.signups,createdInstance:t.createdInstance+i.createdInstance,sentFirstMessage:t.sentFirstMessage+i.sentFirstMessage,paying:t.paying+i.paying}),{signups:0,createdInstance:0,sentFirstMessage:0,paying:0}),f=p.filter(t=>vs.has(t.channel)).reduce((t,i)=>({signups:t.signups+i.signups,createdInstance:t.createdInstance+i.createdInstance,connectedInstance:t.connectedInstance+(i.connectedInstance??0),sentFirstMessage:t.sentFirstMessage+i.sentFirstMessage,paying:t.paying+i.paying}),{signups:0,createdInstance:0,connectedInstance:0,sentFirstMessage:0,paying:0}),j=[...p].sort((t,i)=>i.paying-t.paying||i.signups-t.signups).slice(0,10);return e.jsx(y,{className:"border",children:e.jsxs(C,{className:"p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(E,{className:"w-5 h-5 text-primary"}),"Funil de ativação"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s===0?"Todos os cadastros":`Cadastros dos últimos ${s} dias`," · onde os clientes travam até virar pagante"]})]}),e.jsx("div",{className:"flex gap-2",children:As.map(t=>e.jsx(N,{size:"sm",variant:s===t.days?"default":"outline",onClick:()=>r(t.days),children:t.label},t.days))})]}),o?e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((t,i)=>e.jsx(k,{className:"h-12 w-full rounded-lg"},i))}):e.jsxs("div",{className:"space-y-3",children:[l.map((t,i)=>{const $=c>0?Math.round(t.value/c*100):0,S=i>0?l[i-1].value:null,D=S&&S>0?Math.round(t.value/S*100):null;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-sm mb-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(t.icon,{className:"w-4 h-4 text-muted-foreground"}),t.label]}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:t.value.toLocaleStr
11ing("pt-BR")})," ","· ",$,"% do total",D!==null&&` · ${D}% da etapa anterior`]})]}),e.jsx("div",{className:"h-2.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${$}%`}})})]},t.label)}),e.jsxs("div",{className:"flex items-center justify-between text-sm pt-2 border-t mt-3",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{className:"w-4 h-4 text-emerald-600"}),"Ativaram canal WhatsApp (opt-in)"]}),e.jsxs("span",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:((a==null?void 0:a.whatsappOptIn)??0).toLocaleString("pt-BR")})," ","· ",c>0?Math.round(((a==null?void 0:a.whatsappOptIn)??0)/c*100):0,"% dos cadastros"]})]}),e.jsx("div",{className:"rounded-lg border border-emerald-500/25 bg-emerald-500/5 p-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Conversão da coorte madura"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Exclui cadastros dos últimos ",(a==null?void 0:a.maturityDays)??3," dias, que ainda estão dentro do trial."]})]}),e.jsxs(b,{variant:"outline",className:"border-emerald-500/30 bg-background text-emerald-700",children:[x,"/",d," pagantes · ",u,"%"]})]})}),e.jsxs("p",{className:"text-xs text-muted-foreground pt-1",children:[m!=null?`Mediana cadastro → 1ª mensagem: ${m.toLocaleString("pt-BR")} dia(s).`:"Sem dados de 1ª mensagem no recorte.",s===0&&" No recorte geral, a 1ª mensagem se limita ao histórico de message_stats — cadastros antigos podem distorcer a mediana."]}),j.length>0&&e.jsxs("div",{className:"pt-4 mt-4 border-t space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Aquisição → pagamento"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Canal, primeira landing page e CTA/conteúdo persistidos no cadastro."})]}),g.signups>0&&e.jsxs(b,{variant:"outline",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",children:["Busca orgânica: ",g.paying,"/",g.signups," pagantes · ",Math.round(g.paying/g.signups*100),"%"]}),f.signups>0&&e.jsxs(b,{variant:"outline",className:"border-violet-500/30 bg-violet-500/10 text-violet-700",children:["Assistentes de IA: ",f.paying,"/",f.signups," pagantes · ",Math.round(f.paying/f.signups*100),"%"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-lg border",children:e.jsxs("table",{className:"w-full min-w-[900px] text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Canal"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"Landing page"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium",children:"CTA / conteúdo"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Cadastros"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Instância"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Conectou"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"1ª msg"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Pagantes"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium",children:"Conv."})]})}),e.jsx("tbody",{children:j.map(t=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:K(t.channel)}),e.jsx("td",{className:"max-w-xs truncate px-3 py-2 font-mono text-xs",title:t.landingPage,children:t.landingPage}),e.jsx("td",{className:"max-w-xs truncate px-3 py-2 font-mono text-xs",title:t.contentCta,children:t.contentCta??"(sem CTA / conteúdo)"}),e.jsx("td",{className:"px-3 py-2 text-right",children:t.signups}),e.jsx("td",{className:"px-3 py-2 text-right",children:t.createdInstance}),e.jsx("td",{className:"px-3 py-2 text-right",children:t.connectedInstance??0}),e.jsx("td",{className:"px-3 py-2 text-right",children:t.sentFirstMessage}),e.jsx("td",{className:"px-3 py-2 text-right font-semibold",children:t.paying}),e.jsx("td",{className:"px-3 py-2 text-right",children:t.signups>0?`${Math.round(t.paying/t.signups*100)}%`:"—"})]},`${t.channel}:${t.landingPage}:${t.contentCta??""}`))})]})})]})]})]})})}function Ms(){const{data:s,isLoading:r}=Je(12),a=(s??[]).map(m=>({label:Ns(m.month),novos:m.count,total:m.cumulative})),o=(s??[]).reduce((m,p)=>m+p.count,0),l=(s==null?void 0:s.length)??0,c=l>1?s[l-2].count:null,d=l>2?s[l-3].count:null,x=c!==null&&d!==null&&d>0?Math.round((c-d)/d*100):null,u=(c??0)-(d??0);return e.jsx(y,{className:"border",children:e.jsxs(C,{className:"p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(ie,{className:"w-5 h-5 text-primary"}),"Cadastros por mês — últimos 12 meses"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[o," novos no período · barras = novos no mês · linha = total acumulado"]})]}),x!==null&&e.jsxs(b,{variant:"outline",className:u>=0?"bg-success/15 text-success border-success/30":"bg-destructive/15 text-destructive border-destructive/30",children:[e.jsx(ie,{className:`w-3 h-3 mr-1 ${u<0?"rotate-180":""}`}),u>=0?"+":"",x,"% último mês fechado"]})]}),r?e.jsx(k,{className:"h-[260px] w-full rounded-lg"}):a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-12 text-center",children:"Sem dados de cadastro."}):e.jsx("div",{className:"h-[260px] w-full",children:e.jsx(is,{width:"100%",height:"100%",children:e.jsxs(xs,{data:a,margin:{top:8,right:8,left:0,bottom:0},children:[e.jsx(us,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",vertical:!1}),e.jsx(os,{dataKey:"label",tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"}
11,tickLine:!1,axisLine:!1}),e.jsx(ce,{yAxisId:"l",allowDecimals:!1,tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,width:36}),e.jsx(ce,{yAxisId:"r",orientation:"right",allowDecimals:!1,tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"},tickLine:!1,axisLine:!1,width:40}),e.jsx(cs,{contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12},labelStyle:{color:"hsl(var(--foreground))"}}),e.jsx(ds,{yAxisId:"l",dataKey:"novos",name:"Novos no mês",fill:"hsl(var(--primary))",radius:[4,4,0,0],maxBarSize:40}),e.jsx(ms,{yAxisId:"r",type:"monotone",dataKey:"total",name:"Total acumulado",stroke:"#7c5cff",strokeWidth:2,dot:!1})]})})})]})})}function Ps({client:s,onClose:r}){const a=!!s,o=(s==null?void 0:s.id)??null,{data:l,isLoading:c}=es(o),{data:d,isLoading:x}=ss(o,30),u=(d==null?void 0:d.sent)??{},m=(d==null?void 0:d.received)??{},p=Object.values(u).reduce((t,i)=>t+i,0),g=Object.values(m).reduce((t,i)=>t+i,0),f=p+g,j=s?be(s):null;return e.jsx(De,{open:a,onOpenChange:t=>!t&&r(),children:e.jsxs(Fe,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsxs(_e,{className:"flex items-center gap-2",children:[(s==null?void 0:s.name)||(s==null?void 0:s.email)||"Cliente",j&&e.jsxs(b,{variant:"outline",className:j.cls,children:[e.jsx(j.icon,{className:"w-3 h-3 mr-1"}),j.label]})]}),e.jsxs(qe,{className:"flex flex-wrap gap-x-4 gap-y-1",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(he,{className:"w-3.5 h-3.5"}),s==null?void 0:s.email]}),(s==null?void 0:s.phone)&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(je,{className:"w-3.5 h-3.5"}),s.phone]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(R,{icon:Z,label:"Enviadas 30d",value:x?null:p}),e.jsx(R,{icon:fe,label:"Recebidas 30d",value:x?null:g}),e.jsx(R,{icon:_,label:"Conectadas",value:`${(s==null?void 0:s.activeInstances)??0}/${(s==null?void 0:s.instanceCount)??0}`})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(R,{icon:J,label:"Pagas",value:(s==null?void 0:s.paidInstances)??0}),e.jsx(R,{icon:z,label:"Cortesia / Trial",value:`${(s==null?void 0:s.compedInstances)??0} / ${(s==null?void 0:s.trialInstances)??0}`}),e.jsx(R,{icon:pe,label:"Stripe (quantity)",value:(s==null?void 0:s.subscriptionQuantity)??"—"})]}),(s==null?void 0:s.billingDrift)&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(A,{className:"w-4 h-4 shrink-0"}),"Cobrança divergente: o Stripe cobra ",s.subscriptionQuantity," instância(s), mas o cliente tem ",s.paidInstances," paga(s). Conferir assinatura."]}),!x&&f===0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm text-amber-700",children:[e.jsx(A,{className:"w-4 h-4 shrink-0"}),"Nenhuma mensagem nos últimos 30 dias — candidato a contato de suporte / churn."]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Instâncias ",l?`(${l.length})`:""]}),c?e.jsx("div",{className:"space-y-2",children:Array.from({length:2}).map((t,i)=>e.jsx(k,{className:"h-14 w-full rounded-lg"},i))}):!l||l.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Cliente sem instâncias."}):e.jsx("div",{className:"space-y-2",children:l.map(t=>e.jsx(Ts,{inst:t,sent:u[t.instance]??0,received:m[t.instance]??0},t.id))})]})]})})}function R({icon:s,label:r,value:a}){return e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground mb-1",children:[e.jsx(s,{className:"w-3.5 h-3.5"}),r]}),a===null?e.jsx(k,{className:"h-6 w-12"}):e.jsx("p",{className:"text-xl font-semibold",children:typeof a=="number"?a.toLocaleString("pt-BR"):a})]})}function Ts({inst:s,sent:r,received:a}){const o=s.connected===!0;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o?e.jsx(ps,{className:"w-4 h-4 text-success shrink-0"}):e.jsx(hs,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.name||s.instance}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.phoneConnected||s.instance})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground shrink-0",children:[e.jsxs("span",{className:"flex items-center gap-1",title:"Enviadas (30d)",children:[e.jsx(Z,{className:"w-3 h-3"}
11),r.toLocaleString("pt-BR")]}),e.jsxs("span",{className:"flex items-center gap-1",title:"Recebidas (30d)",children:[e.jsx(fe,{className:"w-3 h-3"}),a.toLocaleString("pt-BR")]})]})]})}function Bs({client:s}){const r=as();return e.jsxs("div",{className:"flex items-center gap-4 shrink-0",onClick:a=>a.stopPropagation(),children:[s.isPartner&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"R$ 59,90 até 10 · R$ 39,90 a partir de 11"}),e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(F,{className:"w-4 h-4 text-primary"}),"Parceiro"]}),e.jsx($e,{checked:s.isPartner,disabled:r.isPending,onCheckedChange:a=>r.mutate({id:s.id,isPartner:a})})]})}export{la 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.