1import{o as G,r as a,j as e,k as d,T as o,C as f}from"./index-D-AFl6v8.js";import{L as J,C as Y,E as Z}from"./index-CfApN3LR.js";import{m as ee,n as re,o as te,p as oe,s as se}from"./superadmin-B2KQJapW.js";import{S as x}from"./Stack-7YBloGKc.js";import{c as ne,P as ie}from"./createLucideIcon-L7O1RZew.js";import{C as m}from"./Card-C02Ei0wK.js";import{C as g}from"./CardContent-Dm-G-azE.js";import{T as ae}from"./trending-up-mfHKTCg8.js";import{U as le,T as ce}from"./users-BNQLfDB3.js";import{T as de,a as xe,b as pe,c as F,d as l,e as he}from"./TableRow-KhikY9Mj.js";import{L as me}from"./Link-DQbJ92mW.js";import{S as ge}from"./TextField-DdZmIhxv.js";import{M as ue}from"./MenuItem-BOli6_Jj.js";import{C as fe}from"./server-Dz7pqCYN.js";import{L as je}from"./LineChart-BE6HZDOs.js";import"./index-BZruhSgt.js";import"./send-D6l0clPM.js";import"./createSvgIcon-DLxHainh.js";import"./check-X8X9CWkw.js";import"./x-BTs_WrB8.js";import"./Modal-CRLh7o4j.js";import"./wrench-Bn1myMGq.js";import"./Drawer-CBLHdxOe.js";import"./styled-C-2iXfty.js";import"./useThemeProps-DgQP1pEg.js";import"./ChartsWrapper-DLfrBfxg.js";import"./timeout-IHVaM_cT.js";import"./Popper-vIybPXYE.js";/** 2 * @license lucide-react v0.545.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const be=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],Fe=ne("dollar-sign",be),c="#0066FF",Ce="https://dashboard.stripe.com/customers",Ae=["FREE","PRO","MAX"],_=i=>i===0?"Unlimited":i>=1e6?`${(i/1e6).toFixed(1)}M`:i>=1e3?`${(i/1e3).toFixed(1)}K`:i.toLocaleString(),j=i=>i===0?"$0":i>=1e6?`$${(i/1e6).toFixed(1)}M`:i>=1e3?`$${(i/1e3).toFixed(1)}K`:`$${i.toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:2})}`,P={FREE:"#ECFDF5",PRO:"#EFF6FF",MAX:"#FEF3C7"},B={FREE:"#059669",PRO:"#0066FF",MAX:"#D97706"},w={FREE:{tokens:1e5,users:1,api:0},PRO:{tokens:0,users:10,api:5},MAX:{tokens:0,users:999,api:25}},Je=()=>{const{auth:i}=G(),p=(i==null?void 0:i.token)??"",[$,v]=a.useState([]),[U,R]=a.useState(!0),[T,C]=a.useState(null),[h,N]=a.useState("org_name"),[A,k]=a.useState("asc"),[z,W]=a.useState(new Set),[t,H]=a.useState(null),[b,K]=a.useState([]),[E,X]=a.useState([]),[S,D]=a.useState(!0),L=a.useCallback(async()=>{if(p){R(!0),C(null);try{const r=await ee(p);v(r)}catch{C("Failed to load billing subscriptions.")}finally{R(!1)}}},[p]),M=a.useCallback(async()=>{if(p){D(!0);try{const[r,s,n]=await Promise.all([re(p),te(p),oe(p)]);H(r),K(s.points),X(n.orgs)}catch{}finally{D(!1)}}},[p]);a.useEffect(()=>{L()},[L]),a.useEffect(()=>{M()},[M]);const q=r=>{h===r?k(s=>s==="asc"?"desc":"asc"):(N(r),k("desc"))},O=[...$].sort((r,s)=>{let n=0;return h==="org_name"?n=r.org_name.localeCompare(s.org_name):h==="tokens_used"&&(n=r.tokens_used-s.tokens_used),A==="asc"?n:-n}),Q=async(r,s)=>{if(p){W(n=>new Set(n).add(r.org_id));try{const n=await se(p,r.org_id,s),u=n.plan&&n.plan.length>0?n.plan.toUpperCase():s;v(V=>V.map(y=>y.org_id===r.org_id?{...y,plan:u,token_limit:n.token_limit_monthly,user_limit:n.user_limit,is_entitled:u!=="FREE"}:y))}catch{C(`Failed to change plan for ${r.org_name}.`)}finally{W(n=>{const u=new Set(n);return u.delete(r.org_id),u})}}},I={org_name:"Org Name",tokens_used:"Tokens Used"};return e.jsx(J,{children:e.jsxs(d,{sx:{backgroundColor:"#f8f9fa",minHeight:"100vh",p:{xs:2,md:4}},children:[e.jsx(x,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},spacing:2,sx:{mb:4},children:e.jsx(d,{children:e.jsx(o,{variant:"h4",fontWeight:600,sx:{color:"#0A0A0A"},children:"Billing"})})}),T&&e.jsx(ie,{sx:{p:2,mb:3,backgroundColor:"#FEF2F2",border:"1px solid #FECACA",borderRadius:"10px"},children:e.jsx(o,{color:"#B91C1C",variant:"body2",children:T})}),e.jsx(x,{direction:{xs:"column",lg:"row"},spacing:3,sx:{mb:3},children:S?e.jsx(d,{sx:{display:"flex",justifyContent:"center",width:"100%",py:4},children:e.jsx(f,{size:28,sx:{color:c}})}):e.jsxs(d,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr",md:"1fr 1fr 1fr 1fr"},gap:2,width:"100%"},children:[e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:1,sx:{mb:1},children:[e.jsx(Fe,{size:16,color:c}),e.jsx(o,{variant:"caption",sx:{color:"#6B7280",textTransform:"uppercase",letterSpacing:"0.04em",fontWeight:600},children:"MRR"})]}),e.jsx(o,{variant:"h5",fontWeight:700,sx:{color:"#0A0A0A"},children:j((t==null?void 0:t.mrr)??0)}
6),e.jsxs(o,{variant:"body2",sx:{color:"#9CA3AF",mt:.5},children:[(t==null?void 0:t.active_subscriptions)??0," active subs"]})]})}),e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:1,sx:{mb:1},children:[e.jsx(Y,{size:16,color:((t==null?void 0:t.failed_payments_count)??0)>0?"#DC2626":"#9CA3AF"}),e.jsx(o,{variant:"caption",sx:{color:"#6B7280",textTransform:"uppercase",letterSpacing:"0.04em",fontWeight:600},children:"Failed Payments"})]}),e.jsx(o,{variant:"h5",fontWeight:700,sx:{color:((t==null?void 0:t.failed_payments_count)??0)>0?"#DC2626":"#0A0A0A"},children:(t==null?void 0:t.failed_payments_count)??0}),e.jsx(o,{variant:"body2",sx:{color:"#9CA3AF",mt:.5},children:"this billing cycle"})]})}),e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:1,sx:{mb:1},children:[e.jsx(ae,{size:16,color:((t==null?void 0:t.churn_rate)??0)>5?"#DC2626":c}),e.jsx(o,{variant:"caption",sx:{color:"#6B7280",textTransform:"uppercase",letterSpacing:"0.04em",fontWeight:600},children:"Churn Rate"})]}),e.jsxs(o,{variant:"h5",fontWeight:700,sx:{color:"#0A0A0A"},children:[((t==null?void 0:t.churn_rate)??0).toFixed(1),"%"]}),e.jsx(o,{variant:"body2",sx:{color:"#9CA3AF",mt:.5},children:"monthly"})]})}),e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:1,sx:{mb:1},children:[e.jsx(le,{size:16,color:c}),e.jsx(o,{variant:"caption",sx:{color:"#6B7280",textTransform:"uppercase",letterSpacing:"0.04em",fontWeight:600},children:"ARPU"})]}),e.jsx(o,{variant:"h5",fontWeight:700,sx:{color:"#0A0A0A"},children:j((t==null?void 0:t.arpu)??0)}),e.jsxs(o,{variant:"body2",sx:{color:"#9CA3AF",mt:.5},children:["LTV: ",j((t==null?void 0:t.ltv_estimate)??0)]})]})})]})}),e.jsxs(x,{direction:{xs:"column",lg:"row"},spacing:3,sx:{mb:3},children:[e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flex:2,minWidth:0},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsx(o,{variant:"subtitle1",fontWeight:600,sx:{color:"#0A0A0A",mb:2},children:"Revenue â Last 12 Months"}),S?e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:6},children:e.jsx(f,{size:24,sx:{color:c}})}):b.length===0||b.every(r=>r.revenue===0)?e.jsx(d,{sx:{display:"flex",justifyContent:"center",alignItems:"center",py:6},children:e.jsx(o,{variant:"body2",color:"#9CA3AF",children:"No revenue data yet. Subscriptions will appear here once they start."})}):e.jsx(d,{sx:{width:"100%",height:260},children:e.jsx(je,{xAxis:[{data:b.map(r=>r.month),scaleType:"point",tickLabelStyle:{fontSize:11,angle:-35,textAnchor:"end"}}],series:[{data:b.map(r=>r.revenue),label:"Revenue",color:c,area:!0,valueFormatter:r=>r?j(r):"$0"}],height:260,margin:{left:60,right:20,top:10,bottom:50}})})]})}),e.jsx(m,{sx:{borderRadius:"12px",border:"1px solid #F0F0F0",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flex:1,minWidth:0},children:e.jsxs(g,{sx:{p:2.5},children:[e.jsx(o,{variant:"subtitle1",fontWeight:600,sx:{color:"#0A0A0A",mb:2},children:"Top Revenue Orgs"}),S?e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:4},children:e.jsx(f,{size:24,sx:{color:c}})}):E.length===0?e.jsx(d,{sx:{display:"flex",justifyContent:"center",alignItems:"center",py:4},children:e.jsx(o,{variant:"body2",color:"#9CA3AF",children:"No paying orgs yet."})}):e.jsx(x,{spacing:1,children:E.map((r,s)=>e.jsxs(x,{direction:"row",alignItems:"center",justifyContent:"space-between",sx:{py:1,px:1.5,borderRadius:"8px",backgroundColor:s===0?"#EFF6FF":"transparent","&:hover":{backgroundColor:"#F9FAFB"}},children:[e.jsxs(x,{direction:"row",alignItems:"center",spacing:1.5,children:[e.jsx(o,{variant:"caption",sx:{fontWeight:700,color:s===0?c:"#9CA3AF",width:20},children:s+1}),e.jsxs(d,{children:[e.jsx(o,{variant:"body2",fontWeight:600,sx:{color:"#0A0A0A"},children:r.org_name}
6),e.jsx(o,{variant:"caption",sx:{color:"#9CA3AF"},children:r.plan})]})]}),e.jsx(o,{variant:"body2",fontWeight:700,sx:{color:c},children:j(r.mrr)})]},r.org_id))})]})})]}),e.jsx(m,{sx:{borderRadius:"12px",boxShadow:"0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04)",border:"1px solid #F0F0F0",overflow:"hidden"},children:e.jsx(g,{sx:{p:0},children:e.jsx(de,{component:d,children:e.jsxs(xe,{children:[e.jsx(pe,{children:e.jsxs(F,{sx:{backgroundColor:"#FAFAFA"},children:[Object.keys(I).map(r=>e.jsx(l,{sortDirection:h===r?A:!1,sx:{fontWeight:600,color:"#374151",fontSize:"0.8125rem",textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap"},children:e.jsx(ce,{active:h===r,direction:h===r?A:"asc",onClick:()=>q(r),sx:{"& .MuiTableSortLabel-icon":{opacity:h===r?1:.3}},children:I[r]})},r)),e.jsx(l,{sx:{fontWeight:600,color:"#374151",fontSize:"0.8125rem",textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap"},children:"Token Limit"}),e.jsx(l,{sx:{fontWeight:600,color:"#374151",fontSize:"0.8125rem",textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap"},children:"Users"}),e.jsx(l,{sx:{fontWeight:600,color:"#374151",fontSize:"0.8125rem",textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap"},children:"Stripe"}),e.jsx(l,{sx:{fontWeight:600,color:"#374151",fontSize:"0.8125rem",textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap"},children:"Plan"})]})}),e.jsx(he,{children:U?e.jsx(F,{children:e.jsx(l,{colSpan:6,align:"center",sx:{py:8},children:e.jsx(f,{size:28,sx:{color:c}})})}):O.length===0?e.jsx(F,{children:e.jsx(l,{colSpan:6,align:"center",sx:{py:8},children:e.jsx(o,{variant:"body2",color:"#9CA3AF",children:"No organizations found."})})}):O.map(r=>e.jsxs(F,{sx:{"&:hover":{backgroundColor:"#F9FAFB"},"& .MuiTableCell-root":{borderBottom:"1px solid #F3F4F6"}},children:[e.jsx(l,{sx:{fontSize:"0.875rem",color:"#0A0A0A",fontWeight:500},children:r.org_name}),e.jsx(l,{sx:{fontSize:"0.875rem",color:"#374151"},children:_(r.tokens_used)}),e.jsx(l,{sx:{fontSize:"0.875rem",color:"#374151"},children:_(r.token_limit)}),e.jsx(l,{sx:{fontSize:"0.875rem",color:"#374151"},children:r.user_limit}),e.jsx(l,{children:r.stripe_customer_id?e.jsxs(me,{href:`${Ce}/${r.stripe_customer_id}`,target:"_blank",rel:"noopener noreferrer",sx:{color:c,textDecoration:"none",display:"inline-flex",alignItems:"center",gap:.5,"&:hover":{textDecoration:"underline"}},children:[r.stripe_customer_id.slice(0,8),"â¦",e.jsx(Z,{size:12})]}):e.jsx(o,{variant:"body2",color:"#9CA3AF",component:"span",children:"N/A"})}),e.jsx(l,{children:e.jsx(ge,{size:"small",value:r.plan.toUpperCase(),onChange:s=>{const n=s.target.value;n!==r.plan.toUpperCase()&&Q(r,n)},disabled:z.has(r.org_id),IconComponent:z.has(r.org_id)?()=>e.jsx(f,{size:16,sx:{mr:1,color:c}}):void 0,sx:{fontSize:"0.8rem",fontWeight:600,height:32,minWidth:130,"& .MuiSelect-select":{py:.5},backgroundColor:P[r.plan.toUpperCase()]??"#F3F4F6",color:B[r.plan.toUpperCase()]??"#374151","& .MuiOutlinedInput-notchedOutline":{borderColor:"transparent"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"#D1D5DB"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:c,borderWidth:2}},children:Ae.map(s=>e.jsx(ue,{value:s,sx:{fontSize:"0.8rem"},children:e.jsxs(x,{direction:"row",spacing:1,alignItems:"center",sx:{width:"100%"},children:[e.jsx(fe,{label:s,size:"small",sx:{backgroundColor:P[s],color:B[s],fontWeight:700,fontSize:"0.7rem",height:22}}),e.jsxs(o,{variant:"caption",color:"text.secondary",children:[_(w[s].tokens)," tokens · ",w[s].users," users · ",w[s].api," API"]})]})},s))})})]},r.org_id))})]})})})})]})})};export{Je 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.