1import{r as w,j as e,L as b}from"./react-vendor-D6ayQBDm.js";import{S as A,a as D,P as L,L as M,W as te,b as I,E as R,c as ae,M as se}from"./SuperAdminBits-5OaqlKAT.js";import{u as re,a as ne,b as oe,c as ie,i as f,d as Q,f as ce,e as le}from"./AdminShell-Dyxr9XOj.js";import{m as de,p as me,f as E,w as ue,a as pe,b as ge,s as $,c as he,d as N,e as q,g as xe}from"./metrics-LA-jAi_f.js";import"./supabase-vendor-CtzU2HKK.js";import"./index-BZT-iXgy.js";import"./radix-vendor-DaLysdXC.js";import"./icons-vendor-B2fu3RZw.js";import"./query-vendor-0N7hVbdK.js";import"./editor-tools-CCoOzlli.js";import"./superAdminRepository-cHf5ZKlR.js";function ye(u){const d=new Date(u),c=new Date;return d.toDateString()===c.toDateString()?xe(u):"".concat(String(d.getDate()).padStart(2,"0"),"/").concat(String(d.getMonth()+1).padStart(2,"0"))}function Me(){var B,U,V,F,O,_,z,G,H,J;const u=re(),d=ne(),c=oe(),C=ie(),h=(U=(B=u.data)==null?void 0:B.workspaces)!=null?U:[],k=(F=(V=u.data)==null?void 0:V.subscriptions)!=null?F:[],l=w.useMemo(()=>{const a=h.filter(s=>s.status==="active").length,o=f(h,s=>s.createdAt,0,30).length,n=de(k.map(s=>({status:s.status,unit_price:s.unitPrice,billing_cycle:s.billingCycle,currency:s.currency}))),r=me(n),p=Object.entries(n).filter(([s])=>s!==r),j=k.filter(s=>{var m;return s.status==="active"&&((m=s.unitPrice)!=null?m:0)>0}).length,x=f(d.data,s=>s.createdAt,0,30).reduce((s,m)=>s+m.energyUsed,0),i=f(d.data,s=>s.createdAt,30,60).reduce((s,m)=>s+m.energyUsed,0),g=le(x,i),t=s=>{const m=(s!=null?s:[]).filter(P=>Q(P.status)),ee=m.filter(P=>P.status==="succeeded").length;return{attempts:m.length,rate:m.length?ee/m.length*100:null}},y=t(f(c.data,s=>s.createdAt,0,30)),K=t(f(c.data,s=>s.createdAt,30,60)),Z=y.rate!=null&&K.rate!=null?y.rate-K.rate:null;return{active:a,created30:o,mrrValue:r?E(n[r],r):"â",mrrSub:"".concat(j," subscription có phÃ").concat(p.length?" · +".concat(p.map(([s,m])=>E(m,s)).join(" · ")):""),energyNow:x,energyDelta:g,aiRate:y.rate,aiAttempts:y.attempts,rateDelta:Z}},[h,k,d.data,c.data]),v=w.useMemo(()=>{var a;return ue((a=c.data)!=null?a:[],o=>o.createdAt)},[c.data]),X=v.reduce((a,o)=>a+o.value,0),W=w.useMemo(()=>{var o;const a=new Map;for(const n of f(c.data,r=>r.createdAt,0,7)){if(!n.provider||!Q(n.status))continue;const r=(o=a.get(n.provider))!=null?o:{total:0,ok:0,latency:[]};r.total+=1,n.status==="succeeded"&&(r.ok+=1),n.latencyMs!=null&&r.latency.push(n.latencyMs),a.set(n.provider,r)}return[...a.entries()].map(([n,r])=>{const p=r.total?1-r.ok/r.total:0;return{name:n,total:r.total,tone:p===0?"ok":p<.05?"warn":"alert",latency:pe(ge(r.latency,50))}}).sort((n,r)=>r.total-n.total)},[c.data]),S=w.useMemo(()=>{var n,r,p,j,x,i,g;const a=new Map(h.map(t=>[t.id,t.name])),o=[];for(const t of h.slice(0,10))o.push({key:"ws-".concat(t.id),at:t.createdAt,title:"".concat(t.name," ÄÆ°á»£c tạo"),meta:"".concat($(t.id)," · ").concat((n=t.status)!=null?n:"â"),tone:t.status==="active"?"ok":"muted",to:"/admin/customers/".concat(t.id)});for(const t of k.slice(0,10))o.push({key:"sub-".concat(t.id),at:t.createdAt,title:"".concat((r=a.get(t.workspaceId))!=null?r:$(t.workspaceId)," · gói ").concat(t.planName||t.planCode||"â"),meta:"".concat($(t.workspaceId)," · ").concat((p=t.status)!=null?p:"â").concat(t.unitPrice?" · ".concat(E(t.unitPrice,t.currency||"VND"),"/").concat((j=t.billingCycle)!=null?j:"â"):""),tone:t.status==="active"?"ok":"alert",to:"/admin/customers/".concat(t.workspaceId)});for(const t of((x=C.data)!=null?x:[]).filter(y=>y.category!=="auth"))o.push({key:"audit-".concat(t.id),at:t.occurredAt,title:t.targetLabel?"".concat(t.type," · ").concat(t.targetLabel):t.type||"sá»± kiá»n",meta:"".concat((i=t.category)!=null?i:"audit"," · ").concat((g=t.actorName)!=null?g:"há» thá»ng"),tone:t.status&&t.status!=="success"?"alert":"muted",to:"/admin/health"});return o.sort((t,y)=>Date.parse(y.at)-Date.parse(t.at)).slice(0,6)},[h,k,C.data]),T=w.useMemo(()=>{var p,j,x;const a=new Map(h.map(i=>[i.id,i.name])),o=new Map;for(const i of f(d.data,g=>g.createdAt,0,30))o.set(i.workspaceId,((p=o.get(i.workspaceId))!=null?p:0)+i.energyUsed);const n=[...o.entries()].sort((i,g)=>g[1]-i[1]).slice(0,5),r=(x=(j=n[0])==null?void 0:j[1])!=null?x:0;return n.map(([i,g])=>{var t;return{id:i,name:(t=a.get(i))!=null?t:$(i),value:g,width:he(g,r)}})},[h,d.data]),Y=u.isLoading||C.isLoading;return e.jsxs("div",{className:"space-y-5","data-admin-section":"overview",children:[e.jsxs("div",{className:"grid grid-cols-2 xl:grid-cols-4 gap-3",children:[e.jsx(A,{label:"Workspaces",loading:u.isLoading,value:N(l.active),delta:l.created30?"+".concat(l.created30):null,up:!0,sub:"Äang hoạt Äá»ng"}),e.jsx(A,{label:"MRR",loading:u.isLoading,value:l.mrrValue,sub:l.mrrSub}),e.jsx(A,{label:"AI energy",loading:d.isLoading,value:q(l.energyNow),delta:ce(l.energyDelta),up:((O=l.energyDelta)!=null?O:0)>=0,sub:"dùng 30 ngà y"}),e.jsx(A,{label:"AI thà nh công",loading:c.isLoading,value:l.aiRate==null?"â":"".concat(l.aiRate.toFixed(1),"%"),delta:l.rateDelta==null?null:"".concat(l.rateDelta>=0?"+":"").concat(l.rateDelta.toFixed(1),"%"),up:((_=l.rateDelta)!=null?_:0)>=0,sub:"".concat(N(l.aiAttempts)," request · 30 ngà y")})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-5",children:[e.jsxs("div",{className:"xl:col-span-2",children:[e.jsx(D,{hint:"".concat(N(X)," request"),children:"// ai request · 12 tuần"}),c.error?e.jsx(L,{children:e.jsx(M,{error:c.error})}):e.jsx(te,{buckets:v,height:132,lastCaption:q((G=(z=v[v.length-1])==null?void 0:z.value)!=null?G:0),centerCaption:"Tuần nà y ".concat(N((J=(H=v[v.length-1])==null?void 0:H.value)!=null?J:0)," request")})]}),e.jsxs("div",{children:[e.jsx(D,{hint:"7 ngà y",children:"// sức khoẻ ai provider"}),e.jsx(L,{className:"p-3 space-y-1",children:c.isLoading?e.jsx(I,{rows:3}):c.error?e.jsx(M,{error:c.error}):W.length===0?e.jsx(R,{children:"Chưa có request nà o tá»i provider trong 7 ngà y."}):W.map(a=>e.jsxs(b,{to:"/admin/health",className:"sa-row flex items-center gap-2.5 px-2 py-2",children:[e.jsx("span",{className:"sa-dot","data-tone":a.tone}),e.jsx("span",{className:"text-sm sa-fg-800 truncate flex-1",children:a.name}),e.jsxs("span",{className:"sa-mono text-[10px] leading-[15px] sa-fg-500 whitespace-nowrap",children:[N(a.total)," · ",a.latency]})]},a.name))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsx(D,{hint:"".concat(S.length," sá»± kiá»n"),children:"// hoạt Äá»ng gần Äây"}),e.jsx(L,{className:"p-3 space-y-0.5",children:Y?e.jsx(I,{rows:5}):u.error?e.jsx(M,{error:u.error}):S.length===0?e.jsx(R,{children:"Chưa có hoạt Äá»ng."}):S.map(a=>{var o;return e.jsxs(b,{to:(o=a.to)!=null?o:"/admin",className:"sa-row flex items-start gap-2.5 px-2 py-2",children:[e.jsx("span",{className:"sa-dot mt-1.5","data-tone":a.tone==="alert"?"alert":a.tone==="ok"?"ok":void 0}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm sa-fg-900 truncate",children:a.title}),e.jsx("div",{className:"sa-mono text-[10px] leading-[15px] sa-fg-500 truncate mt-0.5",children:a.meta})]}),e.jsx("span",{className:"sa-mono text-[10px] leading-[15px] sa-fg-400 shrink-0",children:ye(a.at)})]},a.key)})})]}),e.jsxs("div",{children:[e.jsx(D,{hint:"theo AI energy · 30 ngà y",children:e.jsx(b,{to:"/admin/usage",className:"sa-link",children:"// workspace tiêu thụ nhiá»u"})}),e.jsx(L,{className:"p-3 space-y-2",children:d.isLoading||u.isLoading?e.jsx(I,{rows:5}):d.error?e.jsx(M,{error:d.error}):T.length===0?e.jsx(R,{children:"Chưa có workspace nà o dùng AI energy trong 30 ngà y."}):T.map(a=>e.jsxs(b,{to:"/admin/customers/".concat(a.id),className:"sa-row block px-2 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm sa-fg-900 truncate flex-1",children:a.name}),e.jsx(ae,{children:$(a.id)}),e.jsx("span",{className:"sa-mono text-[10px] leading-[15px] sa-fg-700 whitespace-nowrap",children:q(a.value)})]}),e.jsx(se,{width:a.width,tone:"strong"})]},a.id))})]})]})]})}export{Me 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.