tokentracker-cli 1.5.1 → 1.5.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.
Files changed (130) hide show
  1. package/dashboard/dist/assets/{AchievementBadge-mB7HZSGE.js → AchievementBadge-uuDGO9Mq.js} +1 -1
  2. package/dashboard/dist/assets/{AchievementsPage-DLzeq_eo.js → AchievementsPage-BCTVT7Jo.js} +2 -2
  3. package/dashboard/dist/assets/{AchievementsSection-DrXQyDns.js → AchievementsSection-B6fJSJSr.js} +1 -1
  4. package/dashboard/dist/assets/{BadgeDetailModal-WrgKRybi.js → BadgeDetailModal-FjUN__9G.js} +1 -1
  5. package/dashboard/dist/assets/{BotAnimated-DFRaixVK.js → BotAnimated-B-KqY_Wr.js} +1 -1
  6. package/dashboard/dist/assets/{Card-bFq2tlO8.js → Card-DS8T8piP.js} +1 -1
  7. package/dashboard/dist/assets/{CloudCheckoutPage-gwhGxavy.js → CloudCheckoutPage-_0UjsFPu.js} +1 -1
  8. package/dashboard/dist/assets/{CloudPage-BD4iBYeZ.js → CloudPage-BstgVBaV.js} +2 -2
  9. package/dashboard/dist/assets/{CommandPalette-C_KlPl0U.js → CommandPalette-DtVsYZgc.js} +1 -1
  10. package/dashboard/dist/assets/{CommunityStatsModal-Cl1Bgv8M.js → CommunityStatsModal-DTpEJqV3.js} +1 -1
  11. package/dashboard/dist/assets/{ConfirmModal-NWoYevYC.js → ConfirmModal-Lfdh2vr7.js} +1 -1
  12. package/dashboard/dist/assets/{Controls-D2-D2cfA.js → Controls-DpwQ7pkq.js} +1 -1
  13. package/dashboard/dist/assets/DashboardPage-DUFWejkE.js +1 -0
  14. package/dashboard/dist/assets/{DateRangePopover-8EMVXuH6.js → DateRangePopover-CrWgrzT2.js} +1 -1
  15. package/dashboard/dist/assets/{DevicePage-DbP8d6bM.js → DevicePage-DbK5KWJS.js} +1 -1
  16. package/dashboard/dist/assets/{DialogClose-CEstgLa1.js → DialogClose-Dd2B_o03.js} +1 -1
  17. package/dashboard/dist/assets/DialogDescription-CLy0arbt.js +1 -0
  18. package/dashboard/dist/assets/{DialogTitle-DP5TLLbz.js → DialogTitle-3JQBVha3.js} +1 -1
  19. package/dashboard/dist/assets/{ElectricLogo-Uvi3yMum.js → ElectricLogo-LYAqG8pG.js} +1 -1
  20. package/dashboard/dist/assets/{FadeIn-Dpzihg6f.js → FadeIn-DhDvUor7.js} +1 -1
  21. package/dashboard/dist/assets/{HeaderGithubStar-DllqemKr.js → HeaderGithubStar-9f1XmgYC.js} +1 -1
  22. package/dashboard/dist/assets/{HoverTooltip-Dc-TAH6l.js → HoverTooltip-BXhHAkP7.js} +1 -1
  23. package/dashboard/dist/assets/{IpCheckPage-jd1D5ZKX.js → IpCheckPage-ChPdDeMl.js} +1 -1
  24. package/dashboard/dist/assets/{LandingPage-CB1ZVw-a.js → LandingPage-DnJ7Y9zw.js} +2 -2
  25. package/dashboard/dist/assets/{LeaderboardPage-Bt2cRRmE.js → LeaderboardPage-BF9isLzu.js} +2 -2
  26. package/dashboard/dist/assets/{LeaderboardProBadge-BVlyVOFf.js → LeaderboardProBadge-BM4JKgkC.js} +1 -1
  27. package/dashboard/dist/assets/{LeaderboardProfileModal-CwQFRJg_.js → LeaderboardProfileModal-DfZABOpN.js} +3 -3
  28. package/dashboard/dist/assets/{LeaderboardProfilePage-CeqcTbUG.js → LeaderboardProfilePage-BaZ38iT5.js} +1 -1
  29. package/dashboard/dist/assets/LimitsPage-C7LbG3LX.js +6 -0
  30. package/dashboard/dist/assets/{LocalOnlyNotice-B2_HoCVD.js → LocalOnlyNotice-DvhlYoqQ.js} +1 -1
  31. package/dashboard/dist/assets/{LoginCard-nw9JOc2d.js → LoginCard-g_Gbnzhs.js} +1 -1
  32. package/dashboard/dist/assets/{LoginModal-BHNLTK1D.js → LoginModal-DkJrI6b7.js} +1 -1
  33. package/dashboard/dist/assets/{LoginPage-LI2GZKhM.js → LoginPage-CqCKSo0n.js} +1 -1
  34. package/dashboard/dist/assets/{PetPage-CK6sPeI0.js → PetPage-DbF7ROsj.js} +2 -2
  35. package/dashboard/dist/assets/{PopoverPopup-BsXchEVa.js → PopoverPopup-4WuH41ZT.js} +1 -1
  36. package/dashboard/dist/assets/{ProviderIcon-vgCEy0dh.js → ProviderIcon-6j0A2KD9.js} +1 -1
  37. package/dashboard/dist/assets/{ResetPasswordPage-B4CPj2vX.js → ResetPasswordPage-DBd-iwuM.js} +1 -1
  38. package/dashboard/dist/assets/{Select-BkAy6P2r.js → Select-BBEpLeiG.js} +1 -1
  39. package/dashboard/dist/assets/{SelectItemText-C0RNqDrD.js → SelectItemText-Cn_U_rrO.js} +1 -1
  40. package/dashboard/dist/assets/{SelfHostPage-B-_w-Z-a.js → SelfHostPage-2WZc6Rml.js} +1 -1
  41. package/dashboard/dist/assets/ServiceStatusPage-B-g4MDl0.js +1 -0
  42. package/dashboard/dist/assets/{SessionsPage-CmWXBqD2.js → SessionsPage-CWS0iQ1L.js} +1 -1
  43. package/dashboard/dist/assets/{SettingsPage-CA70zP-t.js → SettingsPage-rXNr96i-.js} +3 -3
  44. package/dashboard/dist/assets/{SkillsPage-CNamhfzU.js → SkillsPage-CudTvbZL.js} +1 -1
  45. package/dashboard/dist/assets/{TokenGalaxy-CXrVBSk6.js → TokenGalaxy-BRKrbTsJ.js} +1 -1
  46. package/dashboard/dist/assets/{TooltipPopup-CR4MqElX.js → TooltipPopup-CsLKXhWC.js} +1 -1
  47. package/dashboard/dist/assets/{TrendMonitor-DQfcrEve.js → TrendMonitor-8onUTbkk.js} +1 -1
  48. package/dashboard/dist/assets/{WidgetsPage-BBXxtZbP.js → WidgetsPage-CcwE0lz8.js} +1 -1
  49. package/dashboard/dist/assets/{WrappedPage-C8i2KlMF.js → WrappedPage-Cj9LLYqP.js} +1 -1
  50. package/dashboard/dist/assets/__vite-browser-external-07djSGmy.js +45 -0
  51. package/dashboard/dist/assets/__vite-browser-external-BDldtsD2.css +1 -0
  52. package/dashboard/dist/assets/{agent-logos-CxQb8vir.js → agent-logos-ChBA1nAH.js} +1 -1
  53. package/dashboard/dist/assets/{arrow-left-D6zkcLVt.js → arrow-left-Bb5mfoPc.js} +1 -1
  54. package/dashboard/dist/assets/{arrow-right-BGb-XVn_.js → arrow-right-D1Ti2XUI.js} +1 -1
  55. package/dashboard/dist/assets/{arrow-up-right-XTStagDJ.js → arrow-up-right-B_CjA_y8.js} +1 -1
  56. package/dashboard/dist/assets/{calendar-days-Cz3NGZiS.js → calendar-days-DdfrAqie.js} +1 -1
  57. package/dashboard/dist/assets/{check-1z_vmHPD.js → check-29zGw1MK.js} +1 -1
  58. package/dashboard/dist/assets/{chevron-down-CkSBY3bE.js → chevron-down-DAzlFX7g.js} +1 -1
  59. package/dashboard/dist/assets/{cloud-checkout-pD5C4r_S.js → cloud-checkout-C2SeCjFM.js} +1 -1
  60. package/dashboard/dist/assets/{composite-BtDzx3a2.js → composite-DIf735Hq.js} +1 -1
  61. package/dashboard/dist/assets/{copy-Ctv_wxuD.js → copy-BOuOM0HQ.js} +1 -1
  62. package/dashboard/dist/assets/{download-DKbKMGSR.js → download-50tQRpGe.js} +1 -1
  63. package/dashboard/dist/assets/{external-link-g9cU017t.js → external-link-BhlQClVe.js} +1 -1
  64. package/dashboard/dist/assets/{flame-DZq3kXUt.js → flame-CeGfA-0L.js} +1 -1
  65. package/dashboard/dist/assets/{format-tokens-CXQfx0PC.js → format-tokens-Cq7YiAkJ.js} +1 -1
  66. package/dashboard/dist/assets/{gift-CKlKjGP6.js → gift-Do-UFhiT.js} +1 -1
  67. package/dashboard/dist/assets/{icons-xPGMnBjl.js → icons-C6EZ_HmP.js} +1 -1
  68. package/dashboard/dist/assets/{index-fVbP5wOv.js → index-BFrbVqsm.js} +1 -1
  69. package/dashboard/dist/assets/{index-CDBOKcDh.js → index-BWhbBAd9.js} +1 -1
  70. package/dashboard/dist/assets/{index-Dl0oFLNr.js → index-D9kwYWLX.js} +1 -1
  71. package/dashboard/dist/assets/{index-BwOjMtB2.js → index-c0crpe9Z.js} +1 -1
  72. package/dashboard/dist/assets/{info-D9xNIuGh.js → info-B4MXmsNE.js} +1 -1
  73. package/dashboard/dist/assets/{link-2-Bk5wYt2n.js → link-2-DuWCslzl.js} +1 -1
  74. package/dashboard/dist/assets/{loader-circle-CcN3pHWb.js → loader-circle-C2I3NZAO.js} +1 -1
  75. package/dashboard/dist/assets/{local-usage-transfer-CYcy1ici.js → local-usage-transfer-BQasvsUF.js} +1 -1
  76. package/dashboard/dist/assets/{modifiers.esm-DbpEzkJe.js → modifiers.esm-DbeNS6FT.js} +1 -1
  77. package/dashboard/dist/assets/{monitor-smartphone-WkWv1qIS.js → monitor-smartphone-C6Y4ktsc.js} +1 -1
  78. package/dashboard/dist/assets/{play-2yZGWMes.js → play-CwgcDJC2.js} +1 -1
  79. package/dashboard/dist/assets/{plus-mOF8tG1F.js → plus-B796wsUO.js} +1 -1
  80. package/dashboard/dist/assets/{provider-display-7gaOvgMp.js → provider-display-Cw26RFDm.js} +1 -1
  81. package/dashboard/dist/assets/{react-CdPiPDhk.js → react-d7Bk1-_K.js} +1 -1
  82. package/dashboard/dist/assets/{safePolygon-C7FJLAlh.js → safePolygon-CDE0dNv_.js} +1 -1
  83. package/dashboard/dist/assets/{search-C63nCrjo.js → search-DtKvsdRs.js} +1 -1
  84. package/dashboard/dist/assets/{server-BaG1rnuv.js → server-gAURHUyz.js} +1 -1
  85. package/dashboard/dist/assets/{shield-check-D_4-Cm6L.js → shield-check-DFVdDTwh.js} +1 -1
  86. package/dashboard/dist/assets/{skills-api-DfbzwpDv.js → skills-api-2rdPUrJI.js} +1 -1
  87. package/dashboard/dist/assets/{sortable.esm-D-v8FRX5.js → sortable.esm-DFlfwnJr.js} +1 -1
  88. package/dashboard/dist/assets/{store-Dv_FYrXK.js → store-BKPCk_de.js} +1 -1
  89. package/dashboard/dist/assets/{terminal-FQi6MaYt.js → terminal-BtWFakvS.js} +1 -1
  90. package/dashboard/dist/assets/{trash-TbK96dEz.js → trash-bpr9zTAM.js} +1 -1
  91. package/dashboard/dist/assets/{use-community-stats-DGoWVZuk.js → use-community-stats-DMnGgLne.js} +1 -1
  92. package/dashboard/dist/assets/{use-latest-request-guard-Dg6uSaYt.js → use-latest-request-guard-BSBlJJHe.js} +1 -1
  93. package/dashboard/dist/assets/use-limits-display-prefs-eYlvnUKn.js +1 -0
  94. package/dashboard/dist/assets/{use-native-settings-DIk0AF3b.js → use-native-settings-OthqiF6g.js} +1 -1
  95. package/dashboard/dist/assets/{use-ordered-list-CUqV3Zgl.js → use-ordered-list-DpAtr0R-.js} +1 -1
  96. package/dashboard/dist/assets/use-reduced-motion-DF0grwHs.js +1 -0
  97. package/dashboard/dist/assets/{use-transform-D_-w22c8.js → use-transform-BRz9dz_2.js} +1 -1
  98. package/dashboard/dist/assets/use-usage-limits-CwmhudAX.js +1 -0
  99. package/dashboard/dist/assets/{useCurrency-B_AuLCsL.js → useCurrency-CAA-tQ27.js} +1 -1
  100. package/dashboard/dist/assets/{usePositioner-DfxvIif8.js → usePositioner-Cj2DPmwM.js} +1 -1
  101. package/dashboard/dist/assets/{useTokenFormat-bbO13V4s.js → useTokenFormat-Bf5-f7Hx.js} +1 -1
  102. package/dashboard/dist/assets/{zap-k07-EXTK.js → zap-B8Fg6PaC.js} +1 -1
  103. package/dashboard/dist/index.html +6 -2
  104. package/dashboard/dist/ip-check.html +2 -2
  105. package/dashboard/dist/leaderboard.html +2 -2
  106. package/dashboard/dist/share.html +2 -2
  107. package/package.json +1 -1
  108. package/src/commands/serve.js +22 -13
  109. package/src/lib/codex-rollout-parser.js +43 -6
  110. package/src/lib/codex-usage-record.js +21 -0
  111. package/src/lib/deepseek-status.js +157 -0
  112. package/src/lib/local-api.js +44 -4
  113. package/src/lib/pricing/curated-overrides.json +94 -0
  114. package/src/lib/pricing/seed-snapshot.json +1 -1
  115. package/src/lib/provider-status.js +15 -2
  116. package/src/lib/qoder-limits.js +95 -23
  117. package/src/lib/rollout.js +68 -14
  118. package/src/lib/session-analytics.js +10 -3
  119. package/src/lib/usage-limits.js +187 -43
  120. package/src/lib/workbuddy-limits.js +292 -27
  121. package/src/lib/zcode-limits.js +457 -42
  122. package/dashboard/dist/assets/DashboardPage-vITMnPXx.js +0 -1
  123. package/dashboard/dist/assets/DialogDescription-0wcygxtH.js +0 -1
  124. package/dashboard/dist/assets/LimitsPage-Bp4ZORmR.js +0 -6
  125. package/dashboard/dist/assets/ServiceStatusPage-5YevsGGD.js +0 -1
  126. package/dashboard/dist/assets/__vite-browser-external-BEEzY7mq.js +0 -45
  127. package/dashboard/dist/assets/__vite-browser-external-Br-KAXh6.css +0 -1
  128. package/dashboard/dist/assets/use-limits-display-prefs-Djbdp7fi.js +0 -1
  129. package/dashboard/dist/assets/use-reduced-motion-DMCok-vZ.js +0 -1
  130. package/dashboard/dist/assets/use-usage-limits-h7aGsIQr.js +0 -1
@@ -0,0 +1 @@
1
+ import{o as _r,r as u,j as e,L as ti,dC as ai,W as ut,aB as Zt,aC as ze,dD as ri,dE as si,az as Jr,dF as fa,aH as Vs,aI as Ws,aJ as wr,dG as ni,dH as oi,dI as ii,aL as vr,aK as Gt,dJ as li,dK as ci,dL as X,c as l,V as jt,X as jr,i as Ee,aA as Qt,bi as Yt,z as Gs,dM as di,an as ui,l as Wt,cf as Na,y as Nt,dN as mi,U as Ys,Q as Js,aN as hi,ao as xi,B as gi,R as pi,h as fi,dO as yi,dP as bi,dQ as ki,dR as _i,am as Zr,_ as wi,a as vi,dS as Qr,g as ji,Z as Ni,cs as Si,dT as Ci,dU as Ti,dV as Ai,dW as Di,dX as Li,cg as Xr,cT as es,dY as Mi,dZ as Ei,aU as Ri,d5 as Ja,d_ as ts,aS as as,d$ as Ii,e0 as Fi,e1 as $i}from"./__vite-browser-external-07djSGmy.js";import{u as at}from"./use-latest-request-guard-BSBlJJHe.js";import{u as rs,L as Pi}from"./use-ordered-list-DpAtr0R-.js";import{t as ss,T as Zs,g as zi,u as Oi}from"./TrendMonitor-8onUTbkk.js";import{u as Bi}from"./use-usage-limits-CwmhudAX.js";import{u as Ta}from"./useCurrency-CAA-tQ27.js";import{u as je}from"./useTokenFormat-Bf5-f7Hx.js";import{f as lt,A as Ui}from"./provider-display-Cw26RFDm.js";import{g as Hi,q as Qs,J as qi,M as Ki,m as He}from"./react-d7Bk1-_K.js";import{u as Vi,C as Wi,a as Gi,b as ns,D as Yi,S as Ji,v as Zi,s as Qi,K as Xi,P as el}from"./sortable.esm-DFlfwnJr.js";import{D as tl,a as al,b as rl,c as sl,d as nl,e as ol}from"./DialogTitle-3JQBVha3.js";import{D as il}from"./DialogClose-Dd2B_o03.js";import{C as Ce}from"./Card-DS8T8piP.js";import{S as Xs}from"./Select-BBEpLeiG.js";import{P as Ct}from"./ProviderIcon-6j0A2KD9.js";import{a as en,u as tn}from"./use-transform-BRz9dz_2.js";import{u as an}from"./use-reduced-motion-DF0grwHs.js";import{f as ya,D as ll,g as cl}from"./DateRangePopover-CrWgrzT2.js";import{I as rn}from"./info-B4MXmsNE.js";import{A as sn}from"./index-BFrbVqsm.js";import{L as dl}from"./loader-circle-C2I3NZAO.js";import{C as ul}from"./chevron-down-DAzlFX7g.js";import{P as ml,a as hl,b as xl,c as gl,d as pl}from"./PopoverPopup-4WuH41ZT.js";import{F as rt}from"./FadeIn-DhDvUor7.js";import{u as fl,a as yl,r as bl,b as os,P as kl,c as _l}from"./local-usage-transfer-BQasvsUF.js";import{L as is}from"./LoginCard-g_Gbnzhs.js";import{L as wl,A as vl}from"./agent-logos-ChBA1nAH.js";import{i as jl}from"./host-mode-Bc_iTzHk.js";import{M as nn}from"./monitor-smartphone-C6Y4ktsc.js";import{C as Nl}from"./check-29zGw1MK.js";import"./terminal-BtWFakvS.js";import"./use-limits-display-prefs-eYlvnUKn.js";import"./play-CwgcDJC2.js";import"./composite-DIf735Hq.js";import"./store-BKPCk_de.js";import"./SelectItemText-Cn_U_rrO.js";import"./usePositioner-Cj2DPmwM.js";import"./safePolygon-CDE0dNv_.js";import"./arrow-left-Bb5mfoPc.js";const on={name:"git-branch",size:24,node:[["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"}]]};on.node;const Sl=_r(on);const ln={name:"laptop",size:24,node:[["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"}]]};ln.node;const Cl=_r(ln);const cn={name:"square-arrow-out-up-right",size:24,node:[["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"}]],aliases:["arrow-up-right-from-square"]};cn.node;const Tl=_r(cn);function Al(t,a,r={}){const s=t.get();let n=null,o=s,i;const d=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,c=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const p=ls(t.get()),m=ls(o);if(p===m){c();return}const g=n?n.getGeneratorVelocity():t.getVelocity();c(),n=new qi({keyframes:[p,m],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:i})},x=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((p,m)=>{o=p,i=g=>m(Za(g,d)),Hi.postRender(x)},c),Qs(a)){let p=r.skipInitialAnimation===!0;const m=a.on("change",f=>{p?(p=!1,t.jump(Za(f,d),!1)):t.set(Za(f,d))}),g=t.on("destroy",m);return()=>{m(),g()}}return c}function Za(t,a){return a?t+a:t}function ls(t){return typeof t=="number"?t:parseFloat(t)}function Dl(t,a={}){const{isStatic:r}=u.useContext(Ki),s=()=>Qs(t)?t.get():t;if(r)return en(s);const n=tn(s());return u.useInsertionEffect(()=>Al(n,t,a),[n,JSON.stringify(a)]),n}function Ll(t,a={}){return Dl(t,{type:"spring",...a})}function Ml(){return e.jsxs(ti,{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 El({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:o=!1,bare:i=!1}){return i?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}),!o&&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(Ml,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!o&&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 Rl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",o={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"},i={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},d=`${n} ${o[a]} ${i[r]} ${s}`.trim();return e.jsx("span",{className:d,children:t})}var Il={};function Fl(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 $l({mv:t,digit:a,height:r}){const s=en(t,n=>{const o=(n%10+10)%10,i=(10+a-o)%10;let d=i*r;return i>5&&(d-=10*r),d});return e.jsx(He.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Pl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function zl(t,a){const r=t/a;return Math.floor(Pl(r))}function Ol(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((d,c)=>/\d/.test(d)&&(s===-1||c<s)).length,o=0,i=!1;return r.map(d=>{if(!/\d/.test(d))return d==="."&&(i=!0),d;if(!i){const c=10**Math.max(n-1,0);return n-=1,c}return o+=1,10**-o})}function Bl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const c=Fl(t,r),h=t!=="."&&t!==",",x=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...c,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...x?{width:c.width}:null},children:t})}const o=zl(a,t),i=tn(0),d=Ll(i,{stiffness:220,damping:26,mass:.8});return u.useEffect(()=>{i.set(o)},[i,o]),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(o)%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,h)=>e.jsx($l,{mv:d,digit:h,height:r},h))})}function Ul({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:o=6,borderRadius:i=4,horizontalPadding:d=0,textColor:c="inherit",fontWeight:h="inherit",containerStyle:x,counterStyle:p,digitStyle:m,gradientHeight:g=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:v}){const w=String(a??t??""),C=u.useMemo(()=>Array.isArray(n)&&n.length?n:Ol(w),[n,w]),D=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Il?.VITEST==="true",L=an()||D,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,I=r+s;return L?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:c,fontSize:r,fontWeight:h,lineHeight:1,...x,...p},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...x},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:o,overflow:"hidden",borderRadius:i,paddingLeft:d,paddingRight:d,lineHeight:1,color:c,fontWeight:h,...p},children:C.map((j,_)=>e.jsx(Bl,{place:j,value:A,height:I,digitStyle:m,shouldReduceMotion:L},`${String(j)}-${_}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:g,background:`linear-gradient(to bottom, ${f}, ${b})`}}),e.jsx("span",{style:v??{height:g,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function Hl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:o,timeZone:i,tzOffsetMinutes:d,now:c,accountView:h=!1,accountAccessToken:x=null,accountRevision:p=0,accountViewResolving:m=!1,deviceId:g=null}={}){const f=!!(h&&x),b=f?"cloud":"local",k=u.useMemo(()=>ai({weeks:s,weekStartsOn:n,now:c}),[c,s,n]),[v,w]=u.useState([]),[C,D]=u.useState(null),[L,A]=u.useState("edge"),[I,j]=u.useState(!1),[_,T]=u.useState(null),P=ut(),z=Zt(a),q=!r,M=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=at([t,k.from,k.to,s,n,b,a,x,p,m,g,i,d,r,P,q,z,M]),W=u.useMemo(()=>{if(!o)return null;const K=wr({timeZone:i,offsetMinutes:d});return`tokentracker.heatmap.${o}.${b}.${s}.${n}.${K}.${g||"all"}${f||!p?"":`.r${p}`}`},[o,g,b,i,d,s,n,f,p]),G=u.useCallback(()=>{if(!W||typeof window>"u")return null;try{const K=window.localStorage.getItem(W);if(!K)return null;const oe=JSON.parse(K);return!oe||!oe.heatmap?null:oe}catch{return null}},[W]),F=u.useCallback(K=>{if(!(!W||typeof window>"u"))try{window.localStorage.setItem(W,JSON.stringify(K))}catch{}},[W]),N=u.useCallback(()=>{if(!(!W||typeof window>"u"))try{window.localStorage.removeItem(W)}catch{}},[W]),$=u.useRef(b);u.useEffect(()=>{$.current!==b&&($.current=b,w([]),D(null),A("edge"),T(null),j(!0))},[b]);const ce=u.useCallback(async()=>{const K=O(),oe=await ze(a),xe=f?await ze(x):null;if(!K()||!oe&&!P&&!M&&!f)return;if(f&&!xe){T("Your session expired. Please sign in again to view account data."),j(!1);return}const pe=f?xe:oe,fe=f?ri:si,Re=f?Vs:Ws;j(!0),T(null);try{try{const te=await fe({baseUrl:t,accessToken:pe,weeks:s,to:k.to,weekStartsOn:n,device:g,timeZone:i,tzOffsetMinutes:d}),re=Array.isArray(te?.weeks)?te.weeks:[];if(!K())return;if(!re.length&&q){const se=G();if(se?.heatmap){if(!K())return;D(se.heatmap),w(se.daily||[]),A("cache");return}}if(!re.some(se=>(Array.isArray(se)?se:[]).some(H=>H&&Number.isFinite(Number(H.level))))&&re.length){const se=[];for(const Z of re)for(const ge of Array.isArray(Z)?Z:[])ge?.day&&se.push({day:ge.day,total_tokens:ge.total_tokens??ge.value??0,billable_total_tokens:ge.billable_total_tokens??ge.value??ge.total_tokens??0});const H=Jr({dailyRows:se,weeks:s,to:te?.to||k.to,weekStartsOn:n});if(!K())return;w(se),D({...H,week_starts_on:n,active_days:se.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:fa({dailyRows:se,to:te?.to||k.to})}),A("client"),q?F({heatmap:{...H,week_starts_on:n,active_days:se.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:fa({dailyRows:se,to:te?.to||k.to})},daily:se,fetchedAt:new Date().toISOString()}):N();return}if(!K())return;D(te||null),w([]),A("edge"),te&&q?F({heatmap:te,daily:[],fetchedAt:new Date().toISOString()}):q||N();return}catch(te){const re=te,ye=re?.status??re?.statusCode;if(ye===401||ye===403)throw te}if(!K())return;const ee=await Re({baseUrl:t,accessToken:pe,from:k.from,to:k.to,device:g,timeZone:i,tzOffsetMinutes:d}),B=Array.isArray(ee?.data)?ee.data:[];if(!K())return;w(B);const de=Jr({dailyRows:B,weeks:s,to:k.to,weekStartsOn:n});if(!K())return;D({...de,week_starts_on:n,active_days:B.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:fa({dailyRows:B,to:k.to})}),A("client"),q?F({heatmap:{...de,week_starts_on:n,active_days:B.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:fa({dailyRows:B,to:k.to})},daily:B,fetchedAt:new Date().toISOString()}):N()}catch(ee){if(!K())return;if(q){const B=G();if(B?.heatmap){if(!K())return;D(B.heatmap),w(B.daily||[]),A("cache"),T(null)}else{const de=ee;T(de?.message||String(de)),w([]),D(null),A("edge")}}else{const B=ee;T(B?.message||String(B)),w([]),D(null),A("edge")}}finally{K()&&j(!1)}},[a,t,P,r,q,k.from,k.to,G,z,i,d,n,s,N,F,M,f,x,p,g,O]);return u.useEffect(()=>{if(m){j(!0);return}if(!z&&!r&&!P&&!M&&!f){w([]),j(!1),T(null),D(null),A("edge");return}if(!q)N(),w([]),T(null),D(null),A("edge");else{const K=G();K?.heatmap&&(D(K.heatmap),w(K.daily||[]),A("cache"))}ce()},[a,P,G,ce,z,r,q,N,M,m]),{range:k,daily:v,heatmap:C,source:P?"mock":L==="client"?"edge":L,loading:I,error:_,refresh:ce}}const ql="tokentracker.dashboard.leftCardOrder.v1",Kl="tokentracker.dashboard.rightCardOrder.v1";function Vl(t,a){const r=rs(ql,t),s=rs(Kl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),o=u.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:o}}const Wl=10;function Gl({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i}={}){const[d,c]=u.useState([]),[h,x]=u.useState(!1),[p,m]=u.useState(null),g=ut(),f=Zt(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=at([t,a,r,s,n,o,i]),v=u.useCallback(async()=>{const w=k(),C=await ze(a);if(w()){if(!C&&!g&&!b){c([]),m(null),x(!1);return}x(!0),m(null);try{const D=await ni({baseUrl:t,accessToken:C,limit:Wl,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i});if(!w())return;c(Array.isArray(D?.entries)?D.entries:[])}catch(D){if(!w())return;const L=D?.message||String(D);m(L),c([])}finally{w()&&x(!1)}}},[a,t,r,g,n,o,s,i,b,k]);return u.useEffect(()=>{if(!f&&!g&&!b){c([]),m(null),x(!1);return}c([]),m(null),x(!0),v()},[g,v,f,b]),{entries:d,loading:h,error:p,refresh:v}}const cs="tokentracker.usage-cache-index",ds=24;function us({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:o=!0,includeSummary:i=!0,cacheKey:d,timeZone:c,tzOffsetMinutes:h,now:x,accountView:p=!1,accountAccessToken:m=null,accountRevision:g=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(p&&m),v=k?"cloud":"local",[w,C]=u.useState([]),[D,L]=u.useState(null),[A,I]=u.useState(null),[j,_]=u.useState("edge"),[T,P]=u.useState(null),[z,q]=u.useState(!1),[M,O]=u.useState(null),W=ut(),G=Zt(a),F=!r&&!W,N=b||"all",$=(()=>{if(!d)return null;const ee=Yl(t)||"default",B=o?i?"daily-summary":"daily-only":"summary",de=wr({timeZone:c,offsetMinutes:h});return`tokentracker.usage.${d}.${v}.${ee}.${s}.${n}.${B}.${de}.${N}${k||!g?"":`.r${g}`}`})(),ce=u.useRef(v);u.useEffect(()=>{ce.current!==v&&(ce.current=v,C([]),L(null),I(null),_("edge"),P(null),O(null),q(!0))},[v]);const ie=u.useCallback(()=>{if(!$||typeof window>"u")return null;try{const ee=window.localStorage.getItem($);if(!ee)return null;const B=JSON.parse(ee),de=i?!!B?.summary:Array.isArray(B?.daily);return!B||!de?null:(ss(cs,$,ds),B)}catch{return null}},[i,$]),K=u.useCallback(ee=>{if(!(!$||typeof window>"u"))try{window.localStorage.setItem($,JSON.stringify(ee)),ss(cs,$,ds)}catch{}},[$]),oe=u.useCallback(()=>{if(!(!$||typeof window>"u"))try{window.localStorage.removeItem($)}catch{}},[$]),xe=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),pe=at([t,s,n,o,i,v,a,m,g,b,c,h,r,W,F,f,G,xe]),fe=u.useCallback(async()=>{const ee=pe(),B=await ze(a),de=k?await ze(m):null;if(!ee()||!B&&!W&&!xe&&!k)return;if(k&&!de){O("Your session expired. Please sign in again to view account data."),q(!1);return}const te=k?Vs:Ws,re=k?oi:ii,ye=k?de:B;q(!0),O(null);try{let se=null,H=null;if(o)if(i){const[ve,Ve]=await Promise.allSettled([te({baseUrl:t,accessToken:ye,from:s,to:n,device:b,timeZone:c,tzOffsetMinutes:h}),re({baseUrl:t,accessToken:ye,from:s,to:n,device:b,timeZone:c,tzOffsetMinutes:h,rolling:!0})]);if(ve.status==="rejected")throw ve.reason;se=ve.value,H=Ve.status==="fulfilled"?Ve.value:null}else se=await te({baseUrl:t,accessToken:ye,from:s,to:n,device:b,timeZone:c,tzOffsetMinutes:h});else i&&(H=await re({baseUrl:t,accessToken:ye,from:s,to:n,device:b,timeZone:c,tzOffsetMinutes:h,rolling:!0}));let Z=o&&Array.isArray(se?.data)?se.data:[];o&&(Z=Xa(Z,s,n,{timeZone:c,offsetMinutes:h,now:x}));let ge=i&&(H?.totals||se?.summary?.totals)||null,Ie=i&&(H?.rolling||se?.summary?.rolling)||null;if(i&&o&&!ge&&!H)try{const ve=await re({baseUrl:t,accessToken:ye,from:s,to:n,device:b,timeZone:c,tzOffsetMinutes:h,rolling:!0});ge=ve?.totals||null,Ie=ve?.rolling||Ie}catch{}const Ne=new Date().toISOString();if(!ee())return;C(Z),L(ge),I(Ie),_("edge"),P(Ne),(ge||!i&&o)&&F?K({summary:ge,rolling:Ie,daily:Z,from:s,to:n,includeDaily:o,includeSummary:i,fetchedAt:Ne}):F||oe()}catch(se){if(!ee())return;if(F){const H=ie();if(H?.summary||!i&&Array.isArray(H?.daily)){L(H.summary),I(H.rolling||null);const Z=Array.isArray(H.daily)?H.daily:[],ge=o?Xa(Z,H.from||s,H.to||n,{timeZone:c,offsetMinutes:h,now:x}):Z;C(ge),_("cache"),P(H.fetchedAt||null),O(null)}else{const Z=se;O(Z?.message||String(Z)),C([]),L(null),I(null),_("edge"),P(null)}}else{const H=se;O(H?.message||String(H)),C([]),L(null),I(null),_("edge"),P(null)}}finally{ee()&&q(!1)}},[a,t,s,o,i,W,r,F,x,ie,G,c,n,h,oe,K,xe,k,m,g,b,pe]);return u.useEffect(()=>{if(f){q(!0);return}const ee=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!G&&!r&&!W&&!ee&&!k){C([]),L(null),I(null),O(null),q(!1),_("edge"),P(null);return}if(!F)oe(),C([]),L(null),I(null),O(null),_("edge"),P(null);else{const B=ie();if(B?.summary||!i&&Array.isArray(B?.daily)){L(B.summary),I(B.rolling||null);const de=Array.isArray(B.daily)?B.daily:[],te=o?Xa(de,B.from||s,B.to||n,{timeZone:c,offsetMinutes:h,now:x}):de;C(te),_("cache"),P(B.fetchedAt||null),O(null)}else C([]),L(null),I(null),_("edge"),P(null),O(null)}q(!0),fe()},[a,W,ie,fe,G,r,F,oe,xe,f,i]),u.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const ee=15e3;let B=Date.now();const de=()=>{if(document.visibilityState!=="visible")return;const te=Date.now();te-B<ee||(B=te,fe())};return window.addEventListener("focus",de),document.addEventListener("visibilitychange",de),()=>{window.removeEventListener("focus",de),document.removeEventListener("visibilitychange",de)}},[fe]),{daily:w,summary:D,rolling:A,source:W?"mock":j,fetchedAt:T,loading:z,error:M,refresh:fe}}function Yl(t){try{return new URL(t).host}catch{return null}}function Qa(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,o=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n,o));return Number.isFinite(i.getTime())&&Gt(i)===a?i:null}function Jl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Xa(t,a,r,{timeZone:s,offsetMinutes:n,now:o}={}){const i=Qa(a),d=Qa(r);if(!i||!d||d<i)return Array.isArray(t)?t:[];const c=o instanceof Date&&Number.isFinite(o.getTime())?o:new Date,h=vr({timeZone:s,offsetMinutes:n,date:c}),x=Qa(h),p=x?x.getTime():c.getTime(),m=new Map;for(const f of t||[])f?.day&&m.set(f.day,f);const g=[];for(let f=i;f<=d;f=Jl(f,1)){const b=Gt(f),k=m.get(b),v=f.getTime()>p;if(k){g.push({...k,missing:!1,future:v});continue}g.push({day:b,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 g}function Zl({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:o,timeZone:i,tzOffsetMinutes:d,accountView:c=!1,accountAccessToken:h=null,accountRevision:x=0,accountViewResolving:p=!1,deviceId:m=null}={}){const g=!!(c&&h),f=g?"cloud":"local",[b,k]=u.useState(null),[v,w]=u.useState("edge"),[C,D]=u.useState(!1),[L,A]=u.useState(null),I=ut(),j=Zt(a),_=!r,T=u.useMemo(()=>{if(!o)return null;const N=Ql(t)||"default",$=wr({timeZone:i,offsetMinutes:d});return`tokentracker.modelBreakdown.${o}.${f}.${N}.${s}.${n}.${$}.${m||"all"}${g||!x?"":`.r${x}`}`},[t,o,m,s,f,i,n,d,g,x]),P=u.useCallback(()=>{if(!T||typeof window>"u")return null;try{const N=window.localStorage.getItem(T);if(!N)return null;const $=JSON.parse(N);return!$||!$.breakdown?null:$}catch{return null}},[T]),z=u.useCallback(N=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(N))}catch{}},[T]),q=u.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),M=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=at([t,s,n,f,a,h,x,m,i,d,r,I,_,p,j,M]),W=u.useRef(f);u.useEffect(()=>{W.current!==f&&(W.current=f,k(null),w("edge"),A(null),D(!0))},[f]);const G=u.useCallback(async()=>{const N=O(),$=await ze(a),ce=g?await ze(h):null;if(!N()||!$&&!I&&!M&&!g)return;if(g&&!ce){A("Your session expired. Please sign in again to view account data."),D(!1);return}const ie=g?ce:$,K=g?li:ci;D(!0),A(null);try{const oe=await K({baseUrl:t,accessToken:ie,from:s,to:n,device:m,timeZone:i,tzOffsetMinutes:d});if(!N())return;k(oe||null),w("edge"),oe&&_?z({breakdown:oe,fetchedAt:new Date().toISOString()}):_||q()}catch(oe){if(!N())return;if(_){const xe=P();if(xe?.breakdown)k(xe.breakdown),w("cache"),A(null);else{k(null),w("edge");const pe=oe;A(pe?.message||String(pe))}}else{k(null),w("edge");const xe=oe;A(xe?.message||String(xe))}}finally{N()&&D(!1)}},[a,t,s,I,r,_,P,i,n,j,d,q,z,M,g,h,x,m,O]);return u.useEffect(()=>{if(p){D(!0);return}if(!j&&!r&&!I&&!M&&!g){k(null),w("edge"),A(null),D(!1);return}if(!_)q(),k(null),w("edge"),A(null);else{const N=P();N?.breakdown?(k(N.breakdown),w("cache"),A(null)):(k(null),w("edge"),A(null))}D(!0),G()},[a,I,P,G,j,r,_,q,M,p]),{breakdown:b,source:I?"mock":v,loading:C,error:L,refresh:G}}function Ql(t){try{return new URL(t).host}catch{return null}}const dn=new Set(["day","hour","month"]);function Xl(t){return dn.has(t)}function ms(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 ec(t,a){const r=ms(t),s=ms(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=X(t),o=X(a);return n==null&&o==null?0:n==null?1:o==null?-1:n===o?0:n<o?-1:1}function tc(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 ac(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]),o=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n-1,o));return!Number.isFinite(i.getTime())||i.getUTCFullYear()!==s||i.getUTCMonth()+1!==n||i.getUTCDate()!==o?null:i.getTime()}function rc(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 o=new Date(Date.UTC(s,n-1,1));return Number.isFinite(o.getTime())?o.getTime():null}function sc(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]),o=Number(r[3]),i=Number(r[4]),d=Number(r[5]),c=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(d)||!Number.isFinite(c)||n<1||n>12||o<1||o>31||i<0||i>23||d<0||d>59||c<0||c>59)return null;const h=new Date(Date.UTC(s,n-1,o,i,d,c));return Number.isFinite(h.getTime())?h.getTime():null}function nc(t,a,r){const s=r==="hour"?sc:r==="month"?rc:ac,n=s(t),o=s(a);return n!=null&&o!=null?n===o?0:n<o?-1:1:tc(t,a)}function un(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],o=dn.has(a)?(d,c)=>nc(d,c,a):ec,i=d=>a==="total_tokens"&&d?.billable_total_tokens!=null?d.billable_total_tokens:d?.[a];return n.map((d,c)=>({row:d,index:c})).sort((d,c)=>{const h=i(d.row),x=i(c.row),p=h==null,m=x==null;if(p&&m)return d.index-c.index;if(p)return 1;if(m)return-1;const g=o(h,x);return g!==0?g*s:d.index-c.index}).map(d=>d.row)}function oc(){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 hs(t){const a=Xl(t)?t:"day";return oc().map((r,s)=>s===0?{...r,key:a}:r)}function xs(t,{key:a,dir:r}){return un(t,{key:a,dir:r})}const Sa=12,ic=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function lc(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 cc(t){return ic.some(a=>lc(t?.[a]))}function dc(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=un(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&cc(n));return s===-1?a:r.slice(s)}function uc(t,a,r=Sa){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Sa,i=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(i,i+n)}function mc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:o,hasActiveDeviceToken:i}={}){return t||a?!1:r?!0:s&&!n&&o===0&&!i}const ba=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function hc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ba.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ba.active:s<=60*6e4?ba.warm:ba.idle}const xc=3e4;function gc({refresh:t,intervalMs:a=xc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let o=!1,i=null,d=Date.now(),c=0;const h=()=>{if(o||s.visibilityState!=="visible"||i)return i;const g=Promise.resolve().then(()=>t()).catch(f=>n(f)).then(()=>{}).finally(()=>{i===g&&(i=null)});return i=g,g},x=r.setInterval(()=>{const g=Date.now();g<c||(c=g+hc({visible:s.visibilityState==="visible",lastInteractionAt:d,now:g}),h())},a),p=()=>{s.visibilityState==="visible"&&(d=Date.now(),c=0,h())},m=()=>{d=Date.now()};return r.addEventListener("focus",p),r.addEventListener("pointerdown",m),r.addEventListener("keydown",m),s.addEventListener("visibilitychange",p),{run:h,stop(){o=!0,r.clearInterval(x),r.removeEventListener("focus",p),r.removeEventListener("pointerdown",m),r.removeEventListener("keydown",m),s.removeEventListener("visibilitychange",p)}}}function pc(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 Gt(r)===t?r:null}function fc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=pc(s)||new Date,o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Gt(o),to:Gt(n)}}function yc(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 Nr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function bc(t){const a=Nr(t?.model_id);return a||null}function mn(t,a){return t?.model?String(t.model):a}function hn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",o=Nr(n);if(!o||o.includes("/"))continue;const i=Math.max(0,X(s?.weight)??0);(!a.has(o)||i>=(r.get(o)||0))&&(a.set(o,n),r.set(o,i))}return a}function xn(t,a){const r=Nr(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function St(t,a=0){const r=X(t?.billable_total_tokens),s=X(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const kc={deepseek:"dsh"};function _c(t){const a=typeof t=="string"?t:"";return kc[a]||a}const wc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count"],gn=["input","output","cached","cacheCreate","reasoning"];function vc(t){let a=0;for(const r of gn)a+=Math.max(0,Number(t?.[r])||0);return a}function jc(t){return vc(t?.tokens)>0}function gs(t,a){for(const r of wc)t[r]=(Number(t[r])||0)+(Number(a?.[r])||0);t.total_cost_usd=String(Number(t.total_cost_usd||0)+Number(a?.total_cost_usd||0))}function ps(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,conversation_count:0,total_cost_usd:"0"}}function Nc(t){const a=new Map;for(const r of t||[]){const s=_c(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:ps(),models:new Map},a.set(s,n)),gs(n.totals,r?.totals);for(const o of Array.isArray(r?.models)?r.models:[]){const i=o?.model_id||o?.model||"";if(!i)continue;let d=n.models.get(i);d||(d={...o,model:o?.model||i,model_id:i,totals:ps()},n.models.set(i,d)),gs(d.totals,o?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function Sc(t,{copyFn:a}={}){const r=typeof a=="function"?a:i=>i,n=Nc(Array.isArray(t?.sources)?t.sources:[]).map(i=>{const d=St(i?.totals),c=X(i?.totals?.total_cost_usd)??0,h=Math.max(0,X(i?.totals?.conversation_count)??0);return{source:i?.source,totalTokens:Number.isFinite(d)?d:0,totalRequests:h,totalCost:Number.isFinite(c)?c:0,inputTokens:Math.max(0,X(i?.totals?.input_tokens)??0),cacheRead:Math.max(0,X(i?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,X(i?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0||i.totalRequests>0);if(!n.length)return[];const o=n.reduce((i,d)=>i+d.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((i,d)=>d.totalTokens-i.totalTokens||d.totalRequests-i.totalRequests).map(i=>{const d=i.source?String(i.source).toUpperCase():r("shared.placeholder.short"),c=o>0?i.totalTokens/o*100:0,h=Number.isFinite(c)?c.toFixed(2):"0.00",x=i.models.map(f=>{const b=St(f?.totals),k=Math.max(0,X(f?.totals?.conversation_count)??0);if((!Number.isFinite(b)||b<=0)&&k<=0)return null;const v=i.totalTokens>0?Math.round(b/i.totalTokens*1e3)/10:0,w=mn(f,r("shared.placeholder.short")),C=bc(f),D=X(f?.totals?.total_cost_usd),L=b<=0?null:D??(i.totalCost>0&&i.totalTokens>0?b/i.totalTokens*i.totalCost:null),A=f?.totals||{};return{id:C,name:w,share:v,usage:b,requests:k,cost:L,tokens:{input:Math.max(0,X(A?.input_tokens)??0),output:Math.max(0,X(A?.output_tokens)??0),cached:Math.max(0,X(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,X(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,X(A?.reasoning_output_tokens)??0)},pricing:f?.pricing||null,costSource:f?.cost_source||null}}).filter(Boolean),p=i.inputTokens+i.cacheRead+i.cacheCreate,g=i.cacheRead+i.cacheCreate>0&&p>0?Math.round(i.cacheRead/p*100):null;return{source:i.source,label:d,totalPercent:String(h),totalPercentValue:c,usd:i.totalCost,usage:i.totalTokens,requests:i.totalRequests,cacheHitRate:g,cacheReusedTokens:i.cacheRead,cacheInputTokens:p,models:x}})}function Cc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const i of a){const d=Array.isArray(i?.models)?i.models:[];for(const c of d){const h=X(c?.usage),x=Math.max(0,X(c?.requests)??0);if((h==null||h<=0)&&x<=0)continue;const p=h??0,m=typeof c?.name=="string"&&c.name.trim()?c.name.trim():typeof c?.id=="string"&&c.id.trim()?c.id.trim():null;m&&s.push({model:c,name:m,usage:p,requests:x})}}const n=hn(s.map(i=>({name:i.name,weight:i.usage})));for(const{model:i,name:d,usage:c,requests:h}of s){const x=xn(d,n);if(!x)continue;const{key:p}=x,m=r.get(p)||{id:p,name:x.name,usage:0,requests:0,cost:0,hasCost:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0}};m.usage+=c,m.requests+=h;const g=i?.tokens||{};for(const b of gn)m.tokens[b]+=Math.max(0,Number(g[b])||0);const f=X(i?.cost);f!=null&&(m.cost+=f,m.hasCost=!0),n.has(p)?m.name=n.get(p):c>=m.nameWeight&&(m.name=d,m.nameWeight=c),r.set(p,m)}const o=Array.from(r.values()).reduce((i,d)=>i+d.usage,0);return Array.from(r.values()).map(i=>({id:i.id,name:i.name,usage:i.usage,requests:i.requests,cost:i.hasCost?i.cost:null,tokens:{...i.tokens},share:o>0?Math.round(i.usage/o*1e3)/10:0})).sort((i,d)=>d.usage!==i.usage?d.usage-i.usage:String(i.name).localeCompare(String(d.name)))}function Tc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:f=>f,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const o=new Map,i=new Map,d=new Map,c=[];let h=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const v=St(k?.totals);if(!Number.isFinite(v)||v<=0)continue;h+=v;const w=mn(k,s("shared.placeholder.short"));c.push({name:w,tokens:v})}}const x=hn(c.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of c){const k=xn(f,x);if(!k)continue;const{key:v}=k;o.set(v,(o.get(v)||0)+b),x.has(v)?i.set(v,x.get(v)):b>=(d.get(v)||0)&&(d.set(v,b),i.set(v,f))}if(!o.size)return[];const p=Array.from(o.values()).reduce((f,b)=>f+b,0),m=h>0?h:p,g=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(o.entries()).map(([f,b])=>{const k=m>0?(b/m*100).toFixed(1):"0.0";return{id:f,name:i.get(f)||s("shared.placeholder.short"),tokens:b,percent:String(k)}}).sort((f,b)=>b.tokens!==f.tokens?b.tokens-f.tokens:String(f.name).localeCompare(String(b.name))).slice(0,g)}function Ac(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Qt(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function fs(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Yt(a);return(a===Gs?t:t*r)<.01?`<${s}0.01`:Qt(t,{decimals:2,currency:a,rate:r})}function ys(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ee(a,{decimals:1})}const Dc=jt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:o}=Ta(),i=u.useMemo(()=>(Array.isArray(s)?s:[]).map(h=>{const x=X(h?.usd)??0,p=X(h?.usage)??0,m=Array.isArray(h?.models)?h.models:[];return{label:h?.label?String(h.label):"",usdValue:x,costLabel:fs(x,n,o),tokensLabel:ys(p),models:m.map(g=>{const f=X(g?.usage)??0,b=X(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:ys(f),costLabel:fs(b,n,o),sortCost:b,pricing:g?.pricing,costSource:g?.costSource,tokens:g?.tokens}}).filter(g=>g.costLabel||g.tokensLabel).sort((g,f)=>f.sortCost-g.sortCost)}}).filter(h=>h.usdValue>0||h.models.length>0).sort((h,x)=>x.usdValue-h.usdValue),[s,n,o]),d=i.some(h=>h.models.some(x=>x.costSource!=="provider_reported"&&x.pricing?.status==="unpriced")),c=u.useMemo(()=>{const h=i.reduce((x,p)=>x+p.usdValue,0);return d&&h===0?l("dashboard.cost_breakdown.unpriced_label"):`${d?"≥":""}${Ac(h,n,o)}`},[i,n,o,d]);return e.jsx(tl,{open:a,onOpenChange:h=>{h||r?.()},children:e.jsxs(al,{children:[e.jsx(rl,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(sl,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(nl,{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(ol,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(il,{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(jr,{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:d?l("dashboard.cost_breakdown.known_subtotal"):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:c}),e.jsx("p",{className:"mb-4 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.method")}),i.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):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:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),i.map((h,x)=>{const p=`fleet-${x}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":p,className:x>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:p,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:h.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:h.costLabel||"—"})]}),h.models.map((m,g)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:m.name,children:m.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:m.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):m.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),m.pricing?.status==="unpriced"&&m.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,m.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,m.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ee(Number(m.tokens.input)||0),output:Ee(Number(m.tokens.output)||0),read:Ee(Number(m.tokens.cached)||0),write:Ee(Number(m.tokens.cacheCreate)||0)})}):null,m.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:m.pricing.input,output:m.pricing.output,read:m.pricing.cache_read,write:m.pricing.cache_write})}):null]})]}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:m.costLabel||(m.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):m.pricing?.status==="free"?Qt(0,{currency:n,rate:o}):l("dashboard.cost_breakdown.rate_unknown"))})]},m.id||`${m.name}-${g}`))]},`${h.label}-${x}`)})]})]})})]})})]})})});function Lc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[o,i]=u.useState(null),[d,c]=u.useState(!1),[h,x]=u.useState(null),p=ut(),m=at([t,a,r,s,n,p]);return u.useEffect(()=>{const g=m();if(!t){i(null),x(null),c(!1);return}c(!0),i(null),x(null),di({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{g()&&i(f||null)}).catch(f=>{g()&&(x(f?.message||String(f)),i(null))}).finally(()=>{g()&&c(!1)})},[t,a,r,s,n,p,m]),{data:o,loading:d,error:h}}function pn(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 fn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function yn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function bn(t,a){return a&&yn(fn(t))==="github"?a:""}function kn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=u.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 bs="#10b981",er=[{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"}],tr=60;function Mc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(m=>[m.day,m]));let o=a||t[0].day,i=r||t[t.length-1].day;o>i&&([o,i]=[i,o]),s&&i>s&&(i=s);const d=t[t.length-1].day;i<d&&(i=d);const c=new Date(`${o}T00:00:00Z`),h=new Date(`${i}T00:00:00Z`);if(!Number.isFinite(c.getTime())||!Number.isFinite(h.getTime()))return t;const x=Math.round((h.getTime()-c.getTime())/864e5)+1;x>tr&&c.setUTCDate(c.getUTCDate()+(x-tr));const p=[];for(;c.getTime()<=h.getTime()&&p.length<tr;){const m=c.toISOString().slice(0,10);p.push(n.get(m)||{day:m,total_tokens:0,billable_total_tokens:0}),c.setUTCDate(c.getUTCDate()+1)}return p}function ar(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function vt({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 Ec({host:t}){if(!t)return null;let a;const r=yn(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(Sl,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function rr({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]=jt.useState(!1),o=typeof t?.project_key=="string"?t.project_key:"",{owner:i,repo:d}=pn(o),c=typeof t?.project_ref=="string"?t.project_ref:"",h=fn(c),{data:x,loading:p,error:m}=Lc({projectKey:o,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:g,formatTokensTooltip:f}=je(),b=jt.useCallback(()=>n(!0),[]),k=M=>{M.target===M.currentTarget&&s&&r()};jt.useEffect(()=>{const M=O=>{O.key==="Escape"&&b()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[b]);const v=x?.totals||null,w=X(v?.billable_total_tokens)??0,C=Number(x?.days_active||0),D=X(v?.input_tokens)??0,L=X(v?.cached_input_tokens)??0,A=D+L>0?L/(D+L):null,I=X(x?.range_total_tokens)??0,j=X(v?.total_tokens)??0,_=I>0?j/I:null,T=jt.useMemo(()=>Mc(x?.daily,x?.from,x?.to,vr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[x,a.timeZone,a.tzOffsetMinutes]),P=er.reduce((M,O)=>M+(X(v?.[O.key])??0),0),z=Array.isArray(x?.sources)?x.sources:[],q=!p&&!m&&v&&j>0;return e.jsx("div",{onAnimationEnd:k,onClick:M=>{M.target===M.currentTarget&&b()},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":o,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:b,"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(jr,{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:bs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:bs}})]}),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(kn,{githubOwner:bn(c,i),letter:(d?.[0]||o?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[i?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[i,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:d||o||"—"})]})]}),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(Ec,{host:h}),h&&x?.from&&x?.to?e.jsx("span",{children:"·"}):null,x?.from&&x?.to?e.jsxs("span",{className:"tabular-nums",children:[x.from," – ",x.to]}):null]})]}),q?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(vt,{label:l("dashboard.projects.detail.stat_total"),value:g(w),title:f(w)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_share"),value:_==null?"—":ar(_)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":ar(A)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_conversations"),value:Na(v.conversation_count)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_active_days"),value:Na(C)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_avg_day"),value:C>0?g(Math.round(w/C)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[p&&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"})]}),!p&&m&&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")}),!p&&!m&&!q&&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")}),q&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[T.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(Zs,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),P>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:er.map(M=>{const O=X(v[M.key])??0;return O<=0?null:e.jsx("div",{style:{width:`${O/P*100}%`,backgroundColor:M.color,minWidth:"2px"}},M.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:er.map(M=>{const O=X(v[M.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:M.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(M.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:g(O)})]},M.key)})})]}),z.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:z.map(M=>{const O=Number(M.total_tokens||0),W=j>0?O/j:0,G=W*100,F=Number(M.conversation_count||0),N=zi(M.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:M.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:lt(M.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(M.days_active||0)}),F>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:F})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:g(O)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:ar(W)})]}),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(G,O>0?1:0))}%`,minWidth:O>0?"3px":0,backgroundColor:N}})})]},M.source)})})]})]})]})]})})}function Ic(t){return e.jsx(ui,{mode:Wt.COMPACT,children:e.jsx(Rc,{...t})})}const Fc=5;function $c({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:o}){const i=typeof t?.project_key=="string"?t.project_key:"",d=typeof t?.project_ref=="string"?t.project_ref:"",{owner:c,repo:h}=pn(i),x=bn(d,c),p=X(t?.billable_total_tokens??t?.total_tokens)??0,m=a>0?Math.min(100,Math.max(2,p/a*100)):0,g=Array.isArray(t?.sources)?t.sources:[],f=g.slice(0,Fc),b=g.length-f.length;return e.jsxs("button",{type:"button",onClick:()=>o?.(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(kn,{githubOwner:x,letter:(h?.[0]||i?.[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:h||i||"—"})]}),f.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[f.map(k=>e.jsx(Ct,{provider:k.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},k.source)),b>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:b})})]})]}),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(p),children:s(p)}),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:`${m}%`,minWidth:p>0?"3px":0}})})]})]})}function Pc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:o,dailyEmptyPrefix:i,installSyncCmd:d,dailyEmptySuffix:c,detailsColumns:h,ariaSortFor:x,toggleSort:p,sortIconFor:m,pagedDetails:g,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:w="day",detailsDateKey:C,renderDetailDate:D,renderDailyBreakdownDate:L,renderDetailCell:A,DETAILS_PAGED_PERIODS:I,period:j,detailsPageCount:_,detailsPage:T,setDetailsPage:P}){const[z,q]=u.useState("daily"),[M,O]=u.useState(null),{formatTokens:W,formatTokensTooltip:G}=je();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:()=>q("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:()=>q("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(Xs,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:F=>r?.(Number(F)),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 F=t.slice(0,a);if(F.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 N=F.reduce(($,ce)=>{const ie=X(ce?.billable_total_tokens??ce?.total_tokens)??0;return ie>$?ie:$},0);return e.jsx("div",{className:"space-y-1",children:F.map(($,ce)=>e.jsx($c,{entry:$,maxTokens:N,copy:n,formatTokens:W,formatTokensTooltip:G,onSelect:O},$?.project_key||$?.project_ref||`entry-${ce}`))})})(),M&&e.jsx(Ic,{entry:M,query:s,onClose:()=>O(null)}),z==="daily"&&e.jsxs("div",{children:[f?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[i,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:d}),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:b.map(F=>e.jsx("th",{"aria-sort":k?.(F.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>p(F.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:F.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(F.key)||""})]})})},F.key))})}),e.jsx("tbody",{children:f.map(F=>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 ${F.missing?"text-oai-gray-400 dark:text-oai-gray-400":F.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:L?L(F):D(F)}),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:A(F,"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:A(F,"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:A(F,"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:A(F,"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:A(F,"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:A(F,"conversation_count")})]},String(F?.[w]||F?.day||F?.hour||F?.month||"")))})]})}),z!=="daily"&&I.has(j)&&_>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>P(F=>Math.max(0,F-1)),disabled:T===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:[T+1," / ",_]}),e.jsx("button",{type:"button",onClick:()=>P(F=>Math.min(_-1,F+1)),disabled:T+1>=_,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 ja(t){return typeof t!="string"?"":t.trim()}function ks(t){const a=ja(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function zc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=ja(r.tool),n=ja(r.planType)||ja(r.plan_type);if(!s||!n)continue;const o=ks(s)||s,i=ks(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:o,plan:i})}return Array.from(a.values())}function Oc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:o=[],className:i=""}){const{formatTokensTooltip:d}=je(),c=l("shared.placeholder.short"),h=l("shared.unit.percent"),x=t??l("identity_card.rank_placeholder"),p=Number.isFinite(Number(a))?Number(a):0,m=p?l("identity_card.streak_value",{days:p}):l("identity_card.rank_placeholder"),g=zc(r),f={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev"),trillionSuffix:l("shared.unit.trillion_abbrev")},b=w=>{if(w==null)return c;const C=Ee(w,f);return C==="-"?c:C},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=o.slice(0,3);return e.jsxs(Ce,{className:`h-full ${i}`,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:d(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:b(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:k.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:d(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:b(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:k.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:d(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:b(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:k.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:b(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:k.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((w,C)=>{const D=w?.name?String(w.name):c,L=w?.percent?String(w.percent):"",A=C===v.length-1,I=C+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"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:I}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:D,children:D}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[L,h]})]},w.id||D)})}),g.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:g.map((w,C)=>e.jsxs(Rl,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${C}`))}),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:x})]}),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:m})]})]})]})}let ka=null;function Bc(){if(ka===null)try{ka=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{ka=!1}return ka}function Uc(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),o=a*Math.sin(s),i=t+.3963377774*n+.2158037573*o,d=t-.1055613458*n-.0638541728*o,c=t-.0894841775*n-1.291485548*o,h=i*i*i,x=d*d*d,p=c*c*c;return[4.0767416621*h-3.3077115913*x+.2309699292*p,-1.2684380046*h+2.6097574011*x-.3413193965*p,-.0041960863*h-.7034186147*x+1.707614701*p].map(g=>{const f=Math.min(1,Math.max(0,g)),b=f<=.0031308?12.92*f:1.055*Math.pow(f,1/2.4)-.055;return Math.round(b*255)})}function _n(t,a,r,s){if(Bc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,o,i]=Uc(t,a,r);return s==null?`rgb(${n} ${o} ${i})`:`rgb(${n} ${o} ${i} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?_n(Number(a[1]),Number(a[2]),Number(a[3])):t}const _s={claude:35,codex:250,grok:200},ws={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 Hc(t,a){const r=_s[a]??_s.claude,s=ws[t]||ws.system_prompt;return _n(s.l,s.c,r)}const qc=[{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"]}],Kc=[["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"]],Vc={duration:.18,ease:[.4,0,.2,1]},Wc={height:0,opacity:0},Gc={height:"auto",opacity:1},Yc={height:0,opacity:0};function Jc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function Zc(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 wn(t,a=null){const r=t.reduce((i,d)=>i+Number(d.totals.total_tokens||0),0),s=Jc(a),n=s||r,o=s&&r>0?s/r:1;return t.map(i=>{const d=o===1?i.totals:Zc(i.totals,o);return{...i,totals:d,percent:n>0?Number((d.total_tokens/n*100).toFixed(2)):0}}).sort((i,d)=>d.totals.total_tokens-i.totals.total_tokens)}function Qc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=qc.map(n=>{const o={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const i of n.from){const d=r.get(i);if(!d)continue;const c=d.totals||{};o.input_tokens+=c.input_tokens||0,o.cached_input_tokens+=c.cached_input_tokens||0,o.cache_creation_input_tokens+=c.cache_creation_input_tokens||0,o.output_tokens+=c.output_tokens||0,o.reasoning_output_tokens+=c.reasoning_output_tokens||0,o.total_tokens+=c.total_tokens||0}return{key:n.key,totals:o}});return wn(s,a)}function Xc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,x)=>x?.name==="Text Response"?h:h+Number(x?.totals?.total_tokens||0),0),o=Number(r.total_tokens||0),i=Math.min(Math.max(0,n),Math.max(0,o-s)),c=[{key:"messages",totals:{total_tokens:Math.max(0,o-s-i)}},{key:"tool_calls",totals:{total_tokens:i}},{key:"reasoning",totals:{total_tokens:s}}];return wn(c,a)}const vs="MCP: ";function ed(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 o=String(n?.name||"");o.startsWith(vs)?(a.push({...n,name:o.slice(vs.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,o)=>(o.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function js(t){return l(`dashboard.context_breakdown.category.${t}`)}function td(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function ad(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),o=Number(r?r.cached_input_tokens||0:a?.cache_read||0),i=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),d=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:td(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:o,cache_creation:i,total_tokens:Number(d||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function rd(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),o=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),d=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:o,cached_input_tokens:i,cache_creation_input_tokens:d,total_tokens:Number(r.total_tokens||n+o)},tools:ad(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function sd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=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:o,cache_creation_input_tokens:i,total_tokens:Number(r.total_tokens||s+n+o+i)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function nd(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 od(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 id(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=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:o,cache_creation_input_tokens:i,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 Ns(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 ld(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 Ss(t){return t==="exec_command"||t==="Bash"}function vn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function cd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function dd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const ud=10;function Ze({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:o=!1,open:i=!1,onToggle:d,tokens:c,percent:h=null,children:x,share:p=null,fillColor:m=null}){const g=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",f=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:ud},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:g,children:r}),s,o&&e.jsx(He.span,{animate:{rotate:i?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(hi,{size:11})})]}),k=m&&p!=null&&p>0,v=k?Math.max(0,Math.min(100,p)):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:k?{backgroundImage:`linear-gradient(to right, ${m.replace(/\)\s*$/," / 0.10)")} 0%, ${m.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[o?e.jsx("button",{type:"button",onClick:d,"aria-expanded":i,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:b}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:b}),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:h||""})]}),o&&x?e.jsx(sn,{initial:!1,children:i&&e.jsx(He.div,{initial:Wc,animate:Gc,exit:Yc,transition:Vc,style:{overflow:"hidden"},children:x},"content")}):null]})}function Cs({execDetails:t,source:a="claude"}){const{formatTokens:r}=je(),[s,n]=u.useState("by_type"),o=id(ld(t,s)),i=a==="codex"||a==="grok",d=i?"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:Kc.map(([c,h])=>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(h)},c))}),o.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:i?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${d} 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")}),i&&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")}),i&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),o.map((c,h)=>e.jsxs(He.div,{role:"row",className:`grid ${d} gap-2 py-1.5`,title:c.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.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:Ee(c.calls||0)}),i&&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:Ee(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:Ns(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:Ns(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)}),i&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ee(c.output_lines||0)})]},c.name))]})})]})}function Kt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=je(),[o,i]=u.useState({}),[d,c]=u.useState(!1),h=rd(t?.categories||[]);function x(p){i(m=>({...m,[p]:!m[p]}))}return h.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(vn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(p=>{const m=p.toolCount>0,g=p.name==="Execution"&&a,f=g&&p.tools.some(k=>Ss(k.name)),b=!!o[p.name];return e.jsxs(Ze,{level:1,label:p.name,labelTone:"strong",hasChevron:m||g&&!f,open:b||g&&!f&&d,onToggle:()=>{m?x(p.name):g&&!f&&c(k=>!k)},tokens:n(p.totals.total_tokens||0),percent:null,children:[m&&e.jsx("ul",{className:"space-y-0.5",children:p.tools.map(k=>{const v=g&&Ss(k.name);return e.jsx(Ze,{level:2,label:k.name,labelTone:v?"accent":"default",hasChevron:v,open:d,onToggle:()=>c(w=>!w),tokens:n(k.total_tokens||0),percent:null,children:v&&e.jsx(Cs,{execDetails:a,source:r})},k.name)})}),g&&!f&&e.jsx(Cs,{execDetails:a,source:r})]},p.name)})})}function md({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null,deviceId:o=null}){const{formatTokens:i}=je(),[d,c]=u.useState(null),[h,x]=u.useState(!1),[p,m]=u.useState(null),[g,f]=u.useState({}),b=u.useRef({});function k(N){f($=>({...$,[N]:!$[N]}))}if(u.useEffect(()=>{let N=!1;const $=`${t||""}|${a||""}|${r||"claude"}|${o||""}`,ce=b.current[$];return c(ce||null),x(!0),n?.(!0),m(null),mi({from:t,to:a,source:r,device:o,timeZone:Js(),tzOffsetMinutes:Ys()}).then(ie=>{N||(b.current[$]=ie,c(ie))}).catch(ie=>{N||m(ie?.message||String(ie))}).finally(()=>{N||(x(!1),n?.(!1))}),()=>{N=!0}},[t,a,r,o]),h&&!d)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(p)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(cd(r))});if(!d||d.scope!=="supported"||!d.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(d?.reason==="local_history_only"?"settings.local_data.local_history_only":vn(r))});const v=r==="claude"?Qc(d.categories||[],s):Xc(d,s),w=d.tool_calls_breakdown||null,C=d.skills_breakdown||null,D=d.message_breakdown||null,L=d.configured_resources||null,A=d.exec_command_breakdown||null,I=nd(C?.skills||[]),j=sd(D?.categories||[]),_=r==="codex"&&(d?.breakdown_status==="queue_fallback"||d?.fallback==="queue_totals"),T=r==="claude"?w?.tool_calls||null:w||null,{mcpSet:P,residualSet:z,mcpTotalTokens:q}=ed(T),M=r==="claude"&&w?.subagents||null,O=M?.categories?.length>0||(L?.custom_agents_count||0)>0,W=r==="claude"?(z?.categories||[]).reduce((N,$)=>N+Number($?.totals?.total_tokens||0),0):0,G=r==="claude"?(M?.categories||[]).reduce((N,$)=>N+Number($?.totals?.total_tokens||0),0):0,F=[...v].sort((N,$)=>($.totals?.total_tokens||0)-(N.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:v.filter(N=>N.percent>0).filter(N=>!(r==="claude"&&(N.key==="tool_calls"||N.key==="custom_agents"))).map(N=>`${js(N.key)} ${N.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[F.map(N=>{const $=N.key==="system_prompt",ce=N.key==="messages",ie=N.key==="tool_calls",K=N.key==="custom_agents";if(N.key,r==="claude"&&(ie||K))return null;const oe=ce&&j.length>0||ie&&(z?.categories?.length>0||_)||K&&O&&M,xe=!!g[N.key],pe=Hc(N.key,r),fe=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:pe},"aria-hidden":"true"}),Re=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(rn,{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,ee=N.percent>0?`${N.percent.toFixed(N.percent<.1&&N.percent>0?2:1)}%`:"0.0%";return e.jsxs(Ze,{level:0,colorSquare:fe,label:js(N.key),labelSuffix:Re,tokens:i(N.totals?.total_tokens||0),percent:ee,hasChevron:oe,open:xe,onToggle:()=>k(N.key),share:N.percent,fillColor:pe,children:[ce&&e.jsx("ul",{className:"space-y-0.5",children:j.map(B=>e.jsx(Ze,{level:1,label:od(B),tokens:i(B.totals.total_tokens||0),percent:null},B.key||B.name))}),ie&&z&&e.jsx(Kt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:_}),ie&&_&&!z&&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")}),K&&M&&e.jsx(Kt,{toolSet:M,execDetails:null,source:r,codexQueueFallback:!1})]},N.key)}),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.tool_calls"),tokens:i(W),percent:null,hasChevron:!0,open:!!g.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Kt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&M?.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(G),percent:null,hasChevron:!0,open:!!g.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Kt,{toolSet:M,execDetails:null,source:r,codexQueueFallback:!1})}),P?.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(q),percent:null,hasChevron:!0,open:!!g.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Kt,{toolSet:P,execDetails:null,source:r,codexQueueFallback:!1})}),I.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(I.reduce((N,$)=>N+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!g.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:I.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(dd(r))}),_?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,L?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ee(L.skills_count||0)," skills ·"," ",Ee(L.mcp_servers_count||0)," MCP servers ·"," ",Ee(L.custom_agents_count||0)," agents ·"," ",Ee(L.memory_files_count||0)," memory files"]}):null]})}function jn({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 st="__all__",hd=`${100 .toFixed(2)}%`;function Jt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function gr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Yt(a);return(a===Gs?s:s*r)<.01?`<${n}0.01`:Qt(s,{decimals:2,currency:a,rate:r})}function xd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:As(a)}:{key:a.key,label:a.label||As(a.key)}):[]}function gd(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 pd={ACODE:"var(--brand-primary-light)",CODEX:"#3b82f6",DSH:"var(--community-deepseek)",CLAUDE:"#d97757",OPENCODE:"#f59e0b",GEMINI:"#2196f3",KIMI:"#a78bfa","KILO-CLI":"#facc15","KILO-CODE":"#facc15",MIMO:"#ff6900",DROID:"#ef4444",ZCODE:"#14b8a6",ANYTHINGLLM:"var(--provider-anythingllm)",LMSTUDIO:"var(--provider-lmstudio)",UNSLOTH:"var(--provider-unsloth)"};function sr(t,a){const r=t?.toUpperCase?.()||"";return pd[r]||`hsl(${150+a*40}, 60%, 45%)`}function fd(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":a==="grok"||r==="grok"||r.includes("grok")?"grok":null}function yd(t){return t==="claude"?l("dashboard.context_breakdown.heading_claude"):t==="codex"?l("dashboard.context_breakdown.heading_codex"):t==="grok"?l("dashboard.context_breakdown.heading_grok"):l("dashboard.context_breakdown.heading")}function bd(t){return!!t?.models?.length}function Nn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function nr(t){const a=Nn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}function Ts(t){return(Number(t?.requests)||0)>0&&!(Number(t?.usage)>0)}function kd(t,a){const r=Jt(a,t?.usage),s=Math.max(0,Number(t?.requests)||0);return r&&s>0?`${r} · ${l("usage.overview.request_count",{count:s})}`:r||(s>0?l("usage.overview.request_count",{count:s}):null)}const _d={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function As(t){const a=_d[t];return a?l(a):String(t).toUpperCase()}function wd({loading:t,onClick:a}){const r=an();return e.jsx(gi,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(He.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-flex"},children:e.jsx(pi,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function vd(){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 jd(){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 Nd({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:o,summaryLabel:i,summaryCostValue:d,onCostInfo:c,fleetData:h=[],onRefresh:x,loading:p,announceLoading:m=!1,summaryLoading:g=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:v,customTo:w,onCustomRangeApply:C,customRangeOpen:D,onCustomRangeOpenChange:L,onOpenShare:A,from:I,to:j,deviceOptions:_=[],selectedDevice:T="",dataRevision:P=0,onDeviceChange:z}){const q=xd(a),M=cl(fi()),O=gd(String(s??"")),W=t==="week"&&typeof I=="string"&&typeof j=="string"&&I.slice(0,7)!==j.slice(0,7),G=t!=="day"&&I&&j?`${ya(I,M)} — ${ya(j,M)}`:null,F=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[N,$]=u.useState(F);u.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const S=window.matchMedia("(max-width: 639px)"),V=ne=>$(ne.matches);return S.addEventListener("change",V),()=>S.removeEventListener("change",V)},[]);const ce=O!=null&&!N,ie=u.useRef(null);u.useEffect(()=>{const S=ie.current?.querySelector('[aria-selected="true"]');S&&typeof S.scrollIntoView=="function"&&S.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[K,oe]=u.useState(null),{resolvedTheme:xe}=xi(),{currency:pe,rate:fe}=Ta(),{formatTokens:Re}=je(),ee=xe==="dark",B=ee?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",de=ee?"rgba(10,10,10,0)":"rgba(255,255,255,0)",te=g&&!b,re=f&&!h.some(bd);u.useEffect(()=>{oe(null)},[t,I,j,T,P]);const ye=S=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(S.key))return;const V=Array.from(S.currentTarget.querySelectorAll('[role="tab"]')).filter(ae=>!ae.disabled),ne=V.indexOf(S.target.closest('[role="tab"]'));if(ne===-1||V.length===0)return;S.preventDefault();let he=ne;S.key==="Home"?he=0:S.key==="End"?he=V.length-1:S.key==="ArrowRight"?he=(ne+1)%V.length:he=(ne-1+V.length)%V.length,V[he].focus(),V[he].click()},se=ce?e.jsx(Ul,{value:O,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:ee?0:8,gradientFrom:B,gradientTo:de,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,H=h.filter(S=>S.models?.length>0&&!Ts(S)),Z=h.filter(S=>S.models?.length>0&&Ts(S)),ge=H.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="devin"),Ie=H.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="kiro"),Ne=H.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="trae"),ve=u.useMemo(()=>Cc(h),[h]),Ve=ve.reduce((S,V)=>S+(Number(V.usage)||0),0),mt=H.reduce((S,V)=>S+(Number(V.usd)||0),0),U=K==null?null:K===st||H.some(function(V){return V.label===K})?K:null;return e.jsx(Ce,{className:k,children:e.jsxs("div",{"aria-busy":p||te||re,children:[m?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:ie,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:ye,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:q.map(S=>{const V=t===S.key,ne=`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(S.key==="custom"){const he=V&&v&&w?`${ya(v,M)} — ${ya(w,M)}`:S.label;return e.jsxs(ml,{open:D,onOpenChange:ae=>{ae?r?.("custom"):L?.(ae)},children:[e.jsx(hl,{render:e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:ne}),children:he}),e.jsx(xl,{children:e.jsx(gl,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(pl,{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(ll,{from:v,to:w,onApply:C,onCancel:()=>L?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:ne,onClick:()=>r?.(S.key),children:S.label},S.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[_.length>1?e.jsx(Xs,{value:T,onValueChange:z,options:_,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,A?e.jsxs("button",{type:"button",onClick:A,"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(Tl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,x&&e.jsx(wd,{loading:p,onClick:x})]})]}),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:i}),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:te?"invisible":void 0,children:o?e.jsx("button",{type:"button",onClick:o,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:se}):e.jsx("span",{title:n||void 0,children:se})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${te?"":"hidden"}`,children:e.jsx(vd,{})})]}),d&&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:[d,e.jsx(rn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:d})}),Ne&&e.jsxs("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("span",{className:"font-medium",children:[l("usage.overview.trae_notice_title"),"."]})," ",l("usage.overview.trae_notice_body")]}),G?e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-1 text-[11px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{className:"tabular-nums",children:G}),W?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:re?void 0:"hidden",children:e.jsx(jd,{})}),(H.length>0||Z.length>0)&&e.jsxs("div",{className:"space-y-6",children:[H.length>0&&e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:H.map(S=>l("usage.overview.distribution_item",{label:lt(S.label),percent:nr(S)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:H.map((S,V)=>{const ne=sr(S.label,V),he=lt(S.label),ae=nr(S);return e.jsx(He.div,{initial:{width:0},animate:{width:`${Nn(S)}%`},transition:{duration:.5,delay:.45+V*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:ne},title:`${he}: ${ae}%`},S.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":U===st,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:Jt(Re,Ve)||String(0),cost:gr(mt,pe,fe)||`${Yt(pe)}0`,count:ve.length}),onClick:()=>oe(U===st?null:st),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${U===st?"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(jn,{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:hd}),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:ve.length})})]}),H.map((S,V)=>{const ne=sr(S.label,V),he=U===S.label,ae=lt(S.label),ue=nr(S);return e.jsxs("button",{"aria-expanded":he,"aria-controls":`provider-details-${S.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:ae,percent:ue,tokens:Jt(Re,S.usage)||String(0),cost:gr(S.usd,pe,fe)||`${Yt(pe)}0`,action:l(he?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>oe(he?null:S.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${he?"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:S.label,size:15,color:ne,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:ae,children:ae})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[ue,"%"]}),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:S.models.length})})]},S.label)})]}),U===st&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[ge&&e.jsx(Cn,{}),Ie&&e.jsx(Tn,{}),e.jsx(Ad,{models:ve})]}),U!=null&&U!==st&&e.jsx("div",{id:`provider-details-${U}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:U}),className:"mt-2",children:H.filter(S=>S.label===U).map(S=>{const V=sr(S.label,0),ne=fd(S),he=[...S.models].sort((ue,Se)=>(Se.share||0)-(ue.share||0)),ae=ne?yd(ne):lt(S.label);return e.jsx(Ld,{provider:S,color:V,providerHeading:ae,contextSource:ne,deviceId:T,from:I,to:j,sortedModels:he},S.label)})})]}),Z.length>0&&e.jsx(Dd,{providers:Z})]})})}const Sd=[{key:"input",labelKey:"dashboard.projects.detail.comp_input"},{key:"cached",labelKey:"dashboard.projects.detail.comp_cached"},{key:"cacheCreate",labelKey:"dashboard.projects.detail.comp_cache_write"},{key:"output",labelKey:"dashboard.projects.detail.comp_output"},{key:"reasoning",labelKey:"dashboard.projects.detail.comp_reasoning"}],Cd="grid grid-cols-[minmax(0,1fr)_auto_auto_auto] items-baseline gap-x-3 mb-1.5 sm:grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_minmax(4.5rem,max-content)]";function Td({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=je();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:Sd.map(s=>{const n=Math.max(0,Number(t?.[s.key])||0);return e.jsxs("span",{className:"inline-flex items-baseline gap-1 text-[11px] tabular-nums",children:[e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-500",children:l(s.labelKey)}),e.jsx("span",{title:r(n),className:"text-oai-gray-600 dark:text-oai-gray-300",children:a(n)})]},s.key)})})}function Ds({model:t,tokensLabel:a,costLabel:r,expandable:s,isExpanded:n}){const{formatTokensTooltip:o}=je();return e.jsxs(e.Fragment,{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:t.name,children:t.name}),e.jsx("span",{title:o(t.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:a}),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:r}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(n?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(ul,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${n?"rotate-180":""}`})]})]})]})}function Sn({models:t,color:a}){const{currency:r,rate:s}=Ta(),{formatTokens:n}=je(),[o,i]=u.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(d=>{const c=kd(d,n),h=gr(d.cost,r,s),x=Math.max(0,Math.min(100,Number(d.share)||0)),p=d.id||d.name,m=jc(d),g=m&&o===p,f=Cd,b={model:d,tokensLabel:c,costLabel:h,expandable:m,isExpanded:g};return e.jsxs("div",{"data-model-rank-row":!0,children:[m?e.jsx("button",{type:"button",onClick:()=>i(g?null:p),"aria-expanded":g,className:`${f} w-full cursor-pointer text-left`,children:e.jsx(Ds,{...b})}):e.jsx("div",{className:f,children:e.jsx(Ds,{...b})}),g&&e.jsx(Td,{tokens:d.tokens}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":x,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${x}%`,backgroundColor:a,opacity:.45}})})]},p)})})}function Ad({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(jn,{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(Sn,{models:t,color:"var(--oai-blue)"})]})}function Cn(){return 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.devin_notice_title"),"."]})," ",l("usage.overview.devin_notice_body")]})}function Tn(){return 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.kiro_notice_title"),"."]})," ",l("usage.overview.kiro_notice_body")]})}function Dd({providers:t}){const a=t.map(r=>l("usage.overview.request_only_item",{label:lt(r.label),count:Math.max(0,Number(r.requests)||0)})).join(l("usage.overview.request_only_separator"));return e.jsx("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:l("usage.overview.request_only_note",{items:a})})}function Ld({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:o,sortedModels:i,deviceId:d}){const{formatTokens:c}=je(),[h,x]=u.useState(!1),p=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",m=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",g=String(t?.source||t?.label||"").trim().toLowerCase()==="kiro";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&&h&&e.jsx(dl,{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:Jt(c,t.cacheReusedTokens)||String(0),input:Jt(c,t.cacheInputTokens)||String(0)})]}),p&&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")]}),m&&e.jsx(Cn,{}),g&&e.jsx(Tn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(md,{from:n,to:o,source:s,deviceId:d,referenceTotalTokens:t.usage,onLoadingChange:x})}):null,e.jsx(Sn,{models:i,color:a})]})}function Md({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:o,transform:i,transition:d,isDragging:c}=Vi({id:t}),h=u.useRef(null),x=u.useRef(null);u.useLayoutEffect(()=>{if(!r)return;const m=h.current?h.current.childNodes.length===0:!0;x.current!==m&&(x.current=m,r(t,m))});const p={transform:Wi.Transform.toString(i)||void 0,transition:d,zIndex:c?20:void 0};return e.jsxs("div",{ref:o,style:p,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:h,"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 Ed({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[o,i]=u.useState(null),[d,c]=u.useState(!1),[h,x]=u.useState(null),p=at([t,a,r,s,n]),m=u.useCallback(async()=>{if(!t)return;const g=p();c(!0),x(null);try{const f=await ze(s);if(!g())return;const b=await yi({from:a,to:r,device:n,accessToken:f});if(!g())return;i(b||null)}catch(f){if(!g())return;x(f?.message||String(f)),i(null)}finally{g()&&c(!1)}},[t,a,r,s,n,p]);return u.useEffect(()=>{if(!t){i(null),x(null),c(!1);return}i(null),x(null),c(!0),m()},[t,m]),{data:o,loading:d,error:h,refresh:m}}function An(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 Rd(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 Id({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:An(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:Rd(t.cost_usd,t.accepted)})]})}function Fd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=je(),{enabled:o}=fl(),{data:i,loading:d}=Ed({enabled:o,from:t,to:a,deviceId:r});if(!o)return null;const c=(i&&i.available&&Array.isArray(i.by_model)?i.by_model:[]).filter(m=>m.outcomes>0&&m.key!=="unknown");if(!c.length)return null;const h=c.slice(0,6),x=i.totals||{},p=`${l("qpd.card.subtitle")}${d?` ${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:p}),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:h.map(m=>e.jsx(Id,{row:m},m.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:x.accepted??0,outcomes:x.outcomes??0,cost:An(x.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(x.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(x.effective_tokens),rate:Dn(x.acceptance_rate)})})]}),x.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 $d=new Set(["unknown","synthetic","openai"]);function or(t){return t==null?"—":`${Math.round(t*100)}%`}function Pd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Je(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function zd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!$d.has(r)&&Number(t?.edit_turns||0)>0}function Ls(){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 Od({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=u.useState({requestKey:null,loading:!0,sessions:null,context:null}),o=s.requestKey===r?s:{loading:!0,sessions:null,context:null},i=u.useId(),{enabled:d}=yl(),c=at([d,t,a]),{formatTokens:h}=je(),x=C=>h(C,{mode:Wt.COMPACT});u.useEffect(()=>{const C=c();if(!d){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([bi({from:t,to:a}),ki()]).then(([D,L])=>{C()&&n({requestKey:r,loading:!1,sessions:D,context:L})}).catch(()=>{C()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[d,t,a,r,c]);const p=u.useMemo(()=>(o.sessions?.by_model||[]).filter(zd).slice(0,5),[o.sessions]),m=u.useMemo(()=>(o.sessions?.subagents||[]).slice(0,3),[o.sessions]);if(!d||!o.loading&&!o.sessions?.available&&!o.context?.estimated_fixed_tokens)return null;const g=o.sessions?.summary||{},f=g.edit_session_rate??g.productive_rate,b=g.first_pass_rate??g.one_shot_rate,k=g.edit_sessions??g.productive_sessions??0,v=g.sessions??o.sessions?.session_count??0,w=g.edit_turns??0;return o.loading&&!o.sessions&&!o.context?e.jsxs(Ce,{children:[e.jsx(Ls,{}),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(Ls,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(ir,{label:l("sessions.card.edit_sessions"),value:or(f),detail:l("sessions.card.edit_session_value",{edits:Je(k),sessions:Je(v)})}),e.jsx(ir,{label:l("sessions.card.first_pass"),value:or(b),detail:l("sessions.card.edit_session_value",{edits:Je(g.first_pass_sessions??g.one_shot_sessions??0),sessions:Je(k)})}),e.jsx(ir,{label:l("sessions.card.cost_edit"),value:Pd(g.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Je(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:Je(v),edits:Je(w)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":i,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:i,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")})]})]}),!!p.length&&e.jsx(Pi,{wrapperClassName:"w-full",label:l("sessions.card.scroll"),children:e.jsxs("table",{className:"w-full 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 whitespace-nowrap",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:p.map(C=>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:C.model,children:C.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:l("sessions.card.edit_session_value",{edits:Je(C.edit_sessions??C.productive_sessions??0),sessions:Je(C.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:or(C.first_pass_rate??C.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums whitespace-nowrap",children:x(C.tokens_per_edit)})]},C.model))})]})}),o.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:x(o.context.estimated_fixed_tokens)})]}):null,!!m.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")}),m.map(C=>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:C.name,calls:Math.round(C.calls)})},C.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function ir({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 le({className:t}){return e.jsx("div",{className:Nt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Bd(){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(le,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function Ud(){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(le,{className:"h-4 w-32"}),e.jsx(le,{className:"h-6 w-24"})]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{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(le,{className:"h-3 w-20"}),e.jsx(le,{className:"h-3 w-12"})]},a))]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-20"}),e.jsx(Bd,{})]})}),e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-28"}),e.jsx(le,{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(le,{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(le,{className:"h-8 w-20 rounded-md"}),e.jsx(le,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(le,{className:"h-3 w-28"}),e.jsx(le,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(le,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(le,{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(le,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(le,{className:"h-3 w-12"})]}),e.jsx(le,{className:"h-5 w-10"}),e.jsx(le,{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(le,{className:"h-7 w-16 rounded"}),e.jsx(le,{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(le,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(le,{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(le,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(le,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const Hd=vl.slice(0,10),Ms=.06,qd=.11,Kd=.05;function Es({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(wl,{logos:Hd,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(He.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 Vd(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:o,identityDisplayName:i,identityStartDate:d,activeDays:c,identitySubscriptions:h,identityScrambleDurationMs:x,projectUsageEntries:p,projectUsageLimit:m,setProjectUsageLimit:g,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:v,isLocalMode:w,shouldShowInstall:C,installPrompt:D,handleCopyInstall:L,installCopied:A,installInitCmdDisplay:I,trendRowsForDisplay:j,trendFromForDisplay:_,trendToForDisplay:T,trendZoomConfig:P,usageFrom:z,usageTo:q,period:M,trendTimeZoneLabel:O,activityHeatmapBlock:W,periodsForDisplay:G,setSelectedPeriod:F,customFrom:N,customTo:$,onCustomRangeApply:ce,customRangeOpen:ie,onCustomRangeOpenChange:K,summaryLabel:oe,summaryValue:xe,summaryFullValue:pe,hasSummary:fe,summaryLoading:Re,providersLoading:ee,onToggleSummaryFormat:B,summaryTotalTokensRaw:de,summaryCostValue:te,summaryConversationsValue:re,rollingUsage:ye,costInfoEnabled:se,openCostModal:H,costModalOpen:Z,closeCostModal:ge,allowBreakdownToggle:Ie,refreshAll:Ne,usageLoadingState:ve,announceUsageLoading:Ve,initialDashboardLoading:mt,fleetData:U,hasDetailsActual:S,dailyEmptyPrefix:V,installSyncCmd:ne,dailyEmptySuffix:he,detailsColumns:ae,ariaSortFor:ue,toggleSort:Se,sortIconFor:Fe,pagedDetails:At,dailyBreakdownRows:ht,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Qe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:xt,renderDailyBreakdownDate:Q,renderDetailCell:Xt,DETAILS_PAGED_PERIODS:be,detailsPageCount:ke,detailsPage:Dt,setDetailsPage:gt,deviceOptions:_e,selectedDevice:pt,onDeviceChange:Ma,deviceUsageBlock:Lt,localHistoryOnly:ea,localHistoryRevision:Mt,leftCardOrder:ta,onLeftReorder:Et,rightCardOrder:Oe,onRightReorder:Te}=t,Rt=null,ft=null,It={statsPanel:!0,installCopy:C,activityHeatmap:!!W,deviceUsage:!!Lt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},Ea=(ta||[]).filter(me=>It[me]),aa={usageOverview:!0,dataDetails:!s},Ra=(Oe||[]).filter(me=>aa[me]);function ra(me,J){switch(me){case"statsPanel":return e.jsx(rt,{delay:J,children:e.jsx(Oc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:M,startDate:d??a("identity_card.rank_placeholder"),streakDays:c,subscriptions:h,periodConversations:re,rolling:ye,topModels:b})});case"installCopy":return e.jsx(rt,{delay:J,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:D}),e.jsxs(He.button,{onClick:L,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:I}),e.jsx(He.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:A?"Copied ✓":"Copy"},A?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(rt,{delay:J,children:W});case"deviceUsage":return e.jsx(rt,{delay:J,children:Lt});case"trendMonitor":return e.jsx(rt,{delay:J,children:e.jsx(Zs,{rows:j,from:_,to:T,period:M,timeZoneLabel:O,showTimeZoneLabel:!1,zoomConfig:P})});case"qualityPerDollar":return e.jsx(Fd,{from:z,to:q,deviceId:pt});case"sessionInsights":return e.jsx(Od,{from:z,to:q});default:return null}}function Ft(me,J){switch(me){case"usageOverview":return e.jsx(rt,{delay:J,children:e.jsx(Nd,{period:M,periods:G,onPeriodChange:F,summaryLabel:oe,summaryValue:xe,summaryFullValue:pe,hasSummary:fe,summaryLoading:Re,providersLoading:ee,onToggleSummaryFormat:fe?B:null,summaryCostValue:te,onCostInfo:se?H:null,fleetData:U,onRefresh:s?null:Ne,loading:ve,announceLoading:Ve,onOpenShare:s?null:r,customFrom:N,customTo:$,onCustomRangeApply:ce,customRangeOpen:ie,onCustomRangeOpenChange:K,from:z,to:q,deviceOptions:_e,selectedDevice:pt,dataRevision:Mt,onDeviceChange:Ma})});case"dataDetails":return e.jsx(rt,{delay:J,children:e.jsx(Pc,{projectEntries:p,projectLimit:m,onProjectLimitChange:g,projectDetailQuery:f,copy:a,hasDetailsActual:S,dailyEmptyPrefix:V,installSyncCmd:ne,dailyEmptySuffix:he,detailsColumns:ae,ariaSortFor:ue,toggleSort:Se,sortIconFor:Fe,pagedDetails:At,dailyBreakdownRows:ht,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Qe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:xt,renderDailyBreakdownDate:Q,renderDetailCell:Xt,DETAILS_PAGED_PERIODS:be,period:M,detailsPageCount:ke,detailsPage:Dt,setDetailsPage:gt})});default:return null}}const Ia=Gi(ns(el,{activationConstraint:{distance:6}}),ns(Xi,{coordinateGetter:Qi})),$t=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||Et?.(String(J.id),String($e.id))},[Et]),Pt=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||Te?.(String(J.id),String($e.id))},[Te]);function sa(me,J,$e,oa){return s?e.jsx(e.Fragment,{children:me.map((Ge,zt)=>e.jsx(jt.Fragment,{children:J(Ge,$e+Ms*zt)},Ge))}):e.jsx(Yi,{sensors:Ia,onDragEnd:oa,children:e.jsx(Ji,{items:me,strategy:Zi,children:me.map((Ge,zt)=>e.jsx(Md,{id:Ge,children:J(Ge,$e+Ms*zt)},Ge))})})}const We=sa(Ea,ra,qd,$t),na=sa(Ra,Ft,Kd,Pt);return e.jsxs(e.Fragment,{children:[e.jsxs(El,{bare:!s,hideHeader:s,header:Rt,footer:s?null:ft,className:s?"screenshot-mode":"",children:[o&&e.jsx(Es,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(is,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Es,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(is,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!o&&!n&&mt&&e.jsx(Ud,{}),!o&&!n&&!mt&&e.jsxs(e.Fragment,{children:[ea&&e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.local_data.local_history_only")}),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:We}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:na})]})]})]}),e.jsx(Dc,{isOpen:Z,onClose:ge,fleetData:U})]})}function Wd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:o=null,accountRevision:i=0,localView:d=!1}={}){const c=d&&!n&&jl(),h=!!(c||n&&o),[x,p]=u.useState(0),[m,g]=u.useState([]),[f,b]=u.useState([]),[k,v]=u.useState(!1),[w,C]=u.useState(null),D=at([h,c,t,a,r,s,o,i]),L=u.useCallback(async()=>{const A=D();if(!h){g([]),b([]),v(!1),C(null);return}v(!0),C(null);try{const I=c?null:await ze(o);if(!A())return;const j=c?await bl({from:t,to:a,timeZone:r,tzOffsetMinutes:s}):await _i({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:I});if(!A())return;g(Array.isArray(j?.devices)?j.devices:[]),b(Array.isArray(j?.account_sources)?j.account_sources:[]),p(c&&Number(j?.revision)||0)}catch(I){if(!A())return;C(I?.message||String(I)),g([]),b([])}finally{A()&&v(!1)}},[h,c,o,t,a,r,s,i,D]);return u.useEffect(()=>{if(c)return window.addEventListener(os,L),()=>window.removeEventListener(os,L)},[c,L]),u.useEffect(()=>{g([]),b([]),C(null),h&&v(!0),L()},[h,L]),{devices:m,accountSources:f,loading:k,error:w,refresh:L,revision:x}}const Gd=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Rs(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 pr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(Gd);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Rs(t.platform)} · ${s}`:Rs(t.platform)}const Is=" · ",Fs="%";function $s({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Cl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Zr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Zr,{className:a,"aria-hidden":!0}):e.jsx(nn,{className:a,"aria-hidden":!0})}function Ps(t,a){return a===t?.id||t?.isCurrent===!0}function Yd({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:o}){const{formatTokens:i,formatTokensTooltip:d}=je(),[c,h]=u.useState(""),[x,p]=u.useState(""),[m,g]=u.useState(!1),[f,b]=u.useState(""),k=typeof o=="function",v=typeof n=="function",w=!!s,C=t.reduce((_,T)=>_+(Number(T.total_tokens)||0),0)+a.reduce((_,T)=>_+(Number(T.total_tokens)||0),0),D=u.useMemo(()=>t.filter(_=>(Number(_.total_tokens)||0)>0||_.id===s).sort((_,T)=>(Number(T.total_tokens)||0)-(Number(_.total_tokens)||0)),[t,s]);function L(_){b(""),h(_.id);const T=typeof _.device_name=="string"?_.device_name:"";p(pr(_)===T?T:"")}function A(){h(""),p(""),b("")}async function I(_){const T=x.trim();if(!(!T||m)){g(!0),b("");try{await o(_.id,T),h(""),p("")}catch{b(_.id)}finally{g(!1)}}}const j=a.filter(_=>(Number(_.total_tokens)||0)>0);return D.length===0&&j.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(nn,{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")}),v&&w&&e.jsx("button",{type:"button",onClick:()=>n(""),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(_=>{const T=Number(_.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=s===_.id,q=pr(_)||l("dashboard.device_card.unnamed"),M=c===_.id,O=z?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",W=w&&!z?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[M?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($s,{platform:_.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:x,disabled:m,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:G=>p(G.target.value),onKeyDown:G=>{G.key==="Enter"?I(_):G.key==="Escape"&&A()},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:m||!x.trim(),onClick:()=>I(_),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Nl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:m,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(jr,{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 ${O}`,style:{width:`${P}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":z,"aria-label":`${l("dashboard.device_filter.aria")}: ${q}${Ps(_,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(z?"":_.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 ${W} ${z?"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($s,{platform:_.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:q,children:q}),Ps(_,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")}),_.imported_at&&e.jsx("span",{className:"shrink-0 whitespace-nowrap text-xs text-oai-gray-500",title:l("settings.local_data.snapshot_time",{time:new Date(_.exported_at).toLocaleString()}),children:l("settings.local_data.imported_label")})]}),e.jsxs("span",{title:d(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Is,P,Fs]})]})]}),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 ${O}`,style:{width:`${P}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>L(_),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(kl,{className:"h-3 w-3"})})]}),f===_.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},_.id)}),j.map(_=>{const T=Number(_.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${z}`,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:_.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:lt(_.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:d(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Is,P,Fs]})]})]}),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 ${w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${P}%`}})})]},`account-${_.source}`)})]})]})}function Ln(){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 Jd(t){if(!Ln()||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,o=>{window.clearTimeout(n),s(o)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(o){dt.delete(r),window.clearTimeout(n),s({ok:!1,error:o?.message||String(o)})}})}async function zs(t,a){if(!Ln()||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 o=window.setTimeout(()=>{ct.has(s)&&(ct.delete(s),n({ok:!1,error:"timeout"}))},8e3);ct.set(s,i=>{window.clearTimeout(o),n(i)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(i){ct.delete(s),window.clearTimeout(o),n({ok:!1,error:i?.message||String(i)})}})}const En=1200,Rn=1630,In={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},Zd="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 lr=!1;function Qd(){if(typeof document>"u"||lr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){lr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=Zd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),lr=!0}async function Xd(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function eu(t,a={}){if(typeof window>"u"||!t)return null;Qd(),await Xd(),await new Promise(c=>requestAnimationFrame(()=>c(null)));const{toBlob:r,toPng:s}=await wi(async()=>{const{toBlob:c,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:c,toPng:h}},[]),n=a.pixelRatio??2,o=t.offsetWidth||En,i=t.offsetHeight||Rn,d={pixelRatio:n,cacheBust:!0,width:o,height:i,style:{width:`${o}px`,height:`${i}px`},skipFonts:!1,filter:c=>!(c instanceof HTMLElement)||c.dataset?.screenshotExclude!=="true"};try{const c=await r(t,d);if(c)return c}catch{}try{const c=await s(t,d);return c?await(await fetch(c)).blob():null}catch{return null}}async function cr(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 Os(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 fr(t){const a=X(t);return Number.isFinite(a)?a:0}function tu(t){return t?fr(t.billable_total_tokens??t.total_tokens):0}function au(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(o=>(Array.isArray(o)?o:[]).slice(0,7).map(d=>{const c=!!d?.future,h=Number.isFinite(d?.level)?Math.max(0,Math.min(4,Math.round(d.level))):0;d?.day&&!c&&(r+=1,h>0&&(s+=1));const x=d?.billable_total_tokens??d?.total_tokens??d?.value??0,p=Number.isFinite(x)?Math.max(0,x):0;return{day:typeof d?.day=="string"?d.day:"",level:h,value:p,future:c}})),totalDays:r,activeDays:s}}function ru(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:o,rank:i,period:d,periodFrom:c,periodTo:h,heatmap:x,capturedAt:p,currency:m,exchangeRate:g}=t,f=tu(n),b=fr(n?.total_cost_usd),k=Array.isArray(o)?o.slice(0,3).map(w=>({id:w?.id??null,name:typeof w?.name=="string"&&w.name?w.name:"—",tokens:fr(w?.tokens),percent:typeof w?.percent=="string"&&w.percent?w.percent:"0.0"})):[],v=au(x);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:d,periodFrom:c,periodTo:h,topModels:k,rank:typeof i=="number"&&Number.isFinite(i)&&i>0?Math.floor(i):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:p||new Date().toISOString(),currency:typeof m=="string"&&m.length>0?m.toUpperCase():"USD",exchangeRate:Number.isFinite(g)&&g>0?g:1}}const su=["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 nu(t){const a=su[t];return a?l(a):"—"}function Fn(t,a){return l("share.date.month_year",{month:nu(t),year:a})}function ou(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 iu(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 yr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function $n(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Yt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const o=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return o>=1e3?`${n}${Math.round(o).toLocaleString("en-US")}`:`${n}${o.toFixed(2)}`}function lu(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 cu(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 du(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 uu({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:o}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const i=a||["#eee","#ccc","#999","#666","#333"],d=o||i[0],c=t.length,h=(c-1)*s,x=Math.max(4,(r-h)/c),p=7*x+6*s;return e.jsx("svg",{width:r,height:p,viewBox:`0 0 ${r} ${p}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((m,g)=>(Array.isArray(m)?m:[]).map((b,k)=>{if(k>=7)return null;const v=du(b),w=g*(x+s),C=k*(x+s),D=v===null?d:i[v];return e.jsx("rect",{x:w,y:C,width:x,height:x,rx:n,ry:n,fill:D},`${g}-${k}`)}))})}const mu=Tt("oklch(0.97 0.01 85)"),Me=Tt("oklch(0.18 0.02 85)"),et=Tt("oklch(0.38 0.015 85)"),Bs=Tt("oklch(0.55 0.012 85)"),nt=Tt("oklch(0.55 0.22 25)"),ot='"Instrument Serif", "Times New Roman", Georgia, serif',hu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',xu=["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 Pn({data:t}){const a=iu(t),r=yr(t.totalTokens),s=$n(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=ou(t.startDate),o=cu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),i=lu(t),d=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:mu,color:Me,fontFamily:hu,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 ${Bs}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Me},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:nt}}),"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:ot,fontSize:52,fontStyle:"italic",lineHeight:1,color:Me,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:Me},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:nt,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:ot,fontSize:o,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Me,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ot,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Me,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",i,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:nt,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})})]})]}),d?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:Me,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(uu,{weeks:t.heatmapWeeks,palette:xu,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 ${Me}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Me,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:ot,fontStyle:"italic",fontSize:26,color:et,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((c,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Bs}`},children:[e.jsx("div",{style:{fontFamily:ot,fontSize:34,fontStyle:"italic",color:nt,lineHeight:1},children:String(h+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:ot,fontSize:32,color:Me,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("div",{style:{fontFamily:ot,fontSize:28,color:Me,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:yr(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 ${Me}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Me},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:nt},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:nt},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:nt},children:"→ tokentracker.cc"})]})]})]})}const gu=In["annual-report"].width,pu="#0a0820",tt="#ffffffee",it="rgba(255,255,255,0.45)",dr="#a78bfa",fu={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(", ")},_a={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"},br='"Space Grotesk", "Inter Tight", sans-serif',ur='"Inter Tight", sans-serif',yu="rgba(255,255,255,0.06)",zn=[yu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],On=48,Bn=28,Ca=4,Un=20,bu=gu-On*2-Bn*2,ku=(bu-Un*2)/3,kr=Math.min(Math.floor((ku-Ca*6)/7),40),_u=kr*7+Ca*6;function wu(t){if(!Array.isArray(t))return t;const a=[];for(const d of t)if(Array.isArray(d))for(const c of d)c?.day&&!c.future&&c.value>0&&a.push(c.value);if(!a.length)return t;a.sort((d,c)=>d-c);const r=d=>{const c=a.length,h=(c-1)*d,x=Math.floor(h);return Math.round((a[x]??0)+((a[Math.min(c-1,x+1)]??0)-(a[x]??0))*(h-x))},s=r(.5),n=r(.75),o=r(.9),i=d=>!d||d<=0?0:d<=s?1:d<=n?2:d<=o?3:4;return t.map(d=>Array.isArray(d)?d.map(c=>c?.day&&!c.future&&typeof c.value=="number"?{...c,level:i(c.value)}:c):d)}function vu(t){if(!Array.isArray(t))return[];const a={},r=wu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const o=n.day.split("-");if(o.length<2)continue;const i=`${o[0]}-${o[1]}`;(a[i]??=[]).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 ju(t){if(!t.length)return[];const a=[...t].sort((i,d)=>i.day.localeCompare(d.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let i=0;i<s.length;i+=7)n.push(s.slice(i,i+7));const o=n[n.length-1];for(;o&&o.length<7;)o.push(null);return n.slice(0,6)}const Nu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Su(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const o of n)o?.day&&!o.future&&a.push(o);a.sort((n,o)=>n.day.localeCompare(o.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 Us(t){const[a,r]=u.useState(null);return u.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const o=document.createElement("canvas");o.width=n.naturalWidth,o.height=n.naturalHeight,o.getContext("2d").drawImage(n,0,0),r(o.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Cu({data:t}){const a=ju(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:it,fontFamily:br,marginBottom:4},children:Nu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ca},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ca},children:r.map((n,o)=>{const i=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:kr,height:kr,borderRadius:4,background:i<0?"transparent":zn[i]}},o)})},s))})]})}function Tu({data:t}){const a=vu(t.heatmapWeeks),r=Su(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,o=Us(n),i=Us("/neon_bg.png"),d=(t.handle||"?")[0].toUpperCase(),c=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:pu,fontFamily:br,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:i||"/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:On,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:it,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:o?e.jsx("img",{src:o,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:d})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:tt},children:t.handle})]})]}),e.jsxs("div",{style:{...fu,borderRadius:22,padding:Bn,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:it},children:[e.jsx("span",{children:l("share.card.annual.less")}),zn.map((h,x)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},x)),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,${_u}px)`,gap:`8px ${Un}px`,justifyContent:"center"},children:a.map(h=>e.jsx(Cu,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:c,marginBottom:c},children:[e.jsxs("div",{style:{..._a,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:tt,letterSpacing:"-0.02em",lineHeight:1},children:yr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:it,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{..._a,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:tt,letterSpacing:"-0.02em",lineHeight:1},children:$n(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:it,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:c},children:[e.jsxs("div",{style:{..._a,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:dr,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:it},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:ur,fontSize:28,fontWeight:700,color:tt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{..._a,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:dr,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:it},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:br,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:dr},children:"tokentracker.cc"})]})]})]})}const Hn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Au={broadsheet:Pn,"annual-report":Tu};function qn(t){return In[t]||{width:En,height:Rn}}function Du(t){const a=Hn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Hs=u.forwardRef(function({data:a,variant:r},s){const n=Au[r]||Pn,{width:o,height:i}=qn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:o,height:i,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function wa(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const Lu=440;function Mu(){const[t,a]=u.useState(null),r=u.useRef(null),s=u.useCallback((n,o="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:o,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return u.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function mr({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 Eu({open:t,onClose:a,data:r,twitterText:s}){const[n,o]=u.useState(null),[i,d]=u.useState(""),[c,h]=u.useState("annual-report"),x=u.useRef(null),{toast:p,push:m}=Mu(),g=vi(),f=u.useMemo(()=>{const j=g?.user;if(!j||typeof j!="object")return null;const _=j.user_metadata||{},T=j.profile||{},P=_.avatar_url||_.picture||T.avatar_url||j.avatar_url;return typeof P=="string"&&P.trim()?P.trim():null},[g?.user]);u.useEffect(()=>{t&&(o(null),d(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:i||r.handle,avatarUrl:f},{width:k,height:v}=qn(c),w=Lu/k;u.useEffect(()=>{if(!t)return;const j=_=>{_.key==="Escape"&&a?.()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[t,a]);const C=u.useCallback(async()=>{const j=x.current;if(!j)return null;try{return await eu(j)}catch(_){return console.warn("[share] capture failed",_),null}},[]),D=u.useCallback(async()=>{if(n)return;o("copy");const j=await C();if(!j){m(l("share.toast.failed"),"error"),o(null);return}let _=!1;if(wa()){const T=await cr(j);T&&(_=(await Jd(T)).ok)}else _=await Qr(j);m(_?l("share.toast.copied"):l("share.toast.failed"),_?"success":"error"),o(null)},[n,C,m]),L=u.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=u.useCallback(async()=>{if(n)return;o("download");const j=await C();if(!j){m(l("share.toast.failed"),"error"),o(null);return}if(wa()){const T=await cr(j);if(T&&(await zs(T,L())).ok){m(l("share.toast.downloaded"),"success"),o(null);return}}const _=Os(j,L());m(_?l("share.toast.downloaded"):l("share.toast.failed"),_?"success":"error"),o(null)},[n,C,L,m]),I=u.useCallback(async()=>{if(n)return;o("x");const j=await C();if(!j){m(l("share.toast.failed"),"error"),o(null);return}if(wa()){const z=await cr(j);z&&(await zs(z,L()),m(l("share.toast.downloaded"),"success"))}else await Qr(j)?m(l("share.toast.copied"),"success"):Os(j,L());const _=new URL("https://twitter.com/intent/tweet");s&&_.searchParams.set("text",s);const T=g?.user?.id,P=typeof T=="string"&&T?`/u/${T}`:"/";if(_.searchParams.set("url",`https://www.tokentracker.cc${P}?ref=share`),wa())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:_.toString()})}catch{window.open(_.toString(),"_blank","noopener,noreferrer")}else window.open(_.toString(),"_blank","noopener,noreferrer");o(null)},[n,C,m,s,L,g]);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:j=>{j.target===j.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Hs,{ref:x,data:b,variant:c})}),e.jsxs(He.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:k*w,height:v*w,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:k,height:v,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Hs,{data:b,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:i,onChange:j=>d(j.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:Hn.map(j=>e.jsx("button",{type:"button",onClick:()=>h(j.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",c===j.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:Du(j.id)},j.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(mr,{onClick:I,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(mr,{onClick:A,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(mr,{onClick:D,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(sn,{children:p?e.jsx(He.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",p.kind==="error"?"bg-red-600 text-white":p.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:p.text})},p.id):null})]})]}):null}function Ru(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:o,topModels:i,period:d,periodFrom:c,periodTo:h,heatmap:x,accessToken:p,userId:m,currency:g,exchangeRate:f}=t,[b,k]=u.useState(null),v=f;return u.useEffect(()=>{if(!a||!m&&!ut())return;let w=!1;return(async()=>{try{const D=await ji({accessToken:p,userId:m,period:d==="day"||d==="custom"?"week":d,metric:"all",limit:100,offset:0});if(w)return;const A=(Array.isArray(D?.entries)?D.entries:Array.isArray(D)?D:[]).find(j=>j?.is_me===!0),I=typeof A?.rank=="number"?A.rank:null;k(I)}catch{w||k(null)}})(),()=>{w=!0}},[a,p,m,d]),u.useMemo(()=>ru({handle:r,startDate:s,activeDays:n,summary:o,topModels:i,rank:b,period:d,periodFrom:c,periodTo:h,heatmap:x,currency:g,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,o,i,b,d,c,h,x,g,v])}function qs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),o={key:a,promise:n};t.current=o;const i=()=>{t.current===o&&(t.current=null)};return n.then(i,i),n}const Iu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function Fu({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const $u=["day","week","month","total","custom"],hr=new Set(["day","hour","month"]),Vt=new Set(["day","total","custom"]),Pu=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],zu=["usageOverview","dataDetails"];function xr(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 va(t){return t?St(t,null):null}function Ks(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function Ou(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function Bu(){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:!Ou(window.location.hostname)}function Am({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:o=!1,publicToken:i=null,signInUrl:d="/sign-in",signUpUrl:c="/sign-up",onMainContentVisible:h}){const{resolvedLocale:x}=Ni(),{currency:p,rate:m}=Ta(),{mode:g,setMode:f,formatTokens:b,formatTokensTooltip:k}=je(),[v,w]=u.useState(!1),[C,D]=u.useState(null),[L,A]=u.useState(null),[I,j]=u.useState(!1),[_,T]=u.useState(null),[P,z]=u.useState(0),[q,M]=u.useState(0),[O,W]=u.useState(null),G=u.useMemo(()=>typeof window>"u"?!1:Si(window.location.search),[]),F=u.useMemo(()=>Bu(),[]),[N,$]=u.useState(!1),ce=2200,[ie,K]=u.useState(!0),[oe,xe]=u.useState(!1),[pe,fe]=u.useState(!1),[Re,ee]=u.useState(!1),[B,de]=u.useState(!1),te=u.useRef(!1),re=ut(),ye=r&&!s,se=u.useMemo(()=>ye&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,ye]),H=ye?se:null,Z=o?Ci(i):H,ge=r||re||o,Ie=ye&&Zt(H),Ne=r&&s&&!o,{accountView:ve,revision:Ve,resolving:mt}=Ti(),U=ve&&!o,S=U?H:null,V=mt&&!o;u.useEffect(()=>{if(!r||re){D(null),A(null),j(!1),T(null);return}if(o)return;if(!Ie){D(null),A(null),j(!1),T(null);return}let y=!0;const E=()=>{D(null),A(null),j(!1),T(null)};return j(!0),T(null),(async()=>{let R=null;try{R=await ze(H)}catch{R=null}if(y){if(!R){E();return}try{const Y={link_code:null,expires_at:null};if(!y)return;D(typeof Y?.link_code=="string"?Y.link_code:null),A(typeof Y?.expires_at=="string"?Y.expires_at:null)}catch(Y){if(!y)return;D(null),A(null),T(Y?.message||"Failed to load link code")}finally{if(!y)return;j(!1)}}})(),()=>{y=!1}},[t,re,r,o,Ie,H,q]);const ne=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");u.useEffect(()=>{if(!ne&&(!r||re||o)){W(null);return}if(!ne&&!Ie){W(null);return}let y=!0;return(async()=>{let E=null;try{E=await ze(H)}catch{E=null}if(y){if(!E&&!ne){W(null);return}try{const R=await Ai({baseUrl:t,accessToken:E});if(!y)return;W(R&&typeof R=="object"?R:null)}catch{if(!y)return;W(null)}}})(),()=>{y=!1}},[Ie,t,H,re,o,r]);const he=u.useMemo(()=>{if(!L)return!1;const y=Date.parse(L);if(!Number.isFinite(y))return!1;const E=P||Date.now();return y<=E},[L,P]);u.useEffect(()=>{!r||re||o||!L||!he||I||(D(null),A(null),T(null),M(y=>y+1))},[he,L,I,re,r]),u.useEffect(()=>{if(!L||o)return;const y=Date.parse(L);if(!Number.isFinite(y))return;const E=Date.now();if(z(E),y<=E)return;const R=window.setTimeout(()=>z(Date.now()),y-E),Y=()=>{typeof document>"u"||document.visibilityState==="visible"&&z(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",Y),window.addEventListener("focus",Y),()=>{window.clearTimeout(R),typeof document<"u"&&document.removeEventListener("visibilitychange",Y),window.removeEventListener("focus",Y)}},[L]);const ae=u.useMemo(()=>Js(),[]),ue=u.useMemo(()=>Ys(),[]),Se=u.useMemo(()=>Di(),[]),Fe=o?null:a?.userId||a?.email||"default",[At,ht]=u.useState("month"),[qe,Aa]=u.useState(null),[Qe,Da]=u.useState(null),[La,xt]=u.useState(!1),Q=G?"total":At,Xt=u.useMemo(()=>Q==="custom"&&qe&&Qe?{from:qe,to:Qe}:Li(Q,{timeZone:ae,offsetMinutes:ue,now:Se}),[Se,Q,ae,ue,qe,Qe]),be=Xt.from,ke=Xt.to,[Dt,gt]=u.useState(null),_e=Dt&&Dt.startsWith("local:")!==U?Dt:null,[pt,Ma]=u.useState(()=>Xr());u.useEffect(()=>{const y=()=>Ma(Xr());return window.addEventListener(es,y),window.addEventListener("storage",y),()=>{window.removeEventListener(es,y),window.removeEventListener("storage",y)}},[]);const{devices:Lt,accountSources:ea,refresh:Mt,loading:ta,revision:Et}=Wd({from:be,to:ke,timeZone:ae,tzOffsetMinutes:ue,accountView:U,accountAccessToken:S,accountRevision:Ve,localView:!o&&!re}),Oe=U?Ve:Et,Te=u.useMemo(()=>Lt.filter(y=>!U||(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.isCurrent||y.id===pt})),[Lt,pt,U]),Rt=u.useMemo(()=>ea.filter(y=>(Number(y.total_tokens)||0)>0),[ea]),ft=Te.length>=2,It=(U||Te.length>=2)&&Te.length+Rt.length>=2;u.useEffect(()=>{if(!ta){if(!ft&&!It){_e!==null&&gt(null);return}_e&&!Te.some(y=>y.id===_e)&&gt(null)}},[ft,It,Te,_e,ta]);const Ea=u.useMemo(()=>ft?[{value:"",label:l("dashboard.device_filter.all")},...Te.map(y=>{const E=pr(y)||l("dashboard.device_card.unnamed"),R=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${E}${R}`}})]:[],[ft,Te,x]),aa=U?{devices:Te,accountSources:Rt}:_l(Te,Rt,_e),Ra=It?e.jsx(Yd,{devices:aa.devices,accountSources:aa.accountSources,currentDeviceId:pt,selectedDeviceId:_e||"",onSelectDevice:y=>gt(y||null),onRenameDevice:U?async(y,E)=>{const R=await ze(S);await $i({deviceId:y,name:E,accessToken:R}),await Mt()}:void 0}):null,ra=u.useMemo(()=>Mi({timeZone:ae,offsetMinutes:ue}),[ae,ue]),Ft=u.useMemo(()=>Ei({timeZone:ae,offsetMinutes:ue}),[ae,ue]),Ia=u.useMemo(()=>`Local time (${Ft})`,[Ft]),$t=ae,Pt=ue,sa=ra,We=u.useMemo(()=>vr({timeZone:ae,offsetMinutes:ue,date:Se||new Date}),[Se,ae,ue]),na=u.useMemo(()=>fc({period:Q,selectedFrom:be,selectedTo:ke,todayKey:We}),[be,Q,ke,We]),{daily:me,summary:J,rolling:$e,source:oa,loading:Ge,error:zt,refresh:Sr}=us({baseUrl:t,accessToken:Z,guestAllowed:Ne,from:be,to:ke,includeDaily:Q!=="total",cacheKey:Fe,timeZone:ae,tzOffsetMinutes:ue,now:Se,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),{daily:Cr,loading:Kn,refresh:Tr}=us({baseUrl:t,accessToken:Z,guestAllowed:Ne,from:na.from,to:na.to,includeDaily:!0,includeSummary:!1,cacheKey:Fe?`${Fe}.daily-breakdown`:"daily-breakdown",timeZone:ae,tzOffsetMinutes:ue,now:Se,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),{breakdown:Xe,loading:Ar,refresh:Dr}=Zl({baseUrl:t,accessToken:Z,guestAllowed:Ne,from:be,to:ke,cacheKey:Fe,timeZone:ae,tzOffsetMinutes:ue,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),[Vn,Wn]=u.useState(3),{entries:Gn,loading:Yn,refresh:Lr}=Gl({baseUrl:t,accessToken:Z,from:be,to:ke,timeZone:ae,tzOffsetMinutes:ue}),Mr=Q==="week"||Q==="month",ia=Q==="week"||Q==="month",Er=u.useMemo(()=>me.filter(y=>y?.future?!1:!y?.day||!We?!0:String(y.day)<=String(We)),[me,We]),{rows:Ye,from:Jn,to:Zn,loading:Qn,refresh:Rr}=Oi({baseUrl:t,accessToken:Z,guestAllowed:Ne,period:Q,from:be,to:ke,months:24,cacheKey:Fe,timeZone:$t,tzOffsetMinutes:Pt,now:Se,sharedRows:Mr?me:null,sharedRange:Mr?{from:be,to:ke}:null,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),Xn=u.useMemo(()=>({baseUrl:t,accessToken:Z,guestAllowed:Ne,cacheKey:Fe,timeZone:$t,tzOffsetMinutes:Pt,now:Se,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),[t,Z,Ne,Fe,$t,Pt,Se,U,S,Oe,V,_e]),{daily:yt,heatmap:Ke,loading:Ir,refresh:Fr}=Hl({baseUrl:t,accessToken:Z,guestAllowed:Ne,weeks:52,cacheKey:Fe,timeZone:ae,tzOffsetMinutes:ue,now:Se,accountView:U,accountAccessToken:S,accountRevision:Oe,accountViewResolving:V,deviceId:_e}),{data:la,refresh:$r}=Bi();u.useEffect(()=>{la&&typeof la=="object"&&Ri(la)},[la]);const Be=u.useMemo(()=>Q==="day"?"hour":Q==="total"?"month":"day",[Q]),eo=u.useMemo(()=>hs(Be),[Be]),ca="day",to=u.useMemo(()=>hs(ca),[]),[Ue,Pr]=u.useState(()=>({key:"day",dir:"desc"}));u.useEffect(()=>{Pr(y=>!hr.has(y.key)||y.key===Be?y:{key:Be,dir:y.dir})},[Be]);const bt=u.useMemo(()=>hr.has(Ue.key)&&Ue.key!==Be?{...Ue,key:Be}:Ue,[Be,Ue]),da=u.useMemo(()=>{if(Q==="day")return Array.isArray(Ye)?Ye.filter(R=>R?.hour&&!R?.future):[];if(Q==="total"){const R=Array.isArray(Ye)?Ye.filter(Y=>Y?.month&&!Y?.future):[];return dc(R)}const y=Er;return!y.some(R=>!R?.missing&&!R?.future)&&me.length>0?me.filter(R=>!R?.future).slice(-30).filter(R=>R?.day):y},[Q,Ye,Er,me]),Ot=u.useMemo(()=>xs(da,bt),[da,bt]),zr=u.useMemo(()=>da.some(y=>!y?.missing&&!y?.future),[da]),Fa=u.useMemo(()=>{if(!Vt.has(Q))return 1;const y=Math.ceil(Ot.length/Sa);return y>0?y:1},[Q,Ot.length]),[$a,ua]=u.useState(0);u.useEffect(()=>{if(!Vt.has(Q)){ua(0);return}ua(y=>Math.min(y,Fa-1))},[Fa,Q]),u.useEffect(()=>{Vt.has(Q)&&ua(0)},[Q,Ue.dir,Ue.key]);const ao=u.useMemo(()=>Vt.has(Q)?uc(Ot,$a,Sa):Ot,[$a,Q,Ot]),Or=u.useMemo(()=>yc(Cr,{period:Q}),[Cr,Q]),kt=u.useMemo(()=>hr.has(Ue.key)?{...Ue,key:ca}:Ue,[Ue]),ro=u.useMemo(()=>xs(Or,kt),[Or,kt]),so=u.useMemo(()=>ia?me:Q==="day"?Array.isArray(Ye)?Ye.filter(y=>y?.hour):[]:Ye,[me,Q,Ye,ia]),no=ia?be:Jn,oo=ia?ke:Zn;function io(y,E){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(E.endsWith("_tokens")){const R=E==="total_tokens"?va(y):y?.[E];return e.jsx("span",{title:k(R),children:b(R)})}return Na(y?.[E])}function lo(y){const E=y?.[Be];if(E==null)return"";const R=String(E);if(Be==="hour"){const[Y,De]=R.split("T");if(Y&&De)return`${Y} ${De.slice(0,5)}`}return R}function co(y){const E=y?.[ca];return E==null?"":String(E)}function uo(y){Pr(E=>E.key===y?{key:y,dir:E.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function mo(y){return bt.key!==y?"none":bt.dir==="asc"?"ascending":"descending"}function ho(y){return bt.key!==y?"":bt.dir==="asc"?"▲":"▼"}function xo(y){return kt.key!==y?"none":kt.dir==="asc"?"ascending":"descending"}function go(y){return kt.key!==y?"":kt.dir==="asc"?"▲":"▼"}const Pa=u.useMemo(()=>{if(!r&&!re&&!o&&!ne)return 0;const y=Number(Ke?.active_days);if(Number.isFinite(y))return y;let E=0;const R=new Set,Y=(we,Pe,Le)=>{typeof we!="string"||!we||R.has(we)||xr(Pe,Le)&&(R.add(we),E+=1)};if(Array.isArray(yt))for(const we of yt)Y(we?.day,va(we));const De=Array.isArray(Ke?.weeks)?Ke.weeks:[];for(const we of De)for(const Pe of Array.isArray(we)?we:[]){const Le=Ks(Pe);Y(Pe?.day,Le,Pe?.level)}return E},[r,re,Ke?.active_days,Ke?.weeks,yt]),[Br,Ur]=u.useState("month"),po=u.useCallback(y=>{U&&!o&&Ja(a?.userId,"history"),y==="custom"?(Ur(E=>E==="custom"?"month":E),ht(E=>qe&&Qe?"custom":E),xt(!0)):(ht(y),Ur(y),xt(!1))},[qe,Qe,U,o,a?.userId]),fo=u.useCallback((y,E)=>{U&&!o&&Ja(a?.userId,"history"),Aa(y),Da(E),ht("custom"),xt(!1)},[U,o,a?.userId]),yo=u.useCallback(y=>{xt(y),!y&&At==="custom"&&!qe&&ht(Br)},[At,qe,Br]),bo=u.useRef(null),ma=u.useMemo(()=>[t||"",Fe||"",U?"cloud":"local",Oe??"",Q||"",be||"",ke||"",We||"",_e||"all",ae||"",ue??""].join(""),[Oe,U,t,Fe,be,Q,_e,ae,We,ke,ue]),Bt=u.useCallback(async()=>qs(bo,ma,async()=>{U&&Ii(),U||Fi(),await Promise.all([Sr(),Fr(),Rr(),Dr(),Lr(),Tr(),...U?[]:[Mt()]])}),[U,Tr,Mt,Fr,Dr,Lr,Rr,Sr,ma]),ko=u.useRef(null),Hr=u.useCallback(async()=>qs(ko,ma,async()=>{await Fu({refreshUsageStats:Bt,refreshUsageLimits:$r})}),[ma,$r,Bt]),za=u.useRef(Bt);u.useEffect(()=>{za.current=Bt},[Bt]);const Oa=u.useRef(null);u.useEffect(()=>{if(!ne||re||U)return;Oa.current||(Oa.current=ts({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Oa.current.then(()=>{if(y)return za.current()}).catch(E=>{y&&console.warn("[DashboardPage] Reload sync failed:",E)}),()=>{y=!1}},[ne,re,U]),u.useEffect(()=>{if(!ne||re||U)return;const y=gc({refresh:()=>za.current(),onError:E=>console.warn("[DashboardPage] Automatic usage refresh failed:",E)});return()=>y.stop()},[ne,re,U]);const _o=u.useCallback(async()=>{ee(!0);try{ne&&await ts(Iu),await Hr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{ee(!1)}},[ne,Hr]),ha=Re||Ge||Kn||Ir||Qn||Ar||Yn,Ba=!B&&(V||U&&ha&&!zr),wo=u.useMemo(()=>l("shared.data_source",{source:String(oa||"edge").toUpperCase()}),[oa,x]),xa=u.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),vo="",qr=u.useMemo(()=>!xa||xa.includes("@")?l("dashboard.identity.fallback"):xa,[xa]),Kr=u.useMemo(()=>qr.replace(/[^a-zA-Z0-9._-]/g,"_"),[qr]),Vr=u.useMemo(()=>o?l("dashboard.identity.fallback"):Kr,[Kr,vo,o]),Wr=u.useMemo(()=>{let y=null;const E=Y=>{typeof Y!="string"||!Y||(!y||Y<y)&&(y=Y)};if(Array.isArray(yt))for(const Y of yt)Y?.day&&xr(va(Y))&&E(Y.day);const R=Array.isArray(Ke?.weeks)?Ke.weeks:[];for(const Y of R)for(const De of Array.isArray(Y)?Y:[]){if(!De?.day)continue;const we=Ks(De),Pe=De?.level;xr(we,Pe)&&E(De.day)}return y},[Ke?.weeks,yt]),jo=u.useMemo(()=>o?[]:(Array.isArray(O?.subscriptions?.items)?O.subscriptions.items:[]).map(R=>{const Y=typeof R?.tool=="string"?R.tool.trim():"",we=(typeof R?.plan_type=="string"?R.plan_type:typeof R?.planType=="string"?R.planType:"").trim();return!Y||!we?null:{tool:Y,planType:we,provider:typeof R?.provider=="string"?R.provider.trim():"",product:typeof R?.product=="string"?R.product.trim():"",rateLimitTier:typeof R?.rate_limit_tier=="string"?R.rate_limit_tier.trim():typeof R?.rateLimitTier=="string"?R.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[o,O]),No=e.jsx(Ui,{heatmap:Ke,timeZoneLabel:ra,timeZoneShortLabel:Ft,hideLegend:G,defaultToLatestMonth:G}),So=u.useMemo(()=>`${be}..${ke}`,[be,Q,ke]),Co=l("usage.summary.total"),Ae=J!=null,_t=Ae?va(J):0,To=b(_t),Ao=u.useCallback(()=>{f(g===Wt.COMPACT?Wt.FULL:Wt.COMPACT)},[f,g]),Do=l("dashboard.core_index.collapse_label"),Lo=l("dashboard.core_index.expand_label"),Mo=l("dashboard.core_index.collapse_aria"),Eo=l("dashboard.core_index.expand_aria"),Ro=!G,wt=l("shared.placeholder.short"),Ua=u.useMemo(()=>{const y=Array.isArray(Xe?.sources)?Xe.sources:[];let E=null,R=0;for(const Pe of y){const Le=St(Pe?.totals);!Number.isFinite(Le)||Le<=0||Le>R&&(R=Le,E=Pe)}let Y=wt,De=wt,we="0.0";if(E&&R>0){Y=E?.source?String(E.source).toUpperCase():wt;const Pe=Array.isArray(E?.models)?E.models:[];let Le=0;for(const Ya of Pe){const pa=St(Ya?.totals);!Number.isFinite(pa)||pa<=0||pa>Le&&(Le=pa,De=Ya?.model?String(Ya.model):wt)}Le>0&&(we=(Le/R*100).toFixed(1))}return{agentName:Y,modelName:De,modelPercent:we}},[Xe,wt]),Ha=Na(_t),Io=l("dashboard.screenshot.twitter_text",{total_tokens:Ha==="-"?wt:Ha,agent_name:Ua.agentName,model_name:Ua.modelName,model_percent:Ua.modelPercent}),Fo=u.useMemo(()=>G?[]:$u,[G]),$o=u.useMemo(()=>[{label:l("usage.metric.total"),value:Ae?b(_t):"—",title:Ae?k(_t):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Ae?b(J?.input_tokens):"—",title:Ae?k(J?.input_tokens):void 0},{label:l("usage.metric.output"),value:Ae?b(J?.output_tokens):"—",title:Ae?k(J?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Ae?b(J?.cached_input_tokens):"—",title:Ae?k(J?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Ae?b(J?.reasoning_output_tokens):"—",title:Ae?k(J?.reasoning_output_tokens):void 0}],[J?.cached_input_tokens,J?.input_tokens,J?.output_tokens,J?.reasoning_output_tokens,_t,Ae,b,k]),qa=(Xe?.sources||[]).some(y=>(y.models||[]).some(E=>E.pricing?.status==="unpriced"&&E.cost_source!=="provider_reported"&&Number(E.totals?.total_tokens)>0)),Ka=u.useMemo(()=>{if(qa&&Number(J?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=Qt(J?.total_cost_usd,{currency:p,rate:m});return qa&&y!=="-"?`≥${y}`:y},[J?.total_cost_usd,p,m,qa]),Po=u.useMemo(()=>J?.conversation_count??null,[J?.conversation_count]),Gr=u.useMemo(()=>Sc(Xe,{copyFn:l}),[Xe]),Yr=u.useMemo(()=>Tc(Xe,{limit:3,copyFn:l}),[Xe]),zo=Ru({enabled:N,handle:Vr,startDate:Wr,activeDays:Pa,summary:J,topModels:Yr,period:Q,periodFrom:be,periodTo:ke,heatmap:Ke,accessToken:typeof Z=="string"?Z:null,userId:a?.userId||null,currency:p,exchangeRate:m}),Oo=u.useCallback(()=>$(!0),[]),Bo=u.useCallback(()=>$(!1),[]),Uo=u.useCallback(()=>w(!0),[]),Ho=u.useCallback(()=>w(!1),[]),qo=Ka&&Ka!=="-"&&Gr.length>0,Ut=l("dashboard.install.cmd.init"),Va=he?null:C,Wa=Va?l("dashboard.install.cmd.init_link_code",{link_code:Va}):Ut,Ko=Ut,Vo=l("dashboard.install.cmd.sync"),Wo=Va?l("dashboard.install.copy"):l("dashboard.install.copy_base"),Go=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const Yo=!!(O?.install?.has_active_device_token??O?.install?.hasActiveDeviceToken),Jo=mc({publicMode:o,screenshotMode:G,forceInstall:F,accessEnabled:ge,heatmapLoading:Ir,activeDays:Pa,hasActiveDeviceToken:Yo}),Zo=l("dashboard.install.prompt"),Qo=u.useCallback(async()=>{!Wa||!await as(Wa)||(xe(!0),window.setTimeout(()=>xe(!1),2e3))},[Wa]);u.useCallback(async()=>{!Ut||!await as(Ut)||(fe(!0),window.setTimeout(()=>fe(!1),2e3))},[Ut]);const Ga=u.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[x]),[Xo,ei]=u.useMemo(()=>{const y=Ga.split("{{cmd}}");return y.length===1?[Ga,""]:[y[0],y.slice(1).join("{{cmd}}")]},[Ga]),Ht=s&&!o,qt=!r&&!re&&!s&&!ne&&!o;u.useEffect(()=>{Ht||qt||Ba||de(!0)},[Ba,qt,Ht]);const ga=Vl(Pu,zu);return u.useEffect(()=>{te.current||Ht||qt||ha||(te.current=!0,h?.())},[h,qt,Ht,ha]),e.jsxs(e.Fragment,{children:[e.jsx(Vd,{copy:l,onOpenShare:Oo,screenshotMode:G,showExpiredGate:Ht,showAuthGate:qt,identityDisplayName:Vr,identityStartDate:Wr,activeDays:Pa,identitySubscriptions:jo,identityScrambleDurationMs:ce,projectUsageEntries:Gn,projectUsageLimit:Vn,setProjectUsageLimit:Wn,projectDetailQuery:{from:be,to:ke,timeZone:ae,tzOffsetMinutes:ue},topModels:Yr,signedIn:r,publicMode:o,isLocalMode:ne,shouldShowInstall:Jo,installPrompt:Zo,handleCopyInstall:Qo,installCopied:oe,installCopiedLabel:Go,installCopyLabel:Wo,installInitCmdDisplay:Ko,linkCodeLoading:I,linkCodeError:_,trendRowsForDisplay:so,trendFromForDisplay:no,trendToForDisplay:oo,trendZoomConfig:Xn,usageFrom:be,usageTo:ke,period:Q,trendTimeZoneLabel:sa,activityHeatmapBlock:No,periodsForDisplay:Fo,setSelectedPeriod:po,customFrom:qe,customTo:Qe,onCustomRangeApply:fo,customRangeOpen:La,onCustomRangeOpenChange:yo,metricsRows:$o,summaryLabel:Co,summaryValue:To,hasSummary:Ae,summaryLoading:Ge,providersLoading:Ar,summaryFullValue:Ha,onToggleSummaryFormat:Ao,summaryTotalTokensRaw:X(_t)||0,summaryCostValue:Ka,summaryConversationsValue:Po,rollingUsage:$e,costInfoEnabled:qo,openCostModal:Uo,allowBreakdownToggle:Ro,coreIndexCollapsed:ie,setCoreIndexCollapsed:K,coreIndexCollapseLabel:Do,coreIndexExpandLabel:Lo,coreIndexCollapseAria:Mo,coreIndexExpandAria:Eo,refreshAll:_o,usageLoadingState:ha,announceUsageLoading:Re,initialDashboardLoading:Ba,usageError:zt,rangeLabel:So,timeZoneRangeLabel:Ia,usageSourceLabel:wo,fleetData:Gr,hasDetailsActual:zr,dailyEmptyPrefix:Xo,installSyncCmd:Vo,dailyEmptySuffix:ei,detailsColumns:eo,ariaSortFor:mo,toggleSort:uo,sortIconFor:ho,pagedDetails:ao,dailyBreakdownRows:ro,dailyBreakdownColumns:to,dailyBreakdownAriaSortFor:xo,dailyBreakdownSortIconFor:go,dailyBreakdownDateKey:ca,detailsDateKey:Be,renderDetailDate:lo,renderDailyBreakdownDate:co,renderDetailCell:io,DETAILS_PAGED_PERIODS:Vt,detailsPageCount:Fa,detailsPage:$a,setDetailsPage:ua,costModalOpen:v,closeCostModal:Ho,deviceOptions:Ea,selectedDevice:_e||"",onDeviceChange:y=>{U&&!o&&Ja(a?.userId,"view"),gt(y||null)},deviceUsageBlock:Ra,localHistoryOnly:!U&&Te.some(y=>y.imported_at),localHistoryRevision:U?0:Et,leftCardOrder:ga.left.order,onLeftReorder:ga.left.reorder,rightCardOrder:ga.right.order,onRightReorder:ga.right.reorder}),e.jsx(Eu,{open:N,onClose:Bo,data:zo,twitterText:Io})]})}export{Am as DashboardPage};