1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/admin-charts-D05e3rUa.js","assets/index-CuSEeJFb.js","assets/index-DK0yIo6F.css","assets/generateCategoricalChart-lXkql-gd.js","assets/throttle-Bgu_Mp4s.js","assets/debounce-BH2V1_7f.js","assets/tiny-invariant-BaFNuDhB.js","assets/string-CFFdVFMV.js","assets/LineChart-QmF0f0aq.js","assets/YAxis-edJjQlh1.js","assets/BarChart-CPEOGCBJ.js","assets/AreaChart-BE8A1YFk.js","assets/PieChart-BXVWJE0w.js"])))=>i.map(i=>d[i]); 2import{r as f,a as x,j as s,B as d,R as V,aE as Z,bm as Q,L as c,C as a,e as t,b as r,d as i,U as H,V as J,br as W,q as T,Z as X,b9 as Y,f as A,bZ as S,o,s as E,E as k,da as ss,bJ as es,c6 as as,c_ as I,a7 as h}from"./index-CuSEeJFb.js";import{T as ts,a as rs,b as y,c as b}from"./tabs-CcPOXtvT.js";import{P as w}from"./progress-B2eMqtVV.js";import{u as is}from"./useTimezone-Cdtx2_VV.js";import{B as ls}from"./bot-ecRnbbNU.js";import{T as ns}from"./trending-down-C0n_6ywh.js";const P=f.lazy(()=>as(()=>import("./admin-charts-D05e3rUa.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function ps(){const[C,D]=f.useState("7d"),[j,_]=f.useState(""),{formatDate:ds,formatTime:cs,formatDateTime:B,userTimezone:ms}=is(),{data:F,isLoading:G,refetch:K}=x({queryKey:["/api/admin/stats"],queryFn:async()=>(await h("GET","/api/admin/stats")).json()}),{data:L}=x({queryKey:["/api/admin/usage-data",C],queryFn:async()=>(await h("GET",`/api/admin/usage-data?days=${C.replace("d","")}`)).json()}),{data:U}=x({queryKey:["/api/admin/alerts"],queryFn:async()=>(await h("GET","/api/admin/alerts")).json()}),{data:u=[]}=x({queryKey:["/api/admin/users"],queryFn:async()=>(await h("GET","/api/admin/users")).json()}),{data:O=[]}=x({queryKey:["/api/admin/users-by-org"],queryFn:async()=>(await h("GET","/api/admin/users-by-org")).json()}),{data:l,isLoading:$}=x({queryKey:["/api/admin/realtime-stats"],queryFn:async()=>(await h("GET","/api/admin/realtime-stats")).json(),refetchInterval:3e4}),M=e=>{switch(e){case"critical":return s.jsx(I,{className:"h-4 w-4 text-red-500"});case"warning":return s.jsx(I,{className:"h-4 w-4 text-yellow-500"});default:return s.jsx(S,{className:"h-4 w-4 text-blue-500"})}},z=e=>`$${(e==null?void 0:e.toLocaleString("en-US",{minimumFractionDigits:2}))||"0.00"}`,g=e=>(e==null?void 0:e.toLocaleString("en-US"))||"0",m=F||{totalUsers:0,activeUsers:0,totalOrganizations:0,totalAIRequests:0,totalCost:0,avgResponseTime:0,errorRate:0,uptime:99.9},R=Array.isArray(L)?L:[],N=Array.isArray(U)?U:[],q=u.filter(e=>{var n,p,v;return((n=e.email)==null?void 0:n.toLowerCase().includes(j.toLowerCase()))||((p=e.firstName)==null?void 0:p.toLowerCase().includes(j.toLowerCase()))||((v=e.lastName)==null?void 0:v.toLowerCase().includes(j.toLowerCase()))}).slice(0,5);return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsxs(d,{variant:"outline",size:"sm",onClick:()=>K(),"data-testid":"button-refresh-stats",children:[s.jsx(V,{className:"h-4 w-4 mr-2"}),"Refresh"]}),s.jsxs("select",{value:C,onChange:e=>D(e.target.value),className:"px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-orange-500","data-testid":"select-time-range",children:[s.jsx("option",{value:"1d",children:"Last 24 hours"}),s.jsx("option",{value:"7d",children:"Last 7 days"}),s.jsx("option",{value:"30d",children:"Last 30 days"}),s.jsx("option",{value:"90d",children:"Last 90 days"})]})]}),s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(Z,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),s.jsx(Q,{placeholder:"Quick user search...",value:j,onChange:e=>_(e.target.value),className:"pl-10","data-testid":"input-user-search"}),j&&q.length>0&&s.jsx("div",{className:"absolute top-full mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg z-10",children:q.map(e=>s.jsxs(c,{href:`/admin/users?user=${e.id}`,className:"block px-4 py-2 text-sm hover:bg-gray-50 dark:hover:bg-gray-700 border-b border-gray-100 dark:border-gray-600 last:border-b-0","data-testid":`search-result-${e.id}`,children:[s.jsxs("div",{className:"font-medium",children:[e.firstName," ",e.lastName]}),s.jsx("div",{className:"text-gray-500 text-xs",children:e.email})]},e.id))})]})]}),G?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8",children:[...Array(4)].map((e,n)=>s.jsx(a,{children:s.jsx(t,{className:"p-6",children:s.jsxs("div",{className:"animate-pulse",children:[s.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 mb-2"}),s.jsx("div",{className:"h-8 bg-gray-200 rounded w-16 mb-2"}),s.jsx("div",{className:"h-3 bg-gray-200 rounded w-20"})]})})},n))}):s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8",children:[s.jsxs(a,{children:[s.jsxs(r,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(i,{className:"text-sm font-medium",children:"Total Users"}),s.jsx(H,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"text-2xl font-bold","data-testid":"metric-total-users",children:g(m.totalUsers)}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.jsx(J,{className:"inline w-3 h-3 mr-1 text-green-500"}),g(m.activeUsers)," active this month"]})]})]}),s.jsxs(a,{children:[s.jsxs(r,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(i,{className:"text-sm font-medium",children:"Organizations"}),s.jsx(W,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"text-2xl font-bold","data-testid":"metric-organizations",children:g(m.totalOrganizations)}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.jsx(T,{className:"inline w-3 h-3 mr-1 text-blue-500"}),"Active companies"]})]})]}),s.jsxs(a,{children:[s.jsxs(r,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(i,{className:"text-sm font-medium",children:"AI Requests"}),s.jsx(ls,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"text-2xl font-bold","data-testid":"metric-ai-requests",children:g(m.totalAIRequests)}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.jsx(X,{className:"inline w-3 h-3 mr-1 text-purple-500"}),"Total AI interactions"]})]})]}),s.jsxs(a,{children:[s.jsxs(r,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[s.jsx(i,{className:"text-sm font-medium",children:"Total Cost"}),s.jsx(Y,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"text-2xl font-bold","data-testid":"metric-total-cost",children:z(m.totalCost)}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.jsx(ns,{className:"inline w-3 h-3 mr-1 text-orange-500"}),"Platform operational costs"]})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8",children:[s.jsxs(a,{className:"lg:col-span-2",children:[s.jsx(r,{children:s.jsxs(i,{className:"flex items-center gap-2",children:[s.jsx(T,{className:"h-5 w-5 text-green-500"}
2),"System Status"]})}),s.jsx(t,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"System Uptime"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(A,{className:"h-4 w-4 text-green-500"}),s.jsxs("span",{className:"text-sm font-bold","data-testid":"uptime-percentage",children:[m.uptime,"%"]})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Average Response Time"}),s.jsxs("span",{className:"text-sm font-bold","data-testid":"response-time",children:[m.avgResponseTime,"ms"]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Error Rate"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),s.jsxs("span",{className:"text-sm font-bold","data-testid":"error-rate",children:[m.errorRate,"%"]})]})]})]})})]}),s.jsxs(a,{children:[s.jsx(r,{children:s.jsxs(i,{className:"flex items-center gap-2",children:[s.jsx(S,{className:"h-5 w-5 text-orange-500"}),"Active Alerts"]})}),s.jsxs(t,{children:[s.jsx("div",{className:"space-y-3",children:N.length===0?s.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:[s.jsx(A,{className:"h-8 w-8 mx-auto mb-2 text-green-500"}),"No active alerts"]}):N.slice(0,3).map(e=>s.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-gray-50 dark:bg-gray-800",children:[M(e.type),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-medium truncate",children:e.message}),s.jsx("p",{className:"text-xs text-muted-foreground",children:B(e.timestamp)})]})]},e.id))}),N.length>3&&s.jsx(d,{variant:"outline",size:"sm",className:"w-full mt-3",asChild:!0,children:s.jsxs(c,{href:"/admin/alerts","data-testid":"button-view-all-alerts",children:["View All Alerts (",N.length,")"]})})]})]})]}),s.jsxs(ts,{defaultValue:"overview",className:"space-y-6",children:[s.jsxs(rs,{className:"grid w-full grid-cols-4",children:[s.jsx(y,{value:"overview","data-testid":"tab-overview",children:"Overview"}),s.jsx(y,{value:"users","data-testid":"tab-users",children:"Users"}),s.jsx(y,{value:"ai-usage","data-testid":"tab-ai-usage",children:"AI Usage"}),s.jsx(y,{value:"performance","data-testid":"tab-performance",children:"Performance"})]}),s.jsx(b,{value:"overview",className:"space-y-6",children:s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"Usage Trends"}),s.jsx(o,{children:"Platform usage over time"})]}),s.jsx(t,{children:s.jsx("div",{className:"h-64",children:s.jsx(f.Suspense,{fallback:s.jsx("div",{className:"flex items-center justify-center h-full",children:"Loading charts..."}),children:s.jsx(P,{data:R,type:"line",dataKey:"requests"})})})})]}),s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"Organization Growth"}),s.jsx(o,{children:"New organizations by week"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"space-y-3",children:O.slice(0,5).map((e,n)=>s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-2 h-2 bg-orange-500 rounded-full"}),s.jsx("span",{className:"text-sm font-medium truncate max-w-48",children:e.name})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(E,{variant:"outline",className:"text-xs",children:[e.userCount||0," users"]}),s.jsx(d,{variant:"ghost",size:"sm",asChild:!0,children:s.jsx(c,{href:`/admin/organizations?org=${e.id}`,children:s.jsx(k,{className:"h-3 w-3"})})})]})]},e.id))}),s.jsx(d,{variant:"outline",className:"w-full mt-4",asChild:!0,children:s.jsx(c,{href:"/admin/organizations","data-testid":"button-view-all-orgs",children:"View All Organizations"})})]})]})]})}),s.jsx(b,{value:"users",className:"space-y-6",children:s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"Recent User Activity"}),s.jsx(o,{children:"Latest user registrations and activities"})]}),s.jsxs(t,{children:[s.jsx("div",{className:"space-y-3",children:u.slice(0,5).map(e=>s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("p",{className:"text-sm font-medium",children:[e.firstName," ",e.lastName]}),s.jsx("p",{className:"text-xs text-muted-foreground",children:e.email})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(E,{variant:"outline",className:"text-xs",children:e.subscriptionPlan}),s.jsx(d,{variant:"ghost",size:"sm",asChild:!0,children:s.jsx(c,{href:`/admin/users?user=${e.id}`,children:s.jsx(k,{className:"h-3 w-3"})})})]})]},e.id))}),s.jsx(d,{variant:"outline",className:"w-full mt-4",asChild:!0,children:s.jsx(c,{href:"/admin/users","data-testid":"button-view-all-users",children:"View All Users"})})]})]}),s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"User Distribution"}),s.jsx(o,{children:"Users by subscription tier"})]}),s.jsx(t,{children:s.jsx("div",{className:"space-y-4",children:["starter","professional","agency","enterprise"].map(e=>{const n=u.filter(v=>v.subscriptionPlan===e).length,p=u.length>0?n/u.length*100:0;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex justify-between text-sm",children:[s.jsx("span",{className:"capitalize font-medium",children:e}),s.jsxs("span",{children:[n," users (",p.toFixed(1),"%)"]})]}),s.jsx(w,{value:p,className:"h-2"})]},e)})})})]})]})}),s.jsx(b,{value:"ai-usage",className:"space-y-6",children:s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"AI Cost Breakdown"}),s.jsx(o,{children:"Costs by AI service provider"})]}),s.jsx(t,{children:s.jsx("div",{className:"h-64",children:s.jsx(f.Suspense,{fallback:s.jsx("div",{className:"flex items-center justify-center h-full",children:"Loading charts..."}),children:s.jsx(P,{data:R,type:"bar",dataKey:"cost"})})})})]}),s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"Real-time AI Stats"}),s.jsx(o,{children:"Live AI usage metrics"})]}),s.jsx(t,{children:$?s.jsx("div",{className:"space-y-3",children:[...Array(4)].map((e,n)=>s.jsxs("div",{className:"animate-pulse",children:[s.jsx("div",{className:"h-4 bg-gray-200 rounded w-24 mb-2"}),s.jsx("div",{className:"h-6 bg-gray-200 rounded w-16"})]},n))}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Requests Today"}),s.jsx("span",{className:"text-sm font-bold",children:g((l==null?void 0:l.requestsToday)||0)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Cost Today"}),s.jsx("span",{className:"text-sm font-bold",children:z((l==null?void 0:l.costToday)||0)})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Avg Response Time"}),s.jsxs("span",{className:"text-sm font-bold",children:[(l==null?void 0:l.avgResponseTime)||0,"ms"]})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-sm font-medium",children:"Active Models"}),s.jsx("span",{className:"text-sm font-bold",children:(l==null?void 0:l.activeModels)||0})]})]})})]})]})}),s.jsx(b,{value:"performance",className:"space-y-6",children:s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"System Performance"}),s.jsx(o,{children:"Server metrics and response times"})]}),s.jsx(t,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsx("span",{className:"text-sm font-medium",children:"CPU Usage"}),s.jsx("span",{className:"text-sm font-bold",children:"24%"})]}),s.jsx(w,{value:24,className:"h-2"}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsx("span",{className:"text-sm font-medium",children:"Memory Usage"}),s.jsx("span",{className:"text-sm font-bold",children:"67%"})]}),s.jsx(w,{value:67,className:"h-2"}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsx("span",{className:"text-sm font-medium",children:"Database Performance"}),s.jsx("span",{className:"text-sm font-bold",children:"Good"})]}),s.jsx(w,{value:85,className:"h-2"})]})})]}),s.jsxs(a,{children:[s.jsxs(r,{children:[s.jsx(i,{children:"Error Monitoring"}),s.jsx(o,{children:"Recent errors and system issues"})]}),s.jsx(t,{children:s.jsxs("div",{className:"text-center py-6",children:[s.jsx(A,{className:"h-12 w-12 mx-auto mb-4 text-green-500"}),s.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"System running smoothly"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Last error: 2 days ago"})]})})]})]})})]}),s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsxs("div",{className:"flex gap-3",children:[s.jsx(d,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs(c,{href:"/admin/users","data-testid":"button-manage-users",children:[s.jsx(ss,{className:"h-4 w-4 mr-2"}),"Manage Users"]})}),s.jsx(d,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs(c,{href:"/admin/system-monitor","data-testid":"button-system-monitor",children:[s.jsx(T,{className:"h-4 w-4 mr-2"}),"System Monitor"]})}),s.jsx(d,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs(c,{href:"/admin/settings","data-testid":"button-admin-settings",children:[s.jsx(es,{className:"h-4 w-4 mr-2"}),"Settings"]})})]})})]})}export{ps 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.