tokentracker-cli 0.83.2 → 0.83.3
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/dashboard/dist/assets/{AchievementBadge-BrSr5pjk.js → AchievementBadge-BEk-hvfD.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-za-wqAO2.js → AchievementsPage-kLeXpzIX.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-CGRVm1uS.js → AchievementsSection-BtDWuZ8m.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-D1XDT2dG.js → BadgeDetailModal-BEgI_98J.js} +1 -1
- package/dashboard/dist/assets/{Card-DX2Wwm9U.js → Card-DvOwwAzG.js} +1 -1
- package/dashboard/dist/assets/{ClawdAnimated-D6JzFu8y.js → ClawdAnimated-B_T5A9tJ.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-NWiETwtS.js → CommandPalette-BqAHVsZU.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-D4FdxAWd.js → CommunityStatsModal-g6EL03ZU.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-SAheZUAv.js → ConfirmModal-C7nLLif7.js} +1 -1
- package/dashboard/dist/assets/DashboardPage-riwGRfNO.js +1 -0
- package/dashboard/dist/assets/{DevicePage-Cf-PHRlL.js → DevicePage-DMs07QPT.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-pg5pVOeD.js → DialogClose-Dlh20IoO.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-BkWNYqG-.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-Im7ESzoS.js → DialogTitle-C6n2pohw.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-CGGFraHR.js → FadeIn-9jciDZsH.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-DRTZXRsx.js → HeaderGithubStar-DWOEAlWe.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-Dn62HUZu.js → IpCheckPage-BrsvUoQe.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-CLsljoir.js → LandingPage-rlam9dyu.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardAvatar-DktI_89h.js → LeaderboardAvatar-BtMM-6cC.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-t87ElnDI.js → LeaderboardPage-AhwAfNL9.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProfileModal-DN7HurS3.js → LeaderboardProfileModal-DBMJkIPl.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-CprOXLXX.js → LeaderboardProfilePage-B2S8pmDd.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-DRX3XMYx.js → LimitsPage-iwfTTvqG.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-B8BtIdAA.js → LocalOnlyNotice-DL72G1p9.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-OoduGJmK.js → LoginCard-6lOxJlws.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-DoDoCpr6.js → LoginModal-C1ldxgZv.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-Dn2KMisI.js → LoginPage-Cz6lrheW.js} +1 -1
- package/dashboard/dist/assets/{PetPage-CVaG5H3O.js → PetPage-CfFyzGFY.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-B2HqJNaq.js → PopoverPopup-qAngi4Xc.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-BYl1Yyf3.js → ProviderIcon-I5z4CMY3.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-DWfgvuvR.js → ResetPasswordPage-A5bHmTUi.js} +1 -1
- package/dashboard/dist/assets/{Select-ClnnGJY1.js → Select-DDInV6Vc.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-iaFWq7GD.js → SelectItemText-DIsD6lWR.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-zwAOWRur.js → SettingsPage-BUCnJfRg.js} +1 -1
- package/dashboard/dist/assets/{SkillsPage-BB96nB2i.js → SkillsPage-BhsGmLpr.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-9_VJKdPr.js → TokenGalaxy-j5bHVfYv.js} +1 -1
- package/dashboard/dist/assets/TrendMonitor-ifxuzprQ.js +19 -0
- package/dashboard/dist/assets/{WidgetsPage-CjAT6p0C.js → WidgetsPage-QZS8jTR0.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-ba6teG1N.js → WrappedPage-CzlxH4gJ.js} +1 -1
- package/dashboard/dist/assets/__vite-browser-external-C44tPAD-.css +1 -0
- package/dashboard/dist/assets/{__vite-browser-external-DWKjPxnU.js → __vite-browser-external-hJyUffEJ.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-HCzl7U8i.js → agent-logos-WXnblKNu.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-TvEj8NTT.js → arrow-up-right-WGuMZ7yP.js} +1 -1
- package/dashboard/dist/assets/{check-Cz3lYRiR.js → check-DQswISeD.js} +1 -1
- package/dashboard/dist/assets/{copy-CTtF84H9.js → copy-6aPUSNsw.js} +1 -1
- package/dashboard/dist/assets/{download-B5WAY6Nh.js → download-DL3wQKU1.js} +1 -1
- package/dashboard/dist/assets/{flame-Cja4F8Mj.js → flame-BY3LUnQc.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-UavRPN4W.js → format-tokens-DUXqRlZ8.js} +1 -1
- package/dashboard/dist/assets/{icons-BW2vjmu_.js → icons-CT3DYBKd.js} +1 -1
- package/dashboard/dist/assets/{index-BnzrUY9J.js → index-BcTWurhn.js} +1 -1
- package/dashboard/dist/assets/{index-Bfxr6erc.js → index-BsgZcvQd.js} +1 -1
- package/dashboard/dist/assets/{index-0w19KMWl.js → index-pza5Zl32.js} +1 -1
- package/dashboard/dist/assets/{info-F-75j15K.js → info-CuyReqZo.js} +1 -1
- package/dashboard/dist/assets/{limits-providers-8NsMiLNP.js → limits-providers-FnlIwbBy.js} +1 -1
- package/dashboard/dist/assets/{link-2-C_eJlLvb.js → link-2-dgMFFrBX.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-BjzQhjhO.js → loader-circle-D2Erh-me.js} +1 -1
- package/dashboard/dist/assets/{provider-display-D1zp03ID.js → provider-display-DXMQRWSr.js} +1 -1
- package/dashboard/dist/assets/{react-Nv3-bJyw.js → react-w-68N3xj.js} +1 -1
- package/dashboard/dist/assets/{skills-api-DazKXxME.js → skills-api-CkMNAsEg.js} +1 -1
- package/dashboard/dist/assets/{terminal-DBXjwlTm.js → terminal-CJMbTjNB.js} +1 -1
- package/dashboard/dist/assets/{trash-2-DLG8hKJm.js → trash-2-VaWsdH7y.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-BQB72xAN.js → use-community-stats-DdAUa2P5.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-CH8MmjYf.js → use-limits-display-prefs-DJUffL2_.js} +1 -1
- package/dashboard/dist/assets/{use-native-settings-__RhxrW5.js → use-native-settings-CiYsT_Ip.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-AhnqpdnT.js → use-ordered-list-B12VdEap.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-C6xgTm9r.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-CCYtJ_cN.js → use-session-efficiency-pref-rHhQnzAS.js} +1 -1
- package/dashboard/dist/assets/{use-transform-BhcppNI4.js → use-transform-uFbh6Odm.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-CbA095lv.js → use-usage-limits-DmT_wC1b.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-Dt2GqkDm.js → useCurrency-D3_YrrTw.js} +1 -1
- package/dashboard/dist/assets/{useScrollLock-C5d53j7C.js → useScrollLock-JHdC5cyV.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-dnqZK7Z-.js → useTokenFormat-CMYJB7gb.js} +1 -1
- package/dashboard/dist/assets/{zap-Bw5OO91s.js → zap-Cr4tl-1M.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dashboard/dist/share.html +2 -2
- package/package.json +1 -1
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/dashboard/dist/assets/DashboardPage-CjnBsm3Q.js +0 -1
- package/dashboard/dist/assets/DialogDescription-CVuGFYFU.js +0 -1
- package/dashboard/dist/assets/TrendMonitor-D9RHcQgH.js +0 -19
- package/dashboard/dist/assets/__vite-browser-external-D_0JUhT7.css +0 -1
- package/dashboard/dist/assets/use-reduced-motion-CA2IXeeO.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as Na,r as d,j as e,L as Lo,bZ as Mo,H as ut,al as Wt,b_ as Fe,b$ as Eo,c0 as Ro,a4 as Ur,c1 as ha,c2 as Rs,c3 as Is,c4 as yr,c5 as Io,c6 as Fo,c7 as $o,c8 as br,c9 as Ut,ca as Po,cb as Bo,cc as re,c as l,R as vt,X as kr,ar as Ht,a5 as Sa,i as Je,v as Fs,cd as zo,aO as _a,d as Nt,ce as Oo,G as $s,E as Ps,U as Uo,B as Ho,a7 as Vo,u as Wo,a as Bs,bp as Ko,cf as Go,cg as qo,ch as Yo,l as ka,ci as Zo,M as Hr,_ as Jo,cj as Vr,g as Qo,Y as Xo,bY as ei,ck as ti,cl as ai,cm as ri,cn as si,co as ni,cp as oi,cq as ii,ac as li,cr as ci,cs as di,ct as Wr,a6 as Kr,cu as ui}from"./__vite-browser-external-hJyUffEJ.js";import{a as Gr,u as mi,C as hi,b as gi,c as qr,D as xi,S as fi,v as pi,s as yi,K as bi,P as ki}from"./use-ordered-list-B12VdEap.js";import{u as Kt,t as Yr,T as zs,g as wi,f as Zr,D as _i,a as vi,b as ji}from"./TrendMonitor-ifxuzprQ.js";import{u as Ni}from"./use-usage-limits-DmT_wC1b.js";import{u as Ca}from"./useCurrency-D3_YrrTw.js";import{u as Me}from"./useTokenFormat-CMYJB7gb.js";import{f as jt,A as Si}from"./provider-display-DXMQRWSr.js";import{g as Ci,q as Os,J as Ti,M as Ai,m as Ne}from"./react-w-68N3xj.js";import{D as Di,a as Li,b as Mi,c as Ei,d as Ri,e as Ii}from"./DialogTitle-C6n2pohw.js";import{D as Fi}from"./DialogClose-Dlh20IoO.js";import{C as Ce}from"./Card-DvOwwAzG.js";import{S as Us}from"./Select-DDInV6Vc.js";import{P as Ct}from"./ProviderIcon-I5z4CMY3.js";import{u as Hs}from"./use-reduced-motion-C6xgTm9r.js";import{a as Vs,u as Ws}from"./use-transform-uFbh6Odm.js";import{I as Ks}from"./info-CuyReqZo.js";import{C as $i,P as Pi,a as Bi,b as zi,c as Oi,d as Ui}from"./PopoverPopup-qAngi4Xc.js";import{A as wr}from"./index-pza5Zl32.js";import{L as Hi}from"./loader-circle-D2Erh-me.js";import{F as st}from"./FadeIn-9jciDZsH.js";import{C as Vi}from"./ClawdAnimated-B_T5A9tJ.js";import{u as Wi,a as Ki,P as Gi}from"./use-session-efficiency-pref-rHhQnzAS.js";import{L as Jr}from"./LoginCard-6lOxJlws.js";import{L as qi,A as Yi}from"./agent-logos-WXnblKNu.js";import{C as Zi}from"./check-DQswISeD.js";import"./terminal-CJMbTjNB.js";import"./limits-providers-FnlIwbBy.js";import"./useScrollLock-JHdC5cyV.js";import"./SelectItemText-DIsD6lWR.js";const Ji=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],Qi=Na("git-branch",Ji);const Xi=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],el=Na("laptop",Xi);const tl=[["path",{d:"M18 8V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h8",key:"10dyio"}],["path",{d:"M10 19v-3.96 3.15",key:"1irgej"}],["path",{d:"M7 19h5",key:"qswx4l"}],["rect",{width:"6",height:"10",x:"16",y:"12",rx:"2",key:"1egngj"}]],Gs=Na("monitor-smartphone",tl);const al=[["path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6",key:"y09zxi"}],["path",{d:"m21 3-9 9",key:"mpx6sq"}],["path",{d:"M15 3h6v6",key:"1q9fwt"}]],rl=Na("square-arrow-out-up-right",al);function sl(t,a,r={}){const s=t.get();let n=null,i=s,o;const u=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,c=()=>{n&&(n.stop(),n=null),t.animation=void 0},g=()=>{const x=Qr(t.get()),h=Qr(i);if(x===h){c();return}const f=n?n.getGeneratorVelocity():t.getVelocity();c(),n=new Ti({keyframes:[x,h],velocity:f,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},m=()=>{g(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((x,h)=>{i=x,o=f=>h(qa(f,u)),Ci.postRender(m)},c),Os(a)){let x=r.skipInitialAnimation===!0;const h=a.on("change",y=>{x?(x=!1,t.jump(qa(y,u),!1)):t.set(qa(y,u))}),f=t.on("destroy",h);return()=>{h(),f()}}return c}function qa(t,a){return a?t+a:t}function Qr(t){return typeof t=="number"?t:parseFloat(t)}function nl(t,a={}){const{isStatic:r}=d.useContext(Ai),s=()=>Os(t)?t.get():t;if(r)return Vs(s);const n=Ws(s());return d.useInsertionEffect(()=>sl(n,t,a),[n,JSON.stringify(a)]),n}function ol(t,a={}){return nl(t,{type:"spring",...a})}function il(){return e.jsxs(Lo,{to:"/landing",className:"flex items-center gap-2.5 no-underline hover:opacity-80 transition-opacity",children:[e.jsx("img",{src:"/app-icon.png",alt:"Token Tracker",width:28,height:28,className:"rounded-md"}),e.jsx("span",{className:"text-base font-semibold text-oai-black dark:text-oai-white leading-tight",children:"Token Tracker"})]})}function ll({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(il,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function cl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},u=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:u,children:t})}var dl={};function ul(t,a){return t==="."?{width:"0.34ch",justifyContent:"center",marginInline:"-0.04ch"}:t===","?{width:"0.08ch",justifyContent:"center",marginInline:"-0.30ch"}:{width:"0.72ch",justifyContent:"flex-start",paddingLeft:"0.04ch",height:a}}function ml({mv:t,digit:a,height:r}){const s=Vs(t,n=>{const i=(n%10+10)%10,o=(10+a-i)%10;let u=o*r;return o>5&&(u-=10*r),u});return e.jsx(Ne.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function hl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function gl(t,a){const r=t/a;return Math.floor(hl(r))}function xl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((u,c)=>/\d/.test(u)&&(s===-1||c<s)).length,i=0,o=!1;return r.map(u=>{if(!/\d/.test(u))return u==="."&&(o=!0),u;if(!o){const c=10**Math.max(n-1,0);return n-=1,c}return i+=1,10**-i})}function fl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const c=ul(t,r),g=t!=="."&&t!==",",m=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...c,...s,...g?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...m?{width:c.width}:null},children:t})}const i=gl(a,t),o=Ws(0),u=ol(o,{stiffness:220,damping:26,mass:.8});return d.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(c,g)=>e.jsx(ml,{mv:u,digit:g,height:r},g))})}function pl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:u=0,textColor:c="inherit",fontWeight:g="inherit",containerStyle:m,counterStyle:x,digitStyle:h,gradientHeight:f=14,gradientFrom:y="rgba(255,255,255,0.95)",gradientTo:w="rgba(255,255,255,0)",topGradientStyle:p,bottomGradientStyle:v}){const _=String(a??t??""),D=d.useMemo(()=>Array.isArray(n)&&n.length?n:xl(_),[n,_]),C=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&dl?.VITEST==="true",M=Hs()||C,L=Number.isFinite(Number(t))?Math.abs(Number(t)):0,B=r+s;return M?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:c,fontSize:r,fontWeight:g,lineHeight:1,...m,...x},children:_}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...m},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:u,paddingRight:u,lineHeight:1,color:c,fontWeight:g,...x},children:D.map((k,j)=>e.jsx(fl,{place:k,value:L,height:B,digitStyle:h,shouldReduceMotion:M},`${String(k)}-${j}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:p??{height:f,background:`linear-gradient(to bottom, ${y}, ${w})`}}),e.jsx("span",{style:v??{height:f,background:`linear-gradient(to top, ${y}, ${w})`}})]})]})}function yl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:u,now:c,accountView:g=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:h=!1,deviceId:f=null}={}){const y=!!(g&&m),w=y?"cloud":"local",p=d.useMemo(()=>Mo({weeks:s,weekStartsOn:n,now:c}),[c,s,n]),[v,_]=d.useState([]),[D,C]=d.useState(null),[M,L]=d.useState("edge"),[B,k]=d.useState(!1),[j,A]=d.useState(null),$=ut(),z=Wt(a),H=!r,E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),R=d.useMemo(()=>{if(!i)return null;const J=yr({timeZone:o,offsetMinutes:u});return`tokentracker.heatmap.${i}.${w}.${s}.${n}.${J}.${f||"all"}`},[i,f,w,o,u,s,n]),K=d.useCallback(()=>{if(!R||typeof window>"u")return null;try{const J=window.localStorage.getItem(R);if(!J)return null;const me=JSON.parse(J);return!me||!me.heatmap?null:me}catch{return null}},[R]),N=d.useCallback(J=>{if(!(!R||typeof window>"u"))try{window.localStorage.setItem(R,JSON.stringify(J))}catch{}},[R]),S=d.useCallback(()=>{if(!(!R||typeof window>"u"))try{window.localStorage.removeItem(R)}catch{}},[R]),q=d.useRef(w);d.useEffect(()=>{q.current!==w&&(q.current=w,_([]),C(null),L("edge"),A(null),k(!0))},[w]);const O=d.useCallback(async()=>{const J=await Fe(a),me=y?await Fe(m):null;if(!J&&!$&&!E&&!y)return;if(y&&!me){A("Your session expired. Please sign in again to view account data."),k(!1);return}const ie=y?me:J,xe=y?Eo:Ro,_e=y?Rs:Is;k(!0),A(null);try{try{const P=await xe({baseUrl:t,accessToken:ie,weeks:s,to:p.to,weekStartsOn:n,device:f,timeZone:o,tzOffsetMinutes:u}),te=Array.isArray(P?.weeks)?P.weeks:[];if(!te.length&&H){const U=K();if(U?.heatmap){C(U.heatmap),_(U.daily||[]),L("cache");return}}if(!te.some(U=>(Array.isArray(U)?U:[]).some(he=>he&&Number.isFinite(Number(he.level))))&&te.length){const U=[];for(const le of te)for(const G of Array.isArray(le)?le:[])G?.day&&U.push({day:G.day,total_tokens:G.total_tokens??G.value??0,billable_total_tokens:G.billable_total_tokens??G.value??G.total_tokens??0});const he=Ur({dailyRows:U,weeks:s,to:P?.to||p.to,weekStartsOn:n});_(U),C({...he,week_starts_on:n,active_days:U.filter(le=>Number(le?.billable_total_tokens??le?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:P?.to||p.to})}),L("client"),H?N({heatmap:{...he,week_starts_on:n,active_days:U.filter(le=>Number(le?.billable_total_tokens??le?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:P?.to||p.to})},daily:U,fetchedAt:new Date().toISOString()}):S();return}C(P||null),_([]),L("edge"),P&&H?N({heatmap:P,daily:[],fetchedAt:new Date().toISOString()}):H||S();return}catch(P){const te=P,ye=te?.status??te?.statusCode;if(ye===401||ye===403)throw P}const fe=await _e({baseUrl:t,accessToken:ie,from:p.from,to:p.to,device:f,timeZone:o,tzOffsetMinutes:u}),ae=Array.isArray(fe?.data)?fe.data:[];_(ae);const Q=Ur({dailyRows:ae,weeks:s,to:p.to,weekStartsOn:n});C({...Q,week_starts_on:n,active_days:ae.filter(P=>Number(P?.billable_total_tokens??P?.total_tokens)>0).length,streak_days:ha({dailyRows:ae,to:p.to})}),L("client"),H?N({heatmap:{...Q,week_starts_on:n,active_days:ae.filter(P=>Number(P?.billable_total_tokens??P?.total_tokens)>0).length,streak_days:ha({dailyRows:ae,to:p.to})},daily:ae,fetchedAt:new Date().toISOString()}):S()}catch(fe){if(H){const ae=K();if(ae?.heatmap)C(ae.heatmap),_(ae.daily||[]),L("cache"),A(null);else{const Q=fe;A(Q?.message||String(Q)),_([]),C(null),L("edge")}}else{const ae=fe;A(ae?.message||String(ae)),_([]),C(null),L("edge")}}finally{k(!1)}},[a,t,$,r,H,p.from,p.to,K,z,o,u,n,s,S,N,E,y,m,x,f]);return d.useEffect(()=>{if(h){k(!0);return}if(!z&&!r&&!$&&!E&&!y){_([]),k(!1),A(null),C(null),L("edge");return}if(!H)S(),_([]),A(null),C(null),L("edge");else{const J=K();J?.heatmap&&(C(J.heatmap),_(J.daily||[]),L("cache"))}O()},[a,$,K,O,z,r,H,S,E,h]),{range:p,daily:v,heatmap:D,source:$?"mock":M==="client"?"edge":M,loading:B,error:j,refresh:O}}const bl="tokentracker.dashboard.leftCardOrder.v1",kl="tokentracker.dashboard.rightCardOrder.v1";function wl(t,a){const r=Gr(bl,t),s=Gr(kl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=d.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const _l=10;function vl({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[u,c]=d.useState([]),[g,m]=d.useState(!1),[x,h]=d.useState(null),f=ut(),y=Wt(a),w=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),p=Kt([t,a,r,s,n,i,o]),v=d.useCallback(async()=>{const _=p(),D=await Fe(a);if(_()){if(!D&&!f&&!w){c([]),h(null),m(!1);return}m(!0),h(null);try{const C=await Io({baseUrl:t,accessToken:D,limit:_l,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!_())return;c(Array.isArray(C?.entries)?C.entries:[])}catch(C){if(!_())return;const M=C?.message||String(C);h(M),c([])}finally{_()&&m(!1)}}},[a,t,r,f,n,i,s,o,w,p]);return d.useEffect(()=>{if(!y&&!f&&!w){c([]),h(null),m(!1);return}c([]),h(null),m(!0),v()},[f,v,y,w]),{entries:u,loading:g,error:x,refresh:v}}const Xr="tokentracker.usage-cache-index",es=24;function ts({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:u,timeZone:c,tzOffsetMinutes:g,now:m,accountView:x=!1,accountAccessToken:h=null,accountRevision:f=0,accountViewResolving:y=!1,deviceId:w=null}={}){const p=!!(x&&h),v=p?"cloud":"local",[_,D]=d.useState([]),[C,M]=d.useState(null),[L,B]=d.useState(null),[k,j]=d.useState("edge"),[A,$]=d.useState(null),[z,H]=d.useState(!1),[E,R]=d.useState(null),K=ut(),N=Wt(a),S=!r&&!K,q=w||"all",O=(()=>{if(!u)return null;const Q=jl(t)||"default",P=i?o?"daily-summary":"daily-only":"summary",te=yr({timeZone:c,offsetMinutes:g});return`tokentracker.usage.${u}.${v}.${Q}.${s}.${n}.${P}.${te}.${q}`})(),ue=d.useRef(v);d.useEffect(()=>{ue.current!==v&&(ue.current=v,D([]),M(null),B(null),j("edge"),$(null),R(null),H(!0))},[v]);const J=d.useCallback(()=>{if(!O||typeof window>"u")return null;try{const Q=window.localStorage.getItem(O);if(!Q)return null;const P=JSON.parse(Q),te=o?!!P?.summary:Array.isArray(P?.daily);return!P||!te?null:(Yr(Xr,O,es),P)}catch{return null}},[o,O]),me=d.useCallback(Q=>{if(!(!O||typeof window>"u"))try{window.localStorage.setItem(O,JSON.stringify(Q)),Yr(Xr,O,es)}catch{}},[O]),ie=d.useCallback(()=>{if(!(!O||typeof window>"u"))try{window.localStorage.removeItem(O)}catch{}},[O]),xe=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),_e=Kt([t,s,n,i,o,v,a,h,f,w,c,g]),fe=d.useCallback(async()=>{const Q=_e(),P=await Fe(a),te=p?await Fe(h):null;if(!Q()||!P&&!K&&!xe&&!p)return;if(p&&!te){R("Your session expired. Please sign in again to view account data."),H(!1);return}const ye=p?Rs:Is,U=p?Fo:$o,he=p?te:P;H(!0),R(null);try{let le=null,G=null;if(i)if(o){const[ee,se]=await Promise.allSettled([ye({baseUrl:t,accessToken:he,from:s,to:n,device:w,timeZone:c,tzOffsetMinutes:g}),U({baseUrl:t,accessToken:he,from:s,to:n,device:w,timeZone:c,tzOffsetMinutes:g,rolling:!0})]);if(ee.status==="rejected")throw ee.reason;le=ee.value,G=se.status==="fulfilled"?se.value:null}else le=await ye({baseUrl:t,accessToken:he,from:s,to:n,device:w,timeZone:c,tzOffsetMinutes:g});else o&&(G=await U({baseUrl:t,accessToken:he,from:s,to:n,device:w,timeZone:c,tzOffsetMinutes:g,rolling:!0}));let Y=i&&Array.isArray(le?.data)?le.data:[];i&&(Y=Za(Y,s,n,{timeZone:c,offsetMinutes:g,now:m}));let T=o&&(G?.totals||le?.summary?.totals)||null,V=o&&(G?.rolling||le?.summary?.rolling)||null;if(o&&i&&!T&&!G)try{const ee=await U({baseUrl:t,accessToken:he,from:s,to:n,device:w,timeZone:c,tzOffsetMinutes:g,rolling:!0});T=ee?.totals||null,V=ee?.rolling||V}catch{}const X=new Date().toISOString();if(!Q())return;D(Y),M(T),B(V),j("edge"),$(X),(T||!o&&i)&&S?me({summary:T,rolling:V,daily:Y,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:X}):S||ie()}catch(le){if(!Q())return;if(S){const G=J();if(G?.summary||!o&&Array.isArray(G?.daily)){M(G.summary),B(G.rolling||null);const Y=Array.isArray(G.daily)?G.daily:[],T=i?Za(Y,G.from||s,G.to||n,{timeZone:c,offsetMinutes:g,now:m}):Y;D(T),j("cache"),$(G.fetchedAt||null),R(null)}else{const Y=le;R(Y?.message||String(Y)),D([]),M(null),B(null),j("edge"),$(null)}}else{const G=le;R(G?.message||String(G)),D([]),M(null),B(null),j("edge"),$(null)}}finally{Q()&&H(!1)}},[a,t,s,i,o,K,r,S,m,J,N,c,n,g,ie,me,xe,p,h,f,w,_e]);return d.useEffect(()=>{if(y){H(!0);return}const Q=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!N&&!r&&!K&&!Q&&!p){D([]),M(null),B(null),R(null),H(!1),j("edge"),$(null);return}if(!S)ie(),D([]),M(null),B(null),R(null),j("edge"),$(null);else{const P=J();if(P?.summary||!o&&Array.isArray(P?.daily)){M(P.summary),B(P.rolling||null);const te=Array.isArray(P.daily)?P.daily:[],ye=i?Za(te,P.from||s,P.to||n,{timeZone:c,offsetMinutes:g,now:m}):te;D(ye),j("cache"),$(P.fetchedAt||null),R(null)}else D([]),M(null),B(null),j("edge"),$(null),R(null)}H(!0),fe()},[a,K,J,fe,N,r,S,ie,xe,y,o]),d.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const Q=15e3;let P=Date.now();const te=()=>{if(document.visibilityState!=="visible")return;const ye=Date.now();ye-P<Q||(P=ye,fe())};return window.addEventListener("focus",te),document.addEventListener("visibilitychange",te),()=>{window.removeEventListener("focus",te),document.removeEventListener("visibilitychange",te)}},[fe]),{daily:_,summary:C,rolling:L,source:K?"mock":k,fetchedAt:A,loading:z,error:E,refresh:fe}}function jl(t){try{return new URL(t).host}catch{return null}}function Ya(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Ut(o)===a?o:null}function Nl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Za(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=Ya(a),u=Ya(r);if(!o||!u||u<o)return Array.isArray(t)?t:[];const c=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,g=br({timeZone:s,offsetMinutes:n,date:c}),m=Ya(g),x=m?m.getTime():c.getTime(),h=new Map;for(const y of t||[])y?.day&&h.set(y.day,y);const f=[];for(let y=o;y<=u;y=Nl(y,1)){const w=Ut(y),p=h.get(w),v=y.getTime()>x;if(p){f.push({...p,missing:!1,future:v});continue}f.push({day:w,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!v,future:v})}return f}function Sl({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:u,accountView:c=!1,accountAccessToken:g=null,accountRevision:m=0,accountViewResolving:x=!1,deviceId:h=null}={}){const f=!!(c&&g),y=f?"cloud":"local",[w,p]=d.useState(null),[v,_]=d.useState("edge"),[D,C]=d.useState(!1),[M,L]=d.useState(null),B=ut(),k=Wt(a),j=!r,A=d.useMemo(()=>{if(!i)return null;const q=Cl(t)||"default",O=yr({timeZone:o,offsetMinutes:u});return`tokentracker.modelBreakdown.${i}.${y}.${q}.${s}.${n}.${O}.${h||"all"}`},[t,i,h,s,y,o,n,u]),$=d.useCallback(()=>{if(!A||typeof window>"u")return null;try{const q=window.localStorage.getItem(A);if(!q)return null;const O=JSON.parse(q);return!O||!O.breakdown?null:O}catch{return null}},[A]),z=d.useCallback(q=>{if(!(!A||typeof window>"u"))try{window.localStorage.setItem(A,JSON.stringify(q))}catch{}},[A]),H=d.useCallback(()=>{if(!(!A||typeof window>"u"))try{window.localStorage.removeItem(A)}catch{}},[A]),E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),R=Kt([t,s,n,y,a,g,m,h,o,u]),K=d.useRef(y);d.useEffect(()=>{K.current!==y&&(K.current=y,p(null),_("edge"),L(null),C(!0))},[y]);const N=d.useCallback(async()=>{const q=R(),O=await Fe(a),ue=f?await Fe(g):null;if(!q()||!O&&!B&&!E&&!f)return;if(f&&!ue){L("Your session expired. Please sign in again to view account data."),C(!1);return}const J=f?ue:O,me=f?Po:Bo;C(!0),L(null);try{const ie=await me({baseUrl:t,accessToken:J,from:s,to:n,device:h,timeZone:o,tzOffsetMinutes:u});if(!q())return;p(ie||null),_("edge"),ie&&j?z({breakdown:ie,fetchedAt:new Date().toISOString()}):j||H()}catch(ie){if(!q())return;if(j){const xe=$();if(xe?.breakdown)p(xe.breakdown),_("cache"),L(null);else{p(null),_("edge");const _e=ie;L(_e?.message||String(_e))}}else{p(null),_("edge");const xe=ie;L(xe?.message||String(xe))}}finally{q()&&C(!1)}},[a,t,s,B,r,j,$,o,n,k,u,H,z,E,f,g,m,h,R]);return d.useEffect(()=>{if(x){C(!0);return}if(!k&&!r&&!B&&!E&&!f){p(null),_("edge"),L(null),C(!1);return}if(!j)H(),p(null),_("edge"),L(null);else{const q=$();q?.breakdown?(p(q.breakdown),_("cache"),L(null)):(p(null),_("edge"),L(null))}C(!0),N()},[a,B,$,N,k,r,j,H,E,x]),{breakdown:w,source:B?"mock":v,loading:D,error:M,refresh:N}}function Cl(t){try{return new URL(t).host}catch{return null}}const qs=new Set(["day","hour","month"]);function Tl(t){return qs.has(t)}function as(t){if(t==null)return null;const a=String(t).trim();if(!/^[0-9]+$/.test(a))return null;const r=a.replace(/^0+/,"");return r.length===0?"0":r}function Al(t,a){const r=as(t),s=as(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=re(t),i=re(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function Dl(t,a){const r=typeof t=="string"?t:String(t||""),s=typeof a=="string"?a:String(a||"");return r===s?0:r<s?-1:1}function Ll(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function Ml(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function El(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),u=Number(r[5]),c=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(u)||!Number.isFinite(c)||n<1||n>12||i<1||i>31||o<0||o>23||u<0||u>59||c<0||c>59)return null;const g=new Date(Date.UTC(s,n-1,i,o,u,c));return Number.isFinite(g.getTime())?g.getTime():null}function Rl(t,a,r){const s=r==="hour"?El:r==="month"?Ml:Ll,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:Dl(t,a)}function Ys(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=qs.has(a)?(u,c)=>Rl(u,c,a):Al,o=u=>a==="total_tokens"&&u?.billable_total_tokens!=null?u.billable_total_tokens:u?.[a];return n.map((u,c)=>({row:u,index:c})).sort((u,c)=>{const g=o(u.row),m=o(c.row),x=g==null,h=m==null;if(x&&h)return u.index-c.index;if(x)return 1;if(h)return-1;const f=i(g,m);return f!==0?f*s:u.index-c.index}).map(u=>u.row)}function Il(){return[{key:"day",label:l("daily.sort.date.label"),title:l("daily.sort.date.title")},{key:"total_tokens",label:l("daily.sort.total.label"),title:l("daily.sort.total.title")},{key:"input_tokens",label:l("daily.sort.input.label"),title:l("daily.sort.input.title")},{key:"output_tokens",label:l("daily.sort.output.label"),title:l("daily.sort.output.title")},{key:"cached_input_tokens",label:l("daily.sort.cached.label"),title:l("daily.sort.cached.title")},{key:"reasoning_output_tokens",label:l("daily.sort.reasoning.label"),title:l("daily.sort.reasoning.title")},{key:"conversation_count",label:l("daily.sort.conversations.label"),title:l("daily.sort.conversations.title")}]}function rs(t){const a=Tl(t)?t:"day";return Il().map((r,s)=>s===0?{...r,key:a}:r)}function ss(t,{key:a,dir:r}){return Ys(t,{key:a,dir:r})}const va=12,Fl=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function $l(t){if(typeof t=="bigint")return t!==0n;if(typeof t=="number")return Number.isFinite(t)&&t!==0;if(t==null)return!1;const a=String(t).trim();if(!a||!/^-?\d+$/.test(a))return!1;const r=a.startsWith("-")?a.slice(1):a;return/[1-9]/.test(r)}function Pl(t){return Fl.some(a=>$l(t?.[a]))}function Bl(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=Ys(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&Pl(n));return s===-1?a:r.slice(s)}function zl(t,a,r=va){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:va,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function Ol({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const ga=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function Ul({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ga.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ga.active:s<=60*6e4?ga.warm:ga.idle}const Hl=3e4;function Vl({refresh:t,intervalMs:a=Hl,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,u=Date.now(),c=0;const g=()=>{if(i||s.visibilityState!=="visible"||o)return o;const f=Promise.resolve().then(()=>t()).catch(y=>n(y)).then(()=>{}).finally(()=>{o===f&&(o=null)});return o=f,f},m=r.setInterval(()=>{const f=Date.now();f<c||(c=f+Ul({visible:s.visibilityState==="visible",lastInteractionAt:u,now:f}),g())},a),x=()=>{s.visibilityState==="visible"&&(u=Date.now(),c=0,g())},h=()=>{u=Date.now()};return r.addEventListener("focus",x),r.addEventListener("pointerdown",h),r.addEventListener("keydown",h),s.addEventListener("visibilitychange",x),{run:g,stop(){i=!0,r.clearInterval(m),r.removeEventListener("focus",x),r.removeEventListener("pointerdown",h),r.removeEventListener("keydown",h),s.removeEventListener("visibilitychange",x)}}}function Wl(t){if(!t)return null;const a=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!a)return null;const r=new Date(Date.UTC(Number(a[1]),Number(a[2])-1,Number(a[3])));return Ut(r)===t?r:null}function Kl({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=Wl(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Ut(i),to:Ut(n)}}function Gl(t,{period:a}={}){const r=(Array.isArray(t)?t:[]).filter(n=>!n?.future&&n?.day);return(a==="total"?r.filter(n=>!n?.missing):r).slice(-30)}function _r(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function ql(t){const a=_r(t?.model_id);return a||null}function Zs(t,a){return t?.model?String(t.model):a}function St(t,a=0){const r=re(t?.billable_total_tokens),s=re(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}function Yl(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const u=St(o?.totals),c=re(o?.totals?.total_cost_usd)??0;return{source:o?.source,totalTokens:Number.isFinite(u)?u:0,totalCost:Number.isFinite(c)?c:0,inputTokens:Math.max(0,re(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,re(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,re(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0);if(!n.length)return[];const i=n.reduce((o,u)=>o+u.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,u)=>u.totalTokens-o.totalTokens).map(o=>{const u=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),c=i>0?o.totalTokens/i*100:0,g=Number.isFinite(c)?c.toFixed(2):"0.00",m=o.models.map(y=>{const w=St(y?.totals);if(!Number.isFinite(w)||w<=0)return null;const p=o.totalTokens>0?Math.round(w/o.totalTokens*1e3)/10:0,v=Zs(y,r("shared.placeholder.short")),_=ql(y),D=re(y?.totals?.total_cost_usd),C=D??(o.totalCost>0&&o.totalTokens>0?w/o.totalTokens*o.totalCost:null);return{id:_,name:v,share:p,usage:w,cost:C}}).filter(Boolean),x=o.inputTokens+o.cacheRead+o.cacheCreate,f=o.cacheRead+o.cacheCreate>0&&x>0?Math.round(o.cacheRead/x*100):null;return{source:o.source,label:u,totalPercent:String(g),totalPercentValue:c,usd:o.totalCost,usage:o.totalTokens,cacheHitRate:f,cacheReusedTokens:o.cacheRead,cacheInputTokens:x,models:m}})}function Zl(t){const a=Array.isArray(t)?t:[],r=new Map;for(const n of a){const i=Array.isArray(n?.models)?n.models:[];for(const o of i){const u=re(o?.usage);if(u==null||u<=0)continue;const c=typeof o?.name=="string"&&o.name.trim()?o.name.trim():typeof o?.id=="string"&&o.id.trim()?o.id.trim():null,g=_r(c);if(!g)continue;const m=r.get(g)||{id:g,name:c,usage:0,cost:0,hasCost:!1,nameWeight:0};m.usage+=u;const x=re(o?.cost);x!=null&&(m.cost+=x,m.hasCost=!0),u>=m.nameWeight&&(m.name=c,m.nameWeight=u),r.set(g,m)}}const s=Array.from(r.values()).reduce((n,i)=>n+i.usage,0);return Array.from(r.values()).map(n=>({id:n.id,name:n.name,usage:n.usage,cost:n.hasCost?n.cost:null,share:s>0?Math.round(n.usage/s*1e3)/10:0})).sort((n,i)=>i.usage!==n.usage?i.usage-n.usage:String(n.name).localeCompare(String(i.name)))}function Jl(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:h=>h,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const i=new Map,o=new Map,u=new Map;let c=0;for(const h of n){const f=Array.isArray(h?.models)?h.models:[];for(const y of f){const w=St(y?.totals);if(!Number.isFinite(w)||w<=0)continue;c+=w;const p=Zs(y,s("shared.placeholder.short")),v=_r(p);if(!v)continue;i.set(v,(i.get(v)||0)+w);const _=u.get(v)||0;w>=_&&(u.set(v,w),o.set(v,p))}}if(!i.size)return[];const g=Array.from(i.values()).reduce((h,f)=>h+f,0),m=c>0?c:g,x=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([h,f])=>{const y=m>0?(f/m*100).toFixed(1):"0.0";return{id:h,name:o.get(h)||s("shared.placeholder.short"),tokens:f,percent:String(y)}}).sort((h,f)=>f.tokens!==h.tokens?f.tokens-h.tokens:String(h.name).localeCompare(String(f.name))).slice(0,x)}function Ql(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Sa(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function ns(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Ht(a);return(a===Fs?t:t*r)<.01?`<${s}0.01`:Sa(t,{decimals:2,currency:a,rate:r})}function os(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Je(a,{decimals:1})}const Xl=vt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=Ca(),o=d.useMemo(()=>(Array.isArray(s)?s:[]).map(c=>{const g=re(c?.usd)??0,m=re(c?.usage)??0,x=Array.isArray(c?.models)?c.models:[];return{label:c?.label?String(c.label):"",usdValue:g,costLabel:ns(g,n,i),tokensLabel:os(m),models:x.map(h=>{const f=re(h?.usage)??0,y=re(h?.cost)??0;return{id:h?.id?String(h.id):"",name:h?.name?String(h.name):"",tokensLabel:os(f),costLabel:ns(y,n,i),sortCost:y}}).filter(h=>h.costLabel||h.tokensLabel).sort((h,f)=>f.sortCost-h.sortCost)}}).filter(c=>c.usdValue>0||c.models.length>0).sort((c,g)=>g.usdValue-c.usdValue),[s,n,i]),u=d.useMemo(()=>{const c=o.reduce((g,m)=>g+m.usdValue,0);return Ql(c,n,i)},[o,n,i]);return e.jsx(Di,{open:a,onOpenChange:c=>{c||r?.()},children:e.jsxs(Li,{children:[e.jsx(Mi,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(Ei,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(Ri,{className:"cost-modal-popup relative w-full max-w-[460px] max-h-[calc(100vh-2rem)] flex flex-col rounded-2xl bg-white dark:bg-oai-gray-950 shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)] ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden",children:[e.jsx(Ii,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(Fi,{type:"button",className:"absolute top-3 right-3 flex h-9 w-9 items-center justify-center rounded-md text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-100 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50 transition-colors z-10","aria-label":l("dashboard.cost_breakdown.close"),children:e.jsx(kr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:u}),o.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:"No spend recorded."}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:"Model"}),e.jsx("span",{role:"columnheader",children:"Cost"})]}),o.map((c,g)=>{const m=`fleet-${g}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":m,className:g>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:m,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:c.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:c.costLabel||"—"})]}),c.models.map((x,h)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsx("span",{role:"cell",className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400 truncate leading-none",title:x.name,children:x.name}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:x.costLabel||""})]},x.id||`${x.name}-${h}`))]},`${c.label}-${g}`)})]})]})})]})})]})})});function ec({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[g,m]=d.useState(null),x=ut();return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}let h=!0;return c(!0),m(null),zo({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{h&&o(f||null)}).catch(f=>{h&&(m(f?.message||String(f)),o(null))}).finally(()=>{h&&c(!1)}),()=>{h=!1}},[t,a,r,s,n,x]),{data:i,loading:u,error:g}}function Js(t){if(typeof t!="string"||!t)return{owner:"",repo:""};const a=t.indexOf("/");return a<0?{owner:"",repo:t}:{owner:t.slice(0,a),repo:t.slice(a+1)}}function Qs(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function Xs(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function en(t,a){return a&&Xs(Qs(t))==="github"?a:""}function tn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=d.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const is="#10b981",Ja=[{key:"input_tokens",labelKey:"dashboard.projects.detail.comp_input",color:"#38bdf8"},{key:"cached_input_tokens",labelKey:"dashboard.projects.detail.comp_cached",color:"#14b8a6"},{key:"cache_creation_input_tokens",labelKey:"dashboard.projects.detail.comp_cache_write",color:"#f59e0b"},{key:"output_tokens",labelKey:"dashboard.projects.detail.comp_output",color:"#a78bfa"},{key:"reasoning_output_tokens",labelKey:"dashboard.projects.detail.comp_reasoning",color:"#fb7185"}],Qa=60;function tc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(h=>[h.day,h]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const u=t[t.length-1].day;o<u&&(o=u);const c=new Date(`${i}T00:00:00Z`),g=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(c.getTime())||!Number.isFinite(g.getTime()))return t;const m=Math.round((g.getTime()-c.getTime())/864e5)+1;m>Qa&&c.setUTCDate(c.getUTCDate()+(m-Qa));const x=[];for(;c.getTime()<=g.getTime()&&x.length<Qa;){const h=c.toISOString().slice(0,10);x.push(n.get(h)||{day:h,total_tokens:0,billable_total_tokens:0}),c.setUTCDate(c.getUTCDate()+1)}return x}function Xa(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function _t({label:t,value:a,title:r}){return e.jsxs("div",{className:"flex flex-col gap-1.5 group min-w-0",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:t}),e.jsx("span",{className:"text-xl font-black font-mono text-zinc-900 dark:text-zinc-50 tracking-tight leading-none tabular-nums truncate transition-transform duration-200 group-hover:-translate-y-[1px]",title:r,children:a})]})}function ac({host:t}){if(!t)return null;let a;const r=Xs(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(Qi,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function er({children:t}){return e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500 select-none",children:t})}function rc({entry:t,query:a={},onClose:r}){const[s,n]=vt.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:u}=Js(i),c=typeof t?.project_ref=="string"?t.project_ref:"",g=Qs(c),{data:m,loading:x,error:h}=ec({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:f,formatTokensTooltip:y}=Me(),w=vt.useCallback(()=>n(!0),[]),p=E=>{E.target===E.currentTarget&&s&&r()};vt.useEffect(()=>{const E=R=>{R.key==="Escape"&&w()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[w]);const v=m?.totals||null,_=re(v?.billable_total_tokens)??0,D=Number(m?.days_active||0),C=re(v?.input_tokens)??0,M=re(v?.cached_input_tokens)??0,L=C+M>0?M/(C+M):null,B=re(m?.range_total_tokens)??0,k=re(v?.total_tokens)??0,j=B>0?k/B:null,A=vt.useMemo(()=>tc(m?.daily,m?.from,m?.to,br({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[m,a.timeZone,a.tzOffsetMinutes]),$=Ja.reduce((E,R)=>E+(re(v?.[R.key])??0),0),z=Array.isArray(m?.sources)?m.sources:[],H=!x&&!h&&v&&k>0;return e.jsx("div",{onAnimationEnd:p,onClick:E=>{E.target===E.currentTarget&&w()},className:Nt("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i,className:Nt("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:w,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(kr,{size:16})}),e.jsxs("div",{className:"w-full md:w-[300px] shrink-0 border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-5 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:is}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:is}})]}),e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:l("dashboard.projects.detail.badge")})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3 min-w-0",children:[e.jsx(tn,{githubOwner:en(c,o),letter:(u?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:u||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(ac,{host:g}),g&&m?.from&&m?.to?e.jsx("span",{children:"·"}):null,m?.from&&m?.to?e.jsxs("span",{className:"tabular-nums",children:[m.from," – ",m.to]}):null]})]}),H?e.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-t border-zinc-200/50 dark:border-zinc-800/50 pt-5 select-none",children:[e.jsx(_t,{label:l("dashboard.projects.detail.stat_total"),value:f(_),title:y(_)}),e.jsx(_t,{label:l("dashboard.projects.detail.stat_share"),value:j==null?"—":Xa(j)}),e.jsx(_t,{label:l("dashboard.projects.detail.stat_cache_hit"),value:L==null?"—":Xa(L)}),e.jsx(_t,{label:l("dashboard.projects.detail.stat_conversations"),value:_a(v.conversation_count)}),e.jsx(_t,{label:l("dashboard.projects.detail.stat_active_days"),value:_a(D)}),e.jsx(_t,{label:l("dashboard.projects.detail.stat_avg_day"),value:D>0?f(Math.round(_/D)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[x&&e.jsxs("div",{className:"space-y-4 p-5 md:p-6",children:[e.jsx("div",{className:"h-32 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-24 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"})]}),!x&&h&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!x&&!h&&!H&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.empty_range")}),H&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[A.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(er,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(zs,{embedded:!0,rows:A,from:A[0]?.day,to:A[A.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),$>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(er,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:Ja.map(E=>{const R=re(v[E.key])??0;return R<=0?null:e.jsx("div",{style:{width:`${R/$*100}%`,backgroundColor:E.color,minWidth:"2px"}},E.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:Ja.map(E=>{const R=re(v[E.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:E.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(E.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(R),children:f(R)})]},E.key)})})]}),z.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(er,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:z.map(E=>{const R=Number(E.total_tokens||0),K=k>0?R/k:0,N=K*100,S=Number(E.conversation_count||0),q=wi(E.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Ct,{provider:E.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:jt(E.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(E.days_active||0)}),S>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:S})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(R),children:f(R)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:Xa(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(N,R>0?1:0))}%`,minWidth:R>0?"3px":0,backgroundColor:q}})})]},E.source)})})]})]})]})]})})}const sc=5;function nc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",u=typeof t?.project_ref=="string"?t.project_ref:"",{owner:c,repo:g}=Js(o),m=en(u,c),x=re(t?.billable_total_tokens??t?.total_tokens)??0,h=a>0?Math.min(100,Math.max(2,x/a*100)):0,f=Array.isArray(t?.sources)?t.sources:[],y=f.slice(0,sc),w=f.length-y.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(tn,{githubOwner:m,letter:(g?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[c?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[c,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:g||o||"—"})]}),y.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[y.map(p=>e.jsx(Ct,{provider:p.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},p.source)),w>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:w})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(x),children:s(x)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${h}%`,minWidth:x>0?"3px":0}})})]})]})}function oc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:u,dailyEmptySuffix:c,detailsColumns:g,ariaSortFor:m,toggleSort:x,sortIconFor:h,pagedDetails:f,dailyBreakdownRows:y=[],dailyBreakdownColumns:w=[],dailyBreakdownAriaSortFor:p,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:_="day",detailsDateKey:D,renderDetailDate:C,renderDailyBreakdownDate:M,renderDetailCell:L,DETAILS_PAGED_PERIODS:B,period:k,detailsPageCount:j,detailsPage:A,setDetailsPage:$}){const[z,H]=d.useState("daily"),[E,R]=d.useState(null),{formatTokens:K,formatTokensTooltip:N}=Me();return e.jsxs(Ce,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${z==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":z==="daily",type:"button",onClick:()=>H("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":z==="projects",type:"button",onClick:()=>H("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),z==="projects"&&e.jsx(Us,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:S=>r?.(Number(S)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),z==="projects"&&(()=>{const S=t.slice(0,a);if(S.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const q=S.reduce((O,ue)=>{const J=re(ue?.billable_total_tokens??ue?.total_tokens)??0;return J>O?J:O},0);return e.jsx("div",{className:"space-y-1",children:S.map((O,ue)=>e.jsx(nc,{entry:O,maxTokens:q,copy:n,formatTokens:K,formatTokensTooltip:N,onSelect:R},O?.project_key||O?.project_ref||`entry-${ue}`))})})(),E&&e.jsx(rc,{entry:E,query:s,onClose:()=>R(null)}),z==="daily"&&e.jsxs("div",{children:[y?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:u}),c]}):e.jsx("div",{className:"overflow-auto max-h-[384px] -mx-4 oai-scrollbar",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsx("tr",{className:"border-b border-oai-gray-200 dark:border-oai-gray-700",children:w.map(S=>e.jsx("th",{"aria-sort":p?.(S.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>x(S.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:S.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(S.key)||""})]})})},S.key))})}),e.jsx("tbody",{children:y.map(S=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${S.missing?"text-oai-gray-400 dark:text-oai-gray-400":S.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:M?M(S):C(S)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:L(S,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(S,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(S,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(S,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(S,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(S,"conversation_count")})]},String(S?.[_]||S?.day||S?.hour||S?.month||"")))})]})}),z!=="daily"&&B.has(k)&&j>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>$(S=>Math.max(0,S-1)),disabled:A===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[A+1," / ",j]}),e.jsx("button",{type:"button",onClick:()=>$(S=>Math.min(j-1,S+1)),disabled:A+1>=j,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function wa(t){return typeof t!="string"?"":t.trim()}function ls(t){const a=wa(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function ic(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=wa(r.tool),n=wa(r.planType)||wa(r.plan_type);if(!s||!n)continue;const i=ls(s)||s,o=ls(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function lc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:u}=Me(),c=l("shared.placeholder.short"),g=l("shared.unit.percent"),m=t??l("identity_card.rank_placeholder"),x=Number.isFinite(Number(a))?Number(a):0,h=x?l("identity_card.streak_value",{days:x}):l("identity_card.rank_placeholder"),f=ic(r),y={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev")},w=_=>{if(_==null)return c;const D=Je(_,y);return D==="-"?c:D},p={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=i.slice(0,3);return e.jsxs(Ce,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:w(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:p.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:w(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:p.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:w(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:p.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:w(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:p.convs})]})]}),v.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:v.map((_,D)=>{const C=_?.name?String(_.name):c,M=_?.percent?String(_.percent):"",L=D===v.length-1,B=D+1;return e.jsxs("div",{className:`flex items-center py-2 ${L?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:B}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:C,children:C}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[M,g]})]},_.id||C)})}),f.length>0&&e.jsx("div",{className:"mt-3 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex flex-wrap gap-1.5",children:f.map((_,D)=>e.jsxs(cl,{variant:"secondary",size:"sm",children:[_.tool," ",_.plan]},`${_.tool}:${_.plan}:${D}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:h})]})]})]})}let xa=null;function cc(){if(xa===null)try{xa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{xa=!1}return xa}function dc(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,u=t-.1055613458*n-.0638541728*i,c=t-.0894841775*n-1.291485548*i,g=o*o*o,m=u*u*u,x=c*c*c;return[4.0767416621*g-3.3077115913*m+.2309699292*x,-1.2684380046*g+2.6097574011*m-.3413193965*x,-.0041960863*g-.7034186147*m+1.707614701*x].map(f=>{const y=Math.min(1,Math.max(0,f)),w=y<=.0031308?12.92*y:1.055*Math.pow(y,1/2.4)-.055;return Math.round(w*255)})}function an(t,a,r,s){if(cc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=dc(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?an(Number(a[1]),Number(a[2]),Number(a[3])):t}const cs={claude:35,codex:250},ds={system_prompt:{l:.55,c:.05},messages:{l:.65,c:.18},tool_calls:{l:.6,c:.14},custom_agents:{l:.55,c:.1},reasoning:{l:.7,c:.08}};function uc(t,a){const r=cs[a]??cs.claude,s=ds[t]||ds.system_prompt;return an(s.l,s.c,r)}const mc=[{key:"system_prompt",from:["system_prefix"]},{key:"messages",from:["user_input","conversation_history","assistant_response"]},{key:"tool_calls",from:["tool_calls"]},{key:"custom_agents",from:["subagents"]},{key:"reasoning",from:["reasoning"]}],hc=[["by_type","dashboard.context_breakdown.exec_details.group_by_type"],["by_executable","dashboard.context_breakdown.exec_details.group_by_executable"],["by_command","dashboard.context_breakdown.exec_details.group_by_command"],["by_duration","dashboard.context_breakdown.exec_details.group_by_duration"],["by_output","dashboard.context_breakdown.exec_details.group_by_output"],["by_exit","dashboard.context_breakdown.exec_details.group_by_exit"]],gc={duration:.18,ease:[.4,0,.2,1]},xc={height:0,opacity:0},fc={height:"auto",opacity:1},pc={height:0,opacity:0};function yc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function bc(t,a){const r={};for(const s of["input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens","total_tokens"])r[s]=Math.round(Number(t?.[s]||0)*a);return r}function rn(t,a=null){const r=t.reduce((o,u)=>o+Number(u.totals.total_tokens||0),0),s=yc(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const u=i===1?o.totals:bc(o.totals,i);return{...o,totals:u,percent:n>0?Number((u.total_tokens/n*100).toFixed(2)):0}}).sort((o,u)=>u.totals.total_tokens-o.totals.total_tokens)}function kc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=mc.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const u=r.get(o);if(!u)continue;const c=u.totals||{};i.input_tokens+=c.input_tokens||0,i.cached_input_tokens+=c.cached_input_tokens||0,i.cache_creation_input_tokens+=c.cache_creation_input_tokens||0,i.output_tokens+=c.output_tokens||0,i.reasoning_output_tokens+=c.reasoning_output_tokens||0,i.total_tokens+=c.total_tokens||0}return{key:n.key,totals:i}});return rn(s,a)}function wc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((g,m)=>m?.name==="Text Response"?g:g+Number(m?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),c=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return rn(c,a)}const us="MCP: ";function _c(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(us)?(a.push({...n,name:i.slice(us.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function ms(t){return l(`dashboard.context_breakdown.category.${t}`)}function vc(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function jc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),u=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:vc(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(u||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function Nc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),u=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:u,total_tokens:Number(r.total_tokens||n+i)},tools:jc(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Sc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Cc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{};return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),total_tokens:Number(r.total_tokens||0)}}).filter(a=>a.name).sort((a,r)=>Number(r.total_tokens||0)-Number(a.total_tokens||0))}function Tc(t){if(t?.key){const a=l(`dashboard.context_breakdown.message_details.${t.key}`);if(a&&!a.includes("dashboard.context_breakdown"))return a}return t?.name||""}function Ac(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function hs(t){const a=Number(t||0);return!Number.isFinite(a)||a<=0?"0ms":a<1e3?`${Math.round(a)}ms`:a<6e4?`${(a/1e3).toFixed(1)}s`:`${Math.round(a/1e3)}s`}function Dc(t,a){return t?a==="by_executable"?t.by_executable||[]:a==="by_command"?t.by_command||[]:a==="by_duration"?t.by_duration||[]:a==="by_output"?t.by_output||[]:a==="by_exit"?t.by_exit||[]:t.by_type||[]:[]}function gs(t){return t==="exec_command"||t==="Bash"}function sn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":"dashboard.context_breakdown.empty"}function Lc(t){return t==="codex"?"dashboard.context_breakdown.error_codex":"dashboard.context_breakdown.error"}function Mc(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":"dashboard.context_breakdown.footnote"}const Ec=10;function Ze({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:u,tokens:c,percent:g=null,children:m,share:x=null,fillColor:h=null}){const f=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",y=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:Ec},"aria-hidden":!a,children:a}),w=e.jsxs(e.Fragment,{children:[y,e.jsx("span",{className:f,children:r}),s,i&&e.jsx(Ne.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx($i,{size:11})})]}),p=h&&x!=null&&x>0,v=p?Math.max(0,Math.min(100,x)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:p?{backgroundImage:`linear-gradient(to right, ${h.replace(/\)\s*$/," / 0.10)")} 0%, ${h.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:u,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:w}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:w}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:c||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:g||""})]}),i&&m?e.jsx(wr,{initial:!1,children:o&&e.jsx(Ne.div,{initial:xc,animate:fc,exit:pc,transition:gc,style:{overflow:"hidden"},children:m},"content")}):null]})}function xs({execDetails:t,source:a="claude"}){const{formatTokens:r}=Me(),[s,n]=d.useState("by_type"),i=Ac(Dc(t,s)),o=a==="codex",u=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:hc.map(([c,g])=>e.jsx("button",{type:"button",onClick:()=>n(c),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===c?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(g)},c))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${u} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((c,g)=>e.jsxs(Ne.div,{role:"row",className:`grid ${u} gap-2 py-1.5`,title:c.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:g*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:c.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Je(c.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Je(c.failures||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:hs(c.duration_ms||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:hs(c.max_duration_ms||0)})]}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:r(c.totals.total_tokens||0)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Je(c.output_lines||0)})]},c.name))]})})]})}function zt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Me(),[i,o]=d.useState({}),[u,c]=d.useState(!1),g=Nc(t?.categories||[]);function m(x){o(h=>({...h,[x]:!h[x]}))}return g.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(sn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:g.map(x=>{const h=x.toolCount>0,f=x.name==="Execution"&&a,y=f&&x.tools.some(p=>gs(p.name)),w=!!i[x.name];return e.jsxs(Ze,{level:1,label:x.name,labelTone:"strong",hasChevron:h||f&&!y,open:w||f&&!y&&u,onToggle:()=>{h?m(x.name):f&&!y&&c(p=>!p)},tokens:n(x.totals.total_tokens||0),percent:null,children:[h&&e.jsx("ul",{className:"space-y-0.5",children:x.tools.map(p=>{const v=f&&gs(p.name);return e.jsx(Ze,{level:2,label:p.name,labelTone:v?"accent":"default",hasChevron:v,open:u,onToggle:()=>c(_=>!_),tokens:n(p.total_tokens||0),percent:null,children:v&&e.jsx(xs,{execDetails:a,source:r})},p.name)})}),f&&!y&&e.jsx(xs,{execDetails:a,source:r})]},x.name)})})}function Rc({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:i}=Me(),[o,u]=d.useState(null),[c,g]=d.useState(!1),[m,x]=d.useState(null),[h,f]=d.useState({});function y(N){f(S=>({...S,[N]:!S[N]}))}if(d.useEffect(()=>{let N=!1;return g(!0),n?.(!0),x(null),Oo({from:t,to:a,source:r,timeZone:Ps(),tzOffsetMinutes:$s()}).then(S=>{N||u(S)}).catch(S=>{N||x(S?.message||String(S))}).finally(()=>{N||(g(!1),n?.(!1))}),()=>{N=!0}},[t,a,r]),c&&!o)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(N=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${N*80}ms`}},N))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(m)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(Lc(r))});if(!o||o.scope!=="supported"||!o.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(sn(r))});const w=r==="claude"?kc(o.categories||[],s):wc(o,s),p=o.tool_calls_breakdown||null,v=o.skills_breakdown||null,_=o.message_breakdown||null,D=o.configured_resources||null,C=o.exec_command_breakdown||null,M=Cc(v?.skills||[]),L=Sc(_?.categories||[]),B=r==="codex"&&(o?.breakdown_status==="queue_fallback"||o?.fallback==="queue_totals"),k=r==="claude"?p?.tool_calls||null:p||null,{mcpSet:j,residualSet:A,mcpTotalTokens:$}=_c(k),z=r==="claude"&&p?.subagents||null,H=z?.categories?.length>0||(D?.custom_agents_count||0)>0,E=r==="claude"?(A?.categories||[]).reduce((N,S)=>N+Number(S?.totals?.total_tokens||0),0):0,R=r==="claude"?(z?.categories||[]).reduce((N,S)=>N+Number(S?.totals?.total_tokens||0),0):0,K=[...w].sort((N,S)=>(S.totals?.total_tokens||0)-(N.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:w.filter(N=>N.percent>0).filter(N=>!(r==="claude"&&(N.key==="tool_calls"||N.key==="custom_agents"))).map(N=>`${ms(N.key)} ${N.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[K.map(N=>{const S=N.key==="system_prompt",q=N.key==="messages",O=N.key==="tool_calls",ue=N.key==="custom_agents";if(N.key,r==="claude"&&(O||ue))return null;const J=q&&L.length>0||O&&(A?.categories?.length>0||B)||ue&&H&&z,me=!!h[N.key],ie=uc(N.key,r),xe=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:ie},"aria-hidden":"true"}),_e=S?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(Ks,{size:11,className:"text-oai-gray-400 dark:text-oai-gray-500 cursor-help","aria-hidden":"true"}),e.jsx("span",{role:"tooltip",className:"pointer-events-none absolute left-1/2 bottom-full z-20 mb-1.5 -translate-x-1/2 w-64 rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 px-2.5 py-1.5 text-[11px] leading-snug text-oai-gray-700 dark:text-oai-gray-200 shadow-md opacity-0 group-hover:opacity-100 transition-opacity",children:l("dashboard.context_breakdown.system_prefix_tooltip")})]}):null,fe=N.percent>0?`${N.percent.toFixed(N.percent<.1&&N.percent>0?2:1)}%`:"0.0%";return e.jsxs(Ze,{level:0,colorSquare:xe,label:ms(N.key),labelSuffix:_e,tokens:i(N.totals?.total_tokens||0),percent:fe,hasChevron:J,open:me,onToggle:()=>y(N.key),share:N.percent,fillColor:ie,children:[q&&e.jsx("ul",{className:"space-y-0.5",children:L.map(ae=>e.jsx(Ze,{level:1,label:Tc(ae),tokens:i(ae.totals.total_tokens||0),percent:null},ae.key||ae.name))}),O&&A&&e.jsx(zt,{toolSet:A,execDetails:C,source:r,codexQueueFallback:B}),O&&B&&!A&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),ue&&z&&e.jsx(zt,{toolSet:z,execDetails:null,source:r,codexQueueFallback:!1})]},N.key)}),r==="claude"&&A?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:i(E),percent:null,hasChevron:!0,open:!!h.tool_calls_aux,onToggle:()=>y("tool_calls_aux"),children:e.jsx(zt,{toolSet:A,execDetails:C,source:r,codexQueueFallback:!1})}),r==="claude"&&z?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:i(R),percent:null,hasChevron:!0,open:!!h.custom_agents_aux,onToggle:()=>y("custom_agents_aux"),children:e.jsx(zt,{toolSet:z,execDetails:null,source:r,codexQueueFallback:!1})}),j?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:i($),percent:null,hasChevron:!0,open:!!h.mcp_servers,onToggle:()=>y("mcp_servers"),children:e.jsx(zt,{toolSet:j,execDetails:null,source:r,codexQueueFallback:!1})}),M.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:i(M.reduce((N,S)=>N+(S.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!h.skills,onToggle:()=>y("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:M.slice(0,12).map(N=>e.jsx(Ze,{level:1,label:N.name,tokens:i(N.total_tokens),percent:null},N.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(Mc(r))}),B?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,D?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Je(D.skills_count||0)," skills ·"," ",Je(D.mcp_servers_count||0)," MCP servers ·"," ",Je(D.custom_agents_count||0)," agents ·"," ",Je(D.memory_files_count||0)," memory files"]}):null]})}function nn({size:t=15,className:a=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:a,"aria-hidden":"true",children:[e.jsx("path",{d:"M12 1.6 23 7.4 12 13.2 1 7.4 12 1.6Z"}),e.jsx("path",{d:"m4 10.3-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.72"}),e.jsx("path",{d:"m4 14.6-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.45"})]})}const nt="__all__",Ic=`${100 .toFixed(2)}%`;function Vt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function mr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Ht(a);return(a===Fs?s:s*r)<.01?`<${n}0.01`:Sa(s,{decimals:2,currency:a,rate:r})}function Fc(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:fs(a)}:{key:a.key,label:a.label||fs(a.key)}):[]}function $c(t){if(typeof t!="string")return null;const a=t.replace(/,/g,"").match(/-?\d+(?:\.\d+)?/);if(!a)return null;const r=Number(a[0]);return Number.isFinite(r)?r:null}const Pc={CODEX:"#3b82f6",CLAUDE:"#d97757",OPENCODE:"#f59e0b",GEMINI:"#2196f3",KIMI:"#a78bfa","KILO-CLI":"#facc15","KILO-CODE":"#facc15",MIMO:"#ff6900",DROID:"#ef4444",ZCODE:"#14b8a6",ANYTHINGLLM:"var(--provider-anythingllm)"};function tr(t,a){const r=t?.toUpperCase?.()||"";return Pc[r]||`hsl(${150+a*40}, 60%, 45%)`}function Bc(t){const a=String(t?.source||"").trim().toLowerCase(),r=String(t?.label||"").trim().toLowerCase();return a==="claude"||r==="claude"?"claude":a==="codex"||r==="codex"?"codex":null}function zc(t){return!!t?.models?.length}function on(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function ar(t){const a=on(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const Oc={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function fs(t){const a=Oc[t];return a?l(a):String(t).toUpperCase()}function Uc({loading:t,onClick:a}){const r=Hs();return e.jsx(Ho,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(Ne.span,{"aria-hidden":"true",animate:t?{rotate:360}:{rotate:0},transition:t&&!r?{duration:1,repeat:1/0,ease:"linear"}:{duration:.3},style:{display:"inline-block"},children:"↻"})})}function Hc(){return e.jsx("div",{"data-testid":"usage-summary-skeleton","aria-hidden":"true",className:"mx-auto h-[58px] sm:h-[72px] w-[min(72vw,18rem)] rounded-2xl bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"})}function Vc(){return e.jsxs("div",{"data-testid":"usage-provider-skeleton","aria-hidden":"true",className:"space-y-6",children:[e.jsx("div",{className:"h-1.5 w-full rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[0,1,2,3].map(t=>e.jsx("div",{className:"h-[92px] rounded-xl border border-oai-gray-100 dark:border-oai-gray-800 bg-oai-gray-50 dark:bg-oai-gray-800/60 animate-pulse motion-reduce:animate-none",style:{animationDelay:`${t*70}ms`}},t))})]})}function Wc({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:u,onCostInfo:c,fleetData:g=[],onRefresh:m,loading:x,announceLoading:h=!1,summaryLoading:f=!1,providersLoading:y=!1,hasSummary:w=!0,className:p="",customFrom:v,customTo:_,onCustomRangeApply:D,customRangeOpen:C,onCustomRangeOpenChange:M,onOpenShare:L,from:B,to:k,deviceOptions:j=[],selectedDevice:A="",onDeviceChange:$}){const z=Fc(a),H=vi(Vo()),E=$c(String(s??"")),R=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[K,N]=d.useState(R);d.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const T=window.matchMedia("(max-width: 639px)"),V=X=>N(X.matches);return T.addEventListener("change",V),()=>T.removeEventListener("change",V)},[]);const S=E!=null&&!K,q=d.useRef(null);d.useEffect(()=>{const T=q.current?.querySelector('[aria-selected="true"]');T&&typeof T.scrollIntoView=="function"&&T.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[O,ue]=d.useState(null),{resolvedTheme:J}=Uo(),{currency:me,rate:ie}=Ca(),{formatTokens:xe}=Me(),_e=J==="dark",fe=_e?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",ae=_e?"rgba(10,10,10,0)":"rgba(255,255,255,0)",Q=f&&!w,P=y&&!g.some(zc);d.useEffect(()=>{ue(null)},[t,B,k,A]);const te=T=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(T.key))return;const V=Array.from(T.currentTarget.querySelectorAll('[role="tab"]')).filter(se=>!se.disabled),X=V.indexOf(T.target.closest('[role="tab"]'));if(X===-1||V.length===0)return;T.preventDefault();let ee=X;T.key==="Home"?ee=0:T.key==="End"?ee=V.length-1:T.key==="ArrowRight"?ee=(X+1)%V.length:ee=(X-1+V.length)%V.length,V[ee].focus(),V[ee].click()},ye=S?e.jsx(pl,{value:E,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:_e?0:8,gradientFrom:fe,gradientTo:ae,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,U=g.filter(T=>T.models?.length>0),he=d.useMemo(()=>Zl(g),[g]),le=he.reduce((T,V)=>T+(Number(V.usage)||0),0),G=U.reduce((T,V)=>T+(Number(V.usd)||0),0),Y=O==null?null:O===nt||U.some(function(V){return V.label===O})?O:null;return e.jsx(Ce,{className:p,children:e.jsxs("div",{"aria-busy":x||Q||P,children:[h?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:q,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:te,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:z.map(T=>{const V=t===T.key,X=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${V?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(T.key==="custom"){const ee=V&&v&&_?`${Zr(v,H)} — ${Zr(_,H)}`:T.label;return e.jsxs(Pi,{open:C,onOpenChange:se=>{se?r?.("custom"):M?.(se)},children:[e.jsx(Bi,{render:e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:X}),children:ee}),e.jsx(zi,{children:e.jsx(Oi,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(Ui,{className:"bg-white dark:bg-oai-gray-900 border border-oai-gray-200 dark:border-oai-gray-700 rounded-xl shadow-lg",children:e.jsx(_i,{from:v,to:_,onApply:D,onCancel:()=>M?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:X,onClick:()=>r?.(T.key),children:T.label},T.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[j.length>1?e.jsx(Us,{value:A,onValueChange:$,options:j,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,L?e.jsxs("button",{type:"button",onClick:L,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(rl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,m&&e.jsx(Uc,{loading:x,onClick:m})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:Q?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:ye}):e.jsx("span",{title:n||void 0,children:ye})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${Q?"":"hidden"}`,children:e.jsx(Hc,{})})]}),u&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:c?e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[u,e.jsx(Ks,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:u})})]}),e.jsx("div",{className:P?void 0:"hidden",children:e.jsx(Vc,{})}),U.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:U.map(T=>l("usage.overview.distribution_item",{label:jt(T.label),percent:ar(T)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:U.map((T,V)=>{const X=tr(T.label,V),ee=jt(T.label),se=ar(T);return e.jsx(Ne.div,{initial:{width:0},animate:{width:`${on(T)}%`},transition:{duration:.5,delay:.45+V*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:X},title:`${ee}: ${se}%`},T.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":Y===nt,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:Vt(xe,le)||String(0),cost:mr(G,me,ie)||`${Ht(me)}0`,count:he.length}),onClick:()=>ue(Y===nt?null:nt),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${Y===nt?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(nn,{size:15,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",children:l("usage.overview.all_tools")})]}),e.jsx("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:Ic}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:he.length})})]}),U.map((T,V)=>{const X=tr(T.label,V),ee=Y===T.label,se=jt(T.label),Ke=ar(T);return e.jsxs("button",{"aria-expanded":ee,"aria-controls":`provider-details-${T.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:se,percent:Ke,tokens:Vt(xe,T.usage)||String(0),cost:mr(T.usd,me,ie)||`${Ht(me)}0`,action:l(ee?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>ue(ee?null:T.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${ee?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(Ct,{provider:T.label,size:15,color:X,className:"text-oai-gray-700 dark:text-oai-gray-300 shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",title:se,children:se})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[Ke,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:T.models.length})})]},T.label)})]}),Y===nt&&e.jsx("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:e.jsx(Kc,{models:he})}),Y!=null&&Y!==nt&&e.jsx("div",{id:`provider-details-${Y}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:Y}),className:"mt-2",children:U.filter(T=>T.label===Y).map(T=>{const V=tr(T.label,0),X=Bc(T),ee=[...T.models].sort((Ke,ce)=>(ce.share||0)-(Ke.share||0)),se=X?`${X==="claude"?"Claude":"Codex"} Context Breakdown`:jt(T.label);return e.jsx(Gc,{provider:T,color:V,providerHeading:se,contextSource:X,from:B,to:k,sortedModels:ee},T.label)})})]})]})})}function ln({models:t,color:a}){const{currency:r,rate:s}=Ca(),{formatTokens:n,formatTokensTooltip:i}=Me();return e.jsx("div",{className:"space-y-3",children:t.map(o=>{const u=Vt(n,o.usage),c=mr(o.cost,r,s),g=Math.max(0,Math.min(100,Number(o.share)||0));return e.jsxs("div",{"data-model-rank-row":!0,children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_4rem] items-baseline gap-x-3 mb-1.5",children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:o.name,children:o.name}),e.jsx("span",{title:i(o.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:u}),e.jsx("span",{className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:c}),e.jsxs("span",{className:"col-start-4 row-start-1 text-right whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[o.share,"%"]})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":g,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${g}%`,backgroundColor:a,opacity:.45}})})]},o.id||o.name)})})}function Kc({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(nn,{size:14,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("usage.overview.all_models")})]}),e.jsx("p",{className:"mb-4 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("usage.overview.all_models_note")}),e.jsx(ln,{models:t,color:"var(--oai-blue)"})]})}function Gc({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o}){const{formatTokens:u}=Me(),[c,g]=d.useState(!1),m=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Ct,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&c&&e.jsx(Hi,{size:12,className:"text-oai-gray-400 dark:text-oai-gray-500 animate-spin shrink-0","aria-label":l("dashboard.context_breakdown.loading_aria")})]}),t.cacheHitRate!=null&&e.jsxs("p",{className:"mb-3 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:[e.jsx("span",{className:"font-medium text-oai-gray-600 dark:text-oai-gray-300",children:l("usage.overview.cache_hit_rate_label")})," ",e.jsxs("span",{className:"text-oai-black dark:text-oai-white",children:[t.cacheHitRate,"%"]})," · ",l("usage.overview.cache_hit_rate_detail",{reused:Vt(u,t.cacheReusedTokens)||String(0),input:Vt(u,t.cacheInputTokens)||String(0)})]}),m&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(Rc,{from:n,to:i,source:s,referenceTotalTokens:t.usage,onLoadingChange:g})}):null,e.jsx(ln,{models:o,color:a})]})}function qc({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:u,isDragging:c}=mi({id:t}),g=d.useRef(null),m=d.useRef(null);d.useLayoutEffect(()=>{if(!r)return;const h=g.current?g.current.childNodes.length===0:!0;m.current!==h&&(m.current=h,r(t,h))});const x={transform:hi.Transform.toString(o)||void 0,transition:u,zIndex:c?20:void 0};return e.jsxs("div",{ref:i,style:x,className:Nt("group/sortable relative has-[[data-sortable-body]:empty]:hidden",c&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:Nt("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",c&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:g,"data-sortable-body":!0,className:Nt("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",c&&"shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]"),children:a})]})}function Yc({todayTokens:t=0,isSyncing:a=!1,hasError:r=!1,isDisconnected:s=!1}={}){return d.useMemo(()=>r?"error":s?"disconnected":a?"working-typing":t===0?"sleeping":t<5e4?"idle-living":t<2e5?"idle-look":t<5e5?"working-ultrathink":t<2e6?"working-typing":"working-ultrathink",[t,a,r,s])}const ps="macAppBannerDismissed",Zc="leaderboardBannerDismissed",Jc="https://github.com/mm7894215/TokenTracker/releases/latest",ys="tokentracker_native_app",fa=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(ys,"1"),!0):localStorage.getItem(ys)==="1"}catch{return!1}})();function Qc({todayTokens:t=0,isSyncing:a=!1,enterDelay:r=0}){const{openLoginModal:s}=Wo(),{signedIn:n}=Bs(),i=Yc({todayTokens:t,isSyncing:a}),o=fa?Zc:ps,[u,c]=d.useState(()=>{try{return localStorage.getItem(o)==="1"?!0:!fa&&new URLSearchParams(window.location.search).get("from")==="menubar"?(localStorage.setItem(ps,"1"),!0):!1}catch{return!1}}),g=d.useCallback(()=>{c(!0);try{localStorage.setItem(o,"1")}catch{}},[o]);if(u)return null;let m,x,h,f,y,w;fa&&n?(m="View the Leaderboard",x="Compare your usage globally",h="Leaderboard",f=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M2 8.5V10h8V8.5M6 1.5v6m0 0L3.5 5M6 7.5l2.5-2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(180 6 6)"})}),y=()=>{window.location.pathname="/leaderboard"}):fa?(m="Join the Leaderboard",x="Log in to compare your usage with others",h="Log In",f=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6.5 1.5h3a1 1 0 011 1v7a1 1 0 01-1 1h-3M5 8.5L7.5 6 5 3.5M7.5 6H1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),y=s):(m="Try the Menu Bar App",x="Always-on stats with Clawd companion",h="Download",f=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6 2v6m0 0L3.5 5.5M6 8l2.5-2.5M2 10h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),w=Jc);const p=w?Ne.a:Ne.button,v=w?{href:w,target:"_blank",rel:"noopener noreferrer"}:{onClick:y};return e.jsx(Ne.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:r,ease:[.16,1,.3,1]},className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(Vi,{state:i,size:56})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-900 dark:text-oai-white",children:m}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-0.5",children:x})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(p,{...v,whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[h,f]}),e.jsx("button",{onClick:g,className:"p-1 text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-300 transition-colors","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})})]})]})})}const bs="widgetOnboardingDismissed",ks="tokentracker_native_app",Xc=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(ks,"1"),!0):localStorage.getItem(ks)==="1"}catch{return!1}})();function ed({enterDelay:t=0}){const[a,r]=d.useState(()=>{try{return localStorage.getItem(bs)==="1"}catch{return!1}}),s=d.useCallback(()=>{r(!0);try{localStorage.setItem(bs,"1")}catch{}},[]);return!Xc||Ko()?null:e.jsx(wr,{initial:!1,children:!a&&e.jsxs(Ne.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-8,transition:{duration:.2,ease:[.4,0,.2,1]}},transition:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:s,"aria-label":l("dashboard.widgets.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"rounded-lg overflow-hidden ring-1 ring-black/5 dark:ring-white/10 shadow-sm",children:e.jsx("img",{src:"/widgets-overview.png",alt:l("dashboard.widgets.title"),width:734,height:552,className:"w-full h-auto block",loading:"lazy",decoding:"async"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.widgets.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.widgets.hint")})]})]},"widget-onboarding-card")})}function td({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[g,m]=d.useState(null),x=Kt([t,a,r,s,n]),h=d.useCallback(async()=>{if(!t)return;const f=x();c(!0),m(null);try{const y=await Fe(s);if(!f())return;const w=await Go({from:a,to:r,device:n,accessToken:y});if(!f())return;o(w||null)}catch(y){if(!f())return;m(y?.message||String(y)),o(null)}finally{f()&&c(!1)}},[t,a,r,s,n,x]);return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}o(null),m(null),c(!0),h()},[t,h]),{data:i,loading:u,error:g,refresh:h}}function cn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function dn(t){return t==null?"—":`${Math.round(t*100)}%`}function ad(t,a){if(a==null||a===0||t==null||t===0)return"—";const r=t/a;return r<1?`$${r.toFixed(4)}`:`$${r.toFixed(2)}`}function rd({row:t}){return e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60 hover:bg-oai-gray-50/40 dark:hover:bg-oai-gray-800/10 transition-colors",children:[e.jsx("td",{className:"py-2.5 pr-2 font-mono text-[11px] text-oai-gray-700 dark:text-oai-gray-300 truncate max-w-[80px] xs:max-w-[110px] sm:max-w-[140px]",title:t.key,children:t.key}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:cn(t.cost_usd)}),e.jsxs("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:[t.accepted,"/",t.outcomes]}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:dn(t.acceptance_rate)}),e.jsx("td",{className:"py-2.5 pl-2 pr-2 text-right tabular-nums font-semibold text-oai-black dark:text-oai-white",children:ad(t.cost_usd,t.accepted)})]})}function sd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Me(),{enabled:i}=Wi(),{data:o,loading:u}=td({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const c=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(h=>h.outcomes>0&&h.key!=="unknown");if(!c.length)return null;const g=c.slice(0,6),m=o.totals||{},x=`${l("qpd.card.subtitle")}${u?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(Ce,{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("qpd.card.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:x}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:g.map(h=>e.jsx(rd,{row:h},h.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:m.accepted??0,outcomes:m.outcomes??0,cost:cn(m.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(m.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(m.effective_tokens),rate:dn(m.acceptance_rate)})})]}),m.outcomes<15&&e.jsxs("p",{className:"mt-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500 italic border-t border-oai-gray-100 dark:border-oai-gray-800/40 pt-2",children:["* ",l("qpd.card.sparse_notice","Tip: Spark outcomes dataset might skew Quality/$ ratios. For precise metrics, select a narrower time window.")]})]})}const nd=new Set(["unknown","synthetic","openai"]);function rr(t){return t==null?"—":`${Math.round(t*100)}%`}function od(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ye(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function id(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!nd.has(r)&&Number(t?.edit_turns||0)>0}function ws(){return e.jsx("div",{className:"mb-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:l("sessions.card.title")}),e.jsx("span",{className:"rounded bg-oai-gray-100 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-oai-gray-500 dark:bg-oai-gray-800/80 dark:text-oai-gray-400",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("sessions.card.subtitle")})]})})}function ld({from:t,to:a}){const[r,s]=d.useState({loading:!0,sessions:null,context:null}),n=d.useId(),{enabled:i}=Ki(),{formatTokens:o}=Me(),u=p=>o(p,{mode:ka.COMPACT});d.useEffect(()=>{if(!i){s({loading:!1,sessions:null,context:null});return}let p=!1;return s(v=>({...v,loading:!0})),Promise.all([qo({from:t,to:a}),Yo()]).then(([v,_])=>{p||s({loading:!1,sessions:v,context:_})}).catch(()=>{p||s({loading:!1,sessions:null,context:null})}),()=>{p=!0}},[i,t,a]);const c=d.useMemo(()=>(r.sessions?.by_model||[]).filter(id).slice(0,5),[r.sessions]),g=d.useMemo(()=>(r.sessions?.subagents||[]).slice(0,3),[r.sessions]);if(!i||!r.loading&&!r.sessions?.available&&!r.context?.estimated_fixed_tokens)return null;const m=r.sessions?.summary||{},x=m.edit_session_rate??m.productive_rate,h=m.first_pass_rate??m.one_shot_rate,f=m.edit_sessions??m.productive_sessions??0,y=m.sessions??r.sessions?.session_count??0,w=m.edit_turns??0;return r.loading&&!r.sessions&&!r.context?e.jsxs(Ce,{children:[e.jsx(ws,{}),e.jsx("div",{role:"status",className:"flex h-24 items-center justify-center rounded-lg bg-oai-gray-50 text-xs text-oai-gray-400 dark:bg-oai-gray-800/50 dark:text-oai-gray-500",children:l("sessions.card.loading")})]}):e.jsxs(Ce,{children:[e.jsx(ws,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(sr,{label:l("sessions.card.edit_sessions"),value:rr(x),detail:l("sessions.card.edit_session_value",{edits:Ye(f),sessions:Ye(y)})}),e.jsx(sr,{label:l("sessions.card.first_pass"),value:rr(h),detail:l("sessions.card.edit_session_value",{edits:Ye(m.first_pass_sessions??m.one_shot_sessions??0),sessions:Ye(f)})}),e.jsx(sr,{label:l("sessions.card.cost_edit"),value:od(m.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ye(w)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Ye(y),edits:Ye(w)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":n,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:n,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!c.length&&e.jsx("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:c.map(p=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:p.model,children:p.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Ye(p.edit_sessions??p.productive_sessions??0),sessions:Ye(p.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:rr(p.first_pass_rate??p.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:u(p.tokens_per_edit)})]},p.model))})]})}),r.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:u(r.context.estimated_fixed_tokens)})]}):null,!!g.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),g.map(p=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:p.name,calls:Math.round(p.calls)})},p.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function sr({label:t,value:a,detail:r}){return e.jsxs("div",{className:"rounded-lg bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 truncate",children:t}),e.jsx("div",{className:"mt-0.5 text-sm font-semibold tabular-nums text-oai-black dark:text-white",children:a}),e.jsx("div",{className:"mt-0.5 text-[9px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 truncate",children:r})]})}function ne({className:t}){return e.jsx("div",{className:Nt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function cd(){return e.jsx("div",{className:"flex gap-1 overflow-hidden",children:Array.from({length:20},(t,a)=>e.jsx("div",{className:"flex flex-col gap-1",children:Array.from({length:7},(r,s)=>e.jsx(ne,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function dd(){return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsxs("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:[e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(ne,{className:"h-4 w-32"}),e.jsx(ne,{className:"h-6 w-24"})]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ne,{className:"h-3.5 w-24"}),Array.from({length:4},(t,a)=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(ne,{className:"h-3 w-20"}),e.jsx(ne,{className:"h-3 w-12"})]},a))]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ne,{className:"h-3.5 w-20"}),e.jsx(cd,{})]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ne,{className:"h-3.5 w-28"}),e.jsx(ne,{className:"h-32 w-full"})]})})]}),e.jsxs("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:[e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex flex-1 min-w-0 gap-1",children:Array.from({length:5},(t,a)=>e.jsx(ne,{className:"h-7 w-14 rounded-md shrink-0"},a))}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(ne,{className:"h-8 w-20 rounded-md"}),e.jsx(ne,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(ne,{className:"h-3 w-28"}),e.jsx(ne,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(ne,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ne,{className:"h-1.5 w-full rounded-full"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-3",children:Array.from({length:5},(t,a)=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ne,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(ne,{className:"h-3 w-12"})]}),e.jsx(ne,{className:"h-5 w-10"}),e.jsx(ne,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(Ce,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(ne,{className:"h-7 w-16 rounded"}),e.jsx(ne,{className:"h-7 w-20 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-200 dark:border-oai-gray-700 pb-2",children:[e.jsx(ne,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(ne,{className:"h-3 flex-1"},a))]}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:8},(t,a)=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-100 dark:border-oai-gray-800 py-2.5 last:border-b-0",children:[e.jsx(ne,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(ne,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const ud=Yi.slice(0,10),_s=.06,md=.11,hd=.05,gd=new Set(["macAppBanner","widgetOnboarding"]);function vs({title:t,subtitle:a,desc:r,loginCard:s,copy:n}){return e.jsxs("div",{className:"min-h-[85vh] w-full flex items-center justify-center text-oai-black dark:text-white relative overflow-hidden px-4 md:px-8 py-8 md:py-16 transition-colors duration-200 bg-[linear-gradient(to_right,#80808007_1px,transparent_1px),linear-gradient(to_bottom,#80808007_1px,transparent_1px)] bg-[size:40px_40px]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_50%_0%,rgba(59,130,246,0.03),transparent_50%)] dark:bg-[radial-gradient(circle_at_50%_0%,rgba(99,102,241,0.05),transparent_50%)] pointer-events-none"}),e.jsxs("div",{className:"w-full max-w-5xl grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-16 items-start relative z-10",children:[e.jsxs("div",{className:"lg:col-span-7 flex flex-col justify-center space-y-8 text-left pr-0 lg:pr-6",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:32,height:32,className:"rounded-md shadow-md border border-oai-gray-200/50 dark:border-oai-gray-800 shadow-black/10 dark:shadow-black/30"}),e.jsx("span",{className:"text-xl font-bold tracking-tight bg-gradient-to-r from-oai-black to-oai-gray-600 dark:from-white dark:to-oai-gray-400 bg-clip-text text-transparent font-oai",children:n("shared.app_name")})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl md:text-4xl lg:text-4.5xl font-black tracking-tight leading-[1.15] text-oai-black dark:text-white",children:t}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm md:text-base max-w-xl leading-relaxed",children:r})]}),e.jsx("div",{className:"w-full max-w-[280px] sm:max-w-md opacity-85 hover:opacity-100 transition-opacity duration-200",children:e.jsx("div",{className:"flex justify-start",children:e.jsx(qi,{logos:ud,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(Ne.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{duration:.3},className:"w-full max-w-[400px] rounded-2xl border border-oai-gray-200/80 dark:border-oai-gray-800 bg-white/70 dark:bg-oai-gray-950/40 backdrop-blur-md shadow-2xl p-1 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -inset-px bg-gradient-to-b from-white/10 dark:from-white/5 to-transparent pointer-events-none rounded-2xl"}),s]})})]})]})}function xd(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:u,activeDays:c,identitySubscriptions:g,identityScrambleDurationMs:m,projectUsageEntries:x,projectUsageLimit:h,setProjectUsageLimit:f,projectDetailQuery:y,topModels:w,signedIn:p,publicMode:v,isLocalMode:_,shouldShowInstall:D,installPrompt:C,handleCopyInstall:M,installCopied:L,installInitCmdDisplay:B,trendRowsForDisplay:k,trendFromForDisplay:j,trendToForDisplay:A,trendZoomConfig:$,usageFrom:z,usageTo:H,period:E,trendTimeZoneLabel:R,activityHeatmapBlock:K,periodsForDisplay:N,setSelectedPeriod:S,customFrom:q,customTo:O,onCustomRangeApply:ue,customRangeOpen:J,onCustomRangeOpenChange:me,summaryLabel:ie,summaryValue:xe,summaryFullValue:_e,hasSummary:fe,summaryLoading:ae,providersLoading:Q,onToggleSummaryFormat:P,summaryTotalTokensRaw:te,summaryCostValue:ye,summaryConversationsValue:U,rollingUsage:he,costInfoEnabled:le,openCostModal:G,costModalOpen:Y,closeCostModal:T,allowBreakdownToggle:V,refreshAll:X,usageLoadingState:ee,announceUsageLoading:se,initialDashboardLoading:Ke,fleetData:ce,hasDetailsActual:$e,dailyEmptyPrefix:ze,installSyncCmd:Se,dailyEmptySuffix:At,detailsColumns:be,ariaSortFor:ke,toggleSort:Ee,sortIconFor:Oe,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ue,dailyBreakdownAriaSortFor:Ta,dailyBreakdownSortIconFor:Qe,dailyBreakdownDateKey:Aa,detailsDateKey:Da,renderDetailDate:ht,renderDailyBreakdownDate:Z,renderDetailCell:Gt,DETAILS_PAGED_PERIODS:ve,detailsPageCount:je,detailsPage:Re,setDetailsPage:gt,deviceOptions:qt,selectedDevice:Lt,onDeviceChange:La,deviceUsageBlock:He,leftCardOrder:Yt,onLeftReorder:at,rightCardOrder:Mt,onRightReorder:Zt}=t,Ma=null,Jt=null,[xt,Ea]=d.useState(()=>new Set),Et=d.useCallback((de,oe)=>{gd.has(de)&&Ea(ge=>{if(ge.has(de)===oe)return ge;const Xe=new Set(ge);return oe?Xe.add(de):Xe.delete(de),Xe})},[]),Rt={macAppBanner:_,statsPanel:!0,widgetOnboarding:_,installCopy:D,activityHeatmap:!!K,deviceUsage:!!He,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:_&&!s},Ra=(Yt||[]).filter(de=>Rt[de]&&!xt.has(de)),rt={usageOverview:!0,dataDetails:!s},Qt=(Mt||[]).filter(de=>rt[de]&&!xt.has(de));function Ve(de,oe){switch(de){case"macAppBanner":return e.jsx(Qc,{todayTokens:te,isSyncing:ee,enterDelay:oe});case"statsPanel":return e.jsx(st,{delay:oe,children:e.jsx(lc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:E,startDate:u??a("identity_card.rank_placeholder"),streakDays:c,subscriptions:g,periodConversations:U,rolling:he,topModels:w})});case"widgetOnboarding":return e.jsx(ed,{enterDelay:oe});case"installCopy":return e.jsx(st,{delay:oe,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:C}),e.jsxs(Ne.button,{onClick:M,whileHover:{scale:1.01},whileTap:{scale:.99},className:"w-full flex items-center justify-between px-3 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-700 rounded-lg transition-colors",children:[e.jsx("code",{className:"text-xs font-mono text-oai-gray-700 dark:text-oai-gray-300",children:B}),e.jsx(Ne.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:L?"Copied ✓":"Copy"},L?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(st,{delay:oe,children:K});case"deviceUsage":return e.jsx(st,{delay:oe,children:He});case"trendMonitor":return e.jsx(st,{delay:oe,children:e.jsx(zs,{rows:k,from:j,to:A,period:E,timeZoneLabel:R,showTimeZoneLabel:!1,zoomConfig:$})});case"qualityPerDollar":return e.jsx(sd,{from:z,to:H,deviceId:Lt});case"sessionInsights":return e.jsx(ld,{from:z,to:H});default:return null}}function pe(de,oe){switch(de){case"usageOverview":return e.jsx(st,{delay:oe,children:e.jsx(Wc,{period:E,periods:N,onPeriodChange:S,summaryLabel:ie,summaryValue:xe,summaryFullValue:_e,hasSummary:fe,summaryLoading:ae,providersLoading:Q,onToggleSummaryFormat:fe?P:null,summaryCostValue:ye,onCostInfo:le?G:null,fleetData:ce,onRefresh:s?null:X,loading:ee,announceLoading:se,onOpenShare:s?null:r,customFrom:q,customTo:O,onCustomRangeApply:ue,customRangeOpen:J,onCustomRangeOpenChange:me,from:z,to:H,deviceOptions:qt,selectedDevice:Lt,onDeviceChange:La})});case"dataDetails":return e.jsx(st,{delay:oe,children:e.jsx(oc,{projectEntries:x,projectLimit:h,onProjectLimitChange:f,projectDetailQuery:y,copy:a,hasDetailsActual:$e,dailyEmptyPrefix:ze,installSyncCmd:Se,dailyEmptySuffix:At,detailsColumns:be,ariaSortFor:ke,toggleSort:Ee,sortIconFor:Oe,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ue,dailyBreakdownAriaSortFor:Ta,dailyBreakdownSortIconFor:Qe,dailyBreakdownDateKey:Aa,detailsDateKey:Da,renderDetailDate:ht,renderDailyBreakdownDate:Z,renderDetailCell:Gt,DETAILS_PAGED_PERIODS:ve,period:E,detailsPageCount:je,detailsPage:Re,setDetailsPage:gt})});default:return null}}const Ia=gi(qr(ki,{activationConstraint:{distance:6}}),qr(bi,{coordinateGetter:yi})),Xt=d.useCallback(de=>{const{active:oe,over:ge}=de;!ge||oe.id===ge.id||at?.(String(oe.id),String(ge.id))},[at]),ea=d.useCallback(de=>{const{active:oe,over:ge}=de;!ge||oe.id===ge.id||Zt?.(String(oe.id),String(ge.id))},[Zt]);function ta(de,oe,ge,Xe){return s?e.jsx(e.Fragment,{children:de.map((Ge,It)=>e.jsx(vt.Fragment,{children:oe(Ge,ge+_s*It)},Ge))}):e.jsx(xi,{sensors:Ia,onDragEnd:Xe,children:e.jsx(fi,{items:de,strategy:pi,children:de.map((Ge,It)=>e.jsx(qc,{id:Ge,onEmptyChange:Et,children:oe(Ge,ge+_s*It)},Ge))})})}const aa=ta(Ra,Ve,md,Xt),ra=ta(Qt,pe,hd,ea);return e.jsxs(e.Fragment,{children:[e.jsxs(ll,{bare:!s,hideHeader:s,header:Ma,footer:s?null:Jt,className:s?"screenshot-mode":"",children:[i&&e.jsx(vs,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(Jr,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(vs,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(Jr,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&Ke&&e.jsx(dd,{}),!i&&!n&&!Ke&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:aa}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:ra})]})})]}),e.jsx(Xl,{isOpen:Y,onClose:T,fleetData:ce})]})}function fd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0}={}){const u=!!(n&&i),[c,g]=d.useState([]),[m,x]=d.useState([]),[h,f]=d.useState(!1),[y,w]=d.useState(null),p=Kt([u,t,a,r,s,i,o]),v=d.useCallback(async()=>{const _=p();if(!u){g([]),x([]),f(!1),w(null);return}f(!0),w(null);try{const D=await Fe(i);if(!_())return;const C=await Zo({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:D});if(!_())return;g(Array.isArray(C?.devices)?C.devices:[]),x(Array.isArray(C?.account_sources)?C.account_sources:[])}catch(D){if(!_())return;w(D?.message||String(D)),g([]),x([])}finally{_()&&f(!1)}},[u,i,t,a,r,s,o,p]);return d.useEffect(()=>{g([]),x([]),w(null),u&&f(!0),v()},[u,v]),{devices:c,accountSources:m,loading:h,error:y,refresh:v}}const pd=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function js(t){const a=String(t||"").toLowerCase();return/iphone|ipad|ios/.test(a)?"iOS":/android/.test(a)?"Android":/mac|darwin/.test(a)?"Mac":/win/.test(a)?"Windows":/linux/.test(a)?"Linux":"Web"}function hr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(pd);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${js(t.platform)} · ${s}`:js(t.platform)}const Ns=" · ",Ss="%";function Cs({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(el,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Hr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Hr,{className:a,"aria-hidden":!0}):e.jsx(Gs,{className:a,"aria-hidden":!0})}function yd({devices:t=[],accountSources:a=[],selectedDeviceId:r="",onSelectDevice:s,onRenameDevice:n}){const{formatTokens:i,formatTokensTooltip:o}=Me(),[u,c]=d.useState(""),[g,m]=d.useState(""),[x,h]=d.useState(!1),[f,y]=d.useState(""),w=typeof n=="function",p=typeof s=="function",v=!!r,_=t.reduce((k,j)=>k+(Number(j.total_tokens)||0),0)+a.reduce((k,j)=>k+(Number(j.total_tokens)||0),0),D=d.useMemo(()=>t.filter(k=>(Number(k.total_tokens)||0)>0).sort((k,j)=>(Number(j.total_tokens)||0)-(Number(k.total_tokens)||0)),[t]);function C(k){y(""),c(k.id);const j=typeof k.device_name=="string"?k.device_name:"";m(hr(k)===j?j:"")}function M(){c(""),m(""),y("")}async function L(k){const j=g.trim();if(!(!j||x)){h(!0),y("");try{await n(k.id,j),c(""),m("")}catch{y(k.id)}finally{h(!1)}}}const B=a.filter(k=>(Number(k.total_tokens)||0)>0);return D.length===0&&B.length===0?e.jsxs(Ce,{bodyClassName:"!px-3 !py-3.5",children:[e.jsx("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide px-2",children:l("dashboard.device_card.title")})}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-center",children:[e.jsx(Gs,{className:"h-7 w-7 text-oai-gray-300 dark:text-oai-gray-600 mb-2 stroke-[1.5]"}),e.jsx("p",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 font-medium",children:l("dashboard.device_card.empty")})]})]}):e.jsxs(Ce,{bodyClassName:"!px-3 !py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:l("dashboard.device_card.title")}),p&&v&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[D.map(k=>{const j=Number(k.total_tokens)||0,A=_>0?(j/_*100).toFixed(1):"0.0",$=r===k.id,z=hr(k)||l("dashboard.device_card.unnamed"),H=u===k.id,E=$?"bg-oai-brand":v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",R=v&&!$?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[H?e.jsxs("div",{className:"w-full rounded-md px-2 py-1.5 bg-oai-gray-50/50 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Cs,{platform:k.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:g,disabled:x,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:K=>m(K.target.value),onKeyDown:K=>{K.key==="Enter"?L(k):K.key==="Escape"&&M()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:x||!g.trim(),onClick:()=>L(k),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Zi,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:x,onClick:M,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(kr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${E}`,style:{width:`${A}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":$,"aria-label":`${l("dashboard.device_filter.aria")}: ${z}`,onClick:()=>s?.($?"":k.id),className:`w-full text-left rounded-md px-2 py-1.5 transition-all duration-200 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-oai-brand/50 ${R} ${$?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Cs,{platform:k.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:z,children:z})]}),e.jsxs("span",{title:o(j),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${w?"group-hover:opacity-0":""}`,children:[i(j),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Ns,A,Ss]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${E}`,style:{width:`${A}%`}})})]}),w&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>C(k),className:"absolute right-2 top-1.5 flex h-4 items-center text-oai-gray-400 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-oai-brand focus:outline-none transition-opacity duration-150",children:e.jsx(Gi,{className:"h-3 w-3"})})]}),f===k.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},k.id)}),B.map(k=>{const j=Number(k.total_tokens)||0,A=_>0?(j/_*100).toFixed(1):"0.0",$=v?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${$}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(Ct,{provider:k.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:jt(k.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:o(j),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(j),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Ns,A,Ss]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${A}%`}})})]},`account-${k.source}`)})]})]})}function un(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ct=new Map,dt=new Map;function mn(){typeof window>"u"||window.__tokentrackerNativeSaveListener||(window.__tokentrackerNativeSaveListener=!0,window.addEventListener("native:saveImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!ct.has(r))return;const s=ct.get(r);ct.delete(r),s({ok:!!a.ok,path:typeof a.path=="string"?a.path:void 0,error:typeof a.error=="string"?a.error:void 0})}),window.addEventListener("native:copyImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!dt.has(r))return;const s=dt.get(r);dt.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function bd(t){if(!un()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const a=window?.webkit?.messageHandlers?.nativeBridge;if(!a)return{ok:!1,error:"native bridge unavailable"};mn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{dt.has(r)&&(dt.delete(r),s({ok:!1,error:"timeout"}))},8e3);dt.set(r,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){dt.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Ts(t,a){if(!un()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const r=window?.webkit?.messageHandlers?.nativeBridge;if(!r)return{ok:!1,error:"native bridge unavailable"};mn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{ct.has(s)&&(ct.delete(s),n({ok:!1,error:"timeout"}))},8e3);ct.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){ct.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const hn=1200,gn=1630,xn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},kd="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter+Tight:wght@400;500;600;700&family=IBM+Plex+Serif:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap";let nr=!1;function wd(){if(typeof document>"u"||nr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){nr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=kd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),nr=!0}async function _d(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function vd(t,a={}){if(typeof window>"u"||!t)return null;wd(),await _d(),await new Promise(c=>requestAnimationFrame(()=>c(null)));const{toBlob:r,toPng:s}=await Jo(async()=>{const{toBlob:c,toPng:g}=await import("./index-BFIcLxb4.js");return{toBlob:c,toPng:g}},[]),n=a.pixelRatio??2,i=t.offsetWidth||hn,o=t.offsetHeight||gn,u={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:c=>!(c instanceof HTMLElement)||c.dataset?.screenshotExclude!=="true"};try{const c=await r(t,u);if(c)return c}catch{}try{const c=await s(t,u);return c?await(await fetch(c)).blob():null}catch{return null}}async function or(t){return new Promise(a=>{const r=new FileReader;r.onload=()=>{const s=typeof r.result=="string"?r.result:null;a(s)},r.onerror=()=>a(null),r.readAsDataURL(t)})}function As(t,a){if(typeof window>"u"||!t)return!1;try{const r=URL.createObjectURL(t),s=document.createElement("a");return s.href=r,s.download=a,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),!0}catch{return!1}}function gr(t){const a=re(t);return Number.isFinite(a)?a:0}function jd(t){return t?gr(t.billable_total_tokens??t.total_tokens):0}function Nd(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(u=>{const c=!!u?.future,g=Number.isFinite(u?.level)?Math.max(0,Math.min(4,Math.round(u.level))):0;u?.day&&!c&&(r+=1,g>0&&(s+=1));const m=u?.billable_total_tokens??u?.total_tokens??u?.value??0,x=Number.isFinite(m)?Math.max(0,m):0;return{day:typeof u?.day=="string"?u.day:"",level:g,value:x,future:c}})),totalDays:r,activeDays:s}}function Sd(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:u,periodFrom:c,periodTo:g,heatmap:m,capturedAt:x,currency:h,exchangeRate:f}=t,y=jd(n),w=gr(n?.total_cost_usd),p=Array.isArray(i)?i.slice(0,3).map(_=>({id:_?.id??null,name:typeof _?.name=="string"&&_.name?_.name:"—",tokens:gr(_?.tokens),percent:typeof _?.percent=="string"&&_.percent?_.percent:"0.0"})):[],v=Nd(m);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:y,totalCost:w,period:u,periodFrom:c,periodTo:g,topModels:p,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:x||new Date().toISOString(),currency:typeof h=="string"&&h.length>0?h.toUpperCase():"USD",exchangeRate:Number.isFinite(f)&&f>0?f:1}}const Cd=["share.month_short.jan","share.month_short.feb","share.month_short.mar","share.month_short.apr","share.month_short.may","share.month_short.jun","share.month_short.jul","share.month_short.aug","share.month_short.sep","share.month_short.oct","share.month_short.nov","share.month_short.dec"];function Td(t){const a=Cd[t];return a?l(a):"—"}function fn(t,a){return l("share.date.month_year",{month:Td(t),year:a})}function Ad(t){if(!t)return"—";const a=t.split("-");if(a.length!==3)return t;const[r,s]=a,n=Number(s)-1;return n<0||n>11?t:fn(n,r)}function Dd(t){if(t.period==="total")return l("share.issue.all_time");if(t.period==="day"&&t.periodTo)return t.periodTo.replace(/-/g,".");if(t.period==="custom"&&t.periodFrom&&t.periodTo)return`${t.periodFrom.replace(/-/g,".")} — ${t.periodTo.replace(/-/g,".")}`;if(t.periodTo){const a=new Date(`${t.periodTo}T00:00:00Z`);if(!Number.isNaN(a.getTime()))return fn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function xr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function pn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Ht(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function Ld(t){const a=t.topModels[0];if(a){const r=parseFloat(a.percent);return Number.isFinite(r)&&r>=60?l("share.hook.top_loyal",{percent:Math.round(r),name:a.name}):t.activeDays>=60?l("share.hook.days_record",{days:t.activeDays}):Number.isFinite(r)&&r>=30?l("share.hook.top_led",{name:a.name,percent:Math.round(r)}):t.topModels.length>1?l("share.hook.multi_models",{count:t.topModels.length,days:t.activeDays}):l("share.hook.days_with_model",{days:t.activeDays,name:a.name})}return t.activeDays>0?l("share.hook.days_record",{days:t.activeDays}):l("share.hook.new_chapter")}function Md(t,a){const r=(t||"").length;if(r<=a.baseChars)return a.baseSize;const s=a.baseSize-(r-a.baseChars)*a.shrinkPerChar;return Math.max(a.minSize,s)}function Ed(t){if(!t||t.future)return null;const a=typeof t.level=="number"?t.level:0;return a<0?0:a>4?4:Math.round(a)}function Rd({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],u=i||o[0],c=t.length,g=(c-1)*s,m=Math.max(4,(r-g)/c),x=7*m+6*s;return e.jsx("svg",{width:r,height:x,viewBox:`0 0 ${r} ${x}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((h,f)=>(Array.isArray(h)?h:[]).map((w,p)=>{if(p>=7)return null;const v=Ed(w),_=f*(m+s),D=p*(m+s),C=v===null?u:o[v];return e.jsx("rect",{x:_,y:D,width:m,height:m,rx:n,ry:n,fill:C},`${f}-${p}`)}))})}const Id=Tt("oklch(0.97 0.01 85)"),Le=Tt("oklch(0.18 0.02 85)"),et=Tt("oklch(0.38 0.015 85)"),Ds=Tt("oklch(0.55 0.012 85)"),ot=Tt("oklch(0.55 0.22 25)"),it='"Instrument Serif", "Times New Roman", Georgia, serif',Fd='"Inter Tight", "Helvetica Neue", Arial, sans-serif',$d=["oklch(0.93 0.013 80)","oklch(0.87 0.04 55)","oklch(0.78 0.09 45)","oklch(0.67 0.16 35)","oklch(0.55 0.22 25)"].map(Tt);function yn({data:t}){const a=Dd(t),r=xr(t.totalTokens),s=pn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=Ad(t.startDate),i=Md(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=Ld(t),u=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Id,color:Le,fontFamily:Fd,padding:"80px 88px 68px 88px",boxSizing:"border-box",display:"flex",flexDirection:"column",position:"relative"},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,paddingBottom:14,borderBottom:`1px solid ${Ds}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Le},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:ot}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:et,textAlign:"right"},children:[l("share.card.broadsheet.issue")," № ",a]})]}),e.jsxs("div",{style:{marginTop:24,display:"flex",justifyContent:"space-between",alignItems:"flex-end",gap:24},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.2em",textTransform:"uppercase",color:et,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:it,fontSize:52,fontStyle:"italic",lineHeight:1,color:Le,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:et,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Le},children:n})]})]}),e.jsxs("div",{style:{marginTop:40,display:"flex",flexDirection:"column"},children:[e.jsx("div",{style:{fontSize:13,letterSpacing:"0.3em",textTransform:"uppercase",color:ot,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:it,fontSize:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Le,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:it,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Le,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:ot,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:et},children:[e.jsxs("span",{children:[l("share.card.broadsheet.estimated_spend")," · ",s]}),e.jsx("span",{children:l("share.card.broadsheet.billable_days",{days:t.activeDays})})]})]}),u?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Le,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:et},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Rd,{weeks:t.heatmapWeeks,palette:$d,width:1024,gap:3,radius:2})]}):null,e.jsxs("section",{style:{marginTop:30,flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",borderBottom:`1px solid ${Le}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Le,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:et},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:it,fontStyle:"italic",fontSize:26,color:et,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((c,g)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Ds}`},children:[e.jsx("div",{style:{fontFamily:it,fontSize:34,fontStyle:"italic",color:ot,lineHeight:1},children:String(g+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:it,fontSize:32,color:Le,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("div",{style:{fontFamily:it,fontSize:28,color:Le,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:xr(c.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:et,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[c.percent,"%"]})]},c.id||c.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Le}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Le},children:[e.jsxs("div",{style:{display:"flex",gap:28},children:[e.jsxs("span",{children:[l("share.card.broadsheet.global_rank")," ",e.jsxs("span",{style:{color:ot},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:ot},children:l("share.card.broadsheet.days_count",{days:t.activeDays})})]})]}),e.jsxs("div",{children:[l("share.card.broadsheet.track_yours")," ",e.jsx("span",{style:{color:ot},children:"→ tokentracker.cc"})]})]})]})}const Pd=xn["annual-report"].width,Bd="#0a0820",tt="#ffffffee",lt="rgba(255,255,255,0.45)",ir="#a78bfa",zd={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(40px)",WebkitBackdropFilter:"blur(40px)",border:"1px solid rgba(255,255,255,0.05)",boxShadow:["0 39px 56px -36px rgba(255,255,255,0.10) inset","0 7px 11px -4px rgba(255,255,255,0.06) inset","0 -82px 68px -64px rgba(101,67,149,0.08) inset","0 98px 100px -48px rgba(208,171,255,0.06) inset","0 4px 18px 0 rgba(156,146,215,0.06) inset","0 1px 40px 0 rgba(228,222,255,0.04) inset"].join(", ")},pa={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},fr='"Space Grotesk", "Inter Tight", sans-serif',lr='"Inter Tight", sans-serif',Od="rgba(255,255,255,0.06)",bn=[Od,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],kn=48,wn=28,ja=4,_n=20,Ud=Pd-kn*2-wn*2,Hd=(Ud-_n*2)/3,pr=Math.min(Math.floor((Hd-ja*6)/7),40),Vd=pr*7+ja*6;function Wd(t){if(!Array.isArray(t))return t;const a=[];for(const u of t)if(Array.isArray(u))for(const c of u)c?.day&&!c.future&&c.value>0&&a.push(c.value);if(!a.length)return t;a.sort((u,c)=>u-c);const r=u=>{const c=a.length,g=(c-1)*u,m=Math.floor(g);return Math.round((a[m]??0)+((a[Math.min(c-1,m+1)]??0)-(a[m]??0))*(g-m))},s=r(.5),n=r(.75),i=r(.9),o=u=>!u||u<=0?0:u<=s?1:u<=n?2:u<=i?3:4;return t.map(u=>Array.isArray(u)?u.map(c=>c?.day&&!c.future&&typeof c.value=="number"?{...c,level:o(c.value)}:c):u)}function Kd(t){if(!Array.isArray(t))return[];const a={},r=Wd(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Gd(t){if(!t.length)return[];const a=[...t].sort((o,u)=>o.day.localeCompare(u.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const qd=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Yd(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Ls(t){const[a,r]=d.useState(null);return d.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Zd({data:t}){const a=Gd(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:lt,fontFamily:fr,marginBottom:4},children:qd[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:ja},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:ja},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:pr,height:pr,borderRadius:4,background:o<0?"transparent":bn[o]}},i)})},s))})]})}function Jd({data:t}){const a=Kd(t.heatmapWeeks),r=Yd(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Ls(n),o=Ls("/neon_bg.png"),u=(t.handle||"?")[0].toUpperCase(),c=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Bd,fontFamily:fr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:kn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:c*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:lt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:tt},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:tt},children:u})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:tt},children:t.handle})]})]}),e.jsxs("div",{style:{...zd,borderRadius:22,padding:wn,marginBottom:c},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:lt},children:[e.jsx("span",{children:l("share.card.annual.less")}),bn.map((g,m)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:g}},m)),e.jsx("span",{children:l("share.card.annual.more")})]}),e.jsx("div",{style:{fontSize:16,fontWeight:700,letterSpacing:"0.14em",color:"rgba(255,255,255,0.22)",textTransform:"uppercase"},children:l("share.card.annual.heatmap_title")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(3,${Vd}px)`,gap:`8px ${_n}px`,justifyContent:"center"},children:a.map(g=>e.jsx(Zd,{data:g},g.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:c,marginBottom:c},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:lr,fontSize:52,fontWeight:700,color:tt,letterSpacing:"-0.02em",lineHeight:1},children:xr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:lr,fontSize:52,fontWeight:700,color:tt,letterSpacing:"-0.02em",lineHeight:1},children:pn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:c},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:ir,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:lr,fontSize:28,fontWeight:700,color:tt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:ir,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:fr,fontSize:28,fontWeight:700,color:tt},children:s?s.name:"—"})]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:44,height:44,style:{width:44,height:44,borderRadius:8,display:"block"}}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:tt},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:ir},children:"tokentracker.cc"})]})]})]})}const vn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Qd={broadsheet:yn,"annual-report":Jd};function jn(t){return xn[t]||{width:hn,height:gn}}function Xd(t){const a=vn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Ms=d.forwardRef(function({data:a,variant:r},s){const n=Qd[r]||yn,{width:i,height:o}=jn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function ya(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const eu=440;function tu(){const[t,a]=d.useState(null),r=d.useRef(null),s=d.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return d.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function cr({onClick:t,disabled:a,children:r,emphasis:s,ariaLabel:n}){return e.jsx("button",{type:"button",onClick:t,disabled:a,"aria-label":n,className:["group relative flex items-center justify-between gap-3 w-full px-4 py-3 text-left","rounded-lg border transition-colors",s?"border-oai-black dark:border-oai-white bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black hover:opacity-90":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600",a?"opacity-60 cursor-not-allowed":"cursor-pointer"].join(" "),children:r})}function au({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=d.useState(null),[o,u]=d.useState(""),[c,g]=d.useState("annual-report"),m=d.useRef(null),{toast:x,push:h}=tu(),f=Bs(),y=d.useMemo(()=>{const k=f?.user;if(!k||typeof k!="object")return null;const j=k.user_metadata||{},A=k.profile||{},$=j.avatar_url||j.picture||A.avatar_url||k.avatar_url;return typeof $=="string"&&$.trim()?$.trim():null},[f?.user]);d.useEffect(()=>{t&&(i(null),u(r?.handle||""))},[t,r?.handle]);const w=r&&{...r,handle:o||r.handle,avatarUrl:y},{width:p,height:v}=jn(c),_=eu/p;d.useEffect(()=>{if(!t)return;const k=j=>{j.key==="Escape"&&a?.()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[t,a]);const D=d.useCallback(async()=>{const k=m.current;if(!k)return null;try{return await vd(k)}catch(j){return console.warn("[share] capture failed",j),null}},[]),C=d.useCallback(async()=>{if(n)return;i("copy");const k=await D();if(!k){h(l("share.toast.failed"),"error"),i(null);return}let j=!1;if(ya()){const A=await or(k);A&&(j=(await bd(A)).ok)}else j=await Vr(k);h(j?l("share.toast.copied"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,h]),M=d.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),L=d.useCallback(async()=>{if(n)return;i("download");const k=await D();if(!k){h(l("share.toast.failed"),"error"),i(null);return}if(ya()){const A=await or(k);if(A&&(await Ts(A,M())).ok){h(l("share.toast.downloaded"),"success"),i(null);return}}const j=As(k,M());h(j?l("share.toast.downloaded"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,M,h]),B=d.useCallback(async()=>{if(n)return;i("x");const k=await D();if(!k){h(l("share.toast.failed"),"error"),i(null);return}if(ya()){const z=await or(k);z&&(await Ts(z,M()),h(l("share.toast.downloaded"),"success"))}else await Vr(k)?h(l("share.toast.copied"),"success"):As(k,M());const j=new URL("https://twitter.com/intent/tweet");s&&j.searchParams.set("text",s);const A=f?.user?.id,$=typeof A=="string"&&A?`/u/${A}`:"/";if(j.searchParams.set("url",`https://www.tokentracker.cc${$}?ref=share`),ya())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:j.toString()})}catch{window.open(j.toString(),"_blank","noopener,noreferrer")}else window.open(j.toString(),"_blank","noopener,noreferrer");i(null)},[n,D,h,s,M,f]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:k=>{k.target===k.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:p,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Ms,{ref:m,data:w,variant:c})}),e.jsxs(Ne.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},transition:{duration:.18,ease:[.2,.8,.2,1]},className:"relative w-full max-w-[1040px] max-h-[92vh] overflow-hidden rounded-2xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-black shadow-oai-lg",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row max-h-[92vh]",children:[e.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-7 bg-oai-gray-50 dark:bg-oai-gray-950 flex items-center justify-center overflow-auto",children:e.jsxs("div",{style:{width:p*_,height:v*_,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:p,height:v,transform:`scale(${_})`,transformOrigin:"top left"},children:e.jsx(Ms,{data:w,variant:c})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:o,onChange:k=>u(k.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:vn.map(k=>e.jsx("button",{type:"button",onClick:()=>g(k.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",c===k.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Xd(k.id)},k.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(cr,{onClick:B,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(cr,{onClick:L,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(cr,{onClick:C,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(wr,{children:x?e.jsx(Ne.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},className:"pointer-events-none absolute left-1/2 bottom-4 -translate-x-1/2",children:e.jsx("div",{className:["px-4 py-2 rounded-full text-xs font-medium shadow-oai-md",x.kind==="error"?"bg-red-600 text-white":x.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:x.text})},x.id):null})]})]}):null}function ru(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:u,periodFrom:c,periodTo:g,heatmap:m,accessToken:x,userId:h,currency:f,exchangeRate:y}=t,[w,p]=d.useState(null),v=y;return d.useEffect(()=>{if(!a||!h&&!ut())return;let _=!1;return(async()=>{try{const C=await Qo({accessToken:x,userId:h,period:u==="day"||u==="custom"?"week":u,metric:"all",limit:100,offset:0});if(_)return;const L=(Array.isArray(C?.entries)?C.entries:Array.isArray(C)?C:[]).find(k=>k?.is_me===!0),B=typeof L?.rank=="number"?L.rank:null;p(B)}catch{_||p(null)}})(),()=>{_=!0}},[a,x,h,u]),d.useMemo(()=>Sd({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:w,period:u,periodFrom:c,periodTo:g,heatmap:m,currency:f,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,i,o,w,u,c,g,m,f,v])}const su=["day","week","month","total","custom"],dr=new Set(["day","hour","month"]),Ot=new Set(["day","total","custom"]),nu=["macAppBanner","statsPanel","widgetOnboarding","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],ou=["usageOverview","dataDetails"];function ur(t,a){if(typeof a=="number"&&a>0)return!0;if(typeof t=="bigint")return t>0n;if(typeof t=="number")return Number.isFinite(t)&&t>0;if(typeof t=="string"){const r=t.trim();if(!r)return!1;if(/^[0-9]+$/.test(r))try{return BigInt(r)>0n}catch{return!1}const s=Number(r);return Number.isFinite(s)&&s>0}return!1}function ba(t){return t?St(t,null):null}function Es(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function iu(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function lu(){if(typeof window>"u")return!1;const t=new URLSearchParams(window.location.search),a=String(t.get("force_install")||"").toLowerCase();return a!=="1"&&a!=="true"?!1:!iu(window.location.hostname)}function zu({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:u="/sign-in",signUpUrl:c="/sign-up",onMainContentVisible:g}){const{resolvedLocale:m}=Xo(),{currency:x,rate:h}=Ca(),{mode:f,setMode:y,formatTokens:w,formatTokensTooltip:p}=Me(),[v,_]=d.useState(!1),[D,C]=d.useState(null),[M,L]=d.useState(null),[B,k]=d.useState(!1),[j,A]=d.useState(null),[$,z]=d.useState(0),[H,E]=d.useState(0),[R,K]=d.useState(null),N=d.useMemo(()=>typeof window>"u"?!1:ei(window.location.search),[]),S=d.useMemo(()=>lu(),[]),[q,O]=d.useState(!1),ue=2200,[J,me]=d.useState(!0),[ie,xe]=d.useState(!1),[_e,fe]=d.useState(!1),[ae,Q]=d.useState(!1),[P,te]=d.useState(!1),ye=d.useRef(!1),U=ut(),he=r&&!s,le=d.useMemo(()=>he&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,he]),G=he?le:null,Y=i?ti(o):G,T=r||U||i,V=he&&Wt(G),X=r&&s&&!i,{accountView:ee,revision:se,resolving:Ke}=ai(),ce=ee&&!i,$e=ce?G:null,ze=Ke&&!i;d.useEffect(()=>{if(!r||U){C(null),L(null),k(!1),A(null);return}if(i)return;if(!V){C(null),L(null),k(!1),A(null);return}let b=!0;const F=()=>{C(null),L(null),k(!1),A(null)};return k(!0),A(null),(async()=>{let I=null;try{I=await Fe(G)}catch{I=null}if(b){if(!I){F();return}try{const W={link_code:null,expires_at:null};if(!b)return;C(typeof W?.link_code=="string"?W.link_code:null),L(typeof W?.expires_at=="string"?W.expires_at:null)}catch(W){if(!b)return;C(null),L(null),A(W?.message||"Failed to load link code")}finally{if(!b)return;k(!1)}}})(),()=>{b=!1}},[t,U,r,i,V,G,H]);const Se=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");d.useEffect(()=>{if(!Se&&(!r||U||i)){K(null);return}if(!Se&&!V){K(null);return}let b=!0;return(async()=>{let F=null;try{F=await Fe(G)}catch{F=null}if(b){if(!F&&!Se){K(null);return}try{const I=await ri({baseUrl:t,accessToken:F});if(!b)return;K(I&&typeof I=="object"?I:null)}catch{if(!b)return;K(null)}}})(),()=>{b=!1}},[V,t,G,U,i,r]);const At=d.useMemo(()=>{if(!M)return!1;const b=Date.parse(M);if(!Number.isFinite(b))return!1;const F=$||Date.now();return b<=F},[M,$]);d.useEffect(()=>{!r||U||i||!M||!At||B||(C(null),L(null),A(null),E(b=>b+1))},[At,M,B,U,r]),d.useEffect(()=>{if(!M||i)return;const b=Date.parse(M);if(!Number.isFinite(b))return;const F=Date.now();if(z(F),b<=F)return;const I=window.setTimeout(()=>z(Date.now()),b-F),W=()=>{typeof document>"u"||document.visibilityState==="visible"&&z(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",W),window.addEventListener("focus",W),()=>{window.clearTimeout(I),typeof document<"u"&&document.removeEventListener("visibilitychange",W),window.removeEventListener("focus",W)}},[M]);const be=d.useMemo(()=>Ps(),[]),ke=d.useMemo(()=>$s(),[]),Ee=d.useMemo(()=>si(),[]),Oe=i?null:a?.userId||a?.email||"default",[Dt,mt]=d.useState("month"),[Ue,Ta]=d.useState(null),[Qe,Aa]=d.useState(null),[Da,ht]=d.useState(!1),Z=N?"total":Dt,Gt=d.useMemo(()=>Z==="custom"&&Ue&&Qe?{from:Ue,to:Qe}:ni(Z,{timeZone:be,offsetMinutes:ke,now:Ee}),[Ee,Z,be,ke,Ue,Qe]),ve=Gt.from,je=Gt.to,[Re,gt]=d.useState(null),{devices:qt,accountSources:Lt,refresh:La}=fd({from:ve,to:je,timeZone:be,tzOffsetMinutes:ke,accountView:ce,accountAccessToken:$e,accountRevision:se}),He=d.useMemo(()=>qt.filter(b=>(Number(b.total_tokens)||0)>0),[qt]),Yt=d.useMemo(()=>Lt.filter(b=>(Number(b.total_tokens)||0)>0),[Lt]),at=ce&&He.length>=2,Mt=ce&&He.length+Yt.length>=2;d.useEffect(()=>{if(!at&&!Mt){Re!==null&>(null);return}Re&&!He.some(b=>b.id===Re)&>(null)},[at,Mt,He,Re]);const Zt=d.useMemo(()=>at?[{value:"",label:l("dashboard.device_filter.all")},...He.map(b=>({value:b.id,label:hr(b)||l("dashboard.device_card.unnamed")}))]:[],[at,He,m]),Ma=Mt?e.jsx(yd,{devices:He,accountSources:Yt,selectedDeviceId:Re||"",onSelectDevice:b=>gt(b||null),onRenameDevice:async(b,F)=>{const I=await Fe($e);await ui({deviceId:b,name:F,accessToken:I}),await La()}}):null,Jt=d.useMemo(()=>oi({timeZone:be,offsetMinutes:ke}),[be,ke]),xt=d.useMemo(()=>ii({timeZone:be,offsetMinutes:ke}),[be,ke]),Ea=d.useMemo(()=>`Local time (${xt})`,[xt]),Et=be,Rt=ke,Ra=Jt,rt=d.useMemo(()=>br({timeZone:be,offsetMinutes:ke,date:Ee||new Date}),[Ee,be,ke]),Qt=d.useMemo(()=>Kl({period:Z,selectedFrom:ve,selectedTo:je,todayKey:rt}),[ve,Z,je,rt]),{daily:Ve,summary:pe,rolling:Ia,source:Xt,loading:ea,error:ta,refresh:aa}=ts({baseUrl:t,accessToken:Y,guestAllowed:X,from:ve,to:je,includeDaily:Z!=="total",cacheKey:Oe,timeZone:be,tzOffsetMinutes:ke,now:Ee,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze,deviceId:Re}),{daily:ra,loading:de,refresh:oe}=ts({baseUrl:t,accessToken:Y,guestAllowed:X,from:Qt.from,to:Qt.to,includeDaily:!0,includeSummary:!1,cacheKey:Oe?`${Oe}.daily-breakdown`:"daily-breakdown",timeZone:be,tzOffsetMinutes:ke,now:Ee,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze}),{breakdown:ge,loading:Xe,refresh:Ge}=Sl({baseUrl:t,accessToken:Y,guestAllowed:X,from:ve,to:je,cacheKey:Oe,timeZone:be,tzOffsetMinutes:ke,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze,deviceId:Re}),[It,Nn]=d.useState(3),{entries:Sn,loading:Cn,refresh:vr}=vl({baseUrl:t,accessToken:Y,from:ve,to:je,timeZone:be,tzOffsetMinutes:ke}),jr=Z==="week"||Z==="month",sa=Z==="week"||Z==="month",Nr=d.useMemo(()=>Ve.filter(b=>b?.future?!1:!b?.day||!rt?!0:String(b.day)<=String(rt)),[Ve,rt]),{rows:qe,from:Tn,to:An,loading:Dn,refresh:Sr}=ji({baseUrl:t,accessToken:Y,guestAllowed:X,period:Z,from:ve,to:je,months:24,cacheKey:Oe,timeZone:Et,tzOffsetMinutes:Rt,now:Ee,sharedRows:jr?Ve:null,sharedRange:jr?{from:ve,to:je}:null,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze,deviceId:Re}),Ln=d.useMemo(()=>({baseUrl:t,accessToken:Y,guestAllowed:X,cacheKey:Oe,timeZone:Et,tzOffsetMinutes:Rt,now:Ee,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze}),[t,Y,X,Oe,Et,Rt,Ee,ce,$e,se,ze]),{daily:ft,heatmap:We,loading:Cr,refresh:Tr}=yl({baseUrl:t,accessToken:Y,guestAllowed:X,weeks:52,cacheKey:Oe,timeZone:be,tzOffsetMinutes:ke,now:Ee,accountView:ce,accountAccessToken:$e,accountRevision:se,accountViewResolving:ze,deviceId:Re}),{data:na,refresh:Ar}=Ni();d.useEffect(()=>{na&&typeof na=="object"&&li(na)},[na]);const Pe=d.useMemo(()=>Z==="day"?"hour":Z==="total"?"month":"day",[Z]),Mn=d.useMemo(()=>rs(Pe),[Pe]),oa="day",En=d.useMemo(()=>rs(oa),[]),[Be,Dr]=d.useState(()=>({key:"day",dir:"desc"}));d.useEffect(()=>{Dr(b=>!dr.has(b.key)||b.key===Pe?b:{key:Pe,dir:b.dir})},[Pe]);const pt=d.useMemo(()=>dr.has(Be.key)&&Be.key!==Pe?{...Be,key:Pe}:Be,[Pe,Be]),ia=d.useMemo(()=>{if(Z==="day")return Array.isArray(qe)?qe.filter(I=>I?.hour&&!I?.future):[];if(Z==="total"){const I=Array.isArray(qe)?qe.filter(W=>W?.month&&!W?.future):[];return Bl(I)}const b=Nr;return!b.some(I=>!I?.missing&&!I?.future)&&Ve.length>0?Ve.filter(I=>!I?.future).slice(-30).filter(I=>I?.day):b},[Z,qe,Nr,Ve]),Ft=d.useMemo(()=>ss(ia,pt),[ia,pt]),Lr=d.useMemo(()=>ia.some(b=>!b?.missing&&!b?.future),[ia]),Fa=d.useMemo(()=>{if(!Ot.has(Z))return 1;const b=Math.ceil(Ft.length/va);return b>0?b:1},[Z,Ft.length]),[$a,la]=d.useState(0);d.useEffect(()=>{if(!Ot.has(Z)){la(0);return}la(b=>Math.min(b,Fa-1))},[Fa,Z]),d.useEffect(()=>{Ot.has(Z)&&la(0)},[Z,Be.dir,Be.key]);const Rn=d.useMemo(()=>Ot.has(Z)?zl(Ft,$a,va):Ft,[$a,Z,Ft]),Mr=d.useMemo(()=>Gl(ra,{period:Z}),[ra,Z]),yt=d.useMemo(()=>dr.has(Be.key)?{...Be,key:oa}:Be,[Be]),In=d.useMemo(()=>ss(Mr,yt),[Mr,yt]),Fn=d.useMemo(()=>sa?Ve:Z==="day"?Array.isArray(qe)?qe.filter(b=>b?.hour):[]:qe,[Ve,Z,qe,sa]),$n=sa?ve:Tn,Pn=sa?je:An;function Bn(b,F){if(b?.future)return"—";if(b?.missing)return l("shared.status.unsynced");if(F.endsWith("_tokens")){const I=F==="total_tokens"?ba(b):b?.[F];return e.jsx("span",{title:p(I),children:w(I)})}return _a(b?.[F])}function zn(b){const F=b?.[Pe];if(F==null)return"";const I=String(F);if(Pe==="hour"){const[W,Ae]=I.split("T");if(W&&Ae)return`${W} ${Ae.slice(0,5)}`}return I}function On(b){const F=b?.[oa];return F==null?"":String(F)}function Un(b){Dr(F=>F.key===b?{key:b,dir:F.dir==="asc"?"desc":"asc"}:{key:b,dir:"desc"})}function Hn(b){return pt.key!==b?"none":pt.dir==="asc"?"ascending":"descending"}function Vn(b){return pt.key!==b?"":pt.dir==="asc"?"▲":"▼"}function Wn(b){return yt.key!==b?"none":yt.dir==="asc"?"ascending":"descending"}function Kn(b){return yt.key!==b?"":yt.dir==="asc"?"▲":"▼"}const Pa=d.useMemo(()=>{if(!r&&!U&&!i&&!Se)return 0;const b=Number(We?.active_days);if(Number.isFinite(b))return b;let F=0;const I=new Set,W=(we,Ie,De)=>{typeof we!="string"||!we||I.has(we)||ur(Ie,De)&&(I.add(we),F+=1)};if(Array.isArray(ft))for(const we of ft)W(we?.day,ba(we));const Ae=Array.isArray(We?.weeks)?We.weeks:[];for(const we of Ae)for(const Ie of Array.isArray(we)?we:[]){const De=Es(Ie);W(Ie?.day,De,Ie?.level)}return F},[r,U,We?.active_days,We?.weeks,ft]),[Er,Rr]=d.useState("month"),Gn=d.useCallback(b=>{b==="custom"?(Rr(F=>F==="custom"?"month":F),mt(F=>Ue&&Qe?"custom":F),ht(!0)):(mt(b),Rr(b),ht(!1))},[Ue,Qe]),qn=d.useCallback((b,F)=>{Ta(b),Aa(F),mt("custom"),ht(!1)},[]),Yn=d.useCallback(b=>{ht(b),!b&&Dt==="custom"&&!Ue&&mt(Er)},[Dt,Ue,Er]),bt=d.useCallback(async()=>{ce&&ci(),ce||di(),await Promise.all([aa(),Tr(),Sr(),Ge(),vr(),oe()])},[ce,oe,Tr,Ge,vr,Sr,aa]),Ir=d.useCallback(async()=>{await Promise.all([bt(),Ar()])},[bt,Ar]),Ba=d.useRef(null);d.useEffect(()=>{if(!Se||U||ce)return;Ba.current||(Ba.current=Wr({auto:!0,background:!0,allLocalSources:!0}));let b=!0;return Ba.current.then(()=>{if(b)return bt()}).catch(F=>{b&&console.warn("[DashboardPage] Reload sync failed:",F)}),()=>{b=!1}},[Se,U,ce,bt]),d.useEffect(()=>{if(!Se||U||ce)return;const b=Vl({refresh:bt,onError:F=>console.warn("[DashboardPage] Automatic usage refresh failed:",F)});return()=>b.stop()},[Se,U,ce,bt]);const Zn=d.useCallback(async()=>{Q(!0);try{Se&&await Wr(),await Ir()}catch(b){console.error("[DashboardPage] Refresh failed:",b)}finally{Q(!1)}},[Se,Ir]),ca=ae||ea||de||Cr||Dn||Xe||Cn,za=!P&&(ze||ce&&ca&&!Lr),Jn=d.useMemo(()=>l("shared.data_source",{source:String(Xt||"edge").toUpperCase()}),[Xt,m]),da=d.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Qn="",Fr=d.useMemo(()=>!da||da.includes("@")?l("dashboard.identity.fallback"):da,[da]),$r=d.useMemo(()=>Fr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Fr]),Pr=d.useMemo(()=>i?l("dashboard.identity.fallback"):$r,[$r,Qn,i]),Br=d.useMemo(()=>{let b=null;const F=W=>{typeof W!="string"||!W||(!b||W<b)&&(b=W)};if(Array.isArray(ft))for(const W of ft)W?.day&&ur(ba(W))&&F(W.day);const I=Array.isArray(We?.weeks)?We.weeks:[];for(const W of I)for(const Ae of Array.isArray(W)?W:[]){if(!Ae?.day)continue;const we=Es(Ae),Ie=Ae?.level;ur(we,Ie)&&F(Ae.day)}return b},[We?.weeks,ft]),Xn=d.useMemo(()=>i?[]:(Array.isArray(R?.subscriptions?.items)?R.subscriptions.items:[]).map(I=>{const W=typeof I?.tool=="string"?I.tool.trim():"",we=(typeof I?.plan_type=="string"?I.plan_type:typeof I?.planType=="string"?I.planType:"").trim();return!W||!we?null:{tool:W,planType:we,provider:typeof I?.provider=="string"?I.provider.trim():"",product:typeof I?.product=="string"?I.product.trim():"",rateLimitTier:typeof I?.rate_limit_tier=="string"?I.rate_limit_tier.trim():typeof I?.rateLimitTier=="string"?I.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,R]),eo=e.jsx(Si,{heatmap:We,timeZoneLabel:Jt,timeZoneShortLabel:xt,hideLegend:N,defaultToLatestMonth:N}),to=d.useMemo(()=>`${ve}..${je}`,[ve,Z,je]),ao=l("usage.summary.total"),Te=pe!=null,kt=Te?ba(pe):0,ro=w(kt),so=d.useCallback(()=>{y(f===ka.COMPACT?ka.FULL:ka.COMPACT)},[y,f]),no=l("dashboard.core_index.collapse_label"),oo=l("dashboard.core_index.expand_label"),io=l("dashboard.core_index.collapse_aria"),lo=l("dashboard.core_index.expand_aria"),co=!N,wt=l("shared.placeholder.short"),Oa=d.useMemo(()=>{const b=Array.isArray(ge?.sources)?ge.sources:[];let F=null,I=0;for(const Ie of b){const De=St(Ie?.totals);!Number.isFinite(De)||De<=0||De>I&&(I=De,F=Ie)}let W=wt,Ae=wt,we="0.0";if(F&&I>0){W=F?.source?String(F.source).toUpperCase():wt;const Ie=Array.isArray(F?.models)?F.models:[];let De=0;for(const Ga of Ie){const ma=St(Ga?.totals);!Number.isFinite(ma)||ma<=0||ma>De&&(De=ma,Ae=Ga?.model?String(Ga.model):wt)}De>0&&(we=(De/I*100).toFixed(1))}return{agentName:W,modelName:Ae,modelPercent:we}},[ge,wt]),Ua=_a(kt),uo=l("dashboard.screenshot.twitter_text",{total_tokens:Ua==="-"?wt:Ua,agent_name:Oa.agentName,model_name:Oa.modelName,model_percent:Oa.modelPercent}),mo=d.useMemo(()=>N?[]:su,[N]),ho=d.useMemo(()=>[{label:l("usage.metric.total"),value:Te?w(kt):"—",title:Te?p(kt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Te?w(pe?.input_tokens):"—",title:Te?p(pe?.input_tokens):void 0},{label:l("usage.metric.output"),value:Te?w(pe?.output_tokens):"—",title:Te?p(pe?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Te?w(pe?.cached_input_tokens):"—",title:Te?p(pe?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Te?w(pe?.reasoning_output_tokens):"—",title:Te?p(pe?.reasoning_output_tokens):void 0}],[pe?.cached_input_tokens,pe?.input_tokens,pe?.output_tokens,pe?.reasoning_output_tokens,kt,Te,w,p]),Ha=d.useMemo(()=>Sa(pe?.total_cost_usd,{currency:x,rate:h}),[pe?.total_cost_usd,x,h]),go=d.useMemo(()=>pe?.conversation_count??null,[pe?.conversation_count]),zr=d.useMemo(()=>Yl(ge,{copyFn:l}),[ge]),Or=d.useMemo(()=>Jl(ge,{limit:3,copyFn:l}),[ge]),xo=ru({enabled:q,handle:Pr,startDate:Br,activeDays:Pa,summary:pe,topModels:Or,period:Z,periodFrom:ve,periodTo:je,heatmap:We,accessToken:typeof Y=="string"?Y:null,userId:a?.userId||null,currency:x,exchangeRate:h}),fo=d.useCallback(()=>O(!0),[]),po=d.useCallback(()=>O(!1),[]),yo=d.useCallback(()=>_(!0),[]),bo=d.useCallback(()=>_(!1),[]),ko=Ha&&Ha!=="-"&&zr.length>0,$t=l("dashboard.install.cmd.init"),Va=At?null:D,Wa=Va?l("dashboard.install.cmd.init_link_code",{link_code:Va}):$t,wo=$t,_o=l("dashboard.install.cmd.sync"),vo=Va?l("dashboard.install.copy"):l("dashboard.install.copy_base"),jo=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const No=!!(R?.install?.has_active_device_token??R?.install?.hasActiveDeviceToken),So=Ol({publicMode:i,screenshotMode:N,forceInstall:S,accessEnabled:T,heatmapLoading:Cr,activeDays:Pa,hasActiveDeviceToken:No}),Co=l("dashboard.install.prompt"),To=d.useCallback(async()=>{!Wa||!await Kr(Wa)||(xe(!0),window.setTimeout(()=>xe(!1),2e3))},[Wa]);d.useCallback(async()=>{!$t||!await Kr($t)||(fe(!0),window.setTimeout(()=>fe(!1),2e3))},[$t]);const Ka=d.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[m]),[Ao,Do]=d.useMemo(()=>{const b=Ka.split("{{cmd}}");return b.length===1?[Ka,""]:[b[0],b.slice(1).join("{{cmd}}")]},[Ka]),Pt=s&&!i,Bt=!r&&!U&&!s&&!Se&&!i;d.useEffect(()=>{Pt||Bt||za||te(!0)},[za,Bt,Pt]);const ua=wl(nu,ou);return d.useEffect(()=>{ye.current||Pt||Bt||ca||(ye.current=!0,g?.())},[g,Bt,Pt,ca]),e.jsxs(e.Fragment,{children:[e.jsx(xd,{copy:l,onOpenShare:fo,screenshotMode:N,showExpiredGate:Pt,showAuthGate:Bt,identityDisplayName:Pr,identityStartDate:Br,activeDays:Pa,identitySubscriptions:Xn,identityScrambleDurationMs:ue,projectUsageEntries:Sn,projectUsageLimit:It,setProjectUsageLimit:Nn,projectDetailQuery:{from:ve,to:je,timeZone:be,tzOffsetMinutes:ke},topModels:Or,signedIn:r,publicMode:i,isLocalMode:Se,shouldShowInstall:So,installPrompt:Co,handleCopyInstall:To,installCopied:ie,installCopiedLabel:jo,installCopyLabel:vo,installInitCmdDisplay:wo,linkCodeLoading:B,linkCodeError:j,trendRowsForDisplay:Fn,trendFromForDisplay:$n,trendToForDisplay:Pn,trendZoomConfig:Ln,usageFrom:ve,usageTo:je,period:Z,trendTimeZoneLabel:Ra,activityHeatmapBlock:eo,periodsForDisplay:mo,setSelectedPeriod:Gn,customFrom:Ue,customTo:Qe,onCustomRangeApply:qn,customRangeOpen:Da,onCustomRangeOpenChange:Yn,metricsRows:ho,summaryLabel:ao,summaryValue:ro,hasSummary:Te,summaryLoading:ea,providersLoading:Xe,summaryFullValue:Ua,onToggleSummaryFormat:so,summaryTotalTokensRaw:re(kt)||0,summaryCostValue:Ha,summaryConversationsValue:go,rollingUsage:Ia,costInfoEnabled:ko,openCostModal:yo,allowBreakdownToggle:co,coreIndexCollapsed:J,setCoreIndexCollapsed:me,coreIndexCollapseLabel:no,coreIndexExpandLabel:oo,coreIndexCollapseAria:io,coreIndexExpandAria:lo,refreshAll:Zn,usageLoadingState:ca,announceUsageLoading:ae,initialDashboardLoading:za,usageError:ta,rangeLabel:to,timeZoneRangeLabel:Ea,usageSourceLabel:Jn,fleetData:zr,hasDetailsActual:Lr,dailyEmptyPrefix:Ao,installSyncCmd:_o,dailyEmptySuffix:Do,detailsColumns:Mn,ariaSortFor:Hn,toggleSort:Un,sortIconFor:Vn,pagedDetails:Rn,dailyBreakdownRows:In,dailyBreakdownColumns:En,dailyBreakdownAriaSortFor:Wn,dailyBreakdownSortIconFor:Kn,dailyBreakdownDateKey:oa,detailsDateKey:Pe,renderDetailDate:zn,renderDailyBreakdownDate:On,renderDetailCell:Bn,DETAILS_PAGED_PERIODS:Ot,detailsPageCount:Fa,detailsPage:$a,setDetailsPage:la,costModalOpen:v,closeCostModal:bo,deviceOptions:Zt,selectedDevice:Re||"",onDeviceChange:b=>gt(b||null),deviceUsageBlock:Ma,leftCardOrder:ua.left.order,onLeftReorder:ua.left.reorder,rightCardOrder:ua.right.order,onRightReorder:ua.right.reorder}),e.jsx(au,{open:q,onClose:po,data:xo,twitterText:uo})]})}export{zu as DashboardPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as p,r as c,j as e,h as b}from"./__vite-browser-external-
|
|
1
|
+
import{a as p,r as c,j as e,h as b}from"./__vite-browser-external-hJyUffEJ.js";const f={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_APP_VERSION:"0.83.3",VITE_INSFORGE_ANON_KEY:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3OC0xMjM0LTU2NzgtOTBhYi1jZGVmMTIzNDU2NzgiLCJlbWFpbCI6ImFub25AaW5zZm9yZ2UuY29tIiwicm9sZSI6ImFub24iLCJpYXQiOjE3ODExNDU5NDd9.T0auta_IrVIh0uXW1bob5QSnzvsnJmN28r5XkSGEuQY",VITE_INSFORGE_BASE_URL:"https://srctyff5.us-east.insforge.app"};function x(){return b(),`${(f&&"https://srctyff5.us-east.insforge.app"||"https://srctyff5.us-east.insforge.app").replace(/\/$/,"")}/functions/tokentracker-device-flow-grant`}function l(a){return(a||"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9-]/g,"")}function k(){const a=p(),[m,u]=c.useState(""),[t,r]=c.useState({kind:"idle",message:""});c.useEffect(()=>{try{const i=new URLSearchParams(window.location.search).get("user_code");i&&u(l(i))}catch{}},[]);async function g(d){if(d?.preventDefault?.(),!a?.signedIn){r({kind:"error",message:"Please sign in first."});return}const i=l(m);if(!/^[A-HJKMNP-Z2-9]{4}-[A-HJKMNP-Z2-9]{4}$/.test(i)){r({kind:"error",message:"Invalid code format. Expected XXXX-XXXX."});return}r({kind:"working",message:"Approving…"});try{const n=await a.getAccessToken?.();if(!n){r({kind:"error",message:"No access token — please sign in again."});return}const s=await fetch(x(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({user_code:i})}),o=await s.json().catch(()=>({}));s.ok?r({kind:"success",message:o.status==="already_approved"?`Already approved earlier${o.client_info?" ("+o.client_info+")":""}.`:`Approved${o.client_info?" for "+o.client_info:""}. You can close this tab — your CLI will pick it up within a few seconds.`}):s.status===404?r({kind:"error",message:"Code not found. Double-check what your CLI printed."}):s.status===410?r({kind:"error",message:"Code expired. Re-run `tracker device-login` and try again."}):s.status===401?r({kind:"error",message:"Session expired. Sign out, sign in, and try again."}):r({kind:"error",message:o?.error||`Server error (HTTP ${s.status}).`})}catch(n){r({kind:"error",message:`Network error: ${n?.message||n}`})}}return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-oai-gray-950 px-6 py-12",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-8",children:[e.jsx("h1",{className:"text-2xl font-semibold text-oai-gray-900 dark:text-white mb-2",children:"Approve your CLI"}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 mb-6",children:"Type the code your CLI showed you. We'll link it to your account so token usage from that machine flows into your leaderboard profile."}),a?.signedIn?null:e.jsx("div",{className:"rounded-md border border-amber-200 bg-amber-50 dark:bg-amber-900/20 dark:border-amber-800 p-4 mb-4",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Sign in first, then return to this page."})}),e.jsxs("form",{onSubmit:g,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-medium uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400 mb-1",children:"CLI code"}),e.jsx("input",{type:"text",value:m,onChange:d=>u(l(d.target.value)),placeholder:"XXXX-XXXX",spellCheck:!1,autoCapitalize:"characters",maxLength:9,className:"w-full font-mono text-xl tracking-widest text-center rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-900 dark:text-white px-4 py-3 focus:outline-none focus:ring-inset focus:ring-2 focus:ring-emerald-600"})]}),e.jsx("button",{type:"submit",disabled:t.kind==="working"||!a?.signedIn,className:"w-full rounded-md bg-emerald-600 hover:bg-emerald-500 disabled:bg-oai-gray-300 disabled:cursor-not-allowed text-white font-medium py-3 transition-colors",children:t.kind==="working"?"Approving…":"Approve"})]}),t.kind==="success"&&e.jsx("div",{className:"mt-4 rounded-md border border-emerald-200 bg-emerald-50 dark:bg-emerald-900/20 dark:border-emerald-800 p-4",children:e.jsx("p",{className:"text-sm text-emerald-700 dark:text-emerald-300",children:t.message})}),t.kind==="error"&&e.jsx("div",{className:"mt-4 rounded-md border border-red-200 bg-red-50 dark:bg-red-900/20 dark:border-red-800 p-4",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:t.message})})]})})}export{k as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as p,w as d,x as m,y as C,z as g}from"./__vite-browser-external-
|
|
1
|
+
import{r as p,w as d,x as m,y as C,z as g}from"./__vite-browser-external-hJyUffEJ.js";import{u as v}from"./DialogTitle-C6n2pohw.js";const h=p.forwardRef(function(e,o){const{render:x,className:E,style:R,disabled:t=!1,nativeButton:n=!0,...a}=e,{store:s}=v(),r=s.useState("open"),{getButtonProps:l,buttonRef:i}=d({disabled:t,native:n}),u={disabled:t};function c(f){r&&s.setOpen(!1,C(g,f.nativeEvent))}return m("button",e,{state:u,ref:[o,i],props:[{onClick:c},a,l]})});export{h as D};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as n,x as a}from"./__vite-browser-external-hJyUffEJ.js";import{u as p}from"./DialogTitle-C6n2pohw.js";import{u as c}from"./useScrollLock-JHdC5cyV.js";const g=n.forwardRef(function(e,r){const{render:l,className:u,style:m,id:s,...t}=e,{store:i}=p(),o=c(s);return i.useSyncedValueWithCleanup("descriptionElementId",o),a("p",e,{ref:r,props:[{id:o},t]})});export{g as D};
|