1import{r,j as e}from"./react-vendor-BXTNdvBF.js";import{A as ae}from"./AdminLayout-38kh7xh4.js";import{h as te,f as I,L as f,es as re,et as oe,eu as ie,ev as ne,ew as le,I as O,B as S,K as de,cw as $}from"./index-DVCmV4wM.js";import{C as m,b as u,c as x,a as p}from"./card-BQMxlNPT.js";import{a as D}from"./adminApi-BZHVw8LJ.js";import{C as ce}from"./circle-alert-XBr8vyzs.js";import{R as me,T as ue,W as xe}from"./generateCategoricalChart-WI4ligyZ.js";import{L as he,C as pe,X as je,Y as ge,a as R}from"./LineChart-GA4w1XFf.js";import"./AccountBreadcrumb-QseNSWwX.js";import"./PageBreadcrumb-DRAGFQka.js";import"./supabase-vendor-Blds1cMP.js";import"./index-Dh4i1-J3.js";const g=12,E=[{value:"24h",label:"24h",dias:1},{value:"yesterday",label:"Ontem",dias:1},{value:"today",label:"Hoje",dias:1},{value:"7d",label:"Semana",dias:7},{value:"30d",label:"Mês",dias:30},{value:"custom",label:"Personalizado",dias:7}],_=a=>{const t=a.getFullYear(),n=String(a.getMonth()+1).padStart(2,"0"),o=String(a.getDate()).padStart(2,"0");return`${t}-${n}-${o}`},fe=[{value:"buscas_total",label:"Mais buscas"},{value:"anuncios_visitados",label:"Mais detalhes abertos"},{value:"cliques_link_original",label:"Mais cliques no original"},{value:"last_activity_at",label:"Atividade mais recente"},{value:"data_cadastro",label:"Cadastro mais recente"}],ve={property_detail_original:"Modal de detalhes",property_card_direct:"Card direto",property_card_original_button:"Botão original do card"};function d(a){return new Intl.NumberFormat("pt-BR").format(a||0)}function Ne(a){if(!a)return"-";const t=new Date(`${a}T00:00:00`);return Number.isNaN(t.getTime())?a:t.toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit"})}function k(a){if(!a)return"-";const t=new Date(a);return Number.isNaN(t.getTime())?a:t.toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}function be(a){const t=Math.max(0,Math.floor(a||0));if(t<60)return`${t}s`;if(t<3600)return`${Math.floor(t/60)}min`;const n=Math.floor(t/3600),o=Math.floor(t%3600/60);return o>0?`${n}h ${o}min`:`${n}h`}function _e(a){var n;const t=(n=a.nome_completo)==null?void 0:n.trim();return t||a.email}function ye(a){const t=String(a||"").trim();return t?ve[t]||t.replace(/_/g," "):null}function Ce(a){const t=String(a||"").trim().toLowerCase();return t?t.replace(/^www\./,""):null}function we({item:a}){const t=ye(a.ultimo_cta_context),n=Ce(a.ultimo_destination_domain);return!t&&!n?null:e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[t?e.jsx($,{variant:"outline",className:"whitespace-nowrap text-[11px] font-medium",children:t}):null,n?e.jsx($,{variant:"secondary",className:"whitespace-nowrap text-[11px] font-medium",children:n}):null]})}function Se(){var B;const[a,t]=r.useState("7d"),n=r.useMemo(()=>{const s=new Date,b=new Date;return b.setDate(s.getDate()-6),{start:_(b),end:_(s)}},[]),[o,F]=r.useState(n.start),[l,q]=r.useState(n.end),[j,h]=r.useState(0),[y,G]=r.useState("buscas_total"),[C,K]=r.useState("desc"),[i,z]=r.useState(null),[T,W]=r.useState([]),[U,X]=r.useState([]),[v,Y]=r.useState(0),[H,V]=r.useState(!0),[N,M]=r.useState(!1),J=a==="custom"&&o&&l&&o<=l?Math.max(1,Math.round((new Date(`${l}T00:00:00`).getTime()-new Date(`${o}T00:00:00`).getTime())/864e5)+1):null,Z=((B=E.find(s=>s.value===a))==null?void 0:B.dias)??7,c=J??Z,L=a!=="custom"||!!o&&!!l&&o<=l,A=r.useMemo(()=>T.map(s=>({data:Ne(s.data),"Novos cadastros":s.novos_cadastros,"Usuários ativos":s.usuarios_ativos,"Usuários com busca":s.usuarios_com_busca})),[T]),Q=r.useMemo(()=>Math.max(1,Math.ceil(v/g)),[v]),ee=r.useMemo(()=>Math.floor(j/g)+1,[j]),w=r.useCallback(async()=>{if(!(a==="custom"&&(!o||!l||o>l))){M(!0);try{const s=a==="custom"&&o&&l?{start:o,end:l}:void 0,[b,se,P]=await Promise.all([D.getLeadsIntencaoUsersSummary(c,s),D.getLeadsIntencaoUsersGrowth(c,s),D.getLeadsIntencaoUsersRanking({dias:c,limit:g,offset:j,sort_by:y,sort_direction:C,range:s})]);z(b),W(se.items||[]),X(P.items||[]),Y(P.total||0)}catch(s){te.error("Falha ao carregar base registrada"),console.error(s)}finally{M(!1),V(!1)}}},[l,o,c,a,j,y,C]);return r.useEffect(()=>{w()},[w]),H?e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(I,{className:"w-5 h-5 mr-2 animate-spin"}),"Carregando base registrada..."]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(m,{children:e.jsxs(u,{children:[e.jsx(x,{children:"Filtros"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Janela usada nos KPIs, no gráfico de crescimento e no ranking."}),e.jsxs("div",{className:"flex flex-wrap items-end gap-4 mt-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(f,{className:"text-xs text-muted-foreground",children:"PerÃodo"}),e.jsxs(re,{value:a,onValueChange:s=>{t(s),h(0)},children:[e.jsx(oe,{className:"w-[180px]",children:e.jsx(ie,{placeholder:"PerÃodo"})}),e.jsx(ne,{children:E.map(s=>e.jsx(le,{value:s.value,children:s.label},s.value))})]})]}),a==="custom"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(f,{htmlFor:"registered-start",className:"text-xs text-muted-foreground",children:"De"}),e.jsx(O,{id:"registered-start",type:"date",value:o,max:l||_(new Date),onChange:s=>{F(s.target.value),h(0)},className:"w-[170px]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(f,{htmlFor:"registered-end",className:"text-xs text-muted-foreground",children:"Até"}),e.jsx(O,{id:"registered-end",type:"date",value:l,min:o||void 0,max:_(new Date),onChange:s=>{q(s.target.value),h(0)},className:"w-[170px]"})]})]}),e.jsxs(S,{variant:"outline",onClick:()=>{w()},disabled:N||!L,children:[N?e.jsx(I,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(de,{className:"w-4 h-4 mr-1"}),"Atualizar"]}),a==="custom"&&!L&&e.jsxs("div",{className:"flex items-center text-amber-600 text-sm",children:[e.jsx(ce,{className:"h-4 w-4 mr-1"}),"Datas inválidas"]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-5 ga
1p-4",children:[e.jsxs(m,{children:[e.jsx(u,{className:"pb-2",children:e.jsx(x,{className:"text-sm",children:"Base Registrada"})}),e.jsx(p,{children:e.jsx("p",{className:"text-2xl font-semibold",children:d((i==null?void 0:i.total_usuarios_ativos)??0)})})]}),e.jsxs(m,{children:[e.jsx(u,{className:"pb-2",children:e.jsxs(x,{className:"text-sm",children:["Novos Cadastros (",c,"d)"]})}),e.jsx(p,{children:e.jsx("p",{className:"text-2xl font-semibold",children:d((i==null?void 0:i.novos_usuarios_periodo)??0)})})]}),e.jsxs(m,{children:[e.jsx(u,{className:"pb-2",children:e.jsxs(x,{className:"text-sm",children:["Usuários Ativos (",c,"d)"]})}),e.jsx(p,{children:e.jsx("p",{className:"text-2xl font-semibold",children:d((i==null?void 0:i.usuarios_ativos_periodo)??0)})})]}),e.jsxs(m,{children:[e.jsx(u,{className:"pb-2",children:e.jsxs(x,{className:"text-sm",children:["Fizeram Busca (",c,"d)"]})}),e.jsx(p,{children:e.jsx("p",{className:"text-2xl font-semibold",children:d((i==null?void 0:i.usuarios_com_busca_periodo)??0)})})]}),e.jsxs(m,{children:[e.jsx(u,{className:"pb-2",children:e.jsxs(x,{className:"text-sm",children:["Clicaram no Original (",c,"d)"]})}),e.jsx(p,{children:e.jsx("p",{className:"text-2xl font-semibold",children:d((i==null?void 0:i.usuarios_com_clique_original_periodo)??0)})})]})]}),e.jsxs(m,{children:[e.jsx(u,{children:e.jsx(x,{children:"Crescimento da Base Registrada"})}),e.jsx(p,{children:A.length>0?e.jsx("div",{className:"h-[320px]",children:e.jsx(me,{width:"100%",height:"100%",children:e.jsxs(he,{data:A,margin:{top:16,right:16,left:0,bottom:0},children:[e.jsx(pe,{strokeDasharray:"3 3"}),e.jsx(je,{dataKey:"data"}),e.jsx(ge,{allowDecimals:!1}),e.jsx(ue,{}),e.jsx(xe,{}),e.jsx(R,{type:"monotone",dataKey:"Novos cadastros",stroke:"#f97316",strokeWidth:2,dot:{r:3},activeDot:{r:5}}),e.jsx(R,{type:"monotone",dataKey:"Usuários ativos",stroke:"#0f766e",strokeWidth:2,dot:{r:3},activeDot:{r:5}}),e.jsx(R,{type:"monotone",dataKey:"Usuários com busca",stroke:"#2563eb",strokeWidth:2,dot:{r:3},activeDot:{r:5}})]})})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sem dados suficientes para o perÃodo selecionado."})})]}),e.jsxs(m,{children:[e.jsxs(u,{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx(x,{children:"Top Usuários Registrados"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Ranking de busca e interação da base autenticada no perÃodo selecionado."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"users-sort-by",children:"Ordenar por"}),e.jsx("select",{id:"users-sort-by",className:"mt-1 w-full h-10 rounded-md border border-input bg-background px-3",value:y,onChange:s=>{G(s.target.value),h(0)},children:fe.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"users-sort-direction",children:"Direção"}),e.jsxs("select",{id:"users-sort-direction",className:"mt-1 w-full h-10 rounded-md border border-input bg-background px-3",value:C,onChange:s=>{K(s.target.value),h(0)},children:[e.jsx("option",{value:"desc",children:"Descendente"}),e.jsx("option",{value:"asc",children:"Ascendente"})]})]})]})]}),e.jsxs(p,{children:[e.jsxs("div",{className:"mb-4 rounded-md border border-border/70 bg-muted/30 p-3 text-xs text-muted-foreground",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Detalhes abertos"})," contam visualizações registradas do detalhe/modal. O mesmo anúncio pode aparecer mais de uma vez e esse total não representa anúncios únicos."]}),e.jsxs("p",{className:"mt-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Cliques em card"})," contam entradas no detalhe iniciadas pela listagem de resultados."," ",e.jsx("span",{className:"font-medium text-foreground",children:"Cliques no original"})," contam saÃdas para a plataforma de origem."]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"py-2 pr-3",children:"Usuário"}),e.jsx("th",{className:"py-2 pr-3",children:"Cadastro / Ãltimo acesso"}),e.jsx("th",{className:"py-2 pr-3",children:"Buscas"}),e.jsx("th",{className:"py-2 pr-3",children:"Interações"}),e.jsx("th",{className:"py-2 pr-3",children:"Ãltima atividade"})]})}),e.jsxs("tbody",{children:[U.map(s=>e.jsxs("tr",{className:"border-b border-border/60 align-top",children:[e.jsxs("td",{className:"py-3 pr-3",children:[e.jsx("div",{className:"font-medium",children:_e(s)}),e.jsx("div",{className:"text-muted-foreground break-all",children:s.email}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID ",s.usuario_id]})]}),e.jsxs("td",{className:"py-3 pr-3",children:[e.jsxs("div",{children:["Cadastro: ",k(s.data_cadastro)]}),e.jsxs("div",{className:"text-muted-foreground",children:["Ãltimo acesso: ",k(s.data_ultimo_acesso)]})]}),e.jsxs("td",{className:"py-3 pr-3",children:[e.jsxs("div",{children:["Total: ",d(s.buscas_total)]}),e.jsxs("div",{className:"text-muted-foreground",children:["Filtros distintos: ",d(s.filtros_distintos)]})]}),e.jsxs("td",{className:"py-3 pr-3",children:[e.jsxs("div",{children:["Detalhes abertos: ",d(s.anuncios_visitados)]}
1),e.jsxs("div",{children:["Cliques em card: ",d(s.cliques_card)]}),e.jsxs("div",{children:["SaÃdas para o original: ",d(s.cliques_link_original)]}),e.jsx(we,{item:s}),e.jsxs("div",{className:"text-muted-foreground",children:["Tempo em detalhe: ",be(s.tempo_total_segundos)]})]}),e.jsx("td",{className:"py-3 pr-3",children:k(s.last_activity_at)})]},`${s.usuario_id}-${s.email}`)),U.length===0&&e.jsx("tr",{children:e.jsx("td",{className:"py-6 text-muted-foreground",colSpan:5,children:"Nenhum usuário encontrado para o perÃodo selecionado."})})]})]})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Página ",ee," de ",Q," (",d(v)," usuários)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:"outline",disabled:j<=0||N,onClick:()=>h(s=>Math.max(0,s-g)),children:"Anterior"}),e.jsx(S,{variant:"outline",disabled:j+g>=v||N,onClick:()=>h(s=>s+g),children:"Próxima"})]})]})]})]})]})}function $e(){return e.jsx(ae,{title:"Base Registrada",description:"Crescimento, ativação e comportamento da base de usuários identificados.",children:e.jsx(Se,{})})}export{$e 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.