tokentracker-cli 1.3.5 → 1.3.7

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 (123) hide show
  1. package/THIRD_PARTY_NOTICES.md +39 -0
  2. package/dashboard/dist/THIRD_PARTY_NOTICES.txt +39 -0
  3. package/dashboard/dist/assets/{AchievementBadge-Dazs3pEa.js → AchievementBadge-B6Ys-Iv6.js} +1 -1
  4. package/dashboard/dist/assets/{AchievementsPage-LWnxZvmw.js → AchievementsPage-C7EJYb05.js} +2 -2
  5. package/dashboard/dist/assets/{AchievementsSection-BLqczmU9.js → AchievementsSection-KjJeaWDP.js} +1 -1
  6. package/dashboard/dist/assets/{BadgeDetailModal-B_n4aj2S.js → BadgeDetailModal-BdoapwT5.js} +1 -1
  7. package/dashboard/dist/assets/{BotAnimated-KDWI_YcZ.js → BotAnimated-coLP7eiI.js} +1 -1
  8. package/dashboard/dist/assets/{Card-BYoxd4OC.js → Card-CMShFKqX.js} +1 -1
  9. package/dashboard/dist/assets/{CloudCheckoutPage-BR2_B03P.js → CloudCheckoutPage-DQ16a4Ui.js} +1 -1
  10. package/dashboard/dist/assets/CloudPage-D1PEMzr2.js +2 -0
  11. package/dashboard/dist/assets/{CloudUsageExport-C_DqZKo1.js → CloudUsageExport-Dn7_qVGy.js} +1 -1
  12. package/dashboard/dist/assets/{CommandPalette-DkCaIQI4.js → CommandPalette-t3sXFKqr.js} +1 -1
  13. package/dashboard/dist/assets/{CommunityStatsModal-pX9OePi4.js → CommunityStatsModal-DHyreMHY.js} +1 -1
  14. package/dashboard/dist/assets/{ConfirmModal-tkgZwz4u.js → ConfirmModal-DiguIoDY.js} +1 -1
  15. package/dashboard/dist/assets/{Controls-MTUhGWy8.js → Controls-D6267L_q.js} +1 -1
  16. package/dashboard/dist/assets/{DashboardPage-SOx-A7lH.js → DashboardPage-0xC6i2rZ.js} +1 -1
  17. package/dashboard/dist/assets/{DateRangePopover-B-BMOm3O.js → DateRangePopover-CVZTfOUX.js} +1 -1
  18. package/dashboard/dist/assets/{DevicePage-DSK9lm7v.js → DevicePage-BagH0rTy.js} +1 -1
  19. package/dashboard/dist/assets/{DialogClose-uVUNu4rg.js → DialogClose-IWs31AbB.js} +1 -1
  20. package/dashboard/dist/assets/DialogDescription-JwE-wyWI.js +1 -0
  21. package/dashboard/dist/assets/{DialogTitle-B-VifiA3.js → DialogTitle-CI8xcLkd.js} +1 -1
  22. package/dashboard/dist/assets/ElectricLogo-CakZnEiu.js +282 -0
  23. package/dashboard/dist/assets/ElectricLogo-D0wiAojj.css +1 -0
  24. package/dashboard/dist/assets/{FadeIn-B6lrj4uo.js → FadeIn-BJiqknMG.js} +1 -1
  25. package/dashboard/dist/assets/{HeaderGithubStar-Cx5zOhXa.js → HeaderGithubStar-Bo6VoGCl.js} +1 -1
  26. package/dashboard/dist/assets/{HoverTooltip-DY1ENf69.js → HoverTooltip-DjJmYzbc.js} +1 -1
  27. package/dashboard/dist/assets/{IpCheckPage-D6TEq64d.js → IpCheckPage-Cp2ELhP8.js} +1 -1
  28. package/dashboard/dist/assets/{LandingPage-OdZUfq--.js → LandingPage-gvBFMTKh.js} +2 -2
  29. package/dashboard/dist/assets/{LeaderboardPage-DCK5xcAt.js → LeaderboardPage-CbWwclwl.js} +2 -2
  30. package/dashboard/dist/assets/{LeaderboardProBadge-CBXJ1u_m.js → LeaderboardProBadge-QK4hLmn1.js} +1 -1
  31. package/dashboard/dist/assets/{LeaderboardProfileModal-Ccdzb7QK.js → LeaderboardProfileModal-DuggTNlv.js} +3 -3
  32. package/dashboard/dist/assets/{LeaderboardProfilePage-CFXlZ0fL.js → LeaderboardProfilePage-CZZAm33s.js} +1 -1
  33. package/dashboard/dist/assets/{LimitsPage-5krjm-g9.js → LimitsPage-DJkws70g.js} +1 -1
  34. package/dashboard/dist/assets/{LocalOnlyNotice-Rk1B8PaZ.js → LocalOnlyNotice-Cf9NPAL1.js} +1 -1
  35. package/dashboard/dist/assets/{LoginCard-DTTIm8vk.js → LoginCard-s3qsEOET.js} +1 -1
  36. package/dashboard/dist/assets/{LoginModal-BNcDdjfr.js → LoginModal-BTLHl4eP.js} +1 -1
  37. package/dashboard/dist/assets/{LoginPage-CQgXP7Ee.js → LoginPage-DDqQpy85.js} +1 -1
  38. package/dashboard/dist/assets/{PetPage-Cw_kAPRs.js → PetPage-D4P5yDL8.js} +1 -1
  39. package/dashboard/dist/assets/{PopoverPopup-NYiGE8A2.js → PopoverPopup-B_fwRpm_.js} +1 -1
  40. package/dashboard/dist/assets/{ProviderIcon-Bp7iFJ_m.js → ProviderIcon-B1oef_V8.js} +1 -1
  41. package/dashboard/dist/assets/{ResetPasswordPage-Cf9kAWDW.js → ResetPasswordPage-BduujSou.js} +1 -1
  42. package/dashboard/dist/assets/{Select-kIcvQFAo.js → Select-ClkKzKsi.js} +1 -1
  43. package/dashboard/dist/assets/{SelectItemText-BpIsAg3b.js → SelectItemText-D_4VNKEi.js} +1 -1
  44. package/dashboard/dist/assets/{SelfHostPage-Ch2vvSwI.js → SelfHostPage-CDNLHmOx.js} +1 -1
  45. package/dashboard/dist/assets/{ServiceStatusPage-hoYBvGbu.js → ServiceStatusPage-V1exv7gK.js} +1 -1
  46. package/dashboard/dist/assets/{SessionsPage-BzRB6q-Z.js → SessionsPage-BR5gBSc1.js} +2 -2
  47. package/dashboard/dist/assets/SettingsPage-LJJCS1G0.js +2 -0
  48. package/dashboard/dist/assets/{SkillsPage-CkqThTZL.js → SkillsPage-D0oeWRew.js} +1 -1
  49. package/dashboard/dist/assets/{TokenGalaxy-eLG-UIZY.js → TokenGalaxy-h5USfWnF.js} +1 -1
  50. package/dashboard/dist/assets/{TooltipPopup-bnMJyilQ.js → TooltipPopup-1KxZ_iHu.js} +1 -1
  51. package/dashboard/dist/assets/{TrendMonitor-X7-aGzIv.js → TrendMonitor-gMTrGZzH.js} +1 -1
  52. package/dashboard/dist/assets/{WidgetsPage-CGznIzrW.js → WidgetsPage-xghIyvm_.js} +1 -1
  53. package/dashboard/dist/assets/{WrappedPage-p31-uUoF.js → WrappedPage-O4zzP87x.js} +1 -1
  54. package/dashboard/dist/assets/__vite-browser-external-DKVGjnxf.js +45 -0
  55. package/dashboard/dist/assets/__vite-browser-external-DvNSoTb8.css +1 -0
  56. package/dashboard/dist/assets/{agent-logos-2TVT3fIE.js → agent-logos-CyXPIQ5S.js} +1 -1
  57. package/dashboard/dist/assets/{arrow-left-DL0hAp_7.js → arrow-left-BqMZ7dgK.js} +1 -1
  58. package/dashboard/dist/assets/{arrow-right-DFCpnV_9.js → arrow-right-D2cfRUf2.js} +1 -1
  59. package/dashboard/dist/assets/{arrow-up-right-DLvfE0Wu.js → arrow-up-right-DSJpQHMH.js} +1 -1
  60. package/dashboard/dist/assets/{calendar-days-B0aDoKSG.js → calendar-days-Cpu5CPAM.js} +1 -1
  61. package/dashboard/dist/assets/{check-C_cfrxiz.js → check-BTSG8HIW.js} +1 -1
  62. package/dashboard/dist/assets/{chevron-down-Ck8ml43e.js → chevron-down-0nuZGQbD.js} +1 -1
  63. package/dashboard/dist/assets/{cloud-checkout-PYnwNfdH.js → cloud-checkout-Jv0vhd5v.js} +1 -1
  64. package/dashboard/dist/assets/{composite-INW-ELWX.js → composite-_t6vz49X.js} +1 -1
  65. package/dashboard/dist/assets/{download-B7uokeIo.js → download-CzxvhDR9.js} +1 -1
  66. package/dashboard/dist/assets/{external-link-CI3crg4K.js → external-link-BwKhoPLM.js} +1 -1
  67. package/dashboard/dist/assets/{flame-DCzvFKV1.js → flame-Bni4FlSO.js} +1 -1
  68. package/dashboard/dist/assets/{format-tokens-CSTEYK2m.js → format-tokens-BLPhLm4w.js} +1 -1
  69. package/dashboard/dist/assets/{gift-dEHDFMc6.js → gift-lj3smodH.js} +1 -1
  70. package/dashboard/dist/assets/{host-mode-r2SW9Mdv.js → host-mode-DluVCV7W.js} +1 -1
  71. package/dashboard/dist/assets/{icons-q-3zvEkh.js → icons-BThVE2Zq.js} +1 -1
  72. package/dashboard/dist/assets/{index-CyHYj9XI.js → index-CETYrL7R.js} +1 -1
  73. package/dashboard/dist/assets/{index-BbrsgHf4.js → index-CarMa6Pv.js} +1 -1
  74. package/dashboard/dist/assets/{index-BV7qwUw4.js → index-D_ERbEBI.js} +1 -1
  75. package/dashboard/dist/assets/{info-BBdY9hV4.js → info-DSgWF_40.js} +1 -1
  76. package/dashboard/dist/assets/{link-2-CLPePfXs.js → link-2-C7H_UH8Q.js} +1 -1
  77. package/dashboard/dist/assets/{loader-circle-ETrjzfmn.js → loader-circle-B2ln5DKm.js} +1 -1
  78. package/dashboard/dist/assets/{modifiers.esm-DHqnp2ol.js → modifiers.esm-DHEGy9eE.js} +1 -1
  79. package/dashboard/dist/assets/{monitor-smartphone-D1kdzrdb.js → monitor-smartphone-BI3aJPNi.js} +1 -1
  80. package/dashboard/dist/assets/{play-Cxp-ronD.js → play-CVxzAkNo.js} +1 -1
  81. package/dashboard/dist/assets/{plus-4n94VzDK.js → plus-UGoZah-U.js} +1 -1
  82. package/dashboard/dist/assets/{provider-display-CRlbeO7t.js → provider-display-C-ibpm5u.js} +1 -1
  83. package/dashboard/dist/assets/{react-DlHjGQFN.js → react-_bbDNdaT.js} +1 -1
  84. package/dashboard/dist/assets/{safePolygon-CVZ27a2_.js → safePolygon-DeLf2a7a.js} +1 -1
  85. package/dashboard/dist/assets/{search-BDPr56_h.js → search-BzL7DvcZ.js} +1 -1
  86. package/dashboard/dist/assets/{server-Bm7fHvVa.js → server-BsilXoLs.js} +1 -1
  87. package/dashboard/dist/assets/{shield-check-DtT8ACzI.js → shield-check-Dx8cSMB0.js} +1 -1
  88. package/dashboard/dist/assets/{skills-api-Dc1-2qu6.js → skills-api-CnOpyIPR.js} +1 -1
  89. package/dashboard/dist/assets/{sortable.esm-B-qN-Xk2.js → sortable.esm-DrIfxJ2p.js} +1 -1
  90. package/dashboard/dist/assets/{store-gHeBU8dQ.js → store-CjkDYjXp.js} +1 -1
  91. package/dashboard/dist/assets/{terminal-D4VZbvhg.js → terminal-CExBqXDx.js} +1 -1
  92. package/dashboard/dist/assets/{trash-BZtLAFQy.js → trash-DSHRpaMy.js} +1 -1
  93. package/dashboard/dist/assets/{use-community-stats-BdqndrbB.js → use-community-stats-B1W63PCE.js} +1 -1
  94. package/dashboard/dist/assets/{use-latest-request-guard-DhGg1cDS.js → use-latest-request-guard-8-lur0NI.js} +1 -1
  95. package/dashboard/dist/assets/{use-limits-display-prefs-D3HOcRFv.js → use-limits-display-prefs-Dq0e_5PV.js} +1 -1
  96. package/dashboard/dist/assets/{use-native-settings-BniKwA_n.js → use-native-settings-CkPyWn4W.js} +1 -1
  97. package/dashboard/dist/assets/{use-ordered-list-b09H7EHq.js → use-ordered-list-Cul7GZDv.js} +1 -1
  98. package/dashboard/dist/assets/{use-pet-settings-CPZdlq_e.js → use-pet-settings-DkNURWe6.js} +2 -2
  99. package/dashboard/dist/assets/use-reduced-motion-CkHJN2uY.js +1 -0
  100. package/dashboard/dist/assets/{use-transform-CIdxjmI8.js → use-transform-DzUhSbxH.js} +1 -1
  101. package/dashboard/dist/assets/{use-usage-limits-eJlU65yY.js → use-usage-limits-3ZkgTe7n.js} +1 -1
  102. package/dashboard/dist/assets/{useCurrency-CM22CmAq.js → useCurrency-EbqxSlEF.js} +1 -1
  103. package/dashboard/dist/assets/{usePositioner-B3l2ulTw.js → usePositioner-cTX1WPQP.js} +1 -1
  104. package/dashboard/dist/assets/{useTokenFormat-D7nzgxKw.js → useTokenFormat-CanmWK4w.js} +1 -1
  105. package/dashboard/dist/assets/{zap-Daxct1WV.js → zap-DQHYg9o6.js} +1 -1
  106. package/dashboard/dist/index.html +2 -2
  107. package/dashboard/dist/ip-check.html +2 -2
  108. package/dashboard/dist/leaderboard.html +2 -2
  109. package/dashboard/dist/share.html +2 -2
  110. package/dashboard/dist/token-tracker-bolt-outline.svg +3 -0
  111. package/dashboard/dist/token-tracker-bolt.svg +3 -0
  112. package/package.json +1 -1
  113. package/src/cli.js +1 -1
  114. package/src/lib/pricing/seed-snapshot.json +1 -1
  115. package/src/lib/rollout.js +49 -16
  116. package/src/lib/session-analytics.js +546 -52
  117. package/src/lib/session-performance.js +24 -1
  118. package/dashboard/dist/assets/CloudPage-DL5RkJKK.js +0 -1
  119. package/dashboard/dist/assets/DialogDescription-DBqGGWNj.js +0 -1
  120. package/dashboard/dist/assets/SettingsPage-DRl2uX-i.js +0 -2
  121. package/dashboard/dist/assets/__vite-browser-external-2g_4s3ot.js +0 -45
  122. package/dashboard/dist/assets/__vite-browser-external-LpFw4zXh.css +0 -1
  123. package/dashboard/dist/assets/use-reduced-motion-D1gcKJUo.js +0 -1
@@ -1 +1 @@
1
- import{o as Nr,r as c,j as e,L as li,dw as ci,W as ht,aA as Zt,aB as Ue,dx as di,dy as ui,ay as Qr,dz as ya,aG as Zs,aH as Qs,aI as Sr,dA as mi,dB as hi,dC as xi,aK as Cr,aJ as Gt,dD as gi,dE as pi,dF as te,c as l,V as jt,X as Tr,i as $e,az as Qt,bs as Yt,z as Xs,dG as fi,an as yi,l as qt,ck as Sa,y as St,dH as bi,U as en,Q as tn,aM as ki,ao as wi,B as _i,R as vi,h as ji,u as Ni,a as an,p as Da,v as rn,bc as Si,dI as Ci,dJ as Ti,dK as Di,dL as Ai,dM as Li,am as Xr,_ as Mi,dN as es,g as Ei,Z as Ii,cX as Ri,dO as Fi,dP as $i,dQ as Pi,dR as Bi,dS as zi,cl as ts,cq as as,dT as Oi,dU as Ui,aT as Hi,cB as er,dV as rs,aR as ss,dW as Ki,dX as Vi,dY as Wi}from"./__vite-browser-external-2g_4s3ot.js";import{u as rt}from"./use-latest-request-guard-DhGg1cDS.js";import{u as ns}from"./use-ordered-list-b09H7EHq.js";import{t as os,T as sn,g as qi,u as Gi}from"./TrendMonitor-X7-aGzIv.js";import{u as Yi}from"./use-usage-limits-eJlU65yY.js";import{u as Aa}from"./useCurrency-CM22CmAq.js";import{u as De}from"./useTokenFormat-D7nzgxKw.js";import{f as Nt,A as Ji}from"./provider-display-CRlbeO7t.js";import{g as Zi,q as nn,J as Qi,M as Xi,m as pe}from"./react-DlHjGQFN.js";import{u as el,C as tl,a as al,b as is,D as rl,S as sl,v as nl,s as ol,K as il,P as ll}from"./sortable.esm-B-qN-Xk2.js";import{D as cl,a as dl,b as ul,c as ml,d as hl,e as xl}from"./DialogTitle-B-VifiA3.js";import{D as gl}from"./DialogClose-uVUNu4rg.js";import{C as Le}from"./Card-BYoxd4OC.js";import{S as on}from"./Select-kIcvQFAo.js";import{P as Tt}from"./ProviderIcon-Bp7iFJ_m.js";import{u as Xt}from"./use-reduced-motion-D1gcKJUo.js";import{a as ln,u as cn}from"./use-transform-CIdxjmI8.js";import{f as ba,D as pl,g as fl}from"./DateRangePopover-B-BMOm3O.js";import{I as dn}from"./info-BBdY9hV4.js";import{A as Dt}from"./index-BV7qwUw4.js";import{L as yl}from"./loader-circle-ETrjzfmn.js";import{P as bl,a as kl,b as wl,c as _l,d as vl}from"./PopoverPopup-NYiGE8A2.js";import{F as ot}from"./FadeIn-B6lrj4uo.js";import{C as un,u as jl}from"./use-pet-settings-CPZdlq_e.js";import{u as Nl}from"./use-native-settings-BniKwA_n.js";import{T as Sl}from"./Controls-MTUhGWy8.js";import{A as Dr}from"./arrow-up-right-DLvfE0Wu.js";import{u as Cl,b as Tl,P as Dl,a as Al}from"./CloudUsageExport-C_DqZKo1.js";import{L as ls}from"./LoginCard-DTTIm8vk.js";import{L as Ll,A as Ml}from"./agent-logos-2TVT3fIE.js";import{M as mn}from"./monitor-smartphone-D1kdzrdb.js";import{C as El}from"./check-C_cfrxiz.js";import"./terminal-D4VZbvhg.js";import"./use-limits-display-prefs-D3HOcRFv.js";import"./play-Cxp-ronD.js";import"./composite-INW-ELWX.js";import"./store-gHeBU8dQ.js";import"./chevron-down-Ck8ml43e.js";import"./SelectItemText-BpIsAg3b.js";import"./usePositioner-B3l2ulTw.js";import"./safePolygon-CVZ27a2_.js";import"./calendar-days-B0aDoKSG.js";import"./download-B7uokeIo.js";import"./arrow-left-DL0hAp_7.js";const hn={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"}]]};hn.node;const Il=Nr(hn);const xn={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"}]]};xn.node;const Rl=Nr(xn);const gn={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"]};gn.node;const Fl=Nr(gn);function $l(t,a,r={}){const s=t.get();let n=null,o=s,i;const u=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},m=()=>{const p=cs(t.get()),x=cs(o);if(p===x){d();return}const g=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new Qi({keyframes:[p,x],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:i})},h=()=>{m(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((p,x)=>{o=p,i=g=>x(tr(g,u)),Zi.postRender(h)},d),nn(a)){let p=r.skipInitialAnimation===!0;const x=a.on("change",f=>{p?(p=!1,t.jump(tr(f,u),!1)):t.set(tr(f,u))}),g=t.on("destroy",x);return()=>{x(),g()}}return d}function tr(t,a){return a?t+a:t}function cs(t){return typeof t=="number"?t:parseFloat(t)}function Pl(t,a={}){const{isStatic:r}=c.useContext(Xi),s=()=>nn(t)?t.get():t;if(r)return ln(s);const n=cn(s());return c.useInsertionEffect(()=>$l(n,t,a),[n,JSON.stringify(a)]),n}function Bl(t,a={}){return Pl(t,{type:"spring",...a})}function zl(){return e.jsxs(li,{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 Ol({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(zl,{}),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 Ul({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"},u=`${n} ${o[a]} ${i[r]} ${s}`.trim();return e.jsx("span",{className:u,children:t})}var Hl={};function Kl(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 Vl({mv:t,digit:a,height:r}){const s=ln(t,n=>{const o=(n%10+10)%10,i=(10+a-o)%10;let u=i*r;return i>5&&(u-=10*r),u});return e.jsx(pe.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Wl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function ql(t,a){const r=t/a;return Math.floor(Wl(r))}function Gl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((u,d)=>/\d/.test(u)&&(s===-1||d<s)).length,o=0,i=!1;return r.map(u=>{if(!/\d/.test(u))return u==="."&&(i=!0),u;if(!i){const d=10**Math.max(n-1,0);return n-=1,d}return o+=1,10**-o})}function Yl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=Kl(t,r),m=t!=="."&&t!==",",h=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...m?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...h?{width:d.width}:null},children:t})}const o=ql(a,t),i=cn(0),u=Bl(i,{stiffness:220,damping:26,mass:.8});return c.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},(d,m)=>e.jsx(Vl,{mv:u,digit:m,height:r},m))})}function Jl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:o=6,borderRadius:i=4,horizontalPadding:u=0,textColor:d="inherit",fontWeight:m="inherit",containerStyle:h,counterStyle:p,digitStyle:x,gradientHeight:g=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const w=String(a??t??""),S=c.useMemo(()=>Array.isArray(n)&&n.length?n:Gl(w),[n,w]),T=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Hl?.VITEST==="true",A=Xt()||T,L=Number.isFinite(Number(t))?Math.abs(Number(t)):0,P=r+s;return A?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:m,lineHeight:1,...h,...p},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...h},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:o,overflow:"hidden",borderRadius:i,paddingLeft:u,paddingRight:u,lineHeight:1,color:d,fontWeight:m,...p},children:S.map((N,v)=>e.jsx(Yl,{place:N,value:L,height:P,digitStyle:x,shouldReduceMotion:A},`${String(N)}-${v}`))}),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:j??{height:g,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function Zl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:o,timeZone:i,tzOffsetMinutes:u,now:d,accountView:m=!1,accountAccessToken:h=null,accountRevision:p=0,accountViewResolving:x=!1,deviceId:g=null}={}){const f=!!(m&&h),b=f?"cloud":"local",k=c.useMemo(()=>ci({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[j,w]=c.useState([]),[S,T]=c.useState(null),[A,L]=c.useState("edge"),[P,N]=c.useState(!1),[v,D]=c.useState(null),R=ht(),O=Zt(a),F=!r,E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=rt([t,k.from,k.to,s,n,b,a,h,p,x,g,i,u,r,R,F,O,E]),K=c.useMemo(()=>{if(!o)return null;const V=Sr({timeZone:i,offsetMinutes:u});return`tokentracker.heatmap.${o}.${b}.${s}.${n}.${V}.${g||"all"}`},[o,g,b,i,u,s,n]),G=c.useCallback(()=>{if(!K||typeof window>"u")return null;try{const V=window.localStorage.getItem(K);if(!V)return null;const ie=JSON.parse(V);return!ie||!ie.heatmap?null:ie}catch{return null}},[K]),_=c.useCallback(V=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(V))}catch{}},[K]),$=c.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=c.useRef(b);c.useEffect(()=>{H.current!==b&&(H.current=b,w([]),T(null),L("edge"),D(null),N(!0))},[b]);const ae=c.useCallback(async()=>{const V=B(),ie=await Ue(a),le=f?await Ue(h):null;if(!V()||!ie&&!R&&!E&&!f)return;if(f&&!le){D("Your session expired. Please sign in again to view account data."),N(!1);return}const Se=f?le:ie,ve=f?di:ui,Me=f?Zs:Qs;N(!0),D(null);try{try{const ee=await ve({baseUrl:t,accessToken:Se,weeks:s,to:k.to,weekStartsOn:n,device:g,timeZone:i,tzOffsetMinutes:u}),re=Array.isArray(ee?.weeks)?ee.weeks:[];if(!V())return;if(!re.length&&F){const W=G();if(W?.heatmap){if(!V())return;T(W.heatmap),w(W.daily||[]),L("cache");return}}if(!re.some(W=>(Array.isArray(W)?W:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&re.length){const W=[];for(const X of re)for(const ue of Array.isArray(X)?X:[])ue?.day&&W.push({day:ue.day,total_tokens:ue.total_tokens??ue.value??0,billable_total_tokens:ue.billable_total_tokens??ue.value??ue.total_tokens??0});const Y=Qr({dailyRows:W,weeks:s,to:ee?.to||k.to,weekStartsOn:n});if(!V())return;w(W),T({...Y,week_starts_on:n,active_days:W.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ya({dailyRows:W,to:ee?.to||k.to})}),L("client"),F?_({heatmap:{...Y,week_starts_on:n,active_days:W.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ya({dailyRows:W,to:ee?.to||k.to})},daily:W,fetchedAt:new Date().toISOString()}):$();return}if(!V())return;T(ee||null),w([]),L("edge"),ee&&F?_({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):F||$();return}catch(ee){const re=ee,be=re?.status??re?.statusCode;if(be===401||be===403)throw ee}if(!V())return;const Q=await Me({baseUrl:t,accessToken:Se,from:k.from,to:k.to,device:g,timeZone:i,tzOffsetMinutes:u}),U=Array.isArray(Q?.data)?Q.data:[];if(!V())return;w(U);const ne=Qr({dailyRows:U,weeks:s,to:k.to,weekStartsOn:n});if(!V())return;T({...ne,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ya({dailyRows:U,to:k.to})}),L("client"),F?_({heatmap:{...ne,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ya({dailyRows:U,to:k.to})},daily:U,fetchedAt:new Date().toISOString()}):$()}catch(Q){if(!V())return;if(F){const U=G();if(U?.heatmap){if(!V())return;T(U.heatmap),w(U.daily||[]),L("cache"),D(null)}else{const ne=Q;D(ne?.message||String(ne)),w([]),T(null),L("edge")}}else{const U=Q;D(U?.message||String(U)),w([]),T(null),L("edge")}}finally{V()&&N(!1)}},[a,t,R,r,F,k.from,k.to,G,O,i,u,n,s,$,_,E,f,h,p,g,B]);return c.useEffect(()=>{if(x){N(!0);return}if(!O&&!r&&!R&&!E&&!f){w([]),N(!1),D(null),T(null),L("edge");return}if(!F)$(),w([]),D(null),T(null),L("edge");else{const V=G();V?.heatmap&&(T(V.heatmap),w(V.daily||[]),L("cache"))}ae()},[a,R,G,ae,O,r,F,$,E,x]),{range:k,daily:j,heatmap:S,source:R?"mock":A==="client"?"edge":A,loading:P,error:v,refresh:ae}}const Ql="tokentracker.dashboard.leftCardOrder.v1",Xl="tokentracker.dashboard.rightCardOrder.v1";function ec(t,a){const r=ns(Ql,t),s=ns(Xl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),o=c.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:o}}const tc=10;function ac({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i}={}){const[u,d]=c.useState([]),[m,h]=c.useState(!1),[p,x]=c.useState(null),g=ht(),f=Zt(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=rt([t,a,r,s,n,o,i]),j=c.useCallback(async()=>{const w=k(),S=await Ue(a);if(w()){if(!S&&!g&&!b){d([]),x(null),h(!1);return}h(!0),x(null);try{const T=await mi({baseUrl:t,accessToken:S,limit:tc,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i});if(!w())return;d(Array.isArray(T?.entries)?T.entries:[])}catch(T){if(!w())return;const A=T?.message||String(T);x(A),d([])}finally{w()&&h(!1)}}},[a,t,r,g,n,o,s,i,b,k]);return c.useEffect(()=>{if(!f&&!g&&!b){d([]),x(null),h(!1);return}d([]),x(null),h(!0),j()},[g,j,f,b]),{entries:u,loading:m,error:p,refresh:j}}const ds="tokentracker.usage-cache-index",us=24;function ms({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:o=!0,includeSummary:i=!0,cacheKey:u,timeZone:d,tzOffsetMinutes:m,now:h,accountView:p=!1,accountAccessToken:x=null,accountRevision:g=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(p&&x),j=k?"cloud":"local",[w,S]=c.useState([]),[T,A]=c.useState(null),[L,P]=c.useState(null),[N,v]=c.useState("edge"),[D,R]=c.useState(null),[O,F]=c.useState(!1),[E,B]=c.useState(null),K=ht(),G=Zt(a),_=!r&&!K,$=b||"all",H=(()=>{if(!u)return null;const Q=rc(t)||"default",U=o?i?"daily-summary":"daily-only":"summary",ne=Sr({timeZone:d,offsetMinutes:m});return`tokentracker.usage.${u}.${j}.${Q}.${s}.${n}.${U}.${ne}.${$}`})(),ae=c.useRef(j);c.useEffect(()=>{ae.current!==j&&(ae.current=j,S([]),A(null),P(null),v("edge"),R(null),B(null),F(!0))},[j]);const me=c.useCallback(()=>{if(!H||typeof window>"u")return null;try{const Q=window.localStorage.getItem(H);if(!Q)return null;const U=JSON.parse(Q),ne=i?!!U?.summary:Array.isArray(U?.daily);return!U||!ne?null:(os(ds,H,us),U)}catch{return null}},[i,H]),V=c.useCallback(Q=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(Q)),os(ds,H,us)}catch{}},[H]),ie=c.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),Se=rt([t,s,n,o,i,j,a,x,g,b,d,m,r,K,_,f,G,le]),ve=c.useCallback(async()=>{const Q=Se(),U=await Ue(a),ne=k?await Ue(x):null;if(!Q()||!U&&!K&&!le&&!k)return;if(k&&!ne){B("Your session expired. Please sign in again to view account data."),F(!1);return}const ee=k?Zs:Qs,re=k?hi:xi,be=k?ne:U;F(!0),B(null);try{let W=null,Y=null;if(o)if(i){const[he,C]=await Promise.allSettled([ee({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m}),re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0})]);if(he.status==="rejected")throw he.reason;W=he.value,Y=C.status==="fulfilled"?C.value:null}else W=await ee({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m});else i&&(Y=await re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0}));let X=o&&Array.isArray(W?.data)?W.data:[];o&&(X=rr(X,s,n,{timeZone:d,offsetMinutes:m,now:h}));let ue=i&&(Y?.totals||W?.summary?.totals)||null,Pe=i&&(Y?.rolling||W?.summary?.rolling)||null;if(i&&o&&!ue&&!Y)try{const he=await re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0});ue=he?.totals||null,Pe=he?.rolling||Pe}catch{}const Ae=new Date().toISOString();if(!Q())return;S(X),A(ue),P(Pe),v("edge"),R(Ae),(ue||!i&&o)&&_?V({summary:ue,rolling:Pe,daily:X,from:s,to:n,includeDaily:o,includeSummary:i,fetchedAt:Ae}):_||ie()}catch(W){if(!Q())return;if(_){const Y=me();if(Y?.summary||!i&&Array.isArray(Y?.daily)){A(Y.summary),P(Y.rolling||null);const X=Array.isArray(Y.daily)?Y.daily:[],ue=o?rr(X,Y.from||s,Y.to||n,{timeZone:d,offsetMinutes:m,now:h}):X;S(ue),v("cache"),R(Y.fetchedAt||null),B(null)}else{const X=W;B(X?.message||String(X)),S([]),A(null),P(null),v("edge"),R(null)}}else{const Y=W;B(Y?.message||String(Y)),S([]),A(null),P(null),v("edge"),R(null)}}finally{Q()&&F(!1)}},[a,t,s,o,i,K,r,_,h,me,G,d,n,m,ie,V,le,k,x,g,b,Se]);return c.useEffect(()=>{if(f){F(!0);return}const Q=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!G&&!r&&!K&&!Q&&!k){S([]),A(null),P(null),B(null),F(!1),v("edge"),R(null);return}if(!_)ie(),S([]),A(null),P(null),B(null),v("edge"),R(null);else{const U=me();if(U?.summary||!i&&Array.isArray(U?.daily)){A(U.summary),P(U.rolling||null);const ne=Array.isArray(U.daily)?U.daily:[],ee=o?rr(ne,U.from||s,U.to||n,{timeZone:d,offsetMinutes:m,now:h}):ne;S(ee),v("cache"),R(U.fetchedAt||null),B(null)}else S([]),A(null),P(null),v("edge"),R(null),B(null)}F(!0),ve()},[a,K,me,ve,G,r,_,ie,le,f,i]),c.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const Q=15e3;let U=Date.now();const ne=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-U<Q||(U=ee,ve())};return window.addEventListener("focus",ne),document.addEventListener("visibilitychange",ne),()=>{window.removeEventListener("focus",ne),document.removeEventListener("visibilitychange",ne)}},[ve]),{daily:w,summary:T,rolling:L,source:K?"mock":N,fetchedAt:D,loading:O,error:E,refresh:ve}}function rc(t){try{return new URL(t).host}catch{return null}}function ar(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 sc(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function rr(t,a,r,{timeZone:s,offsetMinutes:n,now:o}={}){const i=ar(a),u=ar(r);if(!i||!u||u<i)return Array.isArray(t)?t:[];const d=o instanceof Date&&Number.isFinite(o.getTime())?o:new Date,m=Cr({timeZone:s,offsetMinutes:n,date:d}),h=ar(m),p=h?h.getTime():d.getTime(),x=new Map;for(const f of t||[])f?.day&&x.set(f.day,f);const g=[];for(let f=i;f<=u;f=sc(f,1)){const b=Gt(f),k=x.get(b),j=f.getTime()>p;if(k){g.push({...k,missing:!1,future:j});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:!j,future:j})}return g}function nc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:o,timeZone:i,tzOffsetMinutes:u,accountView:d=!1,accountAccessToken:m=null,accountRevision:h=0,accountViewResolving:p=!1,deviceId:x=null}={}){const g=!!(d&&m),f=g?"cloud":"local",[b,k]=c.useState(null),[j,w]=c.useState("edge"),[S,T]=c.useState(!1),[A,L]=c.useState(null),P=ht(),N=Zt(a),v=!r,D=c.useMemo(()=>{if(!o)return null;const $=oc(t)||"default",H=Sr({timeZone:i,offsetMinutes:u});return`tokentracker.modelBreakdown.${o}.${f}.${$}.${s}.${n}.${H}.${x||"all"}`},[t,o,x,s,f,i,n,u]),R=c.useCallback(()=>{if(!D||typeof window>"u")return null;try{const $=window.localStorage.getItem(D);if(!$)return null;const H=JSON.parse($);return!H||!H.breakdown?null:H}catch{return null}},[D]),O=c.useCallback($=>{if(!(!D||typeof window>"u"))try{window.localStorage.setItem(D,JSON.stringify($))}catch{}},[D]),F=c.useCallback(()=>{if(!(!D||typeof window>"u"))try{window.localStorage.removeItem(D)}catch{}},[D]),E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=rt([t,s,n,f,a,m,h,x,i,u,r,P,v,p,N,E]),K=c.useRef(f);c.useEffect(()=>{K.current!==f&&(K.current=f,k(null),w("edge"),L(null),T(!0))},[f]);const G=c.useCallback(async()=>{const $=B(),H=await Ue(a),ae=g?await Ue(m):null;if(!$()||!H&&!P&&!E&&!g)return;if(g&&!ae){L("Your session expired. Please sign in again to view account data."),T(!1);return}const me=g?ae:H,V=g?gi:pi;T(!0),L(null);try{const ie=await V({baseUrl:t,accessToken:me,from:s,to:n,device:x,timeZone:i,tzOffsetMinutes:u});if(!$())return;k(ie||null),w("edge"),ie&&v?O({breakdown:ie,fetchedAt:new Date().toISOString()}):v||F()}catch(ie){if(!$())return;if(v){const le=R();if(le?.breakdown)k(le.breakdown),w("cache"),L(null);else{k(null),w("edge");const Se=ie;L(Se?.message||String(Se))}}else{k(null),w("edge");const le=ie;L(le?.message||String(le))}}finally{$()&&T(!1)}},[a,t,s,P,r,v,R,i,n,N,u,F,O,E,g,m,h,x,B]);return c.useEffect(()=>{if(p){T(!0);return}if(!N&&!r&&!P&&!E&&!g){k(null),w("edge"),L(null),T(!1);return}if(!v)F(),k(null),w("edge"),L(null);else{const $=R();$?.breakdown?(k($.breakdown),w("cache"),L(null)):(k(null),w("edge"),L(null))}T(!0),G()},[a,P,R,G,N,r,v,F,E,p]),{breakdown:b,source:P?"mock":j,loading:S,error:A,refresh:G}}function oc(t){try{return new URL(t).host}catch{return null}}const pn=new Set(["day","hour","month"]);function ic(t){return pn.has(t)}function hs(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 lc(t,a){const r=hs(t),s=hs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=te(t),o=te(a);return n==null&&o==null?0:n==null?1:o==null?-1:n===o?0:n<o?-1:1}function cc(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 dc(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 uc(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 mc(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]),u=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(u)||!Number.isFinite(d)||n<1||n>12||o<1||o>31||i<0||i>23||u<0||u>59||d<0||d>59)return null;const m=new Date(Date.UTC(s,n-1,o,i,u,d));return Number.isFinite(m.getTime())?m.getTime():null}function hc(t,a,r){const s=r==="hour"?mc:r==="month"?uc:dc,n=s(t),o=s(a);return n!=null&&o!=null?n===o?0:n<o?-1:1:cc(t,a)}function fn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],o=pn.has(a)?(u,d)=>hc(u,d,a):lc,i=u=>a==="total_tokens"&&u?.billable_total_tokens!=null?u.billable_total_tokens:u?.[a];return n.map((u,d)=>({row:u,index:d})).sort((u,d)=>{const m=i(u.row),h=i(d.row),p=m==null,x=h==null;if(p&&x)return u.index-d.index;if(p)return 1;if(x)return-1;const g=o(m,h);return g!==0?g*s:u.index-d.index}).map(u=>u.row)}function xc(){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 xs(t){const a=ic(t)?t:"day";return xc().map((r,s)=>s===0?{...r,key:a}:r)}function gs(t,{key:a,dir:r}){return fn(t,{key:a,dir:r})}const Ca=12,gc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function pc(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 fc(t){return gc.some(a=>pc(t?.[a]))}function yc(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=fn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&fc(n));return s===-1?a:r.slice(s)}function bc(t,a,r=Ca){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Ca,i=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(i,i+n)}function kc({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 ka=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function wc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ka.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ka.active:s<=60*6e4?ka.warm:ka.idle}const _c=3e4;function vc({refresh:t,intervalMs:a=_c,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let o=!1,i=null,u=Date.now(),d=0;const m=()=>{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},h=r.setInterval(()=>{const g=Date.now();g<d||(d=g+wc({visible:s.visibilityState==="visible",lastInteractionAt:u,now:g}),m())},a),p=()=>{s.visibilityState==="visible"&&(u=Date.now(),d=0,m())},x=()=>{u=Date.now()};return r.addEventListener("focus",p),r.addEventListener("pointerdown",x),r.addEventListener("keydown",x),s.addEventListener("visibilitychange",p),{run:m,stop(){o=!0,r.clearInterval(h),r.removeEventListener("focus",p),r.removeEventListener("pointerdown",x),r.removeEventListener("keydown",x),s.removeEventListener("visibilitychange",p)}}}function jc(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 Nc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=jc(s)||new Date,o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Gt(o),to:Gt(n)}}function Sc(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 Ar(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Cc(t){const a=Ar(t?.model_id);return a||null}function yn(t,a){return t?.model?String(t.model):a}function bn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",o=Ar(n);if(!o||o.includes("/"))continue;const i=Math.max(0,te(s?.weight)??0);(!a.has(o)||i>=(r.get(o)||0))&&(a.set(o,n),r.set(o,i))}return a}function kn(t,a){const r=Ar(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 Ct(t,a=0){const r=te(t?.billable_total_tokens),s=te(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Tc={deepseek:"dsh"};function Dc(t){const a=typeof t=="string"?t:"";return Tc[a]||a}const Ac=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"],wn=["input","output","cached","cacheCreate","reasoning"];function Lc(t){let a=0;for(const r of wn)a+=Math.max(0,Number(t?.[r])||0);return a}function Mc(t){return Lc(t?.tokens)>0}function ps(t,a){for(const r of Ac)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 fs(){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,total_cost_usd:"0"}}function Ec(t){const a=new Map;for(const r of t||[]){const s=Dc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:fs(),models:new Map},a.set(s,n)),ps(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 u=n.models.get(i);u||(u={...o,model:o?.model||i,model_id:i,totals:fs()},n.models.set(i,u)),ps(u.totals,o?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function Ic(t,{copyFn:a}={}){const r=typeof a=="function"?a:i=>i,n=Ec(Array.isArray(t?.sources)?t.sources:[]).map(i=>{const u=Ct(i?.totals),d=te(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(u)?u:0,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,te(i?.totals?.input_tokens)??0),cacheRead:Math.max(0,te(i?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,te(i?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!n.length)return[];const o=n.reduce((i,u)=>i+u.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((i,u)=>u.totalTokens-i.totalTokens).map(i=>{const u=i.source?String(i.source).toUpperCase():r("shared.placeholder.short"),d=o>0?i.totalTokens/o*100:0,m=Number.isFinite(d)?d.toFixed(2):"0.00",h=i.models.map(f=>{const b=Ct(f?.totals);if(!Number.isFinite(b)||b<=0)return null;const k=i.totalTokens>0?Math.round(b/i.totalTokens*1e3)/10:0,j=yn(f,r("shared.placeholder.short")),w=Cc(f),S=te(f?.totals?.total_cost_usd),T=S??(i.totalCost>0&&i.totalTokens>0?b/i.totalTokens*i.totalCost:null),A=f?.totals||{};return{id:w,name:j,share:k,usage:b,cost:T,tokens:{input:Math.max(0,te(A?.input_tokens)??0),output:Math.max(0,te(A?.output_tokens)??0),cached:Math.max(0,te(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,te(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,te(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:u,totalPercent:String(m),totalPercentValue:d,usd:i.totalCost,usage:i.totalTokens,cacheHitRate:g,cacheReusedTokens:i.cacheRead,cacheInputTokens:p,models:h}})}function Rc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const i of a){const u=Array.isArray(i?.models)?i.models:[];for(const d of u){const m=te(d?.usage);if(m==null||m<=0)continue;const h=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;h&&s.push({model:d,name:h,usage:m})}}const n=bn(s.map(i=>({name:i.name,weight:i.usage})));for(const{model:i,name:u,usage:d}of s){const m=kn(u,n);if(!m)continue;const{key:h}=m,p=r.get(h)||{id:h,name:m.name,usage:0,cost:0,hasCost:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0}};p.usage+=d;const x=i?.tokens||{};for(const f of wn)p.tokens[f]+=Math.max(0,Number(x[f])||0);const g=te(i?.cost);g!=null&&(p.cost+=g,p.hasCost=!0),n.has(h)?p.name=n.get(h):d>=p.nameWeight&&(p.name=u,p.nameWeight=d),r.set(h,p)}const o=Array.from(r.values()).reduce((i,u)=>i+u.usage,0);return Array.from(r.values()).map(i=>({id:i.id,name:i.name,usage:i.usage,cost:i.hasCost?i.cost:null,tokens:{...i.tokens},share:o>0?Math.round(i.usage/o*1e3)/10:0})).sort((i,u)=>u.usage!==i.usage?u.usage-i.usage:String(i.name).localeCompare(String(u.name)))}function Fc(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,u=new Map,d=[];let m=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const j=Ct(k?.totals);if(!Number.isFinite(j)||j<=0)continue;m+=j;const w=yn(k,s("shared.placeholder.short"));d.push({name:w,tokens:j})}}const h=bn(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=kn(f,h);if(!k)continue;const{key:j}=k;o.set(j,(o.get(j)||0)+b),h.has(j)?i.set(j,h.get(j)):b>=(u.get(j)||0)&&(u.set(j,b),i.set(j,f))}if(!o.size)return[];const p=Array.from(o.values()).reduce((f,b)=>f+b,0),x=m>0?m:p,g=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(o.entries()).map(([f,b])=>{const k=x>0?(b/x*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 $c(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 ys(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Yt(a);return(a===Xs?t:t*r)<.01?`<${s}0.01`:Qt(t,{decimals:2,currency:a,rate:r})}function bs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:$e(a,{decimals:1})}const Pc=jt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:o}=Aa(),i=c.useMemo(()=>(Array.isArray(s)?s:[]).map(m=>{const h=te(m?.usd)??0,p=te(m?.usage)??0,x=Array.isArray(m?.models)?m.models:[];return{label:m?.label?String(m.label):"",usdValue:h,costLabel:ys(h,n,o),tokensLabel:bs(p),models:x.map(g=>{const f=te(g?.usage)??0,b=te(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:bs(f),costLabel:ys(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(m=>m.usdValue>0||m.models.length>0).sort((m,h)=>h.usdValue-m.usdValue),[s,n,o]),u=i.some(m=>m.models.some(h=>h.costSource!=="provider_reported"&&h.pricing?.status==="unpriced")),d=c.useMemo(()=>{const m=i.reduce((h,p)=>h+p.usdValue,0);return u&&m===0?l("dashboard.cost_breakdown.unpriced_label"):`${u?"≥":""}${$c(m,n,o)}`},[i,n,o,u]);return e.jsx(cl,{open:a,onOpenChange:m=>{m||r?.()},children:e.jsxs(dl,{children:[e.jsx(ul,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(ml,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(hl,{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(xl,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(gl,{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(Tr,{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:u?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:d}),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((m,h)=>{const p=`fleet-${h}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":p,className:h>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:m.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:m.costLabel||"—"})]}),m.models.map((x,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:x.name,children:x.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:x.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):x.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),x.pricing?.status==="unpriced"&&x.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,x.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,x.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:$e(Number(x.tokens.input)||0),output:$e(Number(x.tokens.output)||0),read:$e(Number(x.tokens.cached)||0),write:$e(Number(x.tokens.cacheCreate)||0)})}):null,x.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:x.pricing.input,output:x.pricing.output,read:x.pricing.cache_read,write:x.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:x.costLabel||(x.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):x.pricing?.status==="free"?Qt(0,{currency:n,rate:o}):l("dashboard.cost_breakdown.rate_unknown"))})]},x.id||`${x.name}-${g}`))]},`${m.label}-${h}`)})]})]})})]})})]})})});function Bc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[o,i]=c.useState(null),[u,d]=c.useState(!1),[m,h]=c.useState(null),p=ht(),x=rt([t,a,r,s,n,p]);return c.useEffect(()=>{const g=x();if(!t){i(null),h(null),d(!1);return}d(!0),i(null),h(null),fi({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{g()&&i(f||null)}).catch(f=>{g()&&(h(f?.message||String(f)),i(null))}).finally(()=>{g()&&d(!1)})},[t,a,r,s,n,p,x]),{data:o,loading:u,error:m}}function _n(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 vn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function jn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function Nn(t,a){return a&&jn(vn(t))==="github"?a:""}function Sn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=c.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 ks="#10b981",sr=[{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"}],nr=60;function zc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(x=>[x.day,x]));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 u=t[t.length-1].day;i<u&&(i=u);const d=new Date(`${o}T00:00:00Z`),m=new Date(`${i}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(m.getTime()))return t;const h=Math.round((m.getTime()-d.getTime())/864e5)+1;h>nr&&d.setUTCDate(d.getUTCDate()+(h-nr));const p=[];for(;d.getTime()<=m.getTime()&&p.length<nr;){const x=d.toISOString().slice(0,10);p.push(n.get(x)||{day:x,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return p}function or(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 Oc({host:t}){if(!t)return null;let a;const r=jn(t);return r==="github"||r==="gitlab"?a=e.jsx(Tt,{provider:r,size:12,className:"fill-current"}):a=e.jsx(Il,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function ir({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 Uc({entry:t,query:a={},onClose:r}){const[s,n]=jt.useState(!1),o=typeof t?.project_key=="string"?t.project_key:"",{owner:i,repo:u}=_n(o),d=typeof t?.project_ref=="string"?t.project_ref:"",m=vn(d),{data:h,loading:p,error:x}=Bc({projectKey:o,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:g,formatTokensTooltip:f}=De(),b=jt.useCallback(()=>n(!0),[]),k=E=>{E.target===E.currentTarget&&s&&r()};jt.useEffect(()=>{const E=B=>{B.key==="Escape"&&b()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[b]);const j=h?.totals||null,w=te(j?.billable_total_tokens)??0,S=Number(h?.days_active||0),T=te(j?.input_tokens)??0,A=te(j?.cached_input_tokens)??0,L=T+A>0?A/(T+A):null,P=te(h?.range_total_tokens)??0,N=te(j?.total_tokens)??0,v=P>0?N/P:null,D=jt.useMemo(()=>zc(h?.daily,h?.from,h?.to,Cr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[h,a.timeZone,a.tzOffsetMinutes]),R=sr.reduce((E,B)=>E+(te(j?.[B.key])??0),0),O=Array.isArray(h?.sources)?h.sources:[],F=!p&&!x&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:E=>{E.target===E.currentTarget&&b()},className:St("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:St("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(Tr,{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:ks}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:ks}})]}),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(Sn,{githubOwner:Nn(d,i),letter:(u?.[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:u||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(Oc,{host:m}),m&&h?.from&&h?.to?e.jsx("span",{children:"·"}):null,h?.from&&h?.to?e.jsxs("span",{className:"tabular-nums",children:[h.from," – ",h.to]}):null]})]}),F?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:v==null?"—":or(v)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:L==null?"—":or(L)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_conversations"),value:Sa(j.conversation_count)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_active_days"),value:Sa(S)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_avg_day"),value:S>0?g(Math.round(w/S)):"—"})]}):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&&x&&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&&!x&&!F&&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")}),F&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[D.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(sn,{embedded:!0,rows:D,from:D[0]?.day,to:D[D.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),R>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:sr.map(E=>{const B=te(j[E.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/R*100}%`,backgroundColor:E.color,minWidth:"2px"}},E.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:sr.map(E=>{const B=te(j[E.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:E.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(E.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(B),children:g(B)})]},E.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(E=>{const B=Number(E.total_tokens||0),K=N>0?B/N:0,G=K*100,_=Number(E.conversation_count||0),$=qi(E.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Tt,{provider:E.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:Nt(E.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(E.days_active||0)}),_>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:_})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(B),children:g(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:or(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(G,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:$}})})]},E.source)})})]})]})]})]})})}function Hc(t){return e.jsx(yi,{mode:qt.COMPACT,children:e.jsx(Uc,{...t})})}const Kc=5;function Vc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:o}){const i=typeof t?.project_key=="string"?t.project_key:"",u=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:m}=_n(i),h=Nn(u,d),p=te(t?.billable_total_tokens??t?.total_tokens)??0,x=a>0?Math.min(100,Math.max(2,p/a*100)):0,g=Array.isArray(t?.sources)?t.sources:[],f=g.slice(0,Kc),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(Sn,{githubOwner:h,letter:(m?.[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:[d?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[d,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:m||i||"—"})]}),f.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[f.map(k=>e.jsx(Tt,{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:`${x}%`,minWidth:p>0?"3px":0}})})]})]})}function Wc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:o,dailyEmptyPrefix:i,installSyncCmd:u,dailyEmptySuffix:d,detailsColumns:m,ariaSortFor:h,toggleSort:p,sortIconFor:x,pagedDetails:g,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:w="day",detailsDateKey:S,renderDetailDate:T,renderDailyBreakdownDate:A,renderDetailCell:L,DETAILS_PAGED_PERIODS:P,period:N,detailsPageCount:v,detailsPage:D,setDetailsPage:R}){const[O,F]=c.useState("daily"),[E,B]=c.useState(null),{formatTokens:K,formatTokensTooltip:G}=De();return e.jsxs(Le,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="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":O==="daily",type:"button",onClick:()=>F("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="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":O==="projects",type:"button",onClick:()=>F("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="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")})]}),O==="projects"&&e.jsx(on,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:_=>r?.(Number(_)),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"})]}),O==="projects"&&(()=>{const _=t.slice(0,a);if(_.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 $=_.reduce((H,ae)=>{const me=te(ae?.billable_total_tokens??ae?.total_tokens)??0;return me>H?me:H},0);return e.jsx("div",{className:"space-y-1",children:_.map((H,ae)=>e.jsx(Vc,{entry:H,maxTokens:$,copy:n,formatTokens:K,formatTokensTooltip:G,onSelect:B},H?.project_key||H?.project_ref||`entry-${ae}`))})})(),E&&e.jsx(Hc,{entry:E,query:s,onClose:()=>B(null)}),O==="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:u}),d]}):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(_=>e.jsx("th",{"aria-sort":k?.(_.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>p(_.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:_.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(_.key)||""})]})})},_.key))})}),e.jsx("tbody",{children:f.map(_=>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 ${_.missing?"text-oai-gray-400 dark:text-oai-gray-400":_.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:A?A(_):T(_)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:L(_,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"conversation_count")})]},String(_?.[w]||_?.day||_?.hour||_?.month||"")))})]})}),O!=="daily"&&P.has(N)&&v>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>R(_=>Math.max(0,_-1)),disabled:D===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:[D+1," / ",v]}),e.jsx("button",{type:"button",onClick:()=>R(_=>Math.min(v-1,_+1)),disabled:D+1>=v,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 Na(t){return typeof t!="string"?"":t.trim()}function ws(t){const a=Na(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function qc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Na(r.tool),n=Na(r.planType)||Na(r.plan_type);if(!s||!n)continue;const o=ws(s)||s,i=ws(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:o,plan:i})}return Array.from(a.values())}function Gc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:o=[],className:i=""}){const{formatTokensTooltip:u}=De(),d=l("shared.placeholder.short"),m=l("shared.unit.percent"),h=t??l("identity_card.rank_placeholder"),p=Number.isFinite(Number(a))?Number(a):0,x=p?l("identity_card.streak_value",{days:p}):l("identity_card.rank_placeholder"),g=qc(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 d;const S=$e(w,f);return S==="-"?d:S},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=o.slice(0,3);return e.jsxs(Le,{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:u(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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:u(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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:u(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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})]})]}),j.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:j.map((w,S)=>{const T=w?.name?String(w.name):d,A=w?.percent?String(w.percent):"",L=S===j.length-1,P=S+1;return e.jsxs("div",{className:`flex items-center py-2 ${L?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:P}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:T,children:T}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[A,m]})]},w.id||T)})}),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,S)=>e.jsxs(Ul,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${S}`))}),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:h})]}),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:x})]})]})]})}let wa=null;function Yc(){if(wa===null)try{wa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{wa=!1}return wa}function Jc(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,u=t-.1055613458*n-.0638541728*o,d=t-.0894841775*n-1.291485548*o,m=i*i*i,h=u*u*u,p=d*d*d;return[4.0767416621*m-3.3077115913*h+.2309699292*p,-1.2684380046*m+2.6097574011*h-.3413193965*p,-.0041960863*m-.7034186147*h+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 Cn(t,a,r,s){if(Yc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,o,i]=Jc(t,a,r);return s==null?`rgb(${n} ${o} ${i})`:`rgb(${n} ${o} ${i} / ${s})`}function At(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Cn(Number(a[1]),Number(a[2]),Number(a[3])):t}const _s={claude:35,codex:250,grok:200},vs={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 Zc(t,a){const r=_s[a]??_s.claude,s=vs[t]||vs.system_prompt;return Cn(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"]}],Xc=[["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"]],ed={duration:.18,ease:[.4,0,.2,1]},td={height:0,opacity:0},ad={height:"auto",opacity:1},rd={height:0,opacity:0};function sd(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function nd(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 Tn(t,a=null){const r=t.reduce((i,u)=>i+Number(u.totals.total_tokens||0),0),s=sd(a),n=s||r,o=s&&r>0?s/r:1;return t.map(i=>{const u=o===1?i.totals:nd(i.totals,o);return{...i,totals:u,percent:n>0?Number((u.total_tokens/n*100).toFixed(2)):0}}).sort((i,u)=>u.totals.total_tokens-i.totals.total_tokens)}function od(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 u=r.get(i);if(!u)continue;const d=u.totals||{};o.input_tokens+=d.input_tokens||0,o.cached_input_tokens+=d.cached_input_tokens||0,o.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,o.output_tokens+=d.output_tokens||0,o.reasoning_output_tokens+=d.reasoning_output_tokens||0,o.total_tokens+=d.total_tokens||0}return{key:n.key,totals:o}});return Tn(s,a)}function id(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((m,h)=>h?.name==="Text Response"?m:m+Number(h?.totals?.total_tokens||0),0),o=Number(r.total_tokens||0),i=Math.min(Math.max(0,n),Math.max(0,o-s)),d=[{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 Tn(d,a)}const js="MCP: ";function ld(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(js)?(a.push({...n,name:o.slice(js.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 Ns(t){return l(`dashboard.context_breakdown.category.${t}`)}function cd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function dd(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),u=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:cd(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(u||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function ud(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),u=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:o,cached_input_tokens:i,cache_creation_input_tokens:u,total_tokens:Number(r.total_tokens||n+o)},tools:dd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function md(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 hd(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 xd(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 gd(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 Ss(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 pd(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 Cs(t){return t==="exec_command"||t==="Bash"}function Dn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function fd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function yd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const bd=10;function Qe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:o=!1,open:i=!1,onToggle:u,tokens:d,percent:m=null,children:h,share:p=null,fillColor:x=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:bd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:g,children:r}),s,o&&e.jsx(pe.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(ki,{size:11})})]}),k=x&&p!=null&&p>0,j=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, ${x.replace(/\)\s*$/," / 0.10)")} 0%, ${x.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[o?e.jsx("button",{type:"button",onClick:u,"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:d||""}),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:m||""})]}),o&&h?e.jsx(Dt,{initial:!1,children:i&&e.jsx(pe.div,{initial:td,animate:ad,exit:rd,transition:ed,style:{overflow:"hidden"},children:h},"content")}):null]})}function Ts({execDetails:t,source:a="claude"}){const{formatTokens:r}=De(),[s,n]=c.useState("by_type"),o=gd(pd(t,s)),i=a==="codex"||a==="grok",u=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:Xc.map(([d,m])=>e.jsx("button",{type:"button",onClick:()=>n(d),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===d?"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(m)},d))}),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 ${u} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),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((d,m)=>e.jsxs(pe.div,{role:"row",className:`grid ${u} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:m*.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:d.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:$e(d.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:$e(d.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:Ss(d.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:Ss(d.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(d.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:$e(d.output_lines||0)})]},d.name))]})})]})}function Kt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=De(),[o,i]=c.useState({}),[u,d]=c.useState(!1),m=ud(t?.categories||[]);function h(p){i(x=>({...x,[p]:!x[p]}))}return m.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(Dn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:m.map(p=>{const x=p.toolCount>0,g=p.name==="Execution"&&a,f=g&&p.tools.some(k=>Cs(k.name)),b=!!o[p.name];return e.jsxs(Qe,{level:1,label:p.name,labelTone:"strong",hasChevron:x||g&&!f,open:b||g&&!f&&u,onToggle:()=>{x?h(p.name):g&&!f&&d(k=>!k)},tokens:n(p.totals.total_tokens||0),percent:null,children:[x&&e.jsx("ul",{className:"space-y-0.5",children:p.tools.map(k=>{const j=g&&Cs(k.name);return e.jsx(Qe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:u,onToggle:()=>d(w=>!w),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(Ts,{execDetails:a,source:r})},k.name)})}),g&&!f&&e.jsx(Ts,{execDetails:a,source:r})]},p.name)})})}function kd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:o}=De(),[i,u]=c.useState(null),[d,m]=c.useState(!1),[h,p]=c.useState(null),[x,g]=c.useState({}),f=c.useRef({});function b(_){g($=>({...$,[_]:!$[_]}))}if(c.useEffect(()=>{let _=!1;const $=`${t||""}|${a||""}|${r||"claude"}`,H=f.current[$];return u(H||null),m(!0),n?.(!0),p(null),bi({from:t,to:a,source:r,timeZone:tn(),tzOffsetMinutes:en()}).then(ae=>{_||(f.current[$]=ae,u(ae))}).catch(ae=>{_||p(ae?.message||String(ae))}).finally(()=>{_||(m(!1),n?.(!1))}),()=>{_=!0}},[t,a,r]),d&&!i)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(_=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${_*80}ms`}},_))}),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(h)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(fd(r))});if(!i||i.scope!=="supported"||!i.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(Dn(r))});const k=r==="claude"?od(i.categories||[],s):id(i,s),j=i.tool_calls_breakdown||null,w=i.skills_breakdown||null,S=i.message_breakdown||null,T=i.configured_resources||null,A=i.exec_command_breakdown||null,L=hd(w?.skills||[]),P=md(S?.categories||[]),N=r==="codex"&&(i?.breakdown_status==="queue_fallback"||i?.fallback==="queue_totals"),v=r==="claude"?j?.tool_calls||null:j||null,{mcpSet:D,residualSet:R,mcpTotalTokens:O}=ld(v),F=r==="claude"&&j?.subagents||null,E=F?.categories?.length>0||(T?.custom_agents_count||0)>0,B=r==="claude"?(R?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,K=r==="claude"?(F?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,G=[...k].sort((_,$)=>($.totals?.total_tokens||0)-(_.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:k.filter(_=>_.percent>0).filter(_=>!(r==="claude"&&(_.key==="tool_calls"||_.key==="custom_agents"))).map(_=>`${Ns(_.key)} ${_.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[G.map(_=>{const $=_.key==="system_prompt",H=_.key==="messages",ae=_.key==="tool_calls",me=_.key==="custom_agents";if(_.key,r==="claude"&&(ae||me))return null;const V=H&&P.length>0||ae&&(R?.categories?.length>0||N)||me&&E&&F,ie=!!x[_.key],le=Zc(_.key,r),Se=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:le},"aria-hidden":"true"}),ve=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(dn,{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,Me=_.percent>0?`${_.percent.toFixed(_.percent<.1&&_.percent>0?2:1)}%`:"0.0%";return e.jsxs(Qe,{level:0,colorSquare:Se,label:Ns(_.key),labelSuffix:ve,tokens:o(_.totals?.total_tokens||0),percent:Me,hasChevron:V,open:ie,onToggle:()=>b(_.key),share:_.percent,fillColor:le,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:P.map(Q=>e.jsx(Qe,{level:1,label:xd(Q),tokens:o(Q.totals.total_tokens||0),percent:null},Q.key||Q.name))}),ae&&R&&e.jsx(Kt,{toolSet:R,execDetails:A,source:r,codexQueueFallback:N}),ae&&N&&!R&&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")}),me&&F&&e.jsx(Kt,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})]},_.key)}),r==="claude"&&R?.categories?.length>0&&e.jsx(Qe,{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:o(B),percent:null,hasChevron:!0,open:!!x.tool_calls_aux,onToggle:()=>b("tool_calls_aux"),children:e.jsx(Kt,{toolSet:R,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&F?.categories?.length>0&&e.jsx(Qe,{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:o(K),percent:null,hasChevron:!0,open:!!x.custom_agents_aux,onToggle:()=>b("custom_agents_aux"),children:e.jsx(Kt,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})}),D?.categories?.length>0&&e.jsx(Qe,{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:o(O),percent:null,hasChevron:!0,open:!!x.mcp_servers,onToggle:()=>b("mcp_servers"),children:e.jsx(Kt,{toolSet:D,execDetails:null,source:r,codexQueueFallback:!1})}),L.length>0&&e.jsx(Qe,{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:o(L.reduce((_,$)=>_+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!x.skills,onToggle:()=>b("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:L.slice(0,12).map(_=>e.jsx(Qe,{level:1,label:_.name,tokens:o(_.total_tokens),percent:null},_.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(yd(r))}),N?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,T?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[$e(T.skills_count||0)," skills ·"," ",$e(T.mcp_servers_count||0)," MCP servers ·"," ",$e(T.custom_agents_count||0)," agents ·"," ",$e(T.memory_files_count||0)," memory files"]}):null]})}function An({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 it="__all__",wd=`${100 .toFixed(2)}%`;function Jt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function br(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Yt(a);return(a===Xs?s:s*r)<.01?`<${n}0.01`:Qt(s,{decimals:2,currency:a,rate:r})}function _d(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Ds(a)}:{key:a.key,label:a.label||Ds(a.key)}):[]}function vd(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 jd={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 lr(t,a){const r=t?.toUpperCase?.()||"";return jd[r]||`hsl(${150+a*40}, 60%, 45%)`}function Nd(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 Sd(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 Cd(t){return!!t?.models?.length}function Ln(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function cr(t){const a=Ln(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const Td={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Ds(t){const a=Td[t];return a?l(a):String(t).toUpperCase()}function Dd({loading:t,onClick:a}){const r=Xt();return e.jsx(_i,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(pe.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(vi,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function Ad(){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 Ld(){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 Md({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:o,summaryLabel:i,summaryCostValue:u,onCostInfo:d,fleetData:m=[],onRefresh:h,loading:p,announceLoading:x=!1,summaryLoading:g=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:w,onCustomRangeApply:S,customRangeOpen:T,onCustomRangeOpenChange:A,onOpenShare:L,from:P,to:N,deviceOptions:v=[],selectedDevice:D="",onDeviceChange:R}){const O=_d(a),F=fl(ji()),E=vd(String(s??"")),B=t==="week"&&typeof P=="string"&&typeof N=="string"&&P.slice(0,7)!==N.slice(0,7),K=P&&N?`${ba(P,F)} — ${ba(N,F)}`:null,G=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[_,$]=c.useState(G);c.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const C=window.matchMedia("(max-width: 639px)"),J=z=>$(z.matches);return C.addEventListener("change",J),()=>C.removeEventListener("change",J)},[]);const H=E!=null&&!_,ae=c.useRef(null);c.useEffect(()=>{const C=ae.current?.querySelector('[aria-selected="true"]');C&&typeof C.scrollIntoView=="function"&&C.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[me,V]=c.useState(null),{resolvedTheme:ie}=wi(),{currency:le,rate:Se}=Aa(),{formatTokens:ve}=De(),Me=ie==="dark",Q=Me?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Me?"rgba(10,10,10,0)":"rgba(255,255,255,0)",ne=g&&!b,ee=f&&!m.some(Cd);c.useEffect(()=>{V(null)},[t,P,N,D]);const re=C=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(C.key))return;const J=Array.from(C.currentTarget.querySelectorAll('[role="tab"]')).filter(xe=>!xe.disabled),z=J.indexOf(C.target.closest('[role="tab"]'));if(z===-1||J.length===0)return;C.preventDefault();let se=z;C.key==="Home"?se=0:C.key==="End"?se=J.length-1:C.key==="ArrowRight"?se=(z+1)%J.length:se=(z-1+J.length)%J.length,J[se].focus(),J[se].click()},be=H?e.jsx(Jl,{value:E,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Me?0:8,gradientFrom:Q,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,W=m.filter(C=>C.models?.length>0),Y=W.some(C=>String(C?.source||C?.label||"").trim().toLowerCase()==="devin"),X=W.some(C=>String(C?.source||C?.label||"").trim().toLowerCase()==="trae"),ue=c.useMemo(()=>Rc(m),[m]),Pe=ue.reduce((C,J)=>C+(Number(J.usage)||0),0),Ae=W.reduce((C,J)=>C+(Number(J.usd)||0),0),he=me==null?null:me===it||W.some(function(J){return J.label===me})?me:null;return e.jsx(Le,{className:k,children:e.jsxs("div",{"aria-busy":p||ne||ee,children:[x?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:ae,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:re,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(C=>{const J=t===C.key,z=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${J?"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(C.key==="custom"){const se=J&&j&&w?`${ba(j,F)} — ${ba(w,F)}`:C.label;return e.jsxs(bl,{open:T,onOpenChange:xe=>{xe?r?.("custom"):A?.(xe)},children:[e.jsx(kl,{render:e.jsx("button",{role:"tab","aria-selected":J,tabIndex:J?0:-1,type:"button",className:z}),children:se}),e.jsx(wl,{children:e.jsx(_l,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(vl,{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(pl,{from:j,to:w,onApply:S,onCancel:()=>A?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":J,tabIndex:J?0:-1,type:"button",className:z,onClick:()=>r?.(C.key),children:C.label},C.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[v.length>1?e.jsx(on,{value:D,onValueChange:R,options:v,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,L?e.jsxs("button",{type:"button",onClick:L,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Fl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,h&&e.jsx(Dd,{loading:p,onClick:h})]})]}),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:ne?"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:be}):e.jsx("span",{title:n||void 0,children:be})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${ne?"":"hidden"}`,children:e.jsx(Ad,{})})]}),u&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:d?e.jsxs("button",{type:"button",onClick:d,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[u,e.jsx(dn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:u})}),X&&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")]}),K?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:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(Ld,{})}),W.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:W.map(C=>l("usage.overview.distribution_item",{label:Nt(C.label),percent:cr(C)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:W.map((C,J)=>{const z=lr(C.label,J),se=Nt(C.label),xe=cr(C);return e.jsx(pe.div,{initial:{width:0},animate:{width:`${Ln(C)}%`},transition:{duration:.5,delay:.45+J*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:z},title:`${se}: ${xe}%`},C.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":he===it,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:Jt(ve,Pe)||String(0),cost:br(Ae,le,Se)||`${Yt(le)}0`,count:ue.length}),onClick:()=>V(he===it?null:it),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${he===it?"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(An,{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:wd}),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:ue.length})})]}),W.map((C,J)=>{const z=lr(C.label,J),se=he===C.label,xe=Nt(C.label),ke=cr(C);return e.jsxs("button",{"aria-expanded":se,"aria-controls":`provider-details-${C.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:xe,percent:ke,tokens:Jt(ve,C.usage)||String(0),cost:br(C.usd,le,Se)||`${Yt(le)}0`,action:l(se?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>V(se?null:C.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${se?"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(Tt,{provider:C.label,size:15,color:z,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:xe,children:xe})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[ke,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:C.models.length})})]},C.label)})]}),he===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Y&&e.jsx(En,{}),e.jsx(Fd,{models:ue})]}),he!=null&&he!==it&&e.jsx("div",{id:`provider-details-${he}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:he}),className:"mt-2",children:W.filter(C=>C.label===he).map(C=>{const J=lr(C.label,0),z=Nd(C),se=[...C.models].sort((ke,st)=>(st.share||0)-(ke.share||0)),xe=z?Sd(z):Nt(C.label);return e.jsx($d,{provider:C,color:J,providerHeading:xe,contextSource:z,from:P,to:N,sortedModels:se},C.label)})})]})]})})}const Ed=[{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"}],Id="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(7rem,max-content)]";function Rd({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=De();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:Ed.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 As({model:t,tokensLabel:a,costLabel:r,expandable:s,isExpanded:n}){const{formatTokensTooltip:o}=De();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 text-right whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",s&&e.jsx("span",{className:"ml-1 align-middle text-[11px] font-normal text-oai-gray-400 dark:text-oai-gray-500",children:l(n?"usage.overview.collapse":"usage.overview.expand")})]})]})}function Mn({models:t,color:a}){const{currency:r,rate:s}=Aa(),{formatTokens:n}=De(),[o,i]=c.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(u=>{const d=Jt(n,u.usage),m=br(u.cost,r,s),h=Math.max(0,Math.min(100,Number(u.share)||0)),p=u.id||u.name,x=Mc(u),g=x&&o===p,f=Id,b={model:u,tokensLabel:d,costLabel:m,expandable:x,isExpanded:g};return e.jsxs("div",{"data-model-rank-row":!0,children:[x?e.jsx("button",{type:"button",onClick:()=>i(g?null:p),"aria-expanded":g,className:`${f} w-full cursor-pointer text-left`,children:e.jsx(As,{...b})}):e.jsx("div",{className:f,children:e.jsx(As,{...b})}),g&&e.jsx(Rd,{tokens:u.tokens}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":h,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${h}%`,backgroundColor:a,opacity:.45}})})]},p)})})}function Fd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(An,{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(Mn,{models:t,color:"var(--oai-blue)"})]})}function En(){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 $d({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:o,sortedModels:i}){const{formatTokens:u}=De(),[d,m]=c.useState(!1),h=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",p=String(t?.source||t?.label||"").trim().toLowerCase()==="devin";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Tt,{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&&d&&e.jsx(yl,{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(u,t.cacheReusedTokens)||String(0),input:Jt(u,t.cacheInputTokens)||String(0)})]}),h&&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")]}),p&&e.jsx(En,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(kd,{from:n,to:o,source:s,referenceTotalTokens:t.usage,onLoadingChange:m})}):null,e.jsx(Mn,{models:i,color:a})]})}function Pd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:o,transform:i,transition:u,isDragging:d}=el({id:t}),m=c.useRef(null),h=c.useRef(null);c.useLayoutEffect(()=>{if(!r)return;const x=m.current?m.current.childNodes.length===0:!0;h.current!==x&&(h.current=x,r(t,x))});const p={transform:tl.Transform.toString(i)||void 0,transition:u,zIndex:d?20:void 0};return e.jsxs("div",{ref:o,style:p,className:St("group/sortable relative has-[[data-sortable-body]:empty]:hidden",d&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:St("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",d&&"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:m,"data-sortable-body":!0,className:St("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)]",d&&"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 Bd({todayTokens:t=0,isSyncing:a=!1,hasError:r=!1,isDisconnected:s=!1}={}){return c.useMemo(()=>r?"error":s?"disconnected":a?"working-typing":t===0?"sleeping":t<5e4?"idle-living":t<2e5?"idle-look":t<5e5?"working-ultrathink":t<2e6?"working-typing":"working-ultrathink",[t,a,r,s])}const Ls="macAppBannerDismissed",zd="leaderboardBannerDismissed",Od="https://github.com/xiufengsun/TokenTracker/releases/latest",Ms="tokentracker_native_app",Vt=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Ms,"1"),!0):localStorage.getItem(Ms)==="1"}catch{return!1}})();function Ud({todayTokens:t=0,isSyncing:a=!1,enterDelay:r=0}){const{openLoginModal:s}=Ni(),{signedIn:n}=an(),o=Bd({todayTokens:t,isSyncing:a}),i=Vt?zd:Ls,[u,d]=c.useState(()=>{try{return localStorage.getItem(i)==="1"?!0:!Vt&&new URLSearchParams(window.location.search).get("from")==="menubar"?(localStorage.setItem(Ls,"1"),!0):!1}catch{return!1}}),m=c.useCallback(()=>{d(!0);try{localStorage.setItem(i,"1")}catch{}},[i]);if(u||!Vt&&Da())return null;let h,p,x,g,f,b;Vt&&n?(h="View the Leaderboard",p="Compare your usage globally",x="Leaderboard",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M2 8.5V10h8V8.5M6 1.5v6m0 0L3.5 5M6 7.5l2.5-2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(180 6 6)"})}),f=()=>{window.location.pathname="/leaderboard"}):Vt?(h="Join the Leaderboard",p="Log in to compare your usage with others",x="Log In",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6.5 1.5h3a1 1 0 011 1v7a1 1 0 01-1 1h-3M5 8.5L7.5 6 5 3.5M7.5 6H1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),f=s):(h="Try the Menu Bar App",p="Always-on stats with Clawd companion",x="Download",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6 2v6m0 0L3.5 5.5M6 8l2.5-2.5M2 10h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),b=Od);const k=b?pe.a:pe.button,j=b?{href:b,target:"_blank",rel:"noopener noreferrer"}:{onClick:f};return e.jsx(pe.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:r,ease:[.16,1,.3,1]},className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(un,{state:o,size:56})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-900 dark:text-oai-white",children:h}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-0.5",children:p})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(k,{...j,whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[x,g]}),e.jsx("button",{onClick:m,className:"p-1 text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-300 transition-colors","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})})]})]})})}const Es="widgetOnboardingDismissed",Is="tokentracker_native_app",Hd=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Is,"1"),!0):localStorage.getItem(Is)==="1"}catch{return!1}})();function Kd({enterDelay:t=0}){const[a,r]=c.useState(()=>{try{return localStorage.getItem(Es)==="1"}catch{return!1}}),s=c.useCallback(()=>{r(!0);try{localStorage.setItem(Es,"1")}catch{}},[]);return!Hd||rn()?null:e.jsx(Dt,{initial:!1,children:!a&&e.jsxs(pe.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-8,transition:{duration:.2,ease:[.4,0,.2,1]}},transition:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:s,"aria-label":l("dashboard.widgets.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"rounded-lg overflow-hidden ring-1 ring-black/5 dark:ring-white/10 shadow-sm",children:e.jsx("img",{src:"/widgets-overview.png",alt:l("dashboard.widgets.title"),width:734,height:552,className:"w-full h-auto block",loading:"lazy",decoding:"async"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.widgets.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.widgets.hint")})]})]},"widget-onboarding-card")})}const Lr="islandOnboardingDismissed";function Vd(){try{return localStorage.getItem(Lr)==="1"}catch{return!1}}function Rs(){try{localStorage.setItem(Lr,"1")}catch{}}function Wd(){try{localStorage.removeItem(Lr)}catch{}}function In({className:t}){return e.jsxs("svg",{viewBox:"0 6 15 9",fill:"currentColor","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"2",y:"6",width:"11",height:"7"}),e.jsx("rect",{x:"0",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"13",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"3",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"5",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"9",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"11",y:"13",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"4",y:"8",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"10",y:"8",width:"1",height:"2"})]})}function qd({reduceMotion:t}){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-950 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 -top-12 h-36 w-56 rounded-full bg-indigo-600/25 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-2 h-32 w-48 rounded-full bg-sky-500/15 blur-3xl"}),e.jsx("div",{className:"absolute bottom-[-3rem] left-1/3 h-32 w-64 rounded-full bg-fuchsia-500/10 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[16px] items-center justify-between bg-black/45 px-2.5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-white/60"}),e.jsx("span",{className:"h-[3px] w-5 rounded-full bg-white/30"}),e.jsx("span",{className:"h-[3px] w-3.5 rounded-full bg-white/20"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-3 rounded-full bg-white/20"}),e.jsx("span",{className:"h-[3px] w-4 rounded-full bg-white/35"})]})]}),e.jsxs(pe.div,{className:"absolute left-1/2 top-0 flex h-[22px] -translate-x-1/2 items-center rounded-b-[10px] bg-black pl-2 pr-2.5 shadow-lg shadow-black/60 ring-1 ring-white/[0.06]",animate:t?void 0:{opacity:[1,.94,1]},transition:t?void 0:{duration:3.2,repeat:1/0,ease:"easeInOut"},children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(In,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),"8.2M"]}),e.jsx("span",{className:"mx-2 h-2.5 w-7 rounded-[2px] bg-black"}),e.jsx("span",{className:"text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:"$12.40"})]})]})}function Gd({enterDelay:t=0}){const{available:a,settings:r,setSetting:s}=Nl(),[n,o]=c.useState(Vd),[i,u]=c.useState(!1),d=Xt(),m=c.useCallback(()=>{o(!0),Rs()},[]),h=c.useCallback(()=>{if(!a){try{window.location.href="tokentracker://open"}catch{}return}s("dynamicIslandEnabled",!0),i&&s("hideMenuBarIcon",!0),Rs(),o(!0),Si({title:l("dashboard.island.enabled_toast"),data:{onUndo:()=>{s("hideMenuBarIcon",!1),s("dynamicIslandEnabled",!1),Wd(),o(!1)}}})},[a,i,s]),p=a&&!!r?.dynamicIslandSupported&&!r?.dynamicIslandEnabled,x=!a&&!rn()&&!Da(),g=!n&&(p||x);return e.jsx(Dt,{initial:!1,children:g&&e.jsxs(pe.div,{initial:d?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:d?{opacity:0}:{opacity:0,y:-8},transition:d?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:m,"aria-label":l("dashboard.island.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx(qd,{reduceMotion:d}),e.jsx("div",{className:"mt-4 flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.island.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] 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 scale-90 origin-left",children:l("qpd.card.badge")})]}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.island.hint")})]})}),a?e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg bg-oai-gray-50 px-3 py-2.5 dark:bg-oai-gray-800/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-medium text-oai-gray-800 dark:text-oai-gray-200",children:l("settings.labs.island_hide_menubar.label")}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("settings.labs.island_hide_menubar.hint")})]}),e.jsx(Sl,{checked:i,onChange:()=>u(f=>!f),ariaLabel:l("settings.labs.island_hide_menubar.aria")})]}):null,e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(pe.button,{type:"button",onClick:h,whileHover:d?void 0:{scale:1.03},whileTap:d?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:a?l("dashboard.island.enable"):l("local_only.open_app")}),e.jsxs("a",{href:"/settings?section=labs",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.island.settings_link"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"island-onboarding-card")})}const Rn="linuxTopBarCardDismissed",Yd="https://github.com/xiufengsun/TokenTracker/tree/main/TokenTrackerLinux/gnome-extension/tokentracker@tokentracker.cc#readme";function Jd(){try{return localStorage.getItem(Rn)==="1"}catch{return!1}}function Zd(){try{localStorage.setItem(Rn,"1")}catch{}}function Qd(){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-800 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 top-4 h-36 w-56 rounded-full bg-orange-500/20 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-8 h-32 w-48 rounded-full bg-purple-600/25 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[22px] items-center gap-2 bg-black px-2.5",children:[e.jsx("div",{className:"flex min-w-0 flex-1 basis-0 items-center",children:e.jsx("span",{className:"h-[7px] w-7 rounded-full bg-white/70"})}),e.jsx("span",{className:"h-[3px] w-10 shrink rounded-full bg-white/60"}),e.jsxs("div",{className:"flex flex-1 basis-0 items-center justify-end gap-2",children:[e.jsxs("span",{className:"flex shrink-0 items-center gap-1 whitespace-nowrap rounded-full bg-white/15 px-1.5 py-0.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(In,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),l("dashboard.linux_topbar.preview_readout")]}),e.jsx("span",{className:"h-[5px] w-[5px] rounded-full bg-white/50"}),e.jsx("span",{className:"h-[5px] w-[5px] rounded-full bg-white/50"}),e.jsx("span",{className:"h-[5px] w-2.5 rounded-sm bg-white/50"})]})]}),e.jsxs("div",{className:"absolute right-10 top-[26px] w-28 rounded-md bg-oai-gray-900/95 p-1.5 ring-1 ring-white/10",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"h-5 flex-1 rounded bg-white/10"}),e.jsx("span",{className:"h-5 flex-1 rounded bg-white/10"})]}),e.jsx("span",{className:"mt-1.5 block h-[3px] w-3/4 rounded-full bg-white/30"}),e.jsx("span",{className:"mt-1 block h-[3px] w-1/2 rounded-full bg-white/20"}),e.jsx("span",{className:"mt-1 block h-[3px] w-2/3 rounded-full bg-white/20"})]})]})}function Xd({enterDelay:t=0}){const[a,r]=c.useState(Jd),s=Xt(),n=c.useCallback(()=>{r(!0),Zd()},[]),o=Da()&&Ci()&&!a;return e.jsx(Dt,{initial:!1,children:o&&e.jsxs(pe.div,{initial:s?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:s?{opacity:0}:{opacity:0,y:-8},transition:s?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:n,"aria-label":l("dashboard.linux_topbar.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsxs("div",{className:"min-w-0 pr-6",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.linux_topbar.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.linux_topbar.hint")})]}),e.jsx("div",{className:"mt-3",children:e.jsx(Qd,{})}),e.jsx("div",{className:"mt-3 flex items-center gap-3",children:e.jsxs(pe.a,{href:Yd,target:"_blank",rel:"noopener noreferrer",whileHover:s?void 0:{scale:1.03},whileTap:s?void 0:{scale:.97},className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[l("dashboard.linux_topbar.setup"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})})]},"linux-topbar-card")})}const Fn="linuxPetCardDismissed";function eu(){try{return localStorage.getItem(Fn)==="1"}catch{return!1}}function tu(){try{localStorage.setItem(Fn,"1")}catch{}}function au({enterDelay:t=0}){const{available:a,loaded:r,settings:s,setSetting:n}=jl(),[o,i]=c.useState(eu),u=Xt(),d=c.useCallback(()=>{i(!0),tu()},[]),m=c.useCallback(()=>{n("visible",!0)},[n]),h=Da()&&a&&r&&!s.visible&&!o;return e.jsx(Dt,{initial:!1,children:h&&e.jsxs(pe.div,{initial:u?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:u?{opacity:0}:{opacity:0,y:-8},transition:u?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:d,"aria-label":l("dashboard.linux_pet.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsxs("div",{className:"flex items-center gap-3 pr-6",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(un,{state:"happy",size:56})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.linux_pet.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.linux_pet.hint")})]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(pe.button,{type:"button",onClick:m,whileHover:u?void 0:{scale:1.03},whileTap:u?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:l("dashboard.linux_pet.show")}),e.jsxs("a",{href:"/pet-settings",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.linux_pet.settings_link"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"linux-pet-card")})}function ru({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[o,i]=c.useState(null),[u,d]=c.useState(!1),[m,h]=c.useState(null),p=rt([t,a,r,s,n]),x=c.useCallback(async()=>{if(!t)return;const g=p();d(!0),h(null);try{const f=await Ue(s);if(!g())return;const b=await Ti({from:a,to:r,device:n,accessToken:f});if(!g())return;i(b||null)}catch(f){if(!g())return;h(f?.message||String(f)),i(null)}finally{g()&&d(!1)}},[t,a,r,s,n,p]);return c.useEffect(()=>{if(!t){i(null),h(null),d(!1);return}i(null),h(null),d(!0),x()},[t,x]),{data:o,loading:u,error:m,refresh:x}}function $n(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Pn(t){return t==null?"—":`${Math.round(t*100)}%`}function su(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 nu({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:$n(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:Pn(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:su(t.cost_usd,t.accepted)})]})}function ou({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=De(),{enabled:o}=Cl(),{data:i,loading:u}=ru({enabled:o,from:t,to:a,deviceId:r});if(!o)return null;const d=(i&&i.available&&Array.isArray(i.by_model)?i.by_model:[]).filter(x=>x.outcomes>0&&x.key!=="unknown");if(!d.length)return null;const m=d.slice(0,6),h=i.totals||{},p=`${l("qpd.card.subtitle")}${u?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(Le,{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:m.map(x=>e.jsx(nu,{row:x},x.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:h.accepted??0,outcomes:h.outcomes??0,cost:$n(h.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(h.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(h.effective_tokens),rate:Pn(h.acceptance_rate)})})]}),h.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 iu=new Set(["unknown","synthetic","openai"]);function dr(t){return t==null?"—":`${Math.round(t*100)}%`}function lu(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function cu(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!iu.has(r)&&Number(t?.edit_turns||0)>0}function Fs(){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 du({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=c.useState({requestKey:null,loading:!0,sessions:null,context:null}),o=s.requestKey===r?s:{loading:!0,sessions:null,context:null},i=c.useId(),{enabled:u}=Tl(),d=rt([u,t,a]),{formatTokens:m}=De(),h=S=>m(S,{mode:qt.COMPACT});c.useEffect(()=>{const S=d();if(!u){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Di({from:t,to:a}),Ai()]).then(([T,A])=>{S()&&n({requestKey:r,loading:!1,sessions:T,context:A})}).catch(()=>{S()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[u,t,a,r,d]);const p=c.useMemo(()=>(o.sessions?.by_model||[]).filter(cu).slice(0,5),[o.sessions]),x=c.useMemo(()=>(o.sessions?.subagents||[]).slice(0,3),[o.sessions]);if(!u||!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,j=g.sessions??o.sessions?.session_count??0,w=g.edit_turns??0;return o.loading&&!o.sessions&&!o.context?e.jsxs(Le,{children:[e.jsx(Fs,{}),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(Le,{children:[e.jsx(Fs,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(ur,{label:l("sessions.card.edit_sessions"),value:dr(f),detail:l("sessions.card.edit_session_value",{edits:Ze(k),sessions:Ze(j)})}),e.jsx(ur,{label:l("sessions.card.first_pass"),value:dr(b),detail:l("sessions.card.edit_session_value",{edits:Ze(g.first_pass_sessions??g.one_shot_sessions??0),sessions:Ze(k)})}),e.jsx(ur,{label:l("sessions.card.cost_edit"),value:lu(g.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(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:Ze(j),edits:Ze(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("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:p.map(S=>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:S.model,children:S.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Ze(S.edit_sessions??S.productive_sessions??0),sessions:Ze(S.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:dr(S.first_pass_rate??S.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:h(S.tokens_per_edit)})]},S.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:h(o.context.estimated_fixed_tokens)})]}):null,!!x.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")}),x.map(S=>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:S.name,calls:Math.round(S.calls)})},S.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function ur({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 ce({className:t}){return e.jsx("div",{className:St("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function uu(){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(ce,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function mu(){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(Le,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(ce,{className:"h-4 w-32"}),e.jsx(ce,{className:"h-6 w-24"})]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{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(ce,{className:"h-3 w-20"}),e.jsx(ce,{className:"h-3 w-12"})]},a))]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(uu,{})]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-28"}),e.jsx(ce,{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(Le,{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(ce,{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(ce,{className:"h-8 w-20 rounded-md"}),e.jsx(ce,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(ce,{className:"h-3 w-28"}),e.jsx(ce,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(ce,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ce,{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(ce,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(ce,{className:"h-3 w-12"})]}),e.jsx(ce,{className:"h-5 w-10"}),e.jsx(ce,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(Le,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(ce,{className:"h-7 w-16 rounded"}),e.jsx(ce,{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(ce,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(ce,{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(ce,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(ce,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const hu=Ml.slice(0,10),$s=.06,xu=.11,gu=.05,pu=new Set(["macAppBanner","widgetOnboarding","linuxTopBarCard"]);function Ps({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(Ll,{logos:hu,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(pe.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 fu(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:o,identityDisplayName:i,identityStartDate:u,activeDays:d,identitySubscriptions:m,identityScrambleDurationMs:h,projectUsageEntries:p,projectUsageLimit:x,setProjectUsageLimit:g,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:j,isLocalMode:w,shouldShowInstall:S,installPrompt:T,handleCopyInstall:A,installCopied:L,installInitCmdDisplay:P,trendRowsForDisplay:N,trendFromForDisplay:v,trendToForDisplay:D,trendZoomConfig:R,usageFrom:O,usageTo:F,period:E,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:G,setSelectedPeriod:_,customFrom:$,customTo:H,onCustomRangeApply:ae,customRangeOpen:me,onCustomRangeOpenChange:V,summaryLabel:ie,summaryValue:le,summaryFullValue:Se,hasSummary:ve,summaryLoading:Me,providersLoading:Q,onToggleSummaryFormat:U,summaryTotalTokensRaw:ne,summaryCostValue:ee,summaryConversationsValue:re,rollingUsage:be,costInfoEnabled:W,openCostModal:Y,costModalOpen:X,closeCostModal:ue,allowBreakdownToggle:Pe,refreshAll:Ae,usageLoadingState:he,announceUsageLoading:C,initialDashboardLoading:J,fleetData:z,hasDetailsActual:se,dailyEmptyPrefix:xe,installSyncCmd:ke,dailyEmptySuffix:st,detailsColumns:fe,ariaSortFor:ye,toggleSort:Be,sortIconFor:ze,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:La,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Ma,detailsDateKey:Ea,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:ea,DETAILS_PAGED_PERIODS:we,detailsPageCount:_e,detailsPage:je,setDetailsPage:pt,deviceOptions:Mt,selectedDevice:ta,onDeviceChange:aa,deviceUsageBlock:Et,leftCardOrder:Ia,onLeftReorder:We,rightCardOrder:ra,onRightReorder:nt}=t,It=null,Ra=null,[sa,na]=c.useState(()=>new Set),Rt=c.useCallback((de,oe)=>{pu.has(de)&&na(Ce=>{if(Ce.has(de)===oe)return Ce;const et=new Set(Ce);return oe?et.add(de):et.delete(de),et})},[]),Fa={macAppBanner:w,statsPanel:!0,islandOnboarding:w,linuxPetCard:w,widgetOnboarding:w,linuxTopBarCard:w,installCopy:S,activityHeatmap:!!K,deviceUsage:!!Et,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},Ft=(Ia||[]).filter(de=>Fa[de]&&!sa.has(de)),$t={usageOverview:!0,dataDetails:!s},$a=(ra||[]).filter(de=>$t[de]&&!sa.has(de));function Ye(de,oe){switch(de){case"macAppBanner":return e.jsx(Ud,{todayTokens:ne,isSyncing:he,enterDelay:oe});case"statsPanel":return e.jsx(ot,{delay:oe,children:e.jsx(Gc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:E,startDate:u??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:m,periodConversations:re,rolling:be,topModels:b})});case"islandOnboarding":return e.jsx(Gd,{enterDelay:oe});case"linuxPetCard":return e.jsx(au,{enterDelay:oe});case"widgetOnboarding":return e.jsx(Kd,{enterDelay:oe});case"linuxTopBarCard":return e.jsx(Xd,{enterDelay:oe});case"installCopy":return e.jsx(ot,{delay:oe,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:T}),e.jsxs(pe.button,{onClick:A,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:P}),e.jsx(pe.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:L?"Copied ✓":"Copy"},L?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:oe,children:K});case"deviceUsage":return e.jsx(ot,{delay:oe,children:Et});case"trendMonitor":return e.jsx(ot,{delay:oe,children:e.jsx(sn,{rows:N,from:v,to:D,period:E,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:R})});case"qualityPerDollar":return e.jsx(ou,{from:O,to:F,deviceId:ta});case"sessionInsights":return e.jsx(du,{from:O,to:F});default:return null}}function oa(de,oe){switch(de){case"usageOverview":return e.jsx(ot,{delay:oe,children:e.jsx(Md,{period:E,periods:G,onPeriodChange:_,summaryLabel:ie,summaryValue:le,summaryFullValue:Se,hasSummary:ve,summaryLoading:Me,providersLoading:Q,onToggleSummaryFormat:ve?U:null,summaryCostValue:ee,onCostInfo:W?Y:null,fleetData:z,onRefresh:s?null:Ae,loading:he,announceLoading:C,onOpenShare:s?null:r,customFrom:$,customTo:H,onCustomRangeApply:ae,customRangeOpen:me,onCustomRangeOpenChange:V,from:O,to:F,deviceOptions:Mt,selectedDevice:ta,onDeviceChange:aa})});case"dataDetails":return e.jsx(ot,{delay:oe,children:e.jsx(Wc,{projectEntries:p,projectLimit:x,onProjectLimitChange:g,projectDetailQuery:f,copy:a,hasDetailsActual:se,dailyEmptyPrefix:xe,installSyncCmd:ke,dailyEmptySuffix:st,detailsColumns:fe,ariaSortFor:ye,toggleSort:Be,sortIconFor:ze,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:La,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Ma,detailsDateKey:Ea,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:ea,DETAILS_PAGED_PERIODS:we,period:E,detailsPageCount:_e,detailsPage:je,setDetailsPage:pt})});default:return null}}const qe=al(is(ll,{activationConstraint:{distance:6}}),is(il,{coordinateGetter:ol})),ge=c.useCallback(de=>{const{active:oe,over:Ce}=de;!Ce||oe.id===Ce.id||We?.(String(oe.id),String(Ce.id))},[We]),Pa=c.useCallback(de=>{const{active:oe,over:Ce}=de;!Ce||oe.id===Ce.id||nt?.(String(oe.id),String(Ce.id))},[nt]);function Pt(de,oe,Ce,et){return s?e.jsx(e.Fragment,{children:de.map((Te,ft)=>e.jsx(jt.Fragment,{children:oe(Te,Ce+$s*ft)},Te))}):e.jsx(rl,{sensors:qe,onDragEnd:et,children:e.jsx(sl,{items:de,strategy:nl,children:de.map((Te,ft)=>e.jsx(Pd,{id:Te,onEmptyChange:Rt,children:oe(Te,Ce+$s*ft)},Te))})})}const ia=Pt(Ft,Ye,xu,ge),Ba=Pt($a,oa,gu,Pa);return e.jsxs(e.Fragment,{children:[e.jsxs(Ol,{bare:!s,hideHeader:s,header:It,footer:s?null:Ra,className:s?"screenshot-mode":"",children:[o&&e.jsx(Ps,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(ls,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Ps,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(ls,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!o&&!n&&J&&e.jsx(mu,{}),!o&&!n&&!J&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:ia}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ba})]})})]}),e.jsx(Pc,{isOpen:X,onClose:ue,fleetData:z})]})}function yu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:o=null,accountRevision:i=0}={}){const u=!!(n&&o),[d,m]=c.useState([]),[h,p]=c.useState([]),[x,g]=c.useState(!1),[f,b]=c.useState(null),k=rt([u,t,a,r,s,o,i]),j=c.useCallback(async()=>{const w=k();if(!u){m([]),p([]),g(!1),b(null);return}g(!0),b(null);try{const S=await Ue(o);if(!w())return;const T=await Li({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:S});if(!w())return;m(Array.isArray(T?.devices)?T.devices:[]),p(Array.isArray(T?.account_sources)?T.account_sources:[])}catch(S){if(!w())return;b(S?.message||String(S)),m([]),p([])}finally{w()&&g(!1)}},[u,o,t,a,r,s,i,k]);return c.useEffect(()=>{m([]),p([]),b(null),u&&g(!0),j()},[u,j]),{devices:d,accountSources:h,loading:x,error:f,refresh:j}}const bu=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Bs(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 kr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(bu);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Bs(t.platform)} · ${s}`:Bs(t.platform)}const zs=" · ",Os="%";function Us({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Rl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Xr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Xr,{className:a,"aria-hidden":!0}):e.jsx(mn,{className:a,"aria-hidden":!0})}function Hs(t,a){return a===t?.id||t?.isCurrent===!0}function ku({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:o}){const{formatTokens:i,formatTokensTooltip:u}=De(),[d,m]=c.useState(""),[h,p]=c.useState(""),[x,g]=c.useState(!1),[f,b]=c.useState(""),k=typeof o=="function",j=typeof n=="function",w=!!s,S=t.reduce((v,D)=>v+(Number(D.total_tokens)||0),0)+a.reduce((v,D)=>v+(Number(D.total_tokens)||0),0),T=c.useMemo(()=>t.filter(v=>(Number(v.total_tokens)||0)>0).sort((v,D)=>(Number(D.total_tokens)||0)-(Number(v.total_tokens)||0)),[t]);function A(v){b(""),m(v.id);const D=typeof v.device_name=="string"?v.device_name:"";p(kr(v)===D?D:"")}function L(){m(""),p(""),b("")}async function P(v){const D=h.trim();if(!(!D||x)){g(!0),b("");try{await o(v.id,D),m(""),p("")}catch{b(v.id)}finally{g(!1)}}}const N=a.filter(v=>(Number(v.total_tokens)||0)>0);return T.length===0&&N.length===0?e.jsxs(Le,{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(mn,{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(Le,{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")}),j&&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:[T.map(v=>{const D=Number(v.total_tokens)||0,R=S>0?(D/S*100).toFixed(1):"0.0",O=s===v.id,F=kr(v)||l("dashboard.device_card.unnamed"),E=d===v.id,B=O?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=w&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[E?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(Us,{platform:v.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:h,disabled:x,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:G=>p(G.target.value),onKeyDown:G=>{G.key==="Enter"?P(v):G.key==="Escape"&&L()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:x||!h.trim(),onClick:()=>P(v),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(El,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:x,onClick:L,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Tr,{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 ${B}`,style:{width:`${R}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${F}${Hs(v,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":v.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 ${K} ${O?"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(Us,{platform:v.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:F,children:F}),Hs(v,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")})]}),e.jsxs("span",{title:u(D),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(D),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[zs,R,Os]})]})]}),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 ${B}`,style:{width:`${R}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>A(v),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(Dl,{className:"h-3 w-3"})})]}),f===v.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},v.id)}),N.map(v=>{const D=Number(v.total_tokens)||0,R=S>0?(D/S*100).toFixed(1):"0.0",O=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,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(Tt,{provider:v.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:Nt(v.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:u(D),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(D),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[zs,R,Os]})]})]}),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:`${R}%`}})})]},`account-${v.source}`)})]})]})}function Bn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function zn(){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||!ut.has(r))return;const s=ut.get(r);ut.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||!mt.has(r))return;const s=mt.get(r);mt.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function wu(t){if(!Bn()||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"};zn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{mt.has(r)&&(mt.delete(r),s({ok:!1,error:"timeout"}))},8e3);mt.set(r,o=>{window.clearTimeout(n),s(o)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(o){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:o?.message||String(o)})}})}async function Ks(t,a){if(!Bn()||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"};zn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const o=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,i=>{window.clearTimeout(o),n(i)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(i){ut.delete(s),window.clearTimeout(o),n({ok:!1,error:i?.message||String(i)})}})}const On=1200,Un=1630,Hn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},_u="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 mr=!1;function vu(){if(typeof document>"u"||mr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){mr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=_u,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),mr=!0}async function ju(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function Nu(t,a={}){if(typeof window>"u"||!t)return null;vu(),await ju(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Mi(async()=>{const{toBlob:d,toPng:m}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:m}},[]),n=a.pixelRatio??2,o=t.offsetWidth||On,i=t.offsetHeight||Un,u={pixelRatio:n,cacheBust:!0,width:o,height:i,style:{width:`${o}px`,height:`${i}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,u);if(d)return d}catch{}try{const d=await s(t,u);return d?await(await fetch(d)).blob():null}catch{return null}}async function hr(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 Vs(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 wr(t){const a=te(t);return Number.isFinite(a)?a:0}function Su(t){return t?wr(t.billable_total_tokens??t.total_tokens):0}function Cu(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(u=>{const d=!!u?.future,m=Number.isFinite(u?.level)?Math.max(0,Math.min(4,Math.round(u.level))):0;u?.day&&!d&&(r+=1,m>0&&(s+=1));const h=u?.billable_total_tokens??u?.total_tokens??u?.value??0,p=Number.isFinite(h)?Math.max(0,h):0;return{day:typeof u?.day=="string"?u.day:"",level:m,value:p,future:d}})),totalDays:r,activeDays:s}}function Tu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:o,rank:i,period:u,periodFrom:d,periodTo:m,heatmap:h,capturedAt:p,currency:x,exchangeRate:g}=t,f=Su(n),b=wr(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:wr(w?.tokens),percent:typeof w?.percent=="string"&&w.percent?w.percent:"0.0"})):[],j=Cu(h);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:u,periodFrom:d,periodTo:m,topModels:k,rank:typeof i=="number"&&Number.isFinite(i)&&i>0?Math.floor(i):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:p||new Date().toISOString(),currency:typeof x=="string"&&x.length>0?x.toUpperCase():"USD",exchangeRate:Number.isFinite(g)&&g>0?g:1}}const Du=["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 Au(t){const a=Du[t];return a?l(a):"—"}function Kn(t,a){return l("share.date.month_year",{month:Au(t),year:a})}function Lu(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:Kn(n,r)}function Mu(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 Kn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function _r(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Vn(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 Eu(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 Iu(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 Ru(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 Fu({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"],u=o||i[0],d=t.length,m=(d-1)*s,h=Math.max(4,(r-m)/d),p=7*h+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((x,g)=>(Array.isArray(x)?x:[]).map((b,k)=>{if(k>=7)return null;const j=Ru(b),w=g*(h+s),S=k*(h+s),T=j===null?u:i[j];return e.jsx("rect",{x:w,y:S,width:h,height:h,rx:n,ry:n,fill:T},`${g}-${k}`)}))})}const $u=At("oklch(0.97 0.01 85)"),Fe=At("oklch(0.18 0.02 85)"),tt=At("oklch(0.38 0.015 85)"),Ws=At("oklch(0.55 0.012 85)"),lt=At("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',Pu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Bu=["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(At);function Wn({data:t}){const a=Mu(t),r=_r(t.totalTokens),s=Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=Lu(t.startDate),o=Iu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),i=Eu(t),u=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:$u,color:Fe,fontFamily:Pu,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 ${Ws}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Fe},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:lt}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:tt,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:tt,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:ct,fontSize:52,fontStyle:"italic",lineHeight:1,color:Fe,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:tt,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Fe},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:lt,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:ct,fontSize:o,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Fe,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Fe,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",i,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:lt,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:tt},children:[e.jsxs("span",{children:[l("share.card.broadsheet.estimated_spend")," · ",s]}),e.jsx("span",{children:l("share.card.broadsheet.billable_days",{days:t.activeDays})})]})]}),u?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Fe,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Fu,{weeks:t.heatmapWeeks,palette:Bu,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 ${Fe}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Fe,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:ct,fontStyle:"italic",fontSize:26,color:tt,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((d,m)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Ws}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(m+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:ct,fontSize:32,color:Fe,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Fe,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:_r(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:tt,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Fe}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Fe},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:lt},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:lt},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:lt},children:"→ tokentracker.cc"})]})]})]})}const zu=Hn["annual-report"].width,Ou="#0a0820",at="#ffffffee",dt="rgba(255,255,255,0.45)",xr="#a78bfa",Uu={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"},vr='"Space Grotesk", "Inter Tight", sans-serif',gr='"Inter Tight", sans-serif',Hu="rgba(255,255,255,0.06)",qn=[Hu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Gn=48,Yn=28,Ta=4,Jn=20,Ku=zu-Gn*2-Yn*2,Vu=(Ku-Jn*2)/3,jr=Math.min(Math.floor((Vu-Ta*6)/7),40),Wu=jr*7+Ta*6;function qu(t){if(!Array.isArray(t))return t;const a=[];for(const u of t)if(Array.isArray(u))for(const d of u)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((u,d)=>u-d);const r=u=>{const d=a.length,m=(d-1)*u,h=Math.floor(m);return Math.round((a[h]??0)+((a[Math.min(d-1,h+1)]??0)-(a[h]??0))*(m-h))},s=r(.5),n=r(.75),o=r(.9),i=u=>!u||u<=0?0:u<=s?1:u<=n?2:u<=o?3:4;return t.map(u=>Array.isArray(u)?u.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:i(d.value)}:d):u)}function Gu(t){if(!Array.isArray(t))return[];const a={},r=qu(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 Yu(t){if(!t.length)return[];const a=[...t].sort((i,u)=>i.day.localeCompare(u.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let 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 Ju=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Zu(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 qs(t){const[a,r]=c.useState(null);return c.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 Qu({data:t}){const a=Yu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:vr,marginBottom:4},children:Ju[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ta},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ta},children:r.map((n,o)=>{const i=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:jr,height:jr,borderRadius:4,background:i<0?"transparent":qn[i]}},o)})},s))})]})}function Xu({data:t}){const a=Gu(t.heatmapWeeks),r=Zu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,o=qs(n),i=qs("/neon_bg.png"),u=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Ou,fontFamily:vr,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:Gn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:d*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:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:at},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:at},children:u})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:at},children:t.handle})]})]}),e.jsxs("div",{style:{...Uu,borderRadius:22,padding:Yn,marginBottom:d},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:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),qn.map((m,h)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:m}},h)),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,${Wu}px)`,gap:`8px ${Jn}px`,justifyContent:"center"},children:a.map(m=>e.jsx(Qu,{data:m},m.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{..._a,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:_r(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,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:gr,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},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:xr,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:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:gr,fontSize:28,fontWeight:700,color:at},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:xr,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:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:vr,fontSize:28,fontWeight:700,color:at},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:at},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:xr},children:"tokentracker.cc"})]})]})]})}const Zn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],em={broadsheet:Wn,"annual-report":Xu};function Qn(t){return Hn[t]||{width:On,height:Un}}function tm(t){const a=Zn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Gs=c.forwardRef(function({data:a,variant:r},s){const n=em[r]||Wn,{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 va(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const am=440;function rm(){const[t,a]=c.useState(null),r=c.useRef(null),s=c.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 c.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function pr({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 sm({open:t,onClose:a,data:r,twitterText:s}){const[n,o]=c.useState(null),[i,u]=c.useState(""),[d,m]=c.useState("annual-report"),h=c.useRef(null),{toast:p,push:x}=rm(),g=an(),f=c.useMemo(()=>{const N=g?.user;if(!N||typeof N!="object")return null;const v=N.user_metadata||{},D=N.profile||{},R=v.avatar_url||v.picture||D.avatar_url||N.avatar_url;return typeof R=="string"&&R.trim()?R.trim():null},[g?.user]);c.useEffect(()=>{t&&(o(null),u(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:i||r.handle,avatarUrl:f},{width:k,height:j}=Qn(d),w=am/k;c.useEffect(()=>{if(!t)return;const N=v=>{v.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const S=c.useCallback(async()=>{const N=h.current;if(!N)return null;try{return await Nu(N)}catch(v){return console.warn("[share] capture failed",v),null}},[]),T=c.useCallback(async()=>{if(n)return;o("copy");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}let v=!1;if(va()){const D=await hr(N);D&&(v=(await wu(D)).ok)}else v=await es(N);x(v?l("share.toast.copied"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,x]),A=c.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),L=c.useCallback(async()=>{if(n)return;o("download");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}if(va()){const D=await hr(N);if(D&&(await Ks(D,A())).ok){x(l("share.toast.downloaded"),"success"),o(null);return}}const v=Vs(N,A());x(v?l("share.toast.downloaded"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,A,x]),P=c.useCallback(async()=>{if(n)return;o("x");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}if(va()){const O=await hr(N);O&&(await Ks(O,A()),x(l("share.toast.downloaded"),"success"))}else await es(N)?x(l("share.toast.copied"),"success"):Vs(N,A());const v=new URL("https://twitter.com/intent/tweet");s&&v.searchParams.set("text",s);const D=g?.user?.id,R=typeof D=="string"&&D?`/u/${D}`:"/";if(v.searchParams.set("url",`https://www.tokentracker.cc${R}?ref=share`),va())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:v.toString()})}catch{window.open(v.toString(),"_blank","noopener,noreferrer")}else window.open(v.toString(),"_blank","noopener,noreferrer");o(null)},[n,S,x,s,A,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:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:j,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Gs,{ref:h,data:b,variant:d})}),e.jsxs(pe.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:j*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:j,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Gs,{data:b,variant:d})})]})}),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:N=>u(N.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:Zn.map(N=>e.jsx("button",{type:"button",onClick:()=>m(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===N.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:tm(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(pr,{onClick:P,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(pr,{onClick:L,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(pr,{onClick:T,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(Dt,{children:p?e.jsx(pe.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 nm(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:o,topModels:i,period:u,periodFrom:d,periodTo:m,heatmap:h,accessToken:p,userId:x,currency:g,exchangeRate:f}=t,[b,k]=c.useState(null),j=f;return c.useEffect(()=>{if(!a||!x&&!ht())return;let w=!1;return(async()=>{try{const T=await Ei({accessToken:p,userId:x,period:u==="day"||u==="custom"?"week":u,metric:"all",limit:100,offset:0});if(w)return;const L=(Array.isArray(T?.entries)?T.entries:Array.isArray(T)?T:[]).find(N=>N?.is_me===!0),P=typeof L?.rank=="number"?L.rank:null;k(P)}catch{w||k(null)}})(),()=>{w=!0}},[a,p,x,u]),c.useMemo(()=>Tu({handle:r,startDate:s,activeDays:n,summary:o,topModels:i,rank:b,period:u,periodFrom:d,periodTo:m,heatmap:h,currency:g,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,o,i,b,u,d,m,h,g,j])}function Ys(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 om=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function im({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const lm=["day","week","month","total","custom"],fr=new Set(["day","hour","month"]),Wt=new Set(["day","total","custom"]),cm=["islandOnboarding","linuxPetCard","macAppBanner","statsPanel","widgetOnboarding","linuxTopBarCard","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],dm=["usageOverview","dataDetails"];function yr(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 ja(t){return t?Ct(t,null):null}function Js(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function um(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function mm(){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:!um(window.location.hostname)}function n0({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:o=!1,publicToken:i=null,signInUrl:u="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:m}){const{resolvedLocale:h}=Ii(),{currency:p,rate:x}=Aa(),{mode:g,setMode:f,formatTokens:b,formatTokensTooltip:k}=De(),[j,w]=c.useState(!1),[S,T]=c.useState(null),[A,L]=c.useState(null),[P,N]=c.useState(!1),[v,D]=c.useState(null),[R,O]=c.useState(0),[F,E]=c.useState(0),[B,K]=c.useState(null),G=c.useMemo(()=>typeof window>"u"?!1:Ri(window.location.search),[]),_=c.useMemo(()=>mm(),[]),[$,H]=c.useState(!1),ae=2200,[me,V]=c.useState(!0),[ie,le]=c.useState(!1),[Se,ve]=c.useState(!1),[Me,Q]=c.useState(!1),[U,ne]=c.useState(!1),ee=c.useRef(!1),re=ht(),be=r&&!s,W=c.useMemo(()=>be&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,be]),Y=be?W:null,X=o?Fi(i):Y,ue=r||re||o,Pe=be&&Zt(Y),Ae=r&&s&&!o,{accountView:he,revision:C,resolving:J}=$i(),z=he&&!o,se=z?Y:null,xe=J&&!o;c.useEffect(()=>{if(!r||re){T(null),L(null),N(!1),D(null);return}if(o)return;if(!Pe){T(null),L(null),N(!1),D(null);return}let y=!0;const M=()=>{T(null),L(null),N(!1),D(null)};return N(!0),D(null),(async()=>{let I=null;try{I=await Ue(Y)}catch{I=null}if(y){if(!I){M();return}try{const q={link_code:null,expires_at:null};if(!y)return;T(typeof q?.link_code=="string"?q.link_code:null),L(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;T(null),L(null),D(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,re,r,o,Pe,Y,F]);const ke=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");c.useEffect(()=>{if(!ke&&(!r||re||o)){K(null);return}if(!ke&&!Pe){K(null);return}let y=!0;return(async()=>{let M=null;try{M=await Ue(Y)}catch{M=null}if(y){if(!M&&!ke){K(null);return}try{const I=await Pi({baseUrl:t,accessToken:M});if(!y)return;K(I&&typeof I=="object"?I:null)}catch{if(!y)return;K(null)}}})(),()=>{y=!1}},[Pe,t,Y,re,o,r]);const st=c.useMemo(()=>{if(!A)return!1;const y=Date.parse(A);if(!Number.isFinite(y))return!1;const M=R||Date.now();return y<=M},[A,R]);c.useEffect(()=>{!r||re||o||!A||!st||P||(T(null),L(null),D(null),E(y=>y+1))},[st,A,P,re,r]),c.useEffect(()=>{if(!A||o)return;const y=Date.parse(A);if(!Number.isFinite(y))return;const M=Date.now();if(O(M),y<=M)return;const I=window.setTimeout(()=>O(Date.now()),y-M),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(I),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[A]);const fe=c.useMemo(()=>tn(),[]),ye=c.useMemo(()=>en(),[]),Be=c.useMemo(()=>Bi(),[]),ze=o?null:a?.userId||a?.email||"default",[Lt,xt]=c.useState("month"),[Ve,La]=c.useState(null),[Xe,Ma]=c.useState(null),[Ea,gt]=c.useState(!1),Z=G?"total":Lt,ea=c.useMemo(()=>Z==="custom"&&Ve&&Xe?{from:Ve,to:Xe}:zi(Z,{timeZone:fe,offsetMinutes:ye,now:Be}),[Be,Z,fe,ye,Ve,Xe]),we=ea.from,_e=ea.to,[je,pt]=c.useState(null),[Mt,ta]=c.useState(()=>ts());c.useEffect(()=>{const y=()=>ta(ts());return window.addEventListener(as,y),window.addEventListener("storage",y),()=>{window.removeEventListener(as,y),window.removeEventListener("storage",y)}},[]);const{devices:aa,accountSources:Et,refresh:Ia}=yu({from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye,accountView:z,accountAccessToken:se,accountRevision:C}),We=c.useMemo(()=>aa.filter(y=>(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.id===Mt})),[aa,Mt]),ra=c.useMemo(()=>Et.filter(y=>(Number(y.total_tokens)||0)>0),[Et]),nt=z&&We.length>=2,It=z&&We.length+ra.length>=2;c.useEffect(()=>{if(!nt&&!It){je!==null&&pt(null);return}je&&!We.some(y=>y.id===je)&&pt(null)},[nt,It,We,je]);const Ra=c.useMemo(()=>nt?[{value:"",label:l("dashboard.device_filter.all")},...We.map(y=>{const M=kr(y)||l("dashboard.device_card.unnamed"),I=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${M}${I}`}})]:[],[nt,We,h]),sa=It?e.jsx(ku,{devices:We,accountSources:ra,currentDeviceId:Mt,selectedDeviceId:je||"",onSelectDevice:y=>pt(y||null),onRenameDevice:async(y,M)=>{const I=await Ue(se);await Wi({deviceId:y,name:M,accessToken:I}),await Ia()}}):null,na=c.useMemo(()=>Oi({timeZone:fe,offsetMinutes:ye}),[fe,ye]),Rt=c.useMemo(()=>Ui({timeZone:fe,offsetMinutes:ye}),[fe,ye]),Fa=c.useMemo(()=>`Local time (${Rt})`,[Rt]),Ft=fe,$t=ye,$a=na,Ye=c.useMemo(()=>Cr({timeZone:fe,offsetMinutes:ye,date:Be||new Date}),[Be,fe,ye]),oa=c.useMemo(()=>Nc({period:Z,selectedFrom:we,selectedTo:_e,todayKey:Ye}),[we,Z,_e,Ye]),{daily:qe,summary:ge,rolling:Pa,source:Pt,loading:ia,error:Ba,refresh:de}=ms({baseUrl:t,accessToken:X,guestAllowed:Ae,from:we,to:_e,includeDaily:Z!=="total",cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{daily:oe,loading:Ce,refresh:et}=ms({baseUrl:t,accessToken:X,guestAllowed:Ae,from:oa.from,to:oa.to,includeDaily:!0,includeSummary:!1,cacheKey:ze?`${ze}.daily-breakdown`:"daily-breakdown",timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{breakdown:Te,loading:ft,refresh:Mr}=nc({baseUrl:t,accessToken:X,guestAllowed:Ae,from:we,to:_e,cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),[Xn,eo]=c.useState(3),{entries:to,loading:ao,refresh:Er}=ac({baseUrl:t,accessToken:X,from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye}),Ir=Z==="week"||Z==="month",la=Z==="week"||Z==="month",Rr=c.useMemo(()=>qe.filter(y=>y?.future?!1:!y?.day||!Ye?!0:String(y.day)<=String(Ye)),[qe,Ye]),{rows:Je,from:ro,to:so,loading:no,refresh:Fr}=Gi({baseUrl:t,accessToken:X,guestAllowed:Ae,period:Z,from:we,to:_e,months:24,cacheKey:ze,timeZone:Ft,tzOffsetMinutes:$t,now:Be,sharedRows:Ir?qe:null,sharedRange:Ir?{from:we,to:_e}:null,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),oo=c.useMemo(()=>({baseUrl:t,accessToken:X,guestAllowed:Ae,cacheKey:ze,timeZone:Ft,tzOffsetMinutes:$t,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),[t,X,Ae,ze,Ft,$t,Be,z,se,C,xe,je]),{daily:yt,heatmap:Ge,loading:$r,refresh:Pr}=Zl({baseUrl:t,accessToken:X,guestAllowed:Ae,weeks:52,cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{data:ca,refresh:Br}=Yi();c.useEffect(()=>{ca&&typeof ca=="object"&&Hi(ca)},[ca]);const He=c.useMemo(()=>Z==="day"?"hour":Z==="total"?"month":"day",[Z]),io=c.useMemo(()=>xs(He),[He]),da="day",lo=c.useMemo(()=>xs(da),[]),[Ke,zr]=c.useState(()=>({key:"day",dir:"desc"}));c.useEffect(()=>{zr(y=>!fr.has(y.key)||y.key===He?y:{key:He,dir:y.dir})},[He]);const bt=c.useMemo(()=>fr.has(Ke.key)&&Ke.key!==He?{...Ke,key:He}:Ke,[He,Ke]),ua=c.useMemo(()=>{if(Z==="day")return Array.isArray(Je)?Je.filter(I=>I?.hour&&!I?.future):[];if(Z==="total"){const I=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return yc(I)}const y=Rr;return!y.some(I=>!I?.missing&&!I?.future)&&qe.length>0?qe.filter(I=>!I?.future).slice(-30).filter(I=>I?.day):y},[Z,Je,Rr,qe]),Bt=c.useMemo(()=>gs(ua,bt),[ua,bt]),Or=c.useMemo(()=>ua.some(y=>!y?.missing&&!y?.future),[ua]),za=c.useMemo(()=>{if(!Wt.has(Z))return 1;const y=Math.ceil(Bt.length/Ca);return y>0?y:1},[Z,Bt.length]),[Oa,ma]=c.useState(0);c.useEffect(()=>{if(!Wt.has(Z)){ma(0);return}ma(y=>Math.min(y,za-1))},[za,Z]),c.useEffect(()=>{Wt.has(Z)&&ma(0)},[Z,Ke.dir,Ke.key]);const co=c.useMemo(()=>Wt.has(Z)?bc(Bt,Oa,Ca):Bt,[Oa,Z,Bt]),Ur=c.useMemo(()=>Sc(oe,{period:Z}),[oe,Z]),kt=c.useMemo(()=>fr.has(Ke.key)?{...Ke,key:da}:Ke,[Ke]),uo=c.useMemo(()=>gs(Ur,kt),[Ur,kt]),mo=c.useMemo(()=>la?qe:Z==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[qe,Z,Je,la]),ho=la?we:ro,xo=la?_e:so;function go(y,M){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(M.endsWith("_tokens")){const I=M==="total_tokens"?ja(y):y?.[M];return e.jsx("span",{title:k(I),children:b(I)})}return Sa(y?.[M])}function po(y){const M=y?.[He];if(M==null)return"";const I=String(M);if(He==="hour"){const[q,Ie]=I.split("T");if(q&&Ie)return`${q} ${Ie.slice(0,5)}`}return I}function fo(y){const M=y?.[da];return M==null?"":String(M)}function yo(y){zr(M=>M.key===y?{key:y,dir:M.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function bo(y){return bt.key!==y?"none":bt.dir==="asc"?"ascending":"descending"}function ko(y){return bt.key!==y?"":bt.dir==="asc"?"▲":"▼"}function wo(y){return kt.key!==y?"none":kt.dir==="asc"?"ascending":"descending"}function _o(y){return kt.key!==y?"":kt.dir==="asc"?"▲":"▼"}const Ua=c.useMemo(()=>{if(!r&&!re&&!o&&!ke)return 0;const y=Number(Ge?.active_days);if(Number.isFinite(y))return y;let M=0;const I=new Set,q=(Ne,Oe,Re)=>{typeof Ne!="string"||!Ne||I.has(Ne)||yr(Oe,Re)&&(I.add(Ne),M+=1)};if(Array.isArray(yt))for(const Ne of yt)q(Ne?.day,ja(Ne));const Ie=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const Ne of Ie)for(const Oe of Array.isArray(Ne)?Ne:[]){const Re=Js(Oe);q(Oe?.day,Re,Oe?.level)}return M},[r,re,Ge?.active_days,Ge?.weeks,yt]),[Hr,Kr]=c.useState("month"),vo=c.useCallback(y=>{z&&!o&&er(a?.userId,"history"),y==="custom"?(Kr(M=>M==="custom"?"month":M),xt(M=>Ve&&Xe?"custom":M),gt(!0)):(xt(y),Kr(y),gt(!1))},[Ve,Xe,z,o,a?.userId]),jo=c.useCallback((y,M)=>{z&&!o&&er(a?.userId,"history"),La(y),Ma(M),xt("custom"),gt(!1)},[z,o,a?.userId]),No=c.useCallback(y=>{gt(y),!y&&Lt==="custom"&&!Ve&&xt(Hr)},[Lt,Ve,Hr]),So=c.useRef(null),ha=c.useMemo(()=>[t||"",ze||"",z?"cloud":"local",C??"",Z||"",we||"",_e||"",Ye||"",je||"all",fe||"",ye??""].join(""),[C,z,t,ze,we,Z,je,fe,Ye,_e,ye]),zt=c.useCallback(async()=>Ys(So,ha,async()=>{z&&Ki(),z||Vi(),await Promise.all([de(),Pr(),Fr(),Mr(),Er(),et()])}),[z,et,Pr,Mr,Er,Fr,de,ha]),Co=c.useRef(null),Vr=c.useCallback(async()=>Ys(Co,ha,async()=>{await im({refreshUsageStats:zt,refreshUsageLimits:Br})}),[ha,Br,zt]),Ha=c.useRef(zt);c.useEffect(()=>{Ha.current=zt},[zt]);const Ka=c.useRef(null);c.useEffect(()=>{if(!ke||re||z)return;Ka.current||(Ka.current=rs({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Ka.current.then(()=>{if(y)return Ha.current()}).catch(M=>{y&&console.warn("[DashboardPage] Reload sync failed:",M)}),()=>{y=!1}},[ke,re,z]),c.useEffect(()=>{if(!ke||re||z)return;const y=vc({refresh:()=>Ha.current(),onError:M=>console.warn("[DashboardPage] Automatic usage refresh failed:",M)});return()=>y.stop()},[ke,re,z]);const To=c.useCallback(async()=>{Q(!0);try{ke&&await rs(om),await Vr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{Q(!1)}},[ke,Vr]),xa=Me||ia||Ce||$r||no||ft||ao,Va=!U&&(xe||z&&xa&&!Or),Do=c.useMemo(()=>l("shared.data_source",{source:String(Pt||"edge").toUpperCase()}),[Pt,h]),ga=c.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Ao="",Wr=c.useMemo(()=>!ga||ga.includes("@")?l("dashboard.identity.fallback"):ga,[ga]),qr=c.useMemo(()=>Wr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Wr]),Gr=c.useMemo(()=>o?l("dashboard.identity.fallback"):qr,[qr,Ao,o]),Yr=c.useMemo(()=>{let y=null;const M=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(yt))for(const q of yt)q?.day&&yr(ja(q))&&M(q.day);const I=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const q of I)for(const Ie of Array.isArray(q)?q:[]){if(!Ie?.day)continue;const Ne=Js(Ie),Oe=Ie?.level;yr(Ne,Oe)&&M(Ie.day)}return y},[Ge?.weeks,yt]),Lo=c.useMemo(()=>o?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(I=>{const q=typeof I?.tool=="string"?I.tool.trim():"",Ne=(typeof I?.plan_type=="string"?I.plan_type:typeof I?.planType=="string"?I.planType:"").trim();return!q||!Ne?null:{tool:q,planType:Ne,provider:typeof I?.provider=="string"?I.provider.trim():"",product:typeof I?.product=="string"?I.product.trim():"",rateLimitTier:typeof I?.rate_limit_tier=="string"?I.rate_limit_tier.trim():typeof I?.rateLimitTier=="string"?I.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[o,B]),Mo=e.jsx(Ji,{heatmap:Ge,timeZoneLabel:na,timeZoneShortLabel:Rt,hideLegend:G,defaultToLatestMonth:G}),Eo=c.useMemo(()=>`${we}..${_e}`,[we,Z,_e]),Io=l("usage.summary.total"),Ee=ge!=null,wt=Ee?ja(ge):0,Ro=b(wt),Fo=c.useCallback(()=>{f(g===qt.COMPACT?qt.FULL:qt.COMPACT)},[f,g]),$o=l("dashboard.core_index.collapse_label"),Po=l("dashboard.core_index.expand_label"),Bo=l("dashboard.core_index.collapse_aria"),zo=l("dashboard.core_index.expand_aria"),Oo=!G,_t=l("shared.placeholder.short"),Wa=c.useMemo(()=>{const y=Array.isArray(Te?.sources)?Te.sources:[];let M=null,I=0;for(const Oe of y){const Re=Ct(Oe?.totals);!Number.isFinite(Re)||Re<=0||Re>I&&(I=Re,M=Oe)}let q=_t,Ie=_t,Ne="0.0";if(M&&I>0){q=M?.source?String(M.source).toUpperCase():_t;const Oe=Array.isArray(M?.models)?M.models:[];let Re=0;for(const Xa of Oe){const fa=Ct(Xa?.totals);!Number.isFinite(fa)||fa<=0||fa>Re&&(Re=fa,Ie=Xa?.model?String(Xa.model):_t)}Re>0&&(Ne=(Re/I*100).toFixed(1))}return{agentName:q,modelName:Ie,modelPercent:Ne}},[Te,_t]),qa=Sa(wt),Uo=l("dashboard.screenshot.twitter_text",{total_tokens:qa==="-"?_t:qa,agent_name:Wa.agentName,model_name:Wa.modelName,model_percent:Wa.modelPercent}),Ho=c.useMemo(()=>G?[]:lm,[G]),Ko=c.useMemo(()=>[{label:l("usage.metric.total"),value:Ee?b(wt):"—",title:Ee?k(wt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Ee?b(ge?.input_tokens):"—",title:Ee?k(ge?.input_tokens):void 0},{label:l("usage.metric.output"),value:Ee?b(ge?.output_tokens):"—",title:Ee?k(ge?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Ee?b(ge?.cached_input_tokens):"—",title:Ee?k(ge?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Ee?b(ge?.reasoning_output_tokens):"—",title:Ee?k(ge?.reasoning_output_tokens):void 0}],[ge?.cached_input_tokens,ge?.input_tokens,ge?.output_tokens,ge?.reasoning_output_tokens,wt,Ee,b,k]),Ga=(Te?.sources||[]).some(y=>(y.models||[]).some(M=>M.pricing?.status==="unpriced"&&M.cost_source!=="provider_reported"&&Number(M.totals?.total_tokens)>0)),Ya=c.useMemo(()=>{if(Ga&&Number(ge?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=Qt(ge?.total_cost_usd,{currency:p,rate:x});return Ga&&y!=="-"?`≥${y}`:y},[ge?.total_cost_usd,p,x,Ga]),Vo=c.useMemo(()=>ge?.conversation_count??null,[ge?.conversation_count]),Jr=c.useMemo(()=>Ic(Te,{copyFn:l}),[Te]),Zr=c.useMemo(()=>Fc(Te,{limit:3,copyFn:l}),[Te]),Wo=nm({enabled:$,handle:Gr,startDate:Yr,activeDays:Ua,summary:ge,topModels:Zr,period:Z,periodFrom:we,periodTo:_e,heatmap:Ge,accessToken:typeof X=="string"?X:null,userId:a?.userId||null,currency:p,exchangeRate:x}),qo=c.useCallback(()=>H(!0),[]),Go=c.useCallback(()=>H(!1),[]),Yo=c.useCallback(()=>w(!0),[]),Jo=c.useCallback(()=>w(!1),[]),Zo=Ya&&Ya!=="-"&&Jr.length>0,Ot=l("dashboard.install.cmd.init"),Ja=st?null:S,Za=Ja?l("dashboard.install.cmd.init_link_code",{link_code:Ja}):Ot,Qo=Ot,Xo=l("dashboard.install.cmd.sync"),ei=Ja?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ti=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const ai=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),ri=kc({publicMode:o,screenshotMode:G,forceInstall:_,accessEnabled:ue,heatmapLoading:$r,activeDays:Ua,hasActiveDeviceToken:ai}),si=l("dashboard.install.prompt"),ni=c.useCallback(async()=>{!Za||!await ss(Za)||(le(!0),window.setTimeout(()=>le(!1),2e3))},[Za]);c.useCallback(async()=>{!Ot||!await ss(Ot)||(ve(!0),window.setTimeout(()=>ve(!1),2e3))},[Ot]);const Qa=c.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[h]),[oi,ii]=c.useMemo(()=>{const y=Qa.split("{{cmd}}");return y.length===1?[Qa,""]:[y[0],y.slice(1).join("{{cmd}}")]},[Qa]),Ut=s&&!o,Ht=!r&&!re&&!s&&!ke&&!o;c.useEffect(()=>{Ut||Ht||Va||ne(!0)},[Va,Ht,Ut]);const pa=ec(cm,dm);return c.useEffect(()=>{ee.current||Ut||Ht||xa||(ee.current=!0,m?.())},[m,Ht,Ut,xa]),e.jsxs(e.Fragment,{children:[z&&!o?e.jsx("div",{className:"mb-3 flex justify-end",children:e.jsx(Al,{from:we,to:_e,deviceId:je})}):null,e.jsx(fu,{copy:l,onOpenShare:qo,screenshotMode:G,showExpiredGate:Ut,showAuthGate:Ht,identityDisplayName:Gr,identityStartDate:Yr,activeDays:Ua,identitySubscriptions:Lo,identityScrambleDurationMs:ae,projectUsageEntries:to,projectUsageLimit:Xn,setProjectUsageLimit:eo,projectDetailQuery:{from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye},topModels:Zr,signedIn:r,publicMode:o,isLocalMode:ke,shouldShowInstall:ri,installPrompt:si,handleCopyInstall:ni,installCopied:ie,installCopiedLabel:ti,installCopyLabel:ei,installInitCmdDisplay:Qo,linkCodeLoading:P,linkCodeError:v,trendRowsForDisplay:mo,trendFromForDisplay:ho,trendToForDisplay:xo,trendZoomConfig:oo,usageFrom:we,usageTo:_e,period:Z,trendTimeZoneLabel:$a,activityHeatmapBlock:Mo,periodsForDisplay:Ho,setSelectedPeriod:vo,customFrom:Ve,customTo:Xe,onCustomRangeApply:jo,customRangeOpen:Ea,onCustomRangeOpenChange:No,metricsRows:Ko,summaryLabel:Io,summaryValue:Ro,hasSummary:Ee,summaryLoading:ia,providersLoading:ft,summaryFullValue:qa,onToggleSummaryFormat:Fo,summaryTotalTokensRaw:te(wt)||0,summaryCostValue:Ya,summaryConversationsValue:Vo,rollingUsage:Pa,costInfoEnabled:Zo,openCostModal:Yo,allowBreakdownToggle:Oo,coreIndexCollapsed:me,setCoreIndexCollapsed:V,coreIndexCollapseLabel:$o,coreIndexExpandLabel:Po,coreIndexCollapseAria:Bo,coreIndexExpandAria:zo,refreshAll:To,usageLoadingState:xa,announceUsageLoading:Me,initialDashboardLoading:Va,usageError:Ba,rangeLabel:Eo,timeZoneRangeLabel:Fa,usageSourceLabel:Do,fleetData:Jr,hasDetailsActual:Or,dailyEmptyPrefix:oi,installSyncCmd:Xo,dailyEmptySuffix:ii,detailsColumns:io,ariaSortFor:bo,toggleSort:yo,sortIconFor:ko,pagedDetails:co,dailyBreakdownRows:uo,dailyBreakdownColumns:lo,dailyBreakdownAriaSortFor:wo,dailyBreakdownSortIconFor:_o,dailyBreakdownDateKey:da,detailsDateKey:He,renderDetailDate:po,renderDailyBreakdownDate:fo,renderDetailCell:go,DETAILS_PAGED_PERIODS:Wt,detailsPageCount:za,detailsPage:Oa,setDetailsPage:ma,costModalOpen:j,closeCostModal:Jo,deviceOptions:Ra,selectedDevice:je||"",onDeviceChange:y=>{z&&!o&&er(a?.userId,"view"),pt(y||null)},deviceUsageBlock:sa,leftCardOrder:pa.left.order,onLeftReorder:pa.left.reorder,rightCardOrder:pa.right.order,onRightReorder:pa.right.reorder}),e.jsx(sm,{open:$,onClose:Go,data:Wo,twitterText:Uo})]})}export{n0 as DashboardPage};
1
+ import{o as Nr,r as c,j as e,L as li,dw as ci,W as ht,aA as Zt,aB as Ue,dx as di,dy as ui,ay as Qr,dz as ya,aG as Zs,aH as Qs,aI as Sr,dA as mi,dB as hi,dC as xi,aK as Cr,aJ as Gt,dD as gi,dE as pi,dF as te,c as l,V as jt,X as Tr,i as $e,az as Qt,bs as Yt,z as Xs,dG as fi,an as yi,l as qt,ck as Sa,y as St,dH as bi,U as en,Q as tn,aM as ki,ao as wi,B as _i,R as vi,h as ji,u as Ni,a as an,p as Da,v as rn,bc as Si,dI as Ci,dJ as Ti,dK as Di,dL as Ai,dM as Li,am as Xr,_ as Mi,dN as es,g as Ei,Z as Ii,cX as Ri,dO as Fi,dP as $i,dQ as Pi,dR as Bi,dS as zi,cl as ts,cq as as,dT as Oi,dU as Ui,aT as Hi,cB as er,dV as rs,aR as ss,dW as Ki,dX as Vi,dY as Wi}from"./__vite-browser-external-DKVGjnxf.js";import{u as rt}from"./use-latest-request-guard-8-lur0NI.js";import{u as ns}from"./use-ordered-list-Cul7GZDv.js";import{t as os,T as sn,g as qi,u as Gi}from"./TrendMonitor-gMTrGZzH.js";import{u as Yi}from"./use-usage-limits-3ZkgTe7n.js";import{u as Aa}from"./useCurrency-EbqxSlEF.js";import{u as De}from"./useTokenFormat-CanmWK4w.js";import{f as Nt,A as Ji}from"./provider-display-C-ibpm5u.js";import{g as Zi,q as nn,J as Qi,M as Xi,m as pe}from"./react-_bbDNdaT.js";import{u as el,C as tl,a as al,b as is,D as rl,S as sl,v as nl,s as ol,K as il,P as ll}from"./sortable.esm-DrIfxJ2p.js";import{D as cl,a as dl,b as ul,c as ml,d as hl,e as xl}from"./DialogTitle-CI8xcLkd.js";import{D as gl}from"./DialogClose-IWs31AbB.js";import{C as Le}from"./Card-CMShFKqX.js";import{S as on}from"./Select-ClkKzKsi.js";import{P as Tt}from"./ProviderIcon-B1oef_V8.js";import{u as Xt}from"./use-reduced-motion-CkHJN2uY.js";import{a as ln,u as cn}from"./use-transform-DzUhSbxH.js";import{f as ba,D as pl,g as fl}from"./DateRangePopover-CVZTfOUX.js";import{I as dn}from"./info-DSgWF_40.js";import{A as Dt}from"./index-D_ERbEBI.js";import{L as yl}from"./loader-circle-B2ln5DKm.js";import{P as bl,a as kl,b as wl,c as _l,d as vl}from"./PopoverPopup-B_fwRpm_.js";import{F as ot}from"./FadeIn-BJiqknMG.js";import{C as un,u as jl}from"./use-pet-settings-DkNURWe6.js";import{u as Nl}from"./use-native-settings-CkPyWn4W.js";import{T as Sl}from"./Controls-D6267L_q.js";import{A as Dr}from"./arrow-up-right-DSJpQHMH.js";import{u as Cl,b as Tl,P as Dl,a as Al}from"./CloudUsageExport-Dn7_qVGy.js";import{L as ls}from"./LoginCard-s3qsEOET.js";import{L as Ll,A as Ml}from"./agent-logos-CyXPIQ5S.js";import{M as mn}from"./monitor-smartphone-BI3aJPNi.js";import{C as El}from"./check-BTSG8HIW.js";import"./terminal-CExBqXDx.js";import"./use-limits-display-prefs-Dq0e_5PV.js";import"./play-CVxzAkNo.js";import"./composite-_t6vz49X.js";import"./store-CjkDYjXp.js";import"./chevron-down-0nuZGQbD.js";import"./SelectItemText-D_4VNKEi.js";import"./usePositioner-cTX1WPQP.js";import"./safePolygon-DeLf2a7a.js";import"./calendar-days-Cpu5CPAM.js";import"./download-CzxvhDR9.js";import"./arrow-left-BqMZ7dgK.js";const hn={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"}]]};hn.node;const Il=Nr(hn);const xn={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"}]]};xn.node;const Rl=Nr(xn);const gn={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"]};gn.node;const Fl=Nr(gn);function $l(t,a,r={}){const s=t.get();let n=null,o=s,i;const u=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},m=()=>{const p=cs(t.get()),x=cs(o);if(p===x){d();return}const g=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new Qi({keyframes:[p,x],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:i})},h=()=>{m(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((p,x)=>{o=p,i=g=>x(tr(g,u)),Zi.postRender(h)},d),nn(a)){let p=r.skipInitialAnimation===!0;const x=a.on("change",f=>{p?(p=!1,t.jump(tr(f,u),!1)):t.set(tr(f,u))}),g=t.on("destroy",x);return()=>{x(),g()}}return d}function tr(t,a){return a?t+a:t}function cs(t){return typeof t=="number"?t:parseFloat(t)}function Pl(t,a={}){const{isStatic:r}=c.useContext(Xi),s=()=>nn(t)?t.get():t;if(r)return ln(s);const n=cn(s());return c.useInsertionEffect(()=>$l(n,t,a),[n,JSON.stringify(a)]),n}function Bl(t,a={}){return Pl(t,{type:"spring",...a})}function zl(){return e.jsxs(li,{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 Ol({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(zl,{}),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 Ul({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"},u=`${n} ${o[a]} ${i[r]} ${s}`.trim();return e.jsx("span",{className:u,children:t})}var Hl={};function Kl(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 Vl({mv:t,digit:a,height:r}){const s=ln(t,n=>{const o=(n%10+10)%10,i=(10+a-o)%10;let u=i*r;return i>5&&(u-=10*r),u});return e.jsx(pe.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Wl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function ql(t,a){const r=t/a;return Math.floor(Wl(r))}function Gl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((u,d)=>/\d/.test(u)&&(s===-1||d<s)).length,o=0,i=!1;return r.map(u=>{if(!/\d/.test(u))return u==="."&&(i=!0),u;if(!i){const d=10**Math.max(n-1,0);return n-=1,d}return o+=1,10**-o})}function Yl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=Kl(t,r),m=t!=="."&&t!==",",h=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...m?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...h?{width:d.width}:null},children:t})}const o=ql(a,t),i=cn(0),u=Bl(i,{stiffness:220,damping:26,mass:.8});return c.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},(d,m)=>e.jsx(Vl,{mv:u,digit:m,height:r},m))})}function Jl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:o=6,borderRadius:i=4,horizontalPadding:u=0,textColor:d="inherit",fontWeight:m="inherit",containerStyle:h,counterStyle:p,digitStyle:x,gradientHeight:g=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const w=String(a??t??""),S=c.useMemo(()=>Array.isArray(n)&&n.length?n:Gl(w),[n,w]),T=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Hl?.VITEST==="true",A=Xt()||T,L=Number.isFinite(Number(t))?Math.abs(Number(t)):0,P=r+s;return A?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:m,lineHeight:1,...h,...p},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...h},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:o,overflow:"hidden",borderRadius:i,paddingLeft:u,paddingRight:u,lineHeight:1,color:d,fontWeight:m,...p},children:S.map((N,v)=>e.jsx(Yl,{place:N,value:L,height:P,digitStyle:x,shouldReduceMotion:A},`${String(N)}-${v}`))}),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:j??{height:g,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function Zl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:o,timeZone:i,tzOffsetMinutes:u,now:d,accountView:m=!1,accountAccessToken:h=null,accountRevision:p=0,accountViewResolving:x=!1,deviceId:g=null}={}){const f=!!(m&&h),b=f?"cloud":"local",k=c.useMemo(()=>ci({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[j,w]=c.useState([]),[S,T]=c.useState(null),[A,L]=c.useState("edge"),[P,N]=c.useState(!1),[v,D]=c.useState(null),R=ht(),O=Zt(a),F=!r,E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=rt([t,k.from,k.to,s,n,b,a,h,p,x,g,i,u,r,R,F,O,E]),K=c.useMemo(()=>{if(!o)return null;const V=Sr({timeZone:i,offsetMinutes:u});return`tokentracker.heatmap.${o}.${b}.${s}.${n}.${V}.${g||"all"}`},[o,g,b,i,u,s,n]),G=c.useCallback(()=>{if(!K||typeof window>"u")return null;try{const V=window.localStorage.getItem(K);if(!V)return null;const ie=JSON.parse(V);return!ie||!ie.heatmap?null:ie}catch{return null}},[K]),_=c.useCallback(V=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(V))}catch{}},[K]),$=c.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=c.useRef(b);c.useEffect(()=>{H.current!==b&&(H.current=b,w([]),T(null),L("edge"),D(null),N(!0))},[b]);const ae=c.useCallback(async()=>{const V=B(),ie=await Ue(a),le=f?await Ue(h):null;if(!V()||!ie&&!R&&!E&&!f)return;if(f&&!le){D("Your session expired. Please sign in again to view account data."),N(!1);return}const Se=f?le:ie,ve=f?di:ui,Me=f?Zs:Qs;N(!0),D(null);try{try{const ee=await ve({baseUrl:t,accessToken:Se,weeks:s,to:k.to,weekStartsOn:n,device:g,timeZone:i,tzOffsetMinutes:u}),re=Array.isArray(ee?.weeks)?ee.weeks:[];if(!V())return;if(!re.length&&F){const W=G();if(W?.heatmap){if(!V())return;T(W.heatmap),w(W.daily||[]),L("cache");return}}if(!re.some(W=>(Array.isArray(W)?W:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&re.length){const W=[];for(const X of re)for(const ue of Array.isArray(X)?X:[])ue?.day&&W.push({day:ue.day,total_tokens:ue.total_tokens??ue.value??0,billable_total_tokens:ue.billable_total_tokens??ue.value??ue.total_tokens??0});const Y=Qr({dailyRows:W,weeks:s,to:ee?.to||k.to,weekStartsOn:n});if(!V())return;w(W),T({...Y,week_starts_on:n,active_days:W.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ya({dailyRows:W,to:ee?.to||k.to})}),L("client"),F?_({heatmap:{...Y,week_starts_on:n,active_days:W.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ya({dailyRows:W,to:ee?.to||k.to})},daily:W,fetchedAt:new Date().toISOString()}):$();return}if(!V())return;T(ee||null),w([]),L("edge"),ee&&F?_({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):F||$();return}catch(ee){const re=ee,be=re?.status??re?.statusCode;if(be===401||be===403)throw ee}if(!V())return;const Q=await Me({baseUrl:t,accessToken:Se,from:k.from,to:k.to,device:g,timeZone:i,tzOffsetMinutes:u}),U=Array.isArray(Q?.data)?Q.data:[];if(!V())return;w(U);const ne=Qr({dailyRows:U,weeks:s,to:k.to,weekStartsOn:n});if(!V())return;T({...ne,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ya({dailyRows:U,to:k.to})}),L("client"),F?_({heatmap:{...ne,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ya({dailyRows:U,to:k.to})},daily:U,fetchedAt:new Date().toISOString()}):$()}catch(Q){if(!V())return;if(F){const U=G();if(U?.heatmap){if(!V())return;T(U.heatmap),w(U.daily||[]),L("cache"),D(null)}else{const ne=Q;D(ne?.message||String(ne)),w([]),T(null),L("edge")}}else{const U=Q;D(U?.message||String(U)),w([]),T(null),L("edge")}}finally{V()&&N(!1)}},[a,t,R,r,F,k.from,k.to,G,O,i,u,n,s,$,_,E,f,h,p,g,B]);return c.useEffect(()=>{if(x){N(!0);return}if(!O&&!r&&!R&&!E&&!f){w([]),N(!1),D(null),T(null),L("edge");return}if(!F)$(),w([]),D(null),T(null),L("edge");else{const V=G();V?.heatmap&&(T(V.heatmap),w(V.daily||[]),L("cache"))}ae()},[a,R,G,ae,O,r,F,$,E,x]),{range:k,daily:j,heatmap:S,source:R?"mock":A==="client"?"edge":A,loading:P,error:v,refresh:ae}}const Ql="tokentracker.dashboard.leftCardOrder.v1",Xl="tokentracker.dashboard.rightCardOrder.v1";function ec(t,a){const r=ns(Ql,t),s=ns(Xl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),o=c.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:o}}const tc=10;function ac({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i}={}){const[u,d]=c.useState([]),[m,h]=c.useState(!1),[p,x]=c.useState(null),g=ht(),f=Zt(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=rt([t,a,r,s,n,o,i]),j=c.useCallback(async()=>{const w=k(),S=await Ue(a);if(w()){if(!S&&!g&&!b){d([]),x(null),h(!1);return}h(!0),x(null);try{const T=await mi({baseUrl:t,accessToken:S,limit:tc,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i});if(!w())return;d(Array.isArray(T?.entries)?T.entries:[])}catch(T){if(!w())return;const A=T?.message||String(T);x(A),d([])}finally{w()&&h(!1)}}},[a,t,r,g,n,o,s,i,b,k]);return c.useEffect(()=>{if(!f&&!g&&!b){d([]),x(null),h(!1);return}d([]),x(null),h(!0),j()},[g,j,f,b]),{entries:u,loading:m,error:p,refresh:j}}const ds="tokentracker.usage-cache-index",us=24;function ms({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:o=!0,includeSummary:i=!0,cacheKey:u,timeZone:d,tzOffsetMinutes:m,now:h,accountView:p=!1,accountAccessToken:x=null,accountRevision:g=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(p&&x),j=k?"cloud":"local",[w,S]=c.useState([]),[T,A]=c.useState(null),[L,P]=c.useState(null),[N,v]=c.useState("edge"),[D,R]=c.useState(null),[O,F]=c.useState(!1),[E,B]=c.useState(null),K=ht(),G=Zt(a),_=!r&&!K,$=b||"all",H=(()=>{if(!u)return null;const Q=rc(t)||"default",U=o?i?"daily-summary":"daily-only":"summary",ne=Sr({timeZone:d,offsetMinutes:m});return`tokentracker.usage.${u}.${j}.${Q}.${s}.${n}.${U}.${ne}.${$}`})(),ae=c.useRef(j);c.useEffect(()=>{ae.current!==j&&(ae.current=j,S([]),A(null),P(null),v("edge"),R(null),B(null),F(!0))},[j]);const me=c.useCallback(()=>{if(!H||typeof window>"u")return null;try{const Q=window.localStorage.getItem(H);if(!Q)return null;const U=JSON.parse(Q),ne=i?!!U?.summary:Array.isArray(U?.daily);return!U||!ne?null:(os(ds,H,us),U)}catch{return null}},[i,H]),V=c.useCallback(Q=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(Q)),os(ds,H,us)}catch{}},[H]),ie=c.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),Se=rt([t,s,n,o,i,j,a,x,g,b,d,m,r,K,_,f,G,le]),ve=c.useCallback(async()=>{const Q=Se(),U=await Ue(a),ne=k?await Ue(x):null;if(!Q()||!U&&!K&&!le&&!k)return;if(k&&!ne){B("Your session expired. Please sign in again to view account data."),F(!1);return}const ee=k?Zs:Qs,re=k?hi:xi,be=k?ne:U;F(!0),B(null);try{let W=null,Y=null;if(o)if(i){const[he,C]=await Promise.allSettled([ee({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m}),re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0})]);if(he.status==="rejected")throw he.reason;W=he.value,Y=C.status==="fulfilled"?C.value:null}else W=await ee({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m});else i&&(Y=await re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0}));let X=o&&Array.isArray(W?.data)?W.data:[];o&&(X=rr(X,s,n,{timeZone:d,offsetMinutes:m,now:h}));let ue=i&&(Y?.totals||W?.summary?.totals)||null,Pe=i&&(Y?.rolling||W?.summary?.rolling)||null;if(i&&o&&!ue&&!Y)try{const he=await re({baseUrl:t,accessToken:be,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:m,rolling:!0});ue=he?.totals||null,Pe=he?.rolling||Pe}catch{}const Ae=new Date().toISOString();if(!Q())return;S(X),A(ue),P(Pe),v("edge"),R(Ae),(ue||!i&&o)&&_?V({summary:ue,rolling:Pe,daily:X,from:s,to:n,includeDaily:o,includeSummary:i,fetchedAt:Ae}):_||ie()}catch(W){if(!Q())return;if(_){const Y=me();if(Y?.summary||!i&&Array.isArray(Y?.daily)){A(Y.summary),P(Y.rolling||null);const X=Array.isArray(Y.daily)?Y.daily:[],ue=o?rr(X,Y.from||s,Y.to||n,{timeZone:d,offsetMinutes:m,now:h}):X;S(ue),v("cache"),R(Y.fetchedAt||null),B(null)}else{const X=W;B(X?.message||String(X)),S([]),A(null),P(null),v("edge"),R(null)}}else{const Y=W;B(Y?.message||String(Y)),S([]),A(null),P(null),v("edge"),R(null)}}finally{Q()&&F(!1)}},[a,t,s,o,i,K,r,_,h,me,G,d,n,m,ie,V,le,k,x,g,b,Se]);return c.useEffect(()=>{if(f){F(!0);return}const Q=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!G&&!r&&!K&&!Q&&!k){S([]),A(null),P(null),B(null),F(!1),v("edge"),R(null);return}if(!_)ie(),S([]),A(null),P(null),B(null),v("edge"),R(null);else{const U=me();if(U?.summary||!i&&Array.isArray(U?.daily)){A(U.summary),P(U.rolling||null);const ne=Array.isArray(U.daily)?U.daily:[],ee=o?rr(ne,U.from||s,U.to||n,{timeZone:d,offsetMinutes:m,now:h}):ne;S(ee),v("cache"),R(U.fetchedAt||null),B(null)}else S([]),A(null),P(null),v("edge"),R(null),B(null)}F(!0),ve()},[a,K,me,ve,G,r,_,ie,le,f,i]),c.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const Q=15e3;let U=Date.now();const ne=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-U<Q||(U=ee,ve())};return window.addEventListener("focus",ne),document.addEventListener("visibilitychange",ne),()=>{window.removeEventListener("focus",ne),document.removeEventListener("visibilitychange",ne)}},[ve]),{daily:w,summary:T,rolling:L,source:K?"mock":N,fetchedAt:D,loading:O,error:E,refresh:ve}}function rc(t){try{return new URL(t).host}catch{return null}}function ar(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 sc(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function rr(t,a,r,{timeZone:s,offsetMinutes:n,now:o}={}){const i=ar(a),u=ar(r);if(!i||!u||u<i)return Array.isArray(t)?t:[];const d=o instanceof Date&&Number.isFinite(o.getTime())?o:new Date,m=Cr({timeZone:s,offsetMinutes:n,date:d}),h=ar(m),p=h?h.getTime():d.getTime(),x=new Map;for(const f of t||[])f?.day&&x.set(f.day,f);const g=[];for(let f=i;f<=u;f=sc(f,1)){const b=Gt(f),k=x.get(b),j=f.getTime()>p;if(k){g.push({...k,missing:!1,future:j});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:!j,future:j})}return g}function nc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:o,timeZone:i,tzOffsetMinutes:u,accountView:d=!1,accountAccessToken:m=null,accountRevision:h=0,accountViewResolving:p=!1,deviceId:x=null}={}){const g=!!(d&&m),f=g?"cloud":"local",[b,k]=c.useState(null),[j,w]=c.useState("edge"),[S,T]=c.useState(!1),[A,L]=c.useState(null),P=ht(),N=Zt(a),v=!r,D=c.useMemo(()=>{if(!o)return null;const $=oc(t)||"default",H=Sr({timeZone:i,offsetMinutes:u});return`tokentracker.modelBreakdown.${o}.${f}.${$}.${s}.${n}.${H}.${x||"all"}`},[t,o,x,s,f,i,n,u]),R=c.useCallback(()=>{if(!D||typeof window>"u")return null;try{const $=window.localStorage.getItem(D);if(!$)return null;const H=JSON.parse($);return!H||!H.breakdown?null:H}catch{return null}},[D]),O=c.useCallback($=>{if(!(!D||typeof window>"u"))try{window.localStorage.setItem(D,JSON.stringify($))}catch{}},[D]),F=c.useCallback(()=>{if(!(!D||typeof window>"u"))try{window.localStorage.removeItem(D)}catch{}},[D]),E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=rt([t,s,n,f,a,m,h,x,i,u,r,P,v,p,N,E]),K=c.useRef(f);c.useEffect(()=>{K.current!==f&&(K.current=f,k(null),w("edge"),L(null),T(!0))},[f]);const G=c.useCallback(async()=>{const $=B(),H=await Ue(a),ae=g?await Ue(m):null;if(!$()||!H&&!P&&!E&&!g)return;if(g&&!ae){L("Your session expired. Please sign in again to view account data."),T(!1);return}const me=g?ae:H,V=g?gi:pi;T(!0),L(null);try{const ie=await V({baseUrl:t,accessToken:me,from:s,to:n,device:x,timeZone:i,tzOffsetMinutes:u});if(!$())return;k(ie||null),w("edge"),ie&&v?O({breakdown:ie,fetchedAt:new Date().toISOString()}):v||F()}catch(ie){if(!$())return;if(v){const le=R();if(le?.breakdown)k(le.breakdown),w("cache"),L(null);else{k(null),w("edge");const Se=ie;L(Se?.message||String(Se))}}else{k(null),w("edge");const le=ie;L(le?.message||String(le))}}finally{$()&&T(!1)}},[a,t,s,P,r,v,R,i,n,N,u,F,O,E,g,m,h,x,B]);return c.useEffect(()=>{if(p){T(!0);return}if(!N&&!r&&!P&&!E&&!g){k(null),w("edge"),L(null),T(!1);return}if(!v)F(),k(null),w("edge"),L(null);else{const $=R();$?.breakdown?(k($.breakdown),w("cache"),L(null)):(k(null),w("edge"),L(null))}T(!0),G()},[a,P,R,G,N,r,v,F,E,p]),{breakdown:b,source:P?"mock":j,loading:S,error:A,refresh:G}}function oc(t){try{return new URL(t).host}catch{return null}}const pn=new Set(["day","hour","month"]);function ic(t){return pn.has(t)}function hs(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 lc(t,a){const r=hs(t),s=hs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=te(t),o=te(a);return n==null&&o==null?0:n==null?1:o==null?-1:n===o?0:n<o?-1:1}function cc(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 dc(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 uc(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 mc(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]),u=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(u)||!Number.isFinite(d)||n<1||n>12||o<1||o>31||i<0||i>23||u<0||u>59||d<0||d>59)return null;const m=new Date(Date.UTC(s,n-1,o,i,u,d));return Number.isFinite(m.getTime())?m.getTime():null}function hc(t,a,r){const s=r==="hour"?mc:r==="month"?uc:dc,n=s(t),o=s(a);return n!=null&&o!=null?n===o?0:n<o?-1:1:cc(t,a)}function fn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],o=pn.has(a)?(u,d)=>hc(u,d,a):lc,i=u=>a==="total_tokens"&&u?.billable_total_tokens!=null?u.billable_total_tokens:u?.[a];return n.map((u,d)=>({row:u,index:d})).sort((u,d)=>{const m=i(u.row),h=i(d.row),p=m==null,x=h==null;if(p&&x)return u.index-d.index;if(p)return 1;if(x)return-1;const g=o(m,h);return g!==0?g*s:u.index-d.index}).map(u=>u.row)}function xc(){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 xs(t){const a=ic(t)?t:"day";return xc().map((r,s)=>s===0?{...r,key:a}:r)}function gs(t,{key:a,dir:r}){return fn(t,{key:a,dir:r})}const Ca=12,gc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function pc(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 fc(t){return gc.some(a=>pc(t?.[a]))}function yc(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=fn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&fc(n));return s===-1?a:r.slice(s)}function bc(t,a,r=Ca){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Ca,i=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(i,i+n)}function kc({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 ka=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function wc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ka.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ka.active:s<=60*6e4?ka.warm:ka.idle}const _c=3e4;function vc({refresh:t,intervalMs:a=_c,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let o=!1,i=null,u=Date.now(),d=0;const m=()=>{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},h=r.setInterval(()=>{const g=Date.now();g<d||(d=g+wc({visible:s.visibilityState==="visible",lastInteractionAt:u,now:g}),m())},a),p=()=>{s.visibilityState==="visible"&&(u=Date.now(),d=0,m())},x=()=>{u=Date.now()};return r.addEventListener("focus",p),r.addEventListener("pointerdown",x),r.addEventListener("keydown",x),s.addEventListener("visibilitychange",p),{run:m,stop(){o=!0,r.clearInterval(h),r.removeEventListener("focus",p),r.removeEventListener("pointerdown",x),r.removeEventListener("keydown",x),s.removeEventListener("visibilitychange",p)}}}function jc(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 Nc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=jc(s)||new Date,o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Gt(o),to:Gt(n)}}function Sc(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 Ar(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Cc(t){const a=Ar(t?.model_id);return a||null}function yn(t,a){return t?.model?String(t.model):a}function bn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",o=Ar(n);if(!o||o.includes("/"))continue;const i=Math.max(0,te(s?.weight)??0);(!a.has(o)||i>=(r.get(o)||0))&&(a.set(o,n),r.set(o,i))}return a}function kn(t,a){const r=Ar(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 Ct(t,a=0){const r=te(t?.billable_total_tokens),s=te(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Tc={deepseek:"dsh"};function Dc(t){const a=typeof t=="string"?t:"";return Tc[a]||a}const Ac=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"],wn=["input","output","cached","cacheCreate","reasoning"];function Lc(t){let a=0;for(const r of wn)a+=Math.max(0,Number(t?.[r])||0);return a}function Mc(t){return Lc(t?.tokens)>0}function ps(t,a){for(const r of Ac)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 fs(){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,total_cost_usd:"0"}}function Ec(t){const a=new Map;for(const r of t||[]){const s=Dc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:fs(),models:new Map},a.set(s,n)),ps(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 u=n.models.get(i);u||(u={...o,model:o?.model||i,model_id:i,totals:fs()},n.models.set(i,u)),ps(u.totals,o?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function Ic(t,{copyFn:a}={}){const r=typeof a=="function"?a:i=>i,n=Ec(Array.isArray(t?.sources)?t.sources:[]).map(i=>{const u=Ct(i?.totals),d=te(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(u)?u:0,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,te(i?.totals?.input_tokens)??0),cacheRead:Math.max(0,te(i?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,te(i?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!n.length)return[];const o=n.reduce((i,u)=>i+u.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((i,u)=>u.totalTokens-i.totalTokens).map(i=>{const u=i.source?String(i.source).toUpperCase():r("shared.placeholder.short"),d=o>0?i.totalTokens/o*100:0,m=Number.isFinite(d)?d.toFixed(2):"0.00",h=i.models.map(f=>{const b=Ct(f?.totals);if(!Number.isFinite(b)||b<=0)return null;const k=i.totalTokens>0?Math.round(b/i.totalTokens*1e3)/10:0,j=yn(f,r("shared.placeholder.short")),w=Cc(f),S=te(f?.totals?.total_cost_usd),T=S??(i.totalCost>0&&i.totalTokens>0?b/i.totalTokens*i.totalCost:null),A=f?.totals||{};return{id:w,name:j,share:k,usage:b,cost:T,tokens:{input:Math.max(0,te(A?.input_tokens)??0),output:Math.max(0,te(A?.output_tokens)??0),cached:Math.max(0,te(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,te(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,te(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:u,totalPercent:String(m),totalPercentValue:d,usd:i.totalCost,usage:i.totalTokens,cacheHitRate:g,cacheReusedTokens:i.cacheRead,cacheInputTokens:p,models:h}})}function Rc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const i of a){const u=Array.isArray(i?.models)?i.models:[];for(const d of u){const m=te(d?.usage);if(m==null||m<=0)continue;const h=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;h&&s.push({model:d,name:h,usage:m})}}const n=bn(s.map(i=>({name:i.name,weight:i.usage})));for(const{model:i,name:u,usage:d}of s){const m=kn(u,n);if(!m)continue;const{key:h}=m,p=r.get(h)||{id:h,name:m.name,usage:0,cost:0,hasCost:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0}};p.usage+=d;const x=i?.tokens||{};for(const f of wn)p.tokens[f]+=Math.max(0,Number(x[f])||0);const g=te(i?.cost);g!=null&&(p.cost+=g,p.hasCost=!0),n.has(h)?p.name=n.get(h):d>=p.nameWeight&&(p.name=u,p.nameWeight=d),r.set(h,p)}const o=Array.from(r.values()).reduce((i,u)=>i+u.usage,0);return Array.from(r.values()).map(i=>({id:i.id,name:i.name,usage:i.usage,cost:i.hasCost?i.cost:null,tokens:{...i.tokens},share:o>0?Math.round(i.usage/o*1e3)/10:0})).sort((i,u)=>u.usage!==i.usage?u.usage-i.usage:String(i.name).localeCompare(String(u.name)))}function Fc(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,u=new Map,d=[];let m=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const j=Ct(k?.totals);if(!Number.isFinite(j)||j<=0)continue;m+=j;const w=yn(k,s("shared.placeholder.short"));d.push({name:w,tokens:j})}}const h=bn(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=kn(f,h);if(!k)continue;const{key:j}=k;o.set(j,(o.get(j)||0)+b),h.has(j)?i.set(j,h.get(j)):b>=(u.get(j)||0)&&(u.set(j,b),i.set(j,f))}if(!o.size)return[];const p=Array.from(o.values()).reduce((f,b)=>f+b,0),x=m>0?m:p,g=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(o.entries()).map(([f,b])=>{const k=x>0?(b/x*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 $c(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 ys(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Yt(a);return(a===Xs?t:t*r)<.01?`<${s}0.01`:Qt(t,{decimals:2,currency:a,rate:r})}function bs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:$e(a,{decimals:1})}const Pc=jt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:o}=Aa(),i=c.useMemo(()=>(Array.isArray(s)?s:[]).map(m=>{const h=te(m?.usd)??0,p=te(m?.usage)??0,x=Array.isArray(m?.models)?m.models:[];return{label:m?.label?String(m.label):"",usdValue:h,costLabel:ys(h,n,o),tokensLabel:bs(p),models:x.map(g=>{const f=te(g?.usage)??0,b=te(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:bs(f),costLabel:ys(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(m=>m.usdValue>0||m.models.length>0).sort((m,h)=>h.usdValue-m.usdValue),[s,n,o]),u=i.some(m=>m.models.some(h=>h.costSource!=="provider_reported"&&h.pricing?.status==="unpriced")),d=c.useMemo(()=>{const m=i.reduce((h,p)=>h+p.usdValue,0);return u&&m===0?l("dashboard.cost_breakdown.unpriced_label"):`${u?"≥":""}${$c(m,n,o)}`},[i,n,o,u]);return e.jsx(cl,{open:a,onOpenChange:m=>{m||r?.()},children:e.jsxs(dl,{children:[e.jsx(ul,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(ml,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(hl,{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(xl,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(gl,{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(Tr,{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:u?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:d}),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((m,h)=>{const p=`fleet-${h}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":p,className:h>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:m.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:m.costLabel||"—"})]}),m.models.map((x,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:x.name,children:x.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:x.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):x.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),x.pricing?.status==="unpriced"&&x.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,x.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,x.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:$e(Number(x.tokens.input)||0),output:$e(Number(x.tokens.output)||0),read:$e(Number(x.tokens.cached)||0),write:$e(Number(x.tokens.cacheCreate)||0)})}):null,x.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:x.pricing.input,output:x.pricing.output,read:x.pricing.cache_read,write:x.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:x.costLabel||(x.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):x.pricing?.status==="free"?Qt(0,{currency:n,rate:o}):l("dashboard.cost_breakdown.rate_unknown"))})]},x.id||`${x.name}-${g}`))]},`${m.label}-${h}`)})]})]})})]})})]})})});function Bc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[o,i]=c.useState(null),[u,d]=c.useState(!1),[m,h]=c.useState(null),p=ht(),x=rt([t,a,r,s,n,p]);return c.useEffect(()=>{const g=x();if(!t){i(null),h(null),d(!1);return}d(!0),i(null),h(null),fi({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{g()&&i(f||null)}).catch(f=>{g()&&(h(f?.message||String(f)),i(null))}).finally(()=>{g()&&d(!1)})},[t,a,r,s,n,p,x]),{data:o,loading:u,error:m}}function _n(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 vn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function jn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function Nn(t,a){return a&&jn(vn(t))==="github"?a:""}function Sn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=c.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 ks="#10b981",sr=[{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"}],nr=60;function zc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(x=>[x.day,x]));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 u=t[t.length-1].day;i<u&&(i=u);const d=new Date(`${o}T00:00:00Z`),m=new Date(`${i}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(m.getTime()))return t;const h=Math.round((m.getTime()-d.getTime())/864e5)+1;h>nr&&d.setUTCDate(d.getUTCDate()+(h-nr));const p=[];for(;d.getTime()<=m.getTime()&&p.length<nr;){const x=d.toISOString().slice(0,10);p.push(n.get(x)||{day:x,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return p}function or(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 Oc({host:t}){if(!t)return null;let a;const r=jn(t);return r==="github"||r==="gitlab"?a=e.jsx(Tt,{provider:r,size:12,className:"fill-current"}):a=e.jsx(Il,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function ir({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 Uc({entry:t,query:a={},onClose:r}){const[s,n]=jt.useState(!1),o=typeof t?.project_key=="string"?t.project_key:"",{owner:i,repo:u}=_n(o),d=typeof t?.project_ref=="string"?t.project_ref:"",m=vn(d),{data:h,loading:p,error:x}=Bc({projectKey:o,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:g,formatTokensTooltip:f}=De(),b=jt.useCallback(()=>n(!0),[]),k=E=>{E.target===E.currentTarget&&s&&r()};jt.useEffect(()=>{const E=B=>{B.key==="Escape"&&b()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[b]);const j=h?.totals||null,w=te(j?.billable_total_tokens)??0,S=Number(h?.days_active||0),T=te(j?.input_tokens)??0,A=te(j?.cached_input_tokens)??0,L=T+A>0?A/(T+A):null,P=te(h?.range_total_tokens)??0,N=te(j?.total_tokens)??0,v=P>0?N/P:null,D=jt.useMemo(()=>zc(h?.daily,h?.from,h?.to,Cr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[h,a.timeZone,a.tzOffsetMinutes]),R=sr.reduce((E,B)=>E+(te(j?.[B.key])??0),0),O=Array.isArray(h?.sources)?h.sources:[],F=!p&&!x&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:E=>{E.target===E.currentTarget&&b()},className:St("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:St("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(Tr,{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:ks}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:ks}})]}),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(Sn,{githubOwner:Nn(d,i),letter:(u?.[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:u||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(Oc,{host:m}),m&&h?.from&&h?.to?e.jsx("span",{children:"·"}):null,h?.from&&h?.to?e.jsxs("span",{className:"tabular-nums",children:[h.from," – ",h.to]}):null]})]}),F?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:v==null?"—":or(v)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:L==null?"—":or(L)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_conversations"),value:Sa(j.conversation_count)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_active_days"),value:Sa(S)}),e.jsx(vt,{label:l("dashboard.projects.detail.stat_avg_day"),value:S>0?g(Math.round(w/S)):"—"})]}):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&&x&&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&&!x&&!F&&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")}),F&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[D.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(sn,{embedded:!0,rows:D,from:D[0]?.day,to:D[D.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),R>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:sr.map(E=>{const B=te(j[E.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/R*100}%`,backgroundColor:E.color,minWidth:"2px"}},E.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:sr.map(E=>{const B=te(j[E.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:E.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(E.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(B),children:g(B)})]},E.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(ir,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(E=>{const B=Number(E.total_tokens||0),K=N>0?B/N:0,G=K*100,_=Number(E.conversation_count||0),$=qi(E.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Tt,{provider:E.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:Nt(E.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(E.days_active||0)}),_>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:_})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(B),children:g(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:or(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(G,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:$}})})]},E.source)})})]})]})]})]})})}function Hc(t){return e.jsx(yi,{mode:qt.COMPACT,children:e.jsx(Uc,{...t})})}const Kc=5;function Vc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:o}){const i=typeof t?.project_key=="string"?t.project_key:"",u=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:m}=_n(i),h=Nn(u,d),p=te(t?.billable_total_tokens??t?.total_tokens)??0,x=a>0?Math.min(100,Math.max(2,p/a*100)):0,g=Array.isArray(t?.sources)?t.sources:[],f=g.slice(0,Kc),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(Sn,{githubOwner:h,letter:(m?.[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:[d?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[d,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:m||i||"—"})]}),f.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[f.map(k=>e.jsx(Tt,{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:`${x}%`,minWidth:p>0?"3px":0}})})]})]})}function Wc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:o,dailyEmptyPrefix:i,installSyncCmd:u,dailyEmptySuffix:d,detailsColumns:m,ariaSortFor:h,toggleSort:p,sortIconFor:x,pagedDetails:g,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:w="day",detailsDateKey:S,renderDetailDate:T,renderDailyBreakdownDate:A,renderDetailCell:L,DETAILS_PAGED_PERIODS:P,period:N,detailsPageCount:v,detailsPage:D,setDetailsPage:R}){const[O,F]=c.useState("daily"),[E,B]=c.useState(null),{formatTokens:K,formatTokensTooltip:G}=De();return e.jsxs(Le,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="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":O==="daily",type:"button",onClick:()=>F("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="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":O==="projects",type:"button",onClick:()=>F("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="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")})]}),O==="projects"&&e.jsx(on,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:_=>r?.(Number(_)),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"})]}),O==="projects"&&(()=>{const _=t.slice(0,a);if(_.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 $=_.reduce((H,ae)=>{const me=te(ae?.billable_total_tokens??ae?.total_tokens)??0;return me>H?me:H},0);return e.jsx("div",{className:"space-y-1",children:_.map((H,ae)=>e.jsx(Vc,{entry:H,maxTokens:$,copy:n,formatTokens:K,formatTokensTooltip:G,onSelect:B},H?.project_key||H?.project_ref||`entry-${ae}`))})})(),E&&e.jsx(Hc,{entry:E,query:s,onClose:()=>B(null)}),O==="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:u}),d]}):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(_=>e.jsx("th",{"aria-sort":k?.(_.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>p(_.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:_.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(_.key)||""})]})})},_.key))})}),e.jsx("tbody",{children:f.map(_=>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 ${_.missing?"text-oai-gray-400 dark:text-oai-gray-400":_.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:A?A(_):T(_)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:L(_,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:L(_,"conversation_count")})]},String(_?.[w]||_?.day||_?.hour||_?.month||"")))})]})}),O!=="daily"&&P.has(N)&&v>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>R(_=>Math.max(0,_-1)),disabled:D===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:[D+1," / ",v]}),e.jsx("button",{type:"button",onClick:()=>R(_=>Math.min(v-1,_+1)),disabled:D+1>=v,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 Na(t){return typeof t!="string"?"":t.trim()}function ws(t){const a=Na(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function qc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Na(r.tool),n=Na(r.planType)||Na(r.plan_type);if(!s||!n)continue;const o=ws(s)||s,i=ws(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:o,plan:i})}return Array.from(a.values())}function Gc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:o=[],className:i=""}){const{formatTokensTooltip:u}=De(),d=l("shared.placeholder.short"),m=l("shared.unit.percent"),h=t??l("identity_card.rank_placeholder"),p=Number.isFinite(Number(a))?Number(a):0,x=p?l("identity_card.streak_value",{days:p}):l("identity_card.rank_placeholder"),g=qc(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 d;const S=$e(w,f);return S==="-"?d:S},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=o.slice(0,3);return e.jsxs(Le,{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:u(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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:u(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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:u(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children: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})]})]}),j.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:j.map((w,S)=>{const T=w?.name?String(w.name):d,A=w?.percent?String(w.percent):"",L=S===j.length-1,P=S+1;return e.jsxs("div",{className:`flex items-center py-2 ${L?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:P}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:T,children:T}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[A,m]})]},w.id||T)})}),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,S)=>e.jsxs(Ul,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${S}`))}),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:h})]}),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:x})]})]})]})}let wa=null;function Yc(){if(wa===null)try{wa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{wa=!1}return wa}function Jc(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,u=t-.1055613458*n-.0638541728*o,d=t-.0894841775*n-1.291485548*o,m=i*i*i,h=u*u*u,p=d*d*d;return[4.0767416621*m-3.3077115913*h+.2309699292*p,-1.2684380046*m+2.6097574011*h-.3413193965*p,-.0041960863*m-.7034186147*h+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 Cn(t,a,r,s){if(Yc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,o,i]=Jc(t,a,r);return s==null?`rgb(${n} ${o} ${i})`:`rgb(${n} ${o} ${i} / ${s})`}function At(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Cn(Number(a[1]),Number(a[2]),Number(a[3])):t}const _s={claude:35,codex:250,grok:200},vs={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 Zc(t,a){const r=_s[a]??_s.claude,s=vs[t]||vs.system_prompt;return Cn(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"]}],Xc=[["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"]],ed={duration:.18,ease:[.4,0,.2,1]},td={height:0,opacity:0},ad={height:"auto",opacity:1},rd={height:0,opacity:0};function sd(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function nd(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 Tn(t,a=null){const r=t.reduce((i,u)=>i+Number(u.totals.total_tokens||0),0),s=sd(a),n=s||r,o=s&&r>0?s/r:1;return t.map(i=>{const u=o===1?i.totals:nd(i.totals,o);return{...i,totals:u,percent:n>0?Number((u.total_tokens/n*100).toFixed(2)):0}}).sort((i,u)=>u.totals.total_tokens-i.totals.total_tokens)}function od(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 u=r.get(i);if(!u)continue;const d=u.totals||{};o.input_tokens+=d.input_tokens||0,o.cached_input_tokens+=d.cached_input_tokens||0,o.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,o.output_tokens+=d.output_tokens||0,o.reasoning_output_tokens+=d.reasoning_output_tokens||0,o.total_tokens+=d.total_tokens||0}return{key:n.key,totals:o}});return Tn(s,a)}function id(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((m,h)=>h?.name==="Text Response"?m:m+Number(h?.totals?.total_tokens||0),0),o=Number(r.total_tokens||0),i=Math.min(Math.max(0,n),Math.max(0,o-s)),d=[{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 Tn(d,a)}const js="MCP: ";function ld(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(js)?(a.push({...n,name:o.slice(js.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 Ns(t){return l(`dashboard.context_breakdown.category.${t}`)}function cd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function dd(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),u=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:cd(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(u||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function ud(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),u=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:o,cached_input_tokens:i,cache_creation_input_tokens:u,total_tokens:Number(r.total_tokens||n+o)},tools:dd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function md(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 hd(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 xd(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 gd(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 Ss(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 pd(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 Cs(t){return t==="exec_command"||t==="Bash"}function Dn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function fd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function yd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const bd=10;function Qe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:o=!1,open:i=!1,onToggle:u,tokens:d,percent:m=null,children:h,share:p=null,fillColor:x=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:bd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:g,children:r}),s,o&&e.jsx(pe.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(ki,{size:11})})]}),k=x&&p!=null&&p>0,j=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, ${x.replace(/\)\s*$/," / 0.10)")} 0%, ${x.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[o?e.jsx("button",{type:"button",onClick:u,"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:d||""}),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:m||""})]}),o&&h?e.jsx(Dt,{initial:!1,children:i&&e.jsx(pe.div,{initial:td,animate:ad,exit:rd,transition:ed,style:{overflow:"hidden"},children:h},"content")}):null]})}function Ts({execDetails:t,source:a="claude"}){const{formatTokens:r}=De(),[s,n]=c.useState("by_type"),o=gd(pd(t,s)),i=a==="codex"||a==="grok",u=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:Xc.map(([d,m])=>e.jsx("button",{type:"button",onClick:()=>n(d),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===d?"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(m)},d))}),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 ${u} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),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((d,m)=>e.jsxs(pe.div,{role:"row",className:`grid ${u} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:m*.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:d.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:$e(d.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:$e(d.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:Ss(d.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:Ss(d.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(d.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:$e(d.output_lines||0)})]},d.name))]})})]})}function Kt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=De(),[o,i]=c.useState({}),[u,d]=c.useState(!1),m=ud(t?.categories||[]);function h(p){i(x=>({...x,[p]:!x[p]}))}return m.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(Dn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:m.map(p=>{const x=p.toolCount>0,g=p.name==="Execution"&&a,f=g&&p.tools.some(k=>Cs(k.name)),b=!!o[p.name];return e.jsxs(Qe,{level:1,label:p.name,labelTone:"strong",hasChevron:x||g&&!f,open:b||g&&!f&&u,onToggle:()=>{x?h(p.name):g&&!f&&d(k=>!k)},tokens:n(p.totals.total_tokens||0),percent:null,children:[x&&e.jsx("ul",{className:"space-y-0.5",children:p.tools.map(k=>{const j=g&&Cs(k.name);return e.jsx(Qe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:u,onToggle:()=>d(w=>!w),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(Ts,{execDetails:a,source:r})},k.name)})}),g&&!f&&e.jsx(Ts,{execDetails:a,source:r})]},p.name)})})}function kd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:o}=De(),[i,u]=c.useState(null),[d,m]=c.useState(!1),[h,p]=c.useState(null),[x,g]=c.useState({}),f=c.useRef({});function b(_){g($=>({...$,[_]:!$[_]}))}if(c.useEffect(()=>{let _=!1;const $=`${t||""}|${a||""}|${r||"claude"}`,H=f.current[$];return u(H||null),m(!0),n?.(!0),p(null),bi({from:t,to:a,source:r,timeZone:tn(),tzOffsetMinutes:en()}).then(ae=>{_||(f.current[$]=ae,u(ae))}).catch(ae=>{_||p(ae?.message||String(ae))}).finally(()=>{_||(m(!1),n?.(!1))}),()=>{_=!0}},[t,a,r]),d&&!i)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(_=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${_*80}ms`}},_))}),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(h)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(fd(r))});if(!i||i.scope!=="supported"||!i.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(Dn(r))});const k=r==="claude"?od(i.categories||[],s):id(i,s),j=i.tool_calls_breakdown||null,w=i.skills_breakdown||null,S=i.message_breakdown||null,T=i.configured_resources||null,A=i.exec_command_breakdown||null,L=hd(w?.skills||[]),P=md(S?.categories||[]),N=r==="codex"&&(i?.breakdown_status==="queue_fallback"||i?.fallback==="queue_totals"),v=r==="claude"?j?.tool_calls||null:j||null,{mcpSet:D,residualSet:R,mcpTotalTokens:O}=ld(v),F=r==="claude"&&j?.subagents||null,E=F?.categories?.length>0||(T?.custom_agents_count||0)>0,B=r==="claude"?(R?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,K=r==="claude"?(F?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,G=[...k].sort((_,$)=>($.totals?.total_tokens||0)-(_.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:k.filter(_=>_.percent>0).filter(_=>!(r==="claude"&&(_.key==="tool_calls"||_.key==="custom_agents"))).map(_=>`${Ns(_.key)} ${_.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[G.map(_=>{const $=_.key==="system_prompt",H=_.key==="messages",ae=_.key==="tool_calls",me=_.key==="custom_agents";if(_.key,r==="claude"&&(ae||me))return null;const V=H&&P.length>0||ae&&(R?.categories?.length>0||N)||me&&E&&F,ie=!!x[_.key],le=Zc(_.key,r),Se=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:le},"aria-hidden":"true"}),ve=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(dn,{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,Me=_.percent>0?`${_.percent.toFixed(_.percent<.1&&_.percent>0?2:1)}%`:"0.0%";return e.jsxs(Qe,{level:0,colorSquare:Se,label:Ns(_.key),labelSuffix:ve,tokens:o(_.totals?.total_tokens||0),percent:Me,hasChevron:V,open:ie,onToggle:()=>b(_.key),share:_.percent,fillColor:le,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:P.map(Q=>e.jsx(Qe,{level:1,label:xd(Q),tokens:o(Q.totals.total_tokens||0),percent:null},Q.key||Q.name))}),ae&&R&&e.jsx(Kt,{toolSet:R,execDetails:A,source:r,codexQueueFallback:N}),ae&&N&&!R&&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")}),me&&F&&e.jsx(Kt,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})]},_.key)}),r==="claude"&&R?.categories?.length>0&&e.jsx(Qe,{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:o(B),percent:null,hasChevron:!0,open:!!x.tool_calls_aux,onToggle:()=>b("tool_calls_aux"),children:e.jsx(Kt,{toolSet:R,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&F?.categories?.length>0&&e.jsx(Qe,{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:o(K),percent:null,hasChevron:!0,open:!!x.custom_agents_aux,onToggle:()=>b("custom_agents_aux"),children:e.jsx(Kt,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})}),D?.categories?.length>0&&e.jsx(Qe,{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:o(O),percent:null,hasChevron:!0,open:!!x.mcp_servers,onToggle:()=>b("mcp_servers"),children:e.jsx(Kt,{toolSet:D,execDetails:null,source:r,codexQueueFallback:!1})}),L.length>0&&e.jsx(Qe,{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:o(L.reduce((_,$)=>_+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!x.skills,onToggle:()=>b("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:L.slice(0,12).map(_=>e.jsx(Qe,{level:1,label:_.name,tokens:o(_.total_tokens),percent:null},_.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(yd(r))}),N?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,T?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[$e(T.skills_count||0)," skills ·"," ",$e(T.mcp_servers_count||0)," MCP servers ·"," ",$e(T.custom_agents_count||0)," agents ·"," ",$e(T.memory_files_count||0)," memory files"]}):null]})}function An({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 it="__all__",wd=`${100 .toFixed(2)}%`;function Jt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function br(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Yt(a);return(a===Xs?s:s*r)<.01?`<${n}0.01`:Qt(s,{decimals:2,currency:a,rate:r})}function _d(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Ds(a)}:{key:a.key,label:a.label||Ds(a.key)}):[]}function vd(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 jd={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 lr(t,a){const r=t?.toUpperCase?.()||"";return jd[r]||`hsl(${150+a*40}, 60%, 45%)`}function Nd(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 Sd(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 Cd(t){return!!t?.models?.length}function Ln(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function cr(t){const a=Ln(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const Td={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Ds(t){const a=Td[t];return a?l(a):String(t).toUpperCase()}function Dd({loading:t,onClick:a}){const r=Xt();return e.jsx(_i,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(pe.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(vi,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function Ad(){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 Ld(){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 Md({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:o,summaryLabel:i,summaryCostValue:u,onCostInfo:d,fleetData:m=[],onRefresh:h,loading:p,announceLoading:x=!1,summaryLoading:g=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:w,onCustomRangeApply:S,customRangeOpen:T,onCustomRangeOpenChange:A,onOpenShare:L,from:P,to:N,deviceOptions:v=[],selectedDevice:D="",onDeviceChange:R}){const O=_d(a),F=fl(ji()),E=vd(String(s??"")),B=t==="week"&&typeof P=="string"&&typeof N=="string"&&P.slice(0,7)!==N.slice(0,7),K=P&&N?`${ba(P,F)} — ${ba(N,F)}`:null,G=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[_,$]=c.useState(G);c.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const C=window.matchMedia("(max-width: 639px)"),J=z=>$(z.matches);return C.addEventListener("change",J),()=>C.removeEventListener("change",J)},[]);const H=E!=null&&!_,ae=c.useRef(null);c.useEffect(()=>{const C=ae.current?.querySelector('[aria-selected="true"]');C&&typeof C.scrollIntoView=="function"&&C.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[me,V]=c.useState(null),{resolvedTheme:ie}=wi(),{currency:le,rate:Se}=Aa(),{formatTokens:ve}=De(),Me=ie==="dark",Q=Me?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Me?"rgba(10,10,10,0)":"rgba(255,255,255,0)",ne=g&&!b,ee=f&&!m.some(Cd);c.useEffect(()=>{V(null)},[t,P,N,D]);const re=C=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(C.key))return;const J=Array.from(C.currentTarget.querySelectorAll('[role="tab"]')).filter(xe=>!xe.disabled),z=J.indexOf(C.target.closest('[role="tab"]'));if(z===-1||J.length===0)return;C.preventDefault();let se=z;C.key==="Home"?se=0:C.key==="End"?se=J.length-1:C.key==="ArrowRight"?se=(z+1)%J.length:se=(z-1+J.length)%J.length,J[se].focus(),J[se].click()},be=H?e.jsx(Jl,{value:E,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Me?0:8,gradientFrom:Q,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,W=m.filter(C=>C.models?.length>0),Y=W.some(C=>String(C?.source||C?.label||"").trim().toLowerCase()==="devin"),X=W.some(C=>String(C?.source||C?.label||"").trim().toLowerCase()==="trae"),ue=c.useMemo(()=>Rc(m),[m]),Pe=ue.reduce((C,J)=>C+(Number(J.usage)||0),0),Ae=W.reduce((C,J)=>C+(Number(J.usd)||0),0),he=me==null?null:me===it||W.some(function(J){return J.label===me})?me:null;return e.jsx(Le,{className:k,children:e.jsxs("div",{"aria-busy":p||ne||ee,children:[x?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:ae,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:re,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(C=>{const J=t===C.key,z=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${J?"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(C.key==="custom"){const se=J&&j&&w?`${ba(j,F)} — ${ba(w,F)}`:C.label;return e.jsxs(bl,{open:T,onOpenChange:xe=>{xe?r?.("custom"):A?.(xe)},children:[e.jsx(kl,{render:e.jsx("button",{role:"tab","aria-selected":J,tabIndex:J?0:-1,type:"button",className:z}),children:se}),e.jsx(wl,{children:e.jsx(_l,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(vl,{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(pl,{from:j,to:w,onApply:S,onCancel:()=>A?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":J,tabIndex:J?0:-1,type:"button",className:z,onClick:()=>r?.(C.key),children:C.label},C.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[v.length>1?e.jsx(on,{value:D,onValueChange:R,options:v,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,L?e.jsxs("button",{type:"button",onClick:L,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Fl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,h&&e.jsx(Dd,{loading:p,onClick:h})]})]}),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:ne?"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:be}):e.jsx("span",{title:n||void 0,children:be})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${ne?"":"hidden"}`,children:e.jsx(Ad,{})})]}),u&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:d?e.jsxs("button",{type:"button",onClick:d,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[u,e.jsx(dn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:u})}),X&&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")]}),K?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:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(Ld,{})}),W.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:W.map(C=>l("usage.overview.distribution_item",{label:Nt(C.label),percent:cr(C)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:W.map((C,J)=>{const z=lr(C.label,J),se=Nt(C.label),xe=cr(C);return e.jsx(pe.div,{initial:{width:0},animate:{width:`${Ln(C)}%`},transition:{duration:.5,delay:.45+J*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:z},title:`${se}: ${xe}%`},C.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":he===it,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:Jt(ve,Pe)||String(0),cost:br(Ae,le,Se)||`${Yt(le)}0`,count:ue.length}),onClick:()=>V(he===it?null:it),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${he===it?"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(An,{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:wd}),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:ue.length})})]}),W.map((C,J)=>{const z=lr(C.label,J),se=he===C.label,xe=Nt(C.label),ke=cr(C);return e.jsxs("button",{"aria-expanded":se,"aria-controls":`provider-details-${C.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:xe,percent:ke,tokens:Jt(ve,C.usage)||String(0),cost:br(C.usd,le,Se)||`${Yt(le)}0`,action:l(se?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>V(se?null:C.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${se?"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(Tt,{provider:C.label,size:15,color:z,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:xe,children:xe})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[ke,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:C.models.length})})]},C.label)})]}),he===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Y&&e.jsx(En,{}),e.jsx(Fd,{models:ue})]}),he!=null&&he!==it&&e.jsx("div",{id:`provider-details-${he}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:he}),className:"mt-2",children:W.filter(C=>C.label===he).map(C=>{const J=lr(C.label,0),z=Nd(C),se=[...C.models].sort((ke,st)=>(st.share||0)-(ke.share||0)),xe=z?Sd(z):Nt(C.label);return e.jsx($d,{provider:C,color:J,providerHeading:xe,contextSource:z,from:P,to:N,sortedModels:se},C.label)})})]})]})})}const Ed=[{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"}],Id="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(7rem,max-content)]";function Rd({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=De();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:Ed.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 As({model:t,tokensLabel:a,costLabel:r,expandable:s,isExpanded:n}){const{formatTokensTooltip:o}=De();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 text-right whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",s&&e.jsx("span",{className:"ml-1 align-middle text-[11px] font-normal text-oai-gray-400 dark:text-oai-gray-500",children:l(n?"usage.overview.collapse":"usage.overview.expand")})]})]})}function Mn({models:t,color:a}){const{currency:r,rate:s}=Aa(),{formatTokens:n}=De(),[o,i]=c.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(u=>{const d=Jt(n,u.usage),m=br(u.cost,r,s),h=Math.max(0,Math.min(100,Number(u.share)||0)),p=u.id||u.name,x=Mc(u),g=x&&o===p,f=Id,b={model:u,tokensLabel:d,costLabel:m,expandable:x,isExpanded:g};return e.jsxs("div",{"data-model-rank-row":!0,children:[x?e.jsx("button",{type:"button",onClick:()=>i(g?null:p),"aria-expanded":g,className:`${f} w-full cursor-pointer text-left`,children:e.jsx(As,{...b})}):e.jsx("div",{className:f,children:e.jsx(As,{...b})}),g&&e.jsx(Rd,{tokens:u.tokens}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":h,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${h}%`,backgroundColor:a,opacity:.45}})})]},p)})})}function Fd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(An,{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(Mn,{models:t,color:"var(--oai-blue)"})]})}function En(){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 $d({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:o,sortedModels:i}){const{formatTokens:u}=De(),[d,m]=c.useState(!1),h=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",p=String(t?.source||t?.label||"").trim().toLowerCase()==="devin";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Tt,{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&&d&&e.jsx(yl,{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(u,t.cacheReusedTokens)||String(0),input:Jt(u,t.cacheInputTokens)||String(0)})]}),h&&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")]}),p&&e.jsx(En,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(kd,{from:n,to:o,source:s,referenceTotalTokens:t.usage,onLoadingChange:m})}):null,e.jsx(Mn,{models:i,color:a})]})}function Pd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:o,transform:i,transition:u,isDragging:d}=el({id:t}),m=c.useRef(null),h=c.useRef(null);c.useLayoutEffect(()=>{if(!r)return;const x=m.current?m.current.childNodes.length===0:!0;h.current!==x&&(h.current=x,r(t,x))});const p={transform:tl.Transform.toString(i)||void 0,transition:u,zIndex:d?20:void 0};return e.jsxs("div",{ref:o,style:p,className:St("group/sortable relative has-[[data-sortable-body]:empty]:hidden",d&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:St("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",d&&"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:m,"data-sortable-body":!0,className:St("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)]",d&&"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 Bd({todayTokens:t=0,isSyncing:a=!1,hasError:r=!1,isDisconnected:s=!1}={}){return c.useMemo(()=>r?"error":s?"disconnected":a?"working-typing":t===0?"sleeping":t<5e4?"idle-living":t<2e5?"idle-look":t<5e5?"working-ultrathink":t<2e6?"working-typing":"working-ultrathink",[t,a,r,s])}const Ls="macAppBannerDismissed",zd="leaderboardBannerDismissed",Od="https://github.com/xiufengsun/TokenTracker/releases/latest",Ms="tokentracker_native_app",Vt=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Ms,"1"),!0):localStorage.getItem(Ms)==="1"}catch{return!1}})();function Ud({todayTokens:t=0,isSyncing:a=!1,enterDelay:r=0}){const{openLoginModal:s}=Ni(),{signedIn:n}=an(),o=Bd({todayTokens:t,isSyncing:a}),i=Vt?zd:Ls,[u,d]=c.useState(()=>{try{return localStorage.getItem(i)==="1"?!0:!Vt&&new URLSearchParams(window.location.search).get("from")==="menubar"?(localStorage.setItem(Ls,"1"),!0):!1}catch{return!1}}),m=c.useCallback(()=>{d(!0);try{localStorage.setItem(i,"1")}catch{}},[i]);if(u||!Vt&&Da())return null;let h,p,x,g,f,b;Vt&&n?(h="View the Leaderboard",p="Compare your usage globally",x="Leaderboard",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M2 8.5V10h8V8.5M6 1.5v6m0 0L3.5 5M6 7.5l2.5-2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(180 6 6)"})}),f=()=>{window.location.pathname="/leaderboard"}):Vt?(h="Join the Leaderboard",p="Log in to compare your usage with others",x="Log In",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6.5 1.5h3a1 1 0 011 1v7a1 1 0 01-1 1h-3M5 8.5L7.5 6 5 3.5M7.5 6H1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),f=s):(h="Try the Menu Bar App",p="Always-on stats with Clawd companion",x="Download",g=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6 2v6m0 0L3.5 5.5M6 8l2.5-2.5M2 10h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),b=Od);const k=b?pe.a:pe.button,j=b?{href:b,target:"_blank",rel:"noopener noreferrer"}:{onClick:f};return e.jsx(pe.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:r,ease:[.16,1,.3,1]},className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(un,{state:o,size:56})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-900 dark:text-oai-white",children:h}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-0.5",children:p})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(k,{...j,whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[x,g]}),e.jsx("button",{onClick:m,className:"p-1 text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-300 transition-colors","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})})]})]})})}const Es="widgetOnboardingDismissed",Is="tokentracker_native_app",Hd=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Is,"1"),!0):localStorage.getItem(Is)==="1"}catch{return!1}})();function Kd({enterDelay:t=0}){const[a,r]=c.useState(()=>{try{return localStorage.getItem(Es)==="1"}catch{return!1}}),s=c.useCallback(()=>{r(!0);try{localStorage.setItem(Es,"1")}catch{}},[]);return!Hd||rn()?null:e.jsx(Dt,{initial:!1,children:!a&&e.jsxs(pe.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-8,transition:{duration:.2,ease:[.4,0,.2,1]}},transition:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:s,"aria-label":l("dashboard.widgets.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"rounded-lg overflow-hidden ring-1 ring-black/5 dark:ring-white/10 shadow-sm",children:e.jsx("img",{src:"/widgets-overview.png",alt:l("dashboard.widgets.title"),width:734,height:552,className:"w-full h-auto block",loading:"lazy",decoding:"async"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.widgets.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.widgets.hint")})]})]},"widget-onboarding-card")})}const Lr="islandOnboardingDismissed";function Vd(){try{return localStorage.getItem(Lr)==="1"}catch{return!1}}function Rs(){try{localStorage.setItem(Lr,"1")}catch{}}function Wd(){try{localStorage.removeItem(Lr)}catch{}}function In({className:t}){return e.jsxs("svg",{viewBox:"0 6 15 9",fill:"currentColor","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"2",y:"6",width:"11",height:"7"}),e.jsx("rect",{x:"0",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"13",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"3",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"5",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"9",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"11",y:"13",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"4",y:"8",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"10",y:"8",width:"1",height:"2"})]})}function qd({reduceMotion:t}){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-950 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 -top-12 h-36 w-56 rounded-full bg-indigo-600/25 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-2 h-32 w-48 rounded-full bg-sky-500/15 blur-3xl"}),e.jsx("div",{className:"absolute bottom-[-3rem] left-1/3 h-32 w-64 rounded-full bg-fuchsia-500/10 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[16px] items-center justify-between bg-black/45 px-2.5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-white/60"}),e.jsx("span",{className:"h-[3px] w-5 rounded-full bg-white/30"}),e.jsx("span",{className:"h-[3px] w-3.5 rounded-full bg-white/20"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-3 rounded-full bg-white/20"}),e.jsx("span",{className:"h-[3px] w-4 rounded-full bg-white/35"})]})]}),e.jsxs(pe.div,{className:"absolute left-1/2 top-0 flex h-[22px] -translate-x-1/2 items-center rounded-b-[10px] bg-black pl-2 pr-2.5 shadow-lg shadow-black/60 ring-1 ring-white/[0.06]",animate:t?void 0:{opacity:[1,.94,1]},transition:t?void 0:{duration:3.2,repeat:1/0,ease:"easeInOut"},children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(In,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),"8.2M"]}),e.jsx("span",{className:"mx-2 h-2.5 w-7 rounded-[2px] bg-black"}),e.jsx("span",{className:"text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:"$12.40"})]})]})}function Gd({enterDelay:t=0}){const{available:a,settings:r,setSetting:s}=Nl(),[n,o]=c.useState(Vd),[i,u]=c.useState(!1),d=Xt(),m=c.useCallback(()=>{o(!0),Rs()},[]),h=c.useCallback(()=>{if(!a){try{window.location.href="tokentracker://open"}catch{}return}s("dynamicIslandEnabled",!0),i&&s("hideMenuBarIcon",!0),Rs(),o(!0),Si({title:l("dashboard.island.enabled_toast"),data:{onUndo:()=>{s("hideMenuBarIcon",!1),s("dynamicIslandEnabled",!1),Wd(),o(!1)}}})},[a,i,s]),p=a&&!!r?.dynamicIslandSupported&&!r?.dynamicIslandEnabled,x=!a&&!rn()&&!Da(),g=!n&&(p||x);return e.jsx(Dt,{initial:!1,children:g&&e.jsxs(pe.div,{initial:d?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:d?{opacity:0}:{opacity:0,y:-8},transition:d?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:m,"aria-label":l("dashboard.island.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx(qd,{reduceMotion:d}),e.jsx("div",{className:"mt-4 flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.island.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] 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 scale-90 origin-left",children:l("qpd.card.badge")})]}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.island.hint")})]})}),a?e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg bg-oai-gray-50 px-3 py-2.5 dark:bg-oai-gray-800/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-medium text-oai-gray-800 dark:text-oai-gray-200",children:l("settings.labs.island_hide_menubar.label")}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("settings.labs.island_hide_menubar.hint")})]}),e.jsx(Sl,{checked:i,onChange:()=>u(f=>!f),ariaLabel:l("settings.labs.island_hide_menubar.aria")})]}):null,e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(pe.button,{type:"button",onClick:h,whileHover:d?void 0:{scale:1.03},whileTap:d?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:a?l("dashboard.island.enable"):l("local_only.open_app")}),e.jsxs("a",{href:"/settings?section=labs",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.island.settings_link"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"island-onboarding-card")})}const Rn="linuxTopBarCardDismissed",Yd="https://github.com/xiufengsun/TokenTracker/tree/main/TokenTrackerLinux/gnome-extension/tokentracker@tokentracker.cc#readme";function Jd(){try{return localStorage.getItem(Rn)==="1"}catch{return!1}}function Zd(){try{localStorage.setItem(Rn,"1")}catch{}}function Qd(){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-800 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 top-4 h-36 w-56 rounded-full bg-orange-500/20 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-8 h-32 w-48 rounded-full bg-purple-600/25 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[22px] items-center gap-2 bg-black px-2.5",children:[e.jsx("div",{className:"flex min-w-0 flex-1 basis-0 items-center",children:e.jsx("span",{className:"h-[7px] w-7 rounded-full bg-white/70"})}),e.jsx("span",{className:"h-[3px] w-10 shrink rounded-full bg-white/60"}),e.jsxs("div",{className:"flex flex-1 basis-0 items-center justify-end gap-2",children:[e.jsxs("span",{className:"flex shrink-0 items-center gap-1 whitespace-nowrap rounded-full bg-white/15 px-1.5 py-0.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(In,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),l("dashboard.linux_topbar.preview_readout")]}),e.jsx("span",{className:"h-[5px] w-[5px] rounded-full bg-white/50"}),e.jsx("span",{className:"h-[5px] w-[5px] rounded-full bg-white/50"}),e.jsx("span",{className:"h-[5px] w-2.5 rounded-sm bg-white/50"})]})]}),e.jsxs("div",{className:"absolute right-10 top-[26px] w-28 rounded-md bg-oai-gray-900/95 p-1.5 ring-1 ring-white/10",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"h-5 flex-1 rounded bg-white/10"}),e.jsx("span",{className:"h-5 flex-1 rounded bg-white/10"})]}),e.jsx("span",{className:"mt-1.5 block h-[3px] w-3/4 rounded-full bg-white/30"}),e.jsx("span",{className:"mt-1 block h-[3px] w-1/2 rounded-full bg-white/20"}),e.jsx("span",{className:"mt-1 block h-[3px] w-2/3 rounded-full bg-white/20"})]})]})}function Xd({enterDelay:t=0}){const[a,r]=c.useState(Jd),s=Xt(),n=c.useCallback(()=>{r(!0),Zd()},[]),o=Da()&&Ci()&&!a;return e.jsx(Dt,{initial:!1,children:o&&e.jsxs(pe.div,{initial:s?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:s?{opacity:0}:{opacity:0,y:-8},transition:s?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:n,"aria-label":l("dashboard.linux_topbar.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsxs("div",{className:"min-w-0 pr-6",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.linux_topbar.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.linux_topbar.hint")})]}),e.jsx("div",{className:"mt-3",children:e.jsx(Qd,{})}),e.jsx("div",{className:"mt-3 flex items-center gap-3",children:e.jsxs(pe.a,{href:Yd,target:"_blank",rel:"noopener noreferrer",whileHover:s?void 0:{scale:1.03},whileTap:s?void 0:{scale:.97},className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[l("dashboard.linux_topbar.setup"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})})]},"linux-topbar-card")})}const Fn="linuxPetCardDismissed";function eu(){try{return localStorage.getItem(Fn)==="1"}catch{return!1}}function tu(){try{localStorage.setItem(Fn,"1")}catch{}}function au({enterDelay:t=0}){const{available:a,loaded:r,settings:s,setSetting:n}=jl(),[o,i]=c.useState(eu),u=Xt(),d=c.useCallback(()=>{i(!0),tu()},[]),m=c.useCallback(()=>{n("visible",!0)},[n]),h=Da()&&a&&r&&!s.visible&&!o;return e.jsx(Dt,{initial:!1,children:h&&e.jsxs(pe.div,{initial:u?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:u?{opacity:0}:{opacity:0,y:-8},transition:u?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:d,"aria-label":l("dashboard.linux_pet.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsxs("div",{className:"flex items-center gap-3 pr-6",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(un,{state:"happy",size:56})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.linux_pet.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.linux_pet.hint")})]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(pe.button,{type:"button",onClick:m,whileHover:u?void 0:{scale:1.03},whileTap:u?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:l("dashboard.linux_pet.show")}),e.jsxs("a",{href:"/pet-settings",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.linux_pet.settings_link"),e.jsx(Dr,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"linux-pet-card")})}function ru({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[o,i]=c.useState(null),[u,d]=c.useState(!1),[m,h]=c.useState(null),p=rt([t,a,r,s,n]),x=c.useCallback(async()=>{if(!t)return;const g=p();d(!0),h(null);try{const f=await Ue(s);if(!g())return;const b=await Ti({from:a,to:r,device:n,accessToken:f});if(!g())return;i(b||null)}catch(f){if(!g())return;h(f?.message||String(f)),i(null)}finally{g()&&d(!1)}},[t,a,r,s,n,p]);return c.useEffect(()=>{if(!t){i(null),h(null),d(!1);return}i(null),h(null),d(!0),x()},[t,x]),{data:o,loading:u,error:m,refresh:x}}function $n(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Pn(t){return t==null?"—":`${Math.round(t*100)}%`}function su(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 nu({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:$n(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:Pn(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:su(t.cost_usd,t.accepted)})]})}function ou({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=De(),{enabled:o}=Cl(),{data:i,loading:u}=ru({enabled:o,from:t,to:a,deviceId:r});if(!o)return null;const d=(i&&i.available&&Array.isArray(i.by_model)?i.by_model:[]).filter(x=>x.outcomes>0&&x.key!=="unknown");if(!d.length)return null;const m=d.slice(0,6),h=i.totals||{},p=`${l("qpd.card.subtitle")}${u?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(Le,{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:m.map(x=>e.jsx(nu,{row:x},x.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:h.accepted??0,outcomes:h.outcomes??0,cost:$n(h.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(h.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(h.effective_tokens),rate:Pn(h.acceptance_rate)})})]}),h.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 iu=new Set(["unknown","synthetic","openai"]);function dr(t){return t==null?"—":`${Math.round(t*100)}%`}function lu(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function cu(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!iu.has(r)&&Number(t?.edit_turns||0)>0}function Fs(){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 du({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=c.useState({requestKey:null,loading:!0,sessions:null,context:null}),o=s.requestKey===r?s:{loading:!0,sessions:null,context:null},i=c.useId(),{enabled:u}=Tl(),d=rt([u,t,a]),{formatTokens:m}=De(),h=S=>m(S,{mode:qt.COMPACT});c.useEffect(()=>{const S=d();if(!u){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Di({from:t,to:a}),Ai()]).then(([T,A])=>{S()&&n({requestKey:r,loading:!1,sessions:T,context:A})}).catch(()=>{S()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[u,t,a,r,d]);const p=c.useMemo(()=>(o.sessions?.by_model||[]).filter(cu).slice(0,5),[o.sessions]),x=c.useMemo(()=>(o.sessions?.subagents||[]).slice(0,3),[o.sessions]);if(!u||!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,j=g.sessions??o.sessions?.session_count??0,w=g.edit_turns??0;return o.loading&&!o.sessions&&!o.context?e.jsxs(Le,{children:[e.jsx(Fs,{}),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(Le,{children:[e.jsx(Fs,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(ur,{label:l("sessions.card.edit_sessions"),value:dr(f),detail:l("sessions.card.edit_session_value",{edits:Ze(k),sessions:Ze(j)})}),e.jsx(ur,{label:l("sessions.card.first_pass"),value:dr(b),detail:l("sessions.card.edit_session_value",{edits:Ze(g.first_pass_sessions??g.one_shot_sessions??0),sessions:Ze(k)})}),e.jsx(ur,{label:l("sessions.card.cost_edit"),value:lu(g.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(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:Ze(j),edits:Ze(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("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:p.map(S=>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:S.model,children:S.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Ze(S.edit_sessions??S.productive_sessions??0),sessions:Ze(S.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:dr(S.first_pass_rate??S.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:h(S.tokens_per_edit)})]},S.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:h(o.context.estimated_fixed_tokens)})]}):null,!!x.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")}),x.map(S=>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:S.name,calls:Math.round(S.calls)})},S.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function ur({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 ce({className:t}){return e.jsx("div",{className:St("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function uu(){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(ce,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function mu(){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(Le,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(ce,{className:"h-4 w-32"}),e.jsx(ce,{className:"h-6 w-24"})]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{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(ce,{className:"h-3 w-20"}),e.jsx(ce,{className:"h-3 w-12"})]},a))]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(uu,{})]})}),e.jsx(Le,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-28"}),e.jsx(ce,{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(Le,{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(ce,{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(ce,{className:"h-8 w-20 rounded-md"}),e.jsx(ce,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(ce,{className:"h-3 w-28"}),e.jsx(ce,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(ce,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ce,{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(ce,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(ce,{className:"h-3 w-12"})]}),e.jsx(ce,{className:"h-5 w-10"}),e.jsx(ce,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(Le,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(ce,{className:"h-7 w-16 rounded"}),e.jsx(ce,{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(ce,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(ce,{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(ce,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(ce,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const hu=Ml.slice(0,10),$s=.06,xu=.11,gu=.05,pu=new Set(["macAppBanner","widgetOnboarding","linuxTopBarCard"]);function Ps({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(Ll,{logos:hu,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(pe.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 fu(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:o,identityDisplayName:i,identityStartDate:u,activeDays:d,identitySubscriptions:m,identityScrambleDurationMs:h,projectUsageEntries:p,projectUsageLimit:x,setProjectUsageLimit:g,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:j,isLocalMode:w,shouldShowInstall:S,installPrompt:T,handleCopyInstall:A,installCopied:L,installInitCmdDisplay:P,trendRowsForDisplay:N,trendFromForDisplay:v,trendToForDisplay:D,trendZoomConfig:R,usageFrom:O,usageTo:F,period:E,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:G,setSelectedPeriod:_,customFrom:$,customTo:H,onCustomRangeApply:ae,customRangeOpen:me,onCustomRangeOpenChange:V,summaryLabel:ie,summaryValue:le,summaryFullValue:Se,hasSummary:ve,summaryLoading:Me,providersLoading:Q,onToggleSummaryFormat:U,summaryTotalTokensRaw:ne,summaryCostValue:ee,summaryConversationsValue:re,rollingUsage:be,costInfoEnabled:W,openCostModal:Y,costModalOpen:X,closeCostModal:ue,allowBreakdownToggle:Pe,refreshAll:Ae,usageLoadingState:he,announceUsageLoading:C,initialDashboardLoading:J,fleetData:z,hasDetailsActual:se,dailyEmptyPrefix:xe,installSyncCmd:ke,dailyEmptySuffix:st,detailsColumns:fe,ariaSortFor:ye,toggleSort:Be,sortIconFor:ze,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:La,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Ma,detailsDateKey:Ea,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:ea,DETAILS_PAGED_PERIODS:we,detailsPageCount:_e,detailsPage:je,setDetailsPage:pt,deviceOptions:Mt,selectedDevice:ta,onDeviceChange:aa,deviceUsageBlock:Et,leftCardOrder:Ia,onLeftReorder:We,rightCardOrder:ra,onRightReorder:nt}=t,It=null,Ra=null,[sa,na]=c.useState(()=>new Set),Rt=c.useCallback((de,oe)=>{pu.has(de)&&na(Ce=>{if(Ce.has(de)===oe)return Ce;const et=new Set(Ce);return oe?et.add(de):et.delete(de),et})},[]),Fa={macAppBanner:w,statsPanel:!0,islandOnboarding:w,linuxPetCard:w,widgetOnboarding:w,linuxTopBarCard:w,installCopy:S,activityHeatmap:!!K,deviceUsage:!!Et,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},Ft=(Ia||[]).filter(de=>Fa[de]&&!sa.has(de)),$t={usageOverview:!0,dataDetails:!s},$a=(ra||[]).filter(de=>$t[de]&&!sa.has(de));function Ye(de,oe){switch(de){case"macAppBanner":return e.jsx(Ud,{todayTokens:ne,isSyncing:he,enterDelay:oe});case"statsPanel":return e.jsx(ot,{delay:oe,children:e.jsx(Gc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:E,startDate:u??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:m,periodConversations:re,rolling:be,topModels:b})});case"islandOnboarding":return e.jsx(Gd,{enterDelay:oe});case"linuxPetCard":return e.jsx(au,{enterDelay:oe});case"widgetOnboarding":return e.jsx(Kd,{enterDelay:oe});case"linuxTopBarCard":return e.jsx(Xd,{enterDelay:oe});case"installCopy":return e.jsx(ot,{delay:oe,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:T}),e.jsxs(pe.button,{onClick:A,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:P}),e.jsx(pe.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:L?"Copied ✓":"Copy"},L?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:oe,children:K});case"deviceUsage":return e.jsx(ot,{delay:oe,children:Et});case"trendMonitor":return e.jsx(ot,{delay:oe,children:e.jsx(sn,{rows:N,from:v,to:D,period:E,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:R})});case"qualityPerDollar":return e.jsx(ou,{from:O,to:F,deviceId:ta});case"sessionInsights":return e.jsx(du,{from:O,to:F});default:return null}}function oa(de,oe){switch(de){case"usageOverview":return e.jsx(ot,{delay:oe,children:e.jsx(Md,{period:E,periods:G,onPeriodChange:_,summaryLabel:ie,summaryValue:le,summaryFullValue:Se,hasSummary:ve,summaryLoading:Me,providersLoading:Q,onToggleSummaryFormat:ve?U:null,summaryCostValue:ee,onCostInfo:W?Y:null,fleetData:z,onRefresh:s?null:Ae,loading:he,announceLoading:C,onOpenShare:s?null:r,customFrom:$,customTo:H,onCustomRangeApply:ae,customRangeOpen:me,onCustomRangeOpenChange:V,from:O,to:F,deviceOptions:Mt,selectedDevice:ta,onDeviceChange:aa})});case"dataDetails":return e.jsx(ot,{delay:oe,children:e.jsx(Wc,{projectEntries:p,projectLimit:x,onProjectLimitChange:g,projectDetailQuery:f,copy:a,hasDetailsActual:se,dailyEmptyPrefix:xe,installSyncCmd:ke,dailyEmptySuffix:st,detailsColumns:fe,ariaSortFor:ye,toggleSort:Be,sortIconFor:ze,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:La,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Ma,detailsDateKey:Ea,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:ea,DETAILS_PAGED_PERIODS:we,period:E,detailsPageCount:_e,detailsPage:je,setDetailsPage:pt})});default:return null}}const qe=al(is(ll,{activationConstraint:{distance:6}}),is(il,{coordinateGetter:ol})),ge=c.useCallback(de=>{const{active:oe,over:Ce}=de;!Ce||oe.id===Ce.id||We?.(String(oe.id),String(Ce.id))},[We]),Pa=c.useCallback(de=>{const{active:oe,over:Ce}=de;!Ce||oe.id===Ce.id||nt?.(String(oe.id),String(Ce.id))},[nt]);function Pt(de,oe,Ce,et){return s?e.jsx(e.Fragment,{children:de.map((Te,ft)=>e.jsx(jt.Fragment,{children:oe(Te,Ce+$s*ft)},Te))}):e.jsx(rl,{sensors:qe,onDragEnd:et,children:e.jsx(sl,{items:de,strategy:nl,children:de.map((Te,ft)=>e.jsx(Pd,{id:Te,onEmptyChange:Rt,children:oe(Te,Ce+$s*ft)},Te))})})}const ia=Pt(Ft,Ye,xu,ge),Ba=Pt($a,oa,gu,Pa);return e.jsxs(e.Fragment,{children:[e.jsxs(Ol,{bare:!s,hideHeader:s,header:It,footer:s?null:Ra,className:s?"screenshot-mode":"",children:[o&&e.jsx(Ps,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(ls,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Ps,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(ls,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!o&&!n&&J&&e.jsx(mu,{}),!o&&!n&&!J&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:ia}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ba})]})})]}),e.jsx(Pc,{isOpen:X,onClose:ue,fleetData:z})]})}function yu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:o=null,accountRevision:i=0}={}){const u=!!(n&&o),[d,m]=c.useState([]),[h,p]=c.useState([]),[x,g]=c.useState(!1),[f,b]=c.useState(null),k=rt([u,t,a,r,s,o,i]),j=c.useCallback(async()=>{const w=k();if(!u){m([]),p([]),g(!1),b(null);return}g(!0),b(null);try{const S=await Ue(o);if(!w())return;const T=await Li({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:S});if(!w())return;m(Array.isArray(T?.devices)?T.devices:[]),p(Array.isArray(T?.account_sources)?T.account_sources:[])}catch(S){if(!w())return;b(S?.message||String(S)),m([]),p([])}finally{w()&&g(!1)}},[u,o,t,a,r,s,i,k]);return c.useEffect(()=>{m([]),p([]),b(null),u&&g(!0),j()},[u,j]),{devices:d,accountSources:h,loading:x,error:f,refresh:j}}const bu=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Bs(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 kr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(bu);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Bs(t.platform)} · ${s}`:Bs(t.platform)}const zs=" · ",Os="%";function Us({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Rl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Xr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Xr,{className:a,"aria-hidden":!0}):e.jsx(mn,{className:a,"aria-hidden":!0})}function Hs(t,a){return a===t?.id||t?.isCurrent===!0}function ku({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:o}){const{formatTokens:i,formatTokensTooltip:u}=De(),[d,m]=c.useState(""),[h,p]=c.useState(""),[x,g]=c.useState(!1),[f,b]=c.useState(""),k=typeof o=="function",j=typeof n=="function",w=!!s,S=t.reduce((v,D)=>v+(Number(D.total_tokens)||0),0)+a.reduce((v,D)=>v+(Number(D.total_tokens)||0),0),T=c.useMemo(()=>t.filter(v=>(Number(v.total_tokens)||0)>0).sort((v,D)=>(Number(D.total_tokens)||0)-(Number(v.total_tokens)||0)),[t]);function A(v){b(""),m(v.id);const D=typeof v.device_name=="string"?v.device_name:"";p(kr(v)===D?D:"")}function L(){m(""),p(""),b("")}async function P(v){const D=h.trim();if(!(!D||x)){g(!0),b("");try{await o(v.id,D),m(""),p("")}catch{b(v.id)}finally{g(!1)}}}const N=a.filter(v=>(Number(v.total_tokens)||0)>0);return T.length===0&&N.length===0?e.jsxs(Le,{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(mn,{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(Le,{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")}),j&&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:[T.map(v=>{const D=Number(v.total_tokens)||0,R=S>0?(D/S*100).toFixed(1):"0.0",O=s===v.id,F=kr(v)||l("dashboard.device_card.unnamed"),E=d===v.id,B=O?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=w&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[E?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(Us,{platform:v.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:h,disabled:x,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:G=>p(G.target.value),onKeyDown:G=>{G.key==="Enter"?P(v):G.key==="Escape"&&L()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:x||!h.trim(),onClick:()=>P(v),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(El,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:x,onClick:L,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Tr,{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 ${B}`,style:{width:`${R}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${F}${Hs(v,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":v.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 ${K} ${O?"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(Us,{platform:v.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:F,children:F}),Hs(v,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")})]}),e.jsxs("span",{title:u(D),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(D),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[zs,R,Os]})]})]}),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 ${B}`,style:{width:`${R}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>A(v),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(Dl,{className:"h-3 w-3"})})]}),f===v.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},v.id)}),N.map(v=>{const D=Number(v.total_tokens)||0,R=S>0?(D/S*100).toFixed(1):"0.0",O=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,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(Tt,{provider:v.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:Nt(v.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:u(D),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(D),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[zs,R,Os]})]})]}),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:`${R}%`}})})]},`account-${v.source}`)})]})]})}function Bn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function zn(){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||!ut.has(r))return;const s=ut.get(r);ut.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||!mt.has(r))return;const s=mt.get(r);mt.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function wu(t){if(!Bn()||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"};zn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{mt.has(r)&&(mt.delete(r),s({ok:!1,error:"timeout"}))},8e3);mt.set(r,o=>{window.clearTimeout(n),s(o)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(o){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:o?.message||String(o)})}})}async function Ks(t,a){if(!Bn()||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"};zn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const o=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,i=>{window.clearTimeout(o),n(i)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(i){ut.delete(s),window.clearTimeout(o),n({ok:!1,error:i?.message||String(i)})}})}const On=1200,Un=1630,Hn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},_u="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 mr=!1;function vu(){if(typeof document>"u"||mr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){mr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=_u,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),mr=!0}async function ju(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function Nu(t,a={}){if(typeof window>"u"||!t)return null;vu(),await ju(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Mi(async()=>{const{toBlob:d,toPng:m}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:m}},[]),n=a.pixelRatio??2,o=t.offsetWidth||On,i=t.offsetHeight||Un,u={pixelRatio:n,cacheBust:!0,width:o,height:i,style:{width:`${o}px`,height:`${i}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,u);if(d)return d}catch{}try{const d=await s(t,u);return d?await(await fetch(d)).blob():null}catch{return null}}async function hr(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 Vs(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 wr(t){const a=te(t);return Number.isFinite(a)?a:0}function Su(t){return t?wr(t.billable_total_tokens??t.total_tokens):0}function Cu(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(u=>{const d=!!u?.future,m=Number.isFinite(u?.level)?Math.max(0,Math.min(4,Math.round(u.level))):0;u?.day&&!d&&(r+=1,m>0&&(s+=1));const h=u?.billable_total_tokens??u?.total_tokens??u?.value??0,p=Number.isFinite(h)?Math.max(0,h):0;return{day:typeof u?.day=="string"?u.day:"",level:m,value:p,future:d}})),totalDays:r,activeDays:s}}function Tu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:o,rank:i,period:u,periodFrom:d,periodTo:m,heatmap:h,capturedAt:p,currency:x,exchangeRate:g}=t,f=Su(n),b=wr(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:wr(w?.tokens),percent:typeof w?.percent=="string"&&w.percent?w.percent:"0.0"})):[],j=Cu(h);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:u,periodFrom:d,periodTo:m,topModels:k,rank:typeof i=="number"&&Number.isFinite(i)&&i>0?Math.floor(i):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:p||new Date().toISOString(),currency:typeof x=="string"&&x.length>0?x.toUpperCase():"USD",exchangeRate:Number.isFinite(g)&&g>0?g:1}}const Du=["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 Au(t){const a=Du[t];return a?l(a):"—"}function Kn(t,a){return l("share.date.month_year",{month:Au(t),year:a})}function Lu(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:Kn(n,r)}function Mu(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 Kn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function _r(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Vn(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 Eu(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 Iu(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 Ru(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 Fu({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"],u=o||i[0],d=t.length,m=(d-1)*s,h=Math.max(4,(r-m)/d),p=7*h+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((x,g)=>(Array.isArray(x)?x:[]).map((b,k)=>{if(k>=7)return null;const j=Ru(b),w=g*(h+s),S=k*(h+s),T=j===null?u:i[j];return e.jsx("rect",{x:w,y:S,width:h,height:h,rx:n,ry:n,fill:T},`${g}-${k}`)}))})}const $u=At("oklch(0.97 0.01 85)"),Fe=At("oklch(0.18 0.02 85)"),tt=At("oklch(0.38 0.015 85)"),Ws=At("oklch(0.55 0.012 85)"),lt=At("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',Pu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Bu=["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(At);function Wn({data:t}){const a=Mu(t),r=_r(t.totalTokens),s=Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=Lu(t.startDate),o=Iu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),i=Eu(t),u=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:$u,color:Fe,fontFamily:Pu,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 ${Ws}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Fe},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:lt}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:tt,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:tt,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:ct,fontSize:52,fontStyle:"italic",lineHeight:1,color:Fe,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:tt,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Fe},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:lt,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:ct,fontSize:o,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Fe,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Fe,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",i,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:lt,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:tt},children:[e.jsxs("span",{children:[l("share.card.broadsheet.estimated_spend")," · ",s]}),e.jsx("span",{children:l("share.card.broadsheet.billable_days",{days:t.activeDays})})]})]}),u?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Fe,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Fu,{weeks:t.heatmapWeeks,palette:Bu,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 ${Fe}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Fe,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:ct,fontStyle:"italic",fontSize:26,color:tt,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((d,m)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Ws}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(m+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:ct,fontSize:32,color:Fe,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Fe,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:_r(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:tt,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Fe}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Fe},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:lt},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:lt},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:lt},children:"→ tokentracker.cc"})]})]})]})}const zu=Hn["annual-report"].width,Ou="#0a0820",at="#ffffffee",dt="rgba(255,255,255,0.45)",xr="#a78bfa",Uu={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"},vr='"Space Grotesk", "Inter Tight", sans-serif',gr='"Inter Tight", sans-serif',Hu="rgba(255,255,255,0.06)",qn=[Hu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Gn=48,Yn=28,Ta=4,Jn=20,Ku=zu-Gn*2-Yn*2,Vu=(Ku-Jn*2)/3,jr=Math.min(Math.floor((Vu-Ta*6)/7),40),Wu=jr*7+Ta*6;function qu(t){if(!Array.isArray(t))return t;const a=[];for(const u of t)if(Array.isArray(u))for(const d of u)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((u,d)=>u-d);const r=u=>{const d=a.length,m=(d-1)*u,h=Math.floor(m);return Math.round((a[h]??0)+((a[Math.min(d-1,h+1)]??0)-(a[h]??0))*(m-h))},s=r(.5),n=r(.75),o=r(.9),i=u=>!u||u<=0?0:u<=s?1:u<=n?2:u<=o?3:4;return t.map(u=>Array.isArray(u)?u.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:i(d.value)}:d):u)}function Gu(t){if(!Array.isArray(t))return[];const a={},r=qu(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 Yu(t){if(!t.length)return[];const a=[...t].sort((i,u)=>i.day.localeCompare(u.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let 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 Ju=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Zu(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 qs(t){const[a,r]=c.useState(null);return c.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 Qu({data:t}){const a=Yu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:vr,marginBottom:4},children:Ju[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ta},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ta},children:r.map((n,o)=>{const i=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:jr,height:jr,borderRadius:4,background:i<0?"transparent":qn[i]}},o)})},s))})]})}function Xu({data:t}){const a=Gu(t.heatmapWeeks),r=Zu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,o=qs(n),i=qs("/neon_bg.png"),u=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Ou,fontFamily:vr,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:Gn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:d*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:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:at},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:at},children:u})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:at},children:t.handle})]})]}),e.jsxs("div",{style:{...Uu,borderRadius:22,padding:Yn,marginBottom:d},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:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),qn.map((m,h)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:m}},h)),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,${Wu}px)`,gap:`8px ${Jn}px`,justifyContent:"center"},children:a.map(m=>e.jsx(Qu,{data:m},m.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{..._a,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:_r(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,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:gr,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},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:xr,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:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:gr,fontSize:28,fontWeight:700,color:at},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:xr,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:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:vr,fontSize:28,fontWeight:700,color:at},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:at},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:xr},children:"tokentracker.cc"})]})]})]})}const Zn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],em={broadsheet:Wn,"annual-report":Xu};function Qn(t){return Hn[t]||{width:On,height:Un}}function tm(t){const a=Zn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Gs=c.forwardRef(function({data:a,variant:r},s){const n=em[r]||Wn,{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 va(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const am=440;function rm(){const[t,a]=c.useState(null),r=c.useRef(null),s=c.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 c.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function pr({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 sm({open:t,onClose:a,data:r,twitterText:s}){const[n,o]=c.useState(null),[i,u]=c.useState(""),[d,m]=c.useState("annual-report"),h=c.useRef(null),{toast:p,push:x}=rm(),g=an(),f=c.useMemo(()=>{const N=g?.user;if(!N||typeof N!="object")return null;const v=N.user_metadata||{},D=N.profile||{},R=v.avatar_url||v.picture||D.avatar_url||N.avatar_url;return typeof R=="string"&&R.trim()?R.trim():null},[g?.user]);c.useEffect(()=>{t&&(o(null),u(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:i||r.handle,avatarUrl:f},{width:k,height:j}=Qn(d),w=am/k;c.useEffect(()=>{if(!t)return;const N=v=>{v.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const S=c.useCallback(async()=>{const N=h.current;if(!N)return null;try{return await Nu(N)}catch(v){return console.warn("[share] capture failed",v),null}},[]),T=c.useCallback(async()=>{if(n)return;o("copy");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}let v=!1;if(va()){const D=await hr(N);D&&(v=(await wu(D)).ok)}else v=await es(N);x(v?l("share.toast.copied"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,x]),A=c.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),L=c.useCallback(async()=>{if(n)return;o("download");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}if(va()){const D=await hr(N);if(D&&(await Ks(D,A())).ok){x(l("share.toast.downloaded"),"success"),o(null);return}}const v=Vs(N,A());x(v?l("share.toast.downloaded"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,A,x]),P=c.useCallback(async()=>{if(n)return;o("x");const N=await S();if(!N){x(l("share.toast.failed"),"error"),o(null);return}if(va()){const O=await hr(N);O&&(await Ks(O,A()),x(l("share.toast.downloaded"),"success"))}else await es(N)?x(l("share.toast.copied"),"success"):Vs(N,A());const v=new URL("https://twitter.com/intent/tweet");s&&v.searchParams.set("text",s);const D=g?.user?.id,R=typeof D=="string"&&D?`/u/${D}`:"/";if(v.searchParams.set("url",`https://www.tokentracker.cc${R}?ref=share`),va())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:v.toString()})}catch{window.open(v.toString(),"_blank","noopener,noreferrer")}else window.open(v.toString(),"_blank","noopener,noreferrer");o(null)},[n,S,x,s,A,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:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:j,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Gs,{ref:h,data:b,variant:d})}),e.jsxs(pe.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:j*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:j,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Gs,{data:b,variant:d})})]})}),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:N=>u(N.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:Zn.map(N=>e.jsx("button",{type:"button",onClick:()=>m(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===N.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:tm(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(pr,{onClick:P,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(pr,{onClick:L,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(pr,{onClick:T,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(Dt,{children:p?e.jsx(pe.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 nm(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:o,topModels:i,period:u,periodFrom:d,periodTo:m,heatmap:h,accessToken:p,userId:x,currency:g,exchangeRate:f}=t,[b,k]=c.useState(null),j=f;return c.useEffect(()=>{if(!a||!x&&!ht())return;let w=!1;return(async()=>{try{const T=await Ei({accessToken:p,userId:x,period:u==="day"||u==="custom"?"week":u,metric:"all",limit:100,offset:0});if(w)return;const L=(Array.isArray(T?.entries)?T.entries:Array.isArray(T)?T:[]).find(N=>N?.is_me===!0),P=typeof L?.rank=="number"?L.rank:null;k(P)}catch{w||k(null)}})(),()=>{w=!0}},[a,p,x,u]),c.useMemo(()=>Tu({handle:r,startDate:s,activeDays:n,summary:o,topModels:i,rank:b,period:u,periodFrom:d,periodTo:m,heatmap:h,currency:g,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,o,i,b,u,d,m,h,g,j])}function Ys(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 om=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function im({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const lm=["day","week","month","total","custom"],fr=new Set(["day","hour","month"]),Wt=new Set(["day","total","custom"]),cm=["islandOnboarding","linuxPetCard","macAppBanner","statsPanel","widgetOnboarding","linuxTopBarCard","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],dm=["usageOverview","dataDetails"];function yr(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 ja(t){return t?Ct(t,null):null}function Js(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function um(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function mm(){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:!um(window.location.hostname)}function n0({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:o=!1,publicToken:i=null,signInUrl:u="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:m}){const{resolvedLocale:h}=Ii(),{currency:p,rate:x}=Aa(),{mode:g,setMode:f,formatTokens:b,formatTokensTooltip:k}=De(),[j,w]=c.useState(!1),[S,T]=c.useState(null),[A,L]=c.useState(null),[P,N]=c.useState(!1),[v,D]=c.useState(null),[R,O]=c.useState(0),[F,E]=c.useState(0),[B,K]=c.useState(null),G=c.useMemo(()=>typeof window>"u"?!1:Ri(window.location.search),[]),_=c.useMemo(()=>mm(),[]),[$,H]=c.useState(!1),ae=2200,[me,V]=c.useState(!0),[ie,le]=c.useState(!1),[Se,ve]=c.useState(!1),[Me,Q]=c.useState(!1),[U,ne]=c.useState(!1),ee=c.useRef(!1),re=ht(),be=r&&!s,W=c.useMemo(()=>be&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,be]),Y=be?W:null,X=o?Fi(i):Y,ue=r||re||o,Pe=be&&Zt(Y),Ae=r&&s&&!o,{accountView:he,revision:C,resolving:J}=$i(),z=he&&!o,se=z?Y:null,xe=J&&!o;c.useEffect(()=>{if(!r||re){T(null),L(null),N(!1),D(null);return}if(o)return;if(!Pe){T(null),L(null),N(!1),D(null);return}let y=!0;const M=()=>{T(null),L(null),N(!1),D(null)};return N(!0),D(null),(async()=>{let I=null;try{I=await Ue(Y)}catch{I=null}if(y){if(!I){M();return}try{const q={link_code:null,expires_at:null};if(!y)return;T(typeof q?.link_code=="string"?q.link_code:null),L(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;T(null),L(null),D(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,re,r,o,Pe,Y,F]);const ke=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");c.useEffect(()=>{if(!ke&&(!r||re||o)){K(null);return}if(!ke&&!Pe){K(null);return}let y=!0;return(async()=>{let M=null;try{M=await Ue(Y)}catch{M=null}if(y){if(!M&&!ke){K(null);return}try{const I=await Pi({baseUrl:t,accessToken:M});if(!y)return;K(I&&typeof I=="object"?I:null)}catch{if(!y)return;K(null)}}})(),()=>{y=!1}},[Pe,t,Y,re,o,r]);const st=c.useMemo(()=>{if(!A)return!1;const y=Date.parse(A);if(!Number.isFinite(y))return!1;const M=R||Date.now();return y<=M},[A,R]);c.useEffect(()=>{!r||re||o||!A||!st||P||(T(null),L(null),D(null),E(y=>y+1))},[st,A,P,re,r]),c.useEffect(()=>{if(!A||o)return;const y=Date.parse(A);if(!Number.isFinite(y))return;const M=Date.now();if(O(M),y<=M)return;const I=window.setTimeout(()=>O(Date.now()),y-M),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(I),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[A]);const fe=c.useMemo(()=>tn(),[]),ye=c.useMemo(()=>en(),[]),Be=c.useMemo(()=>Bi(),[]),ze=o?null:a?.userId||a?.email||"default",[Lt,xt]=c.useState("month"),[Ve,La]=c.useState(null),[Xe,Ma]=c.useState(null),[Ea,gt]=c.useState(!1),Z=G?"total":Lt,ea=c.useMemo(()=>Z==="custom"&&Ve&&Xe?{from:Ve,to:Xe}:zi(Z,{timeZone:fe,offsetMinutes:ye,now:Be}),[Be,Z,fe,ye,Ve,Xe]),we=ea.from,_e=ea.to,[je,pt]=c.useState(null),[Mt,ta]=c.useState(()=>ts());c.useEffect(()=>{const y=()=>ta(ts());return window.addEventListener(as,y),window.addEventListener("storage",y),()=>{window.removeEventListener(as,y),window.removeEventListener("storage",y)}},[]);const{devices:aa,accountSources:Et,refresh:Ia}=yu({from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye,accountView:z,accountAccessToken:se,accountRevision:C}),We=c.useMemo(()=>aa.filter(y=>(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.id===Mt})),[aa,Mt]),ra=c.useMemo(()=>Et.filter(y=>(Number(y.total_tokens)||0)>0),[Et]),nt=z&&We.length>=2,It=z&&We.length+ra.length>=2;c.useEffect(()=>{if(!nt&&!It){je!==null&&pt(null);return}je&&!We.some(y=>y.id===je)&&pt(null)},[nt,It,We,je]);const Ra=c.useMemo(()=>nt?[{value:"",label:l("dashboard.device_filter.all")},...We.map(y=>{const M=kr(y)||l("dashboard.device_card.unnamed"),I=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${M}${I}`}})]:[],[nt,We,h]),sa=It?e.jsx(ku,{devices:We,accountSources:ra,currentDeviceId:Mt,selectedDeviceId:je||"",onSelectDevice:y=>pt(y||null),onRenameDevice:async(y,M)=>{const I=await Ue(se);await Wi({deviceId:y,name:M,accessToken:I}),await Ia()}}):null,na=c.useMemo(()=>Oi({timeZone:fe,offsetMinutes:ye}),[fe,ye]),Rt=c.useMemo(()=>Ui({timeZone:fe,offsetMinutes:ye}),[fe,ye]),Fa=c.useMemo(()=>`Local time (${Rt})`,[Rt]),Ft=fe,$t=ye,$a=na,Ye=c.useMemo(()=>Cr({timeZone:fe,offsetMinutes:ye,date:Be||new Date}),[Be,fe,ye]),oa=c.useMemo(()=>Nc({period:Z,selectedFrom:we,selectedTo:_e,todayKey:Ye}),[we,Z,_e,Ye]),{daily:qe,summary:ge,rolling:Pa,source:Pt,loading:ia,error:Ba,refresh:de}=ms({baseUrl:t,accessToken:X,guestAllowed:Ae,from:we,to:_e,includeDaily:Z!=="total",cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{daily:oe,loading:Ce,refresh:et}=ms({baseUrl:t,accessToken:X,guestAllowed:Ae,from:oa.from,to:oa.to,includeDaily:!0,includeSummary:!1,cacheKey:ze?`${ze}.daily-breakdown`:"daily-breakdown",timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{breakdown:Te,loading:ft,refresh:Mr}=nc({baseUrl:t,accessToken:X,guestAllowed:Ae,from:we,to:_e,cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),[Xn,eo]=c.useState(3),{entries:to,loading:ao,refresh:Er}=ac({baseUrl:t,accessToken:X,from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye}),Ir=Z==="week"||Z==="month",la=Z==="week"||Z==="month",Rr=c.useMemo(()=>qe.filter(y=>y?.future?!1:!y?.day||!Ye?!0:String(y.day)<=String(Ye)),[qe,Ye]),{rows:Je,from:ro,to:so,loading:no,refresh:Fr}=Gi({baseUrl:t,accessToken:X,guestAllowed:Ae,period:Z,from:we,to:_e,months:24,cacheKey:ze,timeZone:Ft,tzOffsetMinutes:$t,now:Be,sharedRows:Ir?qe:null,sharedRange:Ir?{from:we,to:_e}:null,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),oo=c.useMemo(()=>({baseUrl:t,accessToken:X,guestAllowed:Ae,cacheKey:ze,timeZone:Ft,tzOffsetMinutes:$t,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),[t,X,Ae,ze,Ft,$t,Be,z,se,C,xe,je]),{daily:yt,heatmap:Ge,loading:$r,refresh:Pr}=Zl({baseUrl:t,accessToken:X,guestAllowed:Ae,weeks:52,cacheKey:ze,timeZone:fe,tzOffsetMinutes:ye,now:Be,accountView:z,accountAccessToken:se,accountRevision:C,accountViewResolving:xe,deviceId:je}),{data:ca,refresh:Br}=Yi();c.useEffect(()=>{ca&&typeof ca=="object"&&Hi(ca)},[ca]);const He=c.useMemo(()=>Z==="day"?"hour":Z==="total"?"month":"day",[Z]),io=c.useMemo(()=>xs(He),[He]),da="day",lo=c.useMemo(()=>xs(da),[]),[Ke,zr]=c.useState(()=>({key:"day",dir:"desc"}));c.useEffect(()=>{zr(y=>!fr.has(y.key)||y.key===He?y:{key:He,dir:y.dir})},[He]);const bt=c.useMemo(()=>fr.has(Ke.key)&&Ke.key!==He?{...Ke,key:He}:Ke,[He,Ke]),ua=c.useMemo(()=>{if(Z==="day")return Array.isArray(Je)?Je.filter(I=>I?.hour&&!I?.future):[];if(Z==="total"){const I=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return yc(I)}const y=Rr;return!y.some(I=>!I?.missing&&!I?.future)&&qe.length>0?qe.filter(I=>!I?.future).slice(-30).filter(I=>I?.day):y},[Z,Je,Rr,qe]),Bt=c.useMemo(()=>gs(ua,bt),[ua,bt]),Or=c.useMemo(()=>ua.some(y=>!y?.missing&&!y?.future),[ua]),za=c.useMemo(()=>{if(!Wt.has(Z))return 1;const y=Math.ceil(Bt.length/Ca);return y>0?y:1},[Z,Bt.length]),[Oa,ma]=c.useState(0);c.useEffect(()=>{if(!Wt.has(Z)){ma(0);return}ma(y=>Math.min(y,za-1))},[za,Z]),c.useEffect(()=>{Wt.has(Z)&&ma(0)},[Z,Ke.dir,Ke.key]);const co=c.useMemo(()=>Wt.has(Z)?bc(Bt,Oa,Ca):Bt,[Oa,Z,Bt]),Ur=c.useMemo(()=>Sc(oe,{period:Z}),[oe,Z]),kt=c.useMemo(()=>fr.has(Ke.key)?{...Ke,key:da}:Ke,[Ke]),uo=c.useMemo(()=>gs(Ur,kt),[Ur,kt]),mo=c.useMemo(()=>la?qe:Z==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[qe,Z,Je,la]),ho=la?we:ro,xo=la?_e:so;function go(y,M){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(M.endsWith("_tokens")){const I=M==="total_tokens"?ja(y):y?.[M];return e.jsx("span",{title:k(I),children:b(I)})}return Sa(y?.[M])}function po(y){const M=y?.[He];if(M==null)return"";const I=String(M);if(He==="hour"){const[q,Ie]=I.split("T");if(q&&Ie)return`${q} ${Ie.slice(0,5)}`}return I}function fo(y){const M=y?.[da];return M==null?"":String(M)}function yo(y){zr(M=>M.key===y?{key:y,dir:M.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function bo(y){return bt.key!==y?"none":bt.dir==="asc"?"ascending":"descending"}function ko(y){return bt.key!==y?"":bt.dir==="asc"?"▲":"▼"}function wo(y){return kt.key!==y?"none":kt.dir==="asc"?"ascending":"descending"}function _o(y){return kt.key!==y?"":kt.dir==="asc"?"▲":"▼"}const Ua=c.useMemo(()=>{if(!r&&!re&&!o&&!ke)return 0;const y=Number(Ge?.active_days);if(Number.isFinite(y))return y;let M=0;const I=new Set,q=(Ne,Oe,Re)=>{typeof Ne!="string"||!Ne||I.has(Ne)||yr(Oe,Re)&&(I.add(Ne),M+=1)};if(Array.isArray(yt))for(const Ne of yt)q(Ne?.day,ja(Ne));const Ie=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const Ne of Ie)for(const Oe of Array.isArray(Ne)?Ne:[]){const Re=Js(Oe);q(Oe?.day,Re,Oe?.level)}return M},[r,re,Ge?.active_days,Ge?.weeks,yt]),[Hr,Kr]=c.useState("month"),vo=c.useCallback(y=>{z&&!o&&er(a?.userId,"history"),y==="custom"?(Kr(M=>M==="custom"?"month":M),xt(M=>Ve&&Xe?"custom":M),gt(!0)):(xt(y),Kr(y),gt(!1))},[Ve,Xe,z,o,a?.userId]),jo=c.useCallback((y,M)=>{z&&!o&&er(a?.userId,"history"),La(y),Ma(M),xt("custom"),gt(!1)},[z,o,a?.userId]),No=c.useCallback(y=>{gt(y),!y&&Lt==="custom"&&!Ve&&xt(Hr)},[Lt,Ve,Hr]),So=c.useRef(null),ha=c.useMemo(()=>[t||"",ze||"",z?"cloud":"local",C??"",Z||"",we||"",_e||"",Ye||"",je||"all",fe||"",ye??""].join(""),[C,z,t,ze,we,Z,je,fe,Ye,_e,ye]),zt=c.useCallback(async()=>Ys(So,ha,async()=>{z&&Ki(),z||Vi(),await Promise.all([de(),Pr(),Fr(),Mr(),Er(),et()])}),[z,et,Pr,Mr,Er,Fr,de,ha]),Co=c.useRef(null),Vr=c.useCallback(async()=>Ys(Co,ha,async()=>{await im({refreshUsageStats:zt,refreshUsageLimits:Br})}),[ha,Br,zt]),Ha=c.useRef(zt);c.useEffect(()=>{Ha.current=zt},[zt]);const Ka=c.useRef(null);c.useEffect(()=>{if(!ke||re||z)return;Ka.current||(Ka.current=rs({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Ka.current.then(()=>{if(y)return Ha.current()}).catch(M=>{y&&console.warn("[DashboardPage] Reload sync failed:",M)}),()=>{y=!1}},[ke,re,z]),c.useEffect(()=>{if(!ke||re||z)return;const y=vc({refresh:()=>Ha.current(),onError:M=>console.warn("[DashboardPage] Automatic usage refresh failed:",M)});return()=>y.stop()},[ke,re,z]);const To=c.useCallback(async()=>{Q(!0);try{ke&&await rs(om),await Vr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{Q(!1)}},[ke,Vr]),xa=Me||ia||Ce||$r||no||ft||ao,Va=!U&&(xe||z&&xa&&!Or),Do=c.useMemo(()=>l("shared.data_source",{source:String(Pt||"edge").toUpperCase()}),[Pt,h]),ga=c.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Ao="",Wr=c.useMemo(()=>!ga||ga.includes("@")?l("dashboard.identity.fallback"):ga,[ga]),qr=c.useMemo(()=>Wr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Wr]),Gr=c.useMemo(()=>o?l("dashboard.identity.fallback"):qr,[qr,Ao,o]),Yr=c.useMemo(()=>{let y=null;const M=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(yt))for(const q of yt)q?.day&&yr(ja(q))&&M(q.day);const I=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const q of I)for(const Ie of Array.isArray(q)?q:[]){if(!Ie?.day)continue;const Ne=Js(Ie),Oe=Ie?.level;yr(Ne,Oe)&&M(Ie.day)}return y},[Ge?.weeks,yt]),Lo=c.useMemo(()=>o?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(I=>{const q=typeof I?.tool=="string"?I.tool.trim():"",Ne=(typeof I?.plan_type=="string"?I.plan_type:typeof I?.planType=="string"?I.planType:"").trim();return!q||!Ne?null:{tool:q,planType:Ne,provider:typeof I?.provider=="string"?I.provider.trim():"",product:typeof I?.product=="string"?I.product.trim():"",rateLimitTier:typeof I?.rate_limit_tier=="string"?I.rate_limit_tier.trim():typeof I?.rateLimitTier=="string"?I.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[o,B]),Mo=e.jsx(Ji,{heatmap:Ge,timeZoneLabel:na,timeZoneShortLabel:Rt,hideLegend:G,defaultToLatestMonth:G}),Eo=c.useMemo(()=>`${we}..${_e}`,[we,Z,_e]),Io=l("usage.summary.total"),Ee=ge!=null,wt=Ee?ja(ge):0,Ro=b(wt),Fo=c.useCallback(()=>{f(g===qt.COMPACT?qt.FULL:qt.COMPACT)},[f,g]),$o=l("dashboard.core_index.collapse_label"),Po=l("dashboard.core_index.expand_label"),Bo=l("dashboard.core_index.collapse_aria"),zo=l("dashboard.core_index.expand_aria"),Oo=!G,_t=l("shared.placeholder.short"),Wa=c.useMemo(()=>{const y=Array.isArray(Te?.sources)?Te.sources:[];let M=null,I=0;for(const Oe of y){const Re=Ct(Oe?.totals);!Number.isFinite(Re)||Re<=0||Re>I&&(I=Re,M=Oe)}let q=_t,Ie=_t,Ne="0.0";if(M&&I>0){q=M?.source?String(M.source).toUpperCase():_t;const Oe=Array.isArray(M?.models)?M.models:[];let Re=0;for(const Xa of Oe){const fa=Ct(Xa?.totals);!Number.isFinite(fa)||fa<=0||fa>Re&&(Re=fa,Ie=Xa?.model?String(Xa.model):_t)}Re>0&&(Ne=(Re/I*100).toFixed(1))}return{agentName:q,modelName:Ie,modelPercent:Ne}},[Te,_t]),qa=Sa(wt),Uo=l("dashboard.screenshot.twitter_text",{total_tokens:qa==="-"?_t:qa,agent_name:Wa.agentName,model_name:Wa.modelName,model_percent:Wa.modelPercent}),Ho=c.useMemo(()=>G?[]:lm,[G]),Ko=c.useMemo(()=>[{label:l("usage.metric.total"),value:Ee?b(wt):"—",title:Ee?k(wt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Ee?b(ge?.input_tokens):"—",title:Ee?k(ge?.input_tokens):void 0},{label:l("usage.metric.output"),value:Ee?b(ge?.output_tokens):"—",title:Ee?k(ge?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Ee?b(ge?.cached_input_tokens):"—",title:Ee?k(ge?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Ee?b(ge?.reasoning_output_tokens):"—",title:Ee?k(ge?.reasoning_output_tokens):void 0}],[ge?.cached_input_tokens,ge?.input_tokens,ge?.output_tokens,ge?.reasoning_output_tokens,wt,Ee,b,k]),Ga=(Te?.sources||[]).some(y=>(y.models||[]).some(M=>M.pricing?.status==="unpriced"&&M.cost_source!=="provider_reported"&&Number(M.totals?.total_tokens)>0)),Ya=c.useMemo(()=>{if(Ga&&Number(ge?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=Qt(ge?.total_cost_usd,{currency:p,rate:x});return Ga&&y!=="-"?`≥${y}`:y},[ge?.total_cost_usd,p,x,Ga]),Vo=c.useMemo(()=>ge?.conversation_count??null,[ge?.conversation_count]),Jr=c.useMemo(()=>Ic(Te,{copyFn:l}),[Te]),Zr=c.useMemo(()=>Fc(Te,{limit:3,copyFn:l}),[Te]),Wo=nm({enabled:$,handle:Gr,startDate:Yr,activeDays:Ua,summary:ge,topModels:Zr,period:Z,periodFrom:we,periodTo:_e,heatmap:Ge,accessToken:typeof X=="string"?X:null,userId:a?.userId||null,currency:p,exchangeRate:x}),qo=c.useCallback(()=>H(!0),[]),Go=c.useCallback(()=>H(!1),[]),Yo=c.useCallback(()=>w(!0),[]),Jo=c.useCallback(()=>w(!1),[]),Zo=Ya&&Ya!=="-"&&Jr.length>0,Ot=l("dashboard.install.cmd.init"),Ja=st?null:S,Za=Ja?l("dashboard.install.cmd.init_link_code",{link_code:Ja}):Ot,Qo=Ot,Xo=l("dashboard.install.cmd.sync"),ei=Ja?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ti=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const ai=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),ri=kc({publicMode:o,screenshotMode:G,forceInstall:_,accessEnabled:ue,heatmapLoading:$r,activeDays:Ua,hasActiveDeviceToken:ai}),si=l("dashboard.install.prompt"),ni=c.useCallback(async()=>{!Za||!await ss(Za)||(le(!0),window.setTimeout(()=>le(!1),2e3))},[Za]);c.useCallback(async()=>{!Ot||!await ss(Ot)||(ve(!0),window.setTimeout(()=>ve(!1),2e3))},[Ot]);const Qa=c.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[h]),[oi,ii]=c.useMemo(()=>{const y=Qa.split("{{cmd}}");return y.length===1?[Qa,""]:[y[0],y.slice(1).join("{{cmd}}")]},[Qa]),Ut=s&&!o,Ht=!r&&!re&&!s&&!ke&&!o;c.useEffect(()=>{Ut||Ht||Va||ne(!0)},[Va,Ht,Ut]);const pa=ec(cm,dm);return c.useEffect(()=>{ee.current||Ut||Ht||xa||(ee.current=!0,m?.())},[m,Ht,Ut,xa]),e.jsxs(e.Fragment,{children:[z&&!o?e.jsx("div",{className:"mb-3 flex justify-end",children:e.jsx(Al,{from:we,to:_e,deviceId:je})}):null,e.jsx(fu,{copy:l,onOpenShare:qo,screenshotMode:G,showExpiredGate:Ut,showAuthGate:Ht,identityDisplayName:Gr,identityStartDate:Yr,activeDays:Ua,identitySubscriptions:Lo,identityScrambleDurationMs:ae,projectUsageEntries:to,projectUsageLimit:Xn,setProjectUsageLimit:eo,projectDetailQuery:{from:we,to:_e,timeZone:fe,tzOffsetMinutes:ye},topModels:Zr,signedIn:r,publicMode:o,isLocalMode:ke,shouldShowInstall:ri,installPrompt:si,handleCopyInstall:ni,installCopied:ie,installCopiedLabel:ti,installCopyLabel:ei,installInitCmdDisplay:Qo,linkCodeLoading:P,linkCodeError:v,trendRowsForDisplay:mo,trendFromForDisplay:ho,trendToForDisplay:xo,trendZoomConfig:oo,usageFrom:we,usageTo:_e,period:Z,trendTimeZoneLabel:$a,activityHeatmapBlock:Mo,periodsForDisplay:Ho,setSelectedPeriod:vo,customFrom:Ve,customTo:Xe,onCustomRangeApply:jo,customRangeOpen:Ea,onCustomRangeOpenChange:No,metricsRows:Ko,summaryLabel:Io,summaryValue:Ro,hasSummary:Ee,summaryLoading:ia,providersLoading:ft,summaryFullValue:qa,onToggleSummaryFormat:Fo,summaryTotalTokensRaw:te(wt)||0,summaryCostValue:Ya,summaryConversationsValue:Vo,rollingUsage:Pa,costInfoEnabled:Zo,openCostModal:Yo,allowBreakdownToggle:Oo,coreIndexCollapsed:me,setCoreIndexCollapsed:V,coreIndexCollapseLabel:$o,coreIndexExpandLabel:Po,coreIndexCollapseAria:Bo,coreIndexExpandAria:zo,refreshAll:To,usageLoadingState:xa,announceUsageLoading:Me,initialDashboardLoading:Va,usageError:Ba,rangeLabel:Eo,timeZoneRangeLabel:Fa,usageSourceLabel:Do,fleetData:Jr,hasDetailsActual:Or,dailyEmptyPrefix:oi,installSyncCmd:Xo,dailyEmptySuffix:ii,detailsColumns:io,ariaSortFor:bo,toggleSort:yo,sortIconFor:ko,pagedDetails:co,dailyBreakdownRows:uo,dailyBreakdownColumns:lo,dailyBreakdownAriaSortFor:wo,dailyBreakdownSortIconFor:_o,dailyBreakdownDateKey:da,detailsDateKey:He,renderDetailDate:po,renderDailyBreakdownDate:fo,renderDetailCell:go,DETAILS_PAGED_PERIODS:Wt,detailsPageCount:za,detailsPage:Oa,setDetailsPage:ma,costModalOpen:j,closeCostModal:Jo,deviceOptions:Ra,selectedDevice:je||"",onDeviceChange:y=>{z&&!o&&er(a?.userId,"view"),pt(y||null)},deviceUsageBlock:sa,leftCardOrder:pa.left.order,onLeftReorder:pa.left.reorder,rightCardOrder:pa.right.order,onRightReorder:pa.right.reorder}),e.jsx(sm,{open:$,onClose:Go,data:Wo,twitterText:Uo})]})}export{n0 as DashboardPage};