1import{j as e}from"./vendor-motion-hRg_q8lq.js";import{u as g,k as L}from"./vendor-query-bOUN_gKe.js";import{du as E}from"./vendor-fa-Bn2dnpnC.js";import{u as h,n as f,L as k}from"./index-BKzE8EQ8.js";import{r as D,b as T}from"./vendor-react-E98sgxjj.js";import{S as I}from"./SettingsPageShell-wmP4-RpH.js";const R=[7,30,90],l=a=>`$${(typeof a=="number"?a:parseFloat(a||"0")).toFixed(2)}`;function C({gameId:a}){const{t,i18n:c}=h("earnings"),[n,j]=D.useState(30),o=g({queryKey:["game-iap-revenue",a,n],queryFn:()=>f.getGameRevenue(a,n),placeholderData:L}),b=s=>new Date(`${s}T00:00:00`).toLocaleDateString(c.language,{month:"short",day:"numeric"}),p=s=>new Date(s).toLocaleString(c.language,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});if(o.isLoading)return e.jsx("div",{className:"h-40 rounded-md bg-foreground/5 animate-pulse"});if(o.isError||!o.data)return e.jsx("p",{className:"text-sm text-muted-foreground",children:t("iap.error","Couldn't load this game's sales. Try again in a moment.")});const r={...o.data,daily:o.data.daily??[],recent_sales:o.data.recent_sales??[]};if(r.sales===0)return e.jsx("p",{className:"text-sm text-muted-foreground",children:t("iap.empty","No in-game purchases yet. Sales will show up here as players buy from your shop.")});const N=parseFloat(r.gross_creator_usd)-parseFloat(r.net_creator_usd),y=t("iap.unlabelled","Item not recorded"),m=s=>s||y,w=new Map(r.top_items.map(s=>[s.sku,m(s.name)])),v=Math.max(.01,...r.daily.map(s=>parseFloat(s.creator_usd))),_=r.daily.reduce((s,d)=>s+d.sales,0),S=r.daily.reduce((s,d)=>s+parseFloat(d.creator_usd),0);return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(u,{label:t("iap.stat.earned","Earned"),value:l(r.net_creator_usd)}),e.jsx(u,{label:t("iap.stat.sales","Sales"),value:r.sales.toLocaleString()}),e.jsx(u,{label:t("iap.stat.coins","Coins spent"),value:r.coins_spent.toLocaleString()}),e.jsx(u,{label:t("iap.stat.refunded","Refunded"),value:l(N)})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("iap.window","Last {{days}} days · {{sales}} sales · {{earned}}",{days:n,sales:_.toLocaleString(),earned:l(S)})}),e.jsx("div",{className:"flex items-center gap-1 p-0.5 rounded-md bg-foreground
1/5",children:R.map(s=>e.jsx("button",{type:"button",onClick:()=>j(s),"aria-pressed":n===s,className:"h-6 px-2 rounded-[5px] text-[11px] tabular-nums cursor-pointer transition-all "+(n===s?"bg-foreground/10 text-foreground font-medium":"text-muted-foreground hover:text-foreground"),children:t("iap.windowOption","{{days}}d",{days:s})},s))})]}),e.jsx("div",{className:"flex items-end gap-[2px] h-[80px]",children:r.daily.map(s=>{const d=parseFloat(s.creator_usd),F=Object.entries(s.items).sort((i,x)=>parseFloat(x[1])-parseFloat(i[1]));return e.jsxs("div",{className:"flex-1 h-full flex flex-col justify-end group relative cursor-default",children:[e.jsx("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-1 hidden group-hover:block z-10",children:e.jsxs("div",{className:"bg-foreground text-background text-[10px] px-2 py-1 rounded whitespace-nowrap shadow-lg",children:[e.jsx("div",{children:b(s.date)}),e.jsx("div",{className:"tabular-nums",children:t("iap.tooltip","{{sales}} sales · {{earned}}",{sales:s.sales,earned:l(d)})}),F.map(([i,x])=>e.jsxs("div",{className:"tabular-nums opacity-80",children:[w.get(i)??i,": ",l(x)]},i))]})}),e.jsx("div",{className:d>
10?"w-full bg-success":"w-full bg-foreground/10",style:{height:d>0?`${Math.max(4,d/v*100)}%`:"2px"}})]},s.date)})})]}),e.jsxs("section",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:t("iap.itemsTitle","What sold")}),e.jsx("div",{className:"overflow-x-auto scrollbar-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left font-medium py-2",children:t("iap.col.item","Item")}),e.jsx("th",{className:"text-right font-medium py-2 px-3",children:t("iap.col.sold","Sold")}),e.jsx("th",{className:"text-right font-medium py-2 px-3",children:t("iap.col.coins","Coins")}),e.jsx("th",{className:"text-right font-medium py-2 px-3",children:t("iap.col.earned","Earned")}),e.jsx("th",{className:"text-right font-medium py-2",children:t("iap.col.lastSold","Last sold")})]})}),e.jsx("tbody",{children:r.top_items.map(s=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-2 "+(s.name?"text-foreground":"text-muted-foreground italic"),children:m(s.name)}),e.jsxs("td",{className:"py-2 px-3 text-right tabular-nums",children:[s.units_sold.toLocaleString(),s.refunds>0&&e.jsx("span",{className:"ml-1 text-[10px] text-muted-foreground",children:t("iap.refundCount","({{count}} refunded)",{count:s.refunds})})]}),e.jsx("td",{className:"py-2 px-3 text-right tabular-nums",children:s.coins_spent.toLocaleString()}),e.jsx("td",{className:"py-2 px-3 text-right tabular-nums font-medium",children:l(s.net_creator_usd??s.creator_usd)}),e.jsx("td",{className:"py-2 text-right text-muted-foreground whitespace-nowrap",children:s.last_sold_at?p(s.last_sold_at):"â"})]},s.sku))})]})})]}),e.jsxs("section",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:t("iap.recentTitle","Recent sales")}),e.jsx("ul",{className:"divide-y divide-border",children:r.recent_sales.map(s=>e.jsxs("li",{className:"flex items-center justify-between gap-3 py-2 text-sm",children:[e.jsx("span",{className:"truncate "+(s.name?"text-foreground":"text-muted-foreground italic"),children:m(s.name)}),e.jsxs("span",{className:"flex items-center gap-3 shrink-0",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:p(s.created_at)}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:t("iap.coins","{{coins}} coins",{coins:s.coins_spent.toLocaleString()})}),s.refunded?e.jsx("span",{className:"text-xs text-muted-foreground line-through tabular-nums",title:t("iap.refunded","Refunded"),children:l(s.creator_usd)}):e.jsx("span",{className:"text-xs text-foreground tabular-nums",children:l(s.creator_usd)}),s.refunded&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:t("iap.refunded","Refunded")})]})]},s.id))})]})]})}function u({label:a,value:t}){return e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold text-foreground tabular-nums",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a})]})}function W(){const{t:a}=h("settings"),t=Number(T().gameId),{data:c}=g({queryKey:["game-iap-revenue",t,30],queryFn:()=>f.getGameRevenue(t,30),enabled:Number.isFinite(t)}),n=c?.game_name||a("gameEarnings.title","Game earnings");return e.jsxs(I,{title:a("gameEarnings.pageTitle",{defaultValue:"{{game}} earnings | Tesana",game:n}),heading:n,subtitle:a("gameEarnings.subtitle","In-game purchases: what sold, and when."),children:[e.jsxs(k,{to:"/settings/earnings",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1.5 mb-6",children:[e.jsx(E,{icon:["far","arrow-left"],className:"text-[10px]"}),a("gameEarnings.back","Creator earnings")]}),Number.isFinite(t)&&e.jsx(C,{gameId:t})]})}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.