1import{u as k,j as e}from"./vendor-query-skQMsM6X.js";import{b as D,at as n,au as l,ak as o,ax as c,av as d,aw as h,ab as N,aJ as T,p as R}from"./index-BGwtrXIa.js";import{F as p,B as v,s as A,bt as E,U as u,aq as C,M as L,ci as U,db as P,H as z,S as B,dc as F,v as I,o as O,aR as K}from"./vendor-ui-CCmu0bzQ.js";import{R as f,X as w,Y as S,T as j,z as q,y as G,B as M}from"./generateCategoricalChart-BxE9pWj9.js";import{A as H,a as g}from"./AreaChart-Dc-mtYEU.js";import{C as _}from"./CartesianGrid-OCksdiBu.js";import{P as W,a as X}from"./PieChart-FGAAL4ST.js";import{B as $}from"./BarChart-BW7VrK2B.js";import{L as Q}from"./vendor-react-DyYvSSk1.js";import"./vendor-supabase-BfoV2C50.js";const V=async()=>{const{data:s,error:a}=await D.rpc("get_admin_dashboard_stats");if(a)throw a;return s};function Y(){return k({queryKey:["admin-dashboard-stats"],queryFn:V,staleTime:6e4,refetchOnWindowFocus:!1})}const J=[{key:"prompts",title:"Prompts",icon:p,desc:"Edge Functions com prompts",color:"text-blue-500"},{key:"models",title:"Modelos Ativos",icon:v,desc:"Modelos de IA disponÃveis",color:"text-blue-700"},{key:"templates",title:"Templates",icon:A,desc:"Templates de laudo ativos",color:"text-emerald-500"},{key:"frases",title:"Frases Modelo",icon:E,desc:"Frases disponÃveis",color:"text-amber-500"},{key:"users",title:"Usuários",icon:u,desc:"Usuários registrados",color:"text-teal-500"},{key:"ai_calls_today",title:"Chamadas IA Hoje",icon:C,desc:"Requisições à s Edge Functions",color:"text-slate-500"},{key:"transcriptions_today",title:"Transcrições Hoje",icon:L,desc:"Transcrições de áudio (IA)",color:"text-blue-500"},{key:"active_users_30d",title:"Ativos 30d",icon:U,desc:"Usuários ativos (30 dias)",color:"text-teal-500"}];function Z({counters:s,loading:a}){return a?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:8}).map((t,r)=>e.jsxs(n,{children:[e.jsx(l,{className:"pb-2",children:e.jsx(o,{className:"h-4 w-24"})}),e.jsxs(c,{children:[e.jsx(o,{className:"h-8 w-16"}),e.jsx(o,{className:"h-3 w-32 mt-2"})]})]},r))}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:J.map(({key:t,title:r,icon:i,desc:m,color:x})=>e.jsxs(n,{className:"hover:border-primary/50 transition-colors",children:[e.jsxs(l,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium font-mono",children:r}),e.jsx(i,{className:`h-4 w-4 ${x}`})]}),e.jsxs(c,{children:[e.jsx("div",{className:"text-3xl font-bold font-mono",children:(s==null?void 0:s[t])??0}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:m})]})]},t))})}const b=s=>new Date(s+"T00:00:00").toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit"});function ee({data:s,loading:a}){return e.jsxs(n,{children:[e.jsxs(l,{className:"pb-2",children:[e.jsxs(d,{className:"text-base font-mono flex items-center gap-2",children:[e.jsx(C,{className:"h-4 w-4 text-primary"}),"Atividade Diária (14 dias)"]}),e.jsx(h,{children:"Transações de IA e usuários únicos"})]}),e.jsx(c,{children:a?e.jsx(o,{className:"h-[220px] w-full"}):s!=null&&s.length?e.jsx(f,{width:"100%",height:220,children:e.jsxs(H,{data:s,margin:{top:5,right:10,left:0,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"gradTx",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--primary))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--primary))",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"gradUsers",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--accent-foreground))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--accent-foreground))",stopOpacity:0})]})]}),e.jsx(_,{strokeDasharray:"3 3",className:"stroke-border/30"}),e.jsx(w,{dataKey:"day",tickFormatter:b,className:"text-xs",tick:{fontSize:11}}),e.jsx(S,{className:"text-xs",tick:{fontSize:11},width:35}),e.jsx(j,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12},labelFormatter:b}),e.jsx(g,{type:"monotone",dataKey:"transactions",name:"Transações",stroke:"hsl(var(--primary))",fill:"url(#gradTx)",strokeWidth:2}),e.jsx(g,{type:"monotone",dataKey:"unique_users",name:"Usuários",stroke:"hsl(var(--accent-foreground))",fill:"url(#gradUsers)",strokeWidth:2})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"Sem dados de atividade"})})]})}const se={free:"#94a3b8",basic:"#3b82f6",basico:"#3b82f6",professional:"#8b5cf6",profissional:"#8b5cf6",premium:"#f59e0b",trial:"#d4a017"},ae={free:"Gratuito",basic:"Essencial",basico:"Essencial",professional:"Especialista",profissional:"Especialista",premium:"ClÃnica Pro",trial:"Trial"},y=["premium","professional","profissional","trial","basic","basico","free"];function te({data:s,loading:a}){const t=(s??[]).slice().sort((r,i)=>{const m=y.indexOf(r.plan_type),x=y.indexOf(i.plan_type);return(m===-1?99:m)-(x===-1?99:x)}).map(r=>({...r,name:ae[r.plan_type]||r.plan_type,fill:se[r.plan_type]||"#64748b"}));return e.jsxs(n,{children:[e.jsxs(l,{className:"pb-2",children:[e.jsxs(d,{className:"text-base font-mono flex items-center gap-2",children:[e.jsx(u,{className:"h-4 w-4 text-primary"}),"Distribuição de Planos"]}),e.jsx(h,{children:"Usuários por tipo de assinatura"})]}),e.jsx(c,{children:a?e.jsx(o,{className:"h-[220px] w-full"}):t.length?e.jsx(f,{width:"100%",height:220,children:e.jsxs(W,{children:[e.jsx(X,{data:t,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:3,dataKey:"user_count",nameKey:"name",children:t.map((r,i)=>e.jsx(q,{fill:r.fill},i))}),e.jsx(j,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(G,{wrapperStyle:{fontSize:12}})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"Sem dados"})})]})}const re={"agent-research":"Pesquisa IA","ai-generate-conclusion":"Conclusão","ai-suggestion-review":"Revisão","ai-dictation-polish":"Corretor AI","ai-rads-classification":"RADS","ai-inline-edit":"Editar Seleção","ai-voice-inline-edit":"Edição Voz","radreport-chat":"Chat IA","soniox-realt
1ime":"Ditado Premium (voz)","ai-natural-report":"Escriba AI","radreport-agent":"Tomo (assistente)",whisper_transcription:"Transcrição (legado)","deepgram-realtime":"Ditado (legado)"};function ie({data:s,loading:a}){const t=(s==null?void 0:s.map(r=>({...r,label:re[r.feature]||r.feature})))??[];return e.jsxs(n,{children:[e.jsxs(l,{className:"pb-2",children:[e.jsxs(d,{className:"text-base font-mono flex items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 text-primary"}),"Uso por Feature IA (30 dias)"]}),e.jsx(h,{children:"Chamadas e créditos consumidos por função"})]}),e.jsx(c,{children:a?e.jsx(o,{className:"h-[220px] w-full"}):t.length?e.jsx(f,{width:"100%",height:220,children:e.jsxs($,{data:t,layout:"vertical",margin:{top:5,right:10,left:80,bottom:0},children:[e.jsx(_,{strokeDasharray:"3 3",className:"stroke-border/30",horizontal:!1}),e.jsx(w,{type:"number",tick:{fontSize:11}}),e.jsx(S,{type:"category",dataKey:"label",tick:{fontSize:11},width:75}),e.jsx(j,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(M,{dataKey:"calls",name:"Chamadas",fill:"hsl(var(--primary))",radius:[0,4,4,0]})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8 text-sm",children:"Sem dados de uso"})})]})}const oe=s=>new Date(s).toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"});function ne({data:s,loading:a}){return e.jsxs(n,{children:[e.jsxs(l,{className:"pb-2",children:[e.jsxs(d,{className:"text-base font-mono flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 text-primary"}),"Atividade Recente"]}),e.jsx(h,{children:"Ãltimas alterações em prompts"})]}),e.jsx(c,{children:a?e.jsx("div",{className:"space-y-3",children:Array.from({length:5}).map((t,r)=>e.jsx(o,{className:"h-12 w-full"},r))}):e.jsxs("div",{className:"space-y-3",children:[s==null?void 0:s.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/30 border border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(p,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-mono text-sm",children:t.function_name}),e.jsxs(N,{variant:"secondary",className:"ml-2 text-xs",children:["v",t.version]})]})]}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:oe(t.updated_at)})]},t.id)),(!s||s.length===0)&&e.jsx("p",{className:"text-muted-foreground text-center py-4 text-sm",children:"Nenhuma atividade recente"})]})})]})}const le=[{to:"/admin/ai-config",icon:p,title:"Prompts IA",desc:"Editar prompts de sistema"},{to:"/admin/templates",icon:A,title:"Templates",desc:"Gerenciar templates de laudo"},{to:"/admin/users",icon:u,title:"Usuários",desc:"Gerenciar usuários do sistema"}];function ce(){return e.jsxs(n,{children:[e.jsxs(l,{children:[e.jsx(d,{className:"text-lg font-mono",children:"Acesso Rápido"}),e.jsx(h,{children:"Navegue para as principais funcionalidades"})]}),e.jsx(c,{children:e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:le.map(({to:s,icon:a,title:t,desc:r})=>e.jsxs(Q,{to:s,className:"flex items-center gap-3 p-4 rounded-lg bg-muted/30 border border-border/50 hover:border-primary/50 hover:bg-muted/50 transition-all",children:[e.jsx(a,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium font-mono text-sm",children:t}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r})]})]},s))})})]})}const de=[{key:"paying",title:"Pagantes ativos",icon:z,desc:"Assinaturas em cobrança",color:"text-emerald-500"},{key:"trialing",title:"Em Trial",icon:B,desc:"Testando 14 dias grátis",color:"text-amber-500"},{key:"trial_expired_no_conversion",title:"Trial expirado",icon:F,desc:"Sem conversão para pago",color:"text-orange-500"},{key:"canceled_last_30d",title:"Cancelados 30d",icon:I,desc:"Ãltimos 30 dias",color:"text-rose-500"}];function me({data:s,loading:a}){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:de.map(({key:t,title:r,icon:i,desc:m,color:x})=>e.jsxs(n,{className:"hover:border-primary/50 transition-colors",children:[e.jsxs(l,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium font-mono",children:r}),e.jsx(i,{className:`h-4 w-4 ${x}`})]}),e.jsxs(c,{children:[a?e.jsx(o,{className:"h-8 w-16"}):e.jsx("div",{className:"text-3xl font-bold font-mono",children:(s==null?void 0:s[t])??0}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:m})]})]},t))})}function ve(){const{data:s,isLoading:a,dataUpdatedAt:t,refetch:r}=Y(),i=t?new Date(t).toLocaleTimeString("pt-BR"):"...";return e.jsx(T,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground font-mono",children:"Dashboard"}),e.jsx("p",{className:"text-muted-foreground mt-1 font-mono text-sm",children:"Visão geral do sistema RadReport"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(N,{variant:"outline",className:"font-mono text-xs",children:[e.jsx(O,{className:"h-3 w-3 mr-1"}),i]}),e.jsx(R,{variant:"ghost",size:"icon",onClick:()=>r(),disabled:a,children:e.jsx(K,{className:`h-4 w-4 ${a?"animate-spin":""}`})})]})]}),e.jsx(Z,{counters:s==null?void 0:s.counters,loading:a}),e.jsx(me,{data:s==null?void 0:s.subscription_health,loading:a}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(ee,{data:s==null?void 0:s.daily_activity,loading:a}),e.jsx(te,{data:s==null?void 0:s.plan_distribution,loading:a})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(ie,{data:s==null?void 0:s.ai_feature_usage,loading:a}),e.jsx(ne,{data:s==null?void 0:s.recent_prompts,loading:a})]}),e.jsx(ce,{})]})})}export{ve 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.