@kenz1117/dsh-ui-usage-billing 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -2,5 +2,5 @@ window.__ModuleLoader__.load({id:`@kenz1117/dsh-ui-usage-billing`,factory:e=>{va
2
2
  `)}function an(e){return[`site,kind,calls,cost_cny`,...Object.entries(e).map(([e,t])=>{let n=e.startsWith(`site:`)?e.slice(5):e.startsWith(`direct:`)?e.slice(7):`unknown`,r=e.startsWith(`site:`)?`site`:e.startsWith(`direct:`)?`direct`:`unknown`;return[en(tn(n)),r,t.calls,nn(t.cost)].join(`,`)})].join(`
3
3
  `)}function on(e){return e===void 0?``:e.split(/[\\/]/).filter(Boolean).pop()??e}function sn(e){return[`session_id,title,project,calls,cost_cny,last_active,parent_id,sub_calls,sub_cost_cny`,...e.map(e=>[en(tn(e.id)),en(tn(e.title??``)),en(tn(on(e.cwd))),e.calls,nn(e.cost),e.lastActive>0?new Date(e.lastActive).toISOString():``,e.parentId??``,e.subCalls??``,e.subCost===void 0?``:nn(e.subCost)].join(`,`))].join(`
4
4
  `)}function cn(e,t,n){let r=[...n].sort(),i=r[0],a=r.at(-1);return`${e}${i!==void 0&&a!==void 0?`-${i}_${a}`:``}.${t}`}function ln(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=document.createElement(`a`);i.href=r,i.download=e,i.click(),setTimeout(()=>URL.revokeObjectURL(r),0)}function un(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(Math.round(e))}let Y={top:14,right:18,bottom:22,left:46},dn=`var(--ds-blue)`,fn=`var(--ds-cyan)`,pn=`var(--ds-amber)`;function mn(e,t,n,r){return JSON.stringify({days:e,models:t,dayModels:n,total:r},null,2)}function hn(e){let{stats:t,trendDays:n,onTrendDays:r,t:i}=e,a=e.money,o=e.models??[],{byDay:s,byModel:c,total:l}=t,[u,f]=(0,d.useState)(null),[p,h]=(0,d.useState)(`structure`),[g,_]=(0,d.useState)(null),v=t.byDayModels!==void 0,b=e=>{h(e),_(null)},x=(0,d.useMemo)(()=>{let e=t.byRole;if(e===void 0)return[];let n=e.user+e.assistant+e.tool;return n<=0?[]:[{label:i(`roleUser`),value:e.user,seg:V.shareSegUser},{label:i(`roleAssistant`),value:e.assistant,seg:V.shareSegAssistant},{label:i(`roleTool`),value:e.tool,seg:V.shareSegTool}].map(e=>({...e,pct:e.value/n*100}))},[t.byRole,i]),S=(0,d.useMemo)(()=>{let e=[];for(let t=n-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t);let r=q(n.getTime()),i=s[r];e.push({date:r,miss:i?.cacheMiss??0,hit:i?.cacheHit??0,output:i?.output??0,reasoning:i?.reasoning??0})}return e},[s,n]),C=(0,d.useMemo)(()=>{let e=[];for(let r=n-1;r>=0;--r){let n=new Date;n.setDate(n.getDate()-r);let i=q(n.getTime()),a=t.byDayModels?.[i],o={},s=0;if(a!==void 0)for(let[e,t]of Object.entries(a)){let n=t.cacheHit??0,r=t.cacheMiss??0,i=t.output??0,a=n+r+i;a<=0||(o[e]={hit:n,miss:r,output:i,total:a},s+=a)}e.push({date:i,models:o,total:s})}return e},[t.byDayModels,n]),w=(0,d.useMemo)(()=>{let e=new Map;for(let t of C)for(let[n,r]of Object.entries(t.models))e.set(n,(e.get(n)??0)+r.total);return[...e.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>({key:e,name:o.find(t=>t.key===e)?.name??Ht(e).name,color:o.find(t=>t.key===e)?.color??`#8b95a3`}))},[C,o]),T=g!==null&&w.some(e=>e.key===g)?g:null,ee=e=>{if(v){if(p!==`model`){h(`model`),_(e);return}_(t=>t===e?null:e)}},E=(0,d.useMemo)(()=>{let e=0;return Object.entries(c).filter(([,e])=>e.calls>0).map(([t,n])=>{let r=n.input+n.output;e+=r;let i=n.cacheHit+n.cacheMiss;return{key:t,name:Ht(t).name,input:n.input,output:n.output,reasoning:n.reasoning??0,calls:n.calls,cacheHit:n.cacheHit,cacheMiss:n.cacheMiss,cacheHitRate:i>0?n.cacheHit/i*100:0,total:r,share:0}}).sort((e,t)=>t.total-e.total).map(t=>({...t,share:e>0?t.total/e:0}))},[c]),D=(0,d.useMemo)(()=>{let e=Object.entries(t.byTool??{}),n=e.slice(0,8),r=e.slice(8).reduce((e,[,t])=>e+t,0),i=e.reduce((e,[,t])=>e+t,0);return{top:n,rest:r>0?[[`…`,r]]:[],totalCalls:i}},[t.byTool]),O=(0,d.useMemo)(()=>{let e=S.length;if(e===0)return null;let t=680-Y.left-Y.right,n=200-Y.top-Y.bottom,r=Math.max(...p===`model`?C.map(e=>e.total):S.map(e=>e.miss+e.hit+e.output),1),i=e=>Y.top+n-e/r*n,a=t/e,o=Math.min(20,a*.6),s=n=>e===1?Y.left+t/2:Y.left+t*n/(e-1),c=Math.max(1,Math.ceil(e/8)),l=[];for(let t=0;t<e;t+=c)l.push(t);return e>0&&l[l.length-1]!==e-1&&l.push(e-1),{n:e,plotW:t,plotH:n,max:r,y:i,barW:o,inner:s,indices:l,groupW:a}},[S,C,p]),k=()=>{ln(`token-daily-${q()}.csv`,gn(S),`text/csv`)},te=()=>{ln(`token-${q()}.json`,mn(S,E,C,l),`application/json`)},A=u===null?void 0:S[u],j=u===null?void 0:C[u],ne=O===null?0:Math.ceil(80/Math.max(O.groupW,1)),re=u===null||O===null?void 0:u>=O.n-ne?V.chartTooltipAlignRight:u<ne?V.chartTooltipAlignLeft:void 0;return(0,m.jsxs)(`div`,{className:V.tokenPanel,"data-testid":`billing-token-panel`,children:[(0,m.jsxs)(`div`,{className:V.exportBar,role:`group`,"aria-label":i(`tokenExport`),children:[(0,m.jsx)(`span`,{className:V.exportLabel,children:i(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-token-export-csv`,onClick:k,children:i(`tokenExportCsv`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-token-export-json`,onClick:te,children:i(`exportJson`)})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-token-daily`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:i(`tokenDaily`)}),(0,m.jsxs)(`span`,{className:V.panelHeadControls,children:[v&&(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":i(`tokenDaily`),children:[`structure`,`model`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,p===e&&V.rangeButtonActive),"aria-pressed":p===e,onClick:()=>{b(e)},"data-testid":`billing-token-view-${e}`,children:i(e===`structure`?`tokenViewStructure`:`tokenViewModel`)},e))}),(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":i(`tokenDaily`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,n===e&&V.rangeButtonActive),"aria-pressed":n===e,onClick:()=>{r(e)},"data-testid":`billing-token-${e}d`,children:i(e===7?`trend7d`:`trend30d`)},e))})]})]}),O===null||p===`model`&&w.length===0?(0,m.jsx)(`div`,{className:V.chartEmpty,children:i(`trendEmpty`)}):(0,m.jsxs)(`div`,{className:V.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 200`,className:V.chartSvg,role:`img`,"aria-label":i(`tokenDaily`),onMouseLeave:()=>{f(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-Y.left)/O.plotW,r=Math.round(n*(O.n-1));f(Math.min(Math.max(r,0),O.n-1))},children:[[0,.5,1].map(e=>{let t=O.max*e,n=O.y(t);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:Y.left,x2:680-Y.right,y1:n,y2:n,className:V.chartGrid}),(0,m.jsx)(`text`,{x:Y.left-8,y:n+3,textAnchor:`end`,className:V.chartAxisLabel,children:un(t)})]},e)}),p===`structure`?S.map((e,t)=>{let n=O.inner(t)-O.barW/2,r=O.y(0),i=O.y(e.miss),a=O.y(e.miss+e.hit),o=O.y(e.miss+e.hit+e.output);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`rect`,{x:n,y:i,width:O.barW,height:r-i,fill:dn}),(0,m.jsx)(`rect`,{x:n,y:a,width:O.barW,height:i-a,fill:fn}),(0,m.jsx)(`rect`,{x:n,y:o,width:O.barW,height:a-o,fill:pn})]},e.date)}):C.map((e,t)=>{let n=O.inner(t)-O.barW/2,r=0;return(0,m.jsx)(`g`,{children:w.map(t=>{let i=e.models[t.key];if(i===void 0)return null;let a=O.y(r);r+=i.total;let o=O.y(r),s=T!==null&&t.key!==T;return(0,m.jsx)(`rect`,{x:n,y:o,width:O.barW,height:a-o,fill:t.color,opacity:s?.15:1},t.key)})},e.date)}),O.indices.map(e=>{let t=S[e];return t===void 0?null:(0,m.jsx)(`text`,{x:O.inner(e),y:194,textAnchor:`middle`,className:V.chartAxisLabel,children:t.date.slice(5)},t.date)}),u!==null&&(0,m.jsx)(`line`,{x1:O.inner(u),x2:O.inner(u),y1:Y.top,y2:Y.top+O.plotH,className:V.chartCrosshair})]}),u!==null&&p===`structure`&&A!==void 0&&(0,m.jsxs)(`div`,{className:y(V.chartTooltip,re),"data-testid":`billing-token-tooltip`,style:{left:`${O.inner(u)/680*100}%`,top:`${O.y(A.miss+A.hit+A.output)/200*100}%`},children:[(0,m.jsxs)(`div`,{className:V.chartTooltipHead,children:[(0,m.jsx)(`span`,{className:V.chartTooltipDate,children:A.date}),(0,m.jsx)(`strong`,{children:(A.miss+A.hit+A.output).toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(V.chartTooltipRow,V.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:V.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:fn}}),i(`tokenHit`)]}),(0,m.jsx)(`strong`,{children:A.hit.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(V.chartTooltipRow,V.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:V.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:dn}}),i(`tokenMiss`)]}),(0,m.jsx)(`strong`,{children:A.miss.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(V.chartTooltipRow,V.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:V.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:pn}}),i(`tokenOutput`)]}),(0,m.jsx)(`strong`,{children:A.output.toLocaleString()})]})]}),u!==null&&p===`model`&&j!==void 0&&(0,m.jsxs)(`div`,{className:y(V.chartTooltip,re),"data-testid":`billing-token-tooltip`,style:{left:`${O.inner(u)/680*100}%`,top:`${O.y(j.total)/200*100}%`},children:[(0,m.jsxs)(`div`,{className:V.chartTooltipHead,children:[(0,m.jsx)(`span`,{className:V.chartTooltipDate,children:j.date}),(0,m.jsx)(`strong`,{children:j.total.toLocaleString()})]}),w.map(e=>{let t=j.models[e.key];return t===void 0?null:(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:y(V.chartTooltipRow,V.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:V.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name]}),(0,m.jsx)(`strong`,{children:t.total.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:V.chartTooltipModelDetail,children:[i(`tokenHitShort`),` `,t.hit.toLocaleString(),` · `,i(`tokenMissShort`),` `,t.miss.toLocaleString(),` · `,i(`tokenOutput`),` `,t.output.toLocaleString()]})]},e.key)})]}),(0,m.jsx)(`div`,{className:V.chartLegend,children:p===`structure`?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:dn}}),i(`tokenMiss`)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:fn}}),i(`tokenHit`)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:pn}}),i(`tokenOutput`)]})]}):w.map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(V.chartLegendItem,T===e.key&&V.chartLegendItemActive),"aria-pressed":T===e.key,"data-testid":`billing-token-legend-${e.key}`,onClick:()=>{ee(e.key)},children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key))})]})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-token-models`,children:[(0,m.jsx)(`div`,{className:V.panelHead,children:(0,m.jsx)(`h3`,{className:V.panelTitle,children:i(`tokenByModel`)})}),E.length===0?(0,m.jsx)(`div`,{className:V.emptyRow,children:i(`noData`)}):(0,m.jsx)(`div`,{className:V.tableScroll,children:(0,m.jsxs)(`table`,{className:V.modelTable,"data-testid":`billing-token-model-table`,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:i(`model`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`inputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`outputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`tokenReasoningShort`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`tokenTotal`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`tokenShare`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`calls`)})]})}),(0,m.jsx)(`tbody`,{children:E.map(e=>(0,m.jsxs)(`tr`,{"data-testid":`billing-token-model`,className:y(v&&V.modelRowFocusable,T===e.key&&V.modelRowActive),"aria-selected":v?T===e.key:void 0,onClick:v?()=>{ee(e.key)}:void 0,tabIndex:v?0:void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),ee(e.key))}:void 0,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:V.modelName,children:e.name})}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.input)}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.output)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.reasoning>0?J(e.reasoning):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsxs)(`td`,{className:V.numCol,children:[e.cacheHitRate.toFixed(1),`%`]}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.total)}),(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsxs)(`span`,{className:V.tokenModelShareRow,children:[(0,m.jsx)(`span`,{className:V.tokenModelBar,children:(0,m.jsxs)(`span`,{className:V.tokenModelParts,style:{width:`${(e.share*100).toFixed(2)}%`},children:[(0,m.jsx)(`span`,{className:V.tokenModelPartIn,style:{width:`${e.total>0?e.input/e.total*100:0}%`}}),(0,m.jsx)(`span`,{className:V.tokenModelPartOut,style:{width:`${e.total>0?e.output/e.total*100:0}%`}})]})}),(e.share*100).toFixed(1),`%`]})}),(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()})]},e.key))})]})})]}),D.totalCalls>0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-token-tools`,children:[(0,m.jsx)(`div`,{className:V.panelHead,children:(0,m.jsx)(`h3`,{className:V.panelTitle,children:i(`toolRank`)})}),(0,m.jsx)(`div`,{className:V.tableScroll,children:(0,m.jsxs)(`table`,{className:V.modelTable,"data-testid":`billing-tool-table`,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:i(`toolName`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:i(`tokenShare`)})]})}),(0,m.jsx)(`tbody`,{children:[...D.top,...D.rest].map(([e,t])=>(0,m.jsxs)(`tr`,{"data-testid":`billing-tool-row`,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:V.modelName,children:e})}),(0,m.jsx)(`td`,{className:V.numCol,children:t.toLocaleString()}),(0,m.jsxs)(`td`,{className:V.numCol,children:[(t/D.totalCalls*100).toFixed(1),`%`]})]},e))})]})})]}),x.length>0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-roles`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:i(`roleCost`)}),(0,m.jsx)(`span`,{className:V.panelHint,children:i(`roleHint`)})]}),(0,m.jsx)(`div`,{className:V.shareTrack,"data-testid":`billing-role-track`,children:x.map(e=>(0,m.jsx)(`div`,{className:y(V.shareSeg,e.seg),style:{width:`${e.pct}%`}},e.label))}),(0,m.jsx)(`div`,{className:V.shareLegend,children:x.map(e=>(0,m.jsxs)(`span`,{className:V.shareItem,children:[(0,m.jsx)(`span`,{className:y(V.shareDot,e.seg)}),e.label,(0,m.jsxs)(`span`,{className:V.shareValue,children:[a(e.value),` · `,e.pct.toFixed(1),`%`]})]},e.label))})]})]})}function gn(e){return[`date,missInput,cacheHit,output,reasoning,total`,...e.map(e=>`${e.date},${e.miss},${e.hit},${e.output},${e.reasoning},${e.miss+e.hit+e.output}`)].join(`
5
- `)}function _n(){let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}let X={top:18,right:40,bottom:26,left:46};function vn(e){let[,t,n]=e.split(`-`);return`${Number(t)}/${Number(n)}`}function yn(e,t){let n=[];for(let r=0;r<e;r+=t)n.push(r);return e>0&&n[n.length-1]!==e-1&&n.push(e-1),n}let bn={key:`__total__`,name:``,color:``};function xn({data:e,models:t=[],currency:n=`cny`,metric:r=`cost`,t:i}){let a=i??(e=>ze[e]),[o,s]=(0,d.useState)(null),c=e=>K(Xt(e,n),n),l=e=>r===`tokens`?un(e):c(e),u=e=>r===`tokens`?e.tokens??0:e.cost,f=(0,d.useMemo)(()=>{let n=e.length;if(n===0)return null;let i=680-X.left-X.right,a=220-X.top-X.bottom,o=e=>n===1?X.left+i/2:X.left+i*e/(n-1),s=Math.max(...r===`tokens`?e.map(e=>e.tokens??0):e.map(e=>Math.max(e.cost,Object.values(e.byModel??{}).reduce((e,t)=>e+t,0))),1e-4),c=e=>X.top+a-e/s*a,l=Math.max(...e.map(e=>e.calls),1),d=e=>X.top+a-e/l*a,f=i/n,p=Math.min(18,f*.6);return{n,plotW:i,plotH:a,inner:o,yCost:c,yCalls:d,barW:p,bars:e.flatMap((e,n)=>{let i=o(n)-p/2;if(t.length===0||r===`tokens`)return[{date:e.date,model:bn,x:i,base:0,value:u(e),topRounded:!0}];let a=null;for(let n of t)(e.byModel?.[n.key]??0)>0&&(a=n.key);let s=0;return t.map(t=>{let n=e.byModel?.[t.key]??0,r={date:e.date,model:t,x:i,base:s,value:n,topRounded:t.key===a};return s+=n,r})}),costTicks:[0,.25,.5,.75,1].map(e=>s*e).reverse(),callsTicks:[0,.25,.5,.75,1].map(e=>l*e).reverse(),linePath:e.map((e,t)=>{let n=d(e.calls);return`${t===0?`M`:`L`}${o(t)} ${n}`}).join(` `)}},[e,t,r]);if(f===null)return(0,m.jsx)(`div`,{className:V.chartEmpty,children:a(`trendEmpty`)});let{n:p,plotW:h,plotH:g,inner:_,yCost:v,yCalls:y,barW:b,bars:x,costTicks:S,callsTicks:C,linePath:w}=f,T=o===null?void 0:e[o],ee=yn(p,Math.max(1,Math.ceil(p/8)));return(0,m.jsxs)(`div`,{className:V.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 220`,className:V.chartSvg,role:`img`,"aria-label":`Daily cost by model and total calls`,onMouseLeave:()=>{s(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-X.left)/h,r=Math.round(n*(p-1));s(Math.min(Math.max(r,0),p-1))},children:[S.map((e,t)=>{let n=v(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:X.left,x2:680-X.right,y1:n,y2:n,className:V.chartGrid}),(0,m.jsx)(`text`,{x:X.left-8,y:n+3,textAnchor:`end`,className:V.chartAxisLabel,children:l(e)})]},`cost-${t}`)}),x.map(t=>{if(t.value>0)return(0,m.jsx)(`rect`,{x:t.x,y:v(t.base+t.value),width:b,height:v(t.base)-v(t.base+t.value),rx:t.topRounded?2:0,className:t.model.color===``?V.chartBar:V.chartStack,style:t.model.color===``?void 0:{fill:t.model.color}},`${t.date}-${t.model.key}`);let n=e.find(e=>e.date===t.date);return n!==void 0&&n.calls>0&&t.base===0?(0,m.jsx)(`rect`,{x:t.x,y:v(0)-1,width:b,height:1,rx:0,className:V.chartBarPlaceholder},`${t.date}-${t.model.key}-placeholder`):null}),(0,m.jsx)(`path`,{d:w,fill:`none`,className:V.chartLine}),(()=>{let t=_n(),n=e.findIndex(e=>e.date===t);return n>=0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`chartAreaGrad`,x1:`0%`,y1:`0%`,x2:`0%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-blue)`,stopOpacity:`0.35`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-blue)`,stopOpacity:`0`})]})}),(0,m.jsx)(`path`,{d:`${w} L ${_(e.length-1)} ${y(0)} L ${_(0)} ${y(0)} Z`,fill:`url(#chartAreaGrad)`}),(0,m.jsx)(`line`,{x1:_(n),x2:_(n),y1:X.top,y2:X.top+g,stroke:`var(--ds-amber)`,strokeWidth:`1`,strokeDasharray:`3 3`,opacity:`0.6`}),(0,m.jsx)(`text`,{x:_(n)+4,y:X.top-6,fill:`var(--ds-amber)`,fontSize:`10`,fontFamily:`var(--font-num)`,children:vn(t)})]}):null})(),C.map((e,t)=>{let n=y(e);return(0,m.jsx)(`text`,{x:680-X.right+8,y:n+3,textAnchor:`start`,className:V.chartAxisLabel,children:un(e)},`calls-${t}`)}),ee.map(t=>{let n=e[t];return n===void 0?null:(0,m.jsx)(`text`,{x:_(t),y:214,textAnchor:`middle`,className:V.chartAxisLabel,children:vn(n.date)},n.date)}),o!==null&&(0,m.jsx)(`line`,{x1:_(o),x2:_(o),y1:X.top,y2:X.top+g,className:V.chartCrosshair})]}),T!==void 0&&o!==null&&(0,m.jsxs)(`div`,{className:V.chartTooltip,style:{left:`${_(o)/680*100}%`,top:`${v(T.cost)/220*100}%`},children:[(0,m.jsx)(`div`,{className:V.chartTooltipDate,children:T.date}),r!==`tokens`&&t.filter(e=>(T.byModel?.[e.key]??0)>0).map(e=>(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:c(T.byModel?.[e.key]??0)})]},e.key)),(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartLegendBar}),a(`trendTotal`),` `,(0,m.jsx)(`strong`,{children:r===`tokens`?un(T.tokens??0):c(T.cost)})]}),(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartLegendLine}),a(`calls`),` `,(0,m.jsx)(`strong`,{children:T.calls.toLocaleString()})]})]}),t.length>0&&r!==`tokens`&&(0,m.jsxs)(`div`,{className:V.chartLegend,children:[t.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key)),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartLegendLine}),a(`calls`)]})]})]})}let Z={top:14,right:42,bottom:22,left:46};function Sn(e){return e.slice(5,13).replace(`T`,` `)}function Cn(e){return String(e>=100?Math.round(e):Number(e.toFixed(1)))}function wn(e){return e<1e4?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${(e/6e4).toFixed(1)} min`}function Tn(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toFixed(1)}function En(e,t,n){return t===`ttft`?`${Math.round(e)} ms`:`${e.toFixed(1)} ${n(`perfTpsUnit`)}`}function Dn({perf:e,models:t,t:n}){let[r,i]=(0,d.useState)(()=>Oe()),[a,o]=(0,d.useState)(null),s=e=>{i(e),ke(e)},c=e=>t.find(t=>t.key===e)?.color??`#8b95a3`,l=(0,d.useMemo)(()=>e===void 0?[]:Object.entries(e.byModel).map(([e,n])=>({key:e,name:t.find(t=>t.key===e)?.name??e,color:c(e),samples:n.samples,ttftAvg:n.ttftAvg,ttftP50:n.ttftP50,ttftP90:n.ttftP90,...n.ttftMax===void 0?{}:{ttftMax:n.ttftMax},...n.ttftSpikes===void 0?{}:{ttftSpikes:n.ttftSpikes},...n.tpsAvg===void 0?{}:{tpsAvg:n.tpsAvg},latencyAvg:n.latencyAvg,estimatedSamples:n.estimatedSamples})).sort((e,t)=>t.samples-e.samples||t.ttftP90-e.ttftP90),[e,t]),u=(0,d.useMemo)(()=>{if(e===void 0)return[];if(r.models!==void 0){let t=new Set(Object.keys(e.byModel));return r.models.filter(e=>t.has(e))}return l.slice(0,5).map(e=>e.key)},[e,l,r.models]),f=(0,d.useMemo)(()=>{if(e===void 0)return null;let t=Object.keys(e.byHourModel).sort().slice(-48);if(t.length===0)return null;let n=t.length,i=680-Z.left-Z.right,a=180-Z.top-Z.bottom,o=e=>n===1?Z.left+i/2:Z.left+i*e/(n-1),s=new Set(u),c=e=>r.metric===`ttft`?e?.ttftAvg:e?.tpsAvg,d=[],f=0;for(let r of l){if(!s.has(r.key))continue;let i=[];for(let a=0;a<n;a++){let n=t[a];if(n===void 0)continue;let s=c(e.byHourModel[n]?.[r.key]);s===void 0||!Number.isFinite(s)||(i.push({i:a,x:o(a),y:0,v:s}),s>f&&(f=s))}d.push({key:r.key,name:r.name,color:r.color,segments:[],points:i})}let p=d.reduce((e,t)=>e+t.points.length,0);f=Math.max(f,1);let m=e=>Z.top+a-e/f*a;for(let e of d){let t=``,n=-2;for(let r of e.points)r.y=m(r.v),t!==``&&r.i!==n+1&&(e.segments.push(t),t=``),t+=`${t===``?`M`:`L`}${r.x} ${r.y} `,n=r.i;t!==``&&e.segments.push(t)}let h=Math.max(1,Math.ceil(n/8)),g=[];for(let e=0;e<n;e+=h)g.push(e);return g[g.length-1]!==n-1&&g.push(n-1),{hourKeys:t,n,plotW:i,plotH:a,inner:o,yOf:m,series:d,ticks:[0,.5,1].map(e=>f*e).reverse(),xTicks:g,totalPoints:p}},[e,l,u,r.metric]);if(e===void 0||l.length===0)return(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-empty`,children:n(`perfEmpty`)});let p=e=>{let t=u.includes(e)?u.filter(t=>t!==e):[...u,e];s({metric:r.metric,models:t})},h=e=>{s({metric:e,...r.models===void 0?{}:{models:r.models}})},g=a===null||f===null?[]:f.series.flatMap(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?[]:[{key:e.key,name:e.name,color:e.color,v:t.v}]});return(0,m.jsxs)(`div`,{"data-testid":`billing-perf-panel`,children:[l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftAvg),1),t=Math.max(...l.filter(e=>e.tpsAvg!==void 0).map(e=>e.tpsAvg??0),1),r=Math.max(...l.map(e=>e.latencyAvg),1),i=l.reduce((e,t)=>e+t.samples,0),a=l.length>0?l.reduce((e,t)=>e+t.ttftAvg,0)/l.length:0,o=l.map(e=>e.tpsAvg).filter(e=>e!==void 0),s=o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0,c=l.length>0?l.reduce((e,t)=>e+t.latencyAvg,0)/l.length:0,u=[{lbl:n(`perfSamples`),val:i.toLocaleString(),unit:``,pct:65,color:`var(--ds-blue)`},{lbl:n(`perfTtft`),val:wn(a),unit:``,pct:a/e*100,color:`var(--ds-green)`},{lbl:n(`perfTps`),val:o.length>0?Tn(s):`—`,unit:``,pct:s/t*100,color:`var(--ds-blue)`},{lbl:n(`perfLatency`),val:wn(c),unit:``,pct:c/r*100,color:`var(--ds-amber)`}];return(0,m.jsx)(`div`,{className:V.perfHero,"data-testid":`billing-perf-hero`,children:u.map((e,t)=>(0,m.jsxs)(`div`,{className:V.perfHeroCell,children:[(0,m.jsx)(`div`,{className:V.perfHeroLbl,children:e.lbl}),(0,m.jsxs)(`div`,{className:V.perfHeroVal,children:[e.val,e.unit!==``&&(0,m.jsx)(`span`,{className:V.perfHeroUnit,children:e.unit})]}),(0,m.jsx)(`div`,{className:V.perfHeroBar,children:(0,m.jsx)(`i`,{style:{width:`${Math.min(100,e.pct)}%`,background:e.color}})})]},t))})})(),(0,m.jsx)(`div`,{className:V.tableScroll,"data-testid":`billing-perf-table`,children:(0,m.jsxs)(`table`,{className:V.modelTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:n(`model`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfSamples`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfTtft`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfP50`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfP90`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfMax`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfTps`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfLatency`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfEstimated`)})]})}),(0,m.jsx)(`tbody`,{children:l.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:V.modelCell,children:[(0,m.jsx)(`span`,{className:V.modelDot,style:{background:e.color}}),(0,m.jsx)(`span`,{className:V.modelName,children:e.name})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:e.samples.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftP50)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftP90)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.ttftMax===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):(0,m.jsxs)(`span`,{children:[wn(e.ttftMax),e.ttftSpikes!==void 0&&e.ttftSpikes>0?` (${e.ttftSpikes}↑)`:``]})}),(0,m.jsx)(`td`,{className:V.numCol,children:e.tpsAvg===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Tn(e.tpsAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.latencyAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.estimatedSamples>0?e.estimatedSamples:(0,m.jsx)(`span`,{className:V.na,children:`—`})})]},e.key))})]})}),l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftP50),1),t=e=>e<.8?`var(--ds-green)`:e<2?`var(--ds-amber)`:`var(--ds-red)`;return(0,m.jsx)(`div`,{className:V.perfCompareList,"data-testid":`billing-perf-compare`,children:l.map(n=>(0,m.jsxs)(`div`,{className:V.perfCompareRow,children:[(0,m.jsxs)(`div`,{className:V.perfCompareName,children:[(0,m.jsx)(`span`,{className:V.perfCompareDot,style:{background:n.color}}),(0,m.jsx)(`span`,{children:n.name})]}),(0,m.jsx)(`div`,{className:V.perfCompareBar,children:(0,m.jsx)(`i`,{style:{width:`${n.ttftP50/e*100}%`,background:t(n.ttftP50)}})}),(0,m.jsx)(`div`,{className:V.perfCompareNum,children:wn(n.ttftP50)}),(0,m.jsx)(`div`,{className:V.perfCompareNum,children:n.tpsAvg===void 0?`—`:Tn(n.tpsAvg)})]},n.key))})})(),f!==null&&(0,m.jsxs)(`div`,{"data-testid":`billing-perf-hour`,children:[(0,m.jsx)(`div`,{className:V.perfBar,children:(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":n(`perfTitle`),children:[`ttft`,`tps`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,r.metric===e&&V.rangeButtonActive),"aria-pressed":r.metric===e,"data-testid":`billing-perf-tab-${e}`,onClick:()=>{h(e)},children:e===`ttft`?`${n(`perfTtft`)} (ms)`:`${n(`perfTps`)} (${n(`perfTpsUnit`)})`},e))})}),(0,m.jsxs)(`div`,{className:V.perfChips,role:`group`,"aria-label":n(`model`),children:[(0,m.jsx)(`button`,{type:`button`,className:V.perfChip,"data-testid":`billing-perf-chip-all`,onClick:()=>{s({metric:r.metric,models:l.map(e=>e.key)})},children:n(`perfAll`)}),l.map(e=>{let t=u.includes(e.key);return(0,m.jsxs)(`button`,{type:`button`,className:y(V.perfChip,!t&&V.perfChipOff),style:t?{color:e.color,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}:void 0,"aria-pressed":t,"data-testid":`billing-perf-chip-${e.key}`,onClick:()=>{p(e.key)},children:[(0,m.jsx)(`span`,{className:V.perfChipDot,style:{background:t?e.color:`var(--dsw-alias-label-dimmed)`}}),e.name]},e.key)})]}),f.totalPoints>0?(0,m.jsxs)(`div`,{className:V.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 180`,className:V.chartSvg,role:`img`,"aria-label":`Hourly perf comparison by model`,onMouseLeave:()=>{o(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-Z.left)/f.plotW,r=Math.round(n*(f.n-1));o(Math.min(Math.max(r,0),f.n-1))},children:[f.ticks.map((e,t)=>{let n=f.yOf(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:Z.left,x2:680-Z.right,y1:n,y2:n,className:V.chartGrid}),(0,m.jsx)(`text`,{x:Z.left-8,y:n+3,textAnchor:`end`,className:V.chartAxisLabel,children:Cn(e)})]},`tick-${t}`)}),f.series.map(e=>e.segments.map((t,n)=>(0,m.jsx)(`path`,{d:t,fill:`none`,className:V.chartLine,style:{stroke:e.color}},`${e.key}-${n}`))),f.xTicks.map(e=>{let t=f.hourKeys[e];return t===void 0?null:(0,m.jsx)(`text`,{x:f.inner(e),y:174,textAnchor:`middle`,className:V.chartAxisLabel,children:Sn(t)},t)}),a!==null&&(0,m.jsx)(`line`,{x1:f.inner(a),x2:f.inner(a),y1:Z.top,y2:Z.top+f.plotH,className:V.chartCrosshair}),a!==null&&f.series.map(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?null:(0,m.jsx)(`circle`,{cx:t.x,cy:t.y,r:3.5,fill:e.color,className:V.chartHoverDot},`${e.key}-dot`)})]}),a!==null&&g.length>0&&(0,m.jsxs)(`div`,{className:V.chartTooltip,"data-testid":`billing-perf-tooltip`,style:{left:`${f.inner(a)/680*100}%`,top:`${(Z.top+f.plotH/2)/180*100}%`},children:[(0,m.jsx)(`div`,{className:V.chartTooltipDate,children:Sn(f.hourKeys[a]??``)}),g.map(e=>(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:En(e.v,r.metric,n)})]},e.key))]})]}):(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]}),f===null&&(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]})}let Q=`@kenz1117/dsh-ui-usage-billing`,On=`kenz1117`;function kn({t:e,version:t}){return(0,m.jsxs)(`section`,{className:V.setCard,"data-testid":`billing-plugin-info`,children:[(0,m.jsxs)(`div`,{className:V.plgHead,children:[(0,m.jsx)(`span`,{className:V.plgIcon,"aria-hidden":`true`,children:(0,m.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,m.jsx)(`path`,{d:`M10 3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a2 2 0 0 0 4 0V4a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1v1a2 2 0 0 0 4 0 1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0 0 4h1a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1v-1a2 2 0 0 0-4 0 1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 0-4H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 4 0z`})})}),(0,m.jsxs)(`div`,{className:V.plgTitle,children:[(0,m.jsxs)(`div`,{className:V.plgNameRow,children:[(0,m.jsx)(`h3`,{className:V.plgName,children:Q}),(0,m.jsx)(`span`,{className:V.plgTag,children:t===void 0?`—`:`v${t}`})]}),(0,m.jsx)(`p`,{className:V.plgDesc,children:`Usage billing dashboard for DeepSeek Harness`})]})]}),(0,m.jsxs)(`div`,{className:V.plgGrid,children:[(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginAuthor`)}),(0,m.jsxs)(`a`,{className:V.plgLink,href:`https://github.com/${On}`,target:`_blank`,rel:`noreferrer`,children:[`KenZ`,` (`,On,`)`]})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginRepository`)}),(0,m.jsx)(`a`,{className:V.plgLink,href:`https://github.com/kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:`GitHub`})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginNpm`)}),(0,m.jsx)(`a`,{className:V.plgLink,href:`https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:Q})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginLicense`)}),(0,m.jsx)(`span`,{className:V.plgVal,children:`MIT`})]})]})]})}function An(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function jn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Mn(e){let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${String(t%60).padStart(2,`0`)}s`}function Nn({rounds:e,flags:t,currency:n,t:r}){let i=(0,d.useMemo)(()=>e.slice(-40),[e]),a=(0,d.useMemo)(()=>new Set(t.map(e=>`${e.sessionId}:${e.turn}`)),[t]),o=(0,d.useMemo)(()=>Math.max(1e-4,...i.map(e=>e.cost)),[i]);if(i.length===0)return(0,m.jsxs)(`div`,{className:V.roundsEmpty,children:[r(`model`),` —`]});let s=e=>K(Xt(e,n),n);return(0,m.jsxs)(`div`,{className:V.rounds,children:[(0,m.jsx)(`div`,{className:V.roundsBars,role:`img`,"aria-label":`cost per turn`,children:i.map(e=>{let t=a.has(`${e.sessionId}:${e.turn}`),n=Math.max(1,e.cost/o*100),i=xt(e.model,!1)===`deepseek-metered`&&ft(e.startedAt)===`peak`;return(0,m.jsxs)(`div`,{className:y(V.roundsBarCol,i?V.roundsBarColPeak:V.roundsBarColOff),children:[(0,m.jsx)(`span`,{className:V.roundsBarLabel,style:{bottom:`${n}%`},children:s(e.cost)}),(0,m.jsx)(`div`,{className:V.roundsBarWrap,children:(0,m.jsx)(`div`,{className:t?V.roundsBarFlagged:V.roundsBar,style:{height:`${n}%`},"data-testid":`round-bar`,title:`${r(`model`)} ${e.model} · ${s(e.cost)} · ${jn(e.startedAt)}${e.endedAt===void 0?``:` → ${An(e.endedAt)} (${Mn(e.endedAt-e.startedAt)})`}`,children:t&&(0,m.jsx)(`span`,{className:V.roundsFlagMark,"aria-hidden":`true`})})})]},`${e.sessionId}:${e.turn}`)})}),(0,m.jsxs)(`div`,{className:V.roundsAxis,children:[(0,m.jsxs)(`span`,{children:[r(`costAbbr`),` `,s(o)]}),(0,m.jsxs)(`span`,{children:[i.length,` `,r(`roundsUnit`)]})]})]})}let Pn=[`color-mix(in srgb, var(--dsb-3) 70%, transparent)`,`color-mix(in srgb, var(--ds-cyan) 30%, var(--dsb-3))`,`color-mix(in srgb, var(--ds-blue) 60%, var(--dsb-3))`,`var(--ds-blue)`,`var(--ds-amber)`],Fn=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],In=e=>q(e.getTime());function Ln(e,t){let n=new Map;for(let t of e)n.set(t.date,t.value);let r=0;for(let e of n.values())e>r&&(r=e);let i=t.getFullYear(),a=t.getMonth(),o=t.getDate(),s=new Date(i,a+1,0).getDate(),c=new Date(i,a,1).getDay(),l=c+s,u=Math.ceil(l/7),d=[];for(let e=0;e<u;e+=1){let t=[];for(let l=0;l<7;l+=1){let u=e*7+l-c+1;if(u<1){let e=new Date(i,a,u);t.push({date:In(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}if(u>s){let e=new Date(i,a+1,u-s);t.push({date:In(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}let d=new Date(i,a,u),f=In(d),p=n.get(f)??0,m=0;if(p>0&&r>0){let e=Math.ceil(p/r*4);m=Math.min(4,Math.max(1,e))}let h=u>o;t.push({date:f,dayNum:u,value:h?0:p,level:h?0:m,placeholder:h})}d.push(t)}return d}function Rn(e,t,n=52){let r=new Map;for(let t of e)r.set(t.date,t.value);let i=0;for(let e of r.values())e>i&&(i=e);let a=In(t),o=new Date(t);o.setHours(0,0,0,0),o.setDate(o.getDate()-o.getDay());let s=new Date(o);s.setDate(o.getDate()-(n-1)*7);let c=[];for(let e=0;e<n;e+=1){let t=[];for(let n=0;n<7;n+=1){let o=new Date(s);o.setDate(s.getDate()+e*7+n);let c=In(o),l=c>a,u=l?0:r.get(c)??0,d=0;if(!l&&u>0&&i>0){let e=Math.ceil(u/i*4);d=Math.min(4,Math.max(1,e))}t.push({date:c,dayNum:o.getDate(),value:u,level:d,placeholder:l})}c.push(t)}return c}function zn({days:e,currency:t,now:n,t:r,range:i=`month`,unit:a=`cost`}){let[o,s]=(0,d.useState)(null),c=e=>K(Xt(e,t),t),l=e=>a===`tokens`?J(e):c(e),u=(0,d.useMemo)(()=>Ln(e,n??new Date),[e,n]),f=In(n??new Date);if(i!==`month`){let t=Rn(e,n??new Date,i===`half`?26:52),a=[],o=-1;return t.forEach((e,t)=>{let n=Number(e[0]?.date.slice(5,7)??0);n!==o&&(a.push({index:t,label:Fn[n-1]??``}),o=n)}),(0,m.jsxs)(`div`,{className:V.heatmapYear+(i===`half`?` `+V.heatmapHalf:``),"data-testid":i===`half`?`heatmap-half`:`heatmap-year`,children:[(0,m.jsxs)(`div`,{className:V.heatmapYearBody,children:[(0,m.jsx)(`div`,{className:V.heatmapYearWeekdays,"aria-hidden":`true`,children:[{label:`Mon`,row:1},{label:`Wed`,row:3},{label:`Fri`,row:5}].map(e=>(0,m.jsx)(`span`,{className:V.heatmapYearWeekday,style:{gridRow:e.row},children:e.label},e.label))}),(0,m.jsxs)(`div`,{className:V.heatmapYearScroll,children:[(0,m.jsx)(`div`,{className:V.heatmapYearMonths,"aria-hidden":`true`,"data-testid":`heatmap-year-months`,children:a.map(e=>(0,m.jsx)(`span`,{className:V.heatmapYearMonth,style:{gridColumn:e.index+1},children:e.label},e.index))}),(0,m.jsx)(`div`,{className:V.heatmapYearGrid,role:`img`,"aria-label":`yearly cost heatmap`,"data-testid":`heatmap-year-grid`,children:t.flat().map(e=>(0,m.jsx)(`button`,{type:`button`,className:V.heatmapYearCell,"data-testid":`heatmap-year-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Pn[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,tabIndex:-1},e.date))})]})]}),(0,m.jsxs)(`div`,{className:V.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:V.heatmapLegend,children:Pn.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)})]})]})}return(0,m.jsxs)(`div`,{className:V.heatmap,children:[(0,m.jsx)(`div`,{className:V.heatmapGrid,role:`img`,"aria-label":`daily cost heatmap`,children:u.map(e=>e.map(e=>e.placeholder?(0,m.jsx)(`div`,{className:V.heatmapCellEmpty,children:e.dayNum},e.date):(0,m.jsx)(`button`,{type:`button`,className:V.heatmapCell,"data-testid":`heatmap-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Pn[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,onMouseEnter:()=>{s(e)},onMouseLeave:()=>{s(null)},onFocus:()=>{s(e)},onBlur:()=>{s(null)},children:e.dayNum},e.date)))}),(0,m.jsxs)(`div`,{className:V.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:V.heatmapLegend,children:Pn.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)}),o!==null&&(0,m.jsxs)(`span`,{className:V.heatmapHover,"data-testid":`heatmap-hover`,children:[o.date,` · `,l(o.value)]})]})]})}let Bn={window:6,threshold:2,reasonFactor:1.8,reasonHitDropPp:15};function Vn(e){if(e.length===0)return null;let t=0;for(let n of e)t+=n;return t/e.length}function Hn(e){let t=e.cacheHit+e.cacheMiss;return t<=0?null:e.cacheHit/t*100}function Un(e,t){let n=t?.window??Bn.window,r=t?.threshold??Bn.threshold,i=t?.reasonFactor??Bn.reasonFactor,a=t?.reasonHitDropPp??Bn.reasonHitDropPp,o=[];if(n<=0||r<=0)return o;let s=[],c=[],l=[],u=[];for(let t of e){if(t.cost<=0)continue;let e=t.output,d=t.input,f=Hn(t),p=Vn(s),m=[];if(p!==null&&p>0&&t.cost>p*r){let n=Vn(c),r=Vn(l),s=Vn(u);n!==null&&n>0&&e>n*i&&m.push(`output-growth`),r!==null&&r>0&&d>r*i&&m.push(`context-bloat`),s!==null&&f!==null&&f<s-a&&m.push(`cache-hit-drop`),o.push({sessionId:t.sessionId,turn:t.turn,cost:t.cost,reasons:m})}for(s.push(t.cost),c.push(e),l.push(d),f!==null&&u.push(f);s.length>n;)s.shift();for(;c.length>n;)c.shift();for(;l.length>n;)l.shift();for(;u.length>n;)u.shift()}return o}function Wn(e,t){return e==null?null:Number.isFinite(e.nextSwitchInMs)&&e.nextSwitchInMs<=t?`soon`:e.tier===`peak`?`peak`:`offPeak`}let Gn={显式缓存创建:`Explicit cache write`,显式缓存命中:`Explicit cache hit`,长期半价:`Half price`,与标准价一致:`Same as standard`,"限时 5 折":`Limited-time 50% off`};function Kn(e,t){return e===void 0||t!==`en`?e:Gn[e]??e}function qn(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.key.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n)||(e.provider??``).toLowerCase().includes(n))}let Jn={"智谱 AI":`Zhipu AI`,阿里通义:`Alibaba Qwen`,字节豆包:`ByteDance Doubao`,月之暗面:`Moonshot AI`,小米:`Xiaomi`,百度文心:`Baidu ERNIE`,腾讯混元:`Tencent Hunyuan`,零一万物:`01.AI`,阶跃星辰:`StepFun`,科大讯飞:`iFlytek Spark`,商汤:`SenseNova`,百川智能:`Baichuan`,"小米 Token Plan(海外)":`Xiaomi Token Plan (Global)`,"小米 Token Plan(国内)":`Xiaomi Token Plan (CN)`,"小米 Token Plan(新加坡)":`Xiaomi Token Plan (SG)`,"火山引擎 Token Plan":`Volcengine Token Plan`,"火山方舟 Token Plan":`Volcengine Ark Token Plan`,"豆包 Token Plan":`Doubao Token Plan`,"百度文心 Plan":`Baidu ERNIE Plan`,"MiniMax Token Plan(国内)":`MiniMax Token Plan (CN)`};function Yn(e,t){return t===`en`?Jn[e]??e:e}let Xn={workbuddy:`WorkBuddy`,"workbuddy-ai":`WorkBuddy AI`},Zn={"https://tokenhub.tencentmaas.com":`腾讯云 TokenHub`,"https://api.lkeap.cloud.tencent.com":`腾讯云 Token Plan`,"https://api.deepseek.com":`DeepSeek 官方`},Qn={"腾讯云 TokenHub":`Tencent Cloud TokenHub`,"腾讯云 Token Plan":`Tencent Cloud Token Plan`,"DeepSeek 官方":`DeepSeek Official`};function $n(e){try{return new URL(e).host}catch{return e}}function er(e,t=`zh`){if(e.startsWith(`site:`)){let n=e.slice(5),r=Zn[n];return r===void 0?$n(n):t===`en`?Qn[r]??r:r}if(e.startsWith(`direct:`)){let n=e.slice(7);if(/^deepseek(?:-[a-z0-9-]+)?$/i.test(n))return t===`en`?`DeepSeek Official`:`DeepSeek 官方`;let r=Xn[n.trim().toLowerCase()];return r===void 0?`${t===`en`?`Direct`:`直连`} · ${n}`:`${t===`en`?`Direct`:`直连`} · ${r}`}}let tr=[`直连 · `,`Direct · `];function nr(e){for(let t of tr)if(e.startsWith(t))return e.slice(t.length)}let rr=`dsh-billing-peak-alert-v1`,ir={enabled:!1,leadMin:2,position:`bottom-right`,webNotify:!0,mode:`both`};function ar(){try{let e=localStorage.getItem(rr);if(e===null)return{...ir};let t=JSON.parse(e),n=t.mode===`peak`||t.mode===`offPeak`?t.mode:ir.mode,r=t.position===`center`?`center`:`bottom-right`;return{enabled:t.enabled===!0,leadMin:typeof t.leadMin==`number`&&Number.isFinite(t.leadMin)?Math.min(30,Math.max(1,Math.round(t.leadMin))):ir.leadMin,position:r,webNotify:t.webNotify!==!1,mode:n}}catch{return{...ir}}}function or(e){try{localStorage.setItem(rr,JSON.stringify(e))}catch{x(`peak-config-storage-unavailable`)}}function sr(e,t,n,r){if(!t.enabled)return null;let i=Ct(e,r,t.leadMin*6e4);return i===null||t.mode===`peak`&&i.entering!==`peak`||t.mode===`offPeak`&&i.entering!==`offPeak`||i.atMs===n?null:{...i,channel:r}}function cr({hit:e,config:t,t:n,onDismiss:r}){let[i,a]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(e)},[]),(0,d.useEffect)(()=>{i>=e.atMs&&r()},[i,e.atMs,r]),i>=e.atMs)return null;let o=Math.max(1,Math.round((e.atMs-i)/6e4)),s=e.entering,c=n(s===`peak`?`tierPeak`:`tierOff`),l=n(e.channel===`zhipu-coding-plan`?s===`peak`?`peakAlertDescPeakZhipu`:`peakAlertDescOffZhipu`:s===`peak`?`peakAlertDescPeak`:`peakAlertDescOff`),u=s===`peak`;return(0,m.jsxs)(`div`,{className:y(V.peakCard,u?V.peakCardPeak:V.peakCardOff,t.position===`center`?V.peakCardCenter:V.peakCardCorner),"data-testid":`billing-peak-alert`,role:`alert`,children:[(0,m.jsxs)(`div`,{className:V.peakHead,children:[(0,m.jsxs)(`span`,{className:y(V.peakTag,u?V.peakTagPrimary:V.peakTagSuccess),children:[(0,m.jsx)(`span`,{className:y(V.peakDot,u?V.peakDotPrimary:V.peakDotSuccess),"aria-hidden":`true`}),c]}),(0,m.jsx)(`button`,{type:`button`,className:V.peakClose,onClick:r,"aria-label":n(`close`),children:`×`})]}),(0,m.jsxs)(`div`,{className:y(V.peakCount,u?V.peakCountPrimary:V.peakCountSuccess),children:[o,`min`]}),(0,m.jsx)(`p`,{className:V.peakDesc,children:l})]})}let lr=[50,80,100],ur=3e4,dr={total:{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,reasoning:0},byModel:{},byDay:{},byDayModels:{}},fr=[`#4f8cff`,`#2dd4bf`,`#a78bfa`,`#f59e0b`,`#f472b6`,`#fbbf24`,`#38bdf8`,`#6366f1`,`#f97316`,`#14b8a6`],pr={checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]},mr=[{id:`overview`,labelKey:`tabOverview`},{id:`providers`,labelKey:`tabProviders`},{id:`token`,labelKey:`tabToken`},{id:`trends`,labelKey:`tabTrends`},{id:`pricing`,labelKey:`tabPricing`},{id:`settings`,labelKey:`tabSettings`}],hr={fill:`none`,"aria-hidden":!0,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`},gr={overview:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...hr,children:(0,m.jsx)(`path`,{d:`M2 13V3M2 13H14M4 10l4-3 2 2 4-5`})}),providers:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...hr,children:[(0,m.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.5`}),(0,m.jsx)(`path`,{d:`M5 7l2 2 4-4`})]}),token:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...hr,children:[(0,m.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`11`,r:`3`})]}),trends:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...hr,children:(0,m.jsx)(`path`,{d:`M2 4l4 4 3-3 5 5M11 10h3V7`})}),pricing:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...hr,children:[(0,m.jsx)(`path`,{d:`M8 2l6 3v6l-6 3-6-3V5z`}),(0,m.jsx)(`path`,{d:`M8 2v12M2 5h12`})]}),settings:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...hr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`2.5`}),(0,m.jsx)(`path`,{d:`M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2`})]})},_r=p,vr=_r.IconChevronDownOutlineMedium??_r.IconChevronDownOutline14;function yr(e,t){let n=Object.keys(e).filter(e=>e<=t).sort().slice(-7);return n.length===0?0:n.reduce((t,n)=>t+(e[n]?.cost??0),0)/n.length}function br(e,t,n){let r=Object.keys(e).filter(e=>e.startsWith(t)),i=t.split(`-`),a=new Date(Number(i[0]),Number(i[1]),0).getDate(),o=r.length>0?r.reduce((t,n)=>t+(e[n]?.cost??0),0)/r.length:yr(e,n);return o<=0?0:o*a}function xr(e){return Object.keys(e).length}function Sr(e,t=Date.now()){let n=0,r=new Date(t);for(;q(r.getTime())in e;)n+=1,r.setDate(r.getDate()-1);return n}function Cr(e){return e.input+e.output}function wr(e){let t=[];for(let n=6;n>=0;--n){let r=new Date;r.setDate(r.getDate()-n);let i=q(r.getTime());t.push({date:i,cost:e[i]?.cost??0})}return t}function Tr(e,t,n=e=>e.cost){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=0;for(let t=0;t<=i;t+=1){let i=new Date(r);i.setDate(i.getDate()-t);let o=e[q(i.getTime())];o!==void 0&&(a+=n(o))}return a}function Er(e,t,n){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=new Date(r);a.setDate(a.getDate()-i);let o=q(a.getTime()),s=new Date(r);s.setDate(s.getDate()-6);let c=q(s.getTime()),l=0,u=0,d=0,f=0,p=0,m=0,h=0,g,_=0;for(let[r,i]of Object.entries(e)){if(!(n===`today`?r===t:n===`7d`?r>=c&&r<=t:n===`week`?r>=o&&r<=t:r.startsWith(t.slice(0,7))))continue;l+=i.cost,u+=i.calls,d+=i.input,f+=i.output,p+=i.cacheHit,m+=i.cacheMiss,h+=i.reasoning??0;let e=Cr(i);e>_&&(_=e,g=r)}return{cost:l,calls:u,input:d,output:f,cacheHit:p,cacheMiss:m,reasoning:h,peakDay:g,peakTokens:_}}function Dr(e,t){let n={};if(e===void 0)return n;for(let[r,i]of Object.entries(e))if(r.startsWith(t))for(let[e,t]of Object.entries(i))n[e]=(n[e]??0)+t.cost;return n}let Or=[80,100];function kr(e,t){if(!(t>0)||!(e>0))return[];let n=e/t*100;return Or.filter(e=>n>=e)}let Ar={DeepSeek:[`deepseek`],"智谱 AI":[`zhipu`,`glm`,`z.ai`],阿里通义:[`qwen`,`tongyi`,`dashscope`,`aliyun`],字节豆包:[`doubao`,`volcengine`,`ark`],月之暗面:[`moonshot`,`kimi`],小米:[`xiaomi`,`mi`,`mimo`],MiniMax:[`minimax`],百度文心:[`ernie`,`wenxin`,`qianfan`,`baidu`],腾讯混元:[`hunyuan`,`tencent`],零一万物:[`01.ai`,`lingyi`,`yi`],阶跃星辰:[`step`,`stepfun`,`step-3.7`],科大讯飞:[`spark`,`xfyun`,`iflytek`],商汤:[`sensenova`,`sensetime`],百川智能:[`baichuan`],OpenAI:[`openai`],Google:[`google`,`gemini`],xAI:[`xai`,`grok`],Meta:[`meta`,`llama`],Anthropic:[`claude`,`anthropic`],"Mistral AI":[`mistral`,`ministral`,`devstral`],Cohere:[`cohere`,`command`],美团:[`longcat`,`meituan`],面壁智能:[`minicpm`,`modelbest`],小红书:[`dots`,`rednote`,`xiaohongshu`],云知声:[`unisound`,`u2`]};function $(e){return e.trim().toLowerCase().replace(/[\s_/-]+/g,``)}function jr(e,t){if(e.length===0||t.length===0)return!1;if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return n.length>=3&&r.includes(n)}function Mr(e,t){let n=$(e),r=$(t);if(jr(n,r))return!0;let i=Ar[e];return i!==void 0&&i.some(e=>jr($(e),r))}function Nr(e){let t=e.trim().toLowerCase(),n=t.replace(/[\s_/-]+/g,``);if(n.length!==0){for(let[e,n]of Object.entries(Ar))for(let r of n){let n=$(r);if(n.length!==0&&(t===n||t.startsWith(`${n}-`)||t.startsWith(`${n}/`)||t.startsWith(`${n}_`)||t.includes(`${n}-`)||t.includes(`${n}/`)||t.includes(`${n}_`)))return e}for(let[e,t]of Object.entries(Ar))for(let r of t){let t=$(r);if(!(t.length<4)&&n.includes(t))return e}}}let Pr={"kimi-coding":`月之暗面`,"zai-coding-cn":`智谱 AI`,"zai-coding":`智谱 AI`,"qwen-token-plan":`阿里通义`,"qwen-token-plan-cn":`阿里通义`,"xiaomi-token-plan-ams":`小米`,"xiaomi-token-plan-cn":`小米`,"xiaomi-token-plan-sgp":`小米`,"volcengine-token-plan":`字节豆包`,"ark-token-plan":`字节豆包`,"doubao-token-plan":`字节豆包`,ernie:`百度文心`,baidu:`百度文心`,wenxin:`百度文心`,minimax:`MiniMax`,"minimax-cn":`MiniMax`,"minimax-token-plan":`MiniMax`,"minimax-token-plan-cn":`MiniMax`,"hunyuan-token-plan":`腾讯混元`,"tencent-token-plan":`腾讯混元`,"hy-token-plan":`腾讯混元`,"xinghuo-token-plan":`讯飞星火`,"xfyun-coding":`讯飞星火`,"spark-coding":`讯飞星火`,"huawei-token-plan":`华为云`,"pangu-token-plan":`华为云`,"huawei-maas-token-plan":`华为云`,"volcengine-agent-plan":`字节豆包`,"ark-agent-plan":`字节豆包`,"baidu-token-plan":`百度文心`,"ernie-token-plan":`百度文心`,"wenxin-token-plan":`百度文心`,opencode:`OpenCode`,"opencode-go":`OpenCode`};function Fr(e){let t=Pr[e];return t===void 0?Nr(e)??e:t}let Ir=`https://platform.kimi.com/console/pay`,Lr=`https://open.bigmodel.cn/finance-center/finance/pay`,Rr=`https://bailian.console.aliyun.com/`,zr=`https://console.volcengine.com/ark`,Br=`https://console.anthropic.com/settings/billing`,Vr=`https://console.cloud.google.com/billing`,Hr=`https://console.x.ai/`,Ur=`https://platform.xiaomimimo.com/console/balance`,Wr=`https://console.cloud.tencent.com/expense/recharge`,Gr={deepseek:`https://platform.deepseek.com/top_up`,minimax:`https://platform.minimax.cn/console/recharge-records`,moonshot:Ir,kimi:Ir,zhipu:Lr,bigmodel:Lr,qwen:Rr,dashscope:Rr,doubao:zr,volcengine:zr,ark:zr,openai:`https://platform.openai.com/settings/organization/billing`,anthropic:Br,claude:Br,google:Vr,gemini:Vr,xai:Hr,grok:Hr,siliconflow:`https://cloud.siliconflow.cn/account/charge`,hunyuan:Wr,tencent:Wr,腾讯云:Wr,xiaomi:Ur,mimo:Ur,mi:Ur,qianfan:`https://console.bce.baidu.com/qianfan/overview`};function Kr(e){let t=Gr[e];if(t!==void 0)return t;let n=Object.keys(Gr).find(t=>e.startsWith(t));return n===void 0?void 0:Gr[n]}function qr(e){let t=$(e),n=Kr(t);if(n!==void 0)return n;for(let[e,n]of Object.entries(Ar))if(jr($(e),t))for(let e of n){let t=Kr($(e));if(t!==void 0)return t}}function Jr(e){let t=et();if(t===void 0||e.byDayModels===void 0)return e;let n=lt().rate,r=e.byDayModelsSite!==void 0,i={},a={},o=new Map,s=0,c=e=>t.some(t=>t.origin!==void 0&&t.origin!==``&&(t.key===e||W(t.key)===W(e))),l=(e,t,r)=>{if(e===void 0)return r;let i=Math.min(t.cacheHit,t.cacheMiss+t.cacheHit),a=r=>{let a=(t.cacheMiss*r.input+i*r.cacheHit+t.output*r.output)/1e6;return e.currency===`USD`?a*n:a};return e.offPeak===void 0?a(e):a(e)*dt+a(e.offPeak)*.5};for(let[t,n]of Object.entries(e.byDayModels)){let u=0,d={};for(let[i,a]of Object.entries(n)){let n=nt(i)??it(i),s=r&&c(i),f;if(s&&e.byDayModelsSite?.[t]?.[i]!==void 0){let r=0;for(let[a,o]of Object.entries(e.byDayModelsSite[t][i])){let e=a.startsWith(`site:`)?a.slice(5):void 0,t=e===void 0?void 0:nt(i,e);r+=l(t??n,o,o.cost)}f=r}else f=l(n,a,a.cost);u+=f,d[i]={...a,cost:f},o.set(i,(o.get(i)??0)+f)}let f=e.byDay[t];f!==void 0&&(i[t]={...f,cost:u}),a[t]=d,s+=u}return{...e,total:{...e.total,cost:s},byDay:i,byDayModels:a,byModel:Object.fromEntries(Object.entries(e.byModel).map(([e,t])=>{let n=o.get(e);return[e,n===void 0?t:{...t,cost:n}]})),unpricedModels:(e.unpricedModels??[]).filter(e=>!nt(e)&&!it(e))}}let Yr=new Set;function Xr(){return typeof Notification<`u`&&Notification.permission===`granted`}function Zr(e,t){Yr.has(e)||(Yr.add(e),fetch(`/api/billing/notify-claim`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({key:e})}).then(e=>e.json()).then(e=>{e.claimed!==!1&&t()}).catch(()=>t()))}function Qr(e){let t=new Map,n=[];for(let r of e){if(r.title===void 0||r.title===``){n.push(r);continue}let e=t.get(r.title);if(e===void 0){let e={...r,mergedCount:1};t.set(r.title,e),n.push(e);continue}e.children===void 0&&(e.children=[{...e}]),e.children.push({...r}),e.calls+=r.calls,e.cost+=r.cost,e.lastActive=Math.max(e.lastActive,r.lastActive),r.stale===!0&&(e.stale=!0),e.mergedCount=(e.mergedCount??1)+1}return n.sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function $r(e){let t=new Map(e.map(e=>[e.id,e])),n=Qr(e.filter(e=>e.parentId===void 0)),r=new Map;for(let e of n){r.set(e.id,e);for(let t of e.children??[])r.set(t.id,e)}let i=new Set;for(let n of e){if(n.parentId===void 0)continue;let e=new Set,a=n.parentId;for(;a!==void 0&&!e.has(a);){e.add(a);let o=r.get(a);if(o!==void 0){o.subs===void 0?o.subs=[n]:o.subs.push(n),i.add(n.id);break}a=t.get(a)?.parentId}}for(let e of n)e.subs?.sort((e,t)=>t.lastActive-e.lastActive);let a=e.filter(e=>e.parentId!==void 0&&!i.has(e.id));return[...n,...a].sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function ei(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>(e.title??``).toLowerCase().includes(n)||(e.cwd??``).toLowerCase().includes(n)||e.id.toLowerCase().includes(n))}function ti(e,t){let n=e.trim().toLowerCase();return n!==``&&!t.some(e=>e.toLowerCase().includes(n))}function ni(e,t){return e.checked?e.okProviders.some(e=>Mr(t,e))?V.healthOk:e.badProviders.some(e=>Mr(t,e))?V.healthBad:V.healthIdle:V.healthIdle}function ri(e,t){switch(e){case`ok`:return``;case`not-configured`:return t(`subscriptionNotConfigured`);case`unauthorized`:return t(`subscriptionUnauthorized`);case`rate-limited`:return t(`subscriptionRateLimited`);case`invalid-response`:return t(`subscriptionInvalid`);default:return t(`subscriptionUnavailable`)}}function ii(e,t){switch(e){case`session`:return t(`subscriptionSession`);case`weekly`:return t(`subscriptionWeekly`);case`monthly`:return t(`subscriptionMonthly`);case`billing`:return t(`subscriptionBilling`)}}function ai(e,t){switch(e){case`new-api`:return t(`relayKindNewApi`);case`sub2api`:return t(`relayKindSub2Api`);default:return t(`relayKindUnknown`)}}let oi={"new-api":V.siteKindSite,sub2api:V.siteKindDirect,unknown:V.siteKindUnknown},si=e=>e.models.reduce((e,t)=>e+(t.actual??(t.plan===!0?0:t.estimated)),0);function ci(e){return e.children===void 0?{cost:e.subCost??0,calls:e.subCalls??0}:(e.children??[]).reduce((e,t)=>({cost:e.cost+(t.subCost??0),calls:e.calls+(t.subCalls??0)}),{cost:0,calls:0})}function li(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}async function ui(){try{let e=await fetch(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n||!(`total`in n))return null;let r=n,i=e=>typeof e==`object`&&!!e;return{total:r.total??dr.total,byModel:r.byModel??{},byDay:r.byDay??{},...r.byDayModels===void 0?{}:{byDayModels:r.byDayModels},...i(r.byDayModelsSite)?{byDayModelsSite:r.byDayModelsSite}:{},...r.updatedAt===void 0?{}:{updatedAt:r.updatedAt},...typeof r.budget==`number`?{budget:r.budget}:{},...typeof r.lowBalanceThreshold==`number`?{lowBalanceThreshold:r.lowBalanceThreshold}:{},...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{},...Array.isArray(r.byWorkspace)?{byWorkspace:r.byWorkspace}:{},...i(r.bySite)?{bySite:r.bySite}:{},...i(r.byTier)?{byTier:r.byTier}:{},...i(r.byTool)?{byTool:r.byTool}:{},...Array.isArray(r.unpricedModels)?{unpricedModels:r.unpricedModels}:{},...typeof r.staleLedgerSessions==`number`?{staleLedgerSessions:r.staleLedgerSessions}:{},...typeof r.unreadableSessions==`number`?{unreadableSessions:r.unreadableSessions}:{},...typeof r.unreadableFormatSessions==`number`?{unreadableFormatSessions:r.unreadableFormatSessions}:{},...typeof r.unreadableNoLedgerSessions==`number`?{unreadableNoLedgerSessions:r.unreadableNoLedgerSessions}:{},...typeof r.searchCallEstimateCny==`number`?{searchCallEstimateCny:r.searchCallEstimateCny}:{},...r.byRole!==null&&typeof r.byRole==`object`?{byRole:r.byRole}:{},...r.perf!==null&&typeof r.perf==`object`&&r.perf.byModel!==null&&typeof r.perf.byModel==`object`&&r.perf.byHourModel!==null&&typeof r.perf.byHourModel==`object`?{perf:r.perf}:{},...typeof r.pluginVersion==`string`?{pluginVersion:r.pluginVersion}:{}}}catch{return null}}async function di(){try{let e=await fetch(`/api/billing/balance`);if(!e.ok)return{balances:[]};let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return{balances:[]};let r=n;return{balances:Array.isArray(r.balances)?r.balances:[],...r.reconcile===void 0?{}:{reconcile:r.reconcile}}}catch{return{balances:[]}}}async function fi(){let e=await fetch(`/api/billing/subscriptions`);if(!e.ok)throw Error(`subscriptions HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`subscriptions: invalid response`)}async function pi(){let e=await fetch(`/api/billing/relay-quotas`);if(!e.ok)throw Error(`relay-quotas HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`relay-quotas: invalid response`)}async function mi(){try{let e=await fetch(`/api/billing/usage-tool`);if(!e.ok)return;let t=JSON.parse(await e.text());return typeof t.enabled==`boolean`?t.enabled:void 0}catch{return}}async function hi(e){try{let t=await fetch(`/api/billing/usage-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:e})});return t.ok?JSON.parse(await t.text()).ok===!0:!1}catch{return!1}}let gi=!1,_i=0;async function vi(e=0){try{let t=await fetch(`/api/billing/pricing`);if(!t.ok){gi=!1;return}let n=await t.text(),r=JSON.parse(n);if(typeof r!=`object`||!r||!(`source`in r)){gi=!1;return}let i=r;Array.isArray(i.catalog)&&i.catalog.length>0&&i.aliases!==null&&typeof i.aliases==`object`&&Dt(i.catalog,i.aliases);let a=r;if(a.source===`builtin`&&e<3){if(e===0){if(gi)return;gi=!0}setTimeout(()=>{vi(e+1)},2e3);return}gi=!1,_i=a.syncedAt??0,at(a)}catch{gi=!1}}async function yi(){try{return(await fetch(`/api/billing/pricing/refresh`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`})).ok?(await vi(),!0):!1}catch{return!1}}function bi(e,t){switch(e){case`overview`:return{label:`实时`,kind:`neutral`};case`providers`:return{label:`${t.providersCount} 厂商`,kind:`neutral`};case`token`:return{label:xi(t.tokenTotal),kind:`neutral`};case`trends`:return null;case`pricing`:return t.rateAgeMinutes===null||t.rateAgeMinutes<360?{label:`已同步`,kind:`neutral`}:{label:`需同步`,kind:`violet`};case`settings`:return t.settingsDirty<=0?null:{label:String(t.settingsDirty),kind:`hot`}}}function xi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Si({window:e,t}){let n=Math.min(100,Math.max(0,e.usedPercent)),r=Math.min(100,Math.max(0,e.remainingPercent))<=0;return(0,m.jsxs)(`div`,{className:V.subscriptionWindow,children:[(0,m.jsx)(`span`,{className:V.subscriptionWindowLabel,children:ii(e.kind,t)}),(0,m.jsx)(`span`,{className:V.subscriptionTrack,"aria-hidden":`true`,children:(0,m.jsx)(`span`,{className:y(V.subscriptionFill,n>=100&&V.subscriptionFillOver,n>=80&&n<100&&V.subscriptionFillWarn),style:{width:`${n}%`}})}),(0,m.jsxs)(`span`,{className:V.subscriptionMeta,children:[(0,m.jsx)(`span`,{className:y(V.subscriptionPct,r&&V.subscriptionExhausted),children:r?t(`subscriptionExhausted`):t(`subscriptionRemaining`).replace(`{pct}`,String(e.remainingPercent))}),e.resetsAt!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionReset,children:t(`subscriptionReset`).replace(`{date}`,`${q(new Date(e.resetsAt).getTime())} ${li(new Date(e.resetsAt).getTime())}`)})]})]})}function Ci({label:e,t}){return(0,m.jsx)(p.Tooltip,{label:e,side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.helpTip,role:`note`,"aria-label":e,children:`?`})})}function wi(e,t){return e===V.healthOk?t(`healthDotLive`):e===V.healthBad?t(`healthDotFailed`):t(`healthDotUnknown`)}function Ti(e){let t=t=>K(Xt(t,e.currency),e.currency),{wide:n,t:r,onOpen:i,monthCost:a,todayCost:o,weekCost:s,days:c,vendorStatus:l,dash:u,floatPrefs:p,subscriptions:h,cardPrefs:g,monthTokens:_,todayTokens:v,weekTokens:b,budgetPressure:x,deltaPct:S=0}=e,C=(0,d.useMemo)(()=>p.targets.map(e=>h.find(t=>t.provider===e)).filter(e=>e!==void 0),[p.targets,h]),[w,T]=(0,d.useState)(0),ee=C.length===0?0:Math.min(w,C.length-1),E=C[ee],D=(0,d.useRef)(null),[O,k]=(0,d.useState)(!1),[te,A]=(0,d.useState)({left:0,top:0});(0,d.useEffect)(()=>{if(!O||p.mode!==`subscription`||C.length<2)return;let e=setInterval(()=>T(e=>(e+1)%C.length),1500);return()=>clearInterval(e)},[O,p.mode,C.length]);let j=(0,d.useRef)(void 0),ne=(0,d.useCallback)(()=>{window.clearTimeout(j.current),k(!0)},[]),re=(0,d.useCallback)(()=>{window.clearTimeout(j.current),j.current=window.setTimeout(()=>k(!1),120)},[]);(0,d.useEffect)(()=>()=>window.clearTimeout(j.current),[]);let M=(0,d.useCallback)(()=>{let e=D.current?.getBoundingClientRect();e!==void 0&&A({left:e.left,top:e.top-8})},[]);(0,d.useEffect)(()=>{if(!O)return;let e=()=>M();return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[O,M]);let ie=c.length>0?c.reduce((e,t)=>e+t.cost,0)/c.length:0,ae=ie>0?Math.max(0,Math.min(1,o/ie)):0,oe=-80+ae*160,se=(0,m.jsxs)(`svg`,{viewBox:`3.5 10 34 22`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,opacity:.16}),(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,strokeDasharray:`${(41.9*ae).toFixed(2)} 41.9`,className:V.triggerGaugeArc}),(0,m.jsx)(`path`,{d:`M5.23 26.4 8.18 26.92M10.36 17.51 12.29 19.81M20 14v3M27.71 19.81 29.64 17.51M31.82 26.92 34.77 26.4`,strokeWidth:1.6,opacity:.7}),(0,m.jsx)(`path`,{d:`M7.01 21.5 8.31 22.25M14.87 14.91 15.38 16.31M24.62 16.31 25.13 14.91M31.69 22.25 32.99 21.5`,strokeWidth:1.2,opacity:.38}),(0,m.jsx)(`line`,{x1:`20`,y1:`29`,x2:`20`,y2:`19.5`,strokeWidth:2,className:V.triggerGaugeNeedle,style:{transform:`rotate(${oe}deg)`,transformOrigin:`20px 29px`}}),(0,m.jsx)(`circle`,{cx:`20`,cy:`29`,r:`1.5`,fill:`currentColor`,stroke:`none`})]});if(!n)return(0,m.jsx)(`button`,{type:`button`,className:y(V.railButton,x!==`none`&&V.triggerBudgetPulse,x===`over`&&V.triggerBudgetOver),"data-testid":`billing-rail-button`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:se});let N=g.metric===`tokens`,ce=c.map(e=>N?e.tokens:e.cost),P=Math.max(...ce,0),le=ce.map(e=>P>0?4+e/P*12:4);return(0,m.jsxs)(`span`,{ref:D,className:V.triggerWrap,onMouseEnter:()=>{M(),ne()},onMouseLeave:re,onFocusCapture:()=>{M(),ne()},onBlurCapture:()=>k(!1),children:[(0,m.jsxs)(`button`,{type:`button`,className:y(V.trigger,x!==`none`&&V.triggerBudgetPulse,x===`over`&&V.triggerBudgetOver),"data-testid":`billing-trigger`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:[(0,m.jsx)(`span`,{className:y(V.triggerIcon,x!==`none`&&V.triggerBudgetHot),"data-testid":`billing-trigger-icon`,children:se}),(0,m.jsx)(`span`,{className:V.triggerMain,children:(0,m.jsxs)(`span`,{className:V.triggerPrimary,children:[(0,m.jsx)(`span`,{className:V.triggerLabel,children:N?g.span===`day`?r(`triggerTodayTokens`):g.span===`week`?r(`triggerWeekTokens`):r(`triggerMonthTokens`):g.span===`day`?r(`triggerToday`):g.span===`week`?r(`weekCost`):r(`triggerMonth`)}),(()=>{let e=g.span===`day`?N?v:o:g.span===`week`?N?b:s:N?_:a,n=g.span===`day`?S:0;return N?(0,m.jsx)(`span`,{className:V.triggerMetric,"data-testid":`billing-trigger-span-tokens`,children:J(e)}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{className:V.triggerValueRow,children:[(0,m.jsx)(`span`,{className:V.triggerYen,"aria-hidden":`true`,children:t(e).charAt(0)}),(0,m.jsx)(`span`,{className:V.triggerMetric,"data-testid":`billing-trigger-span-money`,children:t(e).slice(1)})]}),g.showDelta&&n!==0&&(0,m.jsxs)(`span`,{className:y(V.triggerDelta,n>0?V.triggerDeltaUp:V.triggerDeltaDown),"data-testid":`billing-trigger-delta`,children:[n>0?`▲`:`▼`,` `,Math.abs(n).toFixed(1),`%`]}),(0,m.jsx)(`span`,{className:V.triggerGlow,"aria-hidden":`true`})]})})()]})}),(0,m.jsx)(`span`,{className:V.triggerSpark,"data-testid":`billing-trigger-spark`,"aria-hidden":`true`,children:le.map((e,t)=>(0,m.jsx)(`span`,{className:t===le.length-1?V.triggerSparkHot:V.triggerSparkBar,style:{height:`${e}px`}},c[t]?.date??String(t)))})]}),(0,f.createPortal)((0,m.jsx)(`span`,{className:y(V.triggerPop,O&&V.triggerPopShown),style:{left:`${te.left}px`,top:`${te.top}px`},"data-testid":`billing-trigger-pop`,"aria-hidden":!O,onMouseEnter:ne,onMouseLeave:re,children:p.mode===`subscription`?(0,m.jsx)(m.Fragment,{children:C.length===0?(0,m.jsx)(`span`,{className:V.triggerPopEmpty,children:r(`floatNoTargets`)}):(0,m.jsxs)(m.Fragment,{children:[E!==void 0&&(0,m.jsxs)(`div`,{className:V.floatSub,"data-testid":`billing-float-subscription`,children:[(0,m.jsxs)(`div`,{className:V.floatSubHead,children:[(0,m.jsx)(`span`,{className:V.floatSubName,children:E.displayName}),E.plan!==void 0&&(0,m.jsx)(`span`,{className:V.floatSubPlan,children:E.plan})]}),E.windows.map(e=>(0,m.jsx)(Si,{window:e,t:r},e.kind))]}),C.length>1&&(0,m.jsx)(`span`,{className:V.triggerPopSwitcher,"data-testid":`billing-float-switcher`,children:(0,m.jsxs)(`span`,{className:V.triggerPopSwitchCount,children:[ee+1,`/`,C.length]})})]})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:V.popHead,children:(0,m.jsx)(`span`,{className:V.popTitle,children:r(`popTitle`)})}),(0,m.jsxs)(`span`,{className:V.metricGrid,children:[(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryToday`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(o)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryWeek`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(s)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryMonth`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(a)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`input`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:J(u.input)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`output`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:J(u.output)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`cacheHit`)}),(0,m.jsx)(`span`,{className:y(V.metricValue,V.metricValueSuccess),children:$t(u.cacheRead+u.cacheMiss>0?u.cacheRead/(u.cacheRead+u.cacheMiss)*100:0)})]})]}),(0,m.jsxs)(`span`,{className:V.popModel,children:[(0,m.jsx)(`span`,{className:V.popModelLabel,children:r(`popTodayModel`)}),l.direct!==void 0||l.sub!==void 0?(0,m.jsxs)(m.Fragment,{children:[l.direct!==void 0&&(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotDirect),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popTagPrimary,children:r(`popDirectLead`)}),(0,m.jsx)(`span`,{className:V.popModelName,children:l.direct.name}),(0,m.jsx)(`span`,{className:y(V.popModelStatus,l.direct.low&&V.popModelStatusLow),children:l.direct.text})]}),l.sub!==void 0&&(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotSub),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popTagSub,children:r(`popSubLead`)}),(0,m.jsx)(`span`,{className:V.popModelName,children:l.sub.name}),(0,m.jsx)(`span`,{className:y(V.popModelStatus,l.sub.low&&V.popModelStatusLow),children:l.sub.text})]})]}):(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotNeutral),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popModelStatus,children:r(`popNoConsumption`)})]})]})]})}),document.body)]})}function Ei({balance:e,days:t,dailyBurn:n,money:r,t:i,onClose:a}){let o=t=>t===void 0?void 0:e.currency===`USD`?`$${t.toFixed(2)}`:r(t),s=o(e.totalBalance),c=o(e.grantedBalance),l=o(e.toppedUpBalance);return(0,m.jsxs)(`span`,{className:V.balanceDetailPop,"data-testid":`billing-balance-detail-pop`,onClick:e=>{e.stopPropagation()},children:[(0,m.jsxs)(`span`,{className:V.balanceDetailHead,children:[(0,m.jsx)(`span`,{className:V.balanceDetailTitle,children:e.displayName}),(0,m.jsx)(`button`,{type:`button`,className:V.balanceDetailClose,"aria-label":i(`close`),onClick:a,children:`×`})]}),(0,m.jsxs)(`span`,{className:V.balanceDetailGrid,children:[s!==void 0&&(0,m.jsx)(Di,{label:i(`balance`),value:s}),c!==void 0&&(0,m.jsx)(Di,{label:i(`balanceGranted`),value:c}),l!==void 0&&(0,m.jsx)(Di,{label:i(`balanceTopped`),value:l}),(0,m.jsx)(Di,{label:i(`balanceDaily`),value:r(n)}),(0,m.jsx)(Di,{label:i(`balanceDaysLong`),value:`${t} ${i(`balanceDaysUnit`)}`})]})]})}function Di({label:e,value:t}){return(0,m.jsxs)(`span`,{className:V.balanceDetailRow,children:[(0,m.jsx)(`span`,{className:V.balanceDetailLabel,children:e}),(0,m.jsx)(`span`,{className:V.balanceDetailValue,children:t})]})}function Oi({userPrices:e,onUserPrices:t,t:n}){let[r,i]=(0,d.useState)(()=>[...e]),[a,o]=(0,d.useState)(new Set),s=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),c=()=>{i(e=>e.filter((e,t)=>!a.has(t))),o(new Set)},l=(e,t)=>i(n=>n.map((n,r)=>r===e?{...n,...t}:n)),u=()=>i(e=>[...e,{key:``,input:0,cacheHit:0,output:0}]),f=e=>{let t=r[e]?.offPeak;return{input:t===void 0?``:String(t.input),cacheHit:t===void 0?``:String(t.cacheHit),output:t===void 0?``:String(t.output)}},p=(e,t,n)=>i(r=>r.map((r,i)=>{if(i!==e)return r;let a=r.offPeak,o={input:a===void 0?``:String(a.input),cacheHit:a===void 0?``:String(a.cacheHit),output:a===void 0?``:String(a.output),[t]:n},s=[o.input,o.cacheHit,o.output].some(e=>e.trim()!==``),c=[o.input,o.cacheHit,o.output].map(e=>Number(e)),l=s&&c.every(e=>Number.isFinite(e)&&e>=0)&&c.some(e=>e>0),{offPeak:u,...d}=r;return l?{...d,offPeak:{input:c[0]??0,cacheHit:c[1]??0,output:c[2]??0}}:d})),h=()=>t(r.filter(e=>e.key.trim()!==``).map(e=>({...e,key:e.key.trim(),...e.origin===void 0||e.origin.trim()===``?{}:{origin:Ze(e.origin.trim())}}))),g=Kt().map(e=>e.key),_=(e,t)=>i(n=>n.map((n,r)=>{if(r!==e)return n;let{currency:i,...a}=n;return t===`USD`?{...a,currency:`USD`}:a})),[v,b]=(0,d.useState)({}),x=(e,t,n)=>`${e}:${t}:${n}`,S=(e,t,n)=>b(r=>{let i=x(e,t,n);if(r[i]===void 0)return r;let a={...r};return delete a[i],a}),C=e=>Number.isFinite(e)&&e!==0?String(e):``,w=(e,t,n)=>{if(b(r=>({...r,[x(e,`main`,t)]:n})),n===``){l(e,{[t]:0});return}let r=Number(n);Number.isFinite(r)&&r>=0&&l(e,{[t]:r})};return(0,m.jsxs)(`section`,{className:V.setCard,"data-testid":`billing-user-prices`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[n(`userPrices`),(0,m.jsx)(Ci,{label:n(`userPricesHint`),t:n})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsx)(`datalist`,{id:`billing-price-model-keys`,children:g.map(e=>(0,m.jsx)(`option`,{value:e},e))}),r.map((e,t)=>(0,m.jsxs)(`div`,{className:V.userPriceRow,"data-testid":`billing-user-price-row`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:V.userPriceCheck,"data-testid":`billing-user-price-select`,checked:a.has(t),"aria-label":n(`userPriceSelect`),onChange:()=>s(t)}),(0,m.jsxs)(`div`,{className:V.userPriceBody,children:[(0,m.jsxs)(`div`,{className:V.userPriceLineMeta,children:[(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceModel`)}),(0,m.jsx)(`input`,{className:V.userPriceInput,"data-testid":`billing-user-price-model`,type:`text`,list:`billing-price-model-keys`,value:e.key,placeholder:`flash`,"aria-label":n(`userPriceModel`),onChange:e=>l(t,{key:e.target.value})})]}),(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceSource`)}),(0,m.jsx)(`input`,{className:V.userPriceInput,"data-testid":`billing-user-price-origin`,type:`text`,value:e.origin??``,placeholder:n(`userPriceSourceHint`),"aria-label":n(`userPriceSource`),onChange:e=>l(t,{origin:e.target.value.trim()})})]}),(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceCurrency`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,e.currency!==`USD`&&V.floatModeBtnOn),onClick:()=>_(t,`CNY`),children:`CNY`}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,e.currency===`USD`&&V.floatModeBtnOn),onClick:()=>_(t,`USD`),children:`USD`})]})]})]}),[{scope:`main`,label:n(`userPriceNormal`),testid:`billing-user-price-normal`,valueOf:n=>v[x(t,`main`,n)]??C(e[n]),onChange:(e,n)=>w(t,e,n)},{scope:`off`,label:n(`userPriceOffPeak`),testid:`billing-user-price-offpeak`,valueOf:e=>v[x(t,`off`,e)]??f(t)[e],onChange:(e,n)=>{b(r=>({...r,[x(t,`off`,e)]:n})),p(t,e,n)}}].map(e=>(0,m.jsxs)(`div`,{className:V.userPricePriceLine,"data-testid":e.testid,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:e.label}),[`input`,`cacheHit`,`output`].map(r=>{let i=n(r===`input`?`tokenMiss`:r===`cacheHit`?`tokenHit`:`tokenOutput`);return(0,m.jsx)(`input`,{className:V.userPriceInputNum,type:`number`,min:0,step:.01,placeholder:i,"aria-label":`${e.label} ${i}`,value:e.valueOf(r),onChange:t=>e.onChange(r,t.target.value),onBlur:()=>S(t,e.scope,r)},r)})]},e.testid))]})]},t)),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-add`,onClick:u,children:n(`userPriceAdd`)}),(0,m.jsxs)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-remove-selected`,disabled:a.size===0,onClick:c,children:[n(`userPriceRemoveSelected`),a.size>0?` (${a.size})`:``]}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-save`,onClick:h,children:n(`userPriceSave`)})]})]})]})}function ki({stats:e,t,onClose:n,userPrices:r,onUserPrices:i,health:a,balances:o,reconcile:s,quotas:c,relayQuotas:l,currency:u,onCurrency:f,language:h,onLanguage:g,turns:_,renderSlot:v,budgetEnabled:b,budgetAmount:x,onToggleBudget:S,onBudgetAmount:C,modelBudgets:w,monthModelCost:T,onModelBudget:ee,peakConfig:E,onPeakConfig:D,onPreviewPeak:O,floatPrefs:k,onFloatPrefs:te,cardPrefs:A,onCardPrefs:j,sitePrefs:M,onSitePrefs:ie,liveCostPrefs:ae,onLiveCostPrefs:oe,quotasStale:se}){let[N,ce]=(0,d.useState)(`cost`),{total:P,byModel:le,byDay:F}=e,[I,ue]=(0,d.useState)(`overview`),[de,fe]=(0,d.useState)(7),[pe,he]=(0,d.useState)(()=>{try{return window.localStorage.getItem(`dsh-billing:reconcile-dismissed`)??``}catch{return``}}),ge=()=>{let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`},ye=(0,d.useCallback)(()=>{let e=ge();he(e);try{window.localStorage.setItem(`dsh-billing:reconcile-dismissed`,e)}catch{}},[]),[R,xe]=(0,d.useState)(()=>{let e=[`unpriced`,`search-estimate`,`unreadable`],t=new Set,n=new Date,r=e=>String(e).padStart(2,`0`),i=`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}`;try{for(let n of e)window.localStorage.getItem(`dsh-billing:notice-${n}-dismissed`)===i&&t.add(n)}catch{}return t}),Se=(0,d.useCallback)(e=>{let t=ge();xe(t=>new Set(t).add(e));try{window.localStorage.setItem(`dsh-billing:notice-${e}-dismissed`,t)}catch{}},[]),[we,Te]=(0,d.useState)(`month`),[Ee,De]=(0,d.useState)(`cost`),[z,Oe]=(0,d.useState)(je),[ke,Ae]=(0,d.useState)(Fe),[Ne,Le]=(0,d.useState)(`budget`),[Re,ze]=(0,d.useState)(``),Be=e=>ti(Re,e);(0,d.useEffect)(()=>{if(I!==`settings`||typeof IntersectionObserver>`u`)return;let e=Array.from(document.querySelectorAll(`[id^="settings-"]`)).filter(e=>!e.closest(`[hidden]`));if(e.length===0)return;let t=new IntersectionObserver(e=>{let t,n=1/0;for(let r of e){if(!r.isIntersecting)continue;let e=r.boundingClientRect.top;e<n&&(n=e,t=r.target.id)}t!==void 0&&Le(t.slice(9))},{rootMargin:`-80px 0px -55% 0px`});for(let n of e)t.observe(n);return()=>{t.disconnect()}},[I]);let Ve=(0,d.useCallback)(e=>{if(Le(e),typeof document>`u`)return;let t=document.getElementById(`settings-${e}`);if(t===null)return;let n=t.closest(`.${V.dashboardBody}`);if(n===null)return;let r=t.getBoundingClientRect().top-n.getBoundingClientRect().top;n.scrollTo({top:n.scrollTop+r,behavior:`smooth`})},[]),He=(0,d.useCallback)(e=>{Oe(e),Me(e)},[]),Ue=(0,d.useCallback)(e=>{Ae(e),Ie(e)},[]);(0,d.useEffect)(()=>{typeof document>`u`||(document.documentElement.dataset.density=z,document.documentElement.dataset.motion=ke)},[z,ke]),(0,d.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t?.density!==void 0&&Oe(t.density)},t=e=>{let t=e.detail;t?.motion!==void 0&&Ae(t.motion)};return window.addEventListener(B,e),window.addEventListener(Pe,t),()=>{window.removeEventListener(B,e),window.removeEventListener(Pe,t)}},[]);let[Ge,Ke]=(0,d.useState)(ne),H=(0,d.useMemo)(()=>c.filter(e=>e.status===`ok`&&e.windows.length>0).map(e=>({id:e.provider,label:e.displayName})),[c]),[qe,Je]=(0,d.useState)(),[Ye,Xe]=(0,d.useState)(new Set),[Ze,Qe]=(0,d.useState)(!1),[$e,et]=(0,d.useState)(``),tt=(0,d.useCallback)(e=>{Xe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),nt=(0,d.useMemo)(()=>$r(e.bySession??[]),[e.bySession]),rt=(0,d.useMemo)(()=>ei(e.bySession??[],$e),[e.bySession,$e]),it=(0,d.useMemo)(()=>[...new Set([...Object.keys(T),...Object.keys(w)])].map(e=>{let t=Ht(e);return{key:e,name:t.key===`other`?void 0:t.name,cost:T[e]??0}}).sort((e,t)=>t.cost-e.cost),[T,w]),[at,ot]=(0,d.useState)(()=>new Set(_e())),st=(0,d.useCallback)(e=>{ot(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),ve([...n]),n})},[]),[ct,ut]=(0,d.useState)(()=>L()),dt=(0,d.useCallback)(()=>{ut(e=>{let t=!e;return be(t),t})},[]),[ft,pt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{let e=!0;return mi().then(t=>{e&&t!==void 0&&pt(t)}),()=>{e=!1}},[]);let mt=(0,d.useCallback)(()=>{let e=!ft;pt(e),hi(e).then(t=>{t||pt(!e)})},[ft]),ht=lt(),[gt,_t]=(0,d.useState)(!1),vt=(0,d.useCallback)(()=>{gt||(_t(!0),yi().finally(()=>{_t(!1)}))},[gt]),yt=_i,U=e=>K(Xt(e,u),u),bt=u===`usd`?`$`:u===`eur`?`€`:`¥`,Ct=h,wt=e=>Yn(e,Ct),[Tt,Et]=(0,d.useState)(``),[Dt,Ot]=(0,d.useState)(()=>me()),[kt,At]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{let e=setInterval(()=>{At(Date.now())},3e4);return()=>{clearInterval(e)}},[]);let W=c.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),jt=E.leadMin*6e4,Mt=(e,n)=>e===0?t(`free`):Zt(Qt(e,n,u,ht.rate),u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`),Nt=(0,d.useMemo)(()=>Un([..._].reverse()),[_]),Pt={peak:e.byTier?.peak.cost??0,offPeak:e.byTier?.offPeak.cost??0},Ft=Pt.peak/2,It=yr(F,q()),Lt=e=>o.find(t=>$(t.provider)===$(e)),Rt=e=>e.balance?.error===`unconfigured`&&e.models.length>0&&e.models.every(e=>e.plan),zt=e=>{if(e===void 0)return(0,m.jsx)(`span`,{className:V.na,children:`—`});if(e.error===`unconfigured`)return t(`balanceUnconfigured`);if(e.error===`unauthorized`)return t(`balanceUnauthorized`);if(e.error===`unreachable`)return t(`balanceUnreachable`);if(e.totalBalance===void 0)return(0,m.jsx)(`span`,{className:V.na,children:`—`});let n=e.currency===`USD`?`$${e.totalBalance.toFixed(2)}`:U(e.totalBalance),r=e.currency===`USD`?e.totalBalance*ht.rate:e.totalBalance,i=It>0?Math.floor(r/It):void 0;return(0,m.jsxs)(`span`,{className:V.balanceCell,children:[(0,m.jsx)(`span`,{children:n}),i!==void 0&&i>=0&&(0,m.jsx)(`button`,{type:`button`,className:y(V.balanceDaysBadge,i<=3&&V.balanceDaysBadgeLow),"data-testid":`billing-balance-days-badge`,title:t(`balanceDays`).replace(`{days}`,String(i)),"aria-label":`${e.displayName} ${t(`balanceDays`).replace(`{days}`,String(i))}`,onClick:t=>{t.stopPropagation(),Je(qe===e.provider?void 0:e.provider)},children:`?`}),qe===e.provider&&(0,m.jsx)(Ei,{balance:e,days:i??0,dailyBurn:It,money:U,t,onClose:()=>{Je(void 0)}})]})},Bt=Object.keys(F).sort(),G=q(),Vt=F[G]?.cost??0,Ut=G.slice(0,7),Gt=G.slice(0,4),qt=Bt.reduce((e,t)=>e+(t.startsWith(Ut)?F[t]?.cost??0:0),0),Yt=Bt.reduce((e,t)=>e+(t.startsWith(Gt)?F[t]?.cost??0:0),0),en=(0,d.useMemo)(()=>br(F,Ut,G)+c.reduce((e,t)=>e+(t.planType===`code`?t.subscriptionAmount??0:0),0),[F,Ut,G,c]),tn=(0,d.useMemo)(()=>{if(!(b&&x>0))return null;let e=x-qt;return{over:e<=0,remainRatio:Math.max(0,Math.min(1,e/x)),remainCny:Math.max(0,e)}},[b,x,qt]),nn=(0,d.useMemo)(()=>{let e=[];for(let t=de-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t),e.push(q(n.getTime()))}return e},[de]),on=nn.at(-1)??G,Y=(0,d.useMemo)(()=>Object.entries(F).map(([e,t])=>({date:e,value:Ee===`tokens`?Cr(t):t.cost})),[F,Ee]),dn=(0,d.useMemo)(()=>Y.reduce((e,t)=>e+t.value,0),[Y]),fn=xr(F),pn=Sr(F),mn=(0,d.useMemo)(()=>nn.map(t=>{let n={},r=e.byDayModels?.[t];if(r!==void 0)for(let[e,t]of Object.entries(r))t.cost>0&&(n[e]=t.cost);let i=F[t];return{date:t,cost:i?.cost??0,calls:i?.calls??0,byModel:n,tokens:i===void 0?0:Cr(i)}}),[nn,F,e.byDayModels]),gn=(0,d.useMemo)(()=>Object.entries(le).filter(([,e])=>e.calls>0).map(([e,t])=>{let n=Ht(e),r=n.key===`other`,i=r?Nr(e):void 0,a={input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output};return{key:e,name:r?e:n.name,provider:i??n.provider,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:Jt(n,a),plan:t.plan===!0,...t.cost>0?{actual:t.cost}:{},uncatalogued:r,estimatedPricing:n.estimated===!0,officialCalls:t.officialCalls??0,officialCost:t.officialCost??0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated)).map((e,t)=>({...e,color:fr[t%fr.length]??`#8b95a3`})),[le]),_n=(0,d.useMemo)(()=>M.hideUnidentified?l.filter(e=>e.kind!==`unknown`):l,[l,M.hideUnidentified]),X=(0,d.useMemo)(()=>{let n=e.byDayModelsSite;if(ct){let t=q();n={[t]:e.byDayModelsSite?.[t]??{}}}let r=new Map;for(let t of Object.values(n??{}))for(let[n,i]of Object.entries(t))for(let[t,a]of Object.entries(i)){let i=r.get(t);i===void 0&&(i=new Map,r.set(t,i));let o=i.get(n)??{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,allPlan:!0};o.calls+=a.calls,o.input+=a.input,o.output+=a.output,o.cacheHit+=a.cacheHit,o.cacheMiss+=a.cacheMiss,o.cost+=a.cost,o.allPlan=o.allPlan&&(a.plan??e.byModel?.[n]?.plan===!0),i.set(n,o)}let i=new Map;for(let[e,t]of r){let n=!e.startsWith(`direct:`)&&!e.startsWith(`site:`),r=[...t.entries()].filter(([,e])=>e.calls>0).map(([e,t],r)=>{let i=Ht(e),a=i.key===`other`,o=a?Nr(e)??i.provider:i.provider;return{key:e,name:a?e:i.name,provider:o,color:fr[r%fr.length]??`#8b95a3`,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:n?0:Jt(i,{input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output}),plan:t.allPlan,...t.cost>0?{actual:t.cost}:{},uncatalogued:a,estimatedPricing:i.estimated===!0,officialCalls:0,officialCost:0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));r.length>0&&i.set(e,r)}let s=e=>er(e,Ct)??t(`channelUnknown`),l=new Map,u=new Map,d=new Map,f=e=>e.startsWith(`direct:`)?`direct`:e.startsWith(`site:`)?`site`:`unknown`,p={direct:2,site:1,unknown:0,vendor:0};for(let[e,t]of i){let n=s(e),r=l.get(n);if(r===void 0)l.set(n,[...t]),u.set(n,f(e)),d.set(n,e);else{r.push(...t),r.sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));let i=u.get(n)??`unknown`,a=f(e);p[a]>p[i]&&(u.set(n,a),d.set(n,e))}}let m=new Map,h=new Map;for(let e of c){if(e.status===`not-configured`)continue;let t=e.displayName??Fr(e.provider),n=s(`direct:${e.provider}`),r=l.has(t)?t:l.has(n)?n:void 0,i=r??`sub:${Fr(e.provider)}`;h.set(i,r??Fr(e.provider));let a=m.get(i);a===void 0?m.set(i,[e]):a.push(e)}let g=e=>e===s(`direct:deepseek`)||e===s(`site:https://api.deepseek.com`)?Lt(`deepseek`)??Lt(e):Lt(e),_=[];for(let[e,t]of l)_.push({id:`ch:${d.get(e)??e}`,name:e,models:t,subscriptions:m.get(e)??[],balance:g(e),dot:ni(a,t[0]?.provider??``),channelKind:u.get(e)??`unknown`});for(let[e,t]of h)l.has(e)||_.push({id:e,name:t,models:[],subscriptions:m.get(e)??[],balance:Lt(t),dot:ni(a,t),channelKind:`vendor`});let v=new Set(_.flatMap(e=>[$(e.name),...e.balance===void 0?[]:[$(e.balance.provider)]]));for(let e of o)v.has($(e.provider))||(e.error===void 0||e.provider.startsWith(`custom:`))&&_.push({id:`bal:${e.provider}`,name:e.displayName,models:[],subscriptions:[],balance:e,dot:ni(a,e.displayName),channelKind:`vendor`});return _.filter(e=>M.hideUnidentified&&e.channelKind===`unknown`?!1:!ct||e.models.length>0).sort((e,t)=>{let n=si(t)-si(e);return n===0?e.models.length===0&&t.models.length===0?0:t.models.length===0?-1:e.models.length===0?1:e.name.localeCompare(t.name,`zh`):n})},[e.byDayModelsSite,e.byModel,c,o,a,Ct,t,ct,M.hideUnidentified]),vn=(0,d.useMemo)(()=>{let t=X.length,n=ge(),r=e.byDay??{},i=r[n],a=i?i.input+i.output+i.cacheHit+i.cacheMiss:0;return Object.keys(r).sort(),{providersCount:t,tokenTotal:a,rateAgeMinutes:yt>0?Math.floor((Date.now()-yt)/6e4):null,settingsDirty:0}},[X,e.byDay,yt]),yn=(0,d.useMemo)(()=>X.filter(e=>e.models.length>0||e.subscriptions.length>0).map(e=>e.id),[X]),bn=yn.length>0&&yn.every(e=>at.has(e)),Z=()=>{let e=new Set(bn?[]:yn);ot(e),ve([...e])},Sn=(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`model`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`inputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`outputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)})]})}),Cn=e=>(0,m.jsx)(`span`,{className:V.modelCell,children:(0,m.jsxs)(`span`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:V.uncataloguedTag,"data-testid":`billing-uncatalogued-tag`,children:t(`uncatalogued`)}),e.estimatedPricing&&(0,m.jsx)(`span`,{className:V.estimatedTag,"data-testid":`billing-estimated-tag`,children:t(`estimatedPricing`)})]}),(0,m.jsx)(`span`,{className:V.modelProvider,children:wt(e.provider)})]})}),wn=e.bySite?.unknown?.calls??0,Tn=gn.reduce((e,t)=>e+t.estimated,0),En=P.cost>0||wn>0?P.cost:Tn,Q=(0,d.useMemo)(()=>{if(Ge===`all`){let e,t=0;for(let[n,r]of Object.entries(F)){let i=Cr(r);i>t&&(t=i,e=n)}return{cost:En,calls:P.calls,input:P.input,output:P.output,cacheHit:P.cacheHit,cacheMiss:P.cacheMiss,reasoning:P.reasoning??0,peakDay:e,peakTokens:t}}return Er(F,q(),Ge)},[Ge,En,P,F]),On=(0,d.useMemo)(()=>gn.map(e=>({key:e.key,name:e.name,color:e.color})),[gn]),An=mn.length>=2?mn.at(-2)?.cost??0:0,jn=An>0?(Vt-An)/An*100:0;return(0,m.jsx)(p.Modal,{open:!0,onClose:n,title:t(`title`),headless:!0,className:y(V.dashboardModal,`dsh-billing-modal`),children:(0,m.jsxs)(`div`,{className:V.dashboard,"data-testid":`billing-dashboard`,children:[(0,m.jsxs)(`div`,{className:V.dashboardHead,"data-testid":`billing-dashboard-head`,children:[(0,m.jsxs)(`div`,{children:[v(`billing.dashboard.decor`,{position:`head`}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h2`,{className:V.dashboardTitle,children:t(`title`)}),v(`billing.dashboard.decor`,{position:`headTitle`})]}),(0,m.jsxs)(`p`,{className:V.dashboardSubtitle,children:[t(`lastUpdated`),` `,on,e.timezone===void 0?null:` · ${e.timezone.name} (${e.timezone.offset})`]})]}),(0,m.jsxs)(`div`,{className:V.dashboardRight,children:[(0,m.jsx)(`span`,{className:V.currencyToggle,role:`group`,"aria-label":t(`language`),children:[`en`,`zh`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.currencyButton,h===e&&V.currencyButtonActive),"aria-pressed":h===e,"data-testid":`billing-language-${e}`,onClick:()=>{g(e)},children:e===`en`?`EN`:`中`},e))}),(0,m.jsx)(`span`,{className:V.currencyToggle,role:`group`,"aria-label":t(`currency`),children:[`cny`,`usd`,`eur`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.currencyButton,u===e&&V.currencyButtonActive),"aria-pressed":u===e,"data-testid":`billing-currency-${e}`,title:t(e===`cny`?`currencyCny`:e===`usd`?`currencyUsd`:`currencyEur`),onClick:()=>{f(e)},children:e===`cny`?`¥ CNY`:e===`usd`?`$ USD`:`€ EUR`},e))}),a.checked&&(0,m.jsxs)(`span`,{className:y(V.healthBadge,a.available?V.healthBadgeOk:V.healthBadgeBad),children:[(0,m.jsx)(`span`,{className:y(V.healthDot,a.available?V.healthOk:V.healthBad),role:`img`,"aria-label":a.available?t(`healthDotLive`):t(`healthDotFailed`),title:a.available?t(`healthDotLive`):t(`healthDotFailed`)}),a.available?`${t(`healthModelsLive`).replace(`{n}`,String(a.models))}${a.failures>0?` · ${t(`healthVendorsDown`).replace(`{n}`,String(a.failures))}`:``}`:t(`healthVendorsUnavailable`).replace(`{n}`,String(a.failures))]}),(0,m.jsx)(`button`,{type:`button`,className:V.closeButton,"aria-label":t(`close`),"data-testid":`billing-close`,onClick:n,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M18 6 6 18`}),(0,m.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]}),(0,m.jsx)(`nav`,{className:V.tabNav,"data-testid":`billing-tab-nav`,role:`tablist`,"aria-label":t(`title`),children:mr.map(e=>{let n=bi(e.id,vn);return(0,m.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":I===e.id,"aria-controls":`billing-tab-panel-${e.id}`,className:y(V.tabButton,I===e.id&&V.tabButtonActive),"data-testid":`billing-tab-${e.id}`,onClick:()=>{ue(e.id)},children:[(0,m.jsx)(`span`,{className:V.tabRailIcon,"aria-hidden":`true`,children:gr[e.id]}),(0,m.jsx)(`span`,{className:V.tabNavLabel,children:t(e.labelKey)}),n&&(0,m.jsx)(`span`,{className:y(V.tabBadge,n.kind===`warn`&&V.tabBadgeWarn,n.kind===`hot`&&V.tabBadgeHot,n.kind===`violet`&&V.tabBadgeViolet),"data-testid":`billing-tab-badge-${e.id}`,children:n.label})]},e.id)})}),(0,m.jsxs)(`div`,{className:V.dashboardBody,children:[I===`overview`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-overview`,children:[s?.kind===`drift`&&s.spent!==void 0&&pe!==ge()&&(0,m.jsxs)(`div`,{className:V.reconcileNotice,"data-testid":`billing-reconcile-notice`,role:`note`,children:[(0,m.jsx)(`span`,{className:V.reconcileIcon,"aria-hidden":`true`,children:(0,m.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,m.jsx)(`line`,{x1:`12`,y1:`10`,x2:`12`,y2:`16`}),(0,m.jsx)(`line`,{x1:`12`,y1:`7.5`,x2:`12.01`,y2:`7.5`})]})}),(0,m.jsx)(`span`,{className:V.reconcileText,children:t(`reconcileDrift`).replace(`{provider}`,s.provider??``).replace(`{spent}`,U(s.spent)).replace(`{today}`,U(s.todayOfficialCost??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.reconcileDismiss,"data-testid":`billing-reconcile-dismiss`,onClick:ye,children:t(`reconcileDismiss`)})]}),(0,m.jsxs)(`section`,{className:V.hero,"data-testid":`billing-hero`,children:[v(`billing.dashboard.decor`,{position:`hero`}),(0,m.jsxs)(`div`,{className:V.heroTop,children:[(0,m.jsxs)(`div`,{className:V.heroMain,children:[(0,m.jsx)(`span`,{className:V.heroLabel,children:t(`monthCost`)}),(0,m.jsxs)(`div`,{className:V.heroReadout,children:[(0,m.jsx)(`span`,{className:V.heroCurrency,"aria-hidden":`true`,children:bt}),(0,m.jsx)(`span`,{className:V.heroValue,children:U(qt).slice(1)})]}),(0,m.jsxs)(`span`,{className:V.heroMeta,children:[P.calls.toLocaleString(),` `,t(`calls`),en>0&&(0,m.jsxs)(`span`,{className:V.heroPred,children:[` `,t(`monthProjected`),` `,U(en)]})]})]}),tn!==null&&(0,m.jsxs)(`div`,{className:V.heroGauge,"data-testid":`billing-hero-gauge`,children:[(0,m.jsxs)(`div`,{className:V.heroGaugeDial,children:[(0,m.jsxs)(`svg`,{className:V.heroGaugeSvg,viewBox:`0 0 120 120`,"aria-hidden":`true`,children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`heroRingGrad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-cyan)`}),(0,m.jsx)(`stop`,{offset:`55%`,stopColor:`var(--ds-blue)`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-amber)`})]})}),(0,m.jsx)(`circle`,{className:V.heroGaugeTrack,cx:`60`,cy:`60`,r:`52`}),(0,m.jsx)(`circle`,{className:y(V.heroGaugeArc,tn.over&&V.heroGaugeArcOver),cx:`60`,cy:`60`,r:`52`,style:{strokeDasharray:`${tn.remainRatio*326.7} 326.7`},stroke:tn.over?void 0:`url(#heroRingGrad)`})]}),(0,m.jsxs)(`span`,{className:V.heroGaugeCenter,children:[(0,m.jsxs)(`span`,{className:y(V.heroGaugeRemain,tn.over&&V.heroGaugeRemainOver),children:[bt,Xt(tn.remainCny,u).toFixed(2)]}),(0,m.jsx)(`span`,{className:V.heroGaugeLabel,children:t(`budgetRemain`)})]})]}),(0,m.jsxs)(`span`,{className:V.heroGaugeSub,children:[U(qt),` / `,U(x)]})]})]}),(0,m.jsxs)(`div`,{className:V.heroSide,children:[(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`yearCost`)}),(0,m.jsx)(`span`,{className:V.heroSideValue,children:U(Yt)})]}),(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`todayCost`)}),(0,m.jsxs)(`span`,{className:V.heroSideValue,children:[U(Vt),(0,m.jsxs)(`span`,{className:y(V.delta,jn>=0?V.deltaUp:V.deltaDown),children:[jn>=0?`▲`:`▼`,` `,Math.abs(jn).toFixed(1),`%`]})]})]}),en>0&&(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`monthProjected`)}),(0,m.jsx)(`span`,{className:V.heroSideValue,children:U(en)})]}),en<=0&&(0,m.jsx)(`span`,{className:V.heroSideSpacer,"aria-hidden":`true`})]})]}),(e.unpricedModels?.length??0)>0&&!R.has(`unpriced`)&&(0,m.jsxs)(`div`,{className:V.unpricedHint,"data-testid":`billing-unpriced-hint`,children:[(0,m.jsx)(`span`,{className:V.unpricedHintBody,children:t(`unpricedHint`).replace(`{count}`,String(e.unpricedModels?.length??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-unpriced-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`unpriced`)},children:`×`})]}),(e.total.searchCalls??0)>0&&!R.has(`search-estimate`)&&(0,m.jsxs)(`div`,{className:V.unpricedHint,"data-testid":`billing-search-estimate-hint`,children:[(0,m.jsx)(`span`,{className:V.unpricedHintBody,children:t(`searchEstimateHint`).replace(`{count}`,String(e.total.searchCalls??0)).replace(`{each}`,U(e.searchCallEstimateCny??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-search-estimate-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`search-estimate`)},children:`×`})]}),(e.unreadableSessions??0)>0&&!R.has(`unreadable`)&&(0,m.jsxs)(`div`,{className:V.staleNotice,"data-testid":`billing-sessions-unreadable`,children:[(0,m.jsxs)(`div`,{className:V.staleNoticeBody,children:[t(`unreadableNotice`).replace(`{count}`,String(e.unreadableSessions)),(e.unreadableNoLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNoticeSub,"data-testid":`billing-sessions-no-ledger`,children:t(`unreadableNoLedgerNotice`).replace(`{count}`,String(e.unreadableNoLedgerSessions))}),(e.unreadableFormatSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNoticeSub,"data-testid":`billing-sessions-format-unsupported`,children:t(`unreadableFormatNotice`).replace(`{count}`,String(e.unreadableFormatSessions))})]}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-unreadable-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`unreadable`)},children:`×`})]}),(0,m.jsxs)(`div`,{className:V.kpiZone,children:[(0,m.jsxs)(`div`,{className:V.kpiZoneHead,children:[(0,m.jsx)(`span`,{className:V.kpiZoneLabel,children:t(`kpiRange`)}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-kpi-range`,role:`group`,"aria-label":t(`kpiRange`),children:[[`today`,`avgRangeToday`],[`7d`,`avgRange7d`],[`week`,`avgRangeWeek`],[`month`,`avgRangeMonth`],[`all`,`avgRangeAll`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,Ge===e&&V.heatmapRangeButtonActive),"data-testid":`billing-kpi-range-${e}`,"aria-pressed":Ge===e,onClick:()=>{Ke(e),re(e)},children:t(n)},e))})]}),(0,m.jsx)(`section`,{className:V.kpiGrid,"data-testid":`billing-kpi-grid`,children:(()=>{let e=Object.keys(F).sort().slice(-7),n=q(),r=e.indexOf(n),i=(e,t)=>e[t]??0,a=e.map(e=>F[e]?.cost??0),o=e.map(e=>F[e]?.calls??0),s=e.map(e=>{let t=F[e];return t===void 0?0:Cr(t)}),c=e.map(e=>{let t=F[e];return t!==void 0&&t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0}),l=r>0&&i(a,r-1)>0?(i(a,r)-i(a,r-1))/i(a,r-1)*100:0,u=r>0&&i(o,r-1)>0?(i(o,r)-i(o,r-1))/i(o,r-1)*100:0,d=r>0&&i(s,r-1)>0?(i(s,r)-i(s,r-1))/i(s,r-1)*100:0,f=r>0&&i(c,r-1)>0?i(c,r)-i(c,r-1):0,h=(e,t)=>(0,m.jsx)(`svg`,{viewBox:`0 0 28 12`,preserveAspectRatio:`none`,style:{display:`block`,width:`100%`,height:`12px`},children:e.map((n,r)=>{let i=n/Math.max(...e,1)*10,a=r*4;return(0,m.jsx)(`rect`,{x:a,y:12-i,width:`2.5`,height:i,fill:t,opacity:r===e.length-1?1:.6},r)})}),g=e=>(0,m.jsxs)(`span`,{className:y(V.kpiDelta,e>0?V.kpiDeltaUp:e<0?V.kpiDeltaDown:V.kpiDeltaFlat),children:[e>0?`▲`:e<0?`▼`:``,` `,Math.abs(e).toFixed(1),`%`]});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-tile`,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCacheHit`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`cacheHitRate`)})}),g(f)]}),(0,m.jsx)(`span`,{className:y(V.kpiValue,V.kpiGreen),children:$t(Q.cacheHit+Q.cacheMiss>0?Q.cacheHit/(Q.cacheHit+Q.cacheMiss)*100:0)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(c,`var(--ds-cyan)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[J(Q.cacheHit),` / `,J(Q.cacheHit+Q.cacheMiss),(P.cacheWrite??0)>0?` · ${t(`tokenCacheWrite`)} ${J(P.cacheWrite??0)}`:``]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescTokens`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokens`)})}),g(d)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:J(Q.input+Q.output)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(s,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[t(`inputTokens`),` `,J(Q.input),` · `,t(`outputTokens`),` `,J(Q.output)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-avg`,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescAvgCost`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`avgCost`)})}),g(l)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:U(Q.calls>0?Q.cost/Q.calls:0)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(a,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[t(`calls`),` `,Q.calls.toLocaleString()]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCalls`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`calls`)})}),g(u)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:Q.calls.toLocaleString()}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(o,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[gn.length,` `,t(`models`)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-think`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescReasoning`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenReasoningShare`)})})}),(0,m.jsx)(`span`,{className:y(V.kpiValue,V.kpiGreen),children:$t(Q.output>0?Q.reasoning/Q.output*100:0)}),(0,m.jsx)(`span`,{className:V.kpiDetail,children:J(Q.reasoning)})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-io`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescIo`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenIo`)})})}),(0,m.jsx)(`span`,{className:V.kpiValue,children:(Q.output>0?Q.input/Q.output:0).toFixed(2)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[J(Q.input),` / `,J(Q.output)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-peak`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescPeak`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenPeak`)})})}),(0,m.jsx)(`span`,{className:V.kpiValue,children:Q.peakTokens>0?un(Q.peakTokens):`—`}),(0,m.jsx)(`span`,{className:V.kpiDetail,children:Q.peakDay??`—`})]})]})})()})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-heatmap`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`heatmap`)}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-heatmap-metric`,role:`group`,"aria-label":t(`heatmap`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,Ee===e&&V.heatmapRangeButtonActive),"data-testid":`billing-heatmap-metric-${e}`,"aria-pressed":Ee===e,onClick:()=>{De(e)},children:t(e===`cost`?`metricCost`:`metricTokens`)},e))}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-heatmap-range`,role:`group`,"aria-label":t(`heatmap`),children:[`month`,`half`,`year`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,we===e&&V.heatmapRangeButtonActive),"data-testid":`billing-heatmap-range-${e}`,"aria-pressed":we===e,onClick:()=>{Te(e)},children:t(e===`month`?`heatmapMonth`:e===`half`?`heatmapHalf`:`heatmapYear`)},e))}),(0,m.jsxs)(`span`,{className:V.panelHint,"data-testid":`billing-heatmap-summary`,children:[t(`heatmapTotal`),` `,Ee===`tokens`?J(dn):U(dn),` · `,t(`activeDays`),` `,fn,` · `,t(`streakDays`),` `,pn]})]}),(0,m.jsx)(zn,{days:Y,currency:u,t,range:we,unit:Ee})]})]}),I===`settings`&&(0,m.jsx)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-settings`,children:(0,m.jsxs)(`div`,{className:V.settingsLayout,children:[(0,m.jsx)(`aside`,{className:V.settingsNav,"data-testid":`billing-settings-nav`,role:`navigation`,"aria-label":`settings`,children:[{id:`display-pref`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`path`,{d:`M5 3v10M11 3v10`}),(0,m.jsx)(`circle`,{cx:`5`,cy:`6.5`,r:`1.8`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`9.5`,r:`1.8`})]}),label:t(`settingsNavDisplayPref`)},{id:`budget`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M5 3l3 4 3-4M8 7v6M5.5 9.5h5M5.5 12h5`})}),label:t(`settingsNavBudget`)},{id:`alert`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`path`,{d:`M8 2a4 4 0 0 1 4 4v3l1.5 2.5h-11L4 9V6a4 4 0 0 1 4-4z`}),(0,m.jsx)(`path`,{d:`M6.5 13.5a1.5 1.5 0 0 0 3 0`})]}),label:t(`settingsNavAlert`)},{id:`display`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 2a6 6 0 0 1 0 12z`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavDisplay`)},{id:`advanced`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M8 2v12M2.8 5l10.4 6M13.2 5L2.8 11`})}),label:t(`settingsNavAdvanced`),advanced:!0},{id:`about`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 7.5V11`}),(0,m.jsx)(`circle`,{cx:`8`,cy:`5.2`,r:`0.9`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavAbout`)}].map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(V.settingsNavItem,Ne===e.id&&V.settingsNavItemActive,e.advanced&&V.settingsNavItemAdvanced),"data-testid":`billing-settings-nav-${e.id}`,onClick:()=>{Ve(e.id)},children:[(0,m.jsx)(`span`,{className:V.settingsNavIcon,"aria-hidden":`true`,children:e.icon}),e.label]},e.id))}),(0,m.jsxs)(`div`,{className:V.settingsPane,children:[(0,m.jsx)(`input`,{className:y(V.ubSearch,V.settingsSearch),type:`search`,value:Re,placeholder:t(`settingsSearchPlaceholder`),"aria-label":t(`settingsSearchPlaceholder`),"data-testid":`billing-settings-search`,onChange:e=>{ze(e.target.value)}}),Re.trim()!==``&&Mi(Re)&&(0,m.jsx)(`p`,{className:V.setCardDesc,"data-testid":`billing-settings-search-empty`,children:t(`settingsSearchEmpty`).replace(`{query}`,Re.trim())}),(0,m.jsxs)(`div`,{hidden:Be(ji.display),className:V.setCard,id:`settings-display-pref`,"data-testid":`billing-density-motion-card`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsx)(`h3`,{className:V.setCardTitle,children:t(`settingsSectionDisplay`)})})}),(0,m.jsxs)(`div`,{className:V.densityRow,children:[(0,m.jsxs)(`div`,{className:V.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`densityLabel`)}),(0,m.jsx)(`span`,{children:t(`densityHint`)})]}),(0,m.jsx)(`div`,{className:V.densityButtons,"data-testid":`billing-density-buttons`,children:[`compact`,`default`,`comfortable`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.densityButton,z===e&&V.densityButtonActive,e===`comfortable`&&V.densityButtonComfortable),"data-testid":`billing-density-${e}`,onClick:()=>{He(e)},children:t(e===`compact`?`densityCompact`:e==="default"?`densityDefault`:`densityComfortable`)},e))})]}),(0,m.jsxs)(`div`,{className:V.densityRow,children:[(0,m.jsxs)(`div`,{className:V.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`motionLabel`)}),(0,m.jsx)(`span`,{children:t(`motionHint`)})]}),(0,m.jsx)(`div`,{className:V.densityButtons,"data-testid":`billing-motion-buttons`,children:[`off`,`subtle`,`rich`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.densityButton,ke===e&&V.densityButtonActive),"data-testid":`billing-motion-${e}`,onClick:()=>{Ue(e)},children:t(e===`off`?`motionOff`:e===`subtle`?`motionSubtle`:`motionRich`)},e))})]})]}),(0,m.jsxs)(`section`,{hidden:Be(ji.budget),className:V.setCard,"data-testid":`billing-budget`,id:`settings-budget`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`budget`),(0,m.jsx)(Ci,{label:t(`budgetHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":b,"aria-label":t(`budget`),"data-testid":`billing-budget-toggle`,className:y(V.switch,b&&V.switchOn),onClick:S,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),b&&(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`budgetAmount`)}),(0,m.jsxs)(`span`,{className:V.inp,"data-testid":`billing-budget-input-wrap`,children:[(0,m.jsx)(`span`,{className:V.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:V.budgetInput,"data-testid":`billing-budget-input`,type:`number`,min:0,step:1,value:x===0?``:x,placeholder:e.budget===void 0?`0`:String(e.budget),"aria-label":`${t(`budget`)}(${u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`})`,title:`${t(`budget`)}(${u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`})`,onChange:e=>{C(e.target.valueAsNumber)}})]})]}),x>0&&(()=>{let e=qt/x*100;return(0,m.jsx)(`div`,{className:V.ctlRowStretch,children:(0,m.jsx)(`div`,{className:V.prog,role:`progressbar`,"aria-valuenow":Math.min(e,100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t(`budget`),"data-testid":`billing-budget-track`,children:(0,m.jsx)(`div`,{className:y(V.progFill,e>=100&&V.budgetFillOver,e>=80&&e<100&&V.budgetFillWarn),style:{width:`${Math.min(e,100)}%`}})})})})(),x>0&&(0,m.jsx)(`p`,{className:V.setCardDesc,"data-testid":`billing-budget-value`,children:t(`budgetSummary`).replace(`{used}`,U(qt)).replace(`{total}`,U(x))})]}),(0,m.jsxs)(`div`,{className:V.ctlCol,"data-testid":`billing-model-budgets`,children:[(0,m.jsxs)(`span`,{className:V.modelBudgetTitle,children:[t(`modelBudgetTitle`),(0,m.jsx)(Ci,{label:t(`modelBudgetHint`),t})]}),it.length===0&&(0,m.jsx)(`p`,{className:V.modelBudgetHint,children:t(`emptyHint`)}),(0,m.jsx)(`div`,{className:V.modelBudgetList,children:it.map(e=>(0,m.jsxs)(`div`,{className:V.modelBudgetRow,children:[(0,m.jsx)(`span`,{className:V.modelBudgetName,title:e.name??e.key,children:e.name??e.key}),(0,m.jsx)(`span`,{className:V.modelBudgetCost,"data-testid":`billing-model-budget-cost-${e.key}`,children:U(e.cost)}),(0,m.jsxs)(`span`,{className:V.inp,children:[(0,m.jsx)(`span`,{className:V.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:V.budgetInput,type:`number`,min:0,step:1,value:w[e.key]??``,placeholder:t(`modelBudgetPlaceholder`),"aria-label":`${t(`modelBudgetTitle`)} · ${e.name??e.key}`,"data-testid":`billing-model-budget-${e.key}`,onChange:t=>{ee(e.key,t.target.valueAsNumber)}})]})]},e.key))})]})]}),(0,m.jsxs)(`section`,{hidden:Be(ji.alert),className:V.setCard,"data-testid":`billing-peak-alert-settings`,id:`settings-alert`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`peakAlert`),(0,m.jsx)(Ci,{label:t(`peakAlertHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":E.enabled,"aria-label":t(`peakAlert`),"data-testid":`billing-peak-alert-toggle`,className:y(V.switch,E.enabled&&V.switchOn),onClick:()=>{D({...E,enabled:!E.enabled})},children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),E.enabled&&(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`label`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertLeadMin`)}),(0,m.jsx)(`span`,{className:V.inp,children:(0,m.jsx)(`input`,{type:`number`,min:1,max:30,step:1,value:E.leadMin,className:V.budgetInput,"aria-label":t(`peakAlertLeadMin`),onChange:e=>{let t=Number(e.target.valueAsNumber);D({...E,leadMin:Number.isFinite(t)?Math.min(30,Math.max(1,Math.round(t))):E.leadMin})}})})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertPos`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertPos`),children:[`bottom-right`,`center`].map(e=>(0,m.jsxs)(`label`,{className:V.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-pos`,checked:E.position===e,onChange:()=>D({...E,position:e})}),(0,m.jsx)(`span`,{className:V.rdoDot,"aria-hidden":`true`}),t(e===`bottom-right`?`peakAlertPosCorner`:`peakAlertPosCenter`)]},e))})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertMode`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertMode`),children:[`both`,`peak`,`offPeak`].map(e=>(0,m.jsxs)(`label`,{className:V.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-mode`,checked:E.mode===e,onChange:()=>D({...E,mode:e})}),(0,m.jsx)(`span`,{className:V.rdoDot,"aria-hidden":`true`}),t(e===`both`?`peakAlertModeBoth`:e===`peak`?`peakAlertModePeak`:`peakAlertModeOff`)]},e))})]}),(0,m.jsxs)(`label`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertWebNotify`)}),(0,m.jsx)(`input`,{type:`checkbox`,checked:E.webNotify,"aria-label":t(`peakAlertWebNotify`),onChange:e=>{D({...E,webNotify:e.target.checked})}})]}),(0,m.jsx)(`div`,{className:V.ctlRow,children:(0,m.jsx)(`button`,{type:`button`,className:V.btn,onClick:O,children:t(`peakAlertPreview`)})})]})]}),(0,m.jsx)(`section`,{hidden:Be(ji.toggles),className:V.setCard,"data-testid":`billing-toggle-setting`,id:`settings-display`,children:(0,m.jsxs)(`div`,{className:V.setGrid3,children:[(0,m.jsx)(`div`,{className:V.setCell,"data-testid":`billing-usage-stats-tool-setting`,children:(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`usageStatsTool`),(0,m.jsx)(Ci,{label:t(`usageStatsToolHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ft,"aria-label":t(`usageStatsTool`),"data-testid":`billing-usage-stats-tool-toggle`,className:y(V.switch,ft&&V.switchOn),onClick:mt,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})}),(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-livecost-setting`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`liveCostBar`),(0,m.jsx)(Ci,{label:t(`liveCostBarHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ae.show,"aria-label":t(`liveCostBar`),"data-testid":`billing-livecost-toggle`,className:y(V.switch,ae.show&&V.switchOn),onClick:()=>oe({...ae,show:!ae.show}),children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),ae.show&&(0,m.jsxs)(`div`,{className:V.rdoRow,"data-testid":`billing-livecost-position`,children:[(0,m.jsx)(`span`,{className:V.rdoLabel,children:t(`liveCostBarPosition`)}),(0,m.jsx)(Pi,{liveCostPrefs:ae,onLiveCostPrefs:oe,t})]})]}),(0,m.jsx)(`div`,{className:V.setCell,"data-testid":`billing-site-list-setting`,children:(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`siteListDisplay`),(0,m.jsx)(Ci,{label:t(`siteListDisplayHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":M.hideUnidentified,"aria-label":t(`siteListDisplay`),"data-testid":`billing-site-hide-unidentified`,className:y(V.switch,M.hideUnidentified&&V.switchOn),onClick:()=>ie({hideUnidentified:!M.hideUnidentified}),children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})})]})}),(0,m.jsx)(`section`,{hidden:Be(ji.displayExtra),className:V.setCard,"data-testid":`billing-display-setting`,id:`settings-display-extra`,children:(0,m.jsxs)(`div`,{className:V.setGrid2,children:[(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-float-setting`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`floatWindow`),(0,m.jsx)(Ci,{label:t(`floatWindowHint`),t})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`floatMode`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-float-mode`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,k.mode===`combined`&&V.floatModeBtnOn),"data-testid":`billing-float-mode-combined`,onClick:()=>te({mode:`combined`,targets:k.targets}),children:t(`floatModeCombined`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,k.mode===`subscription`&&V.floatModeBtnOn),"data-testid":`billing-float-mode-subscription`,onClick:()=>te({mode:`subscription`,targets:k.targets}),children:t(`floatModeSubscription`)})]})]}),k.mode===`subscription`&&(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`floatTargets`)}),(0,m.jsxs)(`span`,{className:V.ctlGroup,"data-testid":`billing-float-targets`,children:[H.map(e=>{let t=k.targets.includes(e.id);return(0,m.jsxs)(`label`,{className:V.floatTarget,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:t,"data-testid":`billing-float-target-${e.id}`,onChange:()=>te({mode:`subscription`,targets:t?k.targets.filter(t=>t!==e.id):[...k.targets,e.id]})}),(0,m.jsx)(`span`,{className:V.floatTargetLabel,children:e.label})]},e.id)}),H.length===0&&(0,m.jsx)(`span`,{className:V.setCardDesc,children:t(`floatNoTargetsHint`)})]})]})]})]}),(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-card-setting`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`cardDisplay`),(0,m.jsx)(Ci,{label:t(`cardDisplayHint`),t})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardMetric`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-metric`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.metric===`money`&&V.floatModeBtnOn),"data-testid":`billing-card-money`,onClick:()=>j({...A,metric:`money`}),children:t(`cardMetricMoney`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.metric===`tokens`&&V.floatModeBtnOn),"data-testid":`billing-card-tokens`,onClick:()=>j({...A,metric:`tokens`}),children:t(`cardMetricTokens`)})]})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardSpan`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-span`,children:[[`day`,`cardSpanDay`],[`week`,`cardSpanWeek`],[`month`,`cardSpanMonth`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.span===e&&V.floatModeBtnOn),"data-testid":`billing-card-span-${e}`,"aria-pressed":A.span===e,onClick:()=>j({...A,span:e}),children:t(n)},e))})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardDeltaBadge`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-delta`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.showDelta&&V.floatModeBtnOn),"data-testid":`billing-card-delta-show`,"aria-pressed":A.showDelta,onClick:()=>j({...A,showDelta:!0}),children:t(`cardDeltaShow`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,!A.showDelta&&V.floatModeBtnOn),"data-testid":`billing-card-delta-hide`,"aria-pressed":!A.showDelta,onClick:()=>j({...A,showDelta:!1}),children:t(`cardDeltaHide`)})]})]})]})]})]})}),(0,m.jsx)(`div`,{hidden:Be(ji.advanced),id:`settings-advanced`,children:(0,m.jsx)(Oi,{userPrices:r,onUserPrices:i,t})}),(0,m.jsx)(`div`,{hidden:Be(ji.about),id:`settings-about`,children:(0,m.jsx)(kn,{t,version:e.pluginVersion})}),(0,m.jsxs)(`section`,{hidden:Be(ji.about),className:V.setCard,"data-testid":`billing-more-works`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsx)(`h3`,{className:V.setCardTitle,children:t(`moreWorksTitle`)})})}),(0,m.jsxs)(`div`,{className:V.moreWorkList,children:[(0,m.jsxs)(`a`,{className:V.moreWorkRow,href:`https://github.com/kenz1117/dsh-engram`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-engram`,children:[(0,m.jsx)(`span`,{className:V.moreWorkName,children:t(`adEngramName`)}),(0,m.jsx)(`span`,{className:V.moreWorkDesc,children:t(`adEngramDesc`)})]}),(0,m.jsxs)(`a`,{className:V.moreWorkRow,href:`https://github.com/kenz1117/dsh-ui-rainbowspeak`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-rainbowspeak`,children:[(0,m.jsx)(`span`,{className:V.moreWorkName,children:t(`adRainbowName`)}),(0,m.jsx)(`span`,{className:V.moreWorkDesc,children:t(`adRainbowDesc`)})]})]})]})]})]})}),I===`trends`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-trends`,children:[(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-trend`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`trend`)}),v(`billing.dashboard.decor`,{position:`trend`}),(0,m.jsxs)(`span`,{className:V.ubCardControlGroup,children:[(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":t(`trend`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,de===e&&V.rangeButtonActive),"aria-pressed":de===e,"data-testid":`billing-trend-${e}d`,onClick:()=>{fe(e)},children:t(e===7?`trend7d`:`trend30d`)},e))}),(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":t(`trendMetric`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,N===e&&V.rangeButtonActive),"aria-pressed":N===e,"data-testid":`billing-trend-metric-${e}`,onClick:()=>{ce(e)},children:t(e===`cost`?`trendMetricCost`:`trendMetricTokens`)},e))})]}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:on})]}),(0,m.jsx)(xn,{data:mn,models:On,currency:u,metric:N,t})]}),_.length>0&&(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-rounds`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`rounds`)}),Nt.length>0&&(0,m.jsxs)(`span`,{className:V.ubTagError,"data-testid":`billing-rounds-flag-count`,children:[Nt.length,` `,t(`anomaly`)]})]}),(0,m.jsx)(`p`,{className:V.ubCardSub,children:t(`roundsHint`).replace(`{count}`,String(_.length))}),(0,m.jsx)(Nn,{rounds:_,flags:Nt,currency:u,t})]}),e.byTier!==void 0&&(()=>{let e=Pt.peak+Pt.offPeak;if(e<=0)return null;let n=Pt.peak/e*100;return(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-share`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`peakShare`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:t(`peakSharePerCall`)})]}),(0,m.jsxs)(`div`,{className:V.shareTrack,"data-testid":`billing-share-track`,children:[(0,m.jsx)(`div`,{className:y(V.shareSeg,V.shareSegPeak),style:{width:`${n}%`}}),(0,m.jsx)(`div`,{className:y(V.shareSeg,V.shareSegOff),style:{width:`${100-n}%`}})]}),(0,m.jsxs)(`div`,{className:V.shareLegend,children:[(0,m.jsxs)(`span`,{className:V.shareItem,children:[(0,m.jsx)(`span`,{className:V.shareDot,style:{background:`var(--ds-blue)`}}),t(`peak`),(0,m.jsxs)(`span`,{className:V.shareValue,"data-testid":`billing-share-peak`,children:[U(Pt.peak),` · `,n.toFixed(1),`%`]})]}),(0,m.jsxs)(`span`,{className:V.shareItem,children:[(0,m.jsx)(`span`,{className:V.shareDot,style:{background:`color-mix(in srgb, var(--ds-blue) 30%, var(--dsb-3))`}}),t(`offPeak`),(0,m.jsxs)(`span`,{className:V.shareValue,"data-testid":`billing-share-offpeak`,children:[U(Pt.offPeak),` · `,(100-n).toFixed(1),`%`]})]})]}),Ft>0&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-share-savings`,children:t(`offPeakSavings`).replace(`{amount}`,U(Ft))})]})})()]}),I===`providers`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-providers`,children:[_n.length>0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-relay-quota`,children:[(0,m.jsx)(`div`,{className:V.panelHead,children:(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`panelRelayQuota`)})}),(0,m.jsx)(`div`,{className:V.providerGroupList,"data-testid":`billing-relay-quotas`,children:_n.map(e=>(0,m.jsxs)(`div`,{className:V.siteRow,"data-testid":`billing-relay-quota`,children:[(0,m.jsxs)(`span`,{className:V.siteRowName,children:[(0,m.jsx)(`span`,{className:y(V.siteKindTag,oi[e.kind]),children:ai(e.kind,t)}),(0,m.jsx)(`span`,{className:V.siteRowTitle,children:e.origin})]}),(0,m.jsxs)(`span`,{className:V.siteRowMeta,children:[e.balance!==void 0&&(0,m.jsxs)(`span`,{className:V.siteRowCost,children:[t(`relayBalance`),` `,e.balance.toFixed(2)]}),(e.windows?.length??0)>0?e.windows?.map(e=>{let n=e.remainingPercent<20;return(0,m.jsxs)(`span`,{className:y(V.siteRowCalls,n&&V.siteRowCallsLow),children:[t(`relayWindowUsed`),` `,e.usedPercent,`%`]},e.kind)}):(0,m.jsx)(`span`,{className:V.siteRowCalls,children:t(`relayNoQuota`)})]})]},e.route))})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-providers`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`providerBilling`)}),v(`billing.dashboard.decor`,{position:`models`}),(0,m.jsx)(`span`,{className:V.panelHint,children:e.updatedAt===void 0?``:`${t(`lastUpdated`)} ${li(e.updatedAt)}`})]}),se&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-subscriptions-stale`,children:t(`subscriptionsStale`)}),(0,m.jsxs)(`div`,{className:V.providerCtlRow,"data-testid":`billing-provider-controls`,children:[(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,disabled:yn.length===0,onClick:Z,children:t(bn?`collapseAll`:`expandAll`)}),(0,m.jsxs)(`span`,{className:V.providerTodayToggle,children:[(0,m.jsx)(`span`,{children:t(`todayOnly`)}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ct,"data-testid":`billing-provider-today-toggle`,className:y(V.switch,ct&&V.switchOn),onClick:dt,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})]}),X.length===0?(0,m.jsxs)(`div`,{className:V.emptyState,"data-testid":`billing-provider-empty`,children:[(0,m.jsxs)(`span`,{className:V.emptyIll,"aria-hidden":`true`,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 96 64`,fill:`none`,children:[(0,m.jsx)(`line`,{x1:`6`,y1:`58`,x2:`90`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`line`,{x1:`6`,y1:`6`,x2:`6`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`path`,{d:`M14 50 L28 40 L42 44 L56 26 L70 30 L82 14`,stroke:`var(--ds-border-strong)`,strokeWidth:`1.5`,strokeLinecap:`round`,fill:`none`,strokeDasharray:`3 3`})]}),(0,m.jsx)(`span`,{className:V.emptyIllDot})]}),(0,m.jsx)(`span`,{className:V.emptyTitle,children:t(ct?`todayNoConsumption`:`noData`)}),(0,m.jsx)(`span`,{className:V.emptyDesc,children:t(`emptyHint`)})]}):(0,m.jsx)(`div`,{className:V.providerGroupList,"data-testid":`billing-provider-groups`,children:X.map(e=>{let n=e.models.length>0||e.subscriptions.length>0,r=n&&at.has(e.id);return(0,m.jsxs)(`div`,{className:V.providerGroup,"data-testid":`billing-provider-group`,children:[(0,m.jsxs)(`div`,{className:y(V.providerGroupHead,n&&V.providerGroupCollapsible),"data-testid":`billing-provider-group-head`,"aria-expanded":n?r:void 0,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:n?()=>{st(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),st(e.id))}:void 0,children:[(0,m.jsxs)(`span`,{className:V.providerGroupTitle,children:[(0,m.jsx)(`span`,{className:y(V.healthDot,e.dot),role:`img`,"aria-label":wi(e.dot,t),title:wi(e.dot,t)}),(()=>{let n=wt(e.name),r=e.channelKind===`direct`?nr(n):void 0,i=e.channelKind===`direct`?t(`directTag`):e.channelKind===`site`?t(`relayTag`):e.channelKind===`unknown`?t(`unknownTag`):void 0;return(0,m.jsxs)(m.Fragment,{children:[i!==void 0&&(0,m.jsx)(`span`,{className:y(V.kindBadge,e.channelKind===`site`&&V.kindBadgeRelay,e.channelKind===`unknown`&&V.kindBadgeUnknown),"data-testid":`billing-kind-badge`,children:i}),e.channelKind!==`unknown`&&(0,m.jsx)(`span`,{className:V.providerGroupName,children:r??n})]})})(),e.subscriptions.length>0&&(0,m.jsxs)(`span`,{className:V.providerGroupBadge,"data-testid":`billing-provider-sub-count`,children:[e.subscriptions.length,` `,t(`planCountUnit`)]})]}),(0,m.jsxs)(`span`,{className:V.providerGroupMeta,children:[(0,m.jsxs)(`span`,{className:V.providerGroupCost,"data-testid":`billing-provider-cost`,children:[(0,m.jsx)(`span`,{className:V.providerGroupCostLabel,children:t(`cost`)}),e.channelKind===`unknown`?(0,m.jsx)(`span`,{className:V.na,children:`—`}):(0,m.jsx)(`span`,{className:V.providerGroupCostValue,children:U(si(e))})]}),!Rt(e)&&e.balance!==void 0?(0,m.jsxs)(`span`,{className:V.providerGroupBalance,"data-testid":`billing-provider-balance`,children:[(0,m.jsx)(`span`,{className:V.providerGroupBalanceLabel,children:t(`balance`)}),zt(e.balance)]}):(0,m.jsx)(`span`,{className:V.providerGroupBalance,"aria-hidden":`true`}),qr(e.name)===void 0?(0,m.jsx)(`span`,{className:V.providerGroupRecharge,"aria-hidden":`true`}):(0,m.jsx)(`a`,{className:V.providerGroupRecharge,"data-testid":`billing-group-recharge`,href:qr(e.name),target:`_blank`,rel:`noreferrer`,title:t(`rechargeHint`),"aria-label":`${wt(e.name)} ${t(`recharge`)}`,onClick:e=>{e.stopPropagation()},children:t(`recharge`)})]})]}),e.models.length>0&&(0,m.jsx)(`div`,{className:V.providerStatRow,"data-testid":`billing-provider-stat-row`,children:(()=>{let n=e.models.reduce((e,t)=>({calls:e.calls+t.calls,input:e.input+t.input,output:e.output+t.output}),{calls:0,input:0,output:0}),r=n.input>0?e.models.reduce((e,t)=>e+t.cacheHitRate,0)/e.models.length:0;return[{lbl:t(`calls`),val:n.calls.toLocaleString(),sub:``},{lbl:t(`inputTokens`),val:J(n.input),sub:r>0?`${t(`cacheHitRate`)} ${r.toFixed(0)}%`:``},{lbl:t(`outputTokens`),val:J(n.output),sub:``},{lbl:t(`cost`),val:U(si(e)),sub:e.models.length===1?``:`${e.models.length} ${t(`models`)}`}].map((e,t)=>(0,m.jsxs)(`div`,{className:V.providerStatCell,children:[(0,m.jsx)(`div`,{className:V.providerStatLbl,children:e.lbl}),(0,m.jsx)(`div`,{className:V.providerStatVal,children:e.val}),e.sub!==``&&(0,m.jsx)(`div`,{className:V.providerStatSub,children:e.sub})]},t))})()}),r&&(0,m.jsxs)(m.Fragment,{children:[e.channelKind===`unknown`&&(0,m.jsx)(`p`,{className:V.unknownHint,"data-testid":`billing-unknown-hint`,children:t(`unknownChannelHint`)}),e.models.length>0&&(0,m.jsx)(`div`,{className:V.tableScroll,"data-testid":`billing-table-scroll`,children:(0,m.jsxs)(`table`,{className:V.modelTable,children:[Sn,(0,m.jsx)(`tbody`,{children:e.models.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:Cn(e)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.input)}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.output)}),(0,m.jsx)(`td`,{className:V.numCol,children:$t(e.cacheHitRate)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.plan?(0,m.jsxs)(`span`,{className:V.planTag,children:[e.estimated>0?(0,m.jsxs)(`span`,{children:[`≈`,U(e.estimated)]}):null,(0,m.jsx)(`span`,{className:V.planTagBadge,"data-testid":`billing-plan-badge`,children:t(`subscriptionTag`)})]}):e.actual===void 0?e.estimated>0?(0,m.jsxs)(`span`,{title:t(`cellEstimateHint`),children:[`≈`,U(e.estimated)]}):(0,m.jsx)(`span`,{className:V.na,children:`—`}):(()=>{let t=e.officialCost,n=e.actual-t;return t>0&&n>0?(0,m.jsxs)(`span`,{className:V.bucketCost,children:[(0,m.jsx)(`span`,{className:V.bucketOfficial,children:U(t)}),(0,m.jsx)(`span`,{className:V.bucketSep,children:`/`}),(0,m.jsx)(`span`,{className:V.bucketThird,children:U(n)})]}):U(e.actual)})()})]},e.key))})]})}),e.subscriptions.length>0&&(0,m.jsx)(`div`,{className:V.subscriptionGrid,"data-testid":`billing-subscriptions-grid`,children:e.subscriptions.map(e=>{let n=ri(e.status,t);return(0,m.jsxs)(`div`,{className:y(V.subscriptionCard,V.subscriptionCardUpgraded),"data-testid":`billing-subscription-card`,children:[(0,m.jsxs)(`div`,{className:V.subscriptionHead,children:[(0,m.jsx)(`span`,{className:V.subscriptionName,children:wt(e.displayName)}),e.planType===`code`&&(()=>{let n=We(e.provider),r=n===void 0?void 0:t(`subscriptionFeePerMonth`).replace(`{amount}`,n.currency===`USD`?`$${n.amount}`:`¥${n.amount}`);return(0,m.jsxs)(`span`,{className:V.subscriptionPlan,"data-kind":`code`,children:[r??(e.subscriptionAmount!==void 0&&e.subscriptionAmount>0?t(`subscriptionFeePerMonth`).replace(`{amount}`,U(e.subscriptionAmount)):t(`planTypeCode`)),n?.label!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionTier,"data-testid":`billing-tier-${e.provider}`,children:n.label}),n!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionAuto,"data-testid":`billing-auto-${e.provider}`,children:t(`subscriptionAutoDetect`)})]})})(),e.planType===`token`&&(0,m.jsx)(`span`,{className:V.subscriptionPlan,"data-kind":`token`,children:t(`planTypeToken`)}),e.plan!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionPlan,children:e.plan})]}),n!==``&&(0,m.jsx)(`div`,{className:V.subscriptionStatus,children:n}),e.windows.length===0&&n===``&&(0,m.jsx)(`div`,{className:V.subscriptionStatus,children:t(`subscriptionNoApi`)}),e.windows.map(e=>(0,m.jsx)(Si,{window:e,t},e.kind))]},e.provider)})})]})]},e.id)})})]}),(0,m.jsxs)(`div`,{className:V.exportBar,"data-testid":`billing-export-bar`,role:`group`,"aria-label":t(`export`),children:[(0,m.jsx)(`span`,{className:V.exportLabel,children:t(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-day`,onClick:()=>{ln(cn(`usage-daily`,`csv`,Object.keys(F)),rn(F),`text/csv`)},children:t(`exportCsvDay`)}),e.bySession!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-sessions`,onClick:()=>{ln(cn(`usage-sessions`,`csv`,Object.keys(F)),sn(e.bySession??[]),`text/csv`)},children:t(`exportCsvSession`)}),e.bySite!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-sites`,onClick:()=>{ln(cn(`usage-sites`,`csv`,Object.keys(F)),an(e.bySite??{}),`text/csv`)},children:t(`exportCsvSite`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-json`,onClick:()=>{ln(cn(`usage-stats`,`json`,Object.keys(F)),JSON.stringify(e,null,2),`application/json`)},children:t(`exportJson`)})]}),e.bySession!==void 0&&(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-sessions`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`sessions`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:e.bySession.length>20?t(`sessionOverflow`).replace(`{limit}`,`20`).replace(`{total}`,String(e.bySession.length)):`${e.bySession.length}`}),e.bySession.length>0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-sessions-view-all`,onClick:()=>{Qe(!0)},children:t(`sessionsViewAll`).replace(`{count}`,String(e.bySession.length))})]}),(e.staleLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-sessions-stale`,children:t(`staleLedgerNotice`).replace(`{count}`,String(e.staleLedgerSessions))}),(0,m.jsx)(`div`,{className:V.ubTablewrap,"data-testid":`billing-sessions-table`,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[nt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:V.emptyRow,children:t(`noData`)})}),nt.slice(0,20).map(e=>{let n=e.children!==void 0||e.subs!==void 0,r=n&&Ye.has(e.id),i=ci(e),a=e=>(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:U(e.cost)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.lastActive>0?`${q(e.lastActive)} ${li(e.lastActive)}`:`—`})]});return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:n?V.sessionGroupRow:void 0,"aria-expanded":n?r:void 0,tabIndex:n?0:void 0,onClick:n?()=>{tt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),tt(e.id))}:void 0,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),"data-testid":`billing-session-stale`,children:t(`sessionStaleBadge`)}),(i.calls>0||i.cost>0)&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),"data-testid":`billing-session-sub`,children:i.cost>0?t(`sessionSubCost`).replace(`{cost}`,U(i.cost)):t(`sessionSubCalls`).replace(`{calls}`,i.calls.toLocaleString())})]}),a(e)]}),r&&e.children?.map(e=>(0,m.jsxs)(`tr`,{className:V.sessionChildRow,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:V.modelProvider,children:e.id.slice(0,8)})}),a(e)]},e.id)),r&&e.subs?.map(e=>(0,m.jsxs)(`tr`,{className:V.sessionChildRow,"data-testid":`billing-session-sub-row`,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),children:t(`sessionSubRow`)}),(0,m.jsx)(`span`,{className:V.modelProvider,children:e.title??e.id.slice(0,8)})]}),a(e)]},e.id))]},e.id)})]})]})}),Ze&&(0,m.jsxs)(`div`,{className:V.sessionViewer,"data-testid":`billing-session-viewer`,children:[(0,m.jsxs)(`div`,{className:V.sessionViewerHead,children:[(0,m.jsx)(`h3`,{className:V.sessionViewerTitle,children:t(`sessions`)}),(0,m.jsx)(`input`,{className:V.ubSearch,type:`search`,value:$e,placeholder:t(`sessionViewerSearch`),"aria-label":t(`sessionViewerSearch`),"data-testid":`billing-session-viewer-search`,onChange:e=>{et(e.target.value)}}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-session-viewer-close`,onClick:()=>{Qe(!1),et(``)},children:t(`close`)})]}),(0,m.jsx)(`div`,{className:V.sessionViewerList,"data-testid":`billing-session-viewer-list`,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[rt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:V.emptyRow,children:t(`noData`)})}),rt.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.cwd!==void 0&&(0,m.jsx)(`span`,{className:V.modelProvider,children:Ai(e.cwd)}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),children:t(`sessionStaleBadge`)})]}),(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:U(e.cost)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.lastActive>0?`${q(e.lastActive)} ${li(e.lastActive)}`:`—`})]},e.id))]})]})})]})]})]}),I===`token`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-token`,children:[(0,m.jsx)(hn,{stats:e,trendDays:de,onTrendDays:fe,models:On,money:U,t}),e.perf!==void 0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-perf`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`perfTitle`)}),(0,m.jsx)(`span`,{className:V.panelHint,children:t(`perfHint`)})]}),(0,m.jsx)(Dn,{perf:e.perf,models:On,t})]})]}),I===`pricing`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:V.ubAlert,role:`note`,children:[(0,m.jsxs)(`div`,{className:V.ubAlertLeft,children:[(0,m.jsxs)(`span`,{className:V.ubRate,"data-testid":`billing-rate`,children:[t(`todayRate`),` 1 USD = `,K(ht.rate)]}),(0,m.jsx)(`span`,{className:y(V.ubTag,ht.live?V.ubTagSuccess:V.ubTagNeutral),children:ht.live?t(`rateLive`):t(`rateBuiltin`)}),yt>0&&(0,m.jsxs)(`span`,{className:V.ubTag,"data-testid":`billing-pricing-synced`,children:[t(`pricingSyncedAt`),` `,new Date(yt).toLocaleTimeString(Ct===`zh`?`zh-CN`:`en-US`,{hour:`2-digit`,minute:`2-digit`})]}),(0,m.jsx)(`button`,{type:`button`,className:V.heatmapRangeButton,"data-testid":`billing-pricing-sync`,disabled:gt,onClick:vt,children:t(gt?`pricingSyncing`:`pricingSyncNow`)})]}),(0,m.jsx)(`p`,{className:V.ubAlertNote,children:t(`pricingTip`)})]}),(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`pricing`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:t(`pricingUnit`)}),(0,m.jsx)(`input`,{className:V.ubSearch,type:`search`,value:Tt,placeholder:t(`pricingSearch`),"aria-label":t(`pricingSearch`),"data-testid":`billing-pricing-search`,onChange:e=>{Et(e.target.value)}})]}),(0,m.jsx)(`div`,{className:V.ubTablewrap,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`thModel`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`thInputMiss`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`thInputHit`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`output`)}),(0,m.jsx)(`th`,{className:V.numCol,colSpan:2,children:t(`band`)})]})}),(0,m.jsx)(`tbody`,{children:qn(Kt(),Tt).map(e=>{let n=e.price.input>0||e.price.output>0;return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:V.ubModel,children:[(()=>{let n=Wn(St(kt,xt(e.key,W)),jt);if(n===null)return null;let r=Dt.includes(e.key),i=`${e.name} · ${t(n===`peak`?`peak`:`offPeak`)} · ${t(`bandPinHint`)}`;return(0,m.jsx)(`button`,{type:`button`,className:y(V.bandDot,V[n],r&&V.bandDotOn),"data-testid":`billing-band-dot`,"aria-pressed":r,"aria-label":i,title:i,onClick:()=>{Ot(Ce(e.key)),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.pinned-pref`))}})})(),(0,m.jsxs)(`span`,{className:V.ubModelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:V.ubTagAlert,"data-testid":`billing-price-uncatalogued`,children:t(`uncatalogued`)}),e.promo!==void 0&&Wt(e.promo,Date.now())&&(0,m.jsx)(p.Tooltip,{label:[e.promo.note,e.promo.endsAtMs===void 0?t(`promoOpenEnded`):t(`promoUntil`,{date:new Date(e.promo.endsAtMs).toLocaleDateString()})].filter(Boolean).join(` · `),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.ubTagPromo,"data-testid":`billing-price-promo`,children:t(`promoBadge`)})})]})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.input,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.cacheHit,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.output,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),n&&e.price.offPeak!==void 0&&e.peakHours!==void 0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsxs)(`span`,{className:V.ubChipPeak,children:[(0,m.jsx)(`span`,{className:V.ubChipLabel,children:e.tierSemantics===`latency`?t(`ubStd`):t(`ubPeak`)}),(0,m.jsxs)(`span`,{children:[Mt(e.price.input,e.price.currency),`/`,Mt(e.price.output,e.price.currency)]})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsxs)(`span`,{className:V.ubChipOff,children:[(0,m.jsx)(`span`,{className:V.ubChipLabel,children:e.tierSemantics===`latency`?`Flex`:t(`ubOff`)}),(0,m.jsxs)(`span`,{children:[Mt(e.price.offPeak.input,e.price.currency),` / `,Mt(e.price.offPeak.output,e.price.currency)]})]})})]}):(0,m.jsx)(`td`,{className:V.numCol,colSpan:2,children:n?(0,m.jsx)(`span`,{className:V.flatTag,children:t(`flat`)}):(0,m.jsx)(`span`,{className:V.na,children:`—`})})]}),(e.extraRows??[]).map(t=>(0,m.jsxs)(`tr`,{className:V.ubExtraRow,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:V.ubExtraName,children:Kn(t.label,Ct)}),t.note!==void 0&&(0,m.jsx)(`span`,{className:V.ubExtraNote,children:Kn(t.note,Ct)})]}),(0,m.jsx)(`td`,{className:V.numCol,children:t.input===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Mt(t.input,e.price.currency)}),(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:t.output===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Mt(t.output,e.price.currency)}),(0,m.jsx)(`td`,{className:V.numCol,colSpan:2,children:(0,m.jsx)(`span`,{className:V.na,children:`—`})})]},`${e.key}:${t.label}`))]},e.key)})})]})})]}),(0,m.jsxs)(`section`,{className:V.ubCard,children:[(0,m.jsx)(`div`,{className:V.ubCardHead,children:(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`pricingNotes`)})}),(0,m.jsxs)(`ul`,{className:V.ubNotes,children:[(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`cacheHit`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteCache`)})]}),(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`peakBand`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteBand`)})]}),(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`pricingSource`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteSource`)})]})]})]})]}),v(`billing.dashboard.decor`,{position:`footer`})]}),(0,m.jsxs)(`footer`,{className:V.modalFooter,"data-testid":`billing-footer`,children:[(0,m.jsx)(`span`,{children:t(`footer`)}),(0,m.jsx)(`span`,{children:t(`footerCredit`).replace(`{version}`,e.pluginVersion===void 0?`—`:`v${e.pluginVersion}`)})]})]})})}function Ai(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??`—`}let ji={display:[`显示`,`密度`,`动效`,`紧凑`,`舒适`,`克制`,`丰富`,`display`,`density`,`motion`,`compact`,`comfortable`],budget:[`预算`,`金额`,`本月`,`花费`,`进度`,`budget`,`amount`,`spend`,`progress`],alert:[`峰谷`,`峰`,`谷`,`提醒`,`通知`,`预览`,`切换`,`peak`,`off-peak`,`alert`,`notify`,`preview`],toggles:[`usage_stats`,`工具`,`即时代费`,`胶囊`,`中转站`,`站点`,`隐藏`,`relay`,`site`,`live`,`cost`,`hide`],displayExtra:[`悬浮`,`订阅`,`计费卡`,`指标`,`环比`,`主数字`,`float`,`subscription`,`card`,`metric`,`delta`],advanced:[`自定义`,`单价`,`价格`,`低谷`,`custom`,`price`],about:[`关于`,`版本`,`作者`,`许可`,`仓库`,`about`,`version`,`author`,`license`,`repo`]};function Mi(e){return Object.values(ji).every(t=>ti(e,t))}let Ni=[`below`,`above`,`toolbar`];function Pi({liveCostPrefs:e,onLiveCostPrefs:t,t:n}){let[r,i]=(0,d.useState)(!1),a={below:n(`liveCostBarPosBelow`),above:n(`liveCostBarPosAbove`),toolbar:n(`liveCostBarPosToolbar`)},o=Ni.map(e=>({id:e,label:a[e]}));return(0,m.jsx)(p.Menu,{open:r,align:`end`,portal:!0,compact:!0,items:o,selectedId:e.position,onSelect:n=>{i(!1);let r=Ni.find(e=>e===n);r!==void 0&&t({...e,position:r})},onClose:()=>{i(!1)},anchor:(0,m.jsxs)(`button`,{type:`button`,className:V.rdoSelect,"data-testid":`billing-livecost-position-select`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>{i(!r)},children:[(0,m.jsx)(`span`,{children:a[e.position]}),(0,m.jsx)(`span`,{className:y(V.rdoChevron,r&&V.rdoChevronOpen),"aria-hidden":!0,children:vr?(0,m.jsx)(vr,{}):null})]})})}function Fi(e){let{t,checkModels:n,publishCosts:r,registerOpen:i,renderSlot:a,useStore:o,actions:s}=e,[c,l]=(0,d.useState)(dr),[u,f]=(0,d.useState)(pr),[p,h]=(0,d.useState)([]),[g,_]=(0,d.useState)(void 0),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[w,T]=(0,d.useState)(()=>ue()),[ee,O]=(0,d.useState)(()=>xe()),k=(0,d.useCallback)(e=>{O(e),Se(e),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.language-pref`))},[]),j=(0,d.useCallback)(e=>{T(e),de(e),window.dispatchEvent(new CustomEvent(I))},[]),[ne,re]=(0,d.useState)(()=>E()),M=(0,d.useCallback)(e=>{re(e),D(e)},[]),[ie,se]=(0,d.useState)(()=>ae()),N=(0,d.useCallback)(e=>{se(e),oe(e)},[]),[F,fe]=(0,d.useState)(()=>P()),pe=(0,d.useCallback)(e=>{fe(e),le(e),window.dispatchEvent(new CustomEvent(ce))},[]),[me,he]=(0,d.useState)(()=>te()),ge=(0,d.useCallback)(e=>{he(e),A(e)},[]),[_e,ve]=(0,d.useState)(()=>{let e=Te();return $e(e),e}),ye=(0,d.useCallback)(e=>{ve(e),$e(e),Ee(e)},[]),L=(0,d.useMemo)(()=>Jr(c),[c,_e]),be=ee,R=(0,d.useCallback)((e,n)=>{let r=(be===`en`?Be:ze)[e]??t(e);if(n===void 0)return r;let i=r;for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[be,t]),[Ce,we]=(0,d.useState)(!1),De=(0,d.useCallback)(()=>{we(!1)},[]),z=(0,d.useCallback)(()=>{ui().then(e=>{e!==null&&l(e)}),di().then(({balances:e,reconcile:t})=>{e.length>0&&h(e),_(t)}),fi().then(e=>{e.length>0&&y(e),x(!1)}).catch(()=>{x(!0)}),pi().then(e=>{C(e)}).catch(()=>{})},[]),Oe=(0,d.useCallback)(()=>{z(),vi(),we(!0)},[z]);(0,d.useEffect)(()=>{z(),vi()},[z]);let[ke,Ae]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{Ae(!document.hidden),document.hidden||(z(),vi())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[z]),(0,d.useEffect)(()=>{if(!ke)return;let e=setInterval(()=>{z(),vi()},Ce?ur:3e5);return()=>{clearInterval(e)}},[z,Ce,ke]),(0,d.useEffect)(()=>{let e=!0;return n().then(t=>{e&&(f(t),ot(t.catalog??[]))}),()=>{e=!1}},[n]);let B=q(),je=Object.entries(L.byDay).filter(([e])=>e.startsWith(B.slice(0,7))).reduce((e,[,t])=>e+t.cost,0),Me=L.byDay[B]?.cost??0,Ne=new Date;Ne.setDate(Ne.getDate()-1);let Pe=`${Ne.getFullYear()}-${String(Ne.getMonth()+1).padStart(2,`0`)}-${String(Ne.getDate()).padStart(2,`0`)}`,Fe=L.byDay[Pe]?.cost??0,Ie=Fe>0?(Me-Fe)/Fe*100:0,Le=Tr(L.byDay,B),V=(0,d.useMemo)(()=>wr(L.byDay).map(e=>{let t=L.byDay[e.date];return{date:e.date,cost:e.cost,tokens:t===void 0?0:Cr(t)}}),[L.byDay]),Re=Object.entries(L.byDay).filter(([e])=>e.startsWith(B.slice(0,7))).reduce((e,[,t])=>e+Cr(t),0),Ve=(()=>{let e=L.byDay[B];return e===void 0?0:Cr(e)})(),He=Tr(L.byDay,B,Cr),Ue=o(e=>e.enabled),We=o(e=>e.amount),Ge=o(e=>e.tierAlertDays),Ke=o(e=>e.lastTierSwitchAt),[H,qe]=(0,d.useState)(()=>ar()),[Je,Ye]=(0,d.useState)(null),[Xe,Ze]=(0,d.useState)(null),[Qe,et]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{if(!H.enabled)return;let e=setInterval(()=>et(Date.now()),ur);return()=>{clearInterval(e)}},[H.enabled]);let tt=(0,d.useCallback)(e=>{qe(e),or(e)},[]),nt=v.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),rt=xt(c.byTurn?.[0]?.model,nt),it=(0,d.useCallback)(()=>{Ze({entering:ft(Date.now())===`peak`?`offPeak`:`peak`,atMs:Date.now()+18e4,channel:rt})},[rt]),at=We>0?We:c.budget??0,st=Ue&&at>0?je/at>=1?`over`:je/at>=.8?`warn`:`none`:`none`,ct=(0,d.useCallback)(()=>{let e=!Ue;s.setEnabled(e),e&&typeof Notification<`u`&&Notification.permission==="default"&&Notification.requestPermission()},[s,Ue]);(0,d.useEffect)(()=>{if(!Ue||at<=0)return;let e=je/at*100,t=lr.filter(t=>e>=t&&Ge?.[String(t)]!==B);if(t.length===0)return;let n=t[t.length-1]??100;if(s.markTierAlerted(t,B),!Xr())return;let r=R(`budgetTierBody`).replace(`{cost}`,K(je)).replace(`{budget}`,K(at)).replace(`{pct}`,String(n));Zr(`budget:${n}:${B}`,()=>{new Notification(R(`budget`),{body:r})})},[Ue,at,je,Ge,B,s,R]),(0,d.useEffect)(()=>{let e=sr(Qe,H,Ke,rt);if(e===null||(s.markTierSwitchAlerted(e.atMs),Ye(e),!H.webNotify||!Xr()))return;let t=Math.max(1,Math.round((e.atMs-Qe)/6e4)),n=R(e.entering===`peak`?`peakAlertTitlePeak`:`peakAlertTitleOff`),r=R(e.channel===`zhipu-coding-plan`?e.entering===`peak`?`tierAlertEnterPeakZhipu`:`tierAlertEnterOffZhipu`:e.entering===`peak`?`tierAlertEnterPeak`:`tierAlertEnterOff`).replace(`{minutes}`,String(t));Zr(`peak:${e.atMs}`,()=>{new Notification(n,{body:r})})},[Qe,Ke,H,rt,s,R]);let ut=o(e=>e.lastBalanceAlertDay),dt=o(e=>e.modelBudgets),pt=o(e=>e.modelTierAlertDays),mt=(0,d.useMemo)(()=>Dr(L.byDayModels,B.slice(0,7)),[L.byDayModels,B]),ht=L.lowBalanceThreshold??50,gt=(0,d.useMemo)(()=>{if(p.length===0)return;let e=yr(L.byDay,B),t=lt().rate;for(let n of p){if(n.totalBalance===void 0||n.error!==void 0)continue;let r=n.currency===`USD`?n.totalBalance*t:n.totalBalance;if(r>=ht)continue;let i=e>0?Math.floor(r/e):void 0;return{name:n.displayName,cny:r,days:i}}},[p,L.lowBalanceThreshold,L.byDay,B]);(0,d.useEffect)(()=>{if(gt===void 0||ut===B||(s.markBalanceAlerted(B),!Xr()))return;let e=R(`balanceLowBody`).replace(`{name}`,gt.name).replace(`{balance}`,K(gt.cny)).replace(`{days}`,gt.days===void 0?`—`:String(gt.days));Zr(`balance:${B}`,()=>{new Notification(R(`balance`),{body:e})})},[gt,ut,B,s,R]),(0,d.useEffect)(()=>{let e=[],t;for(let[n,r]of Object.entries(dt)){if(!(r>0))continue;let i=mt[n]??0;for(let a of kr(i,r)){let o=`${n}:${a}`;pt[o]!==B&&(e.push(o),(t===void 0||a>t.tier)&&(t={model:n,tier:a,cost:i,budget:r}))}}if(e.length===0||t===void 0||(s.markModelTierAlerted(e,B),!Xr()))return;let n=R(`modelBudgetBody`).replace(`{model}`,t.model).replace(`{cost}`,K(t.cost)).replace(`{budget}`,K(t.budget)).replace(`{pct}`,String(t.tier));Zr(`model-budget:${t.model}:${t.tier}:${B}`,()=>{new Notification(R(`modelBudgetTitle`),{body:n})})},[dt,mt,pt,B,s,R]);let _t=(0,d.useMemo)(()=>{let e=B.slice(0,7),t=new Map;for(let[n,r]of Object.entries(L.byDayModels??{}))if(n.startsWith(e))for(let[e,n]of Object.entries(r)){if(n.cost<=0)continue;let r=Ht(e).provider,i=L.byModel?.[e]?.plan===!0,a=t.get(r)??{cost:0,plan:i};a.cost+=n.cost,i||(a.plan=!1),t.set(r,a)}let n,r;for(let e of t){let t=e[1].plan?r:n;(t===void 0||e[1].cost>t[1].cost)&&(e[1].plan?r=e:n=e)}let i=e=>{let t=p.find(t=>$(t.provider)===$(e));if(t===void 0||t.totalBalance===void 0){if(e===`Custom`){let e=p.filter(e=>e.totalBalance!==void 0&&e.error===void 0),t=e[0];return t!==void 0&&e.length===1?i(t.provider):void 0}return{text:t?.error===`unauthorized`?R(`balanceUnauthorized`):t?.error===`unreachable`||t?.error===`invalid`?R(`balanceUnreachable`):R(`balanceUnconfigured`),low:!1}}let n=t.currency===`USD`?`$${t.totalBalance.toFixed(2)}`:K(t.totalBalance),r=lt().rate;return{text:n,low:(t.currency===`USD`?t.totalBalance*r:t.totalBalance)<ht}},a=e=>{let t=v.find(t=>t.displayName===e||Fr(t.provider)===e);if(t===void 0||t.windows.length===0)return{text:R(`subscriptionNoApi`),low:!1};let n=t.windows.reduce((e,t)=>Math.min(e,t.remainingPercent),100);return{text:n<=0?R(`subscriptionExhausted`):R(`subscriptionRemaining`).replace(`{pct}`,String(n)),low:n<20}},o=n===void 0?void 0:i(n[0]);return{direct:n===void 0||o===void 0?void 0:{name:n[0],...o},sub:r===void 0?void 0:{name:r[0],...a(r[0])}}},[L.byDayModels,L.byModel,L.lowBalanceThreshold,p,v,B,R]),vt=(0,d.useMemo)(()=>{let e=L.total;return{input:e.input,output:e.output,cacheRead:e.cacheHit,cacheMiss:e.cacheMiss,calls:e.calls}},[L]);(0,d.useEffect)(()=>{r({todayCost:Me,monthCost:je})},[Me,je,r]),(0,d.useEffect)(()=>i(Oe),[i,Oe]);let yt=(0,d.useMemo)(()=>c.byTurn??[],[c.byTurn]);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(Ti,{...e,t:R,currency:w,onOpen:Oe,monthCost:je,todayCost:Me,weekCost:Le,days:V,vendorStatus:_t,dash:vt,cardPrefs:me,monthTokens:Re,todayTokens:Ve,weekTokens:He,floatPrefs:ne,subscriptions:v,budgetPressure:st,deltaPct:Ie}),Ce&&(0,m.jsx)(ki,{stats:L,t:R,onClose:De,userPrices:_e,onUserPrices:ye,health:u,balances:p,...g===void 0?{}:{reconcile:g},quotas:v,relayQuotas:S,currency:w,onCurrency:j,language:ee,onLanguage:k,turns:yt,renderSlot:a,budgetEnabled:Ue,budgetAmount:at,modelBudgets:dt,monthModelCost:mt,onModelBudget:s.setModelBudget,onToggleBudget:ct,onBudgetAmount:s.setAmount,peakConfig:H,onPeakConfig:tt,onPreviewPeak:it,floatPrefs:ne,onFloatPrefs:M,cardPrefs:me,onCardPrefs:ge,sitePrefs:ie,onSitePrefs:N,liveCostPrefs:F,onLiveCostPrefs:pe,quotasStale:b}),(Je!==null||Xe!==null)&&(0,m.jsx)(cr,{hit:Je??Xe,config:H,t:R,onDismiss:()=>{Ye(null),Ze(null)}})]})}function Ii(e,t){if(t===void 0||e?.bySession===void 0)return 0;let n=e.bySession.find(e=>e.id===t);return(n?.cost??0)+(n?.subCost??0)}function Li(e,t){return t===void 0||e?.bySession===void 0?0:e.bySession.find(e=>e.id===t)?.subCost??0}function Ri(e,t){if(t===void 0||e?.byTurn===void 0)return 0;let n=0,r=-1;for(let i of e.byTurn)i.sessionId===t&&(r===-1||i.turn>r)&&(r=i.turn,n=i.cost);return n}function zi(e,t=20){let n=[];for(let r of e)if(r.status===`ok`)for(let e of r.windows)e.remainingPercent>t||n.push({name:r.displayName,kind:e.kind,pct:e.remainingPercent});return n.sort((e,t)=>e.pct-t.pct).slice(0,3)}function Bi(e,t){if(t===void 0||e?.byTurn===void 0)return;let n=-1,r;for(let i of e.byTurn)i.sessionId===t&&(n===-1||i.turn>n)&&(n=i.turn,r=i.model);return r}async function Vi(){try{let e=await fetch(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return{...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{}}}catch{return null}}async function Hi(){try{let e=await fetch(`/api/billing/subscriptions`);if(!e.ok)return[];let t=JSON.parse(await e.text());if(typeof t!=`object`||!t||!(`quotas`in t))return[];let n=t.quotas;return Array.isArray(n)?n:[]}catch{return[]}}function Ui(e){switch(e){case`session`:return`subscriptionSession`;case`weekly`:return`subscriptionWeekly`;case`monthly`:return`subscriptionMonthly`;default:return`subscriptionBilling`}}function Wi({hasBandPlan:e}){let[t,n]=(0,d.useState)(()=>me()),[r,i]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=()=>{n(me())};window.addEventListener(pe,e),window.addEventListener(`storage`,e);let t=setInterval(()=>{i(Date.now())},3e4);return()=>{window.removeEventListener(pe,e),window.removeEventListener(`storage`,e),clearInterval(t)}},[]),t.length===0)return null;let a=ar().leadMin*6e4,o=t.map(t=>({key:t,state:Wn(St(r,xt(t,e)),a)})).filter(e=>e.state!==null);return o.length===0?null:(0,m.jsx)(`span`,{className:V.bandDots,"data-testid":`billing-pinned-dots`,children:o.map(e=>(0,m.jsx)(`span`,{className:y(V.bandDot,V.bandDotOn,V[e.state]),role:`img`,"aria-label":e.key,title:e.key},e.key))})}function Gi(){let[e,t]=(0,d.useState)(()=>ue());return(0,d.useEffect)(()=>{let e=()=>{t(ue())};return window.addEventListener(I,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(I,e),window.removeEventListener(`storage`,e)}},[]),e}function Ki(){let[e,t]=(0,d.useState)(()=>P().show),[n,r]=(0,d.useState)(()=>P().position);return(0,d.useEffect)(()=>{let e=()=>{t(P().show),r(P().position)};return window.addEventListener(ce,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(ce,e),window.removeEventListener(`storage`,e)}},[]),{visible:e,position:n}}function qi(e,t){let[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(()=>Date.now()),[c,l]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{l(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!c||!t)return;let e=!1,n=()=>{Vi().then(t=>{!e&&t!==null&&r(t)}),Hi().then(t=>{e||a(t)}),e||s(Date.now())};n();let i=setInterval(n,3e4);return()=>{e=!0,clearInterval(i)}},[e,c,t]);let u=(0,d.useMemo)(()=>Ii(n,e),[n,e]),f=(0,d.useMemo)(()=>Li(n,e),[n,e]),p=(0,d.useMemo)(()=>Ri(n,e),[n,e]),m=(0,d.useMemo)(()=>zi(i),[i]),h=(0,d.useMemo)(()=>xt(Bi(n,e),i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)),[n,e,i]);return{sessionCost:u,subCost:f,turnCost:p,tier:(0,d.useMemo)(()=>St(o,h),[o,h]),chips:m,hasBandPlan:i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)}}function Ji({sessionId:e,t}){let{visible:n,position:r}=Ki(),{sessionCost:i,subCost:a,turnCost:o,tier:s,chips:c,hasBandPlan:l}=qi(e,n&&r!==`toolbar`),u=Gi(),d=e=>K(Xt(e,u),u),f=i>0||o>0,p=s?.tier===`peak`;return!n||r===`toolbar`?null:(0,m.jsxs)(`span`,{className:r===`above`?y(V.feeBar,V.feeBarAbove):V.feeBar,"data-testid":`billing-live-cost-bar`,children:[(0,m.jsx)(Wi,{hasBandPlan:l}),s!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:p?V.feeChipPrimary:V.feeChipOff,"data-testid":`billing-live-tier`,children:t(p?`tierPeak`:`tierOff`)}),(0,m.jsx)(`span`,{className:V.feeCount,children:wt(s.nextSwitchInMs)}),(0,m.jsx)(`span`,{className:V.feeSuffix,children:t(p?`tierToOff`:`tierToPeak`)})]}),f&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:V.feeItem,"data-testid":`billing-live-turn`,children:[t(`liveTurn`),` `,(0,m.jsx)(`span`,{className:V.feeNum,"data-tick":`turn`,children:d(o)})]}),(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:V.feeItem,"data-testid":`billing-live-session`,children:[t(`liveSession`),` `,(0,m.jsx)(`span`,{className:V.feeNum,"data-tick":`session`,children:d(i)}),a>0&&(0,m.jsx)(`span`,{className:V.feeSuffix,"data-testid":`billing-live-session-sub`,children:t(`liveSessionSub`).replace(`{cost}`,d(a))})]})]}),c.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:e.pct<=10?V.feeChipError:V.feeChipAlert,"data-testid":`billing-live-quota`,children:[e.name,` `,t(Ui(e.kind)),` `,e.pct,`%`]})]},`${e.name}:${e.kind}`))]})}function Yi({sessionId:e,t}){let n=Gi(),r=e=>K(Xt(e,n),n),{visible:i,position:a}=Ki(),{sessionCost:o,subCost:s,turnCost:c,tier:l,chips:u,hasBandPlan:d}=qi(e,i&&a===`toolbar`);if(!i||a!==`toolbar`)return null;let f=l?.tier===`peak`,h=u.reduce((e,t)=>Math.min(e,t.pct),100),g=h<=10?V.feeInlineError:h<=20?V.feeInlineAlert:V.feeInline,_=[...l===null?[]:[`${wt(l.nextSwitchInMs)} ${t(f?`tierToOff`:`tierToPeak`)}`],`${t(`liveTurn`)} ${r(c)}`,`${t(`liveSession`)} ${r(o)}`,...s>0?[t(`liveSessionSub`).replace(`{cost}`,r(s))]:[],...u.map(e=>`${e.name} ${t(Ui(e.kind))} ${e.pct}%`)].join(` · `);return(0,m.jsx)(p.Tooltip,{label:_,side:`top`,delayMs:500,children:(0,m.jsxs)(`span`,{className:g,"data-testid":`billing-live-cost-chip`,role:`note`,"aria-label":_,children:[(0,m.jsx)(Wi,{hasBandPlan:d}),l!==null&&(0,m.jsx)(`span`,{className:f?V.feeChipPrimary:V.feeChipOff,"data-testid":`billing-live-tier`,children:t(f?`tierPeak`:`tierOff`)}),o>0&&(0,m.jsx)(`span`,{className:V.feeInlineNum,children:r(o)})]})})}function Xi(){let e,t,n=new Set;return{readCosts:()=>e,subscribeCosts:t=>(t(e),n.add(t),()=>{n.delete(t)}),openDashboard:()=>{t?.()},publishCosts:t=>{e=t;for(let e of n)try{e(t)}catch{x(`billing-costs-listener-threw`)}},registerOpen:e=>(t=e,()=>{t===e&&(t=void 0)})}}function Zi(){return(0,h.defineStore)({init:()=>({enabled:!1,amount:0,tierAlertDays:{},lastBalanceAlertDay:``,lastTierSwitchAt:0,modelBudgets:{},modelTierAlertDays:{}}),persist:`dsh.ui-usage-billing.budget`,actions:{setEnabled:(e,t)=>{e.enabled=t},setAmount:(e,t)=>{e.amount=Number.isFinite(t)&&t>0?t:0},markTierAlerted:(e,t,n)=>{e.tierAlertDays??={};for(let r of t)e.tierAlertDays[String(r)]=n},markBalanceAlerted:(e,t)=>{e.lastBalanceAlertDay=t},markTierSwitchAlerted:(e,t)=>{e.lastTierSwitchAt=t},setModelBudget:(e,t,n)=>{e.modelBudgets??={},Number.isFinite(n)&&n>0?e.modelBudgets[t]=n:delete e.modelBudgets[t]},markModelTierAlerted:(e,t,n)=>{e.modelTierAlertDays??={};for(let r of t)e.modelTierAlertDays[r]=n}}})}let Qi={enabled:!1,timeout:0};function $i(){try{let e=localStorage.getItem(`dsh-billing-completion-notify-v1`);if(e===null)return{...Qi};let t=JSON.parse(e);return{enabled:t.enabled===!0,timeout:typeof t.timeout==`number`?t.timeout:0}}catch{return{...Qi}}}function ea(e){return e.completed===!0||e.running===!1}function ta(e,t){let n=new Set,r=new Set,i,a=e.getSnapshot();for(let e of a.ids){let t=a.byId[e];t!==void 0&&(r.add(String(e)),ea(t)&&n.add(String(e)))}let o=e=>{let{enabled:n,timeout:r}=t();if(n&&!(typeof Notification>`u`)&&Notification.permission===`granted`)try{let t=new Notification(e,{body:e,tag:`dsh-billing-completion`,requireInteraction:r===0});r>0&&(i!==void 0&&clearTimeout(i),i=setTimeout(()=>t.close(),r*1e3))}catch{x(`notification-constructor-failed`)}},s=e.subscribe(()=>{let t=e.getSnapshot(),i=[];for(let e of t.ids){let a=t.byId[e];if(a===void 0)continue;let o=String(e),s=ea(a),c=!r.has(o);c&&r.add(o),s&&!c&&!n.has(o)&&i.push(a.title??a.id??o),s?n.add(o):n.delete(o)}if(i.length>0){let e=i.length===1?i[0]:`${i.length} 个会话已完成`;e!==void 0&&o(e)}});return()=>{s(),i!==void 0&&clearTimeout(i)}}let na=[`slots`,`locale`,`remote`,`sessions`];function ra(e){let t=Xi();e.provide(`billingMetrics`,t);let n=Zi();e.effect(()=>e.locale.register(Re,{zh:ze,en:Be}),`ui-usage-billing: dictionaries`),e.slots.inject(`sidebar.footer.action`,()=>e.slots.register({name:`sidebar.footer.action`,id:`usage-billing`,order:-10,locale:Re,children:{"billing.dashboard.decor":{kind:`list`,scope:`root`}},store:n,inject:()=>({checkModels:async()=>{try{let[t,n]=await Promise.all([e.remote.llm.listProviders(),e.remote.llm.listConfigurableProviders()]);if(!t.ok||!n.ok)return{checked:!0,available:!1,models:0,failures:0,okProviders:[],badProviders:[]};let r=new Map(n.value.map(e=>[e.provider,e])),i=await Promise.all(t.value.map(async t=>{let n=r.get(t.id);if(n===void 0)return{provider:t,models:[]};let i=await e.remote.llm.discoverModels(n.settingsNs,{provider:t.id});return i.ok?{provider:t,models:i.value}:{provider:t,failed:!0}})),a=[],o=[],s=[],c=0;for(let e of i){if(`failed`in e){s.push(e.provider.name);continue}o.push(e.provider.name),c+=e.models.length;for(let t of e.models)a.push({id:t.id,...typeof t.name==`string`&&t.name!==``?{name:t.name}:{},provider:e.provider.name})}return{checked:!0,available:o.length>0,models:c,failures:s.length,okProviders:o,badProviders:s,catalog:a}}catch{return{checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]}}},publishCosts:e=>{t.publishCosts(e)},registerOpen:e=>t.registerOpen(e)})},Fi)),e.slots.inject(`conversation.composer.dock`,()=>e.slots.register({name:`conversation.composer.dock`,id:`usage-billing-cost`,order:0,locale:Re,inject:e=>({sessionId:_(e)})},Ji)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-cost-chip`,order:0,locale:Re,inject:e=>({sessionId:_(e)})},Yi)),e.effect(()=>ta(e.sessions.list,$i),`ui-usage-billing: completion notifier`)}return n.UsageBilling=Fi,n.apply=ra,n.inject=na,t.exports}});
5
+ `)}function _n(){let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}let X={top:18,right:40,bottom:26,left:46};function vn(e){let[,t,n]=e.split(`-`);return`${Number(t)}/${Number(n)}`}function yn(e,t){let n=[];for(let r=0;r<e;r+=t)n.push(r);return e>0&&n[n.length-1]!==e-1&&n.push(e-1),n}let bn={key:`__total__`,name:``,color:``};function xn({data:e,models:t=[],currency:n=`cny`,metric:r=`cost`,t:i}){let a=i??(e=>ze[e]),[o,s]=(0,d.useState)(null),c=e=>K(Xt(e,n),n),l=e=>r===`tokens`?un(e):c(e),u=e=>r===`tokens`?e.tokens??0:e.cost,f=(0,d.useMemo)(()=>{let n=e.length;if(n===0)return null;let i=680-X.left-X.right,a=220-X.top-X.bottom,o=e=>n===1?X.left+i/2:X.left+i*e/(n-1),s=Math.max(...r===`tokens`?e.map(e=>e.tokens??0):e.map(e=>Math.max(e.cost,Object.values(e.byModel??{}).reduce((e,t)=>e+t,0))),1e-4),c=e=>X.top+a-e/s*a,l=Math.max(...e.map(e=>e.calls),1),d=e=>X.top+a-e/l*a,f=i/n,p=Math.min(18,f*.6);return{n,plotW:i,plotH:a,inner:o,yCost:c,yCalls:d,barW:p,bars:e.flatMap((e,n)=>{let i=o(n)-p/2;if(t.length===0||r===`tokens`)return[{date:e.date,model:bn,x:i,base:0,value:u(e),topRounded:!0}];let a=null;for(let n of t)(e.byModel?.[n.key]??0)>0&&(a=n.key);let s=0;return t.map(t=>{let n=e.byModel?.[t.key]??0,r={date:e.date,model:t,x:i,base:s,value:n,topRounded:t.key===a};return s+=n,r})}),costTicks:[0,.25,.5,.75,1].map(e=>s*e).reverse(),callsTicks:[0,.25,.5,.75,1].map(e=>l*e).reverse(),linePath:e.map((e,t)=>{let n=d(e.calls);return`${t===0?`M`:`L`}${o(t)} ${n}`}).join(` `)}},[e,t,r]);if(f===null)return(0,m.jsx)(`div`,{className:V.chartEmpty,children:a(`trendEmpty`)});let{n:p,plotW:h,plotH:g,inner:_,yCost:v,yCalls:y,barW:b,bars:x,costTicks:S,callsTicks:C,linePath:w}=f,T=o===null?void 0:e[o],ee=yn(p,Math.max(1,Math.ceil(p/8)));return(0,m.jsxs)(`div`,{className:V.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 220`,className:V.chartSvg,role:`img`,"aria-label":`Daily cost by model and total calls`,onMouseLeave:()=>{s(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-X.left)/h,r=Math.round(n*(p-1));s(Math.min(Math.max(r,0),p-1))},children:[S.map((e,t)=>{let n=v(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:X.left,x2:680-X.right,y1:n,y2:n,className:V.chartGrid}),(0,m.jsx)(`text`,{x:X.left-8,y:n+3,textAnchor:`end`,className:V.chartAxisLabel,children:l(e)})]},`cost-${t}`)}),x.map(t=>{if(t.value>0)return(0,m.jsx)(`rect`,{x:t.x,y:v(t.base+t.value),width:b,height:v(t.base)-v(t.base+t.value),rx:t.topRounded?2:0,className:t.model.color===``?V.chartBar:V.chartStack,style:t.model.color===``?void 0:{fill:t.model.color}},`${t.date}-${t.model.key}`);let n=e.find(e=>e.date===t.date);return n!==void 0&&n.calls>0&&t.base===0?(0,m.jsx)(`rect`,{x:t.x,y:v(0)-1,width:b,height:1,rx:0,className:V.chartBarPlaceholder},`${t.date}-${t.model.key}-placeholder`):null}),(0,m.jsx)(`path`,{d:w,fill:`none`,className:V.chartLine}),(()=>{let t=_n(),n=e.findIndex(e=>e.date===t);return n>=0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`chartAreaGrad`,x1:`0%`,y1:`0%`,x2:`0%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-blue)`,stopOpacity:`0.35`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-blue)`,stopOpacity:`0`})]})}),(0,m.jsx)(`path`,{d:`${w} L ${_(e.length-1)} ${y(0)} L ${_(0)} ${y(0)} Z`,fill:`url(#chartAreaGrad)`}),(0,m.jsx)(`line`,{x1:_(n),x2:_(n),y1:X.top,y2:X.top+g,stroke:`var(--ds-amber)`,strokeWidth:`1`,strokeDasharray:`3 3`,opacity:`0.6`}),(0,m.jsx)(`text`,{x:_(n)+4,y:X.top-6,fill:`var(--ds-amber)`,fontSize:`10`,fontFamily:`var(--font-num)`,children:vn(t)})]}):null})(),C.map((e,t)=>{let n=y(e);return(0,m.jsx)(`text`,{x:680-X.right+8,y:n+3,textAnchor:`start`,className:V.chartAxisLabel,children:un(e)},`calls-${t}`)}),ee.map(t=>{let n=e[t];return n===void 0?null:(0,m.jsx)(`text`,{x:_(t),y:214,textAnchor:`middle`,className:V.chartAxisLabel,children:vn(n.date)},n.date)}),o!==null&&(0,m.jsx)(`line`,{x1:_(o),x2:_(o),y1:X.top,y2:X.top+g,className:V.chartCrosshair})]}),T!==void 0&&o!==null&&(0,m.jsxs)(`div`,{className:V.chartTooltip,style:{left:`${_(o)/680*100}%`,top:`${v(T.cost)/220*100}%`},children:[(0,m.jsx)(`div`,{className:V.chartTooltipDate,children:T.date}),r!==`tokens`&&t.filter(e=>(T.byModel?.[e.key]??0)>0).map(e=>(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:c(T.byModel?.[e.key]??0)})]},e.key)),(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartLegendBar}),a(`trendTotal`),` `,(0,m.jsx)(`strong`,{children:r===`tokens`?un(T.tokens??0):c(T.cost)})]}),(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartLegendLine}),a(`calls`),` `,(0,m.jsx)(`strong`,{children:T.calls.toLocaleString()})]})]}),t.length>0&&r!==`tokens`&&(0,m.jsxs)(`div`,{className:V.chartLegend,children:[t.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key)),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.chartLegendLine}),a(`calls`)]})]})]})}let Z={top:14,right:42,bottom:22,left:46};function Sn(e){return e.slice(5,13).replace(`T`,` `)}function Cn(e){return String(e>=100?Math.round(e):Number(e.toFixed(1)))}function wn(e){return e<1e4?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${(e/6e4).toFixed(1)} min`}function Tn(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toFixed(1)}function En(e,t,n){return t===`ttft`?`${Math.round(e)} ms`:`${e.toFixed(1)} ${n(`perfTpsUnit`)}`}function Dn({perf:e,models:t,t:n}){let[r,i]=(0,d.useState)(()=>Oe()),[a,o]=(0,d.useState)(null),s=e=>{i(e),ke(e)},c=e=>t.find(t=>t.key===e)?.color??`#8b95a3`,l=(0,d.useMemo)(()=>e===void 0?[]:Object.entries(e.byModel).map(([e,n])=>({key:e,name:t.find(t=>t.key===e)?.name??e,color:c(e),samples:n.samples,ttftAvg:n.ttftAvg,ttftP50:n.ttftP50,ttftP90:n.ttftP90,...n.ttftMax===void 0?{}:{ttftMax:n.ttftMax},...n.ttftSpikes===void 0?{}:{ttftSpikes:n.ttftSpikes},...n.tpsAvg===void 0?{}:{tpsAvg:n.tpsAvg},latencyAvg:n.latencyAvg,estimatedSamples:n.estimatedSamples})).sort((e,t)=>t.samples-e.samples||t.ttftP90-e.ttftP90),[e,t]),u=(0,d.useMemo)(()=>{if(e===void 0)return[];if(r.models!==void 0){let t=new Set(Object.keys(e.byModel));return r.models.filter(e=>t.has(e))}return l.slice(0,5).map(e=>e.key)},[e,l,r.models]),f=(0,d.useMemo)(()=>{if(e===void 0)return null;let t=Object.keys(e.byHourModel).sort().slice(-48);if(t.length===0)return null;let n=t.length,i=680-Z.left-Z.right,a=180-Z.top-Z.bottom,o=e=>n===1?Z.left+i/2:Z.left+i*e/(n-1),s=new Set(u),c=e=>r.metric===`ttft`?e?.ttftAvg:e?.tpsAvg,d=[],f=0;for(let r of l){if(!s.has(r.key))continue;let i=[];for(let a=0;a<n;a++){let n=t[a];if(n===void 0)continue;let s=c(e.byHourModel[n]?.[r.key]);s===void 0||!Number.isFinite(s)||(i.push({i:a,x:o(a),y:0,v:s}),s>f&&(f=s))}d.push({key:r.key,name:r.name,color:r.color,segments:[],points:i})}let p=d.reduce((e,t)=>e+t.points.length,0);f=Math.max(f,1);let m=e=>Z.top+a-e/f*a;for(let e of d){let t=``,n=-2;for(let r of e.points)r.y=m(r.v),t!==``&&r.i!==n+1&&(e.segments.push(t),t=``),t+=`${t===``?`M`:`L`}${r.x} ${r.y} `,n=r.i;t!==``&&e.segments.push(t)}let h=Math.max(1,Math.ceil(n/8)),g=[];for(let e=0;e<n;e+=h)g.push(e);return g[g.length-1]!==n-1&&g.push(n-1),{hourKeys:t,n,plotW:i,plotH:a,inner:o,yOf:m,series:d,ticks:[0,.5,1].map(e=>f*e).reverse(),xTicks:g,totalPoints:p}},[e,l,u,r.metric]);if(e===void 0||l.length===0)return(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-empty`,children:n(`perfEmpty`)});let p=e=>{let t=u.includes(e)?u.filter(t=>t!==e):[...u,e];s({metric:r.metric,models:t})},h=e=>{s({metric:e,...r.models===void 0?{}:{models:r.models}})},g=a===null||f===null?[]:f.series.flatMap(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?[]:[{key:e.key,name:e.name,color:e.color,v:t.v}]});return(0,m.jsxs)(`div`,{"data-testid":`billing-perf-panel`,children:[l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftAvg),1),t=Math.max(...l.filter(e=>e.tpsAvg!==void 0).map(e=>e.tpsAvg??0),1),r=Math.max(...l.map(e=>e.latencyAvg),1),i=l.reduce((e,t)=>e+t.samples,0),a=l.length>0?l.reduce((e,t)=>e+t.ttftAvg,0)/l.length:0,o=l.map(e=>e.tpsAvg).filter(e=>e!==void 0),s=o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0,c=l.length>0?l.reduce((e,t)=>e+t.latencyAvg,0)/l.length:0,u=[{lbl:n(`perfSamples`),val:i.toLocaleString(),unit:``,pct:65,color:`var(--ds-blue)`},{lbl:n(`perfTtft`),val:wn(a),unit:``,pct:a/e*100,color:`var(--ds-green)`},{lbl:n(`perfTps`),val:o.length>0?Tn(s):`—`,unit:``,pct:s/t*100,color:`var(--ds-blue)`},{lbl:n(`perfLatency`),val:wn(c),unit:``,pct:c/r*100,color:`var(--ds-amber)`}];return(0,m.jsx)(`div`,{className:V.perfHero,"data-testid":`billing-perf-hero`,children:u.map((e,t)=>(0,m.jsxs)(`div`,{className:V.perfHeroCell,children:[(0,m.jsx)(`div`,{className:V.perfHeroLbl,children:e.lbl}),(0,m.jsxs)(`div`,{className:V.perfHeroVal,children:[e.val,e.unit!==``&&(0,m.jsx)(`span`,{className:V.perfHeroUnit,children:e.unit})]}),(0,m.jsx)(`div`,{className:V.perfHeroBar,children:(0,m.jsx)(`i`,{style:{width:`${Math.min(100,e.pct)}%`,background:e.color}})})]},t))})})(),(0,m.jsx)(`div`,{className:V.tableScroll,"data-testid":`billing-perf-table`,children:(0,m.jsxs)(`table`,{className:V.modelTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:n(`model`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfSamples`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfTtft`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfP50`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfP90`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfMax`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfTps`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfLatency`)}),(0,m.jsx)(`th`,{className:V.numCol,children:n(`perfEstimated`)})]})}),(0,m.jsx)(`tbody`,{children:l.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:V.modelCell,children:[(0,m.jsx)(`span`,{className:V.modelDot,style:{background:e.color}}),(0,m.jsx)(`span`,{className:V.modelName,children:e.name})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:e.samples.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftP50)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.ttftP90)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.ttftMax===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):(0,m.jsxs)(`span`,{children:[wn(e.ttftMax),e.ttftSpikes!==void 0&&e.ttftSpikes>0?` (${e.ttftSpikes}↑)`:``]})}),(0,m.jsx)(`td`,{className:V.numCol,children:e.tpsAvg===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Tn(e.tpsAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:wn(e.latencyAvg)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.estimatedSamples>0?e.estimatedSamples:(0,m.jsx)(`span`,{className:V.na,children:`—`})})]},e.key))})]})}),l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftP50),1),t=e=>e<.8?`var(--ds-green)`:e<2?`var(--ds-amber)`:`var(--ds-red)`;return(0,m.jsx)(`div`,{className:V.perfCompareList,"data-testid":`billing-perf-compare`,children:l.map(n=>(0,m.jsxs)(`div`,{className:V.perfCompareRow,children:[(0,m.jsxs)(`div`,{className:V.perfCompareName,children:[(0,m.jsx)(`span`,{className:V.perfCompareDot,style:{background:n.color}}),(0,m.jsx)(`span`,{children:n.name})]}),(0,m.jsx)(`div`,{className:V.perfCompareBar,children:(0,m.jsx)(`i`,{style:{width:`${n.ttftP50/e*100}%`,background:t(n.ttftP50)}})}),(0,m.jsx)(`div`,{className:V.perfCompareNum,children:wn(n.ttftP50)}),(0,m.jsx)(`div`,{className:V.perfCompareNum,children:n.tpsAvg===void 0?`—`:Tn(n.tpsAvg)})]},n.key))})})(),f!==null&&(0,m.jsxs)(`div`,{"data-testid":`billing-perf-hour`,children:[(0,m.jsx)(`div`,{className:V.perfBar,children:(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":n(`perfTitle`),children:[`ttft`,`tps`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,r.metric===e&&V.rangeButtonActive),"aria-pressed":r.metric===e,"data-testid":`billing-perf-tab-${e}`,onClick:()=>{h(e)},children:e===`ttft`?`${n(`perfTtft`)} (ms)`:`${n(`perfTps`)} (${n(`perfTpsUnit`)})`},e))})}),(0,m.jsxs)(`div`,{className:V.perfChips,role:`group`,"aria-label":n(`model`),children:[(0,m.jsx)(`button`,{type:`button`,className:V.perfChip,"data-testid":`billing-perf-chip-all`,onClick:()=>{s({metric:r.metric,models:l.map(e=>e.key)})},children:n(`perfAll`)}),l.map(e=>{let t=u.includes(e.key);return(0,m.jsxs)(`button`,{type:`button`,className:y(V.perfChip,!t&&V.perfChipOff),style:t?{color:e.color,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}:void 0,"aria-pressed":t,"data-testid":`billing-perf-chip-${e.key}`,onClick:()=>{p(e.key)},children:[(0,m.jsx)(`span`,{className:V.perfChipDot,style:{background:t?e.color:`var(--dsw-alias-label-dimmed)`}}),e.name]},e.key)})]}),f.totalPoints>0?(0,m.jsxs)(`div`,{className:V.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 180`,className:V.chartSvg,role:`img`,"aria-label":`Hourly perf comparison by model`,onMouseLeave:()=>{o(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-Z.left)/f.plotW,r=Math.round(n*(f.n-1));o(Math.min(Math.max(r,0),f.n-1))},children:[f.ticks.map((e,t)=>{let n=f.yOf(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:Z.left,x2:680-Z.right,y1:n,y2:n,className:V.chartGrid}),(0,m.jsx)(`text`,{x:Z.left-8,y:n+3,textAnchor:`end`,className:V.chartAxisLabel,children:Cn(e)})]},`tick-${t}`)}),f.series.map(e=>e.segments.map((t,n)=>(0,m.jsx)(`path`,{d:t,fill:`none`,className:V.chartLine,style:{stroke:e.color}},`${e.key}-${n}`))),f.xTicks.map(e=>{let t=f.hourKeys[e];return t===void 0?null:(0,m.jsx)(`text`,{x:f.inner(e),y:174,textAnchor:`middle`,className:V.chartAxisLabel,children:Sn(t)},t)}),a!==null&&(0,m.jsx)(`line`,{x1:f.inner(a),x2:f.inner(a),y1:Z.top,y2:Z.top+f.plotH,className:V.chartCrosshair}),a!==null&&f.series.map(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?null:(0,m.jsx)(`circle`,{cx:t.x,cy:t.y,r:3.5,fill:e.color,className:V.chartHoverDot},`${e.key}-dot`)})]}),a!==null&&g.length>0&&(0,m.jsxs)(`div`,{className:V.chartTooltip,"data-testid":`billing-perf-tooltip`,style:{left:`${f.inner(a)/680*100}%`,top:`${(Z.top+f.plotH/2)/180*100}%`},children:[(0,m.jsx)(`div`,{className:V.chartTooltipDate,children:Sn(f.hourKeys[a]??``)}),g.map(e=>(0,m.jsxs)(`div`,{className:V.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:V.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:En(e.v,r.metric,n)})]},e.key))]})]}):(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]}),f===null&&(0,m.jsx)(`div`,{className:V.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]})}let Q=`@kenz1117/dsh-ui-usage-billing`,On=`kenz1117`;function kn({t:e,version:t}){return(0,m.jsxs)(`section`,{className:V.setCard,"data-testid":`billing-plugin-info`,children:[(0,m.jsxs)(`div`,{className:V.plgHead,children:[(0,m.jsx)(`span`,{className:V.plgIcon,"aria-hidden":`true`,children:(0,m.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,m.jsx)(`path`,{d:`M10 3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a2 2 0 0 0 4 0V4a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1v1a2 2 0 0 0 4 0 1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0 0 4h1a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1v-1a2 2 0 0 0-4 0 1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 0-4H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 4 0z`})})}),(0,m.jsxs)(`div`,{className:V.plgTitle,children:[(0,m.jsxs)(`div`,{className:V.plgNameRow,children:[(0,m.jsx)(`h3`,{className:V.plgName,children:Q}),(0,m.jsx)(`span`,{className:V.plgTag,children:t===void 0?`—`:`v${t}`})]}),(0,m.jsx)(`p`,{className:V.plgDesc,children:`Usage billing dashboard for DeepSeek Harness`})]})]}),(0,m.jsxs)(`div`,{className:V.plgGrid,children:[(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginAuthor`)}),(0,m.jsxs)(`a`,{className:V.plgLink,href:`https://github.com/${On}`,target:`_blank`,rel:`noreferrer`,children:[`KenZ`,` (`,On,`)`]})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginRepository`)}),(0,m.jsx)(`a`,{className:V.plgLink,href:`https://github.com/kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:`GitHub`})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginNpm`)}),(0,m.jsx)(`a`,{className:V.plgLink,href:`https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:Q})]}),(0,m.jsxs)(`div`,{className:V.plgItem,children:[(0,m.jsx)(`span`,{className:V.plgLabel,children:e(`pluginLicense`)}),(0,m.jsx)(`span`,{className:V.plgVal,children:`MIT`})]})]})]})}function An(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function jn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Mn(e){let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${String(t%60).padStart(2,`0`)}s`}function Nn({rounds:e,flags:t,currency:n,t:r}){let i=(0,d.useMemo)(()=>e.slice(-40),[e]),a=(0,d.useMemo)(()=>new Set(t.map(e=>`${e.sessionId}:${e.turn}`)),[t]),o=(0,d.useMemo)(()=>Math.max(1e-4,...i.map(e=>e.cost)),[i]);if(i.length===0)return(0,m.jsxs)(`div`,{className:V.roundsEmpty,children:[r(`model`),` —`]});let s=e=>K(Xt(e,n),n);return(0,m.jsxs)(`div`,{className:V.rounds,children:[(0,m.jsx)(`div`,{className:V.roundsBars,role:`img`,"aria-label":`cost per turn`,children:i.map(e=>{let t=a.has(`${e.sessionId}:${e.turn}`),n=Math.max(1,e.cost/o*100),i=xt(e.model,!1)===`deepseek-metered`&&ft(e.startedAt)===`peak`;return(0,m.jsxs)(`div`,{className:y(V.roundsBarCol,i?V.roundsBarColPeak:V.roundsBarColOff),children:[(0,m.jsx)(`span`,{className:V.roundsBarLabel,style:{bottom:`${n}%`},children:s(e.cost)}),(0,m.jsx)(`div`,{className:V.roundsBarWrap,children:(0,m.jsx)(`div`,{className:t?V.roundsBarFlagged:V.roundsBar,style:{height:`${n}%`},"data-testid":`round-bar`,title:`${r(`model`)} ${e.model} · ${s(e.cost)} · ${jn(e.startedAt)}${e.endedAt===void 0?``:` → ${An(e.endedAt)} (${Mn(e.endedAt-e.startedAt)})`}`,children:t&&(0,m.jsx)(`span`,{className:V.roundsFlagMark,"aria-hidden":`true`})})})]},`${e.sessionId}:${e.turn}`)})}),(0,m.jsxs)(`div`,{className:V.roundsAxis,children:[(0,m.jsxs)(`span`,{children:[r(`costAbbr`),` `,s(o)]}),(0,m.jsxs)(`span`,{children:[i.length,` `,r(`roundsUnit`)]})]})]})}let Pn=[`color-mix(in srgb, var(--dsb-3) 70%, transparent)`,`color-mix(in srgb, var(--ds-cyan) 30%, var(--dsb-3))`,`color-mix(in srgb, var(--ds-blue) 60%, var(--dsb-3))`,`var(--ds-blue)`,`var(--ds-amber)`],Fn=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],In=e=>q(e.getTime());function Ln(e,t){let n=new Map;for(let t of e)n.set(t.date,t.value);let r=0;for(let e of n.values())e>r&&(r=e);let i=t.getFullYear(),a=t.getMonth(),o=t.getDate(),s=new Date(i,a+1,0).getDate(),c=new Date(i,a,1).getDay(),l=c+s,u=Math.ceil(l/7),d=[];for(let e=0;e<u;e+=1){let t=[];for(let l=0;l<7;l+=1){let u=e*7+l-c+1;if(u<1){let e=new Date(i,a,u);t.push({date:In(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}if(u>s){let e=new Date(i,a+1,u-s);t.push({date:In(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}let d=new Date(i,a,u),f=In(d),p=n.get(f)??0,m=0;if(p>0&&r>0){let e=Math.ceil(p/r*4);m=Math.min(4,Math.max(1,e))}let h=u>o;t.push({date:f,dayNum:u,value:h?0:p,level:h?0:m,placeholder:h})}d.push(t)}return d}function Rn(e,t,n=52){let r=new Map;for(let t of e)r.set(t.date,t.value);let i=0;for(let e of r.values())e>i&&(i=e);let a=In(t),o=new Date(t);o.setHours(0,0,0,0),o.setDate(o.getDate()-o.getDay());let s=new Date(o);s.setDate(o.getDate()-(n-1)*7);let c=[];for(let e=0;e<n;e+=1){let t=[];for(let n=0;n<7;n+=1){let o=new Date(s);o.setDate(s.getDate()+e*7+n);let c=In(o),l=c>a,u=l?0:r.get(c)??0,d=0;if(!l&&u>0&&i>0){let e=Math.ceil(u/i*4);d=Math.min(4,Math.max(1,e))}t.push({date:c,dayNum:o.getDate(),value:u,level:d,placeholder:l})}c.push(t)}return c}function zn({days:e,currency:t,now:n,t:r,range:i=`month`,unit:a=`cost`}){let[o,s]=(0,d.useState)(null),c=e=>K(Xt(e,t),t),l=e=>a===`tokens`?J(e):c(e),u=(0,d.useMemo)(()=>Ln(e,n??new Date),[e,n]),f=In(n??new Date);if(i!==`month`){let t=Rn(e,n??new Date,i===`half`?26:52),a=[],o=-1;return t.forEach((e,t)=>{let n=Number(e[0]?.date.slice(5,7)??0);n!==o&&(a.push({index:t,label:Fn[n-1]??``}),o=n)}),(0,m.jsxs)(`div`,{className:V.heatmapYear+(i===`half`?` `+V.heatmapHalf:``),"data-testid":i===`half`?`heatmap-half`:`heatmap-year`,children:[(0,m.jsxs)(`div`,{className:V.heatmapYearBody,children:[(0,m.jsx)(`div`,{className:V.heatmapYearWeekdays,"aria-hidden":`true`,children:[{label:`Mon`,row:1},{label:`Wed`,row:3},{label:`Fri`,row:5}].map(e=>(0,m.jsx)(`span`,{className:V.heatmapYearWeekday,style:{gridRow:e.row},children:e.label},e.label))}),(0,m.jsxs)(`div`,{className:V.heatmapYearScroll,children:[(0,m.jsx)(`div`,{className:V.heatmapYearMonths,"aria-hidden":`true`,"data-testid":`heatmap-year-months`,children:a.map(e=>(0,m.jsx)(`span`,{className:V.heatmapYearMonth,style:{gridColumn:e.index+1},children:e.label},e.index))}),(0,m.jsx)(`div`,{className:V.heatmapYearGrid,role:`img`,"aria-label":`yearly cost heatmap`,"data-testid":`heatmap-year-grid`,children:t.flat().map(e=>(0,m.jsx)(`button`,{type:`button`,className:V.heatmapYearCell,"data-testid":`heatmap-year-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Pn[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,tabIndex:-1},e.date))})]})]}),(0,m.jsxs)(`div`,{className:V.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:V.heatmapLegend,children:Pn.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)})]})]})}return(0,m.jsxs)(`div`,{className:V.heatmap,children:[(0,m.jsx)(`div`,{className:V.heatmapGrid,role:`img`,"aria-label":`daily cost heatmap`,children:u.map(e=>e.map(e=>e.placeholder?(0,m.jsx)(`div`,{className:V.heatmapCellEmpty,children:e.dayNum},e.date):(0,m.jsx)(`button`,{type:`button`,className:V.heatmapCell,"data-testid":`heatmap-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Pn[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,onMouseEnter:()=>{s(e)},onMouseLeave:()=>{s(null)},onFocus:()=>{s(e)},onBlur:()=>{s(null)},children:e.dayNum},e.date)))}),(0,m.jsxs)(`div`,{className:V.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:V.heatmapLegend,children:Pn.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)}),o!==null&&(0,m.jsxs)(`span`,{className:V.heatmapHover,"data-testid":`heatmap-hover`,children:[o.date,` · `,l(o.value)]})]})]})}let Bn={window:6,threshold:2,reasonFactor:1.8,reasonHitDropPp:15};function Vn(e){if(e.length===0)return null;let t=0;for(let n of e)t+=n;return t/e.length}function Hn(e){let t=e.cacheHit+e.cacheMiss;return t<=0?null:e.cacheHit/t*100}function Un(e,t){let n=t?.window??Bn.window,r=t?.threshold??Bn.threshold,i=t?.reasonFactor??Bn.reasonFactor,a=t?.reasonHitDropPp??Bn.reasonHitDropPp,o=[];if(n<=0||r<=0)return o;let s=[],c=[],l=[],u=[];for(let t of e){if(t.cost<=0)continue;let e=t.output,d=t.input,f=Hn(t),p=Vn(s),m=[];if(p!==null&&p>0&&t.cost>p*r){let n=Vn(c),r=Vn(l),s=Vn(u);n!==null&&n>0&&e>n*i&&m.push(`output-growth`),r!==null&&r>0&&d>r*i&&m.push(`context-bloat`),s!==null&&f!==null&&f<s-a&&m.push(`cache-hit-drop`),o.push({sessionId:t.sessionId,turn:t.turn,cost:t.cost,reasons:m})}for(s.push(t.cost),c.push(e),l.push(d),f!==null&&u.push(f);s.length>n;)s.shift();for(;c.length>n;)c.shift();for(;l.length>n;)l.shift();for(;u.length>n;)u.shift()}return o}let Wn={},Gn={};function Kn(){return(0,h.defineStore)({init:()=>({enabled:!1,amount:0,tierAlertDays:{},lastBalanceAlertDay:``,lastTierSwitchAt:0,modelBudgets:{},modelTierAlertDays:{}}),persist:`dsh.ui-usage-billing.budget`,actions:{setEnabled:(e,t)=>{e.enabled=t},setAmount:(e,t)=>{e.amount=Number.isFinite(t)&&t>0?t:0},markTierAlerted:(e,t,n)=>{e.tierAlertDays??={};for(let r of t)e.tierAlertDays[String(r)]=n},markBalanceAlerted:(e,t)=>{e.lastBalanceAlertDay=t},markTierSwitchAlerted:(e,t)=>{e.lastTierSwitchAt=t},setModelBudget:(e,t,n)=>{e.modelBudgets??={},Number.isFinite(n)&&n>0?e.modelBudgets[t]=n:delete e.modelBudgets[t]},markModelTierAlerted:(e,t,n)=>{e.modelTierAlertDays??={};for(let r of t)e.modelTierAlertDays[r]=n}}})}function qn(e,t){return e==null?null:Number.isFinite(e.nextSwitchInMs)&&e.nextSwitchInMs<=t?`soon`:e.tier===`peak`?`peak`:`offPeak`}let Jn={显式缓存创建:`Explicit cache write`,显式缓存命中:`Explicit cache hit`,长期半价:`Half price`,与标准价一致:`Same as standard`,"限时 5 折":`Limited-time 50% off`};function Yn(e,t){return e===void 0||t!==`en`?e:Jn[e]??e}function Xn(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.key.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n)||(e.provider??``).toLowerCase().includes(n))}let Zn={"智谱 AI":`Zhipu AI`,阿里通义:`Alibaba Qwen`,字节豆包:`ByteDance Doubao`,月之暗面:`Moonshot AI`,小米:`Xiaomi`,百度文心:`Baidu ERNIE`,腾讯混元:`Tencent Hunyuan`,零一万物:`01.AI`,阶跃星辰:`StepFun`,科大讯飞:`iFlytek Spark`,商汤:`SenseNova`,百川智能:`Baichuan`,"小米 Token Plan(海外)":`Xiaomi Token Plan (Global)`,"小米 Token Plan(国内)":`Xiaomi Token Plan (CN)`,"小米 Token Plan(新加坡)":`Xiaomi Token Plan (SG)`,"火山引擎 Token Plan":`Volcengine Token Plan`,"火山方舟 Token Plan":`Volcengine Ark Token Plan`,"豆包 Token Plan":`Doubao Token Plan`,"百度文心 Plan":`Baidu ERNIE Plan`,"MiniMax Token Plan(国内)":`MiniMax Token Plan (CN)`};function Qn(e,t){return t===`en`?Zn[e]??e:e}let $n={workbuddy:`WorkBuddy`,"workbuddy-ai":`WorkBuddy AI`},er={"https://tokenhub.tencentmaas.com":`腾讯云 TokenHub`,"https://api.lkeap.cloud.tencent.com":`腾讯云 Token Plan`,"https://api.deepseek.com":`DeepSeek 官方`},tr={"腾讯云 TokenHub":`Tencent Cloud TokenHub`,"腾讯云 Token Plan":`Tencent Cloud Token Plan`,"DeepSeek 官方":`DeepSeek Official`};function nr(e){try{return new URL(e).host}catch{return e}}function rr(e,t=`zh`){if(e.startsWith(`site:`)){let n=e.slice(5),r=er[n];return r===void 0?nr(n):t===`en`?tr[r]??r:r}if(e.startsWith(`direct:`)){let n=e.slice(7);if(/^deepseek(?:-[a-z0-9-]+)?$/i.test(n))return t===`en`?`DeepSeek Official`:`DeepSeek 官方`;let r=$n[n.trim().toLowerCase()];return r===void 0?`${t===`en`?`Direct`:`直连`} · ${n}`:`${t===`en`?`Direct`:`直连`} · ${r}`}}let ir=[`直连 · `,`Direct · `];function ar(e){for(let t of ir)if(e.startsWith(t))return e.slice(t.length)}let or=`dsh-billing-peak-alert-v1`,sr={enabled:!1,leadMin:2,position:`bottom-right`,webNotify:!0,mode:`both`};function cr(){try{let e=localStorage.getItem(or);if(e===null)return{...sr};let t=JSON.parse(e),n=t.mode===`peak`||t.mode===`offPeak`?t.mode:sr.mode,r=t.position===`center`?`center`:`bottom-right`;return{enabled:t.enabled===!0,leadMin:typeof t.leadMin==`number`&&Number.isFinite(t.leadMin)?Math.min(30,Math.max(1,Math.round(t.leadMin))):sr.leadMin,position:r,webNotify:t.webNotify!==!1,mode:n}}catch{return{...sr}}}function lr(e){try{localStorage.setItem(or,JSON.stringify(e))}catch{x(`peak-config-storage-unavailable`)}}function ur(e,t,n,r){if(!t.enabled)return null;let i=Ct(e,r,t.leadMin*6e4);return i===null||t.mode===`peak`&&i.entering!==`peak`||t.mode===`offPeak`&&i.entering!==`offPeak`||i.atMs===n?null:{...i,channel:r}}function dr({hit:e,config:t,t:n,onDismiss:r}){let[i,a]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(e)},[]),(0,d.useEffect)(()=>{i>=e.atMs&&r()},[i,e.atMs,r]),i>=e.atMs)return null;let o=Math.max(1,Math.round((e.atMs-i)/6e4)),s=e.entering,c=n(s===`peak`?`tierPeak`:`tierOff`),l=n(e.channel===`zhipu-coding-plan`?s===`peak`?`peakAlertDescPeakZhipu`:`peakAlertDescOffZhipu`:s===`peak`?`peakAlertDescPeak`:`peakAlertDescOff`),u=s===`peak`;return(0,m.jsxs)(`div`,{className:y(V.peakCard,u?V.peakCardPeak:V.peakCardOff,t.position===`center`?V.peakCardCenter:V.peakCardCorner),"data-testid":`billing-peak-alert`,role:`alert`,children:[(0,m.jsxs)(`div`,{className:V.peakHead,children:[(0,m.jsxs)(`span`,{className:y(V.peakTag,u?V.peakTagPrimary:V.peakTagSuccess),children:[(0,m.jsx)(`span`,{className:y(V.peakDot,u?V.peakDotPrimary:V.peakDotSuccess),"aria-hidden":`true`}),c]}),(0,m.jsx)(`button`,{type:`button`,className:V.peakClose,onClick:r,"aria-label":n(`close`),children:`×`})]}),(0,m.jsxs)(`div`,{className:y(V.peakCount,u?V.peakCountPrimary:V.peakCountSuccess),children:[o,`min`]}),(0,m.jsx)(`p`,{className:V.peakDesc,children:l})]})}let fr=[50,80,100],pr=3e4,mr={total:{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,reasoning:0},byModel:{},byDay:{},byDayModels:{}},hr=[`#4f8cff`,`#2dd4bf`,`#a78bfa`,`#f59e0b`,`#f472b6`,`#fbbf24`,`#38bdf8`,`#6366f1`,`#f97316`,`#14b8a6`],gr={checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]},_r=[{id:`overview`,labelKey:`tabOverview`},{id:`providers`,labelKey:`tabProviders`},{id:`token`,labelKey:`tabToken`},{id:`trends`,labelKey:`tabTrends`},{id:`pricing`,labelKey:`tabPricing`},{id:`settings`,labelKey:`tabSettings`}],vr={fill:`none`,"aria-hidden":!0,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`},yr={overview:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...vr,children:(0,m.jsx)(`path`,{d:`M2 13V3M2 13H14M4 10l4-3 2 2 4-5`})}),providers:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...vr,children:[(0,m.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.5`}),(0,m.jsx)(`path`,{d:`M5 7l2 2 4-4`})]}),token:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...vr,children:[(0,m.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`11`,r:`3`})]}),trends:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...vr,children:(0,m.jsx)(`path`,{d:`M2 4l4 4 3-3 5 5M11 10h3V7`})}),pricing:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...vr,children:[(0,m.jsx)(`path`,{d:`M8 2l6 3v6l-6 3-6-3V5z`}),(0,m.jsx)(`path`,{d:`M8 2v12M2 5h12`})]}),settings:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...vr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`2.5`}),(0,m.jsx)(`path`,{d:`M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2`})]})},br=p,xr=br.IconChevronDownOutlineMedium??br.IconChevronDownOutline14;function Sr(e,t){let n=Object.keys(e).filter(e=>e<=t).sort().slice(-7);return n.length===0?0:n.reduce((t,n)=>t+(e[n]?.cost??0),0)/n.length}function Cr(e,t,n){let r=Object.keys(e).filter(e=>e.startsWith(t)),i=t.split(`-`),a=new Date(Number(i[0]),Number(i[1]),0).getDate(),o=r.length>0?r.reduce((t,n)=>t+(e[n]?.cost??0),0)/r.length:Sr(e,n);return o<=0?0:o*a}function wr(e){return Object.keys(e).length}function Tr(e,t=Date.now()){let n=0,r=new Date(t);for(;q(r.getTime())in e;)n+=1,r.setDate(r.getDate()-1);return n}function Er(e){return e.input+e.output}function Dr(e){let t=[];for(let n=6;n>=0;--n){let r=new Date;r.setDate(r.getDate()-n);let i=q(r.getTime());t.push({date:i,cost:e[i]?.cost??0})}return t}function Or(e,t,n=e=>e.cost){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=0;for(let t=0;t<=i;t+=1){let i=new Date(r);i.setDate(i.getDate()-t);let o=e[q(i.getTime())];o!==void 0&&(a+=n(o))}return a}function kr(e,t,n){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=new Date(r);a.setDate(a.getDate()-i);let o=q(a.getTime()),s=new Date(r);s.setDate(s.getDate()-6);let c=q(s.getTime()),l=0,u=0,d=0,f=0,p=0,m=0,h=0,g,_=0;for(let[r,i]of Object.entries(e)){if(!(n===`today`?r===t:n===`7d`?r>=c&&r<=t:n===`week`?r>=o&&r<=t:r.startsWith(t.slice(0,7))))continue;l+=i.cost,u+=i.calls,d+=i.input,f+=i.output,p+=i.cacheHit,m+=i.cacheMiss,h+=i.reasoning??0;let e=Er(i);e>_&&(_=e,g=r)}return{cost:l,calls:u,input:d,output:f,cacheHit:p,cacheMiss:m,reasoning:h,peakDay:g,peakTokens:_}}function Ar(e,t){let n={};if(e===void 0)return n;for(let[r,i]of Object.entries(e))if(r.startsWith(t))for(let[e,t]of Object.entries(i))n[e]=(n[e]??0)+t.cost;return n}let jr=[80,100];function Mr(e,t){if(!(t>0)||!(e>0))return[];let n=e/t*100;return jr.filter(e=>n>=e)}let Nr={DeepSeek:[`deepseek`],"智谱 AI":[`zhipu`,`glm`,`z.ai`],阿里通义:[`qwen`,`tongyi`,`dashscope`,`aliyun`],字节豆包:[`doubao`,`volcengine`,`ark`],月之暗面:[`moonshot`,`kimi`],小米:[`xiaomi`,`mi`,`mimo`],MiniMax:[`minimax`],百度文心:[`ernie`,`wenxin`,`qianfan`,`baidu`],腾讯混元:[`hunyuan`,`tencent`],零一万物:[`01.ai`,`lingyi`,`yi`],阶跃星辰:[`step`,`stepfun`,`step-3.7`],科大讯飞:[`spark`,`xfyun`,`iflytek`],商汤:[`sensenova`,`sensetime`],百川智能:[`baichuan`],OpenAI:[`openai`],Google:[`google`,`gemini`],xAI:[`xai`,`grok`],Meta:[`meta`,`llama`],Anthropic:[`claude`,`anthropic`],"Mistral AI":[`mistral`,`ministral`,`devstral`],Cohere:[`cohere`,`command`],美团:[`longcat`,`meituan`],面壁智能:[`minicpm`,`modelbest`],小红书:[`dots`,`rednote`,`xiaohongshu`],云知声:[`unisound`,`u2`]};function $(e){return e.trim().toLowerCase().replace(/[\s_/-]+/g,``)}function Pr(e,t){if(e.length===0||t.length===0)return!1;if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return n.length>=3&&r.includes(n)}function Fr(e,t){let n=$(e),r=$(t);if(Pr(n,r))return!0;let i=Nr[e];return i!==void 0&&i.some(e=>Pr($(e),r))}function Ir(e){let t=e.trim().toLowerCase(),n=t.replace(/[\s_/-]+/g,``);if(n.length!==0){for(let[e,n]of Object.entries(Nr))for(let r of n){let n=$(r);if(n.length!==0&&(t===n||t.startsWith(`${n}-`)||t.startsWith(`${n}/`)||t.startsWith(`${n}_`)||t.includes(`${n}-`)||t.includes(`${n}/`)||t.includes(`${n}_`)))return e}for(let[e,t]of Object.entries(Nr))for(let r of t){let t=$(r);if(!(t.length<4)&&n.includes(t))return e}}}let Lr={"kimi-coding":`月之暗面`,"zai-coding-cn":`智谱 AI`,"zai-coding":`智谱 AI`,"qwen-token-plan":`阿里通义`,"qwen-token-plan-cn":`阿里通义`,"xiaomi-token-plan-ams":`小米`,"xiaomi-token-plan-cn":`小米`,"xiaomi-token-plan-sgp":`小米`,"volcengine-token-plan":`字节豆包`,"ark-token-plan":`字节豆包`,"doubao-token-plan":`字节豆包`,ernie:`百度文心`,baidu:`百度文心`,wenxin:`百度文心`,minimax:`MiniMax`,"minimax-cn":`MiniMax`,"minimax-token-plan":`MiniMax`,"minimax-token-plan-cn":`MiniMax`,"hunyuan-token-plan":`腾讯混元`,"tencent-token-plan":`腾讯混元`,"hy-token-plan":`腾讯混元`,"xinghuo-token-plan":`讯飞星火`,"xfyun-coding":`讯飞星火`,"spark-coding":`讯飞星火`,"huawei-token-plan":`华为云`,"pangu-token-plan":`华为云`,"huawei-maas-token-plan":`华为云`,"volcengine-agent-plan":`字节豆包`,"ark-agent-plan":`字节豆包`,"baidu-token-plan":`百度文心`,"ernie-token-plan":`百度文心`,"wenxin-token-plan":`百度文心`,opencode:`OpenCode`,"opencode-go":`OpenCode`};function Rr(e){let t=Lr[e];return t===void 0?Ir(e)??e:t}let zr=`https://platform.kimi.com/console/pay`,Br=`https://open.bigmodel.cn/finance-center/finance/pay`,Vr=`https://bailian.console.aliyun.com/`,Hr=`https://console.volcengine.com/ark`,Ur=`https://console.anthropic.com/settings/billing`,Wr=`https://console.cloud.google.com/billing`,Gr=`https://console.x.ai/`,Kr=`https://platform.xiaomimimo.com/console/balance`,qr=`https://console.cloud.tencent.com/expense/recharge`,Jr={deepseek:`https://platform.deepseek.com/top_up`,minimax:`https://platform.minimax.cn/console/recharge-records`,moonshot:zr,kimi:zr,zhipu:Br,bigmodel:Br,qwen:Vr,dashscope:Vr,doubao:Hr,volcengine:Hr,ark:Hr,openai:`https://platform.openai.com/settings/organization/billing`,anthropic:Ur,claude:Ur,google:Wr,gemini:Wr,xai:Gr,grok:Gr,siliconflow:`https://cloud.siliconflow.cn/account/charge`,hunyuan:qr,tencent:qr,腾讯云:qr,xiaomi:Kr,mimo:Kr,mi:Kr,qianfan:`https://console.bce.baidu.com/qianfan/overview`};function Yr(e){let t=Jr[e];if(t!==void 0)return t;let n=Object.keys(Jr).find(t=>e.startsWith(t));return n===void 0?void 0:Jr[n]}function Xr(e){let t=$(e),n=Yr(t);if(n!==void 0)return n;for(let[e,n]of Object.entries(Nr))if(Pr($(e),t))for(let e of n){let t=Yr($(e));if(t!==void 0)return t}}function Zr(e){let t=et();if(t===void 0||e.byDayModels===void 0)return e;let n=lt().rate,r=e.byDayModelsSite!==void 0,i={},a={},o=new Map,s=0,c=e=>t.some(t=>t.origin!==void 0&&t.origin!==``&&(t.key===e||W(t.key)===W(e))),l=(e,t,r)=>{if(e===void 0)return r;let i=Math.min(t.cacheHit,t.cacheMiss+t.cacheHit),a=r=>{let a=(t.cacheMiss*r.input+i*r.cacheHit+t.output*r.output)/1e6;return e.currency===`USD`?a*n:a};return e.offPeak===void 0?a(e):a(e)*dt+a(e.offPeak)*.5};for(let[t,n]of Object.entries(e.byDayModels)){let u=0,d={};for(let[i,a]of Object.entries(n)){let n=nt(i)??it(i),s=r&&c(i),f;if(s&&e.byDayModelsSite?.[t]?.[i]!==void 0){let r=0;for(let[a,o]of Object.entries(e.byDayModelsSite[t][i])){let e=a.startsWith(`site:`)?a.slice(5):void 0,t=e===void 0?void 0:nt(i,e);r+=l(t??n,o,o.cost)}f=r}else f=l(n,a,a.cost);u+=f,d[i]={...a,cost:f},o.set(i,(o.get(i)??0)+f)}let f=e.byDay[t];f!==void 0&&(i[t]={...f,cost:u}),a[t]=d,s+=u}return{...e,total:{...e.total,cost:s},byDay:i,byDayModels:a,byModel:Object.fromEntries(Object.entries(e.byModel).map(([e,t])=>{let n=o.get(e);return[e,n===void 0?t:{...t,cost:n}]})),unpricedModels:(e.unpricedModels??[]).filter(e=>!nt(e)&&!it(e))}}let Qr=new Set;function $r(){return typeof Notification<`u`&&Notification.permission===`granted`}function ei(e,t){Qr.has(e)||(Qr.add(e),fetch(`/api/billing/notify-claim`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({key:e})}).then(e=>e.json()).then(e=>{e.claimed!==!1&&t()}).catch(()=>t()))}function ti(e){let t=new Map,n=[];for(let r of e){if(r.title===void 0||r.title===``){n.push(r);continue}let e=t.get(r.title);if(e===void 0){let e={...r,mergedCount:1};t.set(r.title,e),n.push(e);continue}e.children===void 0&&(e.children=[{...e}]),e.children.push({...r}),e.calls+=r.calls,e.cost+=r.cost,e.lastActive=Math.max(e.lastActive,r.lastActive),r.stale===!0&&(e.stale=!0),e.mergedCount=(e.mergedCount??1)+1}return n.sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function ni(e){let t=new Map(e.map(e=>[e.id,e])),n=ti(e.filter(e=>e.parentId===void 0)),r=new Map;for(let e of n){r.set(e.id,e);for(let t of e.children??[])r.set(t.id,e)}let i=new Set;for(let n of e){if(n.parentId===void 0)continue;let e=new Set,a=n.parentId;for(;a!==void 0&&!e.has(a);){e.add(a);let o=r.get(a);if(o!==void 0){o.subs===void 0?o.subs=[n]:o.subs.push(n),i.add(n.id);break}a=t.get(a)?.parentId}}for(let e of n)e.subs?.sort((e,t)=>t.lastActive-e.lastActive);let a=e.filter(e=>e.parentId!==void 0&&!i.has(e.id));return[...n,...a].sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function ri(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>(e.title??``).toLowerCase().includes(n)||(e.cwd??``).toLowerCase().includes(n)||e.id.toLowerCase().includes(n))}function ii(e,t){let n=e.trim().toLowerCase();return n!==``&&!t.some(e=>e.toLowerCase().includes(n))}function ai(e,t){return e.checked?e.okProviders.some(e=>Fr(t,e))?V.healthOk:e.badProviders.some(e=>Fr(t,e))?V.healthBad:V.healthIdle:V.healthIdle}function oi(e,t){switch(e){case`ok`:return``;case`not-configured`:return t(`subscriptionNotConfigured`);case`unauthorized`:return t(`subscriptionUnauthorized`);case`rate-limited`:return t(`subscriptionRateLimited`);case`invalid-response`:return t(`subscriptionInvalid`);default:return t(`subscriptionUnavailable`)}}function si(e,t){switch(e){case`session`:return t(`subscriptionSession`);case`weekly`:return t(`subscriptionWeekly`);case`monthly`:return t(`subscriptionMonthly`);case`billing`:return t(`subscriptionBilling`)}}function ci(e,t){switch(e){case`new-api`:return t(`relayKindNewApi`);case`sub2api`:return t(`relayKindSub2Api`);default:return t(`relayKindUnknown`)}}let li={"new-api":V.siteKindSite,sub2api:V.siteKindDirect,unknown:V.siteKindUnknown},ui=e=>e.models.reduce((e,t)=>e+(t.actual??(t.plan===!0?0:t.estimated)),0);function di(e){return e.children===void 0?{cost:e.subCost??0,calls:e.subCalls??0}:(e.children??[]).reduce((e,t)=>({cost:e.cost+(t.subCost??0),calls:e.calls+(t.subCalls??0)}),{cost:0,calls:0})}function fi(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}async function pi(){try{let e=await fetch(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n||!(`total`in n))return null;let r=n,i=e=>typeof e==`object`&&!!e;return{total:r.total??mr.total,byModel:r.byModel??{},byDay:r.byDay??{},...r.byDayModels===void 0?{}:{byDayModels:r.byDayModels},...i(r.byDayModelsSite)?{byDayModelsSite:r.byDayModelsSite}:{},...r.updatedAt===void 0?{}:{updatedAt:r.updatedAt},...typeof r.budget==`number`?{budget:r.budget}:{},...typeof r.lowBalanceThreshold==`number`?{lowBalanceThreshold:r.lowBalanceThreshold}:{},...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{},...Array.isArray(r.byWorkspace)?{byWorkspace:r.byWorkspace}:{},...i(r.bySite)?{bySite:r.bySite}:{},...i(r.byTier)?{byTier:r.byTier}:{},...i(r.byTool)?{byTool:r.byTool}:{},...Array.isArray(r.unpricedModels)?{unpricedModels:r.unpricedModels}:{},...typeof r.staleLedgerSessions==`number`?{staleLedgerSessions:r.staleLedgerSessions}:{},...typeof r.unreadableSessions==`number`?{unreadableSessions:r.unreadableSessions}:{},...typeof r.unreadableFormatSessions==`number`?{unreadableFormatSessions:r.unreadableFormatSessions}:{},...typeof r.unreadableNoLedgerSessions==`number`?{unreadableNoLedgerSessions:r.unreadableNoLedgerSessions}:{},...typeof r.searchCallEstimateCny==`number`?{searchCallEstimateCny:r.searchCallEstimateCny}:{},...r.byRole!==null&&typeof r.byRole==`object`?{byRole:r.byRole}:{},...r.perf!==null&&typeof r.perf==`object`&&r.perf.byModel!==null&&typeof r.perf.byModel==`object`&&r.perf.byHourModel!==null&&typeof r.perf.byHourModel==`object`?{perf:r.perf}:{},...typeof r.pluginVersion==`string`?{pluginVersion:r.pluginVersion}:{}}}catch{return null}}async function mi(){try{let e=await fetch(`/api/billing/balance`);if(!e.ok)return{balances:[]};let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return{balances:[]};let r=n;return{balances:Array.isArray(r.balances)?r.balances:[],...r.reconcile===void 0?{}:{reconcile:r.reconcile}}}catch{return{balances:[]}}}async function hi(){let e=await fetch(`/api/billing/subscriptions`);if(!e.ok)throw Error(`subscriptions HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`subscriptions: invalid response`)}async function gi(){let e=await fetch(`/api/billing/relay-quotas`);if(!e.ok)throw Error(`relay-quotas HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`relay-quotas: invalid response`)}async function _i(){try{let e=await fetch(`/api/billing/usage-tool`);if(!e.ok)return;let t=JSON.parse(await e.text());return typeof t.enabled==`boolean`?t.enabled:void 0}catch{return}}async function vi(e){try{let t=await fetch(`/api/billing/usage-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:e})});return t.ok?JSON.parse(await t.text()).ok===!0:!1}catch{return!1}}let yi=!1,bi=0;async function xi(e=0){try{let t=await fetch(`/api/billing/pricing`);if(!t.ok){yi=!1;return}let n=await t.text(),r=JSON.parse(n);if(typeof r!=`object`||!r||!(`source`in r)){yi=!1;return}let i=r;Array.isArray(i.catalog)&&i.catalog.length>0&&i.aliases!==null&&typeof i.aliases==`object`&&Dt(i.catalog,i.aliases);let a=r;if(a.source===`builtin`&&e<3){if(e===0){if(yi)return;yi=!0}setTimeout(()=>{xi(e+1)},2e3);return}yi=!1,bi=a.syncedAt??0,at(a)}catch{yi=!1}}async function Si(){try{return(await fetch(`/api/billing/pricing/refresh`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`})).ok?(await xi(),!0):!1}catch{return!1}}function Ci(e,t){switch(e){case`overview`:return{label:`实时`,kind:`neutral`};case`providers`:return{label:`${t.providersCount} 厂商`,kind:`neutral`};case`token`:return{label:wi(t.tokenTotal),kind:`neutral`};case`trends`:return null;case`pricing`:return t.rateAgeMinutes===null||t.rateAgeMinutes<360?{label:`已同步`,kind:`neutral`}:{label:`需同步`,kind:`violet`};case`settings`:return t.settingsDirty<=0?null:{label:String(t.settingsDirty),kind:`hot`}}}function wi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Ti({window:e,t}){let n=Math.min(100,Math.max(0,e.usedPercent)),r=Math.min(100,Math.max(0,e.remainingPercent))<=0;return(0,m.jsxs)(`div`,{className:V.subscriptionWindow,children:[(0,m.jsx)(`span`,{className:V.subscriptionWindowLabel,children:si(e.kind,t)}),(0,m.jsx)(`span`,{className:V.subscriptionTrack,"aria-hidden":`true`,children:(0,m.jsx)(`span`,{className:y(V.subscriptionFill,n>=100&&V.subscriptionFillOver,n>=80&&n<100&&V.subscriptionFillWarn),style:{width:`${n}%`}})}),(0,m.jsxs)(`span`,{className:V.subscriptionMeta,children:[(0,m.jsx)(`span`,{className:y(V.subscriptionPct,r&&V.subscriptionExhausted),children:r?t(`subscriptionExhausted`):t(`subscriptionRemaining`).replace(`{pct}`,String(e.remainingPercent))}),e.resetsAt!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionReset,children:t(`subscriptionReset`).replace(`{date}`,`${q(new Date(e.resetsAt).getTime())} ${fi(new Date(e.resetsAt).getTime())}`)})]})]})}function Ei({label:e,t}){return(0,m.jsx)(p.Tooltip,{label:e,side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.helpTip,role:`note`,"aria-label":e,children:`?`})})}function Di(e,t){return e===V.healthOk?t(`healthDotLive`):e===V.healthBad?t(`healthDotFailed`):t(`healthDotUnknown`)}function Oi(e){let t=t=>K(Xt(t,e.currency),e.currency),{wide:n,t:r,onOpen:i,monthCost:a,todayCost:o,weekCost:s,days:c,vendorStatus:l,dash:u,floatPrefs:p,subscriptions:h,cardPrefs:g,monthTokens:_,todayTokens:v,weekTokens:b,budgetPressure:x,deltaPct:S=0}=e,C=(0,d.useMemo)(()=>p.targets.map(e=>h.find(t=>t.provider===e)).filter(e=>e!==void 0),[p.targets,h]),[w,T]=(0,d.useState)(0),ee=C.length===0?0:Math.min(w,C.length-1),E=C[ee],D=(0,d.useRef)(null),[O,k]=(0,d.useState)(!1),[te,A]=(0,d.useState)({left:0,top:0});(0,d.useEffect)(()=>{if(!O||p.mode!==`subscription`||C.length<2)return;let e=setInterval(()=>T(e=>(e+1)%C.length),1500);return()=>clearInterval(e)},[O,p.mode,C.length]);let j=(0,d.useRef)(void 0),ne=(0,d.useCallback)(()=>{window.clearTimeout(j.current),k(!0)},[]),re=(0,d.useCallback)(()=>{window.clearTimeout(j.current),j.current=window.setTimeout(()=>k(!1),120)},[]);(0,d.useEffect)(()=>()=>window.clearTimeout(j.current),[]);let M=(0,d.useCallback)(()=>{let e=D.current?.getBoundingClientRect();e!==void 0&&A({left:e.left,top:e.top-8})},[]);(0,d.useEffect)(()=>{if(!O)return;let e=()=>M();return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[O,M]);let ie=c.length>0?c.reduce((e,t)=>e+t.cost,0)/c.length:0,ae=ie>0?Math.max(0,Math.min(1,o/ie)):0,oe=-80+ae*160,se=(0,m.jsxs)(`svg`,{viewBox:`3.5 10 34 22`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,opacity:.16}),(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,strokeDasharray:`${(41.9*ae).toFixed(2)} 41.9`,className:V.triggerGaugeArc}),(0,m.jsx)(`path`,{d:`M5.23 26.4 8.18 26.92M10.36 17.51 12.29 19.81M20 14v3M27.71 19.81 29.64 17.51M31.82 26.92 34.77 26.4`,strokeWidth:1.6,opacity:.7}),(0,m.jsx)(`path`,{d:`M7.01 21.5 8.31 22.25M14.87 14.91 15.38 16.31M24.62 16.31 25.13 14.91M31.69 22.25 32.99 21.5`,strokeWidth:1.2,opacity:.38}),(0,m.jsx)(`line`,{x1:`20`,y1:`29`,x2:`20`,y2:`19.5`,strokeWidth:2,className:V.triggerGaugeNeedle,style:{transform:`rotate(${oe}deg)`,transformOrigin:`20px 29px`}}),(0,m.jsx)(`circle`,{cx:`20`,cy:`29`,r:`1.5`,fill:`currentColor`,stroke:`none`})]});if(!n)return(0,m.jsx)(`button`,{type:`button`,className:y(V.railButton,x!==`none`&&V.triggerBudgetPulse,x===`over`&&V.triggerBudgetOver),"data-testid":`billing-rail-button`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:se});let N=g.metric===`tokens`,ce=c.map(e=>N?e.tokens:e.cost),P=Math.max(...ce,0),le=ce.map(e=>P>0?4+e/P*12:4);return(0,m.jsxs)(`span`,{ref:D,className:V.triggerWrap,onMouseEnter:()=>{M(),ne()},onMouseLeave:re,onFocusCapture:()=>{M(),ne()},onBlurCapture:()=>k(!1),children:[(0,m.jsxs)(`button`,{type:`button`,className:y(V.trigger,x!==`none`&&V.triggerBudgetPulse,x===`over`&&V.triggerBudgetOver),"data-testid":`billing-trigger`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:[(0,m.jsx)(`span`,{className:y(V.triggerIcon,x!==`none`&&V.triggerBudgetHot),"data-testid":`billing-trigger-icon`,children:se}),(0,m.jsx)(`span`,{className:V.triggerMain,children:(0,m.jsxs)(`span`,{className:V.triggerPrimary,children:[(0,m.jsx)(`span`,{className:V.triggerLabel,children:N?g.span===`day`?r(`triggerTodayTokens`):g.span===`week`?r(`triggerWeekTokens`):r(`triggerMonthTokens`):g.span===`day`?r(`triggerToday`):g.span===`week`?r(`weekCost`):r(`triggerMonth`)}),(()=>{let e=g.span===`day`?N?v:o:g.span===`week`?N?b:s:N?_:a,n=g.span===`day`?S:0;return N?(0,m.jsx)(`span`,{className:V.triggerMetric,"data-testid":`billing-trigger-span-tokens`,children:J(e)}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{className:V.triggerValueRow,children:[(0,m.jsx)(`span`,{className:V.triggerYen,"aria-hidden":`true`,children:t(e).charAt(0)}),(0,m.jsx)(`span`,{className:V.triggerMetric,"data-testid":`billing-trigger-span-money`,children:t(e).slice(1)})]}),g.showDelta&&n!==0&&(0,m.jsxs)(`span`,{className:y(V.triggerDelta,n>0?V.triggerDeltaUp:V.triggerDeltaDown),"data-testid":`billing-trigger-delta`,children:[n>0?`▲`:`▼`,` `,Math.abs(n).toFixed(1),`%`]}),(0,m.jsx)(`span`,{className:V.triggerGlow,"aria-hidden":`true`})]})})()]})}),(0,m.jsx)(`span`,{className:V.triggerSpark,"data-testid":`billing-trigger-spark`,"aria-hidden":`true`,children:le.map((e,t)=>(0,m.jsx)(`span`,{className:t===le.length-1?V.triggerSparkHot:V.triggerSparkBar,style:{height:`${e}px`}},c[t]?.date??String(t)))})]}),(0,f.createPortal)((0,m.jsx)(`span`,{className:y(V.triggerPop,O&&V.triggerPopShown),style:{left:`${te.left}px`,top:`${te.top}px`},"data-testid":`billing-trigger-pop`,"aria-hidden":!O,onMouseEnter:ne,onMouseLeave:re,children:p.mode===`subscription`?(0,m.jsx)(m.Fragment,{children:C.length===0?(0,m.jsx)(`span`,{className:V.triggerPopEmpty,children:r(`floatNoTargets`)}):(0,m.jsxs)(m.Fragment,{children:[E!==void 0&&(0,m.jsxs)(`div`,{className:V.floatSub,"data-testid":`billing-float-subscription`,children:[(0,m.jsxs)(`div`,{className:V.floatSubHead,children:[(0,m.jsx)(`span`,{className:V.floatSubName,children:E.displayName}),E.plan!==void 0&&(0,m.jsx)(`span`,{className:V.floatSubPlan,children:E.plan})]}),E.windows.map(e=>(0,m.jsx)(Ti,{window:e,t:r},e.kind))]}),C.length>1&&(0,m.jsx)(`span`,{className:V.triggerPopSwitcher,"data-testid":`billing-float-switcher`,children:(0,m.jsxs)(`span`,{className:V.triggerPopSwitchCount,children:[ee+1,`/`,C.length]})})]})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:V.popHead,children:(0,m.jsx)(`span`,{className:V.popTitle,children:r(`popTitle`)})}),(0,m.jsxs)(`span`,{className:V.metricGrid,children:[(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryToday`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(o)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryWeek`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(s)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`floatPrimaryMonth`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:t(a)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`input`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:J(u.input)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`output`)}),(0,m.jsx)(`span`,{className:V.metricValue,children:J(u.output)})]}),(0,m.jsxs)(`span`,{className:V.metricCell,children:[(0,m.jsx)(`span`,{className:V.metricLabel,children:r(`cacheHit`)}),(0,m.jsx)(`span`,{className:y(V.metricValue,V.metricValueSuccess),children:$t(u.cacheRead+u.cacheMiss>0?u.cacheRead/(u.cacheRead+u.cacheMiss)*100:0)})]})]}),(0,m.jsxs)(`span`,{className:V.popModel,children:[(0,m.jsx)(`span`,{className:V.popModelLabel,children:r(`popTodayModel`)}),l.direct!==void 0||l.sub!==void 0?(0,m.jsxs)(m.Fragment,{children:[l.direct!==void 0&&(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotDirect),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popTagPrimary,children:r(`popDirectLead`)}),(0,m.jsx)(`span`,{className:V.popModelName,children:l.direct.name}),(0,m.jsx)(`span`,{className:y(V.popModelStatus,l.direct.low&&V.popModelStatusLow),children:l.direct.text})]}),l.sub!==void 0&&(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotSub),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popTagSub,children:r(`popSubLead`)}),(0,m.jsx)(`span`,{className:V.popModelName,children:l.sub.name}),(0,m.jsx)(`span`,{className:y(V.popModelStatus,l.sub.low&&V.popModelStatusLow),children:l.sub.text})]})]}):(0,m.jsxs)(`span`,{className:V.popModelRow,children:[(0,m.jsx)(`span`,{className:y(V.popDot,V.popDotNeutral),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:V.popModelStatus,children:r(`popNoConsumption`)})]})]})]})}),document.body)]})}function ki({balance:e,days:t,dailyBurn:n,money:r,t:i,onClose:a}){let o=t=>t===void 0?void 0:e.currency===`USD`?`$${t.toFixed(2)}`:r(t),s=o(e.totalBalance),c=o(e.grantedBalance),l=o(e.toppedUpBalance);return(0,m.jsxs)(`span`,{className:V.balanceDetailPop,"data-testid":`billing-balance-detail-pop`,onClick:e=>{e.stopPropagation()},children:[(0,m.jsxs)(`span`,{className:V.balanceDetailHead,children:[(0,m.jsx)(`span`,{className:V.balanceDetailTitle,children:e.displayName}),(0,m.jsx)(`button`,{type:`button`,className:V.balanceDetailClose,"aria-label":i(`close`),onClick:a,children:`×`})]}),(0,m.jsxs)(`span`,{className:V.balanceDetailGrid,children:[s!==void 0&&(0,m.jsx)(Ai,{label:i(`balance`),value:s}),c!==void 0&&(0,m.jsx)(Ai,{label:i(`balanceGranted`),value:c}),l!==void 0&&(0,m.jsx)(Ai,{label:i(`balanceTopped`),value:l}),(0,m.jsx)(Ai,{label:i(`balanceDaily`),value:r(n)}),(0,m.jsx)(Ai,{label:i(`balanceDaysLong`),value:`${t} ${i(`balanceDaysUnit`)}`})]})]})}function Ai({label:e,value:t}){return(0,m.jsxs)(`span`,{className:V.balanceDetailRow,children:[(0,m.jsx)(`span`,{className:V.balanceDetailLabel,children:e}),(0,m.jsx)(`span`,{className:V.balanceDetailValue,children:t})]})}function ji({userPrices:e,onUserPrices:t,t:n}){let[r,i]=(0,d.useState)(()=>[...e]),[a,o]=(0,d.useState)(new Set),s=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),c=()=>{i(e=>e.filter((e,t)=>!a.has(t))),o(new Set)},l=(e,t)=>i(n=>n.map((n,r)=>r===e?{...n,...t}:n)),u=()=>i(e=>[...e,{key:``,input:0,cacheHit:0,output:0}]),f=e=>{let t=r[e]?.offPeak;return{input:t===void 0?``:String(t.input),cacheHit:t===void 0?``:String(t.cacheHit),output:t===void 0?``:String(t.output)}},p=(e,t,n)=>i(r=>r.map((r,i)=>{if(i!==e)return r;let a=r.offPeak,o={input:a===void 0?``:String(a.input),cacheHit:a===void 0?``:String(a.cacheHit),output:a===void 0?``:String(a.output),[t]:n},s=[o.input,o.cacheHit,o.output].some(e=>e.trim()!==``),c=[o.input,o.cacheHit,o.output].map(e=>Number(e)),l=s&&c.every(e=>Number.isFinite(e)&&e>=0)&&c.some(e=>e>0),{offPeak:u,...d}=r;return l?{...d,offPeak:{input:c[0]??0,cacheHit:c[1]??0,output:c[2]??0}}:d})),h=()=>t(r.filter(e=>e.key.trim()!==``).map(e=>({...e,key:e.key.trim(),...e.origin===void 0||e.origin.trim()===``?{}:{origin:Ze(e.origin.trim())}}))),g=Kt().map(e=>e.key),_=(e,t)=>i(n=>n.map((n,r)=>{if(r!==e)return n;let{currency:i,...a}=n;return t===`USD`?{...a,currency:`USD`}:a})),[v,b]=(0,d.useState)({}),x=(e,t,n)=>`${e}:${t}:${n}`,S=(e,t,n)=>b(r=>{let i=x(e,t,n);if(r[i]===void 0)return r;let a={...r};return delete a[i],a}),C=e=>Number.isFinite(e)&&e!==0?String(e):``,w=(e,t,n)=>{if(b(r=>({...r,[x(e,`main`,t)]:n})),n===``){l(e,{[t]:0});return}let r=Number(n);Number.isFinite(r)&&r>=0&&l(e,{[t]:r})};return(0,m.jsxs)(`section`,{className:V.setCard,"data-testid":`billing-user-prices`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[n(`userPrices`),(0,m.jsx)(Ei,{label:n(`userPricesHint`),t:n})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsx)(`datalist`,{id:`billing-price-model-keys`,children:g.map(e=>(0,m.jsx)(`option`,{value:e},e))}),r.map((e,t)=>(0,m.jsxs)(`div`,{className:V.userPriceRow,"data-testid":`billing-user-price-row`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:V.userPriceCheck,"data-testid":`billing-user-price-select`,checked:a.has(t),"aria-label":n(`userPriceSelect`),onChange:()=>s(t)}),(0,m.jsxs)(`div`,{className:V.userPriceBody,children:[(0,m.jsxs)(`div`,{className:V.userPriceLineMeta,children:[(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceModel`)}),(0,m.jsx)(`input`,{className:V.userPriceInput,"data-testid":`billing-user-price-model`,type:`text`,list:`billing-price-model-keys`,value:e.key,placeholder:`flash`,"aria-label":n(`userPriceModel`),onChange:e=>l(t,{key:e.target.value})})]}),(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceSource`)}),(0,m.jsx)(`input`,{className:V.userPriceInput,"data-testid":`billing-user-price-origin`,type:`text`,value:e.origin??``,placeholder:n(`userPriceSourceHint`),"aria-label":n(`userPriceSource`),onChange:e=>l(t,{origin:e.target.value.trim()})})]}),(0,m.jsxs)(`div`,{className:V.userPriceField,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:n(`userPriceCurrency`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,e.currency!==`USD`&&V.floatModeBtnOn),onClick:()=>_(t,`CNY`),children:`CNY`}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,e.currency===`USD`&&V.floatModeBtnOn),onClick:()=>_(t,`USD`),children:`USD`})]})]})]}),[{scope:`main`,label:n(`userPriceNormal`),testid:`billing-user-price-normal`,valueOf:n=>v[x(t,`main`,n)]??C(e[n]),onChange:(e,n)=>w(t,e,n)},{scope:`off`,label:n(`userPriceOffPeak`),testid:`billing-user-price-offpeak`,valueOf:e=>v[x(t,`off`,e)]??f(t)[e],onChange:(e,n)=>{b(r=>({...r,[x(t,`off`,e)]:n})),p(t,e,n)}}].map(e=>(0,m.jsxs)(`div`,{className:V.userPricePriceLine,"data-testid":e.testid,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:e.label}),[`input`,`cacheHit`,`output`].map(r=>{let i=n(r===`input`?`tokenMiss`:r===`cacheHit`?`tokenHit`:`tokenOutput`);return(0,m.jsx)(`input`,{className:V.userPriceInputNum,type:`number`,min:0,step:.01,placeholder:i,"aria-label":`${e.label} ${i}`,value:e.valueOf(r),onChange:t=>e.onChange(r,t.target.value),onBlur:()=>S(t,e.scope,r)},r)})]},e.testid))]})]},t)),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-add`,onClick:u,children:n(`userPriceAdd`)}),(0,m.jsxs)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-remove-selected`,disabled:a.size===0,onClick:c,children:[n(`userPriceRemoveSelected`),a.size>0?` (${a.size})`:``]}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-user-price-save`,onClick:h,children:n(`userPriceSave`)})]})]})]})}function Mi({stats:e,t,onClose:n,userPrices:r,onUserPrices:i,health:a,balances:o,reconcile:s,quotas:c,relayQuotas:l,currency:u,onCurrency:f,language:h,onLanguage:g,turns:_,renderSlot:v,budgetEnabled:b,budgetAmount:x,onToggleBudget:S,onBudgetAmount:C,modelBudgets:w,monthModelCost:T,onModelBudget:ee,peakConfig:E,onPeakConfig:D,onPreviewPeak:O,floatPrefs:k,onFloatPrefs:te,cardPrefs:A,onCardPrefs:j,sitePrefs:M,onSitePrefs:ie,liveCostPrefs:ae,onLiveCostPrefs:oe,quotasStale:se}){let[N,ce]=(0,d.useState)(`cost`),{total:P,byModel:le,byDay:F}=e,[I,ue]=(0,d.useState)(`overview`),[de,fe]=(0,d.useState)(7),[pe,he]=(0,d.useState)(()=>{try{return window.localStorage.getItem(`dsh-billing:reconcile-dismissed`)??``}catch{return``}}),ge=()=>{let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`},ye=(0,d.useCallback)(()=>{let e=ge();he(e);try{window.localStorage.setItem(`dsh-billing:reconcile-dismissed`,e)}catch{}},[]),[R,xe]=(0,d.useState)(()=>{let e=[`unpriced`,`search-estimate`,`unreadable`],t=new Set,n=new Date,r=e=>String(e).padStart(2,`0`),i=`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}`;try{for(let n of e)window.localStorage.getItem(`dsh-billing:notice-${n}-dismissed`)===i&&t.add(n)}catch{}return t}),Se=(0,d.useCallback)(e=>{let t=ge();xe(t=>new Set(t).add(e));try{window.localStorage.setItem(`dsh-billing:notice-${e}-dismissed`,t)}catch{}},[]),[we,Te]=(0,d.useState)(`month`),[Ee,De]=(0,d.useState)(`cost`),[z,Oe]=(0,d.useState)(je),[ke,Ae]=(0,d.useState)(Fe),[Ne,Le]=(0,d.useState)(`budget`),[Re,ze]=(0,d.useState)(``),Be=e=>ii(Re,e);(0,d.useEffect)(()=>{if(I!==`settings`||typeof IntersectionObserver>`u`)return;let e=Array.from(document.querySelectorAll(`[id^="settings-"]`)).filter(e=>!e.closest(`[hidden]`));if(e.length===0)return;let t=new IntersectionObserver(e=>{let t,n=1/0;for(let r of e){if(!r.isIntersecting)continue;let e=r.boundingClientRect.top;e<n&&(n=e,t=r.target.id)}t!==void 0&&Le(t.slice(9))},{rootMargin:`-80px 0px -55% 0px`});for(let n of e)t.observe(n);return()=>{t.disconnect()}},[I]);let Ve=(0,d.useCallback)(e=>{if(Le(e),typeof document>`u`)return;let t=document.getElementById(`settings-${e}`);if(t===null)return;let n=t.closest(`.${V.dashboardBody}`);if(n===null)return;let r=t.getBoundingClientRect().top-n.getBoundingClientRect().top;n.scrollTo({top:n.scrollTop+r,behavior:`smooth`})},[]),He=(0,d.useCallback)(e=>{Oe(e),Me(e)},[]),Ue=(0,d.useCallback)(e=>{Ae(e),Ie(e)},[]);(0,d.useEffect)(()=>{typeof document>`u`||(document.documentElement.dataset.density=z,document.documentElement.dataset.motion=ke)},[z,ke]),(0,d.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t?.density!==void 0&&Oe(t.density)},t=e=>{let t=e.detail;t?.motion!==void 0&&Ae(t.motion)};return window.addEventListener(B,e),window.addEventListener(Pe,t),()=>{window.removeEventListener(B,e),window.removeEventListener(Pe,t)}},[]);let[Ge,Ke]=(0,d.useState)(ne),H=(0,d.useMemo)(()=>c.filter(e=>e.status===`ok`&&e.windows.length>0).map(e=>({id:e.provider,label:e.displayName})),[c]),[qe,Je]=(0,d.useState)(),[Ye,Xe]=(0,d.useState)(new Set),[Ze,Qe]=(0,d.useState)(!1),[$e,et]=(0,d.useState)(``),tt=(0,d.useCallback)(e=>{Xe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),nt=(0,d.useMemo)(()=>ni(e.bySession??[]),[e.bySession]),rt=(0,d.useMemo)(()=>ri(e.bySession??[],$e),[e.bySession,$e]),it=(0,d.useMemo)(()=>[...new Set([...Object.keys(T),...Object.keys(w)])].map(e=>{let t=Ht(e);return{key:e,name:t.key===`other`?void 0:t.name,cost:T[e]??0}}).sort((e,t)=>t.cost-e.cost),[T,w]),[at,ot]=(0,d.useState)(()=>new Set(_e())),st=(0,d.useCallback)(e=>{ot(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),ve([...n]),n})},[]),[ct,ut]=(0,d.useState)(()=>L()),dt=(0,d.useCallback)(()=>{ut(e=>{let t=!e;return be(t),t})},[]),[ft,pt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{let e=!0;return _i().then(t=>{e&&t!==void 0&&pt(t)}),()=>{e=!1}},[]);let mt=(0,d.useCallback)(()=>{let e=!ft;pt(e),vi(e).then(t=>{t||pt(!e)})},[ft]),ht=lt(),[gt,_t]=(0,d.useState)(!1),vt=(0,d.useCallback)(()=>{gt||(_t(!0),Si().finally(()=>{_t(!1)}))},[gt]),yt=bi,U=e=>K(Xt(e,u),u),bt=u===`usd`?`$`:u===`eur`?`€`:`¥`,Ct=h,wt=e=>Qn(e,Ct),[Tt,Et]=(0,d.useState)(``),[Dt,Ot]=(0,d.useState)(()=>me()),[kt,At]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{let e=setInterval(()=>{At(Date.now())},3e4);return()=>{clearInterval(e)}},[]);let W=c.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),jt=E.leadMin*6e4,Mt=(e,n)=>e===0?t(`free`):Zt(Qt(e,n,u,ht.rate),u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`),Nt=(0,d.useMemo)(()=>Un([..._].reverse()),[_]),Pt={peak:e.byTier?.peak.cost??0,offPeak:e.byTier?.offPeak.cost??0},Ft=Pt.peak/2,It=Sr(F,q()),Lt=e=>o.find(t=>$(t.provider)===$(e)),Rt=e=>e.balance?.error===`unconfigured`&&e.models.length>0&&e.models.every(e=>e.plan),zt=e=>{if(e===void 0)return(0,m.jsx)(`span`,{className:V.na,children:`—`});if(e.error===`unconfigured`)return t(`balanceUnconfigured`);if(e.error===`unauthorized`)return t(`balanceUnauthorized`);if(e.error===`unreachable`)return t(`balanceUnreachable`);if(e.totalBalance===void 0)return(0,m.jsx)(`span`,{className:V.na,children:`—`});let n=e.currency===`USD`?`$${e.totalBalance.toFixed(2)}`:U(e.totalBalance),r=e.currency===`USD`?e.totalBalance*ht.rate:e.totalBalance,i=It>0?Math.floor(r/It):void 0;return(0,m.jsxs)(`span`,{className:V.balanceCell,children:[(0,m.jsx)(`span`,{children:n}),i!==void 0&&i>=0&&(0,m.jsx)(`button`,{type:`button`,className:y(V.balanceDaysBadge,i<=3&&V.balanceDaysBadgeLow),"data-testid":`billing-balance-days-badge`,title:t(`balanceDays`).replace(`{days}`,String(i)),"aria-label":`${e.displayName} ${t(`balanceDays`).replace(`{days}`,String(i))}`,onClick:t=>{t.stopPropagation(),Je(qe===e.provider?void 0:e.provider)},children:`?`}),qe===e.provider&&(0,m.jsx)(ki,{balance:e,days:i??0,dailyBurn:It,money:U,t,onClose:()=>{Je(void 0)}})]})},Bt=Object.keys(F).sort(),G=q(),Vt=F[G]?.cost??0,Ut=G.slice(0,7),Gt=G.slice(0,4),qt=Bt.reduce((e,t)=>e+(t.startsWith(Ut)?F[t]?.cost??0:0),0),Yt=Bt.reduce((e,t)=>e+(t.startsWith(Gt)?F[t]?.cost??0:0),0),en=(0,d.useMemo)(()=>Cr(F,Ut,G)+c.reduce((e,t)=>e+(t.planType===`code`?t.subscriptionAmount??0:0),0),[F,Ut,G,c]),tn=(0,d.useMemo)(()=>{if(!(b&&x>0))return null;let e=x-qt;return{over:e<=0,remainRatio:Math.max(0,Math.min(1,e/x)),remainCny:Math.max(0,e)}},[b,x,qt]),nn=(0,d.useMemo)(()=>{let e=[];for(let t=de-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t),e.push(q(n.getTime()))}return e},[de]),on=nn.at(-1)??G,Y=(0,d.useMemo)(()=>Object.entries(F).map(([e,t])=>({date:e,value:Ee===`tokens`?Er(t):t.cost})),[F,Ee]),dn=(0,d.useMemo)(()=>Y.reduce((e,t)=>e+t.value,0),[Y]),fn=wr(F),pn=Tr(F),mn=(0,d.useMemo)(()=>nn.map(t=>{let n={},r=e.byDayModels?.[t];if(r!==void 0)for(let[e,t]of Object.entries(r))t.cost>0&&(n[e]=t.cost);let i=F[t];return{date:t,cost:i?.cost??0,calls:i?.calls??0,byModel:n,tokens:i===void 0?0:Er(i)}}),[nn,F,e.byDayModels]),gn=(0,d.useMemo)(()=>Object.entries(le).filter(([,e])=>e.calls>0).map(([e,t])=>{let n=Ht(e),r=n.key===`other`,i=r?Ir(e):void 0,a={input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output};return{key:e,name:r?e:n.name,provider:i??n.provider,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:Jt(n,a),plan:t.plan===!0,...t.cost>0?{actual:t.cost}:{},uncatalogued:r,estimatedPricing:n.estimated===!0,officialCalls:t.officialCalls??0,officialCost:t.officialCost??0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated)).map((e,t)=>({...e,color:hr[t%hr.length]??`#8b95a3`})),[le]),_n=(0,d.useMemo)(()=>M.hideUnidentified?l.filter(e=>e.kind!==`unknown`):l,[l,M.hideUnidentified]),X=(0,d.useMemo)(()=>{let n=e.byDayModelsSite;if(ct){let t=q();n={[t]:e.byDayModelsSite?.[t]??{}}}let r=new Map;for(let t of Object.values(n??{}))for(let[n,i]of Object.entries(t))for(let[t,a]of Object.entries(i)){let i=r.get(t);i===void 0&&(i=new Map,r.set(t,i));let o=i.get(n)??{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,allPlan:!0};o.calls+=a.calls,o.input+=a.input,o.output+=a.output,o.cacheHit+=a.cacheHit,o.cacheMiss+=a.cacheMiss,o.cost+=a.cost,o.allPlan=o.allPlan&&(a.plan??e.byModel?.[n]?.plan===!0),i.set(n,o)}let i=new Map;for(let[e,t]of r){let n=!e.startsWith(`direct:`)&&!e.startsWith(`site:`),r=[...t.entries()].filter(([,e])=>e.calls>0).map(([e,t],r)=>{let i=Ht(e),a=i.key===`other`,o=a?Ir(e)??i.provider:i.provider;return{key:e,name:a?e:i.name,provider:o,color:hr[r%hr.length]??`#8b95a3`,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:n?0:Jt(i,{input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output}),plan:t.allPlan,...t.cost>0?{actual:t.cost}:{},uncatalogued:a,estimatedPricing:i.estimated===!0,officialCalls:0,officialCost:0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));r.length>0&&i.set(e,r)}let s=e=>rr(e,Ct)??t(`channelUnknown`),l=new Map,u=new Map,d=new Map,f=e=>e.startsWith(`direct:`)?`direct`:e.startsWith(`site:`)?`site`:`unknown`,p={direct:2,site:1,unknown:0,vendor:0};for(let[e,t]of i){let n=s(e),r=l.get(n);if(r===void 0)l.set(n,[...t]),u.set(n,f(e)),d.set(n,e);else{r.push(...t),r.sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));let i=u.get(n)??`unknown`,a=f(e);p[a]>p[i]&&(u.set(n,a),d.set(n,e))}}let m=new Map,h=new Map;for(let e of c){if(e.status===`not-configured`)continue;let t=e.displayName??Rr(e.provider),n=s(`direct:${e.provider}`),r=l.has(t)?t:l.has(n)?n:void 0,i=r??`sub:${Rr(e.provider)}`;h.set(i,r??Rr(e.provider));let a=m.get(i);a===void 0?m.set(i,[e]):a.push(e)}let g=e=>e===s(`direct:deepseek`)||e===s(`site:https://api.deepseek.com`)?Lt(`deepseek`)??Lt(e):Lt(e),_=[];for(let[e,t]of l)_.push({id:`ch:${d.get(e)??e}`,name:e,models:t,subscriptions:m.get(e)??[],balance:g(e),dot:ai(a,t[0]?.provider??``),channelKind:u.get(e)??`unknown`});for(let[e,t]of h)l.has(e)||_.push({id:e,name:t,models:[],subscriptions:m.get(e)??[],balance:Lt(t),dot:ai(a,t),channelKind:`vendor`});let v=new Set(_.flatMap(e=>[$(e.name),...e.balance===void 0?[]:[$(e.balance.provider)]]));for(let e of o)v.has($(e.provider))||(e.error===void 0||e.provider.startsWith(`custom:`))&&_.push({id:`bal:${e.provider}`,name:e.displayName,models:[],subscriptions:[],balance:e,dot:ai(a,e.displayName),channelKind:`vendor`});return _.filter(e=>M.hideUnidentified&&e.channelKind===`unknown`?!1:!ct||e.models.length>0).sort((e,t)=>{let n=ui(t)-ui(e);return n===0?e.models.length===0&&t.models.length===0?0:t.models.length===0?-1:e.models.length===0?1:e.name.localeCompare(t.name,`zh`):n})},[e.byDayModelsSite,e.byModel,c,o,a,Ct,t,ct,M.hideUnidentified]),vn=(0,d.useMemo)(()=>{let t=X.length,n=ge(),r=e.byDay??{},i=r[n],a=i?i.input+i.output+i.cacheHit+i.cacheMiss:0;return Object.keys(r).sort(),{providersCount:t,tokenTotal:a,rateAgeMinutes:yt>0?Math.floor((Date.now()-yt)/6e4):null,settingsDirty:0}},[X,e.byDay,yt]),yn=(0,d.useMemo)(()=>X.filter(e=>e.models.length>0||e.subscriptions.length>0).map(e=>e.id),[X]),bn=yn.length>0&&yn.every(e=>at.has(e)),Z=()=>{let e=new Set(bn?[]:yn);ot(e),ve([...e])},Sn=(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`model`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`inputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`outputTokens`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)})]})}),Cn=e=>(0,m.jsx)(`span`,{className:V.modelCell,children:(0,m.jsxs)(`span`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:V.uncataloguedTag,"data-testid":`billing-uncatalogued-tag`,children:t(`uncatalogued`)}),e.estimatedPricing&&(0,m.jsx)(`span`,{className:V.estimatedTag,"data-testid":`billing-estimated-tag`,children:t(`estimatedPricing`)})]}),(0,m.jsx)(`span`,{className:V.modelProvider,children:wt(e.provider)})]})}),wn=e.bySite?.unknown?.calls??0,Tn=gn.reduce((e,t)=>e+t.estimated,0),En=P.cost>0||wn>0?P.cost:Tn,Q=(0,d.useMemo)(()=>{if(Ge===`all`){let e,t=0;for(let[n,r]of Object.entries(F)){let i=Er(r);i>t&&(t=i,e=n)}return{cost:En,calls:P.calls,input:P.input,output:P.output,cacheHit:P.cacheHit,cacheMiss:P.cacheMiss,reasoning:P.reasoning??0,peakDay:e,peakTokens:t}}return kr(F,q(),Ge)},[Ge,En,P,F]),On=(0,d.useMemo)(()=>gn.map(e=>({key:e.key,name:e.name,color:e.color})),[gn]),An=mn.length>=2?mn.at(-2)?.cost??0:0,jn=An>0?(Vt-An)/An*100:0;return(0,m.jsx)(p.Modal,{open:!0,onClose:n,title:t(`title`),headless:!0,className:y(V.dashboardModal,`dsh-billing-modal`),children:(0,m.jsxs)(`div`,{className:V.dashboard,"data-testid":`billing-dashboard`,children:[(0,m.jsxs)(`div`,{className:V.dashboardHead,"data-testid":`billing-dashboard-head`,children:[(0,m.jsxs)(`div`,{children:[v(`billing.dashboard.decor`,{position:`head`}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h2`,{className:V.dashboardTitle,children:t(`title`)}),v(`billing.dashboard.decor`,{position:`headTitle`})]}),(0,m.jsxs)(`p`,{className:V.dashboardSubtitle,children:[t(`lastUpdated`),` `,on,e.timezone===void 0?null:` · ${e.timezone.name} (${e.timezone.offset})`]})]}),(0,m.jsxs)(`div`,{className:V.dashboardRight,children:[(0,m.jsx)(`span`,{className:V.currencyToggle,role:`group`,"aria-label":t(`language`),children:[`en`,`zh`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.currencyButton,h===e&&V.currencyButtonActive),"aria-pressed":h===e,"data-testid":`billing-language-${e}`,onClick:()=>{g(e)},children:e===`en`?`EN`:`中`},e))}),(0,m.jsx)(`span`,{className:V.currencyToggle,role:`group`,"aria-label":t(`currency`),children:[`cny`,`usd`,`eur`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.currencyButton,u===e&&V.currencyButtonActive),"aria-pressed":u===e,"data-testid":`billing-currency-${e}`,title:t(e===`cny`?`currencyCny`:e===`usd`?`currencyUsd`:`currencyEur`),onClick:()=>{f(e)},children:e===`cny`?`¥ CNY`:e===`usd`?`$ USD`:`€ EUR`},e))}),a.checked&&(0,m.jsxs)(`span`,{className:y(V.healthBadge,a.available?V.healthBadgeOk:V.healthBadgeBad),children:[(0,m.jsx)(`span`,{className:y(V.healthDot,a.available?V.healthOk:V.healthBad),role:`img`,"aria-label":a.available?t(`healthDotLive`):t(`healthDotFailed`),title:a.available?t(`healthDotLive`):t(`healthDotFailed`)}),a.available?`${t(`healthModelsLive`).replace(`{n}`,String(a.models))}${a.failures>0?` · ${t(`healthVendorsDown`).replace(`{n}`,String(a.failures))}`:``}`:t(`healthVendorsUnavailable`).replace(`{n}`,String(a.failures))]}),(0,m.jsx)(`button`,{type:`button`,className:V.closeButton,"aria-label":t(`close`),"data-testid":`billing-close`,onClick:n,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M18 6 6 18`}),(0,m.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]}),(0,m.jsx)(`nav`,{className:V.tabNav,"data-testid":`billing-tab-nav`,role:`tablist`,"aria-label":t(`title`),children:_r.map(e=>{let n=Ci(e.id,vn);return(0,m.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":I===e.id,"aria-controls":`billing-tab-panel-${e.id}`,className:y(V.tabButton,I===e.id&&V.tabButtonActive),"data-testid":`billing-tab-${e.id}`,onClick:()=>{ue(e.id)},children:[(0,m.jsx)(`span`,{className:V.tabRailIcon,"aria-hidden":`true`,children:yr[e.id]}),(0,m.jsx)(`span`,{className:V.tabNavLabel,children:t(e.labelKey)}),n&&(0,m.jsx)(`span`,{className:y(V.tabBadge,n.kind===`warn`&&V.tabBadgeWarn,n.kind===`hot`&&V.tabBadgeHot,n.kind===`violet`&&V.tabBadgeViolet),"data-testid":`billing-tab-badge-${e.id}`,children:n.label})]},e.id)})}),(0,m.jsxs)(`div`,{className:V.dashboardBody,children:[I===`overview`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-overview`,children:[s?.kind===`drift`&&s.spent!==void 0&&pe!==ge()&&(0,m.jsxs)(`div`,{className:V.reconcileNotice,"data-testid":`billing-reconcile-notice`,role:`note`,children:[(0,m.jsx)(`span`,{className:V.reconcileIcon,"aria-hidden":`true`,children:(0,m.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,m.jsx)(`line`,{x1:`12`,y1:`10`,x2:`12`,y2:`16`}),(0,m.jsx)(`line`,{x1:`12`,y1:`7.5`,x2:`12.01`,y2:`7.5`})]})}),(0,m.jsx)(`span`,{className:V.reconcileText,children:t(`reconcileDrift`).replace(`{provider}`,s.provider??``).replace(`{spent}`,U(s.spent)).replace(`{today}`,U(s.todayOfficialCost??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.reconcileDismiss,"data-testid":`billing-reconcile-dismiss`,onClick:ye,children:t(`reconcileDismiss`)})]}),(0,m.jsxs)(`section`,{className:V.hero,"data-testid":`billing-hero`,children:[v(`billing.dashboard.decor`,{position:`hero`}),(0,m.jsxs)(`div`,{className:V.heroTop,children:[(0,m.jsxs)(`div`,{className:V.heroMain,children:[(0,m.jsx)(`span`,{className:V.heroLabel,children:t(`monthCost`)}),(0,m.jsxs)(`div`,{className:V.heroReadout,children:[(0,m.jsx)(`span`,{className:V.heroCurrency,"aria-hidden":`true`,children:bt}),(0,m.jsx)(`span`,{className:V.heroValue,children:U(qt).slice(1)})]}),(0,m.jsxs)(`span`,{className:V.heroMeta,children:[P.calls.toLocaleString(),` `,t(`calls`),en>0&&(0,m.jsxs)(`span`,{className:V.heroPred,children:[` `,t(`monthProjected`),` `,U(en)]})]})]}),tn!==null&&(0,m.jsxs)(`div`,{className:V.heroGauge,"data-testid":`billing-hero-gauge`,children:[(0,m.jsxs)(`div`,{className:V.heroGaugeDial,children:[(0,m.jsxs)(`svg`,{className:V.heroGaugeSvg,viewBox:`0 0 120 120`,"aria-hidden":`true`,children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`heroRingGrad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-cyan)`}),(0,m.jsx)(`stop`,{offset:`55%`,stopColor:`var(--ds-blue)`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-amber)`})]})}),(0,m.jsx)(`circle`,{className:V.heroGaugeTrack,cx:`60`,cy:`60`,r:`52`}),(0,m.jsx)(`circle`,{className:y(V.heroGaugeArc,tn.over&&V.heroGaugeArcOver),cx:`60`,cy:`60`,r:`52`,style:{strokeDasharray:`${tn.remainRatio*326.7} 326.7`},stroke:tn.over?void 0:`url(#heroRingGrad)`})]}),(0,m.jsxs)(`span`,{className:V.heroGaugeCenter,children:[(0,m.jsxs)(`span`,{className:y(V.heroGaugeRemain,tn.over&&V.heroGaugeRemainOver),children:[bt,Xt(tn.remainCny,u).toFixed(2)]}),(0,m.jsx)(`span`,{className:V.heroGaugeLabel,children:t(`budgetRemain`)})]})]}),(0,m.jsxs)(`span`,{className:V.heroGaugeSub,children:[U(qt),` / `,U(x)]})]})]}),(0,m.jsxs)(`div`,{className:V.heroSide,children:[(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`yearCost`)}),(0,m.jsx)(`span`,{className:V.heroSideValue,children:U(Yt)})]}),(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`todayCost`)}),(0,m.jsxs)(`span`,{className:V.heroSideValue,children:[U(Vt),(0,m.jsxs)(`span`,{className:y(V.delta,jn>=0?V.deltaUp:V.deltaDown),children:[jn>=0?`▲`:`▼`,` `,Math.abs(jn).toFixed(1),`%`]})]})]}),en>0&&(0,m.jsxs)(`div`,{className:V.heroSideItem,children:[(0,m.jsx)(`span`,{className:V.heroSideLabel,children:t(`monthProjected`)}),(0,m.jsx)(`span`,{className:V.heroSideValue,children:U(en)})]}),en<=0&&(0,m.jsx)(`span`,{className:V.heroSideSpacer,"aria-hidden":`true`})]})]}),(e.unpricedModels?.length??0)>0&&!R.has(`unpriced`)&&(0,m.jsxs)(`div`,{className:V.unpricedHint,"data-testid":`billing-unpriced-hint`,children:[(0,m.jsx)(`span`,{className:V.unpricedHintBody,children:t(`unpricedHint`).replace(`{count}`,String(e.unpricedModels?.length??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-unpriced-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`unpriced`)},children:`×`})]}),(e.total.searchCalls??0)>0&&!R.has(`search-estimate`)&&(0,m.jsxs)(`div`,{className:V.unpricedHint,"data-testid":`billing-search-estimate-hint`,children:[(0,m.jsx)(`span`,{className:V.unpricedHintBody,children:t(`searchEstimateHint`).replace(`{count}`,String(e.total.searchCalls??0)).replace(`{each}`,U(e.searchCallEstimateCny??0))}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-search-estimate-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`search-estimate`)},children:`×`})]}),(e.unreadableSessions??0)>0&&!R.has(`unreadable`)&&(0,m.jsxs)(`div`,{className:V.staleNotice,"data-testid":`billing-sessions-unreadable`,children:[(0,m.jsxs)(`div`,{className:V.staleNoticeBody,children:[t(`unreadableNotice`).replace(`{count}`,String(e.unreadableSessions)),(e.unreadableNoLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNoticeSub,"data-testid":`billing-sessions-no-ledger`,children:t(`unreadableNoLedgerNotice`).replace(`{count}`,String(e.unreadableNoLedgerSessions))}),(e.unreadableFormatSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNoticeSub,"data-testid":`billing-sessions-format-unsupported`,children:t(`unreadableFormatNotice`).replace(`{count}`,String(e.unreadableFormatSessions))})]}),(0,m.jsx)(`button`,{type:`button`,className:V.noticeDismiss,"data-testid":`billing-unreadable-dismiss`,"aria-label":t(`close`),onClick:()=>{Se(`unreadable`)},children:`×`})]}),(0,m.jsxs)(`div`,{className:V.kpiZone,children:[(0,m.jsxs)(`div`,{className:V.kpiZoneHead,children:[(0,m.jsx)(`span`,{className:V.kpiZoneLabel,children:t(`kpiRange`)}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-kpi-range`,role:`group`,"aria-label":t(`kpiRange`),children:[[`today`,`avgRangeToday`],[`7d`,`avgRange7d`],[`week`,`avgRangeWeek`],[`month`,`avgRangeMonth`],[`all`,`avgRangeAll`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,Ge===e&&V.heatmapRangeButtonActive),"data-testid":`billing-kpi-range-${e}`,"aria-pressed":Ge===e,onClick:()=>{Ke(e),re(e)},children:t(n)},e))})]}),(0,m.jsx)(`section`,{className:V.kpiGrid,"data-testid":`billing-kpi-grid`,children:(()=>{let e=Object.keys(F).sort().slice(-7),n=q(),r=e.indexOf(n),i=(e,t)=>e[t]??0,a=e.map(e=>F[e]?.cost??0),o=e.map(e=>F[e]?.calls??0),s=e.map(e=>{let t=F[e];return t===void 0?0:Er(t)}),c=e.map(e=>{let t=F[e];return t!==void 0&&t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0}),l=r>0&&i(a,r-1)>0?(i(a,r)-i(a,r-1))/i(a,r-1)*100:0,u=r>0&&i(o,r-1)>0?(i(o,r)-i(o,r-1))/i(o,r-1)*100:0,d=r>0&&i(s,r-1)>0?(i(s,r)-i(s,r-1))/i(s,r-1)*100:0,f=r>0&&i(c,r-1)>0?i(c,r)-i(c,r-1):0,h=(e,t)=>(0,m.jsx)(`svg`,{viewBox:`0 0 28 12`,preserveAspectRatio:`none`,style:{display:`block`,width:`100%`,height:`12px`},children:e.map((n,r)=>{let i=n/Math.max(...e,1)*10,a=r*4;return(0,m.jsx)(`rect`,{x:a,y:12-i,width:`2.5`,height:i,fill:t,opacity:r===e.length-1?1:.6},r)})}),g=e=>(0,m.jsxs)(`span`,{className:y(V.kpiDelta,e>0?V.kpiDeltaUp:e<0?V.kpiDeltaDown:V.kpiDeltaFlat),children:[e>0?`▲`:e<0?`▼`:``,` `,Math.abs(e).toFixed(1),`%`]});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-tile`,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCacheHit`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`cacheHitRate`)})}),g(f)]}),(0,m.jsx)(`span`,{className:y(V.kpiValue,V.kpiGreen),children:$t(Q.cacheHit+Q.cacheMiss>0?Q.cacheHit/(Q.cacheHit+Q.cacheMiss)*100:0)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(c,`var(--ds-cyan)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[J(Q.cacheHit),` / `,J(Q.cacheHit+Q.cacheMiss),(P.cacheWrite??0)>0?` · ${t(`tokenCacheWrite`)} ${J(P.cacheWrite??0)}`:``]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescTokens`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokens`)})}),g(d)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:J(Q.input+Q.output)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(s,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[t(`inputTokens`),` `,J(Q.input),` · `,t(`outputTokens`),` `,J(Q.output)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-avg`,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescAvgCost`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`avgCost`)})}),g(l)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:U(Q.calls>0?Q.cost/Q.calls:0)}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(a,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[t(`calls`),` `,Q.calls.toLocaleString()]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,children:[(0,m.jsxs)(`div`,{className:V.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCalls`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`calls`)})}),g(u)]}),(0,m.jsx)(`span`,{className:V.kpiValue,children:Q.calls.toLocaleString()}),(0,m.jsx)(`div`,{className:V.kpiSpark,children:h(o,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[gn.length,` `,t(`models`)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-think`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescReasoning`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenReasoningShare`)})})}),(0,m.jsx)(`span`,{className:y(V.kpiValue,V.kpiGreen),children:$t(Q.output>0?Q.reasoning/Q.output*100:0)}),(0,m.jsx)(`span`,{className:V.kpiDetail,children:J(Q.reasoning)})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-io`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescIo`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenIo`)})})}),(0,m.jsx)(`span`,{className:V.kpiValue,children:(Q.output>0?Q.input/Q.output:0).toFixed(2)}),(0,m.jsxs)(`span`,{className:V.kpiDetail,children:[J(Q.input),` / `,J(Q.output)]})]}),(0,m.jsxs)(`div`,{className:V.kpiTile,"data-testid":`billing-kpi-peak`,children:[(0,m.jsx)(`div`,{className:V.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescPeak`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.kpiLabel,children:t(`tokenPeak`)})})}),(0,m.jsx)(`span`,{className:V.kpiValue,children:Q.peakTokens>0?un(Q.peakTokens):`—`}),(0,m.jsx)(`span`,{className:V.kpiDetail,children:Q.peakDay??`—`})]})]})})()})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-heatmap`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`heatmap`)}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-heatmap-metric`,role:`group`,"aria-label":t(`heatmap`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,Ee===e&&V.heatmapRangeButtonActive),"data-testid":`billing-heatmap-metric-${e}`,"aria-pressed":Ee===e,onClick:()=>{De(e)},children:t(e===`cost`?`metricCost`:`metricTokens`)},e))}),(0,m.jsx)(`div`,{className:V.heatmapRangeSwitch,"data-testid":`billing-heatmap-range`,role:`group`,"aria-label":t(`heatmap`),children:[`month`,`half`,`year`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.heatmapRangeButton,we===e&&V.heatmapRangeButtonActive),"data-testid":`billing-heatmap-range-${e}`,"aria-pressed":we===e,onClick:()=>{Te(e)},children:t(e===`month`?`heatmapMonth`:e===`half`?`heatmapHalf`:`heatmapYear`)},e))}),(0,m.jsxs)(`span`,{className:V.panelHint,"data-testid":`billing-heatmap-summary`,children:[t(`heatmapTotal`),` `,Ee===`tokens`?J(dn):U(dn),` · `,t(`activeDays`),` `,fn,` · `,t(`streakDays`),` `,pn]})]}),(0,m.jsx)(zn,{days:Y,currency:u,t,range:we,unit:Ee})]})]}),I===`settings`&&(0,m.jsx)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-settings`,children:(0,m.jsxs)(`div`,{className:V.settingsLayout,children:[(0,m.jsx)(`aside`,{className:V.settingsNav,"data-testid":`billing-settings-nav`,role:`navigation`,"aria-label":`settings`,children:[{id:`display-pref`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`path`,{d:`M5 3v10M11 3v10`}),(0,m.jsx)(`circle`,{cx:`5`,cy:`6.5`,r:`1.8`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`9.5`,r:`1.8`})]}),label:t(`settingsNavDisplayPref`)},{id:`budget`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M5 3l3 4 3-4M8 7v6M5.5 9.5h5M5.5 12h5`})}),label:t(`settingsNavBudget`)},{id:`alert`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`path`,{d:`M8 2a4 4 0 0 1 4 4v3l1.5 2.5h-11L4 9V6a4 4 0 0 1 4-4z`}),(0,m.jsx)(`path`,{d:`M6.5 13.5a1.5 1.5 0 0 0 3 0`})]}),label:t(`settingsNavAlert`)},{id:`display`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 2a6 6 0 0 1 0 12z`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavDisplay`)},{id:`advanced`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M8 2v12M2.8 5l10.4 6M13.2 5L2.8 11`})}),label:t(`settingsNavAdvanced`),advanced:!0},{id:`about`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 7.5V11`}),(0,m.jsx)(`circle`,{cx:`8`,cy:`5.2`,r:`0.9`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavAbout`)}].map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(V.settingsNavItem,Ne===e.id&&V.settingsNavItemActive,e.advanced&&V.settingsNavItemAdvanced),"data-testid":`billing-settings-nav-${e.id}`,onClick:()=>{Ve(e.id)},children:[(0,m.jsx)(`span`,{className:V.settingsNavIcon,"aria-hidden":`true`,children:e.icon}),e.label]},e.id))}),(0,m.jsxs)(`div`,{className:V.settingsPane,children:[(0,m.jsx)(`input`,{className:y(V.ubSearch,V.settingsSearch),type:`search`,value:Re,placeholder:t(`settingsSearchPlaceholder`),"aria-label":t(`settingsSearchPlaceholder`),"data-testid":`billing-settings-search`,onChange:e=>{ze(e.target.value)}}),Re.trim()!==``&&Fi(Re)&&(0,m.jsx)(`p`,{className:V.setCardDesc,"data-testid":`billing-settings-search-empty`,children:t(`settingsSearchEmpty`).replace(`{query}`,Re.trim())}),(0,m.jsxs)(`div`,{hidden:Be(Pi.display),className:V.setCard,id:`settings-display-pref`,"data-testid":`billing-density-motion-card`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsx)(`h3`,{className:V.setCardTitle,children:t(`settingsSectionDisplay`)})})}),(0,m.jsxs)(`div`,{className:V.densityRow,children:[(0,m.jsxs)(`div`,{className:V.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`densityLabel`)}),(0,m.jsx)(`span`,{children:t(`densityHint`)})]}),(0,m.jsx)(`div`,{className:V.densityButtons,"data-testid":`billing-density-buttons`,children:[`compact`,`default`,`comfortable`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.densityButton,z===e&&V.densityButtonActive,e===`comfortable`&&V.densityButtonComfortable),"data-testid":`billing-density-${e}`,onClick:()=>{He(e)},children:t(e===`compact`?`densityCompact`:e==="default"?`densityDefault`:`densityComfortable`)},e))})]}),(0,m.jsxs)(`div`,{className:V.densityRow,children:[(0,m.jsxs)(`div`,{className:V.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`motionLabel`)}),(0,m.jsx)(`span`,{children:t(`motionHint`)})]}),(0,m.jsx)(`div`,{className:V.densityButtons,"data-testid":`billing-motion-buttons`,children:[`off`,`subtle`,`rich`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.densityButton,ke===e&&V.densityButtonActive),"data-testid":`billing-motion-${e}`,onClick:()=>{Ue(e)},children:t(e===`off`?`motionOff`:e===`subtle`?`motionSubtle`:`motionRich`)},e))})]})]}),(0,m.jsxs)(`section`,{hidden:Be(Pi.budget),className:V.setCard,"data-testid":`billing-budget`,id:`settings-budget`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`budget`),(0,m.jsx)(Ei,{label:t(`budgetHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":b,"aria-label":t(`budget`),"data-testid":`billing-budget-toggle`,className:y(V.switch,b&&V.switchOn),onClick:S,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),b&&(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`budgetAmount`)}),(0,m.jsxs)(`span`,{className:V.inp,"data-testid":`billing-budget-input-wrap`,children:[(0,m.jsx)(`span`,{className:V.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:V.budgetInput,"data-testid":`billing-budget-input`,type:`number`,min:0,step:1,value:x===0?``:x,placeholder:e.budget===void 0?`0`:String(e.budget),"aria-label":`${t(`budget`)}(${u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`})`,title:`${t(`budget`)}(${u===`usd`?`USD`:u===`eur`?`EUR`:`CNY`})`,onChange:e=>{C(e.target.valueAsNumber)}})]})]}),x>0&&(()=>{let e=qt/x*100;return(0,m.jsx)(`div`,{className:V.ctlRowStretch,children:(0,m.jsx)(`div`,{className:V.prog,role:`progressbar`,"aria-valuenow":Math.min(e,100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t(`budget`),"data-testid":`billing-budget-track`,children:(0,m.jsx)(`div`,{className:y(V.progFill,e>=100&&V.budgetFillOver,e>=80&&e<100&&V.budgetFillWarn),style:{width:`${Math.min(e,100)}%`}})})})})(),x>0&&(0,m.jsx)(`p`,{className:V.setCardDesc,"data-testid":`billing-budget-value`,children:t(`budgetSummary`).replace(`{used}`,U(qt)).replace(`{total}`,U(x))})]}),(0,m.jsxs)(`div`,{className:V.ctlCol,"data-testid":`billing-model-budgets`,children:[(0,m.jsxs)(`span`,{className:V.modelBudgetTitle,children:[t(`modelBudgetTitle`),(0,m.jsx)(Ei,{label:t(`modelBudgetHint`),t})]}),it.length===0&&(0,m.jsx)(`p`,{className:V.modelBudgetHint,children:t(`emptyHint`)}),(0,m.jsx)(`div`,{className:V.modelBudgetList,children:it.map(e=>(0,m.jsxs)(`div`,{className:V.modelBudgetRow,children:[(0,m.jsx)(`span`,{className:V.modelBudgetName,title:e.name??e.key,children:e.name??e.key}),(0,m.jsx)(`span`,{className:V.modelBudgetCost,"data-testid":`billing-model-budget-cost-${e.key}`,children:U(e.cost)}),(0,m.jsxs)(`span`,{className:V.inp,children:[(0,m.jsx)(`span`,{className:V.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:V.budgetInput,type:`number`,min:0,step:1,value:w[e.key]??``,placeholder:t(`modelBudgetPlaceholder`),"aria-label":`${t(`modelBudgetTitle`)} · ${e.name??e.key}`,"data-testid":`billing-model-budget-${e.key}`,onChange:t=>{ee(e.key,t.target.valueAsNumber)}})]})]},e.key))})]})]}),(0,m.jsxs)(`section`,{hidden:Be(Pi.alert),className:V.setCard,"data-testid":`billing-peak-alert-settings`,id:`settings-alert`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`peakAlert`),(0,m.jsx)(Ei,{label:t(`peakAlertHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":E.enabled,"aria-label":t(`peakAlert`),"data-testid":`billing-peak-alert-toggle`,className:y(V.switch,E.enabled&&V.switchOn),onClick:()=>{D({...E,enabled:!E.enabled})},children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),E.enabled&&(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`label`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertLeadMin`)}),(0,m.jsx)(`span`,{className:V.inp,children:(0,m.jsx)(`input`,{type:`number`,min:1,max:30,step:1,value:E.leadMin,className:V.budgetInput,"aria-label":t(`peakAlertLeadMin`),onChange:e=>{let t=Number(e.target.valueAsNumber);D({...E,leadMin:Number.isFinite(t)?Math.min(30,Math.max(1,Math.round(t))):E.leadMin})}})})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertPos`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertPos`),children:[`bottom-right`,`center`].map(e=>(0,m.jsxs)(`label`,{className:V.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-pos`,checked:E.position===e,onChange:()=>D({...E,position:e})}),(0,m.jsx)(`span`,{className:V.rdoDot,"aria-hidden":`true`}),t(e===`bottom-right`?`peakAlertPosCorner`:`peakAlertPosCenter`)]},e))})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertMode`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertMode`),children:[`both`,`peak`,`offPeak`].map(e=>(0,m.jsxs)(`label`,{className:V.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-mode`,checked:E.mode===e,onChange:()=>D({...E,mode:e})}),(0,m.jsx)(`span`,{className:V.rdoDot,"aria-hidden":`true`}),t(e===`both`?`peakAlertModeBoth`:e===`peak`?`peakAlertModePeak`:`peakAlertModeOff`)]},e))})]}),(0,m.jsxs)(`label`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`peakAlertWebNotify`)}),(0,m.jsx)(`input`,{type:`checkbox`,checked:E.webNotify,"aria-label":t(`peakAlertWebNotify`),onChange:e=>{D({...E,webNotify:e.target.checked})}})]}),(0,m.jsx)(`div`,{className:V.ctlRow,children:(0,m.jsx)(`button`,{type:`button`,className:V.btn,onClick:O,children:t(`peakAlertPreview`)})})]})]}),(0,m.jsx)(`section`,{hidden:Be(Pi.toggles),className:V.setCard,"data-testid":`billing-toggle-setting`,id:`settings-display`,children:(0,m.jsxs)(`div`,{className:V.setGrid3,children:[(0,m.jsx)(`div`,{className:V.setCell,"data-testid":`billing-usage-stats-tool-setting`,children:(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`usageStatsTool`),(0,m.jsx)(Ei,{label:t(`usageStatsToolHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ft,"aria-label":t(`usageStatsTool`),"data-testid":`billing-usage-stats-tool-toggle`,className:y(V.switch,ft&&V.switchOn),onClick:mt,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})}),(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-livecost-setting`,children:[(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`liveCostBar`),(0,m.jsx)(Ei,{label:t(`liveCostBarHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ae.show,"aria-label":t(`liveCostBar`),"data-testid":`billing-livecost-toggle`,className:y(V.switch,ae.show&&V.switchOn),onClick:()=>oe({...ae,show:!ae.show}),children:(0,m.jsx)(`span`,{className:V.switchKnob})})]}),ae.show&&(0,m.jsxs)(`div`,{className:V.rdoRow,"data-testid":`billing-livecost-position`,children:[(0,m.jsx)(`span`,{className:V.rdoLabel,children:t(`liveCostBarPosition`)}),(0,m.jsx)(Li,{liveCostPrefs:ae,onLiveCostPrefs:oe,t})]})]}),(0,m.jsx)(`div`,{className:V.setCell,"data-testid":`billing-site-list-setting`,children:(0,m.jsxs)(`div`,{className:V.setCardHead,children:[(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`siteListDisplay`),(0,m.jsx)(Ei,{label:t(`siteListDisplayHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":M.hideUnidentified,"aria-label":t(`siteListDisplay`),"data-testid":`billing-site-hide-unidentified`,className:y(V.switch,M.hideUnidentified&&V.switchOn),onClick:()=>ie({hideUnidentified:!M.hideUnidentified}),children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})})]})}),(0,m.jsx)(`section`,{hidden:Be(Pi.displayExtra),className:V.setCard,"data-testid":`billing-display-setting`,id:`settings-display-extra`,children:(0,m.jsxs)(`div`,{className:V.setGrid2,children:[(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-float-setting`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`floatWindow`),(0,m.jsx)(Ei,{label:t(`floatWindowHint`),t})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`floatMode`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-float-mode`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,k.mode===`combined`&&V.floatModeBtnOn),"data-testid":`billing-float-mode-combined`,onClick:()=>te({mode:`combined`,targets:k.targets}),children:t(`floatModeCombined`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,k.mode===`subscription`&&V.floatModeBtnOn),"data-testid":`billing-float-mode-subscription`,onClick:()=>te({mode:`subscription`,targets:k.targets}),children:t(`floatModeSubscription`)})]})]}),k.mode===`subscription`&&(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`floatTargets`)}),(0,m.jsxs)(`span`,{className:V.ctlGroup,"data-testid":`billing-float-targets`,children:[H.map(e=>{let t=k.targets.includes(e.id);return(0,m.jsxs)(`label`,{className:V.floatTarget,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:t,"data-testid":`billing-float-target-${e.id}`,onChange:()=>te({mode:`subscription`,targets:t?k.targets.filter(t=>t!==e.id):[...k.targets,e.id]})}),(0,m.jsx)(`span`,{className:V.floatTargetLabel,children:e.label})]},e.id)}),H.length===0&&(0,m.jsx)(`span`,{className:V.setCardDesc,children:t(`floatNoTargetsHint`)})]})]})]})]}),(0,m.jsxs)(`div`,{className:V.setCell,"data-testid":`billing-card-setting`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsxs)(`h3`,{className:V.setCardTitle,children:[t(`cardDisplay`),(0,m.jsx)(Ei,{label:t(`cardDisplayHint`),t})]})})}),(0,m.jsxs)(`div`,{className:V.ctlCol,children:[(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardMetric`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-metric`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.metric===`money`&&V.floatModeBtnOn),"data-testid":`billing-card-money`,onClick:()=>j({...A,metric:`money`}),children:t(`cardMetricMoney`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.metric===`tokens`&&V.floatModeBtnOn),"data-testid":`billing-card-tokens`,onClick:()=>j({...A,metric:`tokens`}),children:t(`cardMetricTokens`)})]})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardSpan`)}),(0,m.jsx)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-span`,children:[[`day`,`cardSpanDay`],[`week`,`cardSpanWeek`],[`month`,`cardSpanMonth`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.span===e&&V.floatModeBtnOn),"data-testid":`billing-card-span-${e}`,"aria-pressed":A.span===e,onClick:()=>j({...A,span:e}),children:t(n)},e))})]}),(0,m.jsxs)(`div`,{className:V.ctlRow,children:[(0,m.jsx)(`span`,{className:V.ctlLabel,children:t(`cardDeltaBadge`)}),(0,m.jsxs)(`div`,{className:V.ctlGroup,"data-testid":`billing-card-delta`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,A.showDelta&&V.floatModeBtnOn),"data-testid":`billing-card-delta-show`,"aria-pressed":A.showDelta,onClick:()=>j({...A,showDelta:!0}),children:t(`cardDeltaShow`)}),(0,m.jsx)(`button`,{type:`button`,className:y(V.floatModeBtn,!A.showDelta&&V.floatModeBtnOn),"data-testid":`billing-card-delta-hide`,"aria-pressed":!A.showDelta,onClick:()=>j({...A,showDelta:!1}),children:t(`cardDeltaHide`)})]})]})]})]})]})}),(0,m.jsx)(`div`,{hidden:Be(Pi.advanced),id:`settings-advanced`,children:(0,m.jsx)(ji,{userPrices:r,onUserPrices:i,t})}),(0,m.jsx)(`div`,{hidden:Be(Pi.about),id:`settings-about`,children:(0,m.jsx)(kn,{t,version:e.pluginVersion})}),(0,m.jsxs)(`section`,{hidden:Be(Pi.about),className:V.setCard,"data-testid":`billing-more-works`,children:[(0,m.jsx)(`div`,{className:V.setCardHead,children:(0,m.jsx)(`div`,{className:V.setCardMeta,children:(0,m.jsx)(`h3`,{className:V.setCardTitle,children:t(`moreWorksTitle`)})})}),(0,m.jsxs)(`div`,{className:V.moreWorkList,children:[(0,m.jsxs)(`a`,{className:V.moreWorkRow,href:`https://github.com/kenz1117/dsh-engram`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-engram`,children:[(0,m.jsx)(`span`,{className:V.moreWorkName,children:t(`adEngramName`)}),(0,m.jsx)(`span`,{className:V.moreWorkDesc,children:t(`adEngramDesc`)})]}),(0,m.jsxs)(`a`,{className:V.moreWorkRow,href:`https://github.com/kenz1117/dsh-ui-rainbowspeak`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-rainbowspeak`,children:[(0,m.jsx)(`span`,{className:V.moreWorkName,children:t(`adRainbowName`)}),(0,m.jsx)(`span`,{className:V.moreWorkDesc,children:t(`adRainbowDesc`)})]})]})]})]})]})}),I===`trends`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-trends`,children:[(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-trend`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`trend`)}),v(`billing.dashboard.decor`,{position:`trend`}),(0,m.jsxs)(`span`,{className:V.ubCardControlGroup,children:[(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":t(`trend`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,de===e&&V.rangeButtonActive),"aria-pressed":de===e,"data-testid":`billing-trend-${e}d`,onClick:()=>{fe(e)},children:t(e===7?`trend7d`:`trend30d`)},e))}),(0,m.jsx)(`span`,{className:V.rangeToggle,role:`group`,"aria-label":t(`trendMetric`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(V.rangeButton,N===e&&V.rangeButtonActive),"aria-pressed":N===e,"data-testid":`billing-trend-metric-${e}`,onClick:()=>{ce(e)},children:t(e===`cost`?`trendMetricCost`:`trendMetricTokens`)},e))})]}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:on})]}),(0,m.jsx)(xn,{data:mn,models:On,currency:u,metric:N,t})]}),_.length>0&&(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-rounds`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`rounds`)}),Nt.length>0&&(0,m.jsxs)(`span`,{className:V.ubTagError,"data-testid":`billing-rounds-flag-count`,children:[Nt.length,` `,t(`anomaly`)]})]}),(0,m.jsx)(`p`,{className:V.ubCardSub,children:t(`roundsHint`).replace(`{count}`,String(_.length))}),(0,m.jsx)(Nn,{rounds:_,flags:Nt,currency:u,t})]}),e.byTier!==void 0&&(()=>{let e=Pt.peak+Pt.offPeak;if(e<=0)return null;let n=Pt.peak/e*100;return(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-share`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`peakShare`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:t(`peakSharePerCall`)})]}),(0,m.jsxs)(`div`,{className:V.shareTrack,"data-testid":`billing-share-track`,children:[(0,m.jsx)(`div`,{className:y(V.shareSeg,V.shareSegPeak),style:{width:`${n}%`}}),(0,m.jsx)(`div`,{className:y(V.shareSeg,V.shareSegOff),style:{width:`${100-n}%`}})]}),(0,m.jsxs)(`div`,{className:V.shareLegend,children:[(0,m.jsxs)(`span`,{className:V.shareItem,children:[(0,m.jsx)(`span`,{className:V.shareDot,style:{background:`var(--ds-blue)`}}),t(`peak`),(0,m.jsxs)(`span`,{className:V.shareValue,"data-testid":`billing-share-peak`,children:[U(Pt.peak),` · `,n.toFixed(1),`%`]})]}),(0,m.jsxs)(`span`,{className:V.shareItem,children:[(0,m.jsx)(`span`,{className:V.shareDot,style:{background:`color-mix(in srgb, var(--ds-blue) 30%, var(--dsb-3))`}}),t(`offPeak`),(0,m.jsxs)(`span`,{className:V.shareValue,"data-testid":`billing-share-offpeak`,children:[U(Pt.offPeak),` · `,(100-n).toFixed(1),`%`]})]})]}),Ft>0&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-share-savings`,children:t(`offPeakSavings`).replace(`{amount}`,U(Ft))})]})})()]}),I===`providers`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-providers`,children:[_n.length>0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-relay-quota`,children:[(0,m.jsx)(`div`,{className:V.panelHead,children:(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`panelRelayQuota`)})}),(0,m.jsx)(`div`,{className:V.providerGroupList,"data-testid":`billing-relay-quotas`,children:_n.map(e=>(0,m.jsxs)(`div`,{className:V.siteRow,"data-testid":`billing-relay-quota`,children:[(0,m.jsxs)(`span`,{className:V.siteRowName,children:[(0,m.jsx)(`span`,{className:y(V.siteKindTag,li[e.kind]),children:ci(e.kind,t)}),(0,m.jsx)(`span`,{className:V.siteRowTitle,children:e.origin})]}),(0,m.jsxs)(`span`,{className:V.siteRowMeta,children:[e.balance!==void 0&&(0,m.jsxs)(`span`,{className:V.siteRowCost,children:[t(`relayBalance`),` `,e.balance.toFixed(2)]}),(e.windows?.length??0)>0?e.windows?.map(e=>{let n=e.remainingPercent<20;return(0,m.jsxs)(`span`,{className:y(V.siteRowCalls,n&&V.siteRowCallsLow),children:[t(`relayWindowUsed`),` `,e.usedPercent,`%`]},e.kind)}):(0,m.jsx)(`span`,{className:V.siteRowCalls,children:t(`relayNoQuota`)})]})]},e.route))})]}),(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-providers`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`providerBilling`)}),v(`billing.dashboard.decor`,{position:`models`}),(0,m.jsx)(`span`,{className:V.panelHint,children:e.updatedAt===void 0?``:`${t(`lastUpdated`)} ${fi(e.updatedAt)}`})]}),se&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-subscriptions-stale`,children:t(`subscriptionsStale`)}),(0,m.jsxs)(`div`,{className:V.providerCtlRow,"data-testid":`billing-provider-controls`,children:[(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,disabled:yn.length===0,onClick:Z,children:t(bn?`collapseAll`:`expandAll`)}),(0,m.jsxs)(`span`,{className:V.providerTodayToggle,children:[(0,m.jsx)(`span`,{children:t(`todayOnly`)}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ct,"data-testid":`billing-provider-today-toggle`,className:y(V.switch,ct&&V.switchOn),onClick:dt,children:(0,m.jsx)(`span`,{className:V.switchKnob})})]})]}),X.length===0?(0,m.jsxs)(`div`,{className:V.emptyState,"data-testid":`billing-provider-empty`,children:[(0,m.jsxs)(`span`,{className:V.emptyIll,"aria-hidden":`true`,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 96 64`,fill:`none`,children:[(0,m.jsx)(`line`,{x1:`6`,y1:`58`,x2:`90`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`line`,{x1:`6`,y1:`6`,x2:`6`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`path`,{d:`M14 50 L28 40 L42 44 L56 26 L70 30 L82 14`,stroke:`var(--ds-border-strong)`,strokeWidth:`1.5`,strokeLinecap:`round`,fill:`none`,strokeDasharray:`3 3`})]}),(0,m.jsx)(`span`,{className:V.emptyIllDot})]}),(0,m.jsx)(`span`,{className:V.emptyTitle,children:t(ct?`todayNoConsumption`:`noData`)}),(0,m.jsx)(`span`,{className:V.emptyDesc,children:t(`emptyHint`)})]}):(0,m.jsx)(`div`,{className:V.providerGroupList,"data-testid":`billing-provider-groups`,children:X.map(e=>{let n=e.models.length>0||e.subscriptions.length>0,r=n&&at.has(e.id);return(0,m.jsxs)(`div`,{className:V.providerGroup,"data-testid":`billing-provider-group`,children:[(0,m.jsxs)(`div`,{className:y(V.providerGroupHead,n&&V.providerGroupCollapsible),"data-testid":`billing-provider-group-head`,"aria-expanded":n?r:void 0,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:n?()=>{st(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),st(e.id))}:void 0,children:[(0,m.jsxs)(`span`,{className:V.providerGroupTitle,children:[(0,m.jsx)(`span`,{className:y(V.healthDot,e.dot),role:`img`,"aria-label":Di(e.dot,t),title:Di(e.dot,t)}),(()=>{let n=wt(e.name),r=e.channelKind===`direct`?ar(n):void 0,i=e.channelKind===`direct`?t(`directTag`):e.channelKind===`site`?t(`relayTag`):e.channelKind===`unknown`?t(`unknownTag`):void 0;return(0,m.jsxs)(m.Fragment,{children:[i!==void 0&&(0,m.jsx)(`span`,{className:y(V.kindBadge,e.channelKind===`site`&&V.kindBadgeRelay,e.channelKind===`unknown`&&V.kindBadgeUnknown),"data-testid":`billing-kind-badge`,children:i}),e.channelKind!==`unknown`&&(0,m.jsx)(`span`,{className:V.providerGroupName,children:r??n})]})})(),e.subscriptions.length>0&&(0,m.jsxs)(`span`,{className:V.providerGroupBadge,"data-testid":`billing-provider-sub-count`,children:[e.subscriptions.length,` `,t(`planCountUnit`)]})]}),(0,m.jsxs)(`span`,{className:V.providerGroupMeta,children:[(0,m.jsxs)(`span`,{className:V.providerGroupCost,"data-testid":`billing-provider-cost`,children:[(0,m.jsx)(`span`,{className:V.providerGroupCostLabel,children:t(`cost`)}),e.channelKind===`unknown`?(0,m.jsx)(`span`,{className:V.na,children:`—`}):(0,m.jsx)(`span`,{className:V.providerGroupCostValue,children:U(ui(e))})]}),!Rt(e)&&e.balance!==void 0?(0,m.jsxs)(`span`,{className:V.providerGroupBalance,"data-testid":`billing-provider-balance`,children:[(0,m.jsx)(`span`,{className:V.providerGroupBalanceLabel,children:t(`balance`)}),zt(e.balance)]}):(0,m.jsx)(`span`,{className:V.providerGroupBalance,"aria-hidden":`true`}),Xr(e.name)===void 0?(0,m.jsx)(`span`,{className:V.providerGroupRecharge,"aria-hidden":`true`}):(0,m.jsx)(`a`,{className:V.providerGroupRecharge,"data-testid":`billing-group-recharge`,href:Xr(e.name),target:`_blank`,rel:`noreferrer`,title:t(`rechargeHint`),"aria-label":`${wt(e.name)} ${t(`recharge`)}`,onClick:e=>{e.stopPropagation()},children:t(`recharge`)})]})]}),e.models.length>0&&(0,m.jsx)(`div`,{className:V.providerStatRow,"data-testid":`billing-provider-stat-row`,children:(()=>{let n=e.models.reduce((e,t)=>({calls:e.calls+t.calls,input:e.input+t.input,output:e.output+t.output}),{calls:0,input:0,output:0}),r=n.input>0?e.models.reduce((e,t)=>e+t.cacheHitRate,0)/e.models.length:0;return[{lbl:t(`calls`),val:n.calls.toLocaleString(),sub:``},{lbl:t(`inputTokens`),val:J(n.input),sub:r>0?`${t(`cacheHitRate`)} ${r.toFixed(0)}%`:``},{lbl:t(`outputTokens`),val:J(n.output),sub:``},{lbl:t(`cost`),val:U(ui(e)),sub:e.models.length===1?``:`${e.models.length} ${t(`models`)}`}].map((e,t)=>(0,m.jsxs)(`div`,{className:V.providerStatCell,children:[(0,m.jsx)(`div`,{className:V.providerStatLbl,children:e.lbl}),(0,m.jsx)(`div`,{className:V.providerStatVal,children:e.val}),e.sub!==``&&(0,m.jsx)(`div`,{className:V.providerStatSub,children:e.sub})]},t))})()}),r&&(0,m.jsxs)(m.Fragment,{children:[e.channelKind===`unknown`&&(0,m.jsx)(`p`,{className:V.unknownHint,"data-testid":`billing-unknown-hint`,children:t(`unknownChannelHint`)}),e.models.length>0&&(0,m.jsx)(`div`,{className:V.tableScroll,"data-testid":`billing-table-scroll`,children:(0,m.jsxs)(`table`,{className:V.modelTable,children:[Sn,(0,m.jsx)(`tbody`,{children:e.models.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:Cn(e)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.input)}),(0,m.jsx)(`td`,{className:V.numCol,children:J(e.output)}),(0,m.jsx)(`td`,{className:V.numCol,children:$t(e.cacheHitRate)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.plan?(0,m.jsxs)(`span`,{className:V.planTag,children:[e.estimated>0?(0,m.jsxs)(`span`,{children:[`≈`,U(e.estimated)]}):null,(0,m.jsx)(`span`,{className:V.planTagBadge,"data-testid":`billing-plan-badge`,children:t(`subscriptionTag`)})]}):e.actual===void 0?e.estimated>0?(0,m.jsxs)(`span`,{title:t(`cellEstimateHint`),children:[`≈`,U(e.estimated)]}):(0,m.jsx)(`span`,{className:V.na,children:`—`}):(()=>{let t=e.officialCost,n=e.actual-t;return t>0&&n>0?(0,m.jsxs)(`span`,{className:V.bucketCost,children:[(0,m.jsx)(`span`,{className:V.bucketOfficial,children:U(t)}),(0,m.jsx)(`span`,{className:V.bucketSep,children:`/`}),(0,m.jsx)(`span`,{className:V.bucketThird,children:U(n)})]}):U(e.actual)})()})]},e.key))})]})}),e.subscriptions.length>0&&(0,m.jsx)(`div`,{className:V.subscriptionGrid,"data-testid":`billing-subscriptions-grid`,children:e.subscriptions.map(e=>{let n=oi(e.status,t);return(0,m.jsxs)(`div`,{className:y(V.subscriptionCard,V.subscriptionCardUpgraded),"data-testid":`billing-subscription-card`,children:[(0,m.jsxs)(`div`,{className:V.subscriptionHead,children:[(0,m.jsx)(`span`,{className:V.subscriptionName,children:wt(e.displayName)}),e.planType===`code`&&(()=>{let n=We(e.provider),r=n===void 0?void 0:t(`subscriptionFeePerMonth`).replace(`{amount}`,n.currency===`USD`?`$${n.amount}`:`¥${n.amount}`);return(0,m.jsxs)(`span`,{className:V.subscriptionPlan,"data-kind":`code`,children:[r??(e.subscriptionAmount!==void 0&&e.subscriptionAmount>0?t(`subscriptionFeePerMonth`).replace(`{amount}`,U(e.subscriptionAmount)):t(`planTypeCode`)),n?.label!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionTier,"data-testid":`billing-tier-${e.provider}`,children:n.label}),n!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionAuto,"data-testid":`billing-auto-${e.provider}`,children:t(`subscriptionAutoDetect`)})]})})(),e.planType===`token`&&(0,m.jsx)(`span`,{className:V.subscriptionPlan,"data-kind":`token`,children:t(`planTypeToken`)}),e.plan!==void 0&&(0,m.jsx)(`span`,{className:V.subscriptionPlan,children:e.plan})]}),n!==``&&(0,m.jsx)(`div`,{className:V.subscriptionStatus,children:n}),e.windows.length===0&&n===``&&(0,m.jsx)(`div`,{className:V.subscriptionStatus,children:t(`subscriptionNoApi`)}),e.windows.map(e=>(0,m.jsx)(Ti,{window:e,t},e.kind))]},e.provider)})})]})]},e.id)})})]}),(0,m.jsxs)(`div`,{className:V.exportBar,"data-testid":`billing-export-bar`,role:`group`,"aria-label":t(`export`),children:[(0,m.jsx)(`span`,{className:V.exportLabel,children:t(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-day`,onClick:()=>{ln(cn(`usage-daily`,`csv`,Object.keys(F)),rn(F),`text/csv`)},children:t(`exportCsvDay`)}),e.bySession!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-sessions`,onClick:()=>{ln(cn(`usage-sessions`,`csv`,Object.keys(F)),sn(e.bySession??[]),`text/csv`)},children:t(`exportCsvSession`)}),e.bySite!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-sites`,onClick:()=>{ln(cn(`usage-sites`,`csv`,Object.keys(F)),an(e.bySite??{}),`text/csv`)},children:t(`exportCsvSite`)}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-export-json`,onClick:()=>{ln(cn(`usage-stats`,`json`,Object.keys(F)),JSON.stringify(e,null,2),`application/json`)},children:t(`exportJson`)})]}),e.bySession!==void 0&&(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-sessions`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`sessions`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:e.bySession.length>20?t(`sessionOverflow`).replace(`{limit}`,`20`).replace(`{total}`,String(e.bySession.length)):`${e.bySession.length}`}),e.bySession.length>0&&(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-sessions-view-all`,onClick:()=>{Qe(!0)},children:t(`sessionsViewAll`).replace(`{count}`,String(e.bySession.length))})]}),(e.staleLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:V.staleNotice,"data-testid":`billing-sessions-stale`,children:t(`staleLedgerNotice`).replace(`{count}`,String(e.staleLedgerSessions))}),(0,m.jsx)(`div`,{className:V.ubTablewrap,"data-testid":`billing-sessions-table`,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[nt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:V.emptyRow,children:t(`noData`)})}),nt.slice(0,20).map(e=>{let n=e.children!==void 0||e.subs!==void 0,r=n&&Ye.has(e.id),i=di(e),a=e=>(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:U(e.cost)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.lastActive>0?`${q(e.lastActive)} ${fi(e.lastActive)}`:`—`})]});return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:n?V.sessionGroupRow:void 0,"aria-expanded":n?r:void 0,tabIndex:n?0:void 0,onClick:n?()=>{tt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),tt(e.id))}:void 0,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),"data-testid":`billing-session-stale`,children:t(`sessionStaleBadge`)}),(i.calls>0||i.cost>0)&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),"data-testid":`billing-session-sub`,children:i.cost>0?t(`sessionSubCost`).replace(`{cost}`,U(i.cost)):t(`sessionSubCalls`).replace(`{calls}`,i.calls.toLocaleString())})]}),a(e)]}),r&&e.children?.map(e=>(0,m.jsxs)(`tr`,{className:V.sessionChildRow,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:V.modelProvider,children:e.id.slice(0,8)})}),a(e)]},e.id)),r&&e.subs?.map(e=>(0,m.jsxs)(`tr`,{className:V.sessionChildRow,"data-testid":`billing-session-sub-row`,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),children:t(`sessionSubRow`)}),(0,m.jsx)(`span`,{className:V.modelProvider,children:e.title??e.id.slice(0,8)})]}),a(e)]},e.id))]},e.id)})]})]})}),Ze&&(0,m.jsxs)(`div`,{className:V.sessionViewer,"data-testid":`billing-session-viewer`,children:[(0,m.jsxs)(`div`,{className:V.sessionViewerHead,children:[(0,m.jsx)(`h3`,{className:V.sessionViewerTitle,children:t(`sessions`)}),(0,m.jsx)(`input`,{className:V.ubSearch,type:`search`,value:$e,placeholder:t(`sessionViewerSearch`),"aria-label":t(`sessionViewerSearch`),"data-testid":`billing-session-viewer-search`,onChange:e=>{et(e.target.value)}}),(0,m.jsx)(`button`,{type:`button`,className:V.exportButton,"data-testid":`billing-session-viewer-close`,onClick:()=>{Qe(!1),et(``)},children:t(`close`)})]}),(0,m.jsx)(`div`,{className:V.sessionViewerList,"data-testid":`billing-session-viewer-list`,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[rt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:V.emptyRow,children:t(`noData`)})}),rt.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:V.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.cwd!==void 0&&(0,m.jsx)(`span`,{className:V.modelProvider,children:Ni(e.cwd)}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(V.ubTag,V.ubTagNeutral),children:t(`sessionStaleBadge`)})]}),(0,m.jsx)(`td`,{className:V.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:V.numCol,children:U(e.cost)}),(0,m.jsx)(`td`,{className:V.numCol,children:e.lastActive>0?`${q(e.lastActive)} ${fi(e.lastActive)}`:`—`})]},e.id))]})]})})]})]})]}),I===`token`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-token`,children:[(0,m.jsx)(hn,{stats:e,trendDays:de,onTrendDays:fe,models:On,money:U,t}),e.perf!==void 0&&(0,m.jsxs)(`section`,{className:V.panel,"data-testid":`billing-panel-perf`,children:[(0,m.jsxs)(`div`,{className:V.panelHead,children:[(0,m.jsx)(`h3`,{className:V.panelTitle,children:t(`perfTitle`)}),(0,m.jsx)(`span`,{className:V.panelHint,children:t(`perfHint`)})]}),(0,m.jsx)(Dn,{perf:e.perf,models:On,t})]})]}),I===`pricing`&&(0,m.jsxs)(`div`,{className:V.tabPanel,"data-testid":`billing-tab-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:V.ubAlert,role:`note`,children:[(0,m.jsxs)(`div`,{className:V.ubAlertLeft,children:[(0,m.jsxs)(`span`,{className:V.ubRate,"data-testid":`billing-rate`,children:[t(`todayRate`),` 1 USD = `,K(ht.rate)]}),(0,m.jsx)(`span`,{className:y(V.ubTag,ht.live?V.ubTagSuccess:V.ubTagNeutral),children:ht.live?t(`rateLive`):t(`rateBuiltin`)}),yt>0&&(0,m.jsxs)(`span`,{className:V.ubTag,"data-testid":`billing-pricing-synced`,children:[t(`pricingSyncedAt`),` `,new Date(yt).toLocaleTimeString(Ct===`zh`?`zh-CN`:`en-US`,{hour:`2-digit`,minute:`2-digit`})]}),(0,m.jsx)(`button`,{type:`button`,className:V.heatmapRangeButton,"data-testid":`billing-pricing-sync`,disabled:gt,onClick:vt,children:t(gt?`pricingSyncing`:`pricingSyncNow`)})]}),(0,m.jsx)(`p`,{className:V.ubAlertNote,children:t(`pricingTip`)})]}),(0,m.jsxs)(`section`,{className:V.ubCard,"data-testid":`billing-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:V.ubCardHead,children:[(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`pricing`)}),(0,m.jsx)(`span`,{className:V.ubCardSub,children:t(`pricingUnit`)}),(0,m.jsx)(`input`,{className:V.ubSearch,type:`search`,value:Tt,placeholder:t(`pricingSearch`),"aria-label":t(`pricingSearch`),"data-testid":`billing-pricing-search`,onChange:e=>{Et(e.target.value)}})]}),(0,m.jsx)(`div`,{className:V.ubTablewrap,children:(0,m.jsxs)(`table`,{className:V.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`thModel`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`thInputMiss`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`thInputHit`)}),(0,m.jsx)(`th`,{className:V.numCol,children:t(`output`)}),(0,m.jsx)(`th`,{className:V.numCol,colSpan:2,children:t(`band`)})]})}),(0,m.jsx)(`tbody`,{children:Xn(Kt(),Tt).map(e=>{let n=e.price.input>0||e.price.output>0;return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:V.ubModel,children:[(()=>{let n=qn(St(kt,xt(e.key,W)),jt);if(n===null)return null;let r=Dt.includes(e.key),i=`${e.name} · ${t(n===`peak`?`peak`:`offPeak`)} · ${t(`bandPinHint`)}`;return(0,m.jsx)(`button`,{type:`button`,className:y(V.bandDot,V[n],r&&V.bandDotOn),"data-testid":`billing-band-dot`,"aria-pressed":r,"aria-label":i,title:i,onClick:()=>{Ot(Ce(e.key)),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.pinned-pref`))}})})(),(0,m.jsxs)(`span`,{className:V.ubModelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:V.ubTagAlert,"data-testid":`billing-price-uncatalogued`,children:t(`uncatalogued`)}),e.promo!==void 0&&Wt(e.promo,Date.now())&&(0,m.jsx)(p.Tooltip,{label:[e.promo.note,e.promo.endsAtMs===void 0?t(`promoOpenEnded`):t(`promoUntil`,{date:new Date(e.promo.endsAtMs).toLocaleDateString()})].filter(Boolean).join(` · `),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:V.ubTagPromo,"data-testid":`billing-price-promo`,children:t(`promoBadge`)})})]})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.input,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.cacheHit,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:n?Mt(e.price.output,e.price.currency):(0,m.jsx)(`span`,{className:V.na,children:`—`})}),n&&e.price.offPeak!==void 0&&e.peakHours!==void 0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsxs)(`span`,{className:V.ubChipPeak,children:[(0,m.jsx)(`span`,{className:V.ubChipLabel,children:e.tierSemantics===`latency`?t(`ubStd`):t(`ubPeak`)}),(0,m.jsxs)(`span`,{children:[Mt(e.price.input,e.price.currency),`/`,Mt(e.price.output,e.price.currency)]})]})}),(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsxs)(`span`,{className:V.ubChipOff,children:[(0,m.jsx)(`span`,{className:V.ubChipLabel,children:e.tierSemantics===`latency`?`Flex`:t(`ubOff`)}),(0,m.jsxs)(`span`,{children:[Mt(e.price.offPeak.input,e.price.currency),` / `,Mt(e.price.offPeak.output,e.price.currency)]})]})})]}):(0,m.jsx)(`td`,{className:V.numCol,colSpan:2,children:n?(0,m.jsx)(`span`,{className:V.flatTag,children:t(`flat`)}):(0,m.jsx)(`span`,{className:V.na,children:`—`})})]}),(e.extraRows??[]).map(t=>(0,m.jsxs)(`tr`,{className:V.ubExtraRow,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:V.ubExtraName,children:Yn(t.label,Ct)}),t.note!==void 0&&(0,m.jsx)(`span`,{className:V.ubExtraNote,children:Yn(t.note,Ct)})]}),(0,m.jsx)(`td`,{className:V.numCol,children:t.input===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Mt(t.input,e.price.currency)}),(0,m.jsx)(`td`,{className:V.numCol,children:(0,m.jsx)(`span`,{className:V.na,children:`—`})}),(0,m.jsx)(`td`,{className:V.numCol,children:t.output===void 0?(0,m.jsx)(`span`,{className:V.na,children:`—`}):Mt(t.output,e.price.currency)}),(0,m.jsx)(`td`,{className:V.numCol,colSpan:2,children:(0,m.jsx)(`span`,{className:V.na,children:`—`})})]},`${e.key}:${t.label}`))]},e.key)})})]})})]}),(0,m.jsxs)(`section`,{className:V.ubCard,children:[(0,m.jsx)(`div`,{className:V.ubCardHead,children:(0,m.jsx)(`h3`,{className:V.ubCardTitle,children:t(`pricingNotes`)})}),(0,m.jsxs)(`ul`,{className:V.ubNotes,children:[(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`cacheHit`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteCache`)})]}),(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`peakBand`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteBand`)})]}),(0,m.jsxs)(`li`,{className:V.ubNotesItem,children:[(0,m.jsx)(`span`,{className:V.ubNotesTerm,children:t(`pricingSource`)}),(0,m.jsx)(`span`,{className:V.ubNotesDesc,children:t(`noteSource`)})]})]})]})]}),v(`billing.dashboard.decor`,{position:`footer`})]}),(0,m.jsxs)(`footer`,{className:V.modalFooter,"data-testid":`billing-footer`,children:[(0,m.jsx)(`span`,{children:t(`footer`)}),(0,m.jsx)(`span`,{children:t(`footerCredit`).replace(`{version}`,e.pluginVersion===void 0?`—`:`v${e.pluginVersion}`)})]})]})})}function Ni(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??`—`}let Pi={display:[`显示`,`密度`,`动效`,`紧凑`,`舒适`,`克制`,`丰富`,`display`,`density`,`motion`,`compact`,`comfortable`],budget:[`预算`,`金额`,`本月`,`花费`,`进度`,`budget`,`amount`,`spend`,`progress`],alert:[`峰谷`,`峰`,`谷`,`提醒`,`通知`,`预览`,`切换`,`peak`,`off-peak`,`alert`,`notify`,`preview`],toggles:[`usage_stats`,`工具`,`即时代费`,`胶囊`,`中转站`,`站点`,`隐藏`,`relay`,`site`,`live`,`cost`,`hide`],displayExtra:[`悬浮`,`订阅`,`计费卡`,`指标`,`环比`,`主数字`,`float`,`subscription`,`card`,`metric`,`delta`],advanced:[`自定义`,`单价`,`价格`,`低谷`,`custom`,`price`],about:[`关于`,`版本`,`作者`,`许可`,`仓库`,`about`,`version`,`author`,`license`,`repo`]};function Fi(e){return Object.values(Pi).every(t=>ii(e,t))}let Ii=[`below`,`above`,`toolbar`];function Li({liveCostPrefs:e,onLiveCostPrefs:t,t:n}){let[r,i]=(0,d.useState)(!1),a={below:n(`liveCostBarPosBelow`),above:n(`liveCostBarPosAbove`),toolbar:n(`liveCostBarPosToolbar`)},o=Ii.map(e=>({id:e,label:a[e]}));return(0,m.jsx)(p.Menu,{open:r,align:`end`,portal:!0,compact:!0,items:o,selectedId:e.position,onSelect:n=>{i(!1);let r=Ii.find(e=>e===n);r!==void 0&&t({...e,position:r})},onClose:()=>{i(!1)},anchor:(0,m.jsxs)(`button`,{type:`button`,className:V.rdoSelect,"data-testid":`billing-livecost-position-select`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>{i(!r)},children:[(0,m.jsx)(`span`,{children:a[e.position]}),(0,m.jsx)(`span`,{className:y(V.rdoChevron,r&&V.rdoChevronOpen),"aria-hidden":!0,children:xr?(0,m.jsx)(xr,{}):null})]})})}function Ri(e){let{t,checkModels:n,publishCosts:r,registerOpen:i,renderSlot:a,useStore:o,actions:s}=e,[c,l]=(0,d.useState)(mr),[u,f]=(0,d.useState)(gr),[p,h]=(0,d.useState)([]),[g,_]=(0,d.useState)(void 0),[v,y]=(0,d.useState)([]),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[w,T]=(0,d.useState)(()=>ue()),[ee,O]=(0,d.useState)(()=>xe()),k=(0,d.useCallback)(e=>{O(e),Se(e),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.language-pref`))},[]),j=(0,d.useCallback)(e=>{T(e),de(e),window.dispatchEvent(new CustomEvent(I))},[]),[ne,re]=(0,d.useState)(()=>E()),M=(0,d.useCallback)(e=>{re(e),D(e)},[]),[ie,se]=(0,d.useState)(()=>ae()),N=(0,d.useCallback)(e=>{se(e),oe(e)},[]),[F,fe]=(0,d.useState)(()=>P()),pe=(0,d.useCallback)(e=>{fe(e),le(e),window.dispatchEvent(new CustomEvent(ce))},[]),[me,he]=(0,d.useState)(()=>te()),ge=(0,d.useCallback)(e=>{he(e),A(e)},[]),[_e,ve]=(0,d.useState)(()=>{let e=Te();return $e(e),e}),ye=(0,d.useCallback)(e=>{ve(e),$e(e),Ee(e)},[]),L=(0,d.useMemo)(()=>Zr(c),[c,_e]),be=ee,R=(0,d.useCallback)((e,n)=>{let r=(be===`en`?Be:ze)[e]??t(e);if(n===void 0)return r;let i=r;for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[be,t]),[Ce,we]=(0,d.useState)(!1),De=(0,d.useCallback)(()=>{we(!1)},[]),z=(0,d.useCallback)(()=>{pi().then(e=>{e!==null&&l(e)}),mi().then(({balances:e,reconcile:t})=>{e.length>0&&h(e),_(t)}),hi().then(e=>{e.length>0&&y(e),x(!1)}).catch(()=>{x(!0)}),gi().then(e=>{C(e)}).catch(()=>{})},[]),Oe=(0,d.useCallback)(()=>{z(),xi(),we(!0)},[z]);(0,d.useEffect)(()=>{z(),xi()},[z]);let[ke,Ae]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{Ae(!document.hidden),document.hidden||(z(),xi())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[z]),(0,d.useEffect)(()=>{if(!ke)return;let e=setInterval(()=>{z(),xi()},Ce?pr:3e5);return()=>{clearInterval(e)}},[z,Ce,ke]),(0,d.useEffect)(()=>{let e=!0;return n().then(t=>{e&&(f(t),ot(t.catalog??[]))}),()=>{e=!1}},[n]);let B=q(),je=Object.entries(L.byDay).filter(([e])=>e.startsWith(B.slice(0,7))).reduce((e,[,t])=>e+t.cost,0),Me=L.byDay[B]?.cost??0,Ne=new Date;Ne.setDate(Ne.getDate()-1);let Pe=`${Ne.getFullYear()}-${String(Ne.getMonth()+1).padStart(2,`0`)}-${String(Ne.getDate()).padStart(2,`0`)}`,Fe=L.byDay[Pe]?.cost??0,Ie=Fe>0?(Me-Fe)/Fe*100:0,Le=Or(L.byDay,B),V=(0,d.useMemo)(()=>Dr(L.byDay).map(e=>{let t=L.byDay[e.date];return{date:e.date,cost:e.cost,tokens:t===void 0?0:Er(t)}}),[L.byDay]),Re=Object.entries(L.byDay).filter(([e])=>e.startsWith(B.slice(0,7))).reduce((e,[,t])=>e+Er(t),0),Ve=(()=>{let e=L.byDay[B];return e===void 0?0:Er(e)})(),He=Or(L.byDay,B,Er),Ue=o(e=>e.enabled),We=o(e=>e.amount),Ge=o(e=>e.tierAlertDays),Ke=o(e=>e.lastTierSwitchAt),[H,qe]=(0,d.useState)(()=>cr()),[Je,Ye]=(0,d.useState)(null),[Xe,Ze]=(0,d.useState)(null),[Qe,et]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{if(!H.enabled)return;let e=setInterval(()=>et(Date.now()),pr);return()=>{clearInterval(e)}},[H.enabled]);let tt=(0,d.useCallback)(e=>{qe(e),lr(e)},[]),nt=v.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),rt=xt(c.byTurn?.[0]?.model,nt),it=(0,d.useCallback)(()=>{Ze({entering:ft(Date.now())===`peak`?`offPeak`:`peak`,atMs:Date.now()+18e4,channel:rt})},[rt]),at=We>0?We:c.budget??0,st=Ue&&at>0?je/at>=1?`over`:je/at>=.8?`warn`:`none`:`none`,ct=(0,d.useCallback)(()=>{let e=!Ue;s.setEnabled(e),e&&typeof Notification<`u`&&Notification.permission==="default"&&Notification.requestPermission()},[s,Ue]);(0,d.useEffect)(()=>{if(!Ue||at<=0)return;let e=je/at*100,t=fr.filter(t=>e>=t&&Ge?.[String(t)]!==B);if(t.length===0)return;let n=t[t.length-1]??100;if(s.markTierAlerted(t,B),!$r())return;let r=R(`budgetTierBody`).replace(`{cost}`,K(je)).replace(`{budget}`,K(at)).replace(`{pct}`,String(n));ei(`budget:${n}:${B}`,()=>{new Notification(R(`budget`),{body:r})})},[Ue,at,je,Ge,B,s,R]),(0,d.useEffect)(()=>{let e=ur(Qe,H,Ke,rt);if(e===null||(s.markTierSwitchAlerted(e.atMs),Ye(e),!H.webNotify||!$r()))return;let t=Math.max(1,Math.round((e.atMs-Qe)/6e4)),n=R(e.entering===`peak`?`peakAlertTitlePeak`:`peakAlertTitleOff`),r=R(e.channel===`zhipu-coding-plan`?e.entering===`peak`?`tierAlertEnterPeakZhipu`:`tierAlertEnterOffZhipu`:e.entering===`peak`?`tierAlertEnterPeak`:`tierAlertEnterOff`).replace(`{minutes}`,String(t));ei(`peak:${e.atMs}`,()=>{new Notification(n,{body:r})})},[Qe,Ke,H,rt,s,R]);let ut=o(e=>e.lastBalanceAlertDay),dt=o(e=>e.modelBudgets??Wn),pt=o(e=>e.modelTierAlertDays??Gn),mt=(0,d.useMemo)(()=>Ar(L.byDayModels,B.slice(0,7)),[L.byDayModels,B]),ht=L.lowBalanceThreshold??50,gt=(0,d.useMemo)(()=>{if(p.length===0)return;let e=Sr(L.byDay,B),t=lt().rate;for(let n of p){if(n.totalBalance===void 0||n.error!==void 0)continue;let r=n.currency===`USD`?n.totalBalance*t:n.totalBalance;if(r>=ht)continue;let i=e>0?Math.floor(r/e):void 0;return{name:n.displayName,cny:r,days:i}}},[p,L.lowBalanceThreshold,L.byDay,B]);(0,d.useEffect)(()=>{if(gt===void 0||ut===B||(s.markBalanceAlerted(B),!$r()))return;let e=R(`balanceLowBody`).replace(`{name}`,gt.name).replace(`{balance}`,K(gt.cny)).replace(`{days}`,gt.days===void 0?`—`:String(gt.days));ei(`balance:${B}`,()=>{new Notification(R(`balance`),{body:e})})},[gt,ut,B,s,R]),(0,d.useEffect)(()=>{let e=[],t;for(let[n,r]of Object.entries(dt)){if(!(r>0))continue;let i=mt[n]??0;for(let a of Mr(i,r)){let o=`${n}:${a}`;pt[o]!==B&&(e.push(o),(t===void 0||a>t.tier)&&(t={model:n,tier:a,cost:i,budget:r}))}}if(e.length===0||t===void 0||(s.markModelTierAlerted(e,B),!$r()))return;let n=R(`modelBudgetBody`).replace(`{model}`,t.model).replace(`{cost}`,K(t.cost)).replace(`{budget}`,K(t.budget)).replace(`{pct}`,String(t.tier));ei(`model-budget:${t.model}:${t.tier}:${B}`,()=>{new Notification(R(`modelBudgetTitle`),{body:n})})},[dt,mt,pt,B,s,R]);let _t=(0,d.useMemo)(()=>{let e=B.slice(0,7),t=new Map;for(let[n,r]of Object.entries(L.byDayModels??{}))if(n.startsWith(e))for(let[e,n]of Object.entries(r)){if(n.cost<=0)continue;let r=Ht(e).provider,i=L.byModel?.[e]?.plan===!0,a=t.get(r)??{cost:0,plan:i};a.cost+=n.cost,i||(a.plan=!1),t.set(r,a)}let n,r;for(let e of t){let t=e[1].plan?r:n;(t===void 0||e[1].cost>t[1].cost)&&(e[1].plan?r=e:n=e)}let i=e=>{let t=p.find(t=>$(t.provider)===$(e));if(t===void 0||t.totalBalance===void 0){if(e===`Custom`){let e=p.filter(e=>e.totalBalance!==void 0&&e.error===void 0),t=e[0];return t!==void 0&&e.length===1?i(t.provider):void 0}return{text:t?.error===`unauthorized`?R(`balanceUnauthorized`):t?.error===`unreachable`||t?.error===`invalid`?R(`balanceUnreachable`):R(`balanceUnconfigured`),low:!1}}let n=t.currency===`USD`?`$${t.totalBalance.toFixed(2)}`:K(t.totalBalance),r=lt().rate;return{text:n,low:(t.currency===`USD`?t.totalBalance*r:t.totalBalance)<ht}},a=e=>{let t=v.find(t=>t.displayName===e||Rr(t.provider)===e);if(t===void 0||t.windows.length===0)return{text:R(`subscriptionNoApi`),low:!1};let n=t.windows.reduce((e,t)=>Math.min(e,t.remainingPercent),100);return{text:n<=0?R(`subscriptionExhausted`):R(`subscriptionRemaining`).replace(`{pct}`,String(n)),low:n<20}},o=n===void 0?void 0:i(n[0]);return{direct:n===void 0||o===void 0?void 0:{name:n[0],...o},sub:r===void 0?void 0:{name:r[0],...a(r[0])}}},[L.byDayModels,L.byModel,L.lowBalanceThreshold,p,v,B,R]),vt=(0,d.useMemo)(()=>{let e=L.total;return{input:e.input,output:e.output,cacheRead:e.cacheHit,cacheMiss:e.cacheMiss,calls:e.calls}},[L]);(0,d.useEffect)(()=>{r({todayCost:Me,monthCost:je})},[Me,je,r]),(0,d.useEffect)(()=>i(Oe),[i,Oe]);let yt=(0,d.useMemo)(()=>c.byTurn??[],[c.byTurn]);return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(Oi,{...e,t:R,currency:w,onOpen:Oe,monthCost:je,todayCost:Me,weekCost:Le,days:V,vendorStatus:_t,dash:vt,cardPrefs:me,monthTokens:Re,todayTokens:Ve,weekTokens:He,floatPrefs:ne,subscriptions:v,budgetPressure:st,deltaPct:Ie}),Ce&&(0,m.jsx)(Mi,{stats:L,t:R,onClose:De,userPrices:_e,onUserPrices:ye,health:u,balances:p,...g===void 0?{}:{reconcile:g},quotas:v,relayQuotas:S,currency:w,onCurrency:j,language:ee,onLanguage:k,turns:yt,renderSlot:a,budgetEnabled:Ue,budgetAmount:at,modelBudgets:dt,monthModelCost:mt,onModelBudget:s.setModelBudget,onToggleBudget:ct,onBudgetAmount:s.setAmount,peakConfig:H,onPeakConfig:tt,onPreviewPeak:it,floatPrefs:ne,onFloatPrefs:M,cardPrefs:me,onCardPrefs:ge,sitePrefs:ie,onSitePrefs:N,liveCostPrefs:F,onLiveCostPrefs:pe,quotasStale:b}),(Je!==null||Xe!==null)&&(0,m.jsx)(dr,{hit:Je??Xe,config:H,t:R,onDismiss:()=>{Ye(null),Ze(null)}})]})}function zi(e,t){if(t===void 0||e?.bySession===void 0)return 0;let n=e.bySession.find(e=>e.id===t);return(n?.cost??0)+(n?.subCost??0)}function Bi(e,t){return t===void 0||e?.bySession===void 0?0:e.bySession.find(e=>e.id===t)?.subCost??0}function Vi(e,t){if(t===void 0||e?.byTurn===void 0)return 0;let n=0,r=-1;for(let i of e.byTurn)i.sessionId===t&&(r===-1||i.turn>r)&&(r=i.turn,n=i.cost);return n}function Hi(e,t=20){let n=[];for(let r of e)if(r.status===`ok`)for(let e of r.windows)e.remainingPercent>t||n.push({name:r.displayName,kind:e.kind,pct:e.remainingPercent});return n.sort((e,t)=>e.pct-t.pct).slice(0,3)}function Ui(e,t){if(t===void 0||e?.byTurn===void 0)return;let n=-1,r;for(let i of e.byTurn)i.sessionId===t&&(n===-1||i.turn>n)&&(n=i.turn,r=i.model);return r}async function Wi(){try{let e=await fetch(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return{...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{}}}catch{return null}}async function Gi(){try{let e=await fetch(`/api/billing/subscriptions`);if(!e.ok)return[];let t=JSON.parse(await e.text());if(typeof t!=`object`||!t||!(`quotas`in t))return[];let n=t.quotas;return Array.isArray(n)?n:[]}catch{return[]}}function Ki(e){switch(e){case`session`:return`subscriptionSession`;case`weekly`:return`subscriptionWeekly`;case`monthly`:return`subscriptionMonthly`;default:return`subscriptionBilling`}}function qi({hasBandPlan:e}){let[t,n]=(0,d.useState)(()=>me()),[r,i]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=()=>{n(me())};window.addEventListener(pe,e),window.addEventListener(`storage`,e);let t=setInterval(()=>{i(Date.now())},3e4);return()=>{window.removeEventListener(pe,e),window.removeEventListener(`storage`,e),clearInterval(t)}},[]),t.length===0)return null;let a=cr().leadMin*6e4,o=t.map(t=>({key:t,state:qn(St(r,xt(t,e)),a)})).filter(e=>e.state!==null);return o.length===0?null:(0,m.jsx)(`span`,{className:V.bandDots,"data-testid":`billing-pinned-dots`,children:o.map(e=>(0,m.jsx)(`span`,{className:y(V.bandDot,V.bandDotOn,V[e.state]),role:`img`,"aria-label":e.key,title:e.key},e.key))})}function Ji(){let[e,t]=(0,d.useState)(()=>ue());return(0,d.useEffect)(()=>{let e=()=>{t(ue())};return window.addEventListener(I,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(I,e),window.removeEventListener(`storage`,e)}},[]),e}function Yi(){let[e,t]=(0,d.useState)(()=>P().show),[n,r]=(0,d.useState)(()=>P().position);return(0,d.useEffect)(()=>{let e=()=>{t(P().show),r(P().position)};return window.addEventListener(ce,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(ce,e),window.removeEventListener(`storage`,e)}},[]),{visible:e,position:n}}function Xi(e,t){let[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(()=>Date.now()),[c,l]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{l(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!c||!t)return;let e=!1,n=()=>{Wi().then(t=>{!e&&t!==null&&r(t)}),Gi().then(t=>{e||a(t)}),e||s(Date.now())};n();let i=setInterval(n,3e4);return()=>{e=!0,clearInterval(i)}},[e,c,t]);let u=(0,d.useMemo)(()=>zi(n,e),[n,e]),f=(0,d.useMemo)(()=>Bi(n,e),[n,e]),p=(0,d.useMemo)(()=>Vi(n,e),[n,e]),m=(0,d.useMemo)(()=>Hi(i),[i]),h=(0,d.useMemo)(()=>xt(Ui(n,e),i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)),[n,e,i]);return{sessionCost:u,subCost:f,turnCost:p,tier:(0,d.useMemo)(()=>St(o,h),[o,h]),chips:m,hasBandPlan:i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)}}function Zi({sessionId:e,t}){let{visible:n,position:r}=Yi(),{sessionCost:i,subCost:a,turnCost:o,tier:s,chips:c,hasBandPlan:l}=Xi(e,n&&r!==`toolbar`),u=Ji(),d=e=>K(Xt(e,u),u),f=i>0||o>0,p=s?.tier===`peak`;return!n||r===`toolbar`?null:(0,m.jsxs)(`span`,{className:r===`above`?y(V.feeBar,V.feeBarAbove):V.feeBar,"data-testid":`billing-live-cost-bar`,children:[(0,m.jsx)(qi,{hasBandPlan:l}),s!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:p?V.feeChipPrimary:V.feeChipOff,"data-testid":`billing-live-tier`,children:t(p?`tierPeak`:`tierOff`)}),(0,m.jsx)(`span`,{className:V.feeCount,children:wt(s.nextSwitchInMs)}),(0,m.jsx)(`span`,{className:V.feeSuffix,children:t(p?`tierToOff`:`tierToPeak`)})]}),f&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:V.feeItem,"data-testid":`billing-live-turn`,children:[t(`liveTurn`),` `,(0,m.jsx)(`span`,{className:V.feeNum,"data-tick":`turn`,children:d(o)})]}),(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:V.feeItem,"data-testid":`billing-live-session`,children:[t(`liveSession`),` `,(0,m.jsx)(`span`,{className:V.feeNum,"data-tick":`session`,children:d(i)}),a>0&&(0,m.jsx)(`span`,{className:V.feeSuffix,"data-testid":`billing-live-session-sub`,children:t(`liveSessionSub`).replace(`{cost}`,d(a))})]})]}),c.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:V.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:e.pct<=10?V.feeChipError:V.feeChipAlert,"data-testid":`billing-live-quota`,children:[e.name,` `,t(Ki(e.kind)),` `,e.pct,`%`]})]},`${e.name}:${e.kind}`))]})}function Qi({sessionId:e,t}){let n=Ji(),r=e=>K(Xt(e,n),n),{visible:i,position:a}=Yi(),{sessionCost:o,subCost:s,turnCost:c,tier:l,chips:u,hasBandPlan:d}=Xi(e,i&&a===`toolbar`);if(!i||a!==`toolbar`)return null;let f=l?.tier===`peak`,h=u.reduce((e,t)=>Math.min(e,t.pct),100),g=h<=10?V.feeInlineError:h<=20?V.feeInlineAlert:V.feeInline,_=[...l===null?[]:[`${wt(l.nextSwitchInMs)} ${t(f?`tierToOff`:`tierToPeak`)}`],`${t(`liveTurn`)} ${r(c)}`,`${t(`liveSession`)} ${r(o)}`,...s>0?[t(`liveSessionSub`).replace(`{cost}`,r(s))]:[],...u.map(e=>`${e.name} ${t(Ki(e.kind))} ${e.pct}%`)].join(` · `);return(0,m.jsx)(p.Tooltip,{label:_,side:`top`,delayMs:500,children:(0,m.jsxs)(`span`,{className:g,"data-testid":`billing-live-cost-chip`,role:`note`,"aria-label":_,children:[(0,m.jsx)(qi,{hasBandPlan:d}),l!==null&&(0,m.jsx)(`span`,{className:f?V.feeChipPrimary:V.feeChipOff,"data-testid":`billing-live-tier`,children:t(f?`tierPeak`:`tierOff`)}),o>0&&(0,m.jsx)(`span`,{className:V.feeInlineNum,children:r(o)})]})})}function $i(){let e,t,n=new Set;return{readCosts:()=>e,subscribeCosts:t=>(t(e),n.add(t),()=>{n.delete(t)}),openDashboard:()=>{t?.()},publishCosts:t=>{e=t;for(let e of n)try{e(t)}catch{x(`billing-costs-listener-threw`)}},registerOpen:e=>(t=e,()=>{t===e&&(t=void 0)})}}let ea={enabled:!1,timeout:0};function ta(){try{let e=localStorage.getItem(`dsh-billing-completion-notify-v1`);if(e===null)return{...ea};let t=JSON.parse(e);return{enabled:t.enabled===!0,timeout:typeof t.timeout==`number`?t.timeout:0}}catch{return{...ea}}}function na(e){return e.completed===!0||e.running===!1}function ra(e,t){let n=new Set,r=new Set,i,a=e.getSnapshot();for(let e of a.ids){let t=a.byId[e];t!==void 0&&(r.add(String(e)),na(t)&&n.add(String(e)))}let o=e=>{let{enabled:n,timeout:r}=t();if(n&&!(typeof Notification>`u`)&&Notification.permission===`granted`)try{let t=new Notification(e,{body:e,tag:`dsh-billing-completion`,requireInteraction:r===0});r>0&&(i!==void 0&&clearTimeout(i),i=setTimeout(()=>t.close(),r*1e3))}catch{x(`notification-constructor-failed`)}},s=e.subscribe(()=>{let t=e.getSnapshot(),i=[];for(let e of t.ids){let a=t.byId[e];if(a===void 0)continue;let o=String(e),s=na(a),c=!r.has(o);c&&r.add(o),s&&!c&&!n.has(o)&&i.push(a.title??a.id??o),s?n.add(o):n.delete(o)}if(i.length>0){let e=i.length===1?i[0]:`${i.length} 个会话已完成`;e!==void 0&&o(e)}});return()=>{s(),i!==void 0&&clearTimeout(i)}}let ia=[`slots`,`locale`,`remote`,`sessions`];function aa(e){let t=$i();e.provide(`billingMetrics`,t);let n=Kn();e.effect(()=>e.locale.register(Re,{zh:ze,en:Be}),`ui-usage-billing: dictionaries`),e.slots.inject(`sidebar.footer.action`,()=>e.slots.register({name:`sidebar.footer.action`,id:`usage-billing`,order:-10,locale:Re,children:{"billing.dashboard.decor":{kind:`list`,scope:`root`}},store:n,inject:()=>({checkModels:async()=>{try{let[t,n]=await Promise.all([e.remote.llm.listProviders(),e.remote.llm.listConfigurableProviders()]);if(!t.ok||!n.ok)return{checked:!0,available:!1,models:0,failures:0,okProviders:[],badProviders:[]};let r=new Map(n.value.map(e=>[e.provider,e])),i=await Promise.all(t.value.map(async t=>{let n=r.get(t.id);if(n===void 0)return{provider:t,models:[]};let i=await e.remote.llm.discoverModels(n.settingsNs,{provider:t.id});return i.ok?{provider:t,models:i.value}:{provider:t,failed:!0}})),a=[],o=[],s=[],c=0;for(let e of i){if(`failed`in e){s.push(e.provider.name);continue}o.push(e.provider.name),c+=e.models.length;for(let t of e.models)a.push({id:t.id,...typeof t.name==`string`&&t.name!==``?{name:t.name}:{},provider:e.provider.name})}return{checked:!0,available:o.length>0,models:c,failures:s.length,okProviders:o,badProviders:s,catalog:a}}catch{return{checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]}}},publishCosts:e=>{t.publishCosts(e)},registerOpen:e=>t.registerOpen(e)})},Ri)),e.slots.inject(`conversation.composer.dock`,()=>e.slots.register({name:`conversation.composer.dock`,id:`usage-billing-cost`,order:0,locale:Re,inject:e=>({sessionId:_(e)})},Zi)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-cost-chip`,order:0,locale:Re,inject:e=>({sessionId:_(e)})},Qi)),e.effect(()=>ra(e.sessions.list,ta),`ui-usage-billing: completion notifier`)}return n.UsageBilling=Ri,n.apply=aa,n.inject=ia,t.exports}});
6
6
  //# sourceMappingURL=client.js.map
@@ -33,6 +33,10 @@ export type BudgetPrefsActions = {
33
33
  setModelBudget: (d: BudgetPrefsState, key: string, value: number) => void;
34
34
  markModelTierAlerted: (d: BudgetPrefsState, marks: readonly string[], day: string) => void;
35
35
  };
36
+ /** 读取兜底:v1.5.x 老持久化状态缺 `modelBudgets` 键(模块级常量,引用稳定不触发重渲染)。 */
37
+ export declare const EMPTY_MODEL_BUDGETS: Readonly<Record<string, number>>;
38
+ /** 读取兜底:v1.5.x 老持久化状态缺 `modelTierAlertDays` 键(同上)。 */
39
+ export declare const EMPTY_MODEL_TIER_ALERT_DAYS: Readonly<Record<string, string>>;
36
40
  /**
37
41
  * Declare the budget-preferences store handle.
38
42
  * @returns the store handle for the register call's store seat.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kenz1117/dsh-ui-usage-billing",
3
3
  "description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
4
- "version": "1.6.1",
4
+ "version": "1.6.2",
5
5
  "keywords": [
6
6
  "deepseek-harness",
7
7
  "deepseek",