tokentracker-cli 1.5.4 → 1.5.5

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 (117) hide show
  1. package/dashboard/dist/assets/{AchievementBadge-CKNb_cwg.js → AchievementBadge-BYxdWhS1.js} +1 -1
  2. package/dashboard/dist/assets/{AchievementsPage-u9P8DXJI.js → AchievementsPage-Bv9o7Aj8.js} +2 -2
  3. package/dashboard/dist/assets/{AchievementsSection-BSCUJ4DR.js → AchievementsSection-DE5bZGxg.js} +1 -1
  4. package/dashboard/dist/assets/{BadgeDetailModal-Bg7cE3Zq.js → BadgeDetailModal-CgZaSVTp.js} +1 -1
  5. package/dashboard/dist/assets/{BotAnimated-C7D2WbQA.js → BotAnimated-CwhPfUBI.js} +1 -1
  6. package/dashboard/dist/assets/{Card-B4IqAhai.js → Card-Y7qaxMuE.js} +1 -1
  7. package/dashboard/dist/assets/{CloudCheckoutPage-P75pH9Ym.js → CloudCheckoutPage-DVl7jk6b.js} +1 -1
  8. package/dashboard/dist/assets/{CloudPage-DDEZfmZg.js → CloudPage-BnIvpHGH.js} +2 -2
  9. package/dashboard/dist/assets/{CommandPalette-CER_AklA.js → CommandPalette-CzMv2Zxn.js} +1 -1
  10. package/dashboard/dist/assets/{CommunityStatsModal-Cbb74eib.js → CommunityStatsModal-D8sOZqUc.js} +1 -1
  11. package/dashboard/dist/assets/{ConfirmModal-Q1ZQdZHt.js → ConfirmModal-Bun5xKMm.js} +1 -1
  12. package/dashboard/dist/assets/{Controls-DaGOfcoz.js → Controls-ltfnvkFW.js} +1 -1
  13. package/dashboard/dist/assets/{DashboardPage-CXI7RmxO.js → DashboardPage-C3Xu6_3t.js} +1 -1
  14. package/dashboard/dist/assets/{DateRangePopover-DSS1Ira_.js → DateRangePopover-e3gJYqFJ.js} +1 -1
  15. package/dashboard/dist/assets/{DevicePage-6zPLYydh.js → DevicePage-JgT16dEp.js} +1 -1
  16. package/dashboard/dist/assets/{DialogClose-DdCQ36LK.js → DialogClose-DeWert7h.js} +1 -1
  17. package/dashboard/dist/assets/DialogDescription-Ca6W3nCT.js +1 -0
  18. package/dashboard/dist/assets/{DialogTitle-BjP217Y1.js → DialogTitle-BfK_yOeR.js} +1 -1
  19. package/dashboard/dist/assets/{ElectricLogo-Dhq8PM4h.js → ElectricLogo-Bbev0Y8Q.js} +1 -1
  20. package/dashboard/dist/assets/{FadeIn-CGNbED4E.js → FadeIn-fypYWLDK.js} +1 -1
  21. package/dashboard/dist/assets/{HeaderGithubStar-DwqEFzb6.js → HeaderGithubStar-Cnil2Lbo.js} +1 -1
  22. package/dashboard/dist/assets/{HoverTooltip-CQZTgyQy.js → HoverTooltip-Bw_8tru-.js} +1 -1
  23. package/dashboard/dist/assets/{IpCheckPage-Bz09HXLn.js → IpCheckPage-CHnhUgA2.js} +1 -1
  24. package/dashboard/dist/assets/{LandingPage-DC-lZsYR.js → LandingPage-Bq4iQS6S.js} +2 -2
  25. package/dashboard/dist/assets/{LeaderboardPage-D8MpLM_t.js → LeaderboardPage-D42lUdw-.js} +2 -2
  26. package/dashboard/dist/assets/{LeaderboardProBadge-pdXgokhE.js → LeaderboardProBadge-eTKceT90.js} +1 -1
  27. package/dashboard/dist/assets/{LeaderboardProfileModal-nHZLiE0m.js → LeaderboardProfileModal-D-3tRrOR.js} +3 -3
  28. package/dashboard/dist/assets/{LeaderboardProfilePage-BKv3oIAW.js → LeaderboardProfilePage-DkRCJoiA.js} +1 -1
  29. package/dashboard/dist/assets/{LimitsPage-TmRTgSCb.js → LimitsPage-dUXjP3_1.js} +1 -1
  30. package/dashboard/dist/assets/{LocalOnlyNotice-aF01udyR.js → LocalOnlyNotice-CtpjB6Z2.js} +1 -1
  31. package/dashboard/dist/assets/{LoginCard-BaroD0Ct.js → LoginCard-zrRd8o54.js} +1 -1
  32. package/dashboard/dist/assets/{LoginModal-0jgyMGVM.js → LoginModal-DNl5Rt1e.js} +1 -1
  33. package/dashboard/dist/assets/{LoginPage-BUx8U58i.js → LoginPage-BuB707vV.js} +1 -1
  34. package/dashboard/dist/assets/{PetPage-CpOjtJqg.js → PetPage-BpDriXkp.js} +2 -2
  35. package/dashboard/dist/assets/{PopoverPopup-BYjfer-M.js → PopoverPopup-rQNSs8R6.js} +1 -1
  36. package/dashboard/dist/assets/{ProviderIcon-NtYa2h0u.js → ProviderIcon-CumyO371.js} +1 -1
  37. package/dashboard/dist/assets/{ResetPasswordPage-CYUg7TR1.js → ResetPasswordPage-ecUHfJAk.js} +1 -1
  38. package/dashboard/dist/assets/{Select-CYP95o5y.js → Select-YVEqEhk4.js} +1 -1
  39. package/dashboard/dist/assets/{SelectItemText-BCDfusOM.js → SelectItemText-D1NBc4uc.js} +1 -1
  40. package/dashboard/dist/assets/{SelfHostPage-BmVc2rIT.js → SelfHostPage-8nAin68c.js} +1 -1
  41. package/dashboard/dist/assets/{ServiceStatusPage-Dyp8NwIn.js → ServiceStatusPage-D1zxuzOg.js} +1 -1
  42. package/dashboard/dist/assets/{SessionsPage-tGEj6Ztz.js → SessionsPage-B6ksEER_.js} +1 -1
  43. package/dashboard/dist/assets/{SettingsPage-CCMbq5wc.js → SettingsPage-COqP8ZbJ.js} +3 -3
  44. package/dashboard/dist/assets/{SkillsPage-C4O4fbaQ.js → SkillsPage-DCX7xTj0.js} +1 -1
  45. package/dashboard/dist/assets/TokenGalaxy-D4n7AR-R.js +4431 -0
  46. package/dashboard/dist/assets/{TooltipPopup-BJfFYesG.js → TooltipPopup-DvSoB_eS.js} +1 -1
  47. package/dashboard/dist/assets/{TrendMonitor-CElakFSU.js → TrendMonitor-5GVzh0Ye.js} +1 -1
  48. package/dashboard/dist/assets/{WidgetsPage-Cvd1LbJm.js → WidgetsPage-BIc4MBiu.js} +1 -1
  49. package/dashboard/dist/assets/{WrappedPage-wRC1tE_a.js → WrappedPage-BpQk4g0o.js} +1 -1
  50. package/dashboard/dist/assets/{__vite-browser-external-V4TPLCJG.js → __vite-browser-external-B_rKFTTN.js} +3 -3
  51. package/dashboard/dist/assets/{agent-logos-Ba57HF3w.js → agent-logos-DVg-sTm4.js} +1 -1
  52. package/dashboard/dist/assets/{arrow-left-B1bKnxXL.js → arrow-left-Ch6Q7eU5.js} +1 -1
  53. package/dashboard/dist/assets/{arrow-right-DrOlKzX5.js → arrow-right-B2B9GvSI.js} +1 -1
  54. package/dashboard/dist/assets/{arrow-up-right-hlYpo3yw.js → arrow-up-right-DwNO_uSb.js} +1 -1
  55. package/dashboard/dist/assets/{calendar-days-CSY6SEsI.js → calendar-days---NjJlBi.js} +1 -1
  56. package/dashboard/dist/assets/{check-xrP1gLw5.js → check-D3mhgRrW.js} +1 -1
  57. package/dashboard/dist/assets/{chevron-down-6-zT5n9d.js → chevron-down-x-b39Zto.js} +1 -1
  58. package/dashboard/dist/assets/{cloud-checkout-BZymZD4K.js → cloud-checkout-CycWyTsg.js} +1 -1
  59. package/dashboard/dist/assets/{composite-C9izWafa.js → composite-CnA1qtYn.js} +1 -1
  60. package/dashboard/dist/assets/{copy-Dkas5wZX.js → copy-JRnRMgdX.js} +1 -1
  61. package/dashboard/dist/assets/{download-CagGRs0_.js → download-CRLqGD62.js} +1 -1
  62. package/dashboard/dist/assets/{external-link-DRl10hxd.js → external-link-BrmaWV_t.js} +1 -1
  63. package/dashboard/dist/assets/{flame-CkvmsTFB.js → flame-meQ5-vRD.js} +1 -1
  64. package/dashboard/dist/assets/{format-tokens-BtwhO3mV.js → format-tokens-D8mIJGz1.js} +1 -1
  65. package/dashboard/dist/assets/{gift-YzjXkMQx.js → gift-Cd0FPXgO.js} +1 -1
  66. package/dashboard/dist/assets/{icons-CHhKYs0u.js → icons-D-PTKw7b.js} +1 -1
  67. package/dashboard/dist/assets/{index-B0MQZTrM.js → index-CMV9UKNf.js} +1 -1
  68. package/dashboard/dist/assets/{index-DojzoMqd.js → index-C_6gEM83.js} +1 -1
  69. package/dashboard/dist/assets/{index-CJknN9Jd.js → index-DCIZaLNC.js} +1 -1
  70. package/dashboard/dist/assets/index-HLYcwmPD.js +502 -0
  71. package/dashboard/dist/assets/{info-Torep-Ti.js → info-e0tP9P3D.js} +1 -1
  72. package/dashboard/dist/assets/{link-2-DE5Yu-z6.js → link-2-DZ2TQhER.js} +1 -1
  73. package/dashboard/dist/assets/{loader-circle-BL8LxD9n.js → loader-circle-DjflRntu.js} +1 -1
  74. package/dashboard/dist/assets/{local-usage-transfer-8X1InWix.js → local-usage-transfer-XTZLA3XH.js} +1 -1
  75. package/dashboard/dist/assets/{modifiers.esm-D60-6UQa.js → modifiers.esm-BpEQ8-Gt.js} +1 -1
  76. package/dashboard/dist/assets/module-BbVsRaE2.js +3 -0
  77. package/dashboard/dist/assets/{monitor-smartphone-C-IFPjqk.js → monitor-smartphone-VVBcI30G.js} +1 -1
  78. package/dashboard/dist/assets/{play-n6uWrdH9.js → play-DN4Sb3W_.js} +1 -1
  79. package/dashboard/dist/assets/{plus-B2f6TaNj.js → plus-Cz_k7arH.js} +1 -1
  80. package/dashboard/dist/assets/{provider-display-DWqCEcsP.js → provider-display-S1mSaydF.js} +1 -1
  81. package/dashboard/dist/assets/{react-B-zfi_j6.js → react-MQBcjrn_.js} +1 -1
  82. package/dashboard/dist/assets/{safePolygon-C2PsvI-v.js → safePolygon-InKxYcXd.js} +1 -1
  83. package/dashboard/dist/assets/{search-DZOaTLF9.js → search-C-N0RDi0.js} +1 -1
  84. package/dashboard/dist/assets/{server-DIp4Qfsv.js → server-CZkn8vIZ.js} +1 -1
  85. package/dashboard/dist/assets/{shield-check-Cs2M8-iT.js → shield-check-DPrGFouZ.js} +1 -1
  86. package/dashboard/dist/assets/{skills-api-CoYy6Tov.js → skills-api-wMwM-GpF.js} +1 -1
  87. package/dashboard/dist/assets/{sortable.esm-B5_hjIfs.js → sortable.esm-CUPP1ihT.js} +1 -1
  88. package/dashboard/dist/assets/{store-BLXqtJzb.js → store-BpVdRYnQ.js} +1 -1
  89. package/dashboard/dist/assets/{terminal-CEMKX3ba.js → terminal-C-7TFeKg.js} +1 -1
  90. package/dashboard/dist/assets/{trash-DOWYaXjK.js → trash-Be8cd4HD.js} +1 -1
  91. package/dashboard/dist/assets/{use-community-stats-BjRI1Bzz.js → use-community-stats-cG0WrB4Y.js} +1 -1
  92. package/dashboard/dist/assets/{use-latest-request-guard-T7L5qBU6.js → use-latest-request-guard-C91enyPD.js} +1 -1
  93. package/dashboard/dist/assets/{use-limits-display-prefs-vNIrCPZA.js → use-limits-display-prefs-DdwoLqPD.js} +1 -1
  94. package/dashboard/dist/assets/{use-native-settings-Cg5Zb4q_.js → use-native-settings-BR-NiMKh.js} +1 -1
  95. package/dashboard/dist/assets/{use-ordered-list-BF-wIvmG.js → use-ordered-list-oqV724BP.js} +1 -1
  96. package/dashboard/dist/assets/use-reduced-motion-DW5YHBBI.js +1 -0
  97. package/dashboard/dist/assets/{use-transform-CbJ1IcNc.js → use-transform-BsNSgVD6.js} +1 -1
  98. package/dashboard/dist/assets/{use-usage-limits-Dgg3jpC4.js → use-usage-limits-Dk8LcMU-.js} +1 -1
  99. package/dashboard/dist/assets/{useCurrency-3oBHWfSe.js → useCurrency-FxerRfd2.js} +1 -1
  100. package/dashboard/dist/assets/{usePositioner-D0YrIW0A.js → usePositioner-D2J-rSfX.js} +1 -1
  101. package/dashboard/dist/assets/{useTokenFormat-DZAHWE_R.js → useTokenFormat-CaI2nl2C.js} +1 -1
  102. package/dashboard/dist/assets/{zap-kLub6Jiv.js → zap-D3C37XAj.js} +1 -1
  103. package/dashboard/dist/index.html +1 -1
  104. package/dashboard/dist/ip-check.html +1 -1
  105. package/dashboard/dist/leaderboard.html +1 -1
  106. package/dashboard/dist/share.html +1 -1
  107. package/package.json +4 -4
  108. package/src/lib/cursor-config.js +15 -1
  109. package/src/lib/pricing/curated-overrides.json +14 -0
  110. package/src/lib/pricing/seed-snapshot.json +1 -1
  111. package/src/lib/rollout.js +13 -4
  112. package/src/lib/usage-limits.js +266 -10
  113. package/dashboard/dist/assets/DialogDescription-DztHQvj-.js +0 -1
  114. package/dashboard/dist/assets/TokenGalaxy-D2d738xr.js +0 -4426
  115. package/dashboard/dist/assets/index-C2DK8av-.js +0 -502
  116. package/dashboard/dist/assets/module-ZyVsxBG_.js +0 -3
  117. package/dashboard/dist/assets/use-reduced-motion-B9K5mIx4.js +0 -1
@@ -1 +1 @@
1
- import{o as Sr,r as u,j as e,L as di,dC as ui,W as ht,aB as ta,aC as ze,dD as mi,dE as hi,az as rs,dF as wa,aH as Xs,aI as en,aJ as Cr,dG as xi,dH as pi,dI as gi,aL as Tr,aK as Zt,dJ as fi,dK as yi,dL as K,c as l,V as Nt,X as Ar,i as Ie,aA as aa,bi as Qt,z as tn,dM as bi,an as ki,l as Jt,cf as Da,y as St,dN as _i,U as an,Q as rn,aN as wi,ao as vi,B as ji,R as Ni,h as Si,dO as Ci,dP as Ti,dQ as Ai,dR as Di,am as ss,_ as Mi,a as Li,dS as ns,g as Ei,Z as Ri,cs as Ii,dT as Fi,dU as $i,dV as Pi,dW as zi,dX as Oi,cg as os,cT as is,dY as Bi,dZ as Ui,aU as Hi,d5 as ar,d_ as ls,aS as cs,d$ as Ki,e0 as qi,e1 as Vi}from"./__vite-browser-external-V4TPLCJG.js";import{u as st}from"./use-latest-request-guard-T7L5qBU6.js";import{u as ds,L as Wi}from"./use-ordered-list-BF-wIvmG.js";import{t as us,T as sn,g as Gi,u as Yi}from"./TrendMonitor-CElakFSU.js";import{u as Ji}from"./use-usage-limits-Dgg3jpC4.js";import{u as ra}from"./useCurrency-3oBHWfSe.js";import{u as Ne}from"./useTokenFormat-DZAHWE_R.js";import{f as dt,A as Zi}from"./provider-display-DWqCEcsP.js";import{g as Qi,q as nn,J as Xi,M as el,m as Ke}from"./react-B-zfi_j6.js";import{u as tl,C as al,a as rl,b as ms,D as sl,S as nl,v as ol,s as il,K as ll,P as cl}from"./sortable.esm-B5_hjIfs.js";import{D as dl,a as ul,b as ml,c as hl,d as xl,e as pl}from"./DialogTitle-BjP217Y1.js";import{D as gl}from"./DialogClose-DdCQ36LK.js";import{C as Te}from"./Card-B4IqAhai.js";import{S as on}from"./Select-CYP95o5y.js";import{P as Tt}from"./ProviderIcon-NtYa2h0u.js";import{a as ln,u as cn}from"./use-transform-CbJ1IcNc.js";import{u as dn}from"./use-reduced-motion-B9K5mIx4.js";import{f as va,D as fl,g as yl}from"./DateRangePopover-DSS1Ira_.js";import{I as un}from"./info-Torep-Ti.js";import{A as mn}from"./index-CJknN9Jd.js";import{L as bl}from"./loader-circle-BL8LxD9n.js";import{C as kl}from"./chevron-down-6-zT5n9d.js";import{P as _l,a as wl,b as vl,c as jl,d as Nl}from"./PopoverPopup-BYjfer-M.js";import{F as nt}from"./FadeIn-CGNbED4E.js";import{u as Sl,a as Cl,r as Tl,b as hs,P as Al,c as Dl}from"./local-usage-transfer-8X1InWix.js";import{L as xs}from"./LoginCard-BaroD0Ct.js";import{L as Ml,A as Ll}from"./agent-logos-Ba57HF3w.js";import{i as El}from"./host-mode-Bc_iTzHk.js";import{M as hn}from"./monitor-smartphone-C-IFPjqk.js";import{C as Rl}from"./check-xrP1gLw5.js";import"./terminal-CEMKX3ba.js";import"./use-limits-display-prefs-vNIrCPZA.js";import"./play-n6uWrdH9.js";import"./composite-C9izWafa.js";import"./store-BLXqtJzb.js";import"./SelectItemText-BCDfusOM.js";import"./usePositioner-D0YrIW0A.js";import"./safePolygon-C2PsvI-v.js";import"./arrow-left-B1bKnxXL.js";const xn={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"}]]};xn.node;const Il=Sr(xn);const pn={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"}]]};pn.node;const Fl=Sr(pn);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 $l=Sr(gn);function Pl(t,a,r={}){const s=t.get();let n=null,i=s,o;const c=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const g=ps(t.get()),m=ps(i);if(g===m){d();return}const p=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new Xi({keyframes:[g,m],velocity:p,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},x=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((g,m)=>{i=g,o=p=>m(rr(p,c)),Qi.postRender(x)},d),nn(a)){let g=r.skipInitialAnimation===!0;const m=a.on("change",f=>{g?(g=!1,t.jump(rr(f,c),!1)):t.set(rr(f,c))}),p=t.on("destroy",m);return()=>{m(),p()}}return d}function rr(t,a){return a?t+a:t}function ps(t){return typeof t=="number"?t:parseFloat(t)}function zl(t,a={}){const{isStatic:r}=u.useContext(el),s=()=>nn(t)?t.get():t;if(r)return ln(s);const n=cn(s());return u.useInsertionEffect(()=>Pl(n,t,a),[n,JSON.stringify(a)]),n}function Ol(t,a={}){return zl(t,{type:"spring",...a})}function Bl(){return e.jsxs(di,{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 Ul({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Bl,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function Hl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},c=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:c,children:t})}var Kl={};function ql(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 i=(n%10+10)%10,o=(10+a-i)%10;let c=o*r;return o>5&&(c-=10*r),c});return e.jsx(Ke.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 Gl(t,a){const r=t/a;return Math.floor(Wl(r))}function Yl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((c,d)=>/\d/.test(c)&&(s===-1||d<s)).length,i=0,o=!1;return r.map(c=>{if(!/\d/.test(c))return c==="."&&(o=!0),c;if(!o){const d=10**Math.max(n-1,0);return n-=1,d}return i+=1,10**-i})}function Jl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=ql(t,r),h=t!=="."&&t!==",",x=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...x?{width:d.width}:null},children:t})}const i=Gl(a,t),o=cn(0),c=Ol(o,{stiffness:220,damping:26,mass:.8});return u.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(d,h)=>e.jsx(Vl,{mv:c,digit:h,height:r},h))})}function Zl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:c=0,textColor:d="inherit",fontWeight:h="inherit",containerStyle:x,counterStyle:g,digitStyle:m,gradientHeight:p=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:v}){const w=String(a??t??""),C=u.useMemo(()=>Array.isArray(n)&&n.length?n:Yl(w),[n,w]),D=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Kl?.VITEST==="true",M=dn()||D,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,I=r+s;return M?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:h,lineHeight:1,...x,...g},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...x},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:c,paddingRight:c,lineHeight:1,color:d,fontWeight:h,...g},children:C.map((j,_)=>e.jsx(Jl,{place:j,value:A,height:I,digitStyle:m,shouldReduceMotion:M},`${String(j)}-${_}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:p,background:`linear-gradient(to bottom, ${f}, ${b})`}}),e.jsx("span",{style:v??{height:p,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function Ql({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:c,now:d,accountView:h=!1,accountAccessToken:x=null,accountRevision:g=0,accountViewResolving:m=!1,deviceId:p=null}={}){const f=!!(h&&x),b=f?"cloud":"local",k=u.useMemo(()=>ui({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[v,w]=u.useState([]),[C,D]=u.useState(null),[M,A]=u.useState("edge"),[I,j]=u.useState(!1),[_,T]=u.useState(null),z=ht(),B=ta(a),U=!r,L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),$=st([t,k.from,k.to,s,n,b,a,x,g,m,p,o,c,r,z,U,B,L]),V=u.useMemo(()=>{if(!i)return null;const G=Cr({timeZone:o,offsetMinutes:c});return`tokentracker.heatmap.${i}.${b}.${s}.${n}.${G}.${p||"all"}${f||!g?"":`.r${g}`}`},[i,p,b,o,c,s,n,f,g]),H=u.useCallback(()=>{if(!V||typeof window>"u")return null;try{const G=window.localStorage.getItem(V);if(!G)return null;const ie=JSON.parse(G);return!ie||!ie.heatmap?null:ie}catch{return null}},[V]),F=u.useCallback(G=>{if(!(!V||typeof window>"u"))try{window.localStorage.setItem(V,JSON.stringify(G))}catch{}},[V]),N=u.useCallback(()=>{if(!(!V||typeof window>"u"))try{window.localStorage.removeItem(V)}catch{}},[V]),P=u.useRef(b);u.useEffect(()=>{P.current!==b&&(P.current=b,w([]),D(null),A("edge"),T(null),j(!0))},[b]);const de=u.useCallback(async()=>{const G=$(),ie=await ze(a),he=f?await ze(x):null;if(!G()||!ie&&!z&&!L&&!f)return;if(f&&!he){T("Your session expired. Please sign in again to view account data."),j(!1);return}const fe=f?he:ie,ye=f?mi:hi,Oe=f?Xs:en;j(!0),T(null);try{try{const ee=await ye({baseUrl:t,accessToken:fe,weeks:s,to:k.to,weekStartsOn:n,device:p,timeZone:o,tzOffsetMinutes:c}),ne=Array.isArray(ee?.weeks)?ee.weeks:[];if(!G())return;if(!ne.length&&U){const ae=H();if(ae?.heatmap){if(!G())return;D(ae.heatmap),w(ae.daily||[]),A("cache");return}}if(!ne.some(ae=>(Array.isArray(ae)?ae:[]).some(Z=>Z&&Number.isFinite(Number(Z.level))))&&ne.length){const ae=[];for(const te of ne)for(const ge of Array.isArray(te)?te:[])ge?.day&&ae.push({day:ge.day,total_tokens:ge.total_tokens??ge.value??0,billable_total_tokens:ge.billable_total_tokens??ge.value??ge.total_tokens??0});const Z=rs({dailyRows:ae,weeks:s,to:ee?.to||k.to,weekStartsOn:n});if(!G())return;w(ae),D({...Z,week_starts_on:n,active_days:ae.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:wa({dailyRows:ae,to:ee?.to||k.to})}),A("client"),U?F({heatmap:{...Z,week_starts_on:n,active_days:ae.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:wa({dailyRows:ae,to:ee?.to||k.to})},daily:ae,fetchedAt:new Date().toISOString()}):N();return}if(!G())return;D(ee||null),w([]),A("edge"),ee&&U?F({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):U||N();return}catch(ee){const ne=ee,ve=ne?.status??ne?.statusCode;if(ve===401||ve===403)throw ee}if(!G())return;const X=await Oe({baseUrl:t,accessToken:fe,from:k.from,to:k.to,device:p,timeZone:o,tzOffsetMinutes:c}),O=Array.isArray(X?.data)?X.data:[];if(!G())return;w(O);const le=rs({dailyRows:O,weeks:s,to:k.to,weekStartsOn:n});if(!G())return;D({...le,week_starts_on:n,active_days:O.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:wa({dailyRows:O,to:k.to})}),A("client"),U?F({heatmap:{...le,week_starts_on:n,active_days:O.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:wa({dailyRows:O,to:k.to})},daily:O,fetchedAt:new Date().toISOString()}):N()}catch(X){if(!G())return;if(U){const O=H();if(O?.heatmap){if(!G())return;D(O.heatmap),w(O.daily||[]),A("cache"),T(null)}else{const le=X;T(le?.message||String(le)),w([]),D(null),A("edge")}}else{const O=X;T(O?.message||String(O)),w([]),D(null),A("edge")}}finally{G()&&j(!1)}},[a,t,z,r,U,k.from,k.to,H,B,o,c,n,s,N,F,L,f,x,g,p,$]);return u.useEffect(()=>{if(m){j(!0);return}if(!B&&!r&&!z&&!L&&!f){w([]),j(!1),T(null),D(null),A("edge");return}if(!U)N(),w([]),T(null),D(null),A("edge");else{const G=H();G?.heatmap&&(D(G.heatmap),w(G.daily||[]),A("cache"))}de()},[a,z,H,de,B,r,U,N,L,m]),{range:k,daily:v,heatmap:C,source:z?"mock":M==="client"?"edge":M,loading:I,error:_,refresh:de}}const Xl="tokentracker.dashboard.leftCardOrder.v1",ec="tokentracker.dashboard.rightCardOrder.v1";function tc(t,a){const r=ds(Xl,t),s=ds(ec,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=u.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const ac=10;function rc({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[c,d]=u.useState([]),[h,x]=u.useState(!1),[g,m]=u.useState(null),p=ht(),f=ta(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,i,o]),v=u.useCallback(async()=>{const w=k(),C=await ze(a);if(w()){if(!C&&!p&&!b){d([]),m(null),x(!1);return}x(!0),m(null);try{const D=await xi({baseUrl:t,accessToken:C,limit:ac,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!w())return;d(Array.isArray(D?.entries)?D.entries:[])}catch(D){if(!w())return;const M=D?.message||String(D);m(M),d([])}finally{w()&&x(!1)}}},[a,t,r,p,n,i,s,o,b,k]);return u.useEffect(()=>{if(!f&&!p&&!b){d([]),m(null),x(!1);return}d([]),m(null),x(!0),v()},[p,v,f,b]),{entries:c,loading:h,error:g,refresh:v}}const gs="tokentracker.usage-cache-index",fs=24;function ys({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:c,timeZone:d,tzOffsetMinutes:h,now:x,accountView:g=!1,accountAccessToken:m=null,accountRevision:p=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(g&&m),v=k?"cloud":"local",[w,C]=u.useState([]),[D,M]=u.useState(null),[A,I]=u.useState(null),[j,_]=u.useState("edge"),[T,z]=u.useState(null),[B,U]=u.useState(!1),[L,$]=u.useState(null),V=ht(),H=ta(a),F=!r&&!V,N=b||"all",P=(()=>{if(!c)return null;const X=sc(t)||"default",O=i?o?"daily-summary":"daily-only":"summary",le=Cr({timeZone:d,offsetMinutes:h});return`tokentracker.usage.${c}.${v}.${X}.${s}.${n}.${O}.${le}.${N}${k||!p?"":`.r${p}`}`})(),de=u.useRef(v);u.useEffect(()=>{de.current!==v&&(de.current=v,C([]),M(null),I(null),_("edge"),z(null),$(null),U(!0))},[v]);const oe=u.useCallback(()=>{if(!P||typeof window>"u")return null;try{const X=window.localStorage.getItem(P);if(!X)return null;const O=JSON.parse(X),le=o?!!O?.summary:Array.isArray(O?.daily);return!O||!le?null:(us(gs,P,fs),O)}catch{return null}},[o,P]),G=u.useCallback(X=>{if(!(!P||typeof window>"u"))try{window.localStorage.setItem(P,JSON.stringify(X)),us(gs,P,fs)}catch{}},[P]),ie=u.useCallback(()=>{if(!(!P||typeof window>"u"))try{window.localStorage.removeItem(P)}catch{}},[P]),he=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),fe=st([t,s,n,i,o,v,a,m,p,b,d,h,r,V,F,f,H,he]),ye=u.useCallback(async()=>{const X=fe(),O=await ze(a),le=k?await ze(m):null;if(!X()||!O&&!V&&!he&&!k)return;if(k&&!le){$("Your session expired. Please sign in again to view account data."),U(!1);return}const ee=k?Xs:en,ne=k?pi:gi,ve=k?le:O;U(!0),$(null);try{let ae=null,Z=null;if(i)if(o){const[Ae,Qe]=await Promise.allSettled([ee({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h}),ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0})]);if(Ae.status==="rejected")throw Ae.reason;ae=Ae.value,Z=Qe.status==="fulfilled"?Qe.value:null}else ae=await ee({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h});else o&&(Z=await ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0}));let te=i&&Array.isArray(ae?.data)?ae.data:[];i&&(te=nr(te,s,n,{timeZone:d,offsetMinutes:h,now:x}));let ge=o&&(Z?.totals||ae?.summary?.totals)||null,xe=o&&(Z?.rolling||ae?.summary?.rolling)||null;if(o&&i&&!ge&&!Z)try{const Ae=await ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0});ge=Ae?.totals||null,xe=Ae?.rolling||xe}catch{}const je=new Date().toISOString();if(!X())return;C(te),M(ge),I(xe),_("edge"),z(je),(ge||!o&&i)&&F?G({summary:ge,rolling:xe,daily:te,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:je}):F||ie()}catch(ae){if(!X())return;if(F){const Z=oe();if(Z?.summary||!o&&Array.isArray(Z?.daily)){M(Z.summary),I(Z.rolling||null);const te=Array.isArray(Z.daily)?Z.daily:[],ge=i?nr(te,Z.from||s,Z.to||n,{timeZone:d,offsetMinutes:h,now:x}):te;C(ge),_("cache"),z(Z.fetchedAt||null),$(null)}else{const te=ae;$(te?.message||String(te)),C([]),M(null),I(null),_("edge"),z(null)}}else{const Z=ae;$(Z?.message||String(Z)),C([]),M(null),I(null),_("edge"),z(null)}}finally{X()&&U(!1)}},[a,t,s,i,o,V,r,F,x,oe,H,d,n,h,ie,G,he,k,m,p,b,fe]);return u.useEffect(()=>{if(f){U(!0);return}const X=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!H&&!r&&!V&&!X&&!k){C([]),M(null),I(null),$(null),U(!1),_("edge"),z(null);return}if(!F)ie(),C([]),M(null),I(null),$(null),_("edge"),z(null);else{const O=oe();if(O?.summary||!o&&Array.isArray(O?.daily)){M(O.summary),I(O.rolling||null);const le=Array.isArray(O.daily)?O.daily:[],ee=i?nr(le,O.from||s,O.to||n,{timeZone:d,offsetMinutes:h,now:x}):le;C(ee),_("cache"),z(O.fetchedAt||null),$(null)}else C([]),M(null),I(null),_("edge"),z(null),$(null)}U(!0),ye()},[a,V,oe,ye,H,r,F,ie,he,f,o]),u.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const X=15e3;let O=Date.now();const le=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-O<X||(O=ee,ye())};return window.addEventListener("focus",le),document.addEventListener("visibilitychange",le),()=>{window.removeEventListener("focus",le),document.removeEventListener("visibilitychange",le)}},[ye]),{daily:w,summary:D,rolling:A,source:V?"mock":j,fetchedAt:T,loading:B,error:L,refresh:ye}}function sc(t){try{return new URL(t).host}catch{return null}}function sr(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Zt(o)===a?o:null}function nc(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function nr(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=sr(a),c=sr(r);if(!o||!c||c<o)return Array.isArray(t)?t:[];const d=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=Tr({timeZone:s,offsetMinutes:n,date:d}),x=sr(h),g=x?x.getTime():d.getTime(),m=new Map;for(const f of t||[])f?.day&&m.set(f.day,f);const p=[];for(let f=o;f<=c;f=nc(f,1)){const b=Zt(f),k=m.get(b),v=f.getTime()>g;if(k){p.push({...k,missing:!1,future:v});continue}p.push({day:b,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!v,future:v})}return p}function oc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:c,accountView:d=!1,accountAccessToken:h=null,accountRevision:x=0,accountViewResolving:g=!1,deviceId:m=null}={}){const p=!!(d&&h),f=p?"cloud":"local",[b,k]=u.useState(null),[v,w]=u.useState("edge"),[C,D]=u.useState(!1),[M,A]=u.useState(null),I=ht(),j=ta(a),_=!r,T=u.useMemo(()=>{if(!i)return null;const N=ic(t)||"default",P=Cr({timeZone:o,offsetMinutes:c});return`tokentracker.modelBreakdown.${i}.${f}.${N}.${s}.${n}.${P}.${m||"all"}${p||!x?"":`.r${x}`}`},[t,i,m,s,f,o,n,c,p,x]),z=u.useCallback(()=>{if(!T||typeof window>"u")return null;try{const N=window.localStorage.getItem(T);if(!N)return null;const P=JSON.parse(N);return!P||!P.breakdown?null:P}catch{return null}},[T]),B=u.useCallback(N=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(N))}catch{}},[T]),U=u.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),$=st([t,s,n,f,a,h,x,m,o,c,r,I,_,g,j,L]),V=u.useRef(f);u.useEffect(()=>{V.current!==f&&(V.current=f,k(null),w("edge"),A(null),D(!0))},[f]);const H=u.useCallback(async()=>{const N=$(),P=await ze(a),de=p?await ze(h):null;if(!N()||!P&&!I&&!L&&!p)return;if(p&&!de){A("Your session expired. Please sign in again to view account data."),D(!1);return}const oe=p?de:P,G=p?fi:yi;D(!0),A(null);try{const ie=await G({baseUrl:t,accessToken:oe,from:s,to:n,device:m,timeZone:o,tzOffsetMinutes:c});if(!N())return;k(ie||null),w("edge"),ie&&_?B({breakdown:ie,fetchedAt:new Date().toISOString()}):_||U()}catch(ie){if(!N())return;if(_){const he=z();if(he?.breakdown)k(he.breakdown),w("cache"),A(null);else{k(null),w("edge");const fe=ie;A(fe?.message||String(fe))}}else{k(null),w("edge");const he=ie;A(he?.message||String(he))}}finally{N()&&D(!1)}},[a,t,s,I,r,_,z,o,n,j,c,U,B,L,p,h,x,m,$]);return u.useEffect(()=>{if(g){D(!0);return}if(!j&&!r&&!I&&!L&&!p){k(null),w("edge"),A(null),D(!1);return}if(!_)U(),k(null),w("edge"),A(null);else{const N=z();N?.breakdown?(k(N.breakdown),w("cache"),A(null)):(k(null),w("edge"),A(null))}D(!0),H()},[a,I,z,H,j,r,_,U,L,g]),{breakdown:b,source:I?"mock":v,loading:C,error:M,refresh:H}}function ic(t){try{return new URL(t).host}catch{return null}}const fn=new Set(["day","hour","month"]);function lc(t){return fn.has(t)}function bs(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 cc(t,a){const r=bs(t),s=bs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=K(t),i=K(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function dc(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 uc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function mc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function hc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),c=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(c)||!Number.isFinite(d)||n<1||n>12||i<1||i>31||o<0||o>23||c<0||c>59||d<0||d>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,c,d));return Number.isFinite(h.getTime())?h.getTime():null}function xc(t,a,r){const s=r==="hour"?hc:r==="month"?mc:uc,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:dc(t,a)}function yn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=fn.has(a)?(c,d)=>xc(c,d,a):cc,o=c=>a==="total_tokens"&&c?.billable_total_tokens!=null?c.billable_total_tokens:c?.[a];return n.map((c,d)=>({row:c,index:d})).sort((c,d)=>{const h=o(c.row),x=o(d.row),g=h==null,m=x==null;if(g&&m)return c.index-d.index;if(g)return 1;if(m)return-1;const p=i(h,x);return p!==0?p*s:c.index-d.index}).map(c=>c.row)}function pc(){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 ks(t){const a=lc(t)?t:"day";return pc().map((r,s)=>s===0?{...r,key:a}:r)}function _s(t,{key:a,dir:r}){return yn(t,{key:a,dir:r})}const Ma=12,gc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function fc(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 yc(t){return gc.some(a=>fc(t?.[a]))}function bc(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=yn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&yc(n));return s===-1?a:r.slice(s)}function kc(t,a,r=Ma){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Ma,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function _c({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const ja=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 ja.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ja.active:s<=60*6e4?ja.warm:ja.idle}const vc=3e4;function jc({refresh:t,intervalMs:a=vc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,c=Date.now(),d=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const p=Promise.resolve().then(()=>t()).catch(f=>n(f)).then(()=>{}).finally(()=>{o===p&&(o=null)});return o=p,p},x=r.setInterval(()=>{const p=Date.now();p<d||(d=p+wc({visible:s.visibilityState==="visible",lastInteractionAt:c,now:p}),h())},a),g=()=>{s.visibilityState==="visible"&&(c=Date.now(),d=0,h())},m=()=>{c=Date.now()};return r.addEventListener("focus",g),r.addEventListener("pointerdown",m),r.addEventListener("keydown",m),s.addEventListener("visibilitychange",g),{run:h,stop(){i=!0,r.clearInterval(x),r.removeEventListener("focus",g),r.removeEventListener("pointerdown",m),r.removeEventListener("keydown",m),s.removeEventListener("visibilitychange",g)}}}function Nc(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 Zt(r)===t?r:null}function Sc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=Nc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Zt(i),to:Zt(n)}}function Cc(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 Dr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Tc(t){const a=Dr(t?.model_id);return a||null}function bn(t,a){return t?.model?String(t.model):a}function kn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Dr(n);if(!i||i.includes("/"))continue;const o=Math.max(0,K(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function _n(t,a){const r=Dr(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=K(t?.billable_total_tokens),s=K(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Ac={deepseek:"dsh"};function Dc(t){const a=typeof t=="string"?t:"";return Ac[a]||a}const Mc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count"],Mr=["input","output","cached","cacheCreate","reasoning"];function La(t){let a=0;for(const r of Mr)a+=Math.max(0,Number(t?.[r])||0);return a}function Lc(t){return La(t?.tokens)>0}const Xt=["priority","ultrafast"],wn=Mr,Ec={priority:{tokens:{input:"priority_input_tokens",cached:"priority_cached_input_tokens",cacheCreate:"priority_cache_creation_input_tokens",output:"priority_output_tokens",reasoning:"priority_reasoning_output_tokens"},cost:"priority_cost_usd"},ultrafast:{tokens:{input:"ultrafast_input_tokens",cached:"ultrafast_cached_input_tokens",cacheCreate:"ultrafast_cache_creation_input_tokens",output:"ultrafast_output_tokens",reasoning:"ultrafast_reasoning_output_tokens"},cost:"ultrafast_cost_usd"}};function Rc(t){const a={};let r=!1;for(const s of Xt){const n=Ec[s],i={input:Math.max(0,K(t?.[n.tokens.input])??0),output:Math.max(0,K(t?.[n.tokens.output])??0),cached:Math.max(0,K(t?.[n.tokens.cached])??0),cacheCreate:Math.max(0,K(t?.[n.tokens.cacheCreate])??0),reasoning:Math.max(0,K(t?.[n.tokens.reasoning])??0)},o=Math.max(0,K(t?.[n.cost])??0);La(i)<=0&&o<=0||(a[s]={tokens:i,cost:o},r=!0)}return r?a:null}function vn(t,a){if(!a||!Object.keys(a).length)return t;const r={...t||{}};for(const s of Xt){const n=a[s];if(!n)continue;const i=r[s];if(!i){r[s]={tokens:{...n.tokens},cost:n.cost};continue}for(const o of wn)i.tokens[o]+=n.tokens[o]||0;i.cost+=n.cost||0}return r}function jn(t){return!!(t?.tiers?.priority||t?.tiers?.ultrafast)}function Ic(t,a){const r=Number(t?.pricing?.[`${a}_multiplier`]);return Number.isFinite(r)&&r>1?r:0}function Fc(t){if(!jn(t))return null;const a={input:0,output:0,cached:0,cacheCreate:0,reasoning:0};let r=!1;for(const n of wn){let i=Math.max(0,Number(t?.tokens?.[n])||0);for(const o of Xt)i-=Math.max(0,Number(t?.tiers?.[o]?.tokens?.[n])||0);a[n]=Math.max(0,i),a[n]>0&&(r=!0)}let s=Math.max(0,K(t?.cost)??0);for(const n of Xt)s-=Math.max(0,Number(t?.tiers?.[n]?.cost)||0);return s=Math.max(0,s),!r&&s<=0?null:{tokens:a,cost:s}}function Lr(t){return t?.unpriced===!0?!0:t?.costSource!=="provider_reported"&&t?.pricing?.status==="unpriced"}function ws(t,a){for(const r of Mc)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 vs(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,conversation_count:0,total_cost_usd:"0"}}function $c(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:vs(),models:new Map},a.set(s,n)),ws(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let c=n.models.get(o);const d=Rc(i?.totals);c?c.tiers=vn(c.tiers??null,d):(c={...i,model:i?.model||o,model_id:o,totals:vs()},c.tiers=d,n.models.set(o,c)),ws(c.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function Pc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=$c(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const c=Ct(o?.totals),d=K(o?.totals?.total_cost_usd)??0,h=Math.max(0,K(o?.totals?.conversation_count)??0);return{source:o?.source,totalTokens:Number.isFinite(c)?c:0,totalRequests:h,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,K(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,K(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,K(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0||o.totalRequests>0);if(!n.length)return[];const i=n.reduce((o,c)=>o+c.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,c)=>c.totalTokens-o.totalTokens||c.totalRequests-o.totalRequests).map(o=>{const c=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),d=i>0?o.totalTokens/i*100:0,h=Number.isFinite(d)?d.toFixed(2):"0.00",x=o.models.map(f=>{const b=Ct(f?.totals),k=Math.max(0,K(f?.totals?.conversation_count)??0);if((!Number.isFinite(b)||b<=0)&&k<=0)return null;const v=o.totalTokens>0?Math.round(b/o.totalTokens*1e3)/10:0,w=bn(f,r("shared.placeholder.short")),C=Tc(f),D=K(f?.totals?.total_cost_usd),M=b<=0?null:D??(o.totalCost>0&&o.totalTokens>0?b/o.totalTokens*o.totalCost:null),A=f?.totals||{};return{id:C,name:w,share:v,usage:b,requests:k,cost:M,tokens:{input:Math.max(0,K(A?.input_tokens)??0),output:Math.max(0,K(A?.output_tokens)??0),cached:Math.max(0,K(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,K(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,K(A?.reasoning_output_tokens)??0)},tiers:f?.tiers??null,pricing:f?.pricing||null,costSource:f?.cost_source||null}}).filter(Boolean),g=o.inputTokens+o.cacheRead+o.cacheCreate,p=o.cacheRead+o.cacheCreate>0&&g>0?Math.round(o.cacheRead/g*100):null;return{source:o.source,label:c,totalPercent:String(h),totalPercentValue:d,usd:o.totalCost,usage:o.totalTokens,requests:o.totalRequests,cacheHitRate:p,cacheReusedTokens:o.cacheRead,cacheInputTokens:g,models:x}})}function zc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const c=Array.isArray(o?.models)?o.models:[];for(const d of c){const h=K(d?.usage),x=Math.max(0,K(d?.requests)??0);if((h==null||h<=0)&&x<=0)continue;const g=h??0,m=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;m&&s.push({model:d,name:m,usage:g,requests:x})}}const n=kn(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:c,usage:d,requests:h}of s){const x=_n(c,n);if(!x)continue;const{key:g}=x,m=r.get(g)||{id:g,name:x.name,usage:0,requests:0,cost:0,hasCost:!1,unpriced:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0},tiers:null,pricing:null};m.usage+=d,m.requests+=h;const p=o?.tokens||{};for(const b of Mr)m.tokens[b]+=Math.max(0,Number(p[b])||0);m.tiers=vn(m.tiers,o?.tiers??null),!m.pricing&&o?.pricing&&(m.pricing=o.pricing),d>0&&Lr(o)&&(m.unpriced=!0);const f=K(o?.cost);f!=null&&(m.cost+=f,m.hasCost=!0),n.has(g)?m.name=n.get(g):d>=m.nameWeight&&(m.name=c,m.nameWeight=d),r.set(g,m)}const i=Array.from(r.values()).reduce((o,c)=>o+c.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,requests:o.requests,cost:o.hasCost?o.cost:null,unpriced:o.unpriced===!0,tokens:{...o.tokens},tiers:o.tiers,pricing:o.pricing,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,c)=>c.usage!==o.usage?c.usage-o.usage:String(o.name).localeCompare(String(c.name)))}function Oc(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 i=new Map,o=new Map,c=new Map,d=[];let h=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const v=Ct(k?.totals);if(!Number.isFinite(v)||v<=0)continue;h+=v;const w=bn(k,s("shared.placeholder.short"));d.push({name:w,tokens:v})}}const x=kn(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=_n(f,x);if(!k)continue;const{key:v}=k;i.set(v,(i.get(v)||0)+b),x.has(v)?o.set(v,x.get(v)):b>=(c.get(v)||0)&&(c.set(v,b),o.set(v,f))}if(!i.size)return[];const g=Array.from(i.values()).reduce((f,b)=>f+b,0),m=h>0?h:g,p=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([f,b])=>{const k=m>0?(b/m*100).toFixed(1):"0.0";return{id:f,name:o.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,p)}function Bc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=aa(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function js(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Qt(a);return(a===tn?t:t*r)<.01?`<${s}0.01`:aa(t,{decimals:2,currency:a,rate:r})}function Ns(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const Uc=Nt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=ra(),o=u.useMemo(()=>(Array.isArray(s)?s:[]).map(h=>{const x=K(h?.usd)??0,g=K(h?.usage)??0,m=Array.isArray(h?.models)?h.models:[];return{label:h?.label?String(h.label):"",usdValue:x,costLabel:js(x,n,i),tokensLabel:Ns(g),models:m.map(p=>{const f=K(p?.usage)??0,b=K(p?.cost)??0;return{id:p?.id?String(p.id):"",name:p?.name?String(p.name):"",tokensLabel:Ns(f),costLabel:js(b,n,i),sortCost:b,pricing:p?.pricing,costSource:p?.costSource,tokens:p?.tokens}}).filter(p=>p.costLabel||p.tokensLabel).sort((p,f)=>f.sortCost-p.sortCost)}}).filter(h=>h.usdValue>0||h.models.length>0).sort((h,x)=>x.usdValue-h.usdValue),[s,n,i]),c=o.some(h=>h.models.some(x=>Lr(x))),d=u.useMemo(()=>{const h=o.reduce((x,g)=>x+g.usdValue,0);return c&&h===0?l("dashboard.cost_breakdown.unpriced_label"):`${c?"≥":""}${Bc(h,n,i)}`},[o,n,i,c]);return e.jsx(dl,{open:a,onOpenChange:h=>{h||r?.()},children:e.jsxs(ul,{children:[e.jsx(ml,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(hl,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(xl,{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(pl,{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(Ar,{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:c?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")}),o.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")})]}),o.map((h,x)=>{const g=`fleet-${x}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":g,className:x>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:g,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:h.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:h.costLabel||"—"})]}),h.models.map((m,p)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:m.name,children:m.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:m.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):m.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),m.pricing?.status==="unpriced"&&m.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,m.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,m.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(m.tokens.input)||0),output:Ie(Number(m.tokens.output)||0),read:Ie(Number(m.tokens.cached)||0),write:Ie(Number(m.tokens.cacheCreate)||0)})}):null,m.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:m.pricing.input,output:m.pricing.output,read:m.pricing.cache_read,write:m.pricing.cache_write})}):null]})]}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:m.costLabel||(m.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):m.pricing?.status==="free"?aa(0,{currency:n,rate:i}):l("dashboard.cost_breakdown.rate_unknown"))})]},m.id||`${m.name}-${p}`))]},`${h.label}-${x}`)})]})]})})]})})]})})});function Hc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,x]=u.useState(null),g=ht(),m=st([t,a,r,s,n,g]);return u.useEffect(()=>{const p=m();if(!t){o(null),x(null),d(!1);return}d(!0),o(null),x(null),bi({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{p()&&o(f||null)}).catch(f=>{p()&&(x(f?.message||String(f)),o(null))}).finally(()=>{p()&&d(!1)})},[t,a,r,s,n,g,m]),{data:i,loading:c,error:h}}function Nn(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 Sn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function Cn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function Tn(t,a){return a&&Cn(Sn(t))==="github"?a:""}function An({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=u.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const Ss="#10b981",or=[{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"}],ir=60;function Kc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(m=>[m.day,m]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const c=t[t.length-1].day;o<c&&(o=c);const d=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(h.getTime()))return t;const x=Math.round((h.getTime()-d.getTime())/864e5)+1;x>ir&&d.setUTCDate(d.getUTCDate()+(x-ir));const g=[];for(;d.getTime()<=h.getTime()&&g.length<ir;){const m=d.toISOString().slice(0,10);g.push(n.get(m)||{day:m,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return g}function lr(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function jt({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 qc({host:t}){if(!t)return null;let a;const r=Cn(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 cr({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 Vc({entry:t,query:a={},onClose:r}){const[s,n]=Nt.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:c}=Nn(i),d=typeof t?.project_ref=="string"?t.project_ref:"",h=Sn(d),{data:x,loading:g,error:m}=Hc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:p,formatTokensTooltip:f}=Ne(),b=Nt.useCallback(()=>n(!0),[]),k=L=>{L.target===L.currentTarget&&s&&r()};Nt.useEffect(()=>{const L=$=>{$.key==="Escape"&&b()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b]);const v=x?.totals||null,w=K(v?.billable_total_tokens)??0,C=Number(x?.days_active||0),D=K(v?.input_tokens)??0,M=K(v?.cached_input_tokens)??0,A=D+M>0?M/(D+M):null,I=K(x?.range_total_tokens)??0,j=K(v?.total_tokens)??0,_=I>0?j/I:null,T=Nt.useMemo(()=>Kc(x?.daily,x?.from,x?.to,Tr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[x,a.timeZone,a.tzOffsetMinutes]),z=or.reduce((L,$)=>L+(K(v?.[$.key])??0),0),B=Array.isArray(x?.sources)?x.sources:[],U=!g&&!m&&v&&j>0;return e.jsx("div",{onAnimationEnd:k,onClick:L=>{L.target===L.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":i,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(Ar,{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:Ss}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:Ss}})]}),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(An,{githubOwner:Tn(d,o),letter:(c?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:c||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(qc,{host:h}),h&&x?.from&&x?.to?e.jsx("span",{children:"·"}):null,x?.from&&x?.to?e.jsxs("span",{className:"tabular-nums",children:[x.from," – ",x.to]}):null]})]}),U?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(jt,{label:l("dashboard.projects.detail.stat_total"),value:p(w),title:f(w)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_share"),value:_==null?"—":lr(_)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":lr(A)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_conversations"),value:Da(v.conversation_count)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_active_days"),value:Da(C)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_avg_day"),value:C>0?p(Math.round(w/C)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[g&&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"})]}),!g&&m&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!g&&!m&&!U&&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")}),U&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[T.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(sn,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),z>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:or.map(L=>{const $=K(v[L.key])??0;return $<=0?null:e.jsx("div",{style:{width:`${$/z*100}%`,backgroundColor:L.color,minWidth:"2px"}},L.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:or.map(L=>{const $=K(v[L.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:L.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(L.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f($),children:p($)})]},L.key)})})]}),B.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:B.map(L=>{const $=Number(L.total_tokens||0),V=j>0?$/j:0,H=V*100,F=Number(L.conversation_count||0),N=Gi(L.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:L.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:dt(L.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(L.days_active||0)}),F>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:F})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f($),children:p($)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:lr(V)})]}),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(H,$>0?1:0))}%`,minWidth:$>0?"3px":0,backgroundColor:N}})})]},L.source)})})]})]})]})]})})}function Wc(t){return e.jsx(ki,{mode:Jt.COMPACT,children:e.jsx(Vc,{...t})})}const Gc=5;function Yc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",c=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:h}=Nn(o),x=Tn(c,d),g=K(t?.billable_total_tokens??t?.total_tokens)??0,m=a>0?Math.min(100,Math.max(2,g/a*100)):0,p=Array.isArray(t?.sources)?t.sources:[],f=p.slice(0,Gc),b=p.length-f.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(An,{githubOwner:x,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[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:h||o||"—"})]}),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(g),children:s(g)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${m}%`,minWidth:g>0?"3px":0}})})]})]})}function Jc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:c,dailyEmptySuffix:d,detailsColumns:h,ariaSortFor:x,toggleSort:g,sortIconFor:m,pagedDetails:p,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:w="day",detailsDateKey:C,renderDetailDate:D,renderDailyBreakdownDate:M,renderDetailCell:A,DETAILS_PAGED_PERIODS:I,period:j,detailsPageCount:_,detailsPage:T,setDetailsPage:z}){const[B,U]=u.useState("daily"),[L,$]=u.useState(null),{formatTokens:V,formatTokensTooltip:H}=Ne();return e.jsxs(Te,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${B==="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":B==="daily",type:"button",onClick:()=>U("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${B==="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":B==="projects",type:"button",onClick:()=>U("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${B==="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")})]}),B==="projects"&&e.jsx(on,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:F=>r?.(Number(F)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),B==="projects"&&(()=>{const F=t.slice(0,a);if(F.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const N=F.reduce((P,de)=>{const oe=K(de?.billable_total_tokens??de?.total_tokens)??0;return oe>P?oe:P},0);return e.jsx("div",{className:"space-y-1",children:F.map((P,de)=>e.jsx(Yc,{entry:P,maxTokens:N,copy:n,formatTokens:V,formatTokensTooltip:H,onSelect:$},P?.project_key||P?.project_ref||`entry-${de}`))})})(),L&&e.jsx(Wc,{entry:L,query:s,onClose:()=>$(null)}),B==="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:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:c}),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(F=>e.jsx("th",{"aria-sort":k?.(F.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>g(F.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:F.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(F.key)||""})]})})},F.key))})}),e.jsx("tbody",{children:f.map(F=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${F.missing?"text-oai-gray-400 dark:text-oai-gray-400":F.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:M?M(F):D(F)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(F,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"conversation_count")})]},String(F?.[w]||F?.day||F?.hour||F?.month||"")))})]})}),B!=="daily"&&I.has(j)&&_>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>z(F=>Math.max(0,F-1)),disabled:T===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[T+1," / ",_]}),e.jsx("button",{type:"button",onClick:()=>z(F=>Math.min(_-1,F+1)),disabled:T+1>=_,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function Aa(t){return typeof t!="string"?"":t.trim()}function Cs(t){const a=Aa(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Zc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Aa(r.tool),n=Aa(r.planType)||Aa(r.plan_type);if(!s||!n)continue;const i=Cs(s)||s,o=Cs(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function Qc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:c}=Ne(),d=l("shared.placeholder.short"),h=l("shared.unit.percent"),x=t??l("identity_card.rank_placeholder"),g=Number.isFinite(Number(a))?Number(a):0,m=g?l("identity_card.streak_value",{days:g}):l("identity_card.rank_placeholder"),p=Zc(r),f={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev"),trillionSuffix:l("shared.unit.trillion_abbrev")},b=w=>{if(w==null)return d;const C=Ie(w,f);return C==="-"?d:C},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=i.slice(0,3);return e.jsxs(Te,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(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:c(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:c(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),v.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:v.map((w,C)=>{const D=w?.name?String(w.name):d,M=w?.percent?String(w.percent):"",A=C===v.length-1,I=C+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:I}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:D,children:D}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[M,h]})]},w.id||D)})}),p.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:p.map((w,C)=>e.jsxs(Hl,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${C}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:x})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]})]})]})}let Na=null;function Xc(){if(Na===null)try{Na=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{Na=!1}return Na}function ed(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,c=t-.1055613458*n-.0638541728*i,d=t-.0894841775*n-1.291485548*i,h=o*o*o,x=c*c*c,g=d*d*d;return[4.0767416621*h-3.3077115913*x+.2309699292*g,-1.2684380046*h+2.6097574011*x-.3413193965*g,-.0041960863*h-.7034186147*x+1.707614701*g].map(p=>{const f=Math.min(1,Math.max(0,p)),b=f<=.0031308?12.92*f:1.055*Math.pow(f,1/2.4)-.055;return Math.round(b*255)})}function Dn(t,a,r,s){if(Xc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=ed(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function At(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Dn(Number(a[1]),Number(a[2]),Number(a[3])):t}const Ts={claude:35,codex:250,grok:200},As={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 td(t,a){const r=Ts[a]??Ts.claude,s=As[t]||As.system_prompt;return Dn(s.l,s.c,r)}const ad=[{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"]}],rd=[["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"]],sd={duration:.18,ease:[.4,0,.2,1]},nd={height:0,opacity:0},od={height:"auto",opacity:1},id={height:0,opacity:0};function ld(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function cd(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 Mn(t,a=null){const r=t.reduce((o,c)=>o+Number(c.totals.total_tokens||0),0),s=ld(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const c=i===1?o.totals:cd(o.totals,i);return{...o,totals:c,percent:n>0?Number((c.total_tokens/n*100).toFixed(2)):0}}).sort((o,c)=>c.totals.total_tokens-o.totals.total_tokens)}function dd(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=ad.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const c=r.get(o);if(!c)continue;const d=c.totals||{};i.input_tokens+=d.input_tokens||0,i.cached_input_tokens+=d.cached_input_tokens||0,i.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,i.output_tokens+=d.output_tokens||0,i.reasoning_output_tokens+=d.reasoning_output_tokens||0,i.total_tokens+=d.total_tokens||0}return{key:n.key,totals:i}});return Mn(s,a)}function ud(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,x)=>x?.name==="Text Response"?h:h+Number(x?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),d=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return Mn(d,a)}const Ds="MCP: ";function md(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(Ds)?(a.push({...n,name:i.slice(Ds.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function Ms(t){return l(`dashboard.context_breakdown.category.${t}`)}function hd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function xd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),c=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:hd(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(c||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function pd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),c=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:c,total_tokens:Number(r.total_tokens||n+i)},tools:xd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}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),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function fd(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 yd(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 bd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function Ls(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 kd(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 Es(t){return t==="exec_command"||t==="Bash"}function Ln(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function _d(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function wd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const vd=10;function Ze({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:c,tokens:d,percent:h=null,children:x,share:g=null,fillColor:m=null}){const p=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:vd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:p,children:r}),s,i&&e.jsx(Ke.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(wi,{size:11})})]}),k=m&&g!=null&&g>0,v=k?Math.max(0,Math.min(100,g)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:k?{backgroundImage:`linear-gradient(to right, ${m.replace(/\)\s*$/," / 0.10)")} 0%, ${m.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:c,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children: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:h||""})]}),i&&x?e.jsx(mn,{initial:!1,children:o&&e.jsx(Ke.div,{initial:nd,animate:od,exit:id,transition:sd,style:{overflow:"hidden"},children:x},"content")}):null]})}function Rs({execDetails:t,source:a="claude"}){const{formatTokens:r}=Ne(),[s,n]=u.useState("by_type"),i=bd(kd(t,s)),o=a==="codex"||a==="grok",c=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:rd.map(([d,h])=>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(h)},d))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${c} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((d,h)=>e.jsxs(Ke.div,{role:"row",className:`grid ${c} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children: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:Ie(d.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(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:Ls(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:Ls(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)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.output_lines||0)})]},d.name))]})})]})}function Gt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Ne(),[i,o]=u.useState({}),[c,d]=u.useState(!1),h=pd(t?.categories||[]);function x(g){o(m=>({...m,[g]:!m[g]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(Ln(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(g=>{const m=g.toolCount>0,p=g.name==="Execution"&&a,f=p&&g.tools.some(k=>Es(k.name)),b=!!i[g.name];return e.jsxs(Ze,{level:1,label:g.name,labelTone:"strong",hasChevron:m||p&&!f,open:b||p&&!f&&c,onToggle:()=>{m?x(g.name):p&&!f&&d(k=>!k)},tokens:n(g.totals.total_tokens||0),percent:null,children:[m&&e.jsx("ul",{className:"space-y-0.5",children:g.tools.map(k=>{const v=p&&Es(k.name);return e.jsx(Ze,{level:2,label:k.name,labelTone:v?"accent":"default",hasChevron:v,open:c,onToggle:()=>d(w=>!w),tokens:n(k.total_tokens||0),percent:null,children:v&&e.jsx(Rs,{execDetails:a,source:r})},k.name)})}),p&&!f&&e.jsx(Rs,{execDetails:a,source:r})]},g.name)})})}function jd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null,deviceId:i=null}){const{formatTokens:o}=Ne(),[c,d]=u.useState(null),[h,x]=u.useState(!1),[g,m]=u.useState(null),[p,f]=u.useState({}),b=u.useRef({});function k(N){f(P=>({...P,[N]:!P[N]}))}if(u.useEffect(()=>{let N=!1;const P=`${t||""}|${a||""}|${r||"claude"}|${i||""}`,de=b.current[P];return d(de||null),x(!0),n?.(!0),m(null),_i({from:t,to:a,source:r,device:i,timeZone:rn(),tzOffsetMinutes:an()}).then(oe=>{N||(b.current[P]=oe,d(oe))}).catch(oe=>{N||m(oe?.message||String(oe))}).finally(()=>{N||(x(!1),n?.(!1))}),()=>{N=!0}},[t,a,r,i]),h&&!c)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(N=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${N*80}ms`}},N))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(g)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(_d(r))});if(!c||c.scope!=="supported"||!c.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(c?.reason==="local_history_only"?"settings.local_data.local_history_only":Ln(r))});const v=r==="claude"?dd(c.categories||[],s):ud(c,s),w=c.tool_calls_breakdown||null,C=c.skills_breakdown||null,D=c.message_breakdown||null,M=c.configured_resources||null,A=c.exec_command_breakdown||null,I=fd(C?.skills||[]),j=gd(D?.categories||[]),_=r==="codex"&&(c?.breakdown_status==="queue_fallback"||c?.fallback==="queue_totals"),T=r==="claude"?w?.tool_calls||null:w||null,{mcpSet:z,residualSet:B,mcpTotalTokens:U}=md(T),L=r==="claude"&&w?.subagents||null,$=L?.categories?.length>0||(M?.custom_agents_count||0)>0,V=r==="claude"?(B?.categories||[]).reduce((N,P)=>N+Number(P?.totals?.total_tokens||0),0):0,H=r==="claude"?(L?.categories||[]).reduce((N,P)=>N+Number(P?.totals?.total_tokens||0),0):0,F=[...v].sort((N,P)=>(P.totals?.total_tokens||0)-(N.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:v.filter(N=>N.percent>0).filter(N=>!(r==="claude"&&(N.key==="tool_calls"||N.key==="custom_agents"))).map(N=>`${Ms(N.key)} ${N.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[F.map(N=>{const P=N.key==="system_prompt",de=N.key==="messages",oe=N.key==="tool_calls",G=N.key==="custom_agents";if(N.key,r==="claude"&&(oe||G))return null;const ie=de&&j.length>0||oe&&(B?.categories?.length>0||_)||G&&$&&L,he=!!p[N.key],fe=td(N.key,r),ye=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:fe},"aria-hidden":"true"}),Oe=P?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(un,{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,X=N.percent>0?`${N.percent.toFixed(N.percent<.1&&N.percent>0?2:1)}%`:"0.0%";return e.jsxs(Ze,{level:0,colorSquare:ye,label:Ms(N.key),labelSuffix:Oe,tokens:o(N.totals?.total_tokens||0),percent:X,hasChevron:ie,open:he,onToggle:()=>k(N.key),share:N.percent,fillColor:fe,children:[de&&e.jsx("ul",{className:"space-y-0.5",children:j.map(O=>e.jsx(Ze,{level:1,label:yd(O),tokens:o(O.totals.total_tokens||0),percent:null},O.key||O.name))}),oe&&B&&e.jsx(Gt,{toolSet:B,execDetails:A,source:r,codexQueueFallback:_}),oe&&_&&!B&&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")}),G&&L&&e.jsx(Gt,{toolSet:L,execDetails:null,source:r,codexQueueFallback:!1})]},N.key)}),r==="claude"&&B?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(V),percent:null,hasChevron:!0,open:!!p.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Gt,{toolSet:B,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&L?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(H),percent:null,hasChevron:!0,open:!!p.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Gt,{toolSet:L,execDetails:null,source:r,codexQueueFallback:!1})}),z?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(U),percent:null,hasChevron:!0,open:!!p.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Gt,{toolSet:z,execDetails:null,source:r,codexQueueFallback:!1})}),I.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:o(I.reduce((N,P)=>N+(P.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!p.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:I.slice(0,12).map(N=>e.jsx(Ze,{level:1,label:N.name,tokens:o(N.total_tokens),percent:null},N.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(wd(r))}),_?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,M?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(M.skills_count||0)," skills ·"," ",Ie(M.mcp_servers_count||0)," MCP servers ·"," ",Ie(M.custom_agents_count||0)," agents ·"," ",Ie(M.memory_files_count||0)," memory files"]}):null]})}function En({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 ot="__all__",Nd=`${100 .toFixed(2)}%`;function ea(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function Ea(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Qt(a);return(a===tn?s:s*r)<.01?`<${n}0.01`:aa(s,{decimals:2,currency:a,rate:r})}function Sd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Fs(a)}:{key:a.key,label:a.label||Fs(a.key)}):[]}function Cd(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 Td={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 dr(t,a){const r=t?.toUpperCase?.()||"";return Td[r]||`hsl(${150+a*40}, 60%, 45%)`}function Ad(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 Dd(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 Md(t){return!!t?.models?.length}function Rn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function ur(t){const a=Rn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}function Is(t){return(Number(t?.requests)||0)>0&&!(Number(t?.usage)>0)}function Ld(t,a){const r=ea(a,t?.usage),s=Math.max(0,Number(t?.requests)||0);return r&&s>0?`${r} · ${l("usage.overview.request_count",{count:s})}`:r||(s>0?l("usage.overview.request_count",{count:s}):null)}const Ed={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Fs(t){const a=Ed[t];return a?l(a):String(t).toUpperCase()}function Rd({loading:t,onClick:a}){const r=dn();return e.jsx(ji,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(Ke.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(Ni,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function Id(){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 Fd(){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 $d({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:c,onCostInfo:d,fleetData:h=[],onRefresh:x,loading:g,announceLoading:m=!1,summaryLoading:p=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:v,customTo:w,onCustomRangeApply:C,customRangeOpen:D,onCustomRangeOpenChange:M,onOpenShare:A,from:I,to:j,deviceOptions:_=[],selectedDevice:T="",dataRevision:z=0,onDeviceChange:B,accountView:U=!1,accountScopeSwitchable:L=!1,onAccountScopeChange:$=null}){const V=Sd(a),H=yl(Si()),F=Cd(String(s??"")),N=t==="week"&&typeof I=="string"&&typeof j=="string"&&I.slice(0,7)!==j.slice(0,7),P=t!=="day"&&I&&j?`${va(I,H)} — ${va(j,H)}`:null,de=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[oe,G]=u.useState(de);u.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const S=window.matchMedia("(max-width: 639px)"),q=se=>G(se.matches);return S.addEventListener("change",q),()=>S.removeEventListener("change",q)},[]);const ie=F!=null&&!oe,he=u.useRef(null);u.useEffect(()=>{const S=he.current?.querySelector('[aria-selected="true"]');S&&typeof S.scrollIntoView=="function"&&S.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[fe,ye]=u.useState(null),{resolvedTheme:Oe}=vi(),{currency:X,rate:O}=ra(),{formatTokens:le}=Ne(),ee=Oe==="dark",ne=ee?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",ve=ee?"rgba(10,10,10,0)":"rgba(255,255,255,0)",ae=p&&!b,Z=f&&!h.some(Md);u.useEffect(()=>{ye(null)},[t,I,j,T,z]);const te=S=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(S.key))return;const q=Array.from(S.currentTarget.querySelectorAll('[role="tab"]')).filter(re=>!re.disabled),se=q.indexOf(S.target.closest('[role="tab"]'));if(se===-1||q.length===0)return;S.preventDefault();let pe=se;S.key==="Home"?pe=0:S.key==="End"?pe=q.length-1:S.key==="ArrowRight"?pe=(se+1)%q.length:pe=(se-1+q.length)%q.length,q[pe].focus(),q[pe].click()},ge=ie?e.jsx(Zl,{value:F,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:ee?0:8,gradientFrom:ne,gradientTo:ve,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,xe=h.filter(S=>S.models?.length>0&&!Is(S)),je=h.filter(S=>S.models?.length>0&&Is(S)),Ae=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="devin"),Qe=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="kiro"),Dt=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="trae"),Xe=u.useMemo(()=>zc(h),[h]),Mt=Xe.reduce((S,q)=>S+(Number(q.usage)||0),0),W=xe.reduce((S,q)=>S+(Number(q.usd)||0),0),Se=fe==null?null:fe===ot||xe.some(function(q){return q.label===fe})?fe:null;return e.jsx(Te,{className:k,children:e.jsxs("div",{"aria-busy":g||ae||Z,children:[m?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:he,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:te,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:V.map(S=>{const q=t===S.key,se=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${q?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(S.key==="custom"){const pe=q&&v&&w?`${va(v,H)} — ${va(w,H)}`:S.label;return e.jsxs(_l,{open:D,onOpenChange:re=>{re?r?.("custom"):M?.(re)},children:[e.jsx(wl,{render:e.jsx("button",{role:"tab","aria-selected":q,tabIndex:q?0:-1,type:"button",className:se}),children:pe}),e.jsx(vl,{children:e.jsx(jl,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(Nl,{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(fl,{from:v,to:w,onApply:C,onCancel:()=>M?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":q,tabIndex:q?0:-1,type:"button",className:se,onClick:()=>r?.(S.key),children:S.label},S.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[L&&$?e.jsxs("div",{role:"group","aria-label":l("usage.overview.scope_switch_aria"),className:"inline-flex shrink-0 items-center h-8 rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 p-0.5",children:[e.jsx("button",{type:"button","aria-pressed":!U,title:l("usage.overview.scope_local_tip"),onClick:()=>$("local"),className:`inline-flex items-center h-7 px-2.5 text-xs font-medium rounded-md transition-colors duration-200 ${U?"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-oai-white":"bg-oai-white dark:bg-oai-gray-600 shadow-sm text-oai-black dark:text-oai-white"}`,children:l("usage.overview.scope_local")}),e.jsx("button",{type:"button","aria-pressed":U,title:l("usage.overview.scope_account_tip"),onClick:()=>$(null),className:`inline-flex items-center h-7 px-2.5 text-xs font-medium rounded-md transition-colors duration-200 ${U?"bg-oai-white dark:bg-oai-gray-600 shadow-sm text-oai-black dark:text-oai-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-oai-white"}`,children:l("usage.overview.scope_account")})]}):null,!(L&&$)&&U?e.jsx("span",{title:l("usage.overview.scope_account_tip"),className:"inline-flex shrink-0 items-center h-8 px-2.5 text-xs font-medium rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-700 dark:text-oai-gray-300",children:l("usage.overview.scope_account")}):null,_.length>1?e.jsx(on,{value:T,onValueChange:B,options:_,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx($l,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,x&&e.jsx(Rd,{loading:g,onClick:x})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:ae?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:ge}):e.jsx("span",{title:n||void 0,children:ge})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${ae?"":"hidden"}`,children:e.jsx(Id,{})})]}),c&&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:[c,e.jsx(un,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:c})}),Dt&&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")]}),P?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:P}),N?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:Z?void 0:"hidden",children:e.jsx(Fd,{})}),(xe.length>0||je.length>0)&&e.jsxs("div",{className:"space-y-6",children:[xe.length>0&&e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:xe.map(S=>l("usage.overview.distribution_item",{label:dt(S.label),percent:ur(S)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:xe.map((S,q)=>{const se=dr(S.label,q),pe=dt(S.label),re=ur(S);return e.jsx(Ke.div,{initial:{width:0},animate:{width:`${Rn(S)}%`},transition:{duration:.5,delay:.45+q*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:se},title:`${pe}: ${re}%`},S.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":Se===ot,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:ea(le,Mt)||String(0),cost:Ea(W,X,O)||`${Qt(X)}0`,count:Xe.length}),onClick:()=>ye(Se===ot?null:ot),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${Se===ot?"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(En,{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:Nd}),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:Xe.length})})]}),xe.map((S,q)=>{const se=dr(S.label,q),pe=Se===S.label,re=dt(S.label),ue=ur(S);return e.jsxs("button",{"aria-expanded":pe,"aria-controls":`provider-details-${S.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:re,percent:ue,tokens:ea(le,S.usage)||String(0),cost:Ea(S.usd,X,O)||`${Qt(X)}0`,action:l(pe?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>ye(pe?null:S.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${pe?"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:S.label,size:15,color:se,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:re,children:re})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[ue,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:S.models.length})})]},S.label)})]}),Se===ot&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Ae&&e.jsx(Fn,{}),Qe&&e.jsx($n,{}),e.jsx(Hd,{models:Xe})]}),Se!=null&&Se!==ot&&e.jsx("div",{id:`provider-details-${Se}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:Se}),className:"mt-2",children:xe.filter(S=>S.label===Se).map(S=>{const q=dr(S.label,0),se=Ad(S),pe=[...S.models].sort((ue,Ce)=>(Ce.share||0)-(ue.share||0)),re=se?Dd(se):dt(S.label);return e.jsx(qd,{provider:S,color:q,providerHeading:re,contextSource:se,deviceId:T,from:I,to:j,sortedModels:pe},S.label)})})]}),je.length>0&&e.jsx(Kd,{providers:je})]})})}const Pd=[{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"}],zd="grid grid-cols-[minmax(0,1fr)_auto_auto_auto] items-baseline gap-x-3 mb-1.5 sm:grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_minmax(4.5rem,max-content)]";function Od({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Ne();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:Pd.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 Bd(t,a){const r=l(t==="priority"?"usage.overview.tier_fast":t==="ultrafast"?"usage.overview.tier_ultrafast":"usage.overview.tier_standard"),s=t==="standard"?0:Ic(a,t);if(!(s>1))return r;const n=Number.isInteger(s)?String(s):String(Math.round(s*100)/100);return l("usage.overview.tier_rate_label",{label:r,rate:n})}function Ud({model:t}){const{currency:a,rate:r}=ra(),{formatTokens:s,formatTokensTooltip:n}=Ne();if(!jn(t))return null;const i=[{key:"standard",split:Fc(t)},...Xt.map(o=>({key:o,split:t?.tiers?.[o]||null}))].filter(o=>o.split&&(La(o.split.tokens)>0||o.split.cost>0));return i.length?e.jsx("div",{className:"mb-1.5 flex flex-col gap-y-1","data-model-speed-tiers":!0,children:i.map(o=>{const c=La(o.split.tokens);return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 text-[11px] tabular-nums",children:[e.jsx("span",{className:"min-w-[8rem] text-oai-gray-500 dark:text-oai-gray-400",children:Bd(o.key,t)}),e.jsx("span",{title:n(c),className:"text-oai-gray-600 dark:text-oai-gray-300",children:s(c)}),e.jsx("span",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:Ea(o.split.cost,a,r)})]},o.key)})}):null}function $s({model:t,tokensLabel:a,costLabel:r,unpricedLabel:s,expandable:n,isExpanded:i}){const{formatTokensTooltip:o}=Ne();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",{title:s?l("dashboard.cost_breakdown.unpriced"):void 0,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??s}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(i?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(kl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${i?"rotate-180":""}`})]})]})]})}function In({models:t,color:a}){const{currency:r,rate:s}=ra(),{formatTokens:n}=Ne(),[i,o]=u.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(c=>{const d=Ld(c,n),h=Ea(c.cost,r,s),x=!h&&Number(c.usage)>0&&Lr(c)?l("dashboard.cost_breakdown.unpriced_label"):null,g=Math.max(0,Math.min(100,Number(c.share)||0)),m=c.id||c.name,p=Lc(c),f=p&&i===m,b=zd,k={model:c,tokensLabel:d,costLabel:h,unpricedLabel:x,expandable:p,isExpanded:f};return e.jsxs("div",{"data-model-rank-row":!0,children:[p?e.jsx("button",{type:"button",onClick:()=>o(f?null:m),"aria-expanded":f,className:`${b} w-full cursor-pointer text-left`,children:e.jsx($s,{...k})}):e.jsx("div",{className:b,children:e.jsx($s,{...k})}),f&&e.jsxs(e.Fragment,{children:[e.jsx(Od,{tokens:c.tokens}),e.jsx(Ud,{model:c})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":g,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${g}%`,backgroundColor:a,opacity:.45}})})]},m)})})}function Hd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(En,{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(In,{models:t,color:"var(--oai-blue)"})]})}function Fn(){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 $n(){return e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.kiro_notice_title"),"."]})," ",l("usage.overview.kiro_notice_body")]})}function Kd({providers:t}){const a=t.map(r=>l("usage.overview.request_only_item",{label:dt(r.label),count:Math.max(0,Number(r.requests)||0)})).join(l("usage.overview.request_only_separator"));return e.jsx("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:l("usage.overview.request_only_note",{items:a})})}function qd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o,deviceId:c}){const{formatTokens:d}=Ne(),[h,x]=u.useState(!1),g=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",m=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",p=String(t?.source||t?.label||"").trim().toLowerCase()==="kiro";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(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&&h&&e.jsx(bl,{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:ea(d,t.cacheReusedTokens)||String(0),input:ea(d,t.cacheInputTokens)||String(0)})]}),g&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),m&&e.jsx(Fn,{}),p&&e.jsx($n,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(jd,{from:n,to:i,source:s,deviceId:c,referenceTotalTokens:t.usage,onLoadingChange:x})}):null,e.jsx(In,{models:o,color:a})]})}function Vd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:c,isDragging:d}=tl({id:t}),h=u.useRef(null),x=u.useRef(null);u.useLayoutEffect(()=>{if(!r)return;const m=h.current?h.current.childNodes.length===0:!0;x.current!==m&&(x.current=m,r(t,m))});const g={transform:al.Transform.toString(o)||void 0,transition:c,zIndex:d?20:void 0};return e.jsxs("div",{ref:i,style:g,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:h,"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 Wd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,x]=u.useState(null),g=st([t,a,r,s,n]),m=u.useCallback(async()=>{if(!t)return;const p=g();d(!0),x(null);try{const f=await ze(s);if(!p())return;const b=await Ci({from:a,to:r,device:n,accessToken:f});if(!p())return;o(b||null)}catch(f){if(!p())return;x(f?.message||String(f)),o(null)}finally{p()&&d(!1)}},[t,a,r,s,n,g]);return u.useEffect(()=>{if(!t){o(null),x(null),d(!1);return}o(null),x(null),d(!0),m()},[t,m]),{data:i,loading:c,error:h,refresh:m}}function Pn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function zn(t){return t==null?"—":`${Math.round(t*100)}%`}function Gd(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 Yd({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:Pn(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:zn(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:Gd(t.cost_usd,t.accepted)})]})}function Jd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Ne(),{enabled:i}=Sl(),{data:o,loading:c}=Wd({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const d=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(m=>m.outcomes>0&&m.key!=="unknown");if(!d.length)return null;const h=d.slice(0,6),x=o.totals||{},g=`${l("qpd.card.subtitle")}${c?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(Te,{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:g}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(m=>e.jsx(Yd,{row:m},m.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:x.accepted??0,outcomes:x.outcomes??0,cost:Pn(x.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(x.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(x.effective_tokens),rate:zn(x.acceptance_rate)})})]}),x.outcomes<15&&e.jsxs("p",{className:"mt-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500 italic border-t border-oai-gray-100 dark:border-oai-gray-800/40 pt-2",children:["* ",l("qpd.card.sparse_notice","Tip: Spark outcomes dataset might skew Quality/$ ratios. For precise metrics, select a narrower time window.")]})]})}const Zd=new Set(["unknown","synthetic","openai"]);function mr(t){return t==null?"—":`${Math.round(t*100)}%`}function Qd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Je(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function Xd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Zd.has(r)&&Number(t?.edit_turns||0)>0}function Ps(){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 eu({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=u.useState({requestKey:null,loading:!0,sessions:null,context:null}),i=s.requestKey===r?s:{loading:!0,sessions:null,context:null},o=u.useId(),{enabled:c}=Cl(),d=st([c,t,a]),{formatTokens:h}=Ne(),x=C=>h(C,{mode:Jt.COMPACT});u.useEffect(()=>{const C=d();if(!c){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Ti({from:t,to:a}),Ai()]).then(([D,M])=>{C()&&n({requestKey:r,loading:!1,sessions:D,context:M})}).catch(()=>{C()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[c,t,a,r,d]);const g=u.useMemo(()=>(i.sessions?.by_model||[]).filter(Xd).slice(0,5),[i.sessions]),m=u.useMemo(()=>(i.sessions?.subagents||[]).slice(0,3),[i.sessions]);if(!c||!i.loading&&!i.sessions?.available&&!i.context?.estimated_fixed_tokens)return null;const p=i.sessions?.summary||{},f=p.edit_session_rate??p.productive_rate,b=p.first_pass_rate??p.one_shot_rate,k=p.edit_sessions??p.productive_sessions??0,v=p.sessions??i.sessions?.session_count??0,w=p.edit_turns??0;return i.loading&&!i.sessions&&!i.context?e.jsxs(Te,{children:[e.jsx(Ps,{}),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(Te,{children:[e.jsx(Ps,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(hr,{label:l("sessions.card.edit_sessions"),value:mr(f),detail:l("sessions.card.edit_session_value",{edits:Je(k),sessions:Je(v)})}),e.jsx(hr,{label:l("sessions.card.first_pass"),value:mr(b),detail:l("sessions.card.edit_session_value",{edits:Je(p.first_pass_sessions??p.one_shot_sessions??0),sessions:Je(k)})}),e.jsx(hr,{label:l("sessions.card.cost_edit"),value:Qd(p.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Je(w)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Je(v),edits:Je(w)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":o,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:o,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")})]})]}),!!g.length&&e.jsx(Wi,{wrapperClassName:"w-full",label:l("sessions.card.scroll"),children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium whitespace-nowrap",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:g.map(C=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:C.model,children:C.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:l("sessions.card.edit_session_value",{edits:Je(C.edit_sessions??C.productive_sessions??0),sessions:Je(C.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:mr(C.first_pass_rate??C.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums whitespace-nowrap",children:x(C.tokens_per_edit)})]},C.model))})]})}),i.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:x(i.context.estimated_fixed_tokens)})]}):null,!!m.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),m.map(C=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:C.name,calls:Math.round(C.calls)})},C.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function hr({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 tu(){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 au(){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(Te,{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(Te,{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(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(tu,{})]})}),e.jsx(Te,{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(Te,{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(Te,{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 ru=Ll.slice(0,10),zs=.06,su=.11,nu=.05;function Os({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(Ml,{logos:ru,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(Ke.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 ou(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:c,activeDays:d,identitySubscriptions:h,identityScrambleDurationMs:x,projectUsageEntries:g,projectUsageLimit:m,setProjectUsageLimit:p,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:v,isLocalMode:w,accountView:C,accountScopeSwitchable:D,onAccountScopeChange:M,shouldShowInstall:A,installPrompt:I,handleCopyInstall:j,installCopied:_,installInitCmdDisplay:T,trendRowsForDisplay:z,trendFromForDisplay:B,trendToForDisplay:U,trendZoomConfig:L,usageFrom:$,usageTo:V,period:H,trendTimeZoneLabel:F,activityHeatmapBlock:N,periodsForDisplay:P,setSelectedPeriod:de,customFrom:oe,customTo:G,onCustomRangeApply:ie,customRangeOpen:he,onCustomRangeOpenChange:fe,summaryLabel:ye,summaryValue:Oe,summaryFullValue:X,hasSummary:O,summaryLoading:le,providersLoading:ee,onToggleSummaryFormat:ne,summaryTotalTokensRaw:ve,summaryCostValue:ae,summaryConversationsValue:Z,rollingUsage:te,costInfoEnabled:ge,openCostModal:xe,costModalOpen:je,closeCostModal:Ae,allowBreakdownToggle:Qe,refreshAll:Dt,usageLoadingState:Xe,announceUsageLoading:Mt,initialDashboardLoading:W,fleetData:Se,hasDetailsActual:S,dailyEmptyPrefix:q,installSyncCmd:se,dailyEmptySuffix:pe,detailsColumns:re,ariaSortFor:ue,toggleSort:Ce,sortIconFor:Fe,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Ia,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Fa,detailsDateKey:$a,renderDetailDate:pt,renderDailyBreakdownDate:Q,renderDetailCell:sa,DETAILS_PAGED_PERIODS:be,detailsPageCount:ke,detailsPage:Et,setDetailsPage:gt,deviceOptions:_e,selectedDevice:ft,onDeviceChange:Pa,deviceUsageBlock:Rt,localHistoryOnly:na,localHistoryRevision:It,leftCardOrder:oa,onLeftReorder:Ft,rightCardOrder:Be,onRightReorder:De}=t,$t=null,yt=null,Pt={statsPanel:!0,installCopy:A,activityHeatmap:!!N,deviceUsage:!!Rt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},za=(oa||[]).filter(me=>Pt[me]),ia={usageOverview:!0,dataDetails:!s},Oa=(Be||[]).filter(me=>ia[me]);function la(me,J){switch(me){case"statsPanel":return e.jsx(nt,{delay:J,children:e.jsx(Qc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:H,startDate:c??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:h,periodConversations:Z,rolling:te,topModels:b})});case"installCopy":return e.jsx(nt,{delay:J,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:I}),e.jsxs(Ke.button,{onClick:j,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:T}),e.jsx(Ke.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:_?"Copied ✓":"Copy"},_?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(nt,{delay:J,children:N});case"deviceUsage":return e.jsx(nt,{delay:J,children:Rt});case"trendMonitor":return e.jsx(nt,{delay:J,children:e.jsx(sn,{rows:z,from:B,to:U,period:H,timeZoneLabel:F,showTimeZoneLabel:!1,zoomConfig:L})});case"qualityPerDollar":return e.jsx(Jd,{from:$,to:V,deviceId:ft});case"sessionInsights":return e.jsx(eu,{from:$,to:V});default:return null}}function zt(me,J){switch(me){case"usageOverview":return e.jsx(nt,{delay:J,children:e.jsx($d,{accountView:C,accountScopeSwitchable:D,onAccountScopeChange:M,period:H,periods:P,onPeriodChange:de,summaryLabel:ye,summaryValue:Oe,summaryFullValue:X,hasSummary:O,summaryLoading:le,providersLoading:ee,onToggleSummaryFormat:O?ne:null,summaryCostValue:ae,onCostInfo:ge?xe:null,fleetData:Se,onRefresh:s?null:Dt,loading:Xe,announceLoading:Mt,onOpenShare:s?null:r,customFrom:oe,customTo:G,onCustomRangeApply:ie,customRangeOpen:he,onCustomRangeOpenChange:fe,from:$,to:V,deviceOptions:_e,selectedDevice:ft,dataRevision:It,onDeviceChange:Pa})});case"dataDetails":return e.jsx(nt,{delay:J,children:e.jsx(Jc,{projectEntries:g,projectLimit:m,onProjectLimitChange:p,projectDetailQuery:f,copy:a,hasDetailsActual:S,dailyEmptyPrefix:q,installSyncCmd:se,dailyEmptySuffix:pe,detailsColumns:re,ariaSortFor:ue,toggleSort:Ce,sortIconFor:Fe,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Ia,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Fa,detailsDateKey:$a,renderDetailDate:pt,renderDailyBreakdownDate:Q,renderDetailCell:sa,DETAILS_PAGED_PERIODS:be,period:H,detailsPageCount:ke,detailsPage:Et,setDetailsPage:gt})});default:return null}}const Ba=rl(ms(cl,{activationConstraint:{distance:6}}),ms(ll,{coordinateGetter:il})),Ot=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||Ft?.(String(J.id),String($e.id))},[Ft]),Bt=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||De?.(String(J.id),String($e.id))},[De]);function ca(me,J,$e,ua){return s?e.jsx(e.Fragment,{children:me.map((Ge,Ut)=>e.jsx(Nt.Fragment,{children:J(Ge,$e+zs*Ut)},Ge))}):e.jsx(sl,{sensors:Ba,onDragEnd:ua,children:e.jsx(nl,{items:me,strategy:ol,children:me.map((Ge,Ut)=>e.jsx(Vd,{id:Ge,children:J(Ge,$e+zs*Ut)},Ge))})})}const We=ca(za,la,su,Ot),da=ca(Oa,zt,nu,Bt);return e.jsxs(e.Fragment,{children:[e.jsxs(Ul,{bare:!s,hideHeader:s,header:$t,footer:s?null:yt,className:s?"screenshot-mode":"",children:[i&&e.jsx(Os,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Os,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&W&&e.jsx(au,{}),!i&&!n&&!W&&e.jsxs(e.Fragment,{children:[na&&e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.local_data.local_history_only")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:We}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:da})]})]})]}),e.jsx(Uc,{isOpen:je,onClose:Ae,fleetData:Se})]})}function iu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0,localView:c=!1}={}){const d=c&&!n&&El(),h=!!(d||n&&i),[x,g]=u.useState(0),[m,p]=u.useState([]),[f,b]=u.useState([]),[k,v]=u.useState(!1),[w,C]=u.useState(null),D=st([h,d,t,a,r,s,i,o]),M=u.useCallback(async()=>{const A=D();if(!h){p([]),b([]),v(!1),C(null);return}v(!0),C(null);try{const I=d?null:await ze(i);if(!A())return;const j=d?await Tl({from:t,to:a,timeZone:r,tzOffsetMinutes:s}):await Di({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:I});if(!A())return;p(Array.isArray(j?.devices)?j.devices:[]),b(Array.isArray(j?.account_sources)?j.account_sources:[]),g(d&&Number(j?.revision)||0)}catch(I){if(!A())return;C(I?.message||String(I)),p([]),b([])}finally{A()&&v(!1)}},[h,d,i,t,a,r,s,o,D]);return u.useEffect(()=>{if(d)return window.addEventListener(hs,M),()=>window.removeEventListener(hs,M)},[d,M]),u.useEffect(()=>{p([]),b([]),C(null),h&&v(!0),M()},[h,M]),{devices:m,accountSources:f,loading:k,error:w,refresh:M,revision:x}}const lu=/^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 _r(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(lu);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 Us=" · ",Hs="%";function Ks({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Fl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(ss,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(ss,{className:a,"aria-hidden":!0}):e.jsx(hn,{className:a,"aria-hidden":!0})}function qs(t,a){return a===t?.id||t?.isCurrent===!0}function cu({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:c}=Ne(),[d,h]=u.useState(""),[x,g]=u.useState(""),[m,p]=u.useState(!1),[f,b]=u.useState(""),k=typeof i=="function",v=typeof n=="function",w=!!s,C=t.reduce((_,T)=>_+(Number(T.total_tokens)||0),0)+a.reduce((_,T)=>_+(Number(T.total_tokens)||0),0),D=u.useMemo(()=>t.filter(_=>(Number(_.total_tokens)||0)>0||_.id===s).sort((_,T)=>(Number(T.total_tokens)||0)-(Number(_.total_tokens)||0)),[t,s]);function M(_){b(""),h(_.id);const T=typeof _.device_name=="string"?_.device_name:"";g(_r(_)===T?T:"")}function A(){h(""),g(""),b("")}async function I(_){const T=x.trim();if(!(!T||m)){p(!0),b("");try{await i(_.id,T),h(""),g("")}catch{b(_.id)}finally{p(!1)}}}const j=a.filter(_=>(Number(_.total_tokens)||0)>0);return D.length===0&&j.length===0?e.jsxs(Te,{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(hn,{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(Te,{bodyClassName:"!px-3 !py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:l("dashboard.device_card.title")}),v&&w&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[D.map(_=>{const T=Number(_.total_tokens)||0,z=C>0?(T/C*100).toFixed(1):"0.0",B=s===_.id,U=_r(_)||l("dashboard.device_card.unnamed"),L=d===_.id,$=B?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",V=w&&!B?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[L?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(Ks,{platform:_.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:x,disabled:m,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:H=>g(H.target.value),onKeyDown:H=>{H.key==="Enter"?I(_):H.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:m||!x.trim(),onClick:()=>I(_),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Rl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:m,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Ar,{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 ${$}`,style:{width:`${z}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":B,"aria-label":`${l("dashboard.device_filter.aria")}: ${U}${qs(_,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(B?"":_.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 ${V} ${B?"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(Ks,{platform:_.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:U,children:U}),qs(_,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")}),_.imported_at&&e.jsx("span",{className:"shrink-0 whitespace-nowrap text-xs text-oai-gray-500",title:l("settings.local_data.snapshot_time",{time:new Date(_.exported_at).toLocaleString()}),children:l("settings.local_data.imported_label")})]}),e.jsxs("span",{title:c(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Us,z,Hs]})]})]}),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 ${$}`,style:{width:`${z}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>M(_),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(Al,{className:"h-3 w-3"})})]}),f===_.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},_.id)}),j.map(_=>{const T=Number(_.total_tokens)||0,z=C>0?(T/C*100).toFixed(1):"0.0",B=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${B}`,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:_.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:dt(_.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:c(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Us,z,Hs]})]})]}),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:`${z}%`}})})]},`account-${_.source}`)})]})]})}function On(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function Bn(){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 du(t){if(!On()||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"};Bn();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,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Vs(t,a){if(!On()||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"};Bn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){ut.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Un=1200,Hn=1630,Kn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},uu="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 xr=!1;function mu(){if(typeof document>"u"||xr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){xr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=uu,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),xr=!0}async function hu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function xu(t,a={}){if(typeof window>"u"||!t)return null;mu(),await hu(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Mi(async()=>{const{toBlob:d,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Un,o=t.offsetHeight||Hn,c={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,c);if(d)return d}catch{}try{const d=await s(t,c);return d?await(await fetch(d)).blob():null}catch{return null}}async function pr(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 Ws(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=K(t);return Number.isFinite(a)?a:0}function pu(t){return t?wr(t.billable_total_tokens??t.total_tokens):0}function gu(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(c=>{const d=!!c?.future,h=Number.isFinite(c?.level)?Math.max(0,Math.min(4,Math.round(c.level))):0;c?.day&&!d&&(r+=1,h>0&&(s+=1));const x=c?.billable_total_tokens??c?.total_tokens??c?.value??0,g=Number.isFinite(x)?Math.max(0,x):0;return{day:typeof c?.day=="string"?c.day:"",level:h,value:g,future:d}})),totalDays:r,activeDays:s}}function fu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:c,periodFrom:d,periodTo:h,heatmap:x,capturedAt:g,currency:m,exchangeRate:p}=t,f=pu(n),b=wr(n?.total_cost_usd),k=Array.isArray(i)?i.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"})):[],v=gu(x);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:c,periodFrom:d,periodTo:h,topModels:k,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:g||new Date().toISOString(),currency:typeof m=="string"&&m.length>0?m.toUpperCase():"USD",exchangeRate:Number.isFinite(p)&&p>0?p:1}}const yu=["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 bu(t){const a=yu[t];return a?l(a):"—"}function qn(t,a){return l("share.date.month_year",{month:bu(t),year:a})}function ku(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:qn(n,r)}function _u(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 qn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function vr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Vn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Qt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function wu(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 vu(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 ju(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 Nu({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],c=i||o[0],d=t.length,h=(d-1)*s,x=Math.max(4,(r-h)/d),g=7*x+6*s;return e.jsx("svg",{width:r,height:g,viewBox:`0 0 ${r} ${g}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((m,p)=>(Array.isArray(m)?m:[]).map((b,k)=>{if(k>=7)return null;const v=ju(b),w=p*(x+s),C=k*(x+s),D=v===null?c:o[v];return e.jsx("rect",{x:w,y:C,width:x,height:x,rx:n,ry:n,fill:D},`${p}-${k}`)}))})}const Su=At("oklch(0.97 0.01 85)"),Re=At("oklch(0.18 0.02 85)"),at=At("oklch(0.38 0.015 85)"),Gs=At("oklch(0.55 0.012 85)"),it=At("oklch(0.55 0.22 25)"),lt='"Instrument Serif", "Times New Roman", Georgia, serif',Cu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Tu=["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=_u(t),r=vr(t.totalTokens),s=Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=ku(t.startDate),i=vu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=wu(t),c=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Su,color:Re,fontFamily:Cu,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 ${Gs}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:it}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:at,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:at,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:lt,fontSize:52,fontStyle:"italic",lineHeight:1,color:Re,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:at,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Re},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:it,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:lt,fontSize:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:lt,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:it,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:at},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})})]})]}),c?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:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Nu,{weeks:t.heatmapWeeks,palette:Tu,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 ${Re}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:lt,fontStyle:"italic",fontSize:26,color:at,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((d,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Gs}`},children:[e.jsx("div",{style:{fontFamily:lt,fontSize:34,fontStyle:"italic",color:it,lineHeight:1},children:String(h+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:lt,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),e.jsx("div",{style:{fontFamily:lt,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:vr(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},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:it},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:it},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:it},children:"→ tokentracker.cc"})]})]})]})}const Au=Kn["annual-report"].width,Du="#0a0820",rt="#ffffffee",ct="rgba(255,255,255,0.45)",gr="#a78bfa",Mu={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(", ")},Sa={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"},jr='"Space Grotesk", "Inter Tight", sans-serif',fr='"Inter Tight", sans-serif',Lu="rgba(255,255,255,0.06)",Gn=[Lu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Yn=48,Jn=28,Ra=4,Zn=20,Eu=Au-Yn*2-Jn*2,Ru=(Eu-Zn*2)/3,Nr=Math.min(Math.floor((Ru-Ra*6)/7),40),Iu=Nr*7+Ra*6;function Fu(t){if(!Array.isArray(t))return t;const a=[];for(const c of t)if(Array.isArray(c))for(const d of c)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((c,d)=>c-d);const r=c=>{const d=a.length,h=(d-1)*c,x=Math.floor(h);return Math.round((a[x]??0)+((a[Math.min(d-1,x+1)]??0)-(a[x]??0))*(h-x))},s=r(.5),n=r(.75),i=r(.9),o=c=>!c||c<=0?0:c<=s?1:c<=n?2:c<=i?3:4;return t.map(c=>Array.isArray(c)?c.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:o(d.value)}:d):c)}function $u(t){if(!Array.isArray(t))return[];const a={},r=Fu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Pu(t){if(!t.length)return[];const a=[...t].sort((o,c)=>o.day.localeCompare(c.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const zu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ou(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Ys(t){const[a,r]=u.useState(null);return u.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Bu({data:t}){const a=Pu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:ct,fontFamily:jr,marginBottom:4},children:zu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ra},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ra},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:Nr,height:Nr,borderRadius:4,background:o<0?"transparent":Gn[o]}},i)})},s))})]})}function Uu({data:t}){const a=$u(t.heatmapWeeks),r=Ou(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Ys(n),o=Ys("/neon_bg.png"),c=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Du,fontFamily:jr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Yn,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:ct,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:rt},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:c})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...Mu,borderRadius:22,padding:Jn,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:ct},children:[e.jsx("span",{children:l("share.card.annual.less")}),Gn.map((h,x)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},x)),e.jsx("span",{children:l("share.card.annual.more")})]}),e.jsx("div",{style:{fontSize:16,fontWeight:700,letterSpacing:"0.14em",color:"rgba(255,255,255,0.22)",textTransform:"uppercase"},children:l("share.card.annual.heatmap_title")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(3,${Iu}px)`,gap:`8px ${Zn}px`,justifyContent:"center"},children:a.map(h=>e.jsx(Bu,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{...Sa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:fr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:vr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:ct,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...Sa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:fr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:ct,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},children:[e.jsxs("div",{style:{...Sa,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:gr,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:ct},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:fr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...Sa,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:gr,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:ct},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:jr,fontSize:28,fontWeight:700,color:rt},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:rt},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:gr},children:"tokentracker.cc"})]})]})]})}const Qn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Hu={broadsheet:Wn,"annual-report":Uu};function Xn(t){return Kn[t]||{width:Un,height:Hn}}function Ku(t){const a=Qn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Js=u.forwardRef(function({data:a,variant:r},s){const n=Hu[r]||Wn,{width:i,height:o}=Xn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function Ca(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const qu=440;function Vu(){const[t,a]=u.useState(null),r=u.useRef(null),s=u.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return u.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function yr({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 Wu({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState("annual-report"),x=u.useRef(null),{toast:g,push:m}=Vu(),p=Li(),f=u.useMemo(()=>{const j=p?.user;if(!j||typeof j!="object")return null;const _=j.user_metadata||{},T=j.profile||{},z=_.avatar_url||_.picture||T.avatar_url||j.avatar_url;return typeof z=="string"&&z.trim()?z.trim():null},[p?.user]);u.useEffect(()=>{t&&(i(null),c(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:o||r.handle,avatarUrl:f},{width:k,height:v}=Xn(d),w=qu/k;u.useEffect(()=>{if(!t)return;const j=_=>{_.key==="Escape"&&a?.()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[t,a]);const C=u.useCallback(async()=>{const j=x.current;if(!j)return null;try{return await xu(j)}catch(_){return console.warn("[share] capture failed",_),null}},[]),D=u.useCallback(async()=>{if(n)return;i("copy");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}let _=!1;if(Ca()){const T=await pr(j);T&&(_=(await du(T)).ok)}else _=await ns(j);m(_?l("share.toast.copied"):l("share.toast.failed"),_?"success":"error"),i(null)},[n,C,m]),M=u.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=u.useCallback(async()=>{if(n)return;i("download");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}if(Ca()){const T=await pr(j);if(T&&(await Vs(T,M())).ok){m(l("share.toast.downloaded"),"success"),i(null);return}}const _=Ws(j,M());m(_?l("share.toast.downloaded"):l("share.toast.failed"),_?"success":"error"),i(null)},[n,C,M,m]),I=u.useCallback(async()=>{if(n)return;i("x");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}if(Ca()){const B=await pr(j);B&&(await Vs(B,M()),m(l("share.toast.downloaded"),"success"))}else await ns(j)?m(l("share.toast.copied"),"success"):Ws(j,M());const _=new URL("https://twitter.com/intent/tweet");s&&_.searchParams.set("text",s);const T=p?.user?.id,z=typeof T=="string"&&T?`/u/${T}`:"/";if(_.searchParams.set("url",`https://www.tokentracker.cc${z}?ref=share`),Ca())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:_.toString()})}catch{window.open(_.toString(),"_blank","noopener,noreferrer")}else window.open(_.toString(),"_blank","noopener,noreferrer");i(null)},[n,C,m,s,M,p]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:j=>{j.target===j.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Js,{ref:x,data:b,variant:d})}),e.jsxs(Ke.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},transition:{duration:.18,ease:[.2,.8,.2,1]},className:"relative w-full max-w-[1040px] max-h-[92vh] overflow-hidden rounded-2xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-black shadow-oai-lg",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row max-h-[92vh]",children:[e.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-7 bg-oai-gray-50 dark:bg-oai-gray-950 flex items-center justify-center overflow-auto",children:e.jsxs("div",{style:{width:k*w,height:v*w,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:v,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Js,{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:o,onChange:j=>c(j.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:Qn.map(j=>e.jsx("button",{type:"button",onClick:()=>h(j.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===j.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Ku(j.id)},j.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(yr,{onClick:I,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(yr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(yr,{onClick:D,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(mn,{children:g?e.jsx(Ke.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",g.kind==="error"?"bg-red-600 text-white":g.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:g.text})},g.id):null})]})]}):null}function Gu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:c,periodFrom:d,periodTo:h,heatmap:x,accessToken:g,userId:m,currency:p,exchangeRate:f}=t,[b,k]=u.useState(null),v=f;return u.useEffect(()=>{if(!a||!m&&!ht())return;let w=!1;return(async()=>{try{const D=await Ei({accessToken:g,userId:m,period:c==="day"||c==="custom"?"week":c,metric:"all",limit:100,offset:0});if(w)return;const A=(Array.isArray(D?.entries)?D.entries:Array.isArray(D)?D:[]).find(j=>j?.is_me===!0),I=typeof A?.rank=="number"?A.rank:null;k(I)}catch{w||k(null)}})(),()=>{w=!0}},[a,g,m,c]),u.useMemo(()=>fu({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:b,period:c,periodFrom:d,periodTo:h,heatmap:x,currency:p,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,i,o,b,c,d,h,x,p,v])}function Zs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const Yu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function Ju({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const Zu=["day","week","month","total","custom"],br=new Set(["day","hour","month"]),Yt=new Set(["day","total","custom"]),Qu=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Xu=["usageOverview","dataDetails"];function kr(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 Ta(t){return t?Ct(t,null):null}function Qs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function em(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function tm(){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:!em(window.location.hostname)}function Hm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:c="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:h}){const{resolvedLocale:x}=Ri(),{currency:g,rate:m}=ra(),{mode:p,setMode:f,formatTokens:b,formatTokensTooltip:k}=Ne(),[v,w]=u.useState(!1),[C,D]=u.useState(null),[M,A]=u.useState(null),[I,j]=u.useState(!1),[_,T]=u.useState(null),[z,B]=u.useState(0),[U,L]=u.useState(0),[$,V]=u.useState(null),H=u.useMemo(()=>typeof window>"u"?!1:Ii(window.location.search),[]),F=u.useMemo(()=>tm(),[]),[N,P]=u.useState(!1),de=2200,[oe,G]=u.useState(!0),[ie,he]=u.useState(!1),[fe,ye]=u.useState(!1),[Oe,X]=u.useState(!1),[O,le]=u.useState(!1),ee=u.useRef(!1),ne=ht(),ve=r&&!s,ae=u.useMemo(()=>ve&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,ve]),Z=ve?ae:null,te=i?Fi(o):Z,ge=r||ne||i,xe=ve&&ta(Z),je=r&&s&&!i,{accountView:Ae,revision:Qe,resolving:Dt,scopeSwitchable:Xe,setScopeOverride:Mt}=$i(),W=Ae&&!i,Se=Xe&&!i,S=W?Z:null,q=Dt&&!i;u.useEffect(()=>{if(!r||ne){D(null),A(null),j(!1),T(null);return}if(i)return;if(!xe){D(null),A(null),j(!1),T(null);return}let y=!0;const E=()=>{D(null),A(null),j(!1),T(null)};return j(!0),T(null),(async()=>{let R=null;try{R=await ze(Z)}catch{R=null}if(y){if(!R){E();return}try{const Y={link_code:null,expires_at:null};if(!y)return;D(typeof Y?.link_code=="string"?Y.link_code:null),A(typeof Y?.expires_at=="string"?Y.expires_at:null)}catch(Y){if(!y)return;D(null),A(null),T(Y?.message||"Failed to load link code")}finally{if(!y)return;j(!1)}}})(),()=>{y=!1}},[t,ne,r,i,xe,Z,U]);const se=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");u.useEffect(()=>{if(!se&&(!r||ne||i)){V(null);return}if(!se&&!xe){V(null);return}let y=!0;return(async()=>{let E=null;try{E=await ze(Z)}catch{E=null}if(y){if(!E&&!se){V(null);return}try{const R=await Pi({baseUrl:t,accessToken:E});if(!y)return;V(R&&typeof R=="object"?R:null)}catch{if(!y)return;V(null)}}})(),()=>{y=!1}},[xe,t,Z,ne,i,r]);const pe=u.useMemo(()=>{if(!M)return!1;const y=Date.parse(M);if(!Number.isFinite(y))return!1;const E=z||Date.now();return y<=E},[M,z]);u.useEffect(()=>{!r||ne||i||!M||!pe||I||(D(null),A(null),T(null),L(y=>y+1))},[pe,M,I,ne,r]),u.useEffect(()=>{if(!M||i)return;const y=Date.parse(M);if(!Number.isFinite(y))return;const E=Date.now();if(B(E),y<=E)return;const R=window.setTimeout(()=>B(Date.now()),y-E),Y=()=>{typeof document>"u"||document.visibilityState==="visible"&&B(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",Y),window.addEventListener("focus",Y),()=>{window.clearTimeout(R),typeof document<"u"&&document.removeEventListener("visibilitychange",Y),window.removeEventListener("focus",Y)}},[M]);const re=u.useMemo(()=>rn(),[]),ue=u.useMemo(()=>an(),[]),Ce=u.useMemo(()=>zi(),[]),Fe=i?null:a?.userId||a?.email||"default",[Lt,xt]=u.useState("month"),[qe,Ia]=u.useState(null),[et,Fa]=u.useState(null),[$a,pt]=u.useState(!1),Q=H?"total":Lt,sa=u.useMemo(()=>Q==="custom"&&qe&&et?{from:qe,to:et}:Oi(Q,{timeZone:re,offsetMinutes:ue,now:Ce}),[Ce,Q,re,ue,qe,et]),be=sa.from,ke=sa.to,[Et,gt]=u.useState(null),_e=Et&&Et.startsWith("local:")!==W?Et:null,[ft,Pa]=u.useState(()=>os());u.useEffect(()=>{const y=()=>Pa(os());return window.addEventListener(is,y),window.addEventListener("storage",y),()=>{window.removeEventListener(is,y),window.removeEventListener("storage",y)}},[]);const{devices:Rt,accountSources:na,refresh:It,loading:oa,revision:Ft}=iu({from:be,to:ke,timeZone:re,tzOffsetMinutes:ue,accountView:W,accountAccessToken:S,accountRevision:Qe,localView:!i&&!ne}),Be=W?Qe:Ft,De=u.useMemo(()=>Rt.filter(y=>!W||(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.isCurrent||y.id===ft})),[Rt,ft,W]),$t=u.useMemo(()=>na.filter(y=>(Number(y.total_tokens)||0)>0),[na]),yt=De.length>=2,Pt=(W||De.length>=2)&&De.length+$t.length>=2;u.useEffect(()=>{if(!oa){if(!yt&&!Pt){_e!==null&&gt(null);return}_e&&!De.some(y=>y.id===_e)&&gt(null)}},[yt,Pt,De,_e,oa]);const za=u.useMemo(()=>yt?[{value:"",label:l("dashboard.device_filter.all")},...De.map(y=>{const E=_r(y)||l("dashboard.device_card.unnamed"),R=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${E}${R}`}})]:[],[yt,De,x]),ia=W?{devices:De,accountSources:$t}:Dl(De,$t,_e),Oa=Pt?e.jsx(cu,{devices:ia.devices,accountSources:ia.accountSources,currentDeviceId:ft,selectedDeviceId:_e||"",onSelectDevice:y=>gt(y||null),onRenameDevice:W?async(y,E)=>{const R=await ze(S);await Vi({deviceId:y,name:E,accessToken:R}),await It()}:void 0}):null,la=u.useMemo(()=>Bi({timeZone:re,offsetMinutes:ue}),[re,ue]),zt=u.useMemo(()=>Ui({timeZone:re,offsetMinutes:ue}),[re,ue]),Ba=u.useMemo(()=>`Local time (${zt})`,[zt]),Ot=re,Bt=ue,ca=la,We=u.useMemo(()=>Tr({timeZone:re,offsetMinutes:ue,date:Ce||new Date}),[Ce,re,ue]),da=u.useMemo(()=>Sc({period:Q,selectedFrom:be,selectedTo:ke,todayKey:We}),[be,Q,ke,We]),{daily:me,summary:J,rolling:$e,source:ua,loading:Ge,error:Ut,refresh:Er}=ys({baseUrl:t,accessToken:te,guestAllowed:je,from:be,to:ke,includeDaily:Q!=="total",cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{daily:Rr,loading:eo,refresh:Ir}=ys({baseUrl:t,accessToken:te,guestAllowed:je,from:da.from,to:da.to,includeDaily:!0,includeSummary:!1,cacheKey:Fe?`${Fe}.daily-breakdown`:"daily-breakdown",timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{breakdown:tt,loading:Fr,refresh:$r}=oc({baseUrl:t,accessToken:te,guestAllowed:je,from:be,to:ke,cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),[to,ao]=u.useState(3),{entries:ro,loading:so,refresh:Pr}=rc({baseUrl:t,accessToken:te,from:be,to:ke,timeZone:re,tzOffsetMinutes:ue}),zr=Q==="week"||Q==="month",ma=Q==="week"||Q==="month",Or=u.useMemo(()=>me.filter(y=>y?.future?!1:!y?.day||!We?!0:String(y.day)<=String(We)),[me,We]),{rows:Ye,from:no,to:oo,loading:io,refresh:Br}=Yi({baseUrl:t,accessToken:te,guestAllowed:je,period:Q,from:be,to:ke,months:24,cacheKey:Fe,timeZone:Ot,tzOffsetMinutes:Bt,now:Ce,sharedRows:zr?me:null,sharedRange:zr?{from:be,to:ke}:null,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),lo=u.useMemo(()=>({baseUrl:t,accessToken:te,guestAllowed:je,cacheKey:Fe,timeZone:Ot,tzOffsetMinutes:Bt,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),[t,te,je,Fe,Ot,Bt,Ce,W,S,Be,q,_e]),{daily:bt,heatmap:Ve,loading:Ur,refresh:Hr}=Ql({baseUrl:t,accessToken:te,guestAllowed:je,weeks:52,cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{data:ha,refresh:Kr}=Ji();u.useEffect(()=>{ha&&typeof ha=="object"&&Hi(ha)},[ha]);const Ue=u.useMemo(()=>Q==="day"?"hour":Q==="total"?"month":"day",[Q]),co=u.useMemo(()=>ks(Ue),[Ue]),xa="day",uo=u.useMemo(()=>ks(xa),[]),[He,qr]=u.useState(()=>({key:"day",dir:"desc"}));u.useEffect(()=>{qr(y=>!br.has(y.key)||y.key===Ue?y:{key:Ue,dir:y.dir})},[Ue]);const kt=u.useMemo(()=>br.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),pa=u.useMemo(()=>{if(Q==="day")return Array.isArray(Ye)?Ye.filter(R=>R?.hour&&!R?.future):[];if(Q==="total"){const R=Array.isArray(Ye)?Ye.filter(Y=>Y?.month&&!Y?.future):[];return bc(R)}const y=Or;return!y.some(R=>!R?.missing&&!R?.future)&&me.length>0?me.filter(R=>!R?.future).slice(-30).filter(R=>R?.day):y},[Q,Ye,Or,me]),Ht=u.useMemo(()=>_s(pa,kt),[pa,kt]),Vr=u.useMemo(()=>pa.some(y=>!y?.missing&&!y?.future),[pa]),Ua=u.useMemo(()=>{if(!Yt.has(Q))return 1;const y=Math.ceil(Ht.length/Ma);return y>0?y:1},[Q,Ht.length]),[Ha,ga]=u.useState(0);u.useEffect(()=>{if(!Yt.has(Q)){ga(0);return}ga(y=>Math.min(y,Ua-1))},[Ua,Q]),u.useEffect(()=>{Yt.has(Q)&&ga(0)},[Q,He.dir,He.key]);const mo=u.useMemo(()=>Yt.has(Q)?kc(Ht,Ha,Ma):Ht,[Ha,Q,Ht]),Wr=u.useMemo(()=>Cc(Rr,{period:Q}),[Rr,Q]),_t=u.useMemo(()=>br.has(He.key)?{...He,key:xa}:He,[He]),ho=u.useMemo(()=>_s(Wr,_t),[Wr,_t]),xo=u.useMemo(()=>ma?me:Q==="day"?Array.isArray(Ye)?Ye.filter(y=>y?.hour):[]:Ye,[me,Q,Ye,ma]),po=ma?be:no,go=ma?ke:oo;function fo(y,E){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(E.endsWith("_tokens")){const R=E==="total_tokens"?Ta(y):y?.[E];return e.jsx("span",{title:k(R),children:b(R)})}return Da(y?.[E])}function yo(y){const E=y?.[Ue];if(E==null)return"";const R=String(E);if(Ue==="hour"){const[Y,Le]=R.split("T");if(Y&&Le)return`${Y} ${Le.slice(0,5)}`}return R}function bo(y){const E=y?.[xa];return E==null?"":String(E)}function ko(y){qr(E=>E.key===y?{key:y,dir:E.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function _o(y){return kt.key!==y?"none":kt.dir==="asc"?"ascending":"descending"}function wo(y){return kt.key!==y?"":kt.dir==="asc"?"▲":"▼"}function vo(y){return _t.key!==y?"none":_t.dir==="asc"?"ascending":"descending"}function jo(y){return _t.key!==y?"":_t.dir==="asc"?"▲":"▼"}const Ka=u.useMemo(()=>{if(!r&&!ne&&!i&&!se)return 0;const y=Number(Ve?.active_days);if(Number.isFinite(y))return y;let E=0;const R=new Set,Y=(we,Pe,Ee)=>{typeof we!="string"||!we||R.has(we)||kr(Pe,Ee)&&(R.add(we),E+=1)};if(Array.isArray(bt))for(const we of bt)Y(we?.day,Ta(we));const Le=Array.isArray(Ve?.weeks)?Ve.weeks:[];for(const we of Le)for(const Pe of Array.isArray(we)?we:[]){const Ee=Qs(Pe);Y(Pe?.day,Ee,Pe?.level)}return E},[r,ne,Ve?.active_days,Ve?.weeks,bt]),[Gr,Yr]=u.useState("month"),No=u.useCallback(y=>{W&&!i&&ar(a?.userId,"history"),y==="custom"?(Yr(E=>E==="custom"?"month":E),xt(E=>qe&&et?"custom":E),pt(!0)):(xt(y),Yr(y),pt(!1))},[qe,et,W,i,a?.userId]),So=u.useCallback((y,E)=>{W&&!i&&ar(a?.userId,"history"),Ia(y),Fa(E),xt("custom"),pt(!1)},[W,i,a?.userId]),Co=u.useCallback(y=>{pt(y),!y&&Lt==="custom"&&!qe&&xt(Gr)},[Lt,qe,Gr]),To=u.useRef(null),fa=u.useMemo(()=>[t||"",Fe||"",W?"cloud":"local",Be??"",Q||"",be||"",ke||"",We||"",_e||"all",re||"",ue??""].join(""),[Be,W,t,Fe,be,Q,_e,re,We,ke,ue]),Kt=u.useCallback(async()=>Zs(To,fa,async()=>{W&&Ki(),W||qi(),await Promise.all([Er(),Hr(),Br(),$r(),Pr(),Ir(),...W?[]:[It()]])}),[W,Ir,It,Hr,$r,Pr,Br,Er,fa]),Ao=u.useRef(null),Jr=u.useCallback(async()=>Zs(Ao,fa,async()=>{await Ju({refreshUsageStats:Kt,refreshUsageLimits:Kr})}),[fa,Kr,Kt]),qa=u.useRef(Kt);u.useEffect(()=>{qa.current=Kt},[Kt]);const Va=u.useRef(null);u.useEffect(()=>{if(!se||ne||W)return;Va.current||(Va.current=ls({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Va.current.then(()=>{if(y)return qa.current()}).catch(E=>{y&&console.warn("[DashboardPage] Reload sync failed:",E)}),()=>{y=!1}},[se,ne,W]),u.useEffect(()=>{if(!se||ne||W)return;const y=jc({refresh:()=>qa.current(),onError:E=>console.warn("[DashboardPage] Automatic usage refresh failed:",E)});return()=>y.stop()},[se,ne,W]);const Do=u.useCallback(async()=>{X(!0);try{se&&await ls(Yu),await Jr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{X(!1)}},[se,Jr]),ya=Oe||Ge||eo||Ur||io||Fr||so,Wa=!O&&(q||W&&ya&&!Vr),Mo=u.useMemo(()=>l("shared.data_source",{source:String(ua||"edge").toUpperCase()}),[ua,x]),ba=u.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Lo="",Zr=u.useMemo(()=>!ba||ba.includes("@")?l("dashboard.identity.fallback"):ba,[ba]),Qr=u.useMemo(()=>Zr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Zr]),Xr=u.useMemo(()=>i?l("dashboard.identity.fallback"):Qr,[Qr,Lo,i]),es=u.useMemo(()=>{let y=null;const E=Y=>{typeof Y!="string"||!Y||(!y||Y<y)&&(y=Y)};if(Array.isArray(bt))for(const Y of bt)Y?.day&&kr(Ta(Y))&&E(Y.day);const R=Array.isArray(Ve?.weeks)?Ve.weeks:[];for(const Y of R)for(const Le of Array.isArray(Y)?Y:[]){if(!Le?.day)continue;const we=Qs(Le),Pe=Le?.level;kr(we,Pe)&&E(Le.day)}return y},[Ve?.weeks,bt]),Eo=u.useMemo(()=>i?[]:(Array.isArray($?.subscriptions?.items)?$.subscriptions.items:[]).map(R=>{const Y=typeof R?.tool=="string"?R.tool.trim():"",we=(typeof R?.plan_type=="string"?R.plan_type:typeof R?.planType=="string"?R.planType:"").trim();return!Y||!we?null:{tool:Y,planType:we,provider:typeof R?.provider=="string"?R.provider.trim():"",product:typeof R?.product=="string"?R.product.trim():"",rateLimitTier:typeof R?.rate_limit_tier=="string"?R.rate_limit_tier.trim():typeof R?.rateLimitTier=="string"?R.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,$]),Ro=e.jsx(Zi,{heatmap:Ve,timeZoneLabel:la,timeZoneShortLabel:zt,hideLegend:H,defaultToLatestMonth:H}),Io=u.useMemo(()=>`${be}..${ke}`,[be,Q,ke]),Fo=l("usage.summary.total"),Me=J!=null,wt=Me?Ta(J):0,$o=b(wt),Po=u.useCallback(()=>{f(p===Jt.COMPACT?Jt.FULL:Jt.COMPACT)},[f,p]),zo=l("dashboard.core_index.collapse_label"),Oo=l("dashboard.core_index.expand_label"),Bo=l("dashboard.core_index.collapse_aria"),Uo=l("dashboard.core_index.expand_aria"),Ho=!H,vt=l("shared.placeholder.short"),Ga=u.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let E=null,R=0;for(const Pe of y){const Ee=Ct(Pe?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>R&&(R=Ee,E=Pe)}let Y=vt,Le=vt,we="0.0";if(E&&R>0){Y=E?.source?String(E.source).toUpperCase():vt;const Pe=Array.isArray(E?.models)?E.models:[];let Ee=0;for(const tr of Pe){const _a=Ct(tr?.totals);!Number.isFinite(_a)||_a<=0||_a>Ee&&(Ee=_a,Le=tr?.model?String(tr.model):vt)}Ee>0&&(we=(Ee/R*100).toFixed(1))}return{agentName:Y,modelName:Le,modelPercent:we}},[tt,vt]),Ya=Da(wt),Ko=l("dashboard.screenshot.twitter_text",{total_tokens:Ya==="-"?vt:Ya,agent_name:Ga.agentName,model_name:Ga.modelName,model_percent:Ga.modelPercent}),qo=u.useMemo(()=>H?[]:Zu,[H]),Vo=u.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(wt):"—",title:Me?k(wt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(J?.input_tokens):"—",title:Me?k(J?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(J?.output_tokens):"—",title:Me?k(J?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(J?.cached_input_tokens):"—",title:Me?k(J?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(J?.reasoning_output_tokens):"—",title:Me?k(J?.reasoning_output_tokens):void 0}],[J?.cached_input_tokens,J?.input_tokens,J?.output_tokens,J?.reasoning_output_tokens,wt,Me,b,k]),Ja=(tt?.sources||[]).some(y=>(y.models||[]).some(E=>E.pricing?.status==="unpriced"&&E.cost_source!=="provider_reported"&&Number(E.totals?.total_tokens)>0)),Za=u.useMemo(()=>{if(Ja&&Number(J?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=aa(J?.total_cost_usd,{currency:g,rate:m});return Ja&&y!=="-"?`≥${y}`:y},[J?.total_cost_usd,g,m,Ja]),Wo=u.useMemo(()=>J?.conversation_count??null,[J?.conversation_count]),ts=u.useMemo(()=>Pc(tt,{copyFn:l}),[tt]),as=u.useMemo(()=>Oc(tt,{limit:3,copyFn:l}),[tt]),Go=Gu({enabled:N,handle:Xr,startDate:es,activeDays:Ka,summary:J,topModels:as,period:Q,periodFrom:be,periodTo:ke,heatmap:Ve,accessToken:typeof te=="string"?te:null,userId:a?.userId||null,currency:g,exchangeRate:m}),Yo=u.useCallback(()=>P(!0),[]),Jo=u.useCallback(()=>P(!1),[]),Zo=u.useCallback(()=>w(!0),[]),Qo=u.useCallback(()=>w(!1),[]),Xo=Za&&Za!=="-"&&ts.length>0,qt=l("dashboard.install.cmd.init"),Qa=pe?null:C,Xa=Qa?l("dashboard.install.cmd.init_link_code",{link_code:Qa}):qt,ei=qt,ti=l("dashboard.install.cmd.sync"),ai=Qa?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ri=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const si=!!($?.install?.has_active_device_token??$?.install?.hasActiveDeviceToken),ni=_c({publicMode:i,screenshotMode:H,forceInstall:F,accessEnabled:ge,heatmapLoading:Ur,activeDays:Ka,hasActiveDeviceToken:si}),oi=l("dashboard.install.prompt"),ii=u.useCallback(async()=>{!Xa||!await cs(Xa)||(he(!0),window.setTimeout(()=>he(!1),2e3))},[Xa]);u.useCallback(async()=>{!qt||!await cs(qt)||(ye(!0),window.setTimeout(()=>ye(!1),2e3))},[qt]);const er=u.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[x]),[li,ci]=u.useMemo(()=>{const y=er.split("{{cmd}}");return y.length===1?[er,""]:[y[0],y.slice(1).join("{{cmd}}")]},[er]),Vt=s&&!i,Wt=!r&&!ne&&!s&&!se&&!i;u.useEffect(()=>{Vt||Wt||Wa||le(!0)},[Wa,Wt,Vt]);const ka=tc(Qu,Xu);return u.useEffect(()=>{ee.current||Vt||Wt||ya||(ee.current=!0,h?.())},[h,Wt,Vt,ya]),e.jsxs(e.Fragment,{children:[e.jsx(ou,{copy:l,accountView:W,accountScopeSwitchable:Se,onAccountScopeChange:Mt,onOpenShare:Yo,screenshotMode:H,showExpiredGate:Vt,showAuthGate:Wt,identityDisplayName:Xr,identityStartDate:es,activeDays:Ka,identitySubscriptions:Eo,identityScrambleDurationMs:de,projectUsageEntries:ro,projectUsageLimit:to,setProjectUsageLimit:ao,projectDetailQuery:{from:be,to:ke,timeZone:re,tzOffsetMinutes:ue},topModels:as,signedIn:r,publicMode:i,isLocalMode:se,shouldShowInstall:ni,installPrompt:oi,handleCopyInstall:ii,installCopied:ie,installCopiedLabel:ri,installCopyLabel:ai,installInitCmdDisplay:ei,linkCodeLoading:I,linkCodeError:_,trendRowsForDisplay:xo,trendFromForDisplay:po,trendToForDisplay:go,trendZoomConfig:lo,usageFrom:be,usageTo:ke,period:Q,trendTimeZoneLabel:ca,activityHeatmapBlock:Ro,periodsForDisplay:qo,setSelectedPeriod:No,customFrom:qe,customTo:et,onCustomRangeApply:So,customRangeOpen:$a,onCustomRangeOpenChange:Co,metricsRows:Vo,summaryLabel:Fo,summaryValue:$o,hasSummary:Me,summaryLoading:Ge,providersLoading:Fr,summaryFullValue:Ya,onToggleSummaryFormat:Po,summaryTotalTokensRaw:K(wt)||0,summaryCostValue:Za,summaryConversationsValue:Wo,rollingUsage:$e,costInfoEnabled:Xo,openCostModal:Zo,allowBreakdownToggle:Ho,coreIndexCollapsed:oe,setCoreIndexCollapsed:G,coreIndexCollapseLabel:zo,coreIndexExpandLabel:Oo,coreIndexCollapseAria:Bo,coreIndexExpandAria:Uo,refreshAll:Do,usageLoadingState:ya,announceUsageLoading:Oe,initialDashboardLoading:Wa,usageError:Ut,rangeLabel:Io,timeZoneRangeLabel:Ba,usageSourceLabel:Mo,fleetData:ts,hasDetailsActual:Vr,dailyEmptyPrefix:li,installSyncCmd:ti,dailyEmptySuffix:ci,detailsColumns:co,ariaSortFor:_o,toggleSort:ko,sortIconFor:wo,pagedDetails:mo,dailyBreakdownRows:ho,dailyBreakdownColumns:uo,dailyBreakdownAriaSortFor:vo,dailyBreakdownSortIconFor:jo,dailyBreakdownDateKey:xa,detailsDateKey:Ue,renderDetailDate:yo,renderDailyBreakdownDate:bo,renderDetailCell:fo,DETAILS_PAGED_PERIODS:Yt,detailsPageCount:Ua,detailsPage:Ha,setDetailsPage:ga,costModalOpen:v,closeCostModal:Qo,deviceOptions:za,selectedDevice:_e||"",onDeviceChange:y=>{W&&!i&&ar(a?.userId,"view"),gt(y||null)},deviceUsageBlock:Oa,localHistoryOnly:!W&&De.some(y=>y.imported_at),localHistoryRevision:W?0:Ft,leftCardOrder:ka.left.order,onLeftReorder:ka.left.reorder,rightCardOrder:ka.right.order,onRightReorder:ka.right.reorder}),e.jsx(Wu,{open:N,onClose:Jo,data:Go,twitterText:Ko})]})}export{Hm as DashboardPage};
1
+ import{o as Sr,r as u,j as e,L as di,dC as ui,W as ht,aB as ta,aC as ze,dD as mi,dE as hi,az as rs,dF as wa,aH as Xs,aI as en,aJ as Cr,dG as xi,dH as pi,dI as gi,aL as Tr,aK as Zt,dJ as fi,dK as yi,dL as K,c as l,V as Nt,X as Ar,i as Ie,aA as aa,bi as Qt,z as tn,dM as bi,an as ki,l as Jt,cf as Da,y as St,dN as _i,U as an,Q as rn,aN as wi,ao as vi,B as ji,R as Ni,h as Si,dO as Ci,dP as Ti,dQ as Ai,dR as Di,am as ss,_ as Mi,a as Li,dS as ns,g as Ei,Z as Ri,cs as Ii,dT as Fi,dU as $i,dV as Pi,dW as zi,dX as Oi,cg as os,cT as is,dY as Bi,dZ as Ui,aU as Hi,d5 as ar,d_ as ls,aS as cs,d$ as Ki,e0 as qi,e1 as Vi}from"./__vite-browser-external-B_rKFTTN.js";import{u as st}from"./use-latest-request-guard-C91enyPD.js";import{u as ds,L as Wi}from"./use-ordered-list-oqV724BP.js";import{t as us,T as sn,g as Gi,u as Yi}from"./TrendMonitor-5GVzh0Ye.js";import{u as Ji}from"./use-usage-limits-Dk8LcMU-.js";import{u as ra}from"./useCurrency-FxerRfd2.js";import{u as Ne}from"./useTokenFormat-CaI2nl2C.js";import{f as dt,A as Zi}from"./provider-display-S1mSaydF.js";import{g as Qi,q as nn,J as Xi,M as el,m as Ke}from"./react-MQBcjrn_.js";import{u as tl,C as al,a as rl,b as ms,D as sl,S as nl,v as ol,s as il,K as ll,P as cl}from"./sortable.esm-CUPP1ihT.js";import{D as dl,a as ul,b as ml,c as hl,d as xl,e as pl}from"./DialogTitle-BfK_yOeR.js";import{D as gl}from"./DialogClose-DeWert7h.js";import{C as Te}from"./Card-Y7qaxMuE.js";import{S as on}from"./Select-YVEqEhk4.js";import{P as Tt}from"./ProviderIcon-CumyO371.js";import{a as ln,u as cn}from"./use-transform-BsNSgVD6.js";import{u as dn}from"./use-reduced-motion-DW5YHBBI.js";import{f as va,D as fl,g as yl}from"./DateRangePopover-e3gJYqFJ.js";import{I as un}from"./info-e0tP9P3D.js";import{A as mn}from"./index-DCIZaLNC.js";import{L as bl}from"./loader-circle-DjflRntu.js";import{C as kl}from"./chevron-down-x-b39Zto.js";import{P as _l,a as wl,b as vl,c as jl,d as Nl}from"./PopoverPopup-rQNSs8R6.js";import{F as nt}from"./FadeIn-fypYWLDK.js";import{u as Sl,a as Cl,r as Tl,b as hs,P as Al,c as Dl}from"./local-usage-transfer-XTZLA3XH.js";import{L as xs}from"./LoginCard-zrRd8o54.js";import{L as Ml,A as Ll}from"./agent-logos-DVg-sTm4.js";import{i as El}from"./host-mode-Bc_iTzHk.js";import{M as hn}from"./monitor-smartphone-VVBcI30G.js";import{C as Rl}from"./check-D3mhgRrW.js";import"./terminal-C-7TFeKg.js";import"./use-limits-display-prefs-DdwoLqPD.js";import"./play-DN4Sb3W_.js";import"./composite-CnA1qtYn.js";import"./store-BpVdRYnQ.js";import"./SelectItemText-D1NBc4uc.js";import"./usePositioner-D2J-rSfX.js";import"./safePolygon-InKxYcXd.js";import"./arrow-left-Ch6Q7eU5.js";const xn={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"}]]};xn.node;const Il=Sr(xn);const pn={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"}]]};pn.node;const Fl=Sr(pn);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 $l=Sr(gn);function Pl(t,a,r={}){const s=t.get();let n=null,i=s,o;const c=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const g=ps(t.get()),m=ps(i);if(g===m){d();return}const p=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new Xi({keyframes:[g,m],velocity:p,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},x=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((g,m)=>{i=g,o=p=>m(rr(p,c)),Qi.postRender(x)},d),nn(a)){let g=r.skipInitialAnimation===!0;const m=a.on("change",f=>{g?(g=!1,t.jump(rr(f,c),!1)):t.set(rr(f,c))}),p=t.on("destroy",m);return()=>{m(),p()}}return d}function rr(t,a){return a?t+a:t}function ps(t){return typeof t=="number"?t:parseFloat(t)}function zl(t,a={}){const{isStatic:r}=u.useContext(el),s=()=>nn(t)?t.get():t;if(r)return ln(s);const n=cn(s());return u.useInsertionEffect(()=>Pl(n,t,a),[n,JSON.stringify(a)]),n}function Ol(t,a={}){return zl(t,{type:"spring",...a})}function Bl(){return e.jsxs(di,{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 Ul({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Bl,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function Hl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},c=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:c,children:t})}var Kl={};function ql(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 i=(n%10+10)%10,o=(10+a-i)%10;let c=o*r;return o>5&&(c-=10*r),c});return e.jsx(Ke.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 Gl(t,a){const r=t/a;return Math.floor(Wl(r))}function Yl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((c,d)=>/\d/.test(c)&&(s===-1||d<s)).length,i=0,o=!1;return r.map(c=>{if(!/\d/.test(c))return c==="."&&(o=!0),c;if(!o){const d=10**Math.max(n-1,0);return n-=1,d}return i+=1,10**-i})}function Jl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=ql(t,r),h=t!=="."&&t!==",",x=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...x?{width:d.width}:null},children:t})}const i=Gl(a,t),o=cn(0),c=Ol(o,{stiffness:220,damping:26,mass:.8});return u.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(d,h)=>e.jsx(Vl,{mv:c,digit:h,height:r},h))})}function Zl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:c=0,textColor:d="inherit",fontWeight:h="inherit",containerStyle:x,counterStyle:g,digitStyle:m,gradientHeight:p=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:v}){const w=String(a??t??""),C=u.useMemo(()=>Array.isArray(n)&&n.length?n:Yl(w),[n,w]),D=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Kl?.VITEST==="true",M=dn()||D,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,I=r+s;return M?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:h,lineHeight:1,...x,...g},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...x},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:c,paddingRight:c,lineHeight:1,color:d,fontWeight:h,...g},children:C.map((j,_)=>e.jsx(Jl,{place:j,value:A,height:I,digitStyle:m,shouldReduceMotion:M},`${String(j)}-${_}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:p,background:`linear-gradient(to bottom, ${f}, ${b})`}}),e.jsx("span",{style:v??{height:p,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function Ql({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:c,now:d,accountView:h=!1,accountAccessToken:x=null,accountRevision:g=0,accountViewResolving:m=!1,deviceId:p=null}={}){const f=!!(h&&x),b=f?"cloud":"local",k=u.useMemo(()=>ui({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[v,w]=u.useState([]),[C,D]=u.useState(null),[M,A]=u.useState("edge"),[I,j]=u.useState(!1),[_,T]=u.useState(null),z=ht(),B=ta(a),U=!r,L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),$=st([t,k.from,k.to,s,n,b,a,x,g,m,p,o,c,r,z,U,B,L]),V=u.useMemo(()=>{if(!i)return null;const G=Cr({timeZone:o,offsetMinutes:c});return`tokentracker.heatmap.${i}.${b}.${s}.${n}.${G}.${p||"all"}${f||!g?"":`.r${g}`}`},[i,p,b,o,c,s,n,f,g]),H=u.useCallback(()=>{if(!V||typeof window>"u")return null;try{const G=window.localStorage.getItem(V);if(!G)return null;const ie=JSON.parse(G);return!ie||!ie.heatmap?null:ie}catch{return null}},[V]),F=u.useCallback(G=>{if(!(!V||typeof window>"u"))try{window.localStorage.setItem(V,JSON.stringify(G))}catch{}},[V]),N=u.useCallback(()=>{if(!(!V||typeof window>"u"))try{window.localStorage.removeItem(V)}catch{}},[V]),P=u.useRef(b);u.useEffect(()=>{P.current!==b&&(P.current=b,w([]),D(null),A("edge"),T(null),j(!0))},[b]);const de=u.useCallback(async()=>{const G=$(),ie=await ze(a),he=f?await ze(x):null;if(!G()||!ie&&!z&&!L&&!f)return;if(f&&!he){T("Your session expired. Please sign in again to view account data."),j(!1);return}const fe=f?he:ie,ye=f?mi:hi,Oe=f?Xs:en;j(!0),T(null);try{try{const ee=await ye({baseUrl:t,accessToken:fe,weeks:s,to:k.to,weekStartsOn:n,device:p,timeZone:o,tzOffsetMinutes:c}),ne=Array.isArray(ee?.weeks)?ee.weeks:[];if(!G())return;if(!ne.length&&U){const ae=H();if(ae?.heatmap){if(!G())return;D(ae.heatmap),w(ae.daily||[]),A("cache");return}}if(!ne.some(ae=>(Array.isArray(ae)?ae:[]).some(Z=>Z&&Number.isFinite(Number(Z.level))))&&ne.length){const ae=[];for(const te of ne)for(const ge of Array.isArray(te)?te:[])ge?.day&&ae.push({day:ge.day,total_tokens:ge.total_tokens??ge.value??0,billable_total_tokens:ge.billable_total_tokens??ge.value??ge.total_tokens??0});const Z=rs({dailyRows:ae,weeks:s,to:ee?.to||k.to,weekStartsOn:n});if(!G())return;w(ae),D({...Z,week_starts_on:n,active_days:ae.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:wa({dailyRows:ae,to:ee?.to||k.to})}),A("client"),U?F({heatmap:{...Z,week_starts_on:n,active_days:ae.filter(te=>Number(te?.billable_total_tokens??te?.total_tokens)>0).length,streak_days:wa({dailyRows:ae,to:ee?.to||k.to})},daily:ae,fetchedAt:new Date().toISOString()}):N();return}if(!G())return;D(ee||null),w([]),A("edge"),ee&&U?F({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):U||N();return}catch(ee){const ne=ee,ve=ne?.status??ne?.statusCode;if(ve===401||ve===403)throw ee}if(!G())return;const X=await Oe({baseUrl:t,accessToken:fe,from:k.from,to:k.to,device:p,timeZone:o,tzOffsetMinutes:c}),O=Array.isArray(X?.data)?X.data:[];if(!G())return;w(O);const le=rs({dailyRows:O,weeks:s,to:k.to,weekStartsOn:n});if(!G())return;D({...le,week_starts_on:n,active_days:O.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:wa({dailyRows:O,to:k.to})}),A("client"),U?F({heatmap:{...le,week_starts_on:n,active_days:O.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:wa({dailyRows:O,to:k.to})},daily:O,fetchedAt:new Date().toISOString()}):N()}catch(X){if(!G())return;if(U){const O=H();if(O?.heatmap){if(!G())return;D(O.heatmap),w(O.daily||[]),A("cache"),T(null)}else{const le=X;T(le?.message||String(le)),w([]),D(null),A("edge")}}else{const O=X;T(O?.message||String(O)),w([]),D(null),A("edge")}}finally{G()&&j(!1)}},[a,t,z,r,U,k.from,k.to,H,B,o,c,n,s,N,F,L,f,x,g,p,$]);return u.useEffect(()=>{if(m){j(!0);return}if(!B&&!r&&!z&&!L&&!f){w([]),j(!1),T(null),D(null),A("edge");return}if(!U)N(),w([]),T(null),D(null),A("edge");else{const G=H();G?.heatmap&&(D(G.heatmap),w(G.daily||[]),A("cache"))}de()},[a,z,H,de,B,r,U,N,L,m]),{range:k,daily:v,heatmap:C,source:z?"mock":M==="client"?"edge":M,loading:I,error:_,refresh:de}}const Xl="tokentracker.dashboard.leftCardOrder.v1",ec="tokentracker.dashboard.rightCardOrder.v1";function tc(t,a){const r=ds(Xl,t),s=ds(ec,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=u.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const ac=10;function rc({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[c,d]=u.useState([]),[h,x]=u.useState(!1),[g,m]=u.useState(null),p=ht(),f=ta(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,i,o]),v=u.useCallback(async()=>{const w=k(),C=await ze(a);if(w()){if(!C&&!p&&!b){d([]),m(null),x(!1);return}x(!0),m(null);try{const D=await xi({baseUrl:t,accessToken:C,limit:ac,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!w())return;d(Array.isArray(D?.entries)?D.entries:[])}catch(D){if(!w())return;const M=D?.message||String(D);m(M),d([])}finally{w()&&x(!1)}}},[a,t,r,p,n,i,s,o,b,k]);return u.useEffect(()=>{if(!f&&!p&&!b){d([]),m(null),x(!1);return}d([]),m(null),x(!0),v()},[p,v,f,b]),{entries:c,loading:h,error:g,refresh:v}}const gs="tokentracker.usage-cache-index",fs=24;function ys({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:c,timeZone:d,tzOffsetMinutes:h,now:x,accountView:g=!1,accountAccessToken:m=null,accountRevision:p=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(g&&m),v=k?"cloud":"local",[w,C]=u.useState([]),[D,M]=u.useState(null),[A,I]=u.useState(null),[j,_]=u.useState("edge"),[T,z]=u.useState(null),[B,U]=u.useState(!1),[L,$]=u.useState(null),V=ht(),H=ta(a),F=!r&&!V,N=b||"all",P=(()=>{if(!c)return null;const X=sc(t)||"default",O=i?o?"daily-summary":"daily-only":"summary",le=Cr({timeZone:d,offsetMinutes:h});return`tokentracker.usage.${c}.${v}.${X}.${s}.${n}.${O}.${le}.${N}${k||!p?"":`.r${p}`}`})(),de=u.useRef(v);u.useEffect(()=>{de.current!==v&&(de.current=v,C([]),M(null),I(null),_("edge"),z(null),$(null),U(!0))},[v]);const oe=u.useCallback(()=>{if(!P||typeof window>"u")return null;try{const X=window.localStorage.getItem(P);if(!X)return null;const O=JSON.parse(X),le=o?!!O?.summary:Array.isArray(O?.daily);return!O||!le?null:(us(gs,P,fs),O)}catch{return null}},[o,P]),G=u.useCallback(X=>{if(!(!P||typeof window>"u"))try{window.localStorage.setItem(P,JSON.stringify(X)),us(gs,P,fs)}catch{}},[P]),ie=u.useCallback(()=>{if(!(!P||typeof window>"u"))try{window.localStorage.removeItem(P)}catch{}},[P]),he=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),fe=st([t,s,n,i,o,v,a,m,p,b,d,h,r,V,F,f,H,he]),ye=u.useCallback(async()=>{const X=fe(),O=await ze(a),le=k?await ze(m):null;if(!X()||!O&&!V&&!he&&!k)return;if(k&&!le){$("Your session expired. Please sign in again to view account data."),U(!1);return}const ee=k?Xs:en,ne=k?pi:gi,ve=k?le:O;U(!0),$(null);try{let ae=null,Z=null;if(i)if(o){const[Ae,Qe]=await Promise.allSettled([ee({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h}),ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0})]);if(Ae.status==="rejected")throw Ae.reason;ae=Ae.value,Z=Qe.status==="fulfilled"?Qe.value:null}else ae=await ee({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h});else o&&(Z=await ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0}));let te=i&&Array.isArray(ae?.data)?ae.data:[];i&&(te=nr(te,s,n,{timeZone:d,offsetMinutes:h,now:x}));let ge=o&&(Z?.totals||ae?.summary?.totals)||null,xe=o&&(Z?.rolling||ae?.summary?.rolling)||null;if(o&&i&&!ge&&!Z)try{const Ae=await ne({baseUrl:t,accessToken:ve,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0});ge=Ae?.totals||null,xe=Ae?.rolling||xe}catch{}const je=new Date().toISOString();if(!X())return;C(te),M(ge),I(xe),_("edge"),z(je),(ge||!o&&i)&&F?G({summary:ge,rolling:xe,daily:te,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:je}):F||ie()}catch(ae){if(!X())return;if(F){const Z=oe();if(Z?.summary||!o&&Array.isArray(Z?.daily)){M(Z.summary),I(Z.rolling||null);const te=Array.isArray(Z.daily)?Z.daily:[],ge=i?nr(te,Z.from||s,Z.to||n,{timeZone:d,offsetMinutes:h,now:x}):te;C(ge),_("cache"),z(Z.fetchedAt||null),$(null)}else{const te=ae;$(te?.message||String(te)),C([]),M(null),I(null),_("edge"),z(null)}}else{const Z=ae;$(Z?.message||String(Z)),C([]),M(null),I(null),_("edge"),z(null)}}finally{X()&&U(!1)}},[a,t,s,i,o,V,r,F,x,oe,H,d,n,h,ie,G,he,k,m,p,b,fe]);return u.useEffect(()=>{if(f){U(!0);return}const X=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!H&&!r&&!V&&!X&&!k){C([]),M(null),I(null),$(null),U(!1),_("edge"),z(null);return}if(!F)ie(),C([]),M(null),I(null),$(null),_("edge"),z(null);else{const O=oe();if(O?.summary||!o&&Array.isArray(O?.daily)){M(O.summary),I(O.rolling||null);const le=Array.isArray(O.daily)?O.daily:[],ee=i?nr(le,O.from||s,O.to||n,{timeZone:d,offsetMinutes:h,now:x}):le;C(ee),_("cache"),z(O.fetchedAt||null),$(null)}else C([]),M(null),I(null),_("edge"),z(null),$(null)}U(!0),ye()},[a,V,oe,ye,H,r,F,ie,he,f,o]),u.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const X=15e3;let O=Date.now();const le=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-O<X||(O=ee,ye())};return window.addEventListener("focus",le),document.addEventListener("visibilitychange",le),()=>{window.removeEventListener("focus",le),document.removeEventListener("visibilitychange",le)}},[ye]),{daily:w,summary:D,rolling:A,source:V?"mock":j,fetchedAt:T,loading:B,error:L,refresh:ye}}function sc(t){try{return new URL(t).host}catch{return null}}function sr(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Zt(o)===a?o:null}function nc(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function nr(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=sr(a),c=sr(r);if(!o||!c||c<o)return Array.isArray(t)?t:[];const d=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=Tr({timeZone:s,offsetMinutes:n,date:d}),x=sr(h),g=x?x.getTime():d.getTime(),m=new Map;for(const f of t||[])f?.day&&m.set(f.day,f);const p=[];for(let f=o;f<=c;f=nc(f,1)){const b=Zt(f),k=m.get(b),v=f.getTime()>g;if(k){p.push({...k,missing:!1,future:v});continue}p.push({day:b,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!v,future:v})}return p}function oc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:c,accountView:d=!1,accountAccessToken:h=null,accountRevision:x=0,accountViewResolving:g=!1,deviceId:m=null}={}){const p=!!(d&&h),f=p?"cloud":"local",[b,k]=u.useState(null),[v,w]=u.useState("edge"),[C,D]=u.useState(!1),[M,A]=u.useState(null),I=ht(),j=ta(a),_=!r,T=u.useMemo(()=>{if(!i)return null;const N=ic(t)||"default",P=Cr({timeZone:o,offsetMinutes:c});return`tokentracker.modelBreakdown.${i}.${f}.${N}.${s}.${n}.${P}.${m||"all"}${p||!x?"":`.r${x}`}`},[t,i,m,s,f,o,n,c,p,x]),z=u.useCallback(()=>{if(!T||typeof window>"u")return null;try{const N=window.localStorage.getItem(T);if(!N)return null;const P=JSON.parse(N);return!P||!P.breakdown?null:P}catch{return null}},[T]),B=u.useCallback(N=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(N))}catch{}},[T]),U=u.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),$=st([t,s,n,f,a,h,x,m,o,c,r,I,_,g,j,L]),V=u.useRef(f);u.useEffect(()=>{V.current!==f&&(V.current=f,k(null),w("edge"),A(null),D(!0))},[f]);const H=u.useCallback(async()=>{const N=$(),P=await ze(a),de=p?await ze(h):null;if(!N()||!P&&!I&&!L&&!p)return;if(p&&!de){A("Your session expired. Please sign in again to view account data."),D(!1);return}const oe=p?de:P,G=p?fi:yi;D(!0),A(null);try{const ie=await G({baseUrl:t,accessToken:oe,from:s,to:n,device:m,timeZone:o,tzOffsetMinutes:c});if(!N())return;k(ie||null),w("edge"),ie&&_?B({breakdown:ie,fetchedAt:new Date().toISOString()}):_||U()}catch(ie){if(!N())return;if(_){const he=z();if(he?.breakdown)k(he.breakdown),w("cache"),A(null);else{k(null),w("edge");const fe=ie;A(fe?.message||String(fe))}}else{k(null),w("edge");const he=ie;A(he?.message||String(he))}}finally{N()&&D(!1)}},[a,t,s,I,r,_,z,o,n,j,c,U,B,L,p,h,x,m,$]);return u.useEffect(()=>{if(g){D(!0);return}if(!j&&!r&&!I&&!L&&!p){k(null),w("edge"),A(null),D(!1);return}if(!_)U(),k(null),w("edge"),A(null);else{const N=z();N?.breakdown?(k(N.breakdown),w("cache"),A(null)):(k(null),w("edge"),A(null))}D(!0),H()},[a,I,z,H,j,r,_,U,L,g]),{breakdown:b,source:I?"mock":v,loading:C,error:M,refresh:H}}function ic(t){try{return new URL(t).host}catch{return null}}const fn=new Set(["day","hour","month"]);function lc(t){return fn.has(t)}function bs(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 cc(t,a){const r=bs(t),s=bs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=K(t),i=K(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function dc(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 uc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function mc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function hc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),c=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(c)||!Number.isFinite(d)||n<1||n>12||i<1||i>31||o<0||o>23||c<0||c>59||d<0||d>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,c,d));return Number.isFinite(h.getTime())?h.getTime():null}function xc(t,a,r){const s=r==="hour"?hc:r==="month"?mc:uc,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:dc(t,a)}function yn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=fn.has(a)?(c,d)=>xc(c,d,a):cc,o=c=>a==="total_tokens"&&c?.billable_total_tokens!=null?c.billable_total_tokens:c?.[a];return n.map((c,d)=>({row:c,index:d})).sort((c,d)=>{const h=o(c.row),x=o(d.row),g=h==null,m=x==null;if(g&&m)return c.index-d.index;if(g)return 1;if(m)return-1;const p=i(h,x);return p!==0?p*s:c.index-d.index}).map(c=>c.row)}function pc(){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 ks(t){const a=lc(t)?t:"day";return pc().map((r,s)=>s===0?{...r,key:a}:r)}function _s(t,{key:a,dir:r}){return yn(t,{key:a,dir:r})}const Ma=12,gc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function fc(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 yc(t){return gc.some(a=>fc(t?.[a]))}function bc(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=yn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&yc(n));return s===-1?a:r.slice(s)}function kc(t,a,r=Ma){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Ma,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function _c({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const ja=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 ja.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ja.active:s<=60*6e4?ja.warm:ja.idle}const vc=3e4;function jc({refresh:t,intervalMs:a=vc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,c=Date.now(),d=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const p=Promise.resolve().then(()=>t()).catch(f=>n(f)).then(()=>{}).finally(()=>{o===p&&(o=null)});return o=p,p},x=r.setInterval(()=>{const p=Date.now();p<d||(d=p+wc({visible:s.visibilityState==="visible",lastInteractionAt:c,now:p}),h())},a),g=()=>{s.visibilityState==="visible"&&(c=Date.now(),d=0,h())},m=()=>{c=Date.now()};return r.addEventListener("focus",g),r.addEventListener("pointerdown",m),r.addEventListener("keydown",m),s.addEventListener("visibilitychange",g),{run:h,stop(){i=!0,r.clearInterval(x),r.removeEventListener("focus",g),r.removeEventListener("pointerdown",m),r.removeEventListener("keydown",m),s.removeEventListener("visibilitychange",g)}}}function Nc(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 Zt(r)===t?r:null}function Sc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=Nc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Zt(i),to:Zt(n)}}function Cc(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 Dr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Tc(t){const a=Dr(t?.model_id);return a||null}function bn(t,a){return t?.model?String(t.model):a}function kn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Dr(n);if(!i||i.includes("/"))continue;const o=Math.max(0,K(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function _n(t,a){const r=Dr(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=K(t?.billable_total_tokens),s=K(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Ac={deepseek:"dsh"};function Dc(t){const a=typeof t=="string"?t:"";return Ac[a]||a}const Mc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count"],Mr=["input","output","cached","cacheCreate","reasoning"];function La(t){let a=0;for(const r of Mr)a+=Math.max(0,Number(t?.[r])||0);return a}function Lc(t){return La(t?.tokens)>0}const Xt=["priority","ultrafast"],wn=Mr,Ec={priority:{tokens:{input:"priority_input_tokens",cached:"priority_cached_input_tokens",cacheCreate:"priority_cache_creation_input_tokens",output:"priority_output_tokens",reasoning:"priority_reasoning_output_tokens"},cost:"priority_cost_usd"},ultrafast:{tokens:{input:"ultrafast_input_tokens",cached:"ultrafast_cached_input_tokens",cacheCreate:"ultrafast_cache_creation_input_tokens",output:"ultrafast_output_tokens",reasoning:"ultrafast_reasoning_output_tokens"},cost:"ultrafast_cost_usd"}};function Rc(t){const a={};let r=!1;for(const s of Xt){const n=Ec[s],i={input:Math.max(0,K(t?.[n.tokens.input])??0),output:Math.max(0,K(t?.[n.tokens.output])??0),cached:Math.max(0,K(t?.[n.tokens.cached])??0),cacheCreate:Math.max(0,K(t?.[n.tokens.cacheCreate])??0),reasoning:Math.max(0,K(t?.[n.tokens.reasoning])??0)},o=Math.max(0,K(t?.[n.cost])??0);La(i)<=0&&o<=0||(a[s]={tokens:i,cost:o},r=!0)}return r?a:null}function vn(t,a){if(!a||!Object.keys(a).length)return t;const r={...t||{}};for(const s of Xt){const n=a[s];if(!n)continue;const i=r[s];if(!i){r[s]={tokens:{...n.tokens},cost:n.cost};continue}for(const o of wn)i.tokens[o]+=n.tokens[o]||0;i.cost+=n.cost||0}return r}function jn(t){return!!(t?.tiers?.priority||t?.tiers?.ultrafast)}function Ic(t,a){const r=Number(t?.pricing?.[`${a}_multiplier`]);return Number.isFinite(r)&&r>1?r:0}function Fc(t){if(!jn(t))return null;const a={input:0,output:0,cached:0,cacheCreate:0,reasoning:0};let r=!1;for(const n of wn){let i=Math.max(0,Number(t?.tokens?.[n])||0);for(const o of Xt)i-=Math.max(0,Number(t?.tiers?.[o]?.tokens?.[n])||0);a[n]=Math.max(0,i),a[n]>0&&(r=!0)}let s=Math.max(0,K(t?.cost)??0);for(const n of Xt)s-=Math.max(0,Number(t?.tiers?.[n]?.cost)||0);return s=Math.max(0,s),!r&&s<=0?null:{tokens:a,cost:s}}function Lr(t){return t?.unpriced===!0?!0:t?.costSource!=="provider_reported"&&t?.pricing?.status==="unpriced"}function ws(t,a){for(const r of Mc)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 vs(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,conversation_count:0,total_cost_usd:"0"}}function $c(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:vs(),models:new Map},a.set(s,n)),ws(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let c=n.models.get(o);const d=Rc(i?.totals);c?c.tiers=vn(c.tiers??null,d):(c={...i,model:i?.model||o,model_id:o,totals:vs()},c.tiers=d,n.models.set(o,c)),ws(c.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function Pc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=$c(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const c=Ct(o?.totals),d=K(o?.totals?.total_cost_usd)??0,h=Math.max(0,K(o?.totals?.conversation_count)??0);return{source:o?.source,totalTokens:Number.isFinite(c)?c:0,totalRequests:h,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,K(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,K(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,K(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0||o.totalRequests>0);if(!n.length)return[];const i=n.reduce((o,c)=>o+c.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,c)=>c.totalTokens-o.totalTokens||c.totalRequests-o.totalRequests).map(o=>{const c=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),d=i>0?o.totalTokens/i*100:0,h=Number.isFinite(d)?d.toFixed(2):"0.00",x=o.models.map(f=>{const b=Ct(f?.totals),k=Math.max(0,K(f?.totals?.conversation_count)??0);if((!Number.isFinite(b)||b<=0)&&k<=0)return null;const v=o.totalTokens>0?Math.round(b/o.totalTokens*1e3)/10:0,w=bn(f,r("shared.placeholder.short")),C=Tc(f),D=K(f?.totals?.total_cost_usd),M=b<=0?null:D??(o.totalCost>0&&o.totalTokens>0?b/o.totalTokens*o.totalCost:null),A=f?.totals||{};return{id:C,name:w,share:v,usage:b,requests:k,cost:M,tokens:{input:Math.max(0,K(A?.input_tokens)??0),output:Math.max(0,K(A?.output_tokens)??0),cached:Math.max(0,K(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,K(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,K(A?.reasoning_output_tokens)??0)},tiers:f?.tiers??null,pricing:f?.pricing||null,costSource:f?.cost_source||null}}).filter(Boolean),g=o.inputTokens+o.cacheRead+o.cacheCreate,p=o.cacheRead+o.cacheCreate>0&&g>0?Math.round(o.cacheRead/g*100):null;return{source:o.source,label:c,totalPercent:String(h),totalPercentValue:d,usd:o.totalCost,usage:o.totalTokens,requests:o.totalRequests,cacheHitRate:p,cacheReusedTokens:o.cacheRead,cacheInputTokens:g,models:x}})}function zc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const c=Array.isArray(o?.models)?o.models:[];for(const d of c){const h=K(d?.usage),x=Math.max(0,K(d?.requests)??0);if((h==null||h<=0)&&x<=0)continue;const g=h??0,m=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;m&&s.push({model:d,name:m,usage:g,requests:x})}}const n=kn(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:c,usage:d,requests:h}of s){const x=_n(c,n);if(!x)continue;const{key:g}=x,m=r.get(g)||{id:g,name:x.name,usage:0,requests:0,cost:0,hasCost:!1,unpriced:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0},tiers:null,pricing:null};m.usage+=d,m.requests+=h;const p=o?.tokens||{};for(const b of Mr)m.tokens[b]+=Math.max(0,Number(p[b])||0);m.tiers=vn(m.tiers,o?.tiers??null),!m.pricing&&o?.pricing&&(m.pricing=o.pricing),d>0&&Lr(o)&&(m.unpriced=!0);const f=K(o?.cost);f!=null&&(m.cost+=f,m.hasCost=!0),n.has(g)?m.name=n.get(g):d>=m.nameWeight&&(m.name=c,m.nameWeight=d),r.set(g,m)}const i=Array.from(r.values()).reduce((o,c)=>o+c.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,requests:o.requests,cost:o.hasCost?o.cost:null,unpriced:o.unpriced===!0,tokens:{...o.tokens},tiers:o.tiers,pricing:o.pricing,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,c)=>c.usage!==o.usage?c.usage-o.usage:String(o.name).localeCompare(String(c.name)))}function Oc(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 i=new Map,o=new Map,c=new Map,d=[];let h=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const v=Ct(k?.totals);if(!Number.isFinite(v)||v<=0)continue;h+=v;const w=bn(k,s("shared.placeholder.short"));d.push({name:w,tokens:v})}}const x=kn(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=_n(f,x);if(!k)continue;const{key:v}=k;i.set(v,(i.get(v)||0)+b),x.has(v)?o.set(v,x.get(v)):b>=(c.get(v)||0)&&(c.set(v,b),o.set(v,f))}if(!i.size)return[];const g=Array.from(i.values()).reduce((f,b)=>f+b,0),m=h>0?h:g,p=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([f,b])=>{const k=m>0?(b/m*100).toFixed(1):"0.0";return{id:f,name:o.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,p)}function Bc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=aa(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function js(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Qt(a);return(a===tn?t:t*r)<.01?`<${s}0.01`:aa(t,{decimals:2,currency:a,rate:r})}function Ns(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const Uc=Nt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=ra(),o=u.useMemo(()=>(Array.isArray(s)?s:[]).map(h=>{const x=K(h?.usd)??0,g=K(h?.usage)??0,m=Array.isArray(h?.models)?h.models:[];return{label:h?.label?String(h.label):"",usdValue:x,costLabel:js(x,n,i),tokensLabel:Ns(g),models:m.map(p=>{const f=K(p?.usage)??0,b=K(p?.cost)??0;return{id:p?.id?String(p.id):"",name:p?.name?String(p.name):"",tokensLabel:Ns(f),costLabel:js(b,n,i),sortCost:b,pricing:p?.pricing,costSource:p?.costSource,tokens:p?.tokens}}).filter(p=>p.costLabel||p.tokensLabel).sort((p,f)=>f.sortCost-p.sortCost)}}).filter(h=>h.usdValue>0||h.models.length>0).sort((h,x)=>x.usdValue-h.usdValue),[s,n,i]),c=o.some(h=>h.models.some(x=>Lr(x))),d=u.useMemo(()=>{const h=o.reduce((x,g)=>x+g.usdValue,0);return c&&h===0?l("dashboard.cost_breakdown.unpriced_label"):`${c?"≥":""}${Bc(h,n,i)}`},[o,n,i,c]);return e.jsx(dl,{open:a,onOpenChange:h=>{h||r?.()},children:e.jsxs(ul,{children:[e.jsx(ml,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(hl,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(xl,{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(pl,{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(Ar,{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:c?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")}),o.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")})]}),o.map((h,x)=>{const g=`fleet-${x}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":g,className:x>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:g,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:h.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:h.costLabel||"—"})]}),h.models.map((m,p)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:m.name,children:m.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:m.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):m.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),m.pricing?.status==="unpriced"&&m.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,m.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,m.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(m.tokens.input)||0),output:Ie(Number(m.tokens.output)||0),read:Ie(Number(m.tokens.cached)||0),write:Ie(Number(m.tokens.cacheCreate)||0)})}):null,m.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:m.pricing.input,output:m.pricing.output,read:m.pricing.cache_read,write:m.pricing.cache_write})}):null]})]}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:m.costLabel||(m.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):m.pricing?.status==="free"?aa(0,{currency:n,rate:i}):l("dashboard.cost_breakdown.rate_unknown"))})]},m.id||`${m.name}-${p}`))]},`${h.label}-${x}`)})]})]})})]})})]})})});function Hc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,x]=u.useState(null),g=ht(),m=st([t,a,r,s,n,g]);return u.useEffect(()=>{const p=m();if(!t){o(null),x(null),d(!1);return}d(!0),o(null),x(null),bi({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{p()&&o(f||null)}).catch(f=>{p()&&(x(f?.message||String(f)),o(null))}).finally(()=>{p()&&d(!1)})},[t,a,r,s,n,g,m]),{data:i,loading:c,error:h}}function Nn(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 Sn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function Cn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function Tn(t,a){return a&&Cn(Sn(t))==="github"?a:""}function An({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=u.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const Ss="#10b981",or=[{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"}],ir=60;function Kc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(m=>[m.day,m]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const c=t[t.length-1].day;o<c&&(o=c);const d=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(h.getTime()))return t;const x=Math.round((h.getTime()-d.getTime())/864e5)+1;x>ir&&d.setUTCDate(d.getUTCDate()+(x-ir));const g=[];for(;d.getTime()<=h.getTime()&&g.length<ir;){const m=d.toISOString().slice(0,10);g.push(n.get(m)||{day:m,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return g}function lr(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function jt({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 qc({host:t}){if(!t)return null;let a;const r=Cn(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 cr({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 Vc({entry:t,query:a={},onClose:r}){const[s,n]=Nt.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:c}=Nn(i),d=typeof t?.project_ref=="string"?t.project_ref:"",h=Sn(d),{data:x,loading:g,error:m}=Hc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:p,formatTokensTooltip:f}=Ne(),b=Nt.useCallback(()=>n(!0),[]),k=L=>{L.target===L.currentTarget&&s&&r()};Nt.useEffect(()=>{const L=$=>{$.key==="Escape"&&b()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b]);const v=x?.totals||null,w=K(v?.billable_total_tokens)??0,C=Number(x?.days_active||0),D=K(v?.input_tokens)??0,M=K(v?.cached_input_tokens)??0,A=D+M>0?M/(D+M):null,I=K(x?.range_total_tokens)??0,j=K(v?.total_tokens)??0,_=I>0?j/I:null,T=Nt.useMemo(()=>Kc(x?.daily,x?.from,x?.to,Tr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[x,a.timeZone,a.tzOffsetMinutes]),z=or.reduce((L,$)=>L+(K(v?.[$.key])??0),0),B=Array.isArray(x?.sources)?x.sources:[],U=!g&&!m&&v&&j>0;return e.jsx("div",{onAnimationEnd:k,onClick:L=>{L.target===L.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":i,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(Ar,{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:Ss}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:Ss}})]}),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(An,{githubOwner:Tn(d,o),letter:(c?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:c||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(qc,{host:h}),h&&x?.from&&x?.to?e.jsx("span",{children:"·"}):null,x?.from&&x?.to?e.jsxs("span",{className:"tabular-nums",children:[x.from," – ",x.to]}):null]})]}),U?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(jt,{label:l("dashboard.projects.detail.stat_total"),value:p(w),title:f(w)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_share"),value:_==null?"—":lr(_)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":lr(A)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_conversations"),value:Da(v.conversation_count)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_active_days"),value:Da(C)}),e.jsx(jt,{label:l("dashboard.projects.detail.stat_avg_day"),value:C>0?p(Math.round(w/C)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[g&&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"})]}),!g&&m&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!g&&!m&&!U&&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")}),U&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[T.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(sn,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),z>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:or.map(L=>{const $=K(v[L.key])??0;return $<=0?null:e.jsx("div",{style:{width:`${$/z*100}%`,backgroundColor:L.color,minWidth:"2px"}},L.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:or.map(L=>{const $=K(v[L.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:L.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(L.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f($),children:p($)})]},L.key)})})]}),B.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(cr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:B.map(L=>{const $=Number(L.total_tokens||0),V=j>0?$/j:0,H=V*100,F=Number(L.conversation_count||0),N=Gi(L.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:L.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:dt(L.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(L.days_active||0)}),F>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:F})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f($),children:p($)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:lr(V)})]}),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(H,$>0?1:0))}%`,minWidth:$>0?"3px":0,backgroundColor:N}})})]},L.source)})})]})]})]})]})})}function Wc(t){return e.jsx(ki,{mode:Jt.COMPACT,children:e.jsx(Vc,{...t})})}const Gc=5;function Yc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",c=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:h}=Nn(o),x=Tn(c,d),g=K(t?.billable_total_tokens??t?.total_tokens)??0,m=a>0?Math.min(100,Math.max(2,g/a*100)):0,p=Array.isArray(t?.sources)?t.sources:[],f=p.slice(0,Gc),b=p.length-f.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(An,{githubOwner:x,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[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:h||o||"—"})]}),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(g),children:s(g)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${m}%`,minWidth:g>0?"3px":0}})})]})]})}function Jc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:c,dailyEmptySuffix:d,detailsColumns:h,ariaSortFor:x,toggleSort:g,sortIconFor:m,pagedDetails:p,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:w="day",detailsDateKey:C,renderDetailDate:D,renderDailyBreakdownDate:M,renderDetailCell:A,DETAILS_PAGED_PERIODS:I,period:j,detailsPageCount:_,detailsPage:T,setDetailsPage:z}){const[B,U]=u.useState("daily"),[L,$]=u.useState(null),{formatTokens:V,formatTokensTooltip:H}=Ne();return e.jsxs(Te,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${B==="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":B==="daily",type:"button",onClick:()=>U("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${B==="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":B==="projects",type:"button",onClick:()=>U("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${B==="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")})]}),B==="projects"&&e.jsx(on,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:F=>r?.(Number(F)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),B==="projects"&&(()=>{const F=t.slice(0,a);if(F.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const N=F.reduce((P,de)=>{const oe=K(de?.billable_total_tokens??de?.total_tokens)??0;return oe>P?oe:P},0);return e.jsx("div",{className:"space-y-1",children:F.map((P,de)=>e.jsx(Yc,{entry:P,maxTokens:N,copy:n,formatTokens:V,formatTokensTooltip:H,onSelect:$},P?.project_key||P?.project_ref||`entry-${de}`))})})(),L&&e.jsx(Wc,{entry:L,query:s,onClose:()=>$(null)}),B==="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:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:c}),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(F=>e.jsx("th",{"aria-sort":k?.(F.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>g(F.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:F.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(F.key)||""})]})})},F.key))})}),e.jsx("tbody",{children:f.map(F=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${F.missing?"text-oai-gray-400 dark:text-oai-gray-400":F.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:M?M(F):D(F)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(F,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"conversation_count")})]},String(F?.[w]||F?.day||F?.hour||F?.month||"")))})]})}),B!=="daily"&&I.has(j)&&_>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>z(F=>Math.max(0,F-1)),disabled:T===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[T+1," / ",_]}),e.jsx("button",{type:"button",onClick:()=>z(F=>Math.min(_-1,F+1)),disabled:T+1>=_,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function Aa(t){return typeof t!="string"?"":t.trim()}function Cs(t){const a=Aa(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Zc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Aa(r.tool),n=Aa(r.planType)||Aa(r.plan_type);if(!s||!n)continue;const i=Cs(s)||s,o=Cs(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function Qc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:c}=Ne(),d=l("shared.placeholder.short"),h=l("shared.unit.percent"),x=t??l("identity_card.rank_placeholder"),g=Number.isFinite(Number(a))?Number(a):0,m=g?l("identity_card.streak_value",{days:g}):l("identity_card.rank_placeholder"),p=Zc(r),f={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev"),trillionSuffix:l("shared.unit.trillion_abbrev")},b=w=>{if(w==null)return d;const C=Ie(w,f);return C==="-"?d:C},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=i.slice(0,3);return e.jsxs(Te,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(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:c(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:c(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),v.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:v.map((w,C)=>{const D=w?.name?String(w.name):d,M=w?.percent?String(w.percent):"",A=C===v.length-1,I=C+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:I}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:D,children:D}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[M,h]})]},w.id||D)})}),p.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:p.map((w,C)=>e.jsxs(Hl,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${C}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:x})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]})]})]})}let Na=null;function Xc(){if(Na===null)try{Na=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{Na=!1}return Na}function ed(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,c=t-.1055613458*n-.0638541728*i,d=t-.0894841775*n-1.291485548*i,h=o*o*o,x=c*c*c,g=d*d*d;return[4.0767416621*h-3.3077115913*x+.2309699292*g,-1.2684380046*h+2.6097574011*x-.3413193965*g,-.0041960863*h-.7034186147*x+1.707614701*g].map(p=>{const f=Math.min(1,Math.max(0,p)),b=f<=.0031308?12.92*f:1.055*Math.pow(f,1/2.4)-.055;return Math.round(b*255)})}function Dn(t,a,r,s){if(Xc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=ed(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function At(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Dn(Number(a[1]),Number(a[2]),Number(a[3])):t}const Ts={claude:35,codex:250,grok:200},As={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 td(t,a){const r=Ts[a]??Ts.claude,s=As[t]||As.system_prompt;return Dn(s.l,s.c,r)}const ad=[{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"]}],rd=[["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"]],sd={duration:.18,ease:[.4,0,.2,1]},nd={height:0,opacity:0},od={height:"auto",opacity:1},id={height:0,opacity:0};function ld(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function cd(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 Mn(t,a=null){const r=t.reduce((o,c)=>o+Number(c.totals.total_tokens||0),0),s=ld(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const c=i===1?o.totals:cd(o.totals,i);return{...o,totals:c,percent:n>0?Number((c.total_tokens/n*100).toFixed(2)):0}}).sort((o,c)=>c.totals.total_tokens-o.totals.total_tokens)}function dd(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=ad.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const c=r.get(o);if(!c)continue;const d=c.totals||{};i.input_tokens+=d.input_tokens||0,i.cached_input_tokens+=d.cached_input_tokens||0,i.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,i.output_tokens+=d.output_tokens||0,i.reasoning_output_tokens+=d.reasoning_output_tokens||0,i.total_tokens+=d.total_tokens||0}return{key:n.key,totals:i}});return Mn(s,a)}function ud(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,x)=>x?.name==="Text Response"?h:h+Number(x?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),d=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return Mn(d,a)}const Ds="MCP: ";function md(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(Ds)?(a.push({...n,name:i.slice(Ds.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function Ms(t){return l(`dashboard.context_breakdown.category.${t}`)}function hd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function xd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),c=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:hd(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(c||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function pd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),c=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:c,total_tokens:Number(r.total_tokens||n+i)},tools:xd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}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),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function fd(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 yd(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 bd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function Ls(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 kd(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 Es(t){return t==="exec_command"||t==="Bash"}function Ln(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function _d(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function wd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const vd=10;function Ze({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:c,tokens:d,percent:h=null,children:x,share:g=null,fillColor:m=null}){const p=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:vd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:p,children:r}),s,i&&e.jsx(Ke.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(wi,{size:11})})]}),k=m&&g!=null&&g>0,v=k?Math.max(0,Math.min(100,g)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:k?{backgroundImage:`linear-gradient(to right, ${m.replace(/\)\s*$/," / 0.10)")} 0%, ${m.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:c,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children: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:h||""})]}),i&&x?e.jsx(mn,{initial:!1,children:o&&e.jsx(Ke.div,{initial:nd,animate:od,exit:id,transition:sd,style:{overflow:"hidden"},children:x},"content")}):null]})}function Rs({execDetails:t,source:a="claude"}){const{formatTokens:r}=Ne(),[s,n]=u.useState("by_type"),i=bd(kd(t,s)),o=a==="codex"||a==="grok",c=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:rd.map(([d,h])=>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(h)},d))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${c} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((d,h)=>e.jsxs(Ke.div,{role:"row",className:`grid ${c} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children: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:Ie(d.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(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:Ls(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:Ls(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)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.output_lines||0)})]},d.name))]})})]})}function Gt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Ne(),[i,o]=u.useState({}),[c,d]=u.useState(!1),h=pd(t?.categories||[]);function x(g){o(m=>({...m,[g]:!m[g]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(Ln(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(g=>{const m=g.toolCount>0,p=g.name==="Execution"&&a,f=p&&g.tools.some(k=>Es(k.name)),b=!!i[g.name];return e.jsxs(Ze,{level:1,label:g.name,labelTone:"strong",hasChevron:m||p&&!f,open:b||p&&!f&&c,onToggle:()=>{m?x(g.name):p&&!f&&d(k=>!k)},tokens:n(g.totals.total_tokens||0),percent:null,children:[m&&e.jsx("ul",{className:"space-y-0.5",children:g.tools.map(k=>{const v=p&&Es(k.name);return e.jsx(Ze,{level:2,label:k.name,labelTone:v?"accent":"default",hasChevron:v,open:c,onToggle:()=>d(w=>!w),tokens:n(k.total_tokens||0),percent:null,children:v&&e.jsx(Rs,{execDetails:a,source:r})},k.name)})}),p&&!f&&e.jsx(Rs,{execDetails:a,source:r})]},g.name)})})}function jd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null,deviceId:i=null}){const{formatTokens:o}=Ne(),[c,d]=u.useState(null),[h,x]=u.useState(!1),[g,m]=u.useState(null),[p,f]=u.useState({}),b=u.useRef({});function k(N){f(P=>({...P,[N]:!P[N]}))}if(u.useEffect(()=>{let N=!1;const P=`${t||""}|${a||""}|${r||"claude"}|${i||""}`,de=b.current[P];return d(de||null),x(!0),n?.(!0),m(null),_i({from:t,to:a,source:r,device:i,timeZone:rn(),tzOffsetMinutes:an()}).then(oe=>{N||(b.current[P]=oe,d(oe))}).catch(oe=>{N||m(oe?.message||String(oe))}).finally(()=>{N||(x(!1),n?.(!1))}),()=>{N=!0}},[t,a,r,i]),h&&!c)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(N=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${N*80}ms`}},N))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(g)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(_d(r))});if(!c||c.scope!=="supported"||!c.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(c?.reason==="local_history_only"?"settings.local_data.local_history_only":Ln(r))});const v=r==="claude"?dd(c.categories||[],s):ud(c,s),w=c.tool_calls_breakdown||null,C=c.skills_breakdown||null,D=c.message_breakdown||null,M=c.configured_resources||null,A=c.exec_command_breakdown||null,I=fd(C?.skills||[]),j=gd(D?.categories||[]),_=r==="codex"&&(c?.breakdown_status==="queue_fallback"||c?.fallback==="queue_totals"),T=r==="claude"?w?.tool_calls||null:w||null,{mcpSet:z,residualSet:B,mcpTotalTokens:U}=md(T),L=r==="claude"&&w?.subagents||null,$=L?.categories?.length>0||(M?.custom_agents_count||0)>0,V=r==="claude"?(B?.categories||[]).reduce((N,P)=>N+Number(P?.totals?.total_tokens||0),0):0,H=r==="claude"?(L?.categories||[]).reduce((N,P)=>N+Number(P?.totals?.total_tokens||0),0):0,F=[...v].sort((N,P)=>(P.totals?.total_tokens||0)-(N.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:v.filter(N=>N.percent>0).filter(N=>!(r==="claude"&&(N.key==="tool_calls"||N.key==="custom_agents"))).map(N=>`${Ms(N.key)} ${N.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[F.map(N=>{const P=N.key==="system_prompt",de=N.key==="messages",oe=N.key==="tool_calls",G=N.key==="custom_agents";if(N.key,r==="claude"&&(oe||G))return null;const ie=de&&j.length>0||oe&&(B?.categories?.length>0||_)||G&&$&&L,he=!!p[N.key],fe=td(N.key,r),ye=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:fe},"aria-hidden":"true"}),Oe=P?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(un,{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,X=N.percent>0?`${N.percent.toFixed(N.percent<.1&&N.percent>0?2:1)}%`:"0.0%";return e.jsxs(Ze,{level:0,colorSquare:ye,label:Ms(N.key),labelSuffix:Oe,tokens:o(N.totals?.total_tokens||0),percent:X,hasChevron:ie,open:he,onToggle:()=>k(N.key),share:N.percent,fillColor:fe,children:[de&&e.jsx("ul",{className:"space-y-0.5",children:j.map(O=>e.jsx(Ze,{level:1,label:yd(O),tokens:o(O.totals.total_tokens||0),percent:null},O.key||O.name))}),oe&&B&&e.jsx(Gt,{toolSet:B,execDetails:A,source:r,codexQueueFallback:_}),oe&&_&&!B&&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")}),G&&L&&e.jsx(Gt,{toolSet:L,execDetails:null,source:r,codexQueueFallback:!1})]},N.key)}),r==="claude"&&B?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(V),percent:null,hasChevron:!0,open:!!p.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Gt,{toolSet:B,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&L?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(H),percent:null,hasChevron:!0,open:!!p.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Gt,{toolSet:L,execDetails:null,source:r,codexQueueFallback:!1})}),z?.categories?.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(U),percent:null,hasChevron:!0,open:!!p.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Gt,{toolSet:z,execDetails:null,source:r,codexQueueFallback:!1})}),I.length>0&&e.jsx(Ze,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:o(I.reduce((N,P)=>N+(P.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!p.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:I.slice(0,12).map(N=>e.jsx(Ze,{level:1,label:N.name,tokens:o(N.total_tokens),percent:null},N.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(wd(r))}),_?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,M?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(M.skills_count||0)," skills ·"," ",Ie(M.mcp_servers_count||0)," MCP servers ·"," ",Ie(M.custom_agents_count||0)," agents ·"," ",Ie(M.memory_files_count||0)," memory files"]}):null]})}function En({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 ot="__all__",Nd=`${100 .toFixed(2)}%`;function ea(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function Ea(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Qt(a);return(a===tn?s:s*r)<.01?`<${n}0.01`:aa(s,{decimals:2,currency:a,rate:r})}function Sd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Fs(a)}:{key:a.key,label:a.label||Fs(a.key)}):[]}function Cd(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 Td={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 dr(t,a){const r=t?.toUpperCase?.()||"";return Td[r]||`hsl(${150+a*40}, 60%, 45%)`}function Ad(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 Dd(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 Md(t){return!!t?.models?.length}function Rn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function ur(t){const a=Rn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}function Is(t){return(Number(t?.requests)||0)>0&&!(Number(t?.usage)>0)}function Ld(t,a){const r=ea(a,t?.usage),s=Math.max(0,Number(t?.requests)||0);return r&&s>0?`${r} · ${l("usage.overview.request_count",{count:s})}`:r||(s>0?l("usage.overview.request_count",{count:s}):null)}const Ed={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Fs(t){const a=Ed[t];return a?l(a):String(t).toUpperCase()}function Rd({loading:t,onClick:a}){const r=dn();return e.jsx(ji,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(Ke.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(Ni,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function Id(){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 Fd(){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 $d({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:c,onCostInfo:d,fleetData:h=[],onRefresh:x,loading:g,announceLoading:m=!1,summaryLoading:p=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:v,customTo:w,onCustomRangeApply:C,customRangeOpen:D,onCustomRangeOpenChange:M,onOpenShare:A,from:I,to:j,deviceOptions:_=[],selectedDevice:T="",dataRevision:z=0,onDeviceChange:B,accountView:U=!1,accountScopeSwitchable:L=!1,onAccountScopeChange:$=null}){const V=Sd(a),H=yl(Si()),F=Cd(String(s??"")),N=t==="week"&&typeof I=="string"&&typeof j=="string"&&I.slice(0,7)!==j.slice(0,7),P=t!=="day"&&I&&j?`${va(I,H)} — ${va(j,H)}`:null,de=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[oe,G]=u.useState(de);u.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const S=window.matchMedia("(max-width: 639px)"),q=se=>G(se.matches);return S.addEventListener("change",q),()=>S.removeEventListener("change",q)},[]);const ie=F!=null&&!oe,he=u.useRef(null);u.useEffect(()=>{const S=he.current?.querySelector('[aria-selected="true"]');S&&typeof S.scrollIntoView=="function"&&S.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[fe,ye]=u.useState(null),{resolvedTheme:Oe}=vi(),{currency:X,rate:O}=ra(),{formatTokens:le}=Ne(),ee=Oe==="dark",ne=ee?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",ve=ee?"rgba(10,10,10,0)":"rgba(255,255,255,0)",ae=p&&!b,Z=f&&!h.some(Md);u.useEffect(()=>{ye(null)},[t,I,j,T,z]);const te=S=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(S.key))return;const q=Array.from(S.currentTarget.querySelectorAll('[role="tab"]')).filter(re=>!re.disabled),se=q.indexOf(S.target.closest('[role="tab"]'));if(se===-1||q.length===0)return;S.preventDefault();let pe=se;S.key==="Home"?pe=0:S.key==="End"?pe=q.length-1:S.key==="ArrowRight"?pe=(se+1)%q.length:pe=(se-1+q.length)%q.length,q[pe].focus(),q[pe].click()},ge=ie?e.jsx(Zl,{value:F,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:ee?0:8,gradientFrom:ne,gradientTo:ve,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,xe=h.filter(S=>S.models?.length>0&&!Is(S)),je=h.filter(S=>S.models?.length>0&&Is(S)),Ae=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="devin"),Qe=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="kiro"),Dt=xe.some(S=>String(S?.source||S?.label||"").trim().toLowerCase()==="trae"),Xe=u.useMemo(()=>zc(h),[h]),Mt=Xe.reduce((S,q)=>S+(Number(q.usage)||0),0),W=xe.reduce((S,q)=>S+(Number(q.usd)||0),0),Se=fe==null?null:fe===ot||xe.some(function(q){return q.label===fe})?fe:null;return e.jsx(Te,{className:k,children:e.jsxs("div",{"aria-busy":g||ae||Z,children:[m?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:he,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:te,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:V.map(S=>{const q=t===S.key,se=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${q?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(S.key==="custom"){const pe=q&&v&&w?`${va(v,H)} — ${va(w,H)}`:S.label;return e.jsxs(_l,{open:D,onOpenChange:re=>{re?r?.("custom"):M?.(re)},children:[e.jsx(wl,{render:e.jsx("button",{role:"tab","aria-selected":q,tabIndex:q?0:-1,type:"button",className:se}),children:pe}),e.jsx(vl,{children:e.jsx(jl,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(Nl,{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(fl,{from:v,to:w,onApply:C,onCancel:()=>M?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":q,tabIndex:q?0:-1,type:"button",className:se,onClick:()=>r?.(S.key),children:S.label},S.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[L&&$?e.jsxs("div",{role:"group","aria-label":l("usage.overview.scope_switch_aria"),className:"inline-flex shrink-0 items-center h-8 rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 p-0.5",children:[e.jsx("button",{type:"button","aria-pressed":!U,title:l("usage.overview.scope_local_tip"),onClick:()=>$("local"),className:`inline-flex items-center h-7 px-2.5 text-xs font-medium rounded-md transition-colors duration-200 ${U?"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-oai-white":"bg-oai-white dark:bg-oai-gray-600 shadow-sm text-oai-black dark:text-oai-white"}`,children:l("usage.overview.scope_local")}),e.jsx("button",{type:"button","aria-pressed":U,title:l("usage.overview.scope_account_tip"),onClick:()=>$(null),className:`inline-flex items-center h-7 px-2.5 text-xs font-medium rounded-md transition-colors duration-200 ${U?"bg-oai-white dark:bg-oai-gray-600 shadow-sm text-oai-black dark:text-oai-white":"text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-black dark:hover:text-oai-white"}`,children:l("usage.overview.scope_account")})]}):null,!(L&&$)&&U?e.jsx("span",{title:l("usage.overview.scope_account_tip"),className:"inline-flex shrink-0 items-center h-8 px-2.5 text-xs font-medium rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-700 dark:text-oai-gray-300",children:l("usage.overview.scope_account")}):null,_.length>1?e.jsx(on,{value:T,onValueChange:B,options:_,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx($l,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,x&&e.jsx(Rd,{loading:g,onClick:x})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:ae?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:ge}):e.jsx("span",{title:n||void 0,children:ge})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${ae?"":"hidden"}`,children:e.jsx(Id,{})})]}),c&&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:[c,e.jsx(un,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:c})}),Dt&&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")]}),P?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:P}),N?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:Z?void 0:"hidden",children:e.jsx(Fd,{})}),(xe.length>0||je.length>0)&&e.jsxs("div",{className:"space-y-6",children:[xe.length>0&&e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:xe.map(S=>l("usage.overview.distribution_item",{label:dt(S.label),percent:ur(S)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:xe.map((S,q)=>{const se=dr(S.label,q),pe=dt(S.label),re=ur(S);return e.jsx(Ke.div,{initial:{width:0},animate:{width:`${Rn(S)}%`},transition:{duration:.5,delay:.45+q*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:se},title:`${pe}: ${re}%`},S.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":Se===ot,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:ea(le,Mt)||String(0),cost:Ea(W,X,O)||`${Qt(X)}0`,count:Xe.length}),onClick:()=>ye(Se===ot?null:ot),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${Se===ot?"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(En,{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:Nd}),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:Xe.length})})]}),xe.map((S,q)=>{const se=dr(S.label,q),pe=Se===S.label,re=dt(S.label),ue=ur(S);return e.jsxs("button",{"aria-expanded":pe,"aria-controls":`provider-details-${S.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:re,percent:ue,tokens:ea(le,S.usage)||String(0),cost:Ea(S.usd,X,O)||`${Qt(X)}0`,action:l(pe?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>ye(pe?null:S.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${pe?"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:S.label,size:15,color:se,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:re,children:re})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[ue,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:S.models.length})})]},S.label)})]}),Se===ot&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Ae&&e.jsx(Fn,{}),Qe&&e.jsx($n,{}),e.jsx(Hd,{models:Xe})]}),Se!=null&&Se!==ot&&e.jsx("div",{id:`provider-details-${Se}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:Se}),className:"mt-2",children:xe.filter(S=>S.label===Se).map(S=>{const q=dr(S.label,0),se=Ad(S),pe=[...S.models].sort((ue,Ce)=>(Ce.share||0)-(ue.share||0)),re=se?Dd(se):dt(S.label);return e.jsx(qd,{provider:S,color:q,providerHeading:re,contextSource:se,deviceId:T,from:I,to:j,sortedModels:pe},S.label)})})]}),je.length>0&&e.jsx(Kd,{providers:je})]})})}const Pd=[{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"}],zd="grid grid-cols-[minmax(0,1fr)_auto_auto_auto] items-baseline gap-x-3 mb-1.5 sm:grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_minmax(4.5rem,max-content)]";function Od({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Ne();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:Pd.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 Bd(t,a){const r=l(t==="priority"?"usage.overview.tier_fast":t==="ultrafast"?"usage.overview.tier_ultrafast":"usage.overview.tier_standard"),s=t==="standard"?0:Ic(a,t);if(!(s>1))return r;const n=Number.isInteger(s)?String(s):String(Math.round(s*100)/100);return l("usage.overview.tier_rate_label",{label:r,rate:n})}function Ud({model:t}){const{currency:a,rate:r}=ra(),{formatTokens:s,formatTokensTooltip:n}=Ne();if(!jn(t))return null;const i=[{key:"standard",split:Fc(t)},...Xt.map(o=>({key:o,split:t?.tiers?.[o]||null}))].filter(o=>o.split&&(La(o.split.tokens)>0||o.split.cost>0));return i.length?e.jsx("div",{className:"mb-1.5 flex flex-col gap-y-1","data-model-speed-tiers":!0,children:i.map(o=>{const c=La(o.split.tokens);return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 text-[11px] tabular-nums",children:[e.jsx("span",{className:"min-w-[8rem] text-oai-gray-500 dark:text-oai-gray-400",children:Bd(o.key,t)}),e.jsx("span",{title:n(c),className:"text-oai-gray-600 dark:text-oai-gray-300",children:s(c)}),e.jsx("span",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:Ea(o.split.cost,a,r)})]},o.key)})}):null}function $s({model:t,tokensLabel:a,costLabel:r,unpricedLabel:s,expandable:n,isExpanded:i}){const{formatTokensTooltip:o}=Ne();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",{title:s?l("dashboard.cost_breakdown.unpriced"):void 0,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??s}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(i?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(kl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${i?"rotate-180":""}`})]})]})]})}function In({models:t,color:a}){const{currency:r,rate:s}=ra(),{formatTokens:n}=Ne(),[i,o]=u.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(c=>{const d=Ld(c,n),h=Ea(c.cost,r,s),x=!h&&Number(c.usage)>0&&Lr(c)?l("dashboard.cost_breakdown.unpriced_label"):null,g=Math.max(0,Math.min(100,Number(c.share)||0)),m=c.id||c.name,p=Lc(c),f=p&&i===m,b=zd,k={model:c,tokensLabel:d,costLabel:h,unpricedLabel:x,expandable:p,isExpanded:f};return e.jsxs("div",{"data-model-rank-row":!0,children:[p?e.jsx("button",{type:"button",onClick:()=>o(f?null:m),"aria-expanded":f,className:`${b} w-full cursor-pointer text-left`,children:e.jsx($s,{...k})}):e.jsx("div",{className:b,children:e.jsx($s,{...k})}),f&&e.jsxs(e.Fragment,{children:[e.jsx(Od,{tokens:c.tokens}),e.jsx(Ud,{model:c})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":g,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${g}%`,backgroundColor:a,opacity:.45}})})]},m)})})}function Hd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(En,{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(In,{models:t,color:"var(--oai-blue)"})]})}function Fn(){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 $n(){return e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.kiro_notice_title"),"."]})," ",l("usage.overview.kiro_notice_body")]})}function Kd({providers:t}){const a=t.map(r=>l("usage.overview.request_only_item",{label:dt(r.label),count:Math.max(0,Number(r.requests)||0)})).join(l("usage.overview.request_only_separator"));return e.jsx("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:l("usage.overview.request_only_note",{items:a})})}function qd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o,deviceId:c}){const{formatTokens:d}=Ne(),[h,x]=u.useState(!1),g=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",m=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",p=String(t?.source||t?.label||"").trim().toLowerCase()==="kiro";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(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&&h&&e.jsx(bl,{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:ea(d,t.cacheReusedTokens)||String(0),input:ea(d,t.cacheInputTokens)||String(0)})]}),g&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),m&&e.jsx(Fn,{}),p&&e.jsx($n,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(jd,{from:n,to:i,source:s,deviceId:c,referenceTotalTokens:t.usage,onLoadingChange:x})}):null,e.jsx(In,{models:o,color:a})]})}function Vd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:c,isDragging:d}=tl({id:t}),h=u.useRef(null),x=u.useRef(null);u.useLayoutEffect(()=>{if(!r)return;const m=h.current?h.current.childNodes.length===0:!0;x.current!==m&&(x.current=m,r(t,m))});const g={transform:al.Transform.toString(o)||void 0,transition:c,zIndex:d?20:void 0};return e.jsxs("div",{ref:i,style:g,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:h,"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 Wd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,x]=u.useState(null),g=st([t,a,r,s,n]),m=u.useCallback(async()=>{if(!t)return;const p=g();d(!0),x(null);try{const f=await ze(s);if(!p())return;const b=await Ci({from:a,to:r,device:n,accessToken:f});if(!p())return;o(b||null)}catch(f){if(!p())return;x(f?.message||String(f)),o(null)}finally{p()&&d(!1)}},[t,a,r,s,n,g]);return u.useEffect(()=>{if(!t){o(null),x(null),d(!1);return}o(null),x(null),d(!0),m()},[t,m]),{data:i,loading:c,error:h,refresh:m}}function Pn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function zn(t){return t==null?"—":`${Math.round(t*100)}%`}function Gd(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 Yd({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:Pn(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:zn(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:Gd(t.cost_usd,t.accepted)})]})}function Jd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Ne(),{enabled:i}=Sl(),{data:o,loading:c}=Wd({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const d=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(m=>m.outcomes>0&&m.key!=="unknown");if(!d.length)return null;const h=d.slice(0,6),x=o.totals||{},g=`${l("qpd.card.subtitle")}${c?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(Te,{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:g}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(m=>e.jsx(Yd,{row:m},m.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:x.accepted??0,outcomes:x.outcomes??0,cost:Pn(x.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(x.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(x.effective_tokens),rate:zn(x.acceptance_rate)})})]}),x.outcomes<15&&e.jsxs("p",{className:"mt-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500 italic border-t border-oai-gray-100 dark:border-oai-gray-800/40 pt-2",children:["* ",l("qpd.card.sparse_notice","Tip: Spark outcomes dataset might skew Quality/$ ratios. For precise metrics, select a narrower time window.")]})]})}const Zd=new Set(["unknown","synthetic","openai"]);function mr(t){return t==null?"—":`${Math.round(t*100)}%`}function Qd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Je(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function Xd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Zd.has(r)&&Number(t?.edit_turns||0)>0}function Ps(){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 eu({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=u.useState({requestKey:null,loading:!0,sessions:null,context:null}),i=s.requestKey===r?s:{loading:!0,sessions:null,context:null},o=u.useId(),{enabled:c}=Cl(),d=st([c,t,a]),{formatTokens:h}=Ne(),x=C=>h(C,{mode:Jt.COMPACT});u.useEffect(()=>{const C=d();if(!c){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Ti({from:t,to:a}),Ai()]).then(([D,M])=>{C()&&n({requestKey:r,loading:!1,sessions:D,context:M})}).catch(()=>{C()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[c,t,a,r,d]);const g=u.useMemo(()=>(i.sessions?.by_model||[]).filter(Xd).slice(0,5),[i.sessions]),m=u.useMemo(()=>(i.sessions?.subagents||[]).slice(0,3),[i.sessions]);if(!c||!i.loading&&!i.sessions?.available&&!i.context?.estimated_fixed_tokens)return null;const p=i.sessions?.summary||{},f=p.edit_session_rate??p.productive_rate,b=p.first_pass_rate??p.one_shot_rate,k=p.edit_sessions??p.productive_sessions??0,v=p.sessions??i.sessions?.session_count??0,w=p.edit_turns??0;return i.loading&&!i.sessions&&!i.context?e.jsxs(Te,{children:[e.jsx(Ps,{}),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(Te,{children:[e.jsx(Ps,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(hr,{label:l("sessions.card.edit_sessions"),value:mr(f),detail:l("sessions.card.edit_session_value",{edits:Je(k),sessions:Je(v)})}),e.jsx(hr,{label:l("sessions.card.first_pass"),value:mr(b),detail:l("sessions.card.edit_session_value",{edits:Je(p.first_pass_sessions??p.one_shot_sessions??0),sessions:Je(k)})}),e.jsx(hr,{label:l("sessions.card.cost_edit"),value:Qd(p.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Je(w)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Je(v),edits:Je(w)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":o,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:o,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")})]})]}),!!g.length&&e.jsx(Wi,{wrapperClassName:"w-full",label:l("sessions.card.scroll"),children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium whitespace-nowrap",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:g.map(C=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:C.model,children:C.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:l("sessions.card.edit_session_value",{edits:Je(C.edit_sessions??C.productive_sessions??0),sessions:Je(C.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:mr(C.first_pass_rate??C.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums whitespace-nowrap",children:x(C.tokens_per_edit)})]},C.model))})]})}),i.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:x(i.context.estimated_fixed_tokens)})]}):null,!!m.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),m.map(C=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:C.name,calls:Math.round(C.calls)})},C.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function hr({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 tu(){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 au(){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(Te,{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(Te,{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(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(tu,{})]})}),e.jsx(Te,{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(Te,{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(Te,{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 ru=Ll.slice(0,10),zs=.06,su=.11,nu=.05;function Os({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(Ml,{logos:ru,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(Ke.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 ou(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:c,activeDays:d,identitySubscriptions:h,identityScrambleDurationMs:x,projectUsageEntries:g,projectUsageLimit:m,setProjectUsageLimit:p,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:v,isLocalMode:w,accountView:C,accountScopeSwitchable:D,onAccountScopeChange:M,shouldShowInstall:A,installPrompt:I,handleCopyInstall:j,installCopied:_,installInitCmdDisplay:T,trendRowsForDisplay:z,trendFromForDisplay:B,trendToForDisplay:U,trendZoomConfig:L,usageFrom:$,usageTo:V,period:H,trendTimeZoneLabel:F,activityHeatmapBlock:N,periodsForDisplay:P,setSelectedPeriod:de,customFrom:oe,customTo:G,onCustomRangeApply:ie,customRangeOpen:he,onCustomRangeOpenChange:fe,summaryLabel:ye,summaryValue:Oe,summaryFullValue:X,hasSummary:O,summaryLoading:le,providersLoading:ee,onToggleSummaryFormat:ne,summaryTotalTokensRaw:ve,summaryCostValue:ae,summaryConversationsValue:Z,rollingUsage:te,costInfoEnabled:ge,openCostModal:xe,costModalOpen:je,closeCostModal:Ae,allowBreakdownToggle:Qe,refreshAll:Dt,usageLoadingState:Xe,announceUsageLoading:Mt,initialDashboardLoading:W,fleetData:Se,hasDetailsActual:S,dailyEmptyPrefix:q,installSyncCmd:se,dailyEmptySuffix:pe,detailsColumns:re,ariaSortFor:ue,toggleSort:Ce,sortIconFor:Fe,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Ia,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Fa,detailsDateKey:$a,renderDetailDate:pt,renderDailyBreakdownDate:Q,renderDetailCell:sa,DETAILS_PAGED_PERIODS:be,detailsPageCount:ke,detailsPage:Et,setDetailsPage:gt,deviceOptions:_e,selectedDevice:ft,onDeviceChange:Pa,deviceUsageBlock:Rt,localHistoryOnly:na,localHistoryRevision:It,leftCardOrder:oa,onLeftReorder:Ft,rightCardOrder:Be,onRightReorder:De}=t,$t=null,yt=null,Pt={statsPanel:!0,installCopy:A,activityHeatmap:!!N,deviceUsage:!!Rt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},za=(oa||[]).filter(me=>Pt[me]),ia={usageOverview:!0,dataDetails:!s},Oa=(Be||[]).filter(me=>ia[me]);function la(me,J){switch(me){case"statsPanel":return e.jsx(nt,{delay:J,children:e.jsx(Qc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:H,startDate:c??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:h,periodConversations:Z,rolling:te,topModels:b})});case"installCopy":return e.jsx(nt,{delay:J,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:I}),e.jsxs(Ke.button,{onClick:j,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:T}),e.jsx(Ke.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:_?"Copied ✓":"Copy"},_?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(nt,{delay:J,children:N});case"deviceUsage":return e.jsx(nt,{delay:J,children:Rt});case"trendMonitor":return e.jsx(nt,{delay:J,children:e.jsx(sn,{rows:z,from:B,to:U,period:H,timeZoneLabel:F,showTimeZoneLabel:!1,zoomConfig:L})});case"qualityPerDollar":return e.jsx(Jd,{from:$,to:V,deviceId:ft});case"sessionInsights":return e.jsx(eu,{from:$,to:V});default:return null}}function zt(me,J){switch(me){case"usageOverview":return e.jsx(nt,{delay:J,children:e.jsx($d,{accountView:C,accountScopeSwitchable:D,onAccountScopeChange:M,period:H,periods:P,onPeriodChange:de,summaryLabel:ye,summaryValue:Oe,summaryFullValue:X,hasSummary:O,summaryLoading:le,providersLoading:ee,onToggleSummaryFormat:O?ne:null,summaryCostValue:ae,onCostInfo:ge?xe:null,fleetData:Se,onRefresh:s?null:Dt,loading:Xe,announceLoading:Mt,onOpenShare:s?null:r,customFrom:oe,customTo:G,onCustomRangeApply:ie,customRangeOpen:he,onCustomRangeOpenChange:fe,from:$,to:V,deviceOptions:_e,selectedDevice:ft,dataRevision:It,onDeviceChange:Pa})});case"dataDetails":return e.jsx(nt,{delay:J,children:e.jsx(Jc,{projectEntries:g,projectLimit:m,onProjectLimitChange:p,projectDetailQuery:f,copy:a,hasDetailsActual:S,dailyEmptyPrefix:q,installSyncCmd:se,dailyEmptySuffix:pe,detailsColumns:re,ariaSortFor:ue,toggleSort:Ce,sortIconFor:Fe,pagedDetails:Lt,dailyBreakdownRows:xt,dailyBreakdownColumns:qe,dailyBreakdownAriaSortFor:Ia,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Fa,detailsDateKey:$a,renderDetailDate:pt,renderDailyBreakdownDate:Q,renderDetailCell:sa,DETAILS_PAGED_PERIODS:be,period:H,detailsPageCount:ke,detailsPage:Et,setDetailsPage:gt})});default:return null}}const Ba=rl(ms(cl,{activationConstraint:{distance:6}}),ms(ll,{coordinateGetter:il})),Ot=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||Ft?.(String(J.id),String($e.id))},[Ft]),Bt=u.useCallback(me=>{const{active:J,over:$e}=me;!$e||J.id===$e.id||De?.(String(J.id),String($e.id))},[De]);function ca(me,J,$e,ua){return s?e.jsx(e.Fragment,{children:me.map((Ge,Ut)=>e.jsx(Nt.Fragment,{children:J(Ge,$e+zs*Ut)},Ge))}):e.jsx(sl,{sensors:Ba,onDragEnd:ua,children:e.jsx(nl,{items:me,strategy:ol,children:me.map((Ge,Ut)=>e.jsx(Vd,{id:Ge,children:J(Ge,$e+zs*Ut)},Ge))})})}const We=ca(za,la,su,Ot),da=ca(Oa,zt,nu,Bt);return e.jsxs(e.Fragment,{children:[e.jsxs(Ul,{bare:!s,hideHeader:s,header:$t,footer:s?null:yt,className:s?"screenshot-mode":"",children:[i&&e.jsx(Os,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Os,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&W&&e.jsx(au,{}),!i&&!n&&!W&&e.jsxs(e.Fragment,{children:[na&&e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.local_data.local_history_only")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:We}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:da})]})]})]}),e.jsx(Uc,{isOpen:je,onClose:Ae,fleetData:Se})]})}function iu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0,localView:c=!1}={}){const d=c&&!n&&El(),h=!!(d||n&&i),[x,g]=u.useState(0),[m,p]=u.useState([]),[f,b]=u.useState([]),[k,v]=u.useState(!1),[w,C]=u.useState(null),D=st([h,d,t,a,r,s,i,o]),M=u.useCallback(async()=>{const A=D();if(!h){p([]),b([]),v(!1),C(null);return}v(!0),C(null);try{const I=d?null:await ze(i);if(!A())return;const j=d?await Tl({from:t,to:a,timeZone:r,tzOffsetMinutes:s}):await Di({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:I});if(!A())return;p(Array.isArray(j?.devices)?j.devices:[]),b(Array.isArray(j?.account_sources)?j.account_sources:[]),g(d&&Number(j?.revision)||0)}catch(I){if(!A())return;C(I?.message||String(I)),p([]),b([])}finally{A()&&v(!1)}},[h,d,i,t,a,r,s,o,D]);return u.useEffect(()=>{if(d)return window.addEventListener(hs,M),()=>window.removeEventListener(hs,M)},[d,M]),u.useEffect(()=>{p([]),b([]),C(null),h&&v(!0),M()},[h,M]),{devices:m,accountSources:f,loading:k,error:w,refresh:M,revision:x}}const lu=/^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 _r(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(lu);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 Us=" · ",Hs="%";function Ks({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Fl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(ss,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(ss,{className:a,"aria-hidden":!0}):e.jsx(hn,{className:a,"aria-hidden":!0})}function qs(t,a){return a===t?.id||t?.isCurrent===!0}function cu({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:c}=Ne(),[d,h]=u.useState(""),[x,g]=u.useState(""),[m,p]=u.useState(!1),[f,b]=u.useState(""),k=typeof i=="function",v=typeof n=="function",w=!!s,C=t.reduce((_,T)=>_+(Number(T.total_tokens)||0),0)+a.reduce((_,T)=>_+(Number(T.total_tokens)||0),0),D=u.useMemo(()=>t.filter(_=>(Number(_.total_tokens)||0)>0||_.id===s).sort((_,T)=>(Number(T.total_tokens)||0)-(Number(_.total_tokens)||0)),[t,s]);function M(_){b(""),h(_.id);const T=typeof _.device_name=="string"?_.device_name:"";g(_r(_)===T?T:"")}function A(){h(""),g(""),b("")}async function I(_){const T=x.trim();if(!(!T||m)){p(!0),b("");try{await i(_.id,T),h(""),g("")}catch{b(_.id)}finally{p(!1)}}}const j=a.filter(_=>(Number(_.total_tokens)||0)>0);return D.length===0&&j.length===0?e.jsxs(Te,{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(hn,{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(Te,{bodyClassName:"!px-3 !py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:l("dashboard.device_card.title")}),v&&w&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[D.map(_=>{const T=Number(_.total_tokens)||0,z=C>0?(T/C*100).toFixed(1):"0.0",B=s===_.id,U=_r(_)||l("dashboard.device_card.unnamed"),L=d===_.id,$=B?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",V=w&&!B?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[L?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(Ks,{platform:_.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:x,disabled:m,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:H=>g(H.target.value),onKeyDown:H=>{H.key==="Enter"?I(_):H.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:m||!x.trim(),onClick:()=>I(_),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Rl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:m,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Ar,{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 ${$}`,style:{width:`${z}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":B,"aria-label":`${l("dashboard.device_filter.aria")}: ${U}${qs(_,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(B?"":_.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 ${V} ${B?"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(Ks,{platform:_.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:U,children:U}),qs(_,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")}),_.imported_at&&e.jsx("span",{className:"shrink-0 whitespace-nowrap text-xs text-oai-gray-500",title:l("settings.local_data.snapshot_time",{time:new Date(_.exported_at).toLocaleString()}),children:l("settings.local_data.imported_label")})]}),e.jsxs("span",{title:c(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Us,z,Hs]})]})]}),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 ${$}`,style:{width:`${z}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>M(_),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(Al,{className:"h-3 w-3"})})]}),f===_.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},_.id)}),j.map(_=>{const T=Number(_.total_tokens)||0,z=C>0?(T/C*100).toFixed(1):"0.0",B=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${B}`,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:_.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:dt(_.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:c(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Us,z,Hs]})]})]}),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:`${z}%`}})})]},`account-${_.source}`)})]})]})}function On(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function Bn(){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 du(t){if(!On()||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"};Bn();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,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Vs(t,a){if(!On()||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"};Bn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){ut.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Un=1200,Hn=1630,Kn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},uu="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 xr=!1;function mu(){if(typeof document>"u"||xr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){xr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=uu,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),xr=!0}async function hu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function xu(t,a={}){if(typeof window>"u"||!t)return null;mu(),await hu(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Mi(async()=>{const{toBlob:d,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Un,o=t.offsetHeight||Hn,c={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,c);if(d)return d}catch{}try{const d=await s(t,c);return d?await(await fetch(d)).blob():null}catch{return null}}async function pr(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 Ws(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=K(t);return Number.isFinite(a)?a:0}function pu(t){return t?wr(t.billable_total_tokens??t.total_tokens):0}function gu(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(c=>{const d=!!c?.future,h=Number.isFinite(c?.level)?Math.max(0,Math.min(4,Math.round(c.level))):0;c?.day&&!d&&(r+=1,h>0&&(s+=1));const x=c?.billable_total_tokens??c?.total_tokens??c?.value??0,g=Number.isFinite(x)?Math.max(0,x):0;return{day:typeof c?.day=="string"?c.day:"",level:h,value:g,future:d}})),totalDays:r,activeDays:s}}function fu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:c,periodFrom:d,periodTo:h,heatmap:x,capturedAt:g,currency:m,exchangeRate:p}=t,f=pu(n),b=wr(n?.total_cost_usd),k=Array.isArray(i)?i.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"})):[],v=gu(x);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:c,periodFrom:d,periodTo:h,topModels:k,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:g||new Date().toISOString(),currency:typeof m=="string"&&m.length>0?m.toUpperCase():"USD",exchangeRate:Number.isFinite(p)&&p>0?p:1}}const yu=["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 bu(t){const a=yu[t];return a?l(a):"—"}function qn(t,a){return l("share.date.month_year",{month:bu(t),year:a})}function ku(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:qn(n,r)}function _u(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 qn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function vr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Vn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Qt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function wu(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 vu(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 ju(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 Nu({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],c=i||o[0],d=t.length,h=(d-1)*s,x=Math.max(4,(r-h)/d),g=7*x+6*s;return e.jsx("svg",{width:r,height:g,viewBox:`0 0 ${r} ${g}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((m,p)=>(Array.isArray(m)?m:[]).map((b,k)=>{if(k>=7)return null;const v=ju(b),w=p*(x+s),C=k*(x+s),D=v===null?c:o[v];return e.jsx("rect",{x:w,y:C,width:x,height:x,rx:n,ry:n,fill:D},`${p}-${k}`)}))})}const Su=At("oklch(0.97 0.01 85)"),Re=At("oklch(0.18 0.02 85)"),at=At("oklch(0.38 0.015 85)"),Gs=At("oklch(0.55 0.012 85)"),it=At("oklch(0.55 0.22 25)"),lt='"Instrument Serif", "Times New Roman", Georgia, serif',Cu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Tu=["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=_u(t),r=vr(t.totalTokens),s=Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=ku(t.startDate),i=vu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=wu(t),c=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Su,color:Re,fontFamily:Cu,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 ${Gs}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:it}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:at,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:at,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:lt,fontSize:52,fontStyle:"italic",lineHeight:1,color:Re,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:at,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Re},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:it,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:lt,fontSize:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:lt,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:it,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:at},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})})]})]}),c?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:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Nu,{weeks:t.heatmapWeeks,palette:Tu,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 ${Re}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:lt,fontStyle:"italic",fontSize:26,color:at,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((d,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Gs}`},children:[e.jsx("div",{style:{fontFamily:lt,fontSize:34,fontStyle:"italic",color:it,lineHeight:1},children:String(h+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:lt,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.name}),e.jsx("div",{style:{fontFamily:lt,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:vr(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},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:it},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:it},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:it},children:"→ tokentracker.cc"})]})]})]})}const Au=Kn["annual-report"].width,Du="#0a0820",rt="#ffffffee",ct="rgba(255,255,255,0.45)",gr="#a78bfa",Mu={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(", ")},Sa={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"},jr='"Space Grotesk", "Inter Tight", sans-serif',fr='"Inter Tight", sans-serif',Lu="rgba(255,255,255,0.06)",Gn=[Lu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Yn=48,Jn=28,Ra=4,Zn=20,Eu=Au-Yn*2-Jn*2,Ru=(Eu-Zn*2)/3,Nr=Math.min(Math.floor((Ru-Ra*6)/7),40),Iu=Nr*7+Ra*6;function Fu(t){if(!Array.isArray(t))return t;const a=[];for(const c of t)if(Array.isArray(c))for(const d of c)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((c,d)=>c-d);const r=c=>{const d=a.length,h=(d-1)*c,x=Math.floor(h);return Math.round((a[x]??0)+((a[Math.min(d-1,x+1)]??0)-(a[x]??0))*(h-x))},s=r(.5),n=r(.75),i=r(.9),o=c=>!c||c<=0?0:c<=s?1:c<=n?2:c<=i?3:4;return t.map(c=>Array.isArray(c)?c.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:o(d.value)}:d):c)}function $u(t){if(!Array.isArray(t))return[];const a={},r=Fu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Pu(t){if(!t.length)return[];const a=[...t].sort((o,c)=>o.day.localeCompare(c.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const zu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ou(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Ys(t){const[a,r]=u.useState(null);return u.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Bu({data:t}){const a=Pu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:ct,fontFamily:jr,marginBottom:4},children:zu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ra},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ra},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:Nr,height:Nr,borderRadius:4,background:o<0?"transparent":Gn[o]}},i)})},s))})]})}function Uu({data:t}){const a=$u(t.heatmapWeeks),r=Ou(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Ys(n),o=Ys("/neon_bg.png"),c=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Du,fontFamily:jr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Yn,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:ct,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:rt},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:c})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...Mu,borderRadius:22,padding:Jn,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:ct},children:[e.jsx("span",{children:l("share.card.annual.less")}),Gn.map((h,x)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},x)),e.jsx("span",{children:l("share.card.annual.more")})]}),e.jsx("div",{style:{fontSize:16,fontWeight:700,letterSpacing:"0.14em",color:"rgba(255,255,255,0.22)",textTransform:"uppercase"},children:l("share.card.annual.heatmap_title")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(3,${Iu}px)`,gap:`8px ${Zn}px`,justifyContent:"center"},children:a.map(h=>e.jsx(Bu,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{...Sa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:fr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:vr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:ct,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...Sa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:fr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Vn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:ct,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},children:[e.jsxs("div",{style:{...Sa,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:gr,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:ct},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:fr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...Sa,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:gr,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:ct},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:jr,fontSize:28,fontWeight:700,color:rt},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:rt},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:gr},children:"tokentracker.cc"})]})]})]})}const Qn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Hu={broadsheet:Wn,"annual-report":Uu};function Xn(t){return Kn[t]||{width:Un,height:Hn}}function Ku(t){const a=Qn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Js=u.forwardRef(function({data:a,variant:r},s){const n=Hu[r]||Wn,{width:i,height:o}=Xn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function Ca(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const qu=440;function Vu(){const[t,a]=u.useState(null),r=u.useRef(null),s=u.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return u.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function yr({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 Wu({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState("annual-report"),x=u.useRef(null),{toast:g,push:m}=Vu(),p=Li(),f=u.useMemo(()=>{const j=p?.user;if(!j||typeof j!="object")return null;const _=j.user_metadata||{},T=j.profile||{},z=_.avatar_url||_.picture||T.avatar_url||j.avatar_url;return typeof z=="string"&&z.trim()?z.trim():null},[p?.user]);u.useEffect(()=>{t&&(i(null),c(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:o||r.handle,avatarUrl:f},{width:k,height:v}=Xn(d),w=qu/k;u.useEffect(()=>{if(!t)return;const j=_=>{_.key==="Escape"&&a?.()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[t,a]);const C=u.useCallback(async()=>{const j=x.current;if(!j)return null;try{return await xu(j)}catch(_){return console.warn("[share] capture failed",_),null}},[]),D=u.useCallback(async()=>{if(n)return;i("copy");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}let _=!1;if(Ca()){const T=await pr(j);T&&(_=(await du(T)).ok)}else _=await ns(j);m(_?l("share.toast.copied"):l("share.toast.failed"),_?"success":"error"),i(null)},[n,C,m]),M=u.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=u.useCallback(async()=>{if(n)return;i("download");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}if(Ca()){const T=await pr(j);if(T&&(await Vs(T,M())).ok){m(l("share.toast.downloaded"),"success"),i(null);return}}const _=Ws(j,M());m(_?l("share.toast.downloaded"):l("share.toast.failed"),_?"success":"error"),i(null)},[n,C,M,m]),I=u.useCallback(async()=>{if(n)return;i("x");const j=await C();if(!j){m(l("share.toast.failed"),"error"),i(null);return}if(Ca()){const B=await pr(j);B&&(await Vs(B,M()),m(l("share.toast.downloaded"),"success"))}else await ns(j)?m(l("share.toast.copied"),"success"):Ws(j,M());const _=new URL("https://twitter.com/intent/tweet");s&&_.searchParams.set("text",s);const T=p?.user?.id,z=typeof T=="string"&&T?`/u/${T}`:"/";if(_.searchParams.set("url",`https://www.tokentracker.cc${z}?ref=share`),Ca())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:_.toString()})}catch{window.open(_.toString(),"_blank","noopener,noreferrer")}else window.open(_.toString(),"_blank","noopener,noreferrer");i(null)},[n,C,m,s,M,p]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:j=>{j.target===j.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Js,{ref:x,data:b,variant:d})}),e.jsxs(Ke.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},transition:{duration:.18,ease:[.2,.8,.2,1]},className:"relative w-full max-w-[1040px] max-h-[92vh] overflow-hidden rounded-2xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-black shadow-oai-lg",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row max-h-[92vh]",children:[e.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-7 bg-oai-gray-50 dark:bg-oai-gray-950 flex items-center justify-center overflow-auto",children:e.jsxs("div",{style:{width:k*w,height:v*w,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:v,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Js,{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:o,onChange:j=>c(j.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:Qn.map(j=>e.jsx("button",{type:"button",onClick:()=>h(j.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===j.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Ku(j.id)},j.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(yr,{onClick:I,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(yr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(yr,{onClick:D,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(mn,{children:g?e.jsx(Ke.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",g.kind==="error"?"bg-red-600 text-white":g.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:g.text})},g.id):null})]})]}):null}function Gu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:c,periodFrom:d,periodTo:h,heatmap:x,accessToken:g,userId:m,currency:p,exchangeRate:f}=t,[b,k]=u.useState(null),v=f;return u.useEffect(()=>{if(!a||!m&&!ht())return;let w=!1;return(async()=>{try{const D=await Ei({accessToken:g,userId:m,period:c==="day"||c==="custom"?"week":c,metric:"all",limit:100,offset:0});if(w)return;const A=(Array.isArray(D?.entries)?D.entries:Array.isArray(D)?D:[]).find(j=>j?.is_me===!0),I=typeof A?.rank=="number"?A.rank:null;k(I)}catch{w||k(null)}})(),()=>{w=!0}},[a,g,m,c]),u.useMemo(()=>fu({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:b,period:c,periodFrom:d,periodTo:h,heatmap:x,currency:p,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,i,o,b,c,d,h,x,p,v])}function Zs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const Yu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function Ju({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const Zu=["day","week","month","total","custom"],br=new Set(["day","hour","month"]),Yt=new Set(["day","total","custom"]),Qu=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Xu=["usageOverview","dataDetails"];function kr(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 Ta(t){return t?Ct(t,null):null}function Qs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function em(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function tm(){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:!em(window.location.hostname)}function Hm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:c="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:h}){const{resolvedLocale:x}=Ri(),{currency:g,rate:m}=ra(),{mode:p,setMode:f,formatTokens:b,formatTokensTooltip:k}=Ne(),[v,w]=u.useState(!1),[C,D]=u.useState(null),[M,A]=u.useState(null),[I,j]=u.useState(!1),[_,T]=u.useState(null),[z,B]=u.useState(0),[U,L]=u.useState(0),[$,V]=u.useState(null),H=u.useMemo(()=>typeof window>"u"?!1:Ii(window.location.search),[]),F=u.useMemo(()=>tm(),[]),[N,P]=u.useState(!1),de=2200,[oe,G]=u.useState(!0),[ie,he]=u.useState(!1),[fe,ye]=u.useState(!1),[Oe,X]=u.useState(!1),[O,le]=u.useState(!1),ee=u.useRef(!1),ne=ht(),ve=r&&!s,ae=u.useMemo(()=>ve&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,ve]),Z=ve?ae:null,te=i?Fi(o):Z,ge=r||ne||i,xe=ve&&ta(Z),je=r&&s&&!i,{accountView:Ae,revision:Qe,resolving:Dt,scopeSwitchable:Xe,setScopeOverride:Mt}=$i(),W=Ae&&!i,Se=Xe&&!i,S=W?Z:null,q=Dt&&!i;u.useEffect(()=>{if(!r||ne){D(null),A(null),j(!1),T(null);return}if(i)return;if(!xe){D(null),A(null),j(!1),T(null);return}let y=!0;const E=()=>{D(null),A(null),j(!1),T(null)};return j(!0),T(null),(async()=>{let R=null;try{R=await ze(Z)}catch{R=null}if(y){if(!R){E();return}try{const Y={link_code:null,expires_at:null};if(!y)return;D(typeof Y?.link_code=="string"?Y.link_code:null),A(typeof Y?.expires_at=="string"?Y.expires_at:null)}catch(Y){if(!y)return;D(null),A(null),T(Y?.message||"Failed to load link code")}finally{if(!y)return;j(!1)}}})(),()=>{y=!1}},[t,ne,r,i,xe,Z,U]);const se=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");u.useEffect(()=>{if(!se&&(!r||ne||i)){V(null);return}if(!se&&!xe){V(null);return}let y=!0;return(async()=>{let E=null;try{E=await ze(Z)}catch{E=null}if(y){if(!E&&!se){V(null);return}try{const R=await Pi({baseUrl:t,accessToken:E});if(!y)return;V(R&&typeof R=="object"?R:null)}catch{if(!y)return;V(null)}}})(),()=>{y=!1}},[xe,t,Z,ne,i,r]);const pe=u.useMemo(()=>{if(!M)return!1;const y=Date.parse(M);if(!Number.isFinite(y))return!1;const E=z||Date.now();return y<=E},[M,z]);u.useEffect(()=>{!r||ne||i||!M||!pe||I||(D(null),A(null),T(null),L(y=>y+1))},[pe,M,I,ne,r]),u.useEffect(()=>{if(!M||i)return;const y=Date.parse(M);if(!Number.isFinite(y))return;const E=Date.now();if(B(E),y<=E)return;const R=window.setTimeout(()=>B(Date.now()),y-E),Y=()=>{typeof document>"u"||document.visibilityState==="visible"&&B(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",Y),window.addEventListener("focus",Y),()=>{window.clearTimeout(R),typeof document<"u"&&document.removeEventListener("visibilitychange",Y),window.removeEventListener("focus",Y)}},[M]);const re=u.useMemo(()=>rn(),[]),ue=u.useMemo(()=>an(),[]),Ce=u.useMemo(()=>zi(),[]),Fe=i?null:a?.userId||a?.email||"default",[Lt,xt]=u.useState("month"),[qe,Ia]=u.useState(null),[et,Fa]=u.useState(null),[$a,pt]=u.useState(!1),Q=H?"total":Lt,sa=u.useMemo(()=>Q==="custom"&&qe&&et?{from:qe,to:et}:Oi(Q,{timeZone:re,offsetMinutes:ue,now:Ce}),[Ce,Q,re,ue,qe,et]),be=sa.from,ke=sa.to,[Et,gt]=u.useState(null),_e=Et&&Et.startsWith("local:")!==W?Et:null,[ft,Pa]=u.useState(()=>os());u.useEffect(()=>{const y=()=>Pa(os());return window.addEventListener(is,y),window.addEventListener("storage",y),()=>{window.removeEventListener(is,y),window.removeEventListener("storage",y)}},[]);const{devices:Rt,accountSources:na,refresh:It,loading:oa,revision:Ft}=iu({from:be,to:ke,timeZone:re,tzOffsetMinutes:ue,accountView:W,accountAccessToken:S,accountRevision:Qe,localView:!i&&!ne}),Be=W?Qe:Ft,De=u.useMemo(()=>Rt.filter(y=>!W||(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.isCurrent||y.id===ft})),[Rt,ft,W]),$t=u.useMemo(()=>na.filter(y=>(Number(y.total_tokens)||0)>0),[na]),yt=De.length>=2,Pt=(W||De.length>=2)&&De.length+$t.length>=2;u.useEffect(()=>{if(!oa){if(!yt&&!Pt){_e!==null&&gt(null);return}_e&&!De.some(y=>y.id===_e)&&gt(null)}},[yt,Pt,De,_e,oa]);const za=u.useMemo(()=>yt?[{value:"",label:l("dashboard.device_filter.all")},...De.map(y=>{const E=_r(y)||l("dashboard.device_card.unnamed"),R=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${E}${R}`}})]:[],[yt,De,x]),ia=W?{devices:De,accountSources:$t}:Dl(De,$t,_e),Oa=Pt?e.jsx(cu,{devices:ia.devices,accountSources:ia.accountSources,currentDeviceId:ft,selectedDeviceId:_e||"",onSelectDevice:y=>gt(y||null),onRenameDevice:W?async(y,E)=>{const R=await ze(S);await Vi({deviceId:y,name:E,accessToken:R}),await It()}:void 0}):null,la=u.useMemo(()=>Bi({timeZone:re,offsetMinutes:ue}),[re,ue]),zt=u.useMemo(()=>Ui({timeZone:re,offsetMinutes:ue}),[re,ue]),Ba=u.useMemo(()=>`Local time (${zt})`,[zt]),Ot=re,Bt=ue,ca=la,We=u.useMemo(()=>Tr({timeZone:re,offsetMinutes:ue,date:Ce||new Date}),[Ce,re,ue]),da=u.useMemo(()=>Sc({period:Q,selectedFrom:be,selectedTo:ke,todayKey:We}),[be,Q,ke,We]),{daily:me,summary:J,rolling:$e,source:ua,loading:Ge,error:Ut,refresh:Er}=ys({baseUrl:t,accessToken:te,guestAllowed:je,from:be,to:ke,includeDaily:Q!=="total",cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{daily:Rr,loading:eo,refresh:Ir}=ys({baseUrl:t,accessToken:te,guestAllowed:je,from:da.from,to:da.to,includeDaily:!0,includeSummary:!1,cacheKey:Fe?`${Fe}.daily-breakdown`:"daily-breakdown",timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{breakdown:tt,loading:Fr,refresh:$r}=oc({baseUrl:t,accessToken:te,guestAllowed:je,from:be,to:ke,cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),[to,ao]=u.useState(3),{entries:ro,loading:so,refresh:Pr}=rc({baseUrl:t,accessToken:te,from:be,to:ke,timeZone:re,tzOffsetMinutes:ue}),zr=Q==="week"||Q==="month",ma=Q==="week"||Q==="month",Or=u.useMemo(()=>me.filter(y=>y?.future?!1:!y?.day||!We?!0:String(y.day)<=String(We)),[me,We]),{rows:Ye,from:no,to:oo,loading:io,refresh:Br}=Yi({baseUrl:t,accessToken:te,guestAllowed:je,period:Q,from:be,to:ke,months:24,cacheKey:Fe,timeZone:Ot,tzOffsetMinutes:Bt,now:Ce,sharedRows:zr?me:null,sharedRange:zr?{from:be,to:ke}:null,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),lo=u.useMemo(()=>({baseUrl:t,accessToken:te,guestAllowed:je,cacheKey:Fe,timeZone:Ot,tzOffsetMinutes:Bt,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),[t,te,je,Fe,Ot,Bt,Ce,W,S,Be,q,_e]),{daily:bt,heatmap:Ve,loading:Ur,refresh:Hr}=Ql({baseUrl:t,accessToken:te,guestAllowed:je,weeks:52,cacheKey:Fe,timeZone:re,tzOffsetMinutes:ue,now:Ce,accountView:W,accountAccessToken:S,accountRevision:Be,accountViewResolving:q,deviceId:_e}),{data:ha,refresh:Kr}=Ji();u.useEffect(()=>{ha&&typeof ha=="object"&&Hi(ha)},[ha]);const Ue=u.useMemo(()=>Q==="day"?"hour":Q==="total"?"month":"day",[Q]),co=u.useMemo(()=>ks(Ue),[Ue]),xa="day",uo=u.useMemo(()=>ks(xa),[]),[He,qr]=u.useState(()=>({key:"day",dir:"desc"}));u.useEffect(()=>{qr(y=>!br.has(y.key)||y.key===Ue?y:{key:Ue,dir:y.dir})},[Ue]);const kt=u.useMemo(()=>br.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),pa=u.useMemo(()=>{if(Q==="day")return Array.isArray(Ye)?Ye.filter(R=>R?.hour&&!R?.future):[];if(Q==="total"){const R=Array.isArray(Ye)?Ye.filter(Y=>Y?.month&&!Y?.future):[];return bc(R)}const y=Or;return!y.some(R=>!R?.missing&&!R?.future)&&me.length>0?me.filter(R=>!R?.future).slice(-30).filter(R=>R?.day):y},[Q,Ye,Or,me]),Ht=u.useMemo(()=>_s(pa,kt),[pa,kt]),Vr=u.useMemo(()=>pa.some(y=>!y?.missing&&!y?.future),[pa]),Ua=u.useMemo(()=>{if(!Yt.has(Q))return 1;const y=Math.ceil(Ht.length/Ma);return y>0?y:1},[Q,Ht.length]),[Ha,ga]=u.useState(0);u.useEffect(()=>{if(!Yt.has(Q)){ga(0);return}ga(y=>Math.min(y,Ua-1))},[Ua,Q]),u.useEffect(()=>{Yt.has(Q)&&ga(0)},[Q,He.dir,He.key]);const mo=u.useMemo(()=>Yt.has(Q)?kc(Ht,Ha,Ma):Ht,[Ha,Q,Ht]),Wr=u.useMemo(()=>Cc(Rr,{period:Q}),[Rr,Q]),_t=u.useMemo(()=>br.has(He.key)?{...He,key:xa}:He,[He]),ho=u.useMemo(()=>_s(Wr,_t),[Wr,_t]),xo=u.useMemo(()=>ma?me:Q==="day"?Array.isArray(Ye)?Ye.filter(y=>y?.hour):[]:Ye,[me,Q,Ye,ma]),po=ma?be:no,go=ma?ke:oo;function fo(y,E){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(E.endsWith("_tokens")){const R=E==="total_tokens"?Ta(y):y?.[E];return e.jsx("span",{title:k(R),children:b(R)})}return Da(y?.[E])}function yo(y){const E=y?.[Ue];if(E==null)return"";const R=String(E);if(Ue==="hour"){const[Y,Le]=R.split("T");if(Y&&Le)return`${Y} ${Le.slice(0,5)}`}return R}function bo(y){const E=y?.[xa];return E==null?"":String(E)}function ko(y){qr(E=>E.key===y?{key:y,dir:E.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function _o(y){return kt.key!==y?"none":kt.dir==="asc"?"ascending":"descending"}function wo(y){return kt.key!==y?"":kt.dir==="asc"?"▲":"▼"}function vo(y){return _t.key!==y?"none":_t.dir==="asc"?"ascending":"descending"}function jo(y){return _t.key!==y?"":_t.dir==="asc"?"▲":"▼"}const Ka=u.useMemo(()=>{if(!r&&!ne&&!i&&!se)return 0;const y=Number(Ve?.active_days);if(Number.isFinite(y))return y;let E=0;const R=new Set,Y=(we,Pe,Ee)=>{typeof we!="string"||!we||R.has(we)||kr(Pe,Ee)&&(R.add(we),E+=1)};if(Array.isArray(bt))for(const we of bt)Y(we?.day,Ta(we));const Le=Array.isArray(Ve?.weeks)?Ve.weeks:[];for(const we of Le)for(const Pe of Array.isArray(we)?we:[]){const Ee=Qs(Pe);Y(Pe?.day,Ee,Pe?.level)}return E},[r,ne,Ve?.active_days,Ve?.weeks,bt]),[Gr,Yr]=u.useState("month"),No=u.useCallback(y=>{W&&!i&&ar(a?.userId,"history"),y==="custom"?(Yr(E=>E==="custom"?"month":E),xt(E=>qe&&et?"custom":E),pt(!0)):(xt(y),Yr(y),pt(!1))},[qe,et,W,i,a?.userId]),So=u.useCallback((y,E)=>{W&&!i&&ar(a?.userId,"history"),Ia(y),Fa(E),xt("custom"),pt(!1)},[W,i,a?.userId]),Co=u.useCallback(y=>{pt(y),!y&&Lt==="custom"&&!qe&&xt(Gr)},[Lt,qe,Gr]),To=u.useRef(null),fa=u.useMemo(()=>[t||"",Fe||"",W?"cloud":"local",Be??"",Q||"",be||"",ke||"",We||"",_e||"all",re||"",ue??""].join(""),[Be,W,t,Fe,be,Q,_e,re,We,ke,ue]),Kt=u.useCallback(async()=>Zs(To,fa,async()=>{W&&Ki(),W||qi(),await Promise.all([Er(),Hr(),Br(),$r(),Pr(),Ir(),...W?[]:[It()]])}),[W,Ir,It,Hr,$r,Pr,Br,Er,fa]),Ao=u.useRef(null),Jr=u.useCallback(async()=>Zs(Ao,fa,async()=>{await Ju({refreshUsageStats:Kt,refreshUsageLimits:Kr})}),[fa,Kr,Kt]),qa=u.useRef(Kt);u.useEffect(()=>{qa.current=Kt},[Kt]);const Va=u.useRef(null);u.useEffect(()=>{if(!se||ne||W)return;Va.current||(Va.current=ls({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Va.current.then(()=>{if(y)return qa.current()}).catch(E=>{y&&console.warn("[DashboardPage] Reload sync failed:",E)}),()=>{y=!1}},[se,ne,W]),u.useEffect(()=>{if(!se||ne||W)return;const y=jc({refresh:()=>qa.current(),onError:E=>console.warn("[DashboardPage] Automatic usage refresh failed:",E)});return()=>y.stop()},[se,ne,W]);const Do=u.useCallback(async()=>{X(!0);try{se&&await ls(Yu),await Jr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{X(!1)}},[se,Jr]),ya=Oe||Ge||eo||Ur||io||Fr||so,Wa=!O&&(q||W&&ya&&!Vr),Mo=u.useMemo(()=>l("shared.data_source",{source:String(ua||"edge").toUpperCase()}),[ua,x]),ba=u.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Lo="",Zr=u.useMemo(()=>!ba||ba.includes("@")?l("dashboard.identity.fallback"):ba,[ba]),Qr=u.useMemo(()=>Zr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Zr]),Xr=u.useMemo(()=>i?l("dashboard.identity.fallback"):Qr,[Qr,Lo,i]),es=u.useMemo(()=>{let y=null;const E=Y=>{typeof Y!="string"||!Y||(!y||Y<y)&&(y=Y)};if(Array.isArray(bt))for(const Y of bt)Y?.day&&kr(Ta(Y))&&E(Y.day);const R=Array.isArray(Ve?.weeks)?Ve.weeks:[];for(const Y of R)for(const Le of Array.isArray(Y)?Y:[]){if(!Le?.day)continue;const we=Qs(Le),Pe=Le?.level;kr(we,Pe)&&E(Le.day)}return y},[Ve?.weeks,bt]),Eo=u.useMemo(()=>i?[]:(Array.isArray($?.subscriptions?.items)?$.subscriptions.items:[]).map(R=>{const Y=typeof R?.tool=="string"?R.tool.trim():"",we=(typeof R?.plan_type=="string"?R.plan_type:typeof R?.planType=="string"?R.planType:"").trim();return!Y||!we?null:{tool:Y,planType:we,provider:typeof R?.provider=="string"?R.provider.trim():"",product:typeof R?.product=="string"?R.product.trim():"",rateLimitTier:typeof R?.rate_limit_tier=="string"?R.rate_limit_tier.trim():typeof R?.rateLimitTier=="string"?R.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,$]),Ro=e.jsx(Zi,{heatmap:Ve,timeZoneLabel:la,timeZoneShortLabel:zt,hideLegend:H,defaultToLatestMonth:H}),Io=u.useMemo(()=>`${be}..${ke}`,[be,Q,ke]),Fo=l("usage.summary.total"),Me=J!=null,wt=Me?Ta(J):0,$o=b(wt),Po=u.useCallback(()=>{f(p===Jt.COMPACT?Jt.FULL:Jt.COMPACT)},[f,p]),zo=l("dashboard.core_index.collapse_label"),Oo=l("dashboard.core_index.expand_label"),Bo=l("dashboard.core_index.collapse_aria"),Uo=l("dashboard.core_index.expand_aria"),Ho=!H,vt=l("shared.placeholder.short"),Ga=u.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let E=null,R=0;for(const Pe of y){const Ee=Ct(Pe?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>R&&(R=Ee,E=Pe)}let Y=vt,Le=vt,we="0.0";if(E&&R>0){Y=E?.source?String(E.source).toUpperCase():vt;const Pe=Array.isArray(E?.models)?E.models:[];let Ee=0;for(const tr of Pe){const _a=Ct(tr?.totals);!Number.isFinite(_a)||_a<=0||_a>Ee&&(Ee=_a,Le=tr?.model?String(tr.model):vt)}Ee>0&&(we=(Ee/R*100).toFixed(1))}return{agentName:Y,modelName:Le,modelPercent:we}},[tt,vt]),Ya=Da(wt),Ko=l("dashboard.screenshot.twitter_text",{total_tokens:Ya==="-"?vt:Ya,agent_name:Ga.agentName,model_name:Ga.modelName,model_percent:Ga.modelPercent}),qo=u.useMemo(()=>H?[]:Zu,[H]),Vo=u.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(wt):"—",title:Me?k(wt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(J?.input_tokens):"—",title:Me?k(J?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(J?.output_tokens):"—",title:Me?k(J?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(J?.cached_input_tokens):"—",title:Me?k(J?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(J?.reasoning_output_tokens):"—",title:Me?k(J?.reasoning_output_tokens):void 0}],[J?.cached_input_tokens,J?.input_tokens,J?.output_tokens,J?.reasoning_output_tokens,wt,Me,b,k]),Ja=(tt?.sources||[]).some(y=>(y.models||[]).some(E=>E.pricing?.status==="unpriced"&&E.cost_source!=="provider_reported"&&Number(E.totals?.total_tokens)>0)),Za=u.useMemo(()=>{if(Ja&&Number(J?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=aa(J?.total_cost_usd,{currency:g,rate:m});return Ja&&y!=="-"?`≥${y}`:y},[J?.total_cost_usd,g,m,Ja]),Wo=u.useMemo(()=>J?.conversation_count??null,[J?.conversation_count]),ts=u.useMemo(()=>Pc(tt,{copyFn:l}),[tt]),as=u.useMemo(()=>Oc(tt,{limit:3,copyFn:l}),[tt]),Go=Gu({enabled:N,handle:Xr,startDate:es,activeDays:Ka,summary:J,topModels:as,period:Q,periodFrom:be,periodTo:ke,heatmap:Ve,accessToken:typeof te=="string"?te:null,userId:a?.userId||null,currency:g,exchangeRate:m}),Yo=u.useCallback(()=>P(!0),[]),Jo=u.useCallback(()=>P(!1),[]),Zo=u.useCallback(()=>w(!0),[]),Qo=u.useCallback(()=>w(!1),[]),Xo=Za&&Za!=="-"&&ts.length>0,qt=l("dashboard.install.cmd.init"),Qa=pe?null:C,Xa=Qa?l("dashboard.install.cmd.init_link_code",{link_code:Qa}):qt,ei=qt,ti=l("dashboard.install.cmd.sync"),ai=Qa?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ri=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const si=!!($?.install?.has_active_device_token??$?.install?.hasActiveDeviceToken),ni=_c({publicMode:i,screenshotMode:H,forceInstall:F,accessEnabled:ge,heatmapLoading:Ur,activeDays:Ka,hasActiveDeviceToken:si}),oi=l("dashboard.install.prompt"),ii=u.useCallback(async()=>{!Xa||!await cs(Xa)||(he(!0),window.setTimeout(()=>he(!1),2e3))},[Xa]);u.useCallback(async()=>{!qt||!await cs(qt)||(ye(!0),window.setTimeout(()=>ye(!1),2e3))},[qt]);const er=u.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[x]),[li,ci]=u.useMemo(()=>{const y=er.split("{{cmd}}");return y.length===1?[er,""]:[y[0],y.slice(1).join("{{cmd}}")]},[er]),Vt=s&&!i,Wt=!r&&!ne&&!s&&!se&&!i;u.useEffect(()=>{Vt||Wt||Wa||le(!0)},[Wa,Wt,Vt]);const ka=tc(Qu,Xu);return u.useEffect(()=>{ee.current||Vt||Wt||ya||(ee.current=!0,h?.())},[h,Wt,Vt,ya]),e.jsxs(e.Fragment,{children:[e.jsx(ou,{copy:l,accountView:W,accountScopeSwitchable:Se,onAccountScopeChange:Mt,onOpenShare:Yo,screenshotMode:H,showExpiredGate:Vt,showAuthGate:Wt,identityDisplayName:Xr,identityStartDate:es,activeDays:Ka,identitySubscriptions:Eo,identityScrambleDurationMs:de,projectUsageEntries:ro,projectUsageLimit:to,setProjectUsageLimit:ao,projectDetailQuery:{from:be,to:ke,timeZone:re,tzOffsetMinutes:ue},topModels:as,signedIn:r,publicMode:i,isLocalMode:se,shouldShowInstall:ni,installPrompt:oi,handleCopyInstall:ii,installCopied:ie,installCopiedLabel:ri,installCopyLabel:ai,installInitCmdDisplay:ei,linkCodeLoading:I,linkCodeError:_,trendRowsForDisplay:xo,trendFromForDisplay:po,trendToForDisplay:go,trendZoomConfig:lo,usageFrom:be,usageTo:ke,period:Q,trendTimeZoneLabel:ca,activityHeatmapBlock:Ro,periodsForDisplay:qo,setSelectedPeriod:No,customFrom:qe,customTo:et,onCustomRangeApply:So,customRangeOpen:$a,onCustomRangeOpenChange:Co,metricsRows:Vo,summaryLabel:Fo,summaryValue:$o,hasSummary:Me,summaryLoading:Ge,providersLoading:Fr,summaryFullValue:Ya,onToggleSummaryFormat:Po,summaryTotalTokensRaw:K(wt)||0,summaryCostValue:Za,summaryConversationsValue:Wo,rollingUsage:$e,costInfoEnabled:Xo,openCostModal:Zo,allowBreakdownToggle:Ho,coreIndexCollapsed:oe,setCoreIndexCollapsed:G,coreIndexCollapseLabel:zo,coreIndexExpandLabel:Oo,coreIndexCollapseAria:Bo,coreIndexExpandAria:Uo,refreshAll:Do,usageLoadingState:ya,announceUsageLoading:Oe,initialDashboardLoading:Wa,usageError:Ut,rangeLabel:Io,timeZoneRangeLabel:Ba,usageSourceLabel:Mo,fleetData:ts,hasDetailsActual:Vr,dailyEmptyPrefix:li,installSyncCmd:ti,dailyEmptySuffix:ci,detailsColumns:co,ariaSortFor:_o,toggleSort:ko,sortIconFor:wo,pagedDetails:mo,dailyBreakdownRows:ho,dailyBreakdownColumns:uo,dailyBreakdownAriaSortFor:vo,dailyBreakdownSortIconFor:jo,dailyBreakdownDateKey:xa,detailsDateKey:Ue,renderDetailDate:yo,renderDailyBreakdownDate:bo,renderDetailCell:fo,DETAILS_PAGED_PERIODS:Yt,detailsPageCount:Ua,detailsPage:Ha,setDetailsPage:ga,costModalOpen:v,closeCostModal:Qo,deviceOptions:za,selectedDevice:_e||"",onDeviceChange:y=>{W&&!i&&ar(a?.userId,"view"),gt(y||null)},deviceUsageBlock:Oa,localHistoryOnly:!W&&De.some(y=>y.imported_at),localHistoryRevision:W?0:Ft,leftCardOrder:ka.left.order,onLeftReorder:ka.left.reorder,rightCardOrder:ka.right.order,onRightReorder:ka.right.reorder}),e.jsx(Wu,{open:N,onClose:Jo,data:Go,twitterText:Ko})]})}export{Hm as DashboardPage};