1import{a as m,j as s}from"./vendor-query-CVWBAYQN.js";import{P as C}from"./PageShell-DDy5DWJ7.js";import{S as h,N as M,C as a,f as i,b as j,d as y,s as c}from"./index-DJLejKcN.js";import{E as R}from"./EmptyState-C3vD0qG_.js";import{T as q}from"./ToolLoadingState-B6nB0p0M.js";import{u as v}from"./useAdminEnabled-CWcvke8Z.js";import{A}from"./AdminUserEmailLink-Dz8Vmxy-.js";import{E as P,f as N,p as E}from"./adminMrrSummary-JBbA75yE.js";import{C as g}from"./vendor-icons-BJ-Rh-HN.js";import"./ErrorState-De3uL_pY.js";import"./HeroBackdrop-CytUHOCH.js";import"./DrawerHero-CNs4a2F0.js";import"./HelpButton-C88-Kq3v.js";import"./HelpOverlayContext-vHZe9ebM.js";import"./vendor-supabase-DhFQUKws.js";import"./vendor-motion-8aOieDHp.js";import"./GoldMedallion-B1lpev0e.js";function W(){var b;const{enabled:n,loading:_,isAdmin:w}=v(),p=m({queryKey:["admin-mrr-summary"],enabled:n,queryFn:async()=>{const{data:e,error:t}=await c.rpc("admin_mrr_summary");if(t)throw t;return E(e)}}),x=m({queryKey:["admin-subscriptions-list"],enabled:n,queryFn:async()=>{const{data:e,error:t}=await c.from("subscriptions").select("id, user_id, tier, status, seat_count").order("updated_at",{ascending:!1}).limit(200);if(t)throw t;return e??[]}}),S=m({queryKey:["admin-seat-member-count"],enabled:n,queryFn:async()=>{const{count:e,error:t}=await c.from("seat_members").select("id",{count:"exact",head:!0});if(t)throw t;return e??0}}),f=m({queryKey:["admin-tier-counts"],enabled:n,queryFn:async()=>{const{data:e,error:t}=await c.from("profiles").select("subscription_tier");if(t)throw t;const l=new Map;for(const u of e??[]){const o=u.subscription_tier??"free";l.set(o,(l.get(o)??0)+1)}return Array.from(l.entries()).map(([u,o])=>({tier:u,count:o}))}});if(_)return s.jsx(h,{className:"h-40 w-full"});if(!w)return s.jsx(M,{});const d=x.data??[],r=p.data??P;return s.jsxs(C,{title:"Subscriptions",icon:g,subtitle:"Stripe-backed subscriptions, MRR, and seat operability",children:[s.jsxs("div",{className:"mb-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[s.jsx(a,{children:s.jsxs(i,{className:"pt-5",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"MRR (active)"}),s.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums",children:p.isLoading?"â¦":N(r.mrr_cents)}),s.jsxs("p",{className:"mt-0.5 text-step-caption text-muted-foreground",children:[r.paying_subscribers," paying · ",r.active_seats," seats"]})]})}),s.jsx(a,{children:s.jsxs(i,{className:"pt-5",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"In trial"}),s.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums",children:r.trialing_count}),s.jsxs("p",{className:"mt-0.5 text-step-caption text-muted-foreground",children:["Potential ",N(r.trialing_mrr_potential_cents)]})]})}),s.jsx(a,{className:r.past_due_count>0?"border-destructive/30":void 0,children:s.jsxs(i,{className:"pt-5",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Past due"}),s.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums",children:r.past_due_count})]})}),s.jsx(a,{children:s.jsxs(i,{className:"pt-5",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Seat members"}),s.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums",children:S.data??0}),s.jsxs("p",{className:"mt-0.5 text-step-caption text-muted-foreground",children:[d.length," subscription row(s)"]})]})})]}),x.isLoading?s.jsx(q,{}):d.length===0?s.jsx(R,{icon:g,title:"No subscription rows",description:"Self-serve checkout has not created rows yet, or Stripe is not configured."}):s.jsxs(a,{children:[s.jsx(j,{children:s.jsx(y,{className:"text-base",children:"Recent subscriptions"})}),s.jsx(i,{className:"space-y-2 text-sm",children:d.map(e=>s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border/60 py-2 last:border-0",children:[s.jsx(A,{userId:e.user_id}),s.jsx("span",{children:e.tier}),s.jsx("span",{className:"text-muted-foreground",children:e.status}),s.jsxs("span",{className:"tabular-nums",children:[e.seat_count," seats"]})]},e.id))})]}),s.jsxs(a,{className:"mt-6",children:[s.jsx(j,{children:s.jsx(y,{className:"text-base",children:"Profile tier distribution"})}),s.jsx(i,{className:"space-y-1 text-sm",children:f.isLoading?s.jsx(h,{className:"h-16 w-full"}):(b=f.data)==null?void 0:b.map(e=>s.jsxs("div",{className:"flex justify-between border-b border-border/60 py-1",children:[s.jsx("span",{children:e.tier}),s.jsx("span",{className:"text-muted-foreground",children:e.count})]},e.tier))})]})]})}export{W 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.