1import{j as e}from"./index-COia_u_c.js";import{Y as h,f,L as j}from"./error-boundary-f1in_24u.js";import{C as a,a as n,b as i,c}from"./card-9FFZVsXh.js";import{B as p}from"./badge-CRv2Uj06.js";import{C as g}from"./circle-alert-DdfpBD5C.js";function d(r){const s=typeof r=="string"?Number(r):r;return Number.isFinite(s)?`$${(s/100).toFixed(2)}`:"$0"}function w(){const[,r]=h("/agency/:id/revenue"),s=r?.id,{data:l,isLoading:m,isError:u,error:x}=f({queryKey:["/api/work/agency",s,"revenue"],enabled:!!s,queryFn:async()=>{const t=await fetch(`/api/work/agency/${s}/revenue`,{credentials:"include"});if(!t.ok)throw new Error(`revenue_${t.status}`);return await t.json()}});if(!s)return null;if(m)return e.jsx("div",{className:"flex min-h-[60vh] items-center justify-center","data-testid":"loader-agency-revenue",children:e.jsx(j,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(u||!l)return e.jsx("div",{className:"mx-auto max-w-2xl px-4 py-12","data-testid":"error-agency-revenue",children:e.jsx(a,{children:e.jsxs(n,{className:"flex flex-col items-center gap-2 py-10 text-center",children:[e.jsx(g,{className:"h-6 w-6 text-muted-foreground","aria-hidden":!0}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Couldnât load revenue."," ",x instanceof Error&&/403/.test(x.message)?"Only the workspace owner can view this page.":"Please try again."]})]})})});const o=l.totals;return e.jsxs("div",{className:"mx-auto max-w-5xl space-y-6 px-4 py-10","data-testid":"page-agency-revenue",children:[e.jsxs("header",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold","data-testid":"text-revenue-title",children:"Workspace revenue"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Settlements aggregated across every service in your published bundles."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs(a,{"data-testid":"card-total-gross",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-xs font-medium text-muted-foreground",children:"Gross collected"})}),e.jsx(n,{children:e.jsx("p",{className:"text-2xl font-semibold","data-testid":"text-total-gross",children:d(o.grossCents)})})]}),e.jsxs(a,{"data-testid":"card-total-fees",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-xs font-medium text-muted-foreground",children:"Platform fees"})}),e.jsx(n,{children:e.jsx("p",{className:"text-2xl font-semibold","data-testid":"text-total-fees",children:d(o.platformFeeCents)})})]}),e.jsxs(a,{"data-testid":"card-total-net",children:[e.jsx(i,{className:"pb-2",children:e.jsx(c,{className:"text-xs font-medium text-muted-foreground",children:"Net to creators"})}),e.jsx(n,{children:e.jsx("p",{className:"text-2xl font-semibold","data-testid":"text-total-net",children:d(o.netCents)})})]})]}),e.jsxs(a,{"data-testid":"card-recent-settlements",children:[e.jsx(i,{children:e.jsx(c,{className:"text-base",children:"Recent settlements"})}),e.jsx(n,{children:l.recent.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground","data-testid":"text-no-settlements",children:"No settlements yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs text-muted-foreground",children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"py-2 text-left font-medium",children:"Service"}),e.jsx("th",{className:"py-2 text-right font-medium",children:"Gross"}),e.jsx("th",{className:"py-2 text-right font-medium",children:"Net"}),e.jsx("th",{className:"py-2 text-right font-medium",children:"Creator %"}),e.jsx("th",{className:"py-2 text-left font-medium",children:"Status"}),e.jsx("th",{className:"py-2 text-left font-medium",children:"When"})]})}),e.jsx("tbody",{children:l.recent.map(t=>e.jsxs("tr",{className:"border-b last:border-b-0","data-testid":`row-settlement-${t.id}`,children:[e.jsxs("td",{className:"py-2 font-mono text-xs text-muted-foreground",children:[t.serviceId.slice(0,8),"â¦"]}),e.jsx("td",{className:"py-2 text-right",children:d(t.grossCents)}),e.jsx("td",{className:"py-2 text-right",children:d(t.netCents)}),e.jsx("td",{className:"py-2 text-right tabular-nums","data-testid":`text-effective-creator-pct-${t.id}`,children:t.grossCents>0?`${Math.round(t.netCents/t.grossCents*100)}%`:"â"}),e.jsx("td",{className:"py-2",children:e.jsx(p,{variant:"secondary",children:t.status})}),e.jsx("td",{className:"py-2 text-xs text-muted-foreground",children:new Date(t.chargedAt??t.createdAt).toLocaleStr
1ing()})]},t.id))})]})})})]})]})}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.