1import{j as e}from"./ui-C6t_nCSG.js";import{r as i}from"./vendor-BStmp9eX.js";import{a as h,A as U}from"./index-BL6G0anb.js";import{U as E,b as y,b8 as I,A as B,z as k,Z as _,b9 as C,h as S}from"./icons-Od_4ddEk.js";const V=()=>{const[a,x]=i.useState(null),[l,o]=i.useState(null),[n,d]=i.useState([]),[r,m]=i.useState(null),[j,g]=i.useState(!0),[u,t]=i.useState(null),[f,A]=i.useState(new Date);i.useEffect(()=>{N();const s=setInterval(N,3e4);return()=>clearInterval(s)},[]);const N=async()=>{try{g(!0),t(null);const[s,$,L,T]=await Promise.all([M(),P(),R(),D()]);x(s),o($),d(L),m(T),A(new Date)}catch(s){t(s.message||"Failed to load monitoring data")}finally{g(!1)}},M=async()=>{try{return(await h.get(3001,"user-management/admin/metrics"))?.data||v()}catch{return v()}},P=async()=>{try{return(await h.get(3008,"analytics/revenue/latest"))?.data||w()}catch{return w()}},R=async()=>{try{return(await h.get(3001,"user-management/admin/cost-anomalies?limit=10"))?.data||[]}catch{return[]}},D=async()=>{try{return(await h.get(3001,"user-management/admin/performance"))?.data||b()}catch{return b()}},b=()=>({lcp:{avg:0,min:0,max:0,count:0},fid:{avg:0,min:0,max:0,count:0},cls:{avg:0,min:0,max:0,count:0},fcp:{avg:0,min:0,max:0,count:0},ttfb:{avg:0,min:0,max:0,count:0},api_response_time:{avg:0,min:0,max:0,count:0},page_load_time:{avg:0,min:0,max:0,count:0}}),v=()=>({total_users:0,active_trials:0,expired_trials:0,total_storage_gb:0,storage_cost_per_month:0,total_meeting_hours:0,cost_anomalies_count:0,system_health:"healthy",error_rate:0,uptime_percentage:100}),w=()=>({mrr:0,arr:0,new_customers:0,churned_customers:0,churn_rate:0,active_subscriptions:0});if(j&&!a)return e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-1/4"}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:[1,2,3,4].map(s=>e.jsx("div",{className:"h-32 bg-gray-200 rounded"},s))})]})});const F=s=>{switch(s){case"healthy":return"text-green-600 bg-green-100";case"degraded":return"text-yellow-600 bg-yellow-100";case"down":return"text-red-600 bg-red-100";default:return"text-gray-600 bg-gray-100"}};return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"System Monitoring"}),e.jsx("p",{className:"text-gray-600",children:"Real-time system health and cost monitoring"})]}),e.jsxs("div",{className:"text-sm text-gray-500",children:["Last updated: ",f.toLocaleTimeString()]})]}),u&&e.jsx(U,{variant:"error",title:"Error",onClose:()=>t(null),children:u}),a&&e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"System Health"}),e.jsx("span",{className:`px-3 py-1 rounded-full text-sm font-medium ${F(a.system_health)}`,children:a.system_health.toUpperCase()})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Uptime"}),e.jsxs("p",{className:"text-2xl font-bold",children:[a.uptime_percentage.toFixed(2),"%"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Error Rate"}),e.jsxs("p",{className:"text-2xl font-bold",children:[a.error_rate.toFixed(2),"%"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(p,{title:"Total Users",value:a?.total_users||0,icon:e.jsx(E,{className:"w-6 h-6"}),color:"blue"}),e.jsx(p,{title:"Active Trials",value:a?.active_trials||0,icon:e.jsx(y,{className:"w-6 h-6"}),color:"green"}),e.jsx(p,{title:"Storage Cost",value:`$${a?.storage_cost_per_month.toFixed(2)||"0.00"}`,subtitle:`${a?.total_storage_gb.toFixed(1)||0} GB`,icon:e.jsx(I,{className:"w-6 h-6"}),color:"yellow"}),e.jsx(p,{title:"Cost Anomalies",value:a?.cost_anomalies_count||0,icon:e.jsx(B,{className:"w-6 h-6"}),color:a&&a.cost_anomalies_count>0?"red":"gray"})]}),l&&e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(k,{className:"w-5 h-5 text-green-600"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Revenue Metrics"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"MRR"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",l.mrr.toLocaleStr
1ing()]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"ARR"}),e.jsxs("p",{className:"text-2xl font-bold",children:["$",l.arr.toLocaleString()]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Active Subscriptions"}),e.jsx("p",{className:"text-2xl font-bold",children:l.active_subscriptions})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"New Customers"}),e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:["+",l.new_customers]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Churned"}),e.jsxs("p",{className:"text-2xl font-bold text-red-600",children:["-",l.churned_customers]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Churn Rate"}),e.jsxs("p",{className:"text-2xl font-bold",children:[l.churn_rate.toFixed(2),"%"]})]})]})]}),r&&e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(_,{className:"w-5 h-5 text-blue-600"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Performance Metrics"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(c,{title:"LCP",subtitle:"Largest Contentful Paint",value:r.lcp.avg,unit:"ms",threshold:{good:2500,poor:4e3},count:r.lcp.count,icon:e.jsx(C,{className:"w-5 h-5"})}),e.jsx(c,{title:"FID",subtitle:"First Input Delay",value:r.fid.avg,unit:"ms",threshold:{good:100,poor:300},count:r.fid.count,icon:e.jsx(S,{className:"w-5 h-5"})}),e.jsx(c,{title:"CLS",subtitle:"Cumulative Layout Shift",value:r.cls.avg,unit:"",threshold:{good:.1,poor:.25},count:r.cls.count,icon:e.jsx(y,{className:"w-5 h-5"})}),e.jsx(c,{title:"FCP",subtitle:"First Contentful Paint",value:r.fcp.avg,unit:"ms",threshold:{good:1800,poor:3e3},count:r.fcp.count,icon:e.jsx(_,{className:"w-5 h-5"})}),e.jsx(c,{title:"TTFB",subtitle:"Time to First Byte",value:r.ttfb.avg,unit:"ms",threshold:{good:800,poor:1800},count:r.ttfb.count,icon:e.jsx(S,{className:"w-5 h-5"})}),e.jsx(c,{title:"API Response",subtitle:"Average API Response Time",value:r.api_response_time.avg,unit:"ms",threshold:{good:200,poor:500},count:r.api_response_time.count,icon:e.jsx(y,{className:"w-5 h-5"})}),e.jsx(c,{title:"Page Load",subtitle:"Average Page Load Time",value:r.page_load_time.avg,unit:"ms",threshold:{good:2e3,poor:4e3},count:r.page_load_time.count,icon:e.jsx(C,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Recent Cost Anomalies"}),e.jsx("button",{onClick:N,className:"text-sm text-blue-600 hover:text-blue-800",children:"Refresh"})]}),n.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Threshold"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Actual"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Action"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"Time"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:n.map(s=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:s.anomaly_type}),e.jsx("td",{className:"px-4 py-3 text-sm",children:s.threshold_value}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold text-red-600",children:s.actual_value}),e.jsx("td",{className:"px-4 py-3 text-sm",children:s.action_taken}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-500",children:new Date(s.created_at).toLocaleStr
1ing()})]},s.id))})]})}):e.jsx("p",{className:"text-gray-500 text-center py-8",children:"No cost anomalies detected"})]})]})},p=({title:a,value:x,subtitle:l,icon:o,color:n})=>{const d={blue:"bg-blue-100 text-blue-600",green:"bg-green-100 text-green-600",yellow:"bg-yellow-100 text-yellow-600",red:"bg-red-100 text-red-600",gray:"bg-gray-100 text-gray-600"};return e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-gray-600",children:a}),e.jsx("div",{className:`p-2 rounded-lg ${d[n]}`,children:o})]}),e.jsx("p",{className:"text-2xl font-bold",children:x}),l&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:l})]})},c=({title:a,subtitle:x,value:l,unit:o,threshold:n,count:d,icon:r})=>{const m=t=>t===0?"N/A":o===""?t.toFixed(3):t<1e3?`${Math.round(t)}${o}`:`${(t/1e3).toFixed(2)}s`,j=t=>t===0?"text-gray-500":t<=n.good?"text-green-600":t<=n.poor?"text-yellow-600":"text-red-600",g=t=>t===0?"bg-gray-100":t<=n.good?"bg-green-100":t<=n.poor?"bg-yellow-100":"bg-red-100",u=t=>{if(t===0)return 0;const f=n.poor*1.5;return Math.min(100,t/f*100)};return e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 border border-gray-200",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`p-1.5 rounded ${g(l)}`,children:r}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-gray-900",children:a}),e.jsx("p",{className:"text-xs text-gray-500",children:x})]})]})}),e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[e.jsx("span",{className:`text-2xl font-bold ${j(l)}`,children:m(l)}),d>0&&e.jsxs("span",{className:"text-xs text-gray-500",children:["(",d," samples)"]})]}),e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2 mt-2",children:e.jsx("div",{className:`h-2 rounded-full ${g(l).replace("100","500")}`,style:{width:`${u(l)}%`}})}),e.jsxs("div",{className:"flex justify-between text-xs text-gray-500 mt-1",children:[e.jsxs("span",{children:["Good: <",m(n.good)]}),e.jsxs("span",{children:["Poor: >",m(n.poor)]})]})]})]})};export{V as AdminMonitoring};
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.