tokentracker-cli 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dashboard/dist/assets/{AchievementBadge-WGbdoboF.js → AchievementBadge-3IYidbrI.js} +1 -1
  2. package/dashboard/dist/assets/{AchievementsPage-BvybbsXv.js → AchievementsPage-DmZ_ojyM.js} +2 -2
  3. package/dashboard/dist/assets/{AchievementsSection-ChNzTFSR.js → AchievementsSection-DIYrrzhw.js} +1 -1
  4. package/dashboard/dist/assets/{BadgeDetailModal-DhI9Ejz3.js → BadgeDetailModal-DMMExCe4.js} +1 -1
  5. package/dashboard/dist/assets/{BotAnimated-Bch0Yxej.js → BotAnimated-y6vZNRvC.js} +1 -1
  6. package/dashboard/dist/assets/{Card-DWdL7d1T.js → Card-LJX3G3zo.js} +1 -1
  7. package/dashboard/dist/assets/{CloudCheckoutPage-BjGoOz6P.js → CloudCheckoutPage-BGBgSXNE.js} +1 -1
  8. package/dashboard/dist/assets/{CloudPage-Btb6a97x.js → CloudPage-Dij2GTXi.js} +2 -2
  9. package/dashboard/dist/assets/{CommandPalette-DwP3k7LE.js → CommandPalette-BIky6Fk0.js} +1 -1
  10. package/dashboard/dist/assets/{CommunityStatsModal-mzqLxpwE.js → CommunityStatsModal-DbM99i0s.js} +1 -1
  11. package/dashboard/dist/assets/{ConfirmModal-Dm76q4EX.js → ConfirmModal-C_NH8vgO.js} +1 -1
  12. package/dashboard/dist/assets/{Controls-ClZjOBoD.js → Controls-BEAj_kvr.js} +1 -1
  13. package/dashboard/dist/assets/{DashboardPage-Doc8f4NL.js → DashboardPage-DO7h2dfu.js} +1 -1
  14. package/dashboard/dist/assets/{DateRangePopover-vfTUePPg.js → DateRangePopover-PQXB8v0k.js} +1 -1
  15. package/dashboard/dist/assets/{DevicePage-Jjg5q0C2.js → DevicePage-0JZ3OIWZ.js} +1 -1
  16. package/dashboard/dist/assets/{DialogClose-Ci5mPZ6X.js → DialogClose-BpWoD5h9.js} +1 -1
  17. package/dashboard/dist/assets/DialogDescription-ne_rYSD7.js +1 -0
  18. package/dashboard/dist/assets/{DialogTitle-DI21oZxH.js → DialogTitle-DoQgdh5w.js} +1 -1
  19. package/dashboard/dist/assets/{ElectricLogo-DfeZBwPZ.js → ElectricLogo-0O87VjKv.js} +1 -1
  20. package/dashboard/dist/assets/{FadeIn-C7SIILTc.js → FadeIn-9ph1h_AG.js} +1 -1
  21. package/dashboard/dist/assets/{HeaderGithubStar-RStLbadn.js → HeaderGithubStar-DCZ92xbH.js} +1 -1
  22. package/dashboard/dist/assets/{HoverTooltip-DI7uAp1_.js → HoverTooltip-CCKdmuOP.js} +1 -1
  23. package/dashboard/dist/assets/{IpCheckPage-DTZNTJVh.js → IpCheckPage-CpyhpmdS.js} +1 -1
  24. package/dashboard/dist/assets/{LandingPage-Df5scNlw.js → LandingPage-spvsPkYy.js} +2 -2
  25. package/dashboard/dist/assets/{LeaderboardPage-Ck3SqtnI.js → LeaderboardPage-2nJ08ohw.js} +2 -2
  26. package/dashboard/dist/assets/{LeaderboardProBadge-CGx6m7R6.js → LeaderboardProBadge-D6FSL3Qy.js} +1 -1
  27. package/dashboard/dist/assets/{LeaderboardProfileModal-DuP7rgfv.js → LeaderboardProfileModal-DD1jX-rD.js} +3 -3
  28. package/dashboard/dist/assets/{LeaderboardProfilePage-B5qUJkZX.js → LeaderboardProfilePage-DYqRrntL.js} +1 -1
  29. package/dashboard/dist/assets/{LimitsPage-Bv_Lcvcz.js → LimitsPage-DXHikunk.js} +1 -1
  30. package/dashboard/dist/assets/{LocalOnlyNotice-Cg4y02JM.js → LocalOnlyNotice-BURiQAtP.js} +1 -1
  31. package/dashboard/dist/assets/{LoginCard-Wz0uJKXx.js → LoginCard-Cv2ijoJx.js} +1 -1
  32. package/dashboard/dist/assets/{LoginModal-C13v_Gs0.js → LoginModal-DyOideDA.js} +1 -1
  33. package/dashboard/dist/assets/{LoginPage-COH9xXtd.js → LoginPage-BKNvqvYi.js} +1 -1
  34. package/dashboard/dist/assets/{PetPage-BWCnURub.js → PetPage-BBmozE0L.js} +2 -2
  35. package/dashboard/dist/assets/{PopoverPopup-Dw811N-_.js → PopoverPopup-DDnISLKM.js} +1 -1
  36. package/dashboard/dist/assets/{ProviderIcon-CHxhYzK-.js → ProviderIcon-Da90GDcM.js} +1 -1
  37. package/dashboard/dist/assets/{ResetPasswordPage-Ll6jshqg.js → ResetPasswordPage-DsETr50j.js} +1 -1
  38. package/dashboard/dist/assets/{Select-BbooQ3sa.js → Select-pZDawyxt.js} +1 -1
  39. package/dashboard/dist/assets/{SelectItemText-DBiW70wi.js → SelectItemText-D5wuuN7G.js} +1 -1
  40. package/dashboard/dist/assets/{SelfHostPage-BMHJxz5q.js → SelfHostPage-sm-PARYj.js} +1 -1
  41. package/dashboard/dist/assets/{ServiceStatusPage-D6LH0ac-.js → ServiceStatusPage-D4f8h0sL.js} +1 -1
  42. package/dashboard/dist/assets/{SessionsPage-Mrer6v17.js → SessionsPage-xVLsTN4m.js} +1 -1
  43. package/dashboard/dist/assets/{SettingsPage-D_7P_y_l.js → SettingsPage-Dt9iFheY.js} +3 -3
  44. package/dashboard/dist/assets/{SkillsPage-Ka7xm-1v.js → SkillsPage-BdWalPpd.js} +1 -1
  45. package/dashboard/dist/assets/{TokenGalaxy-BEURDPFq.js → TokenGalaxy-d2_ml0tE.js} +1 -1
  46. package/dashboard/dist/assets/{TooltipPopup-ZiuFFARC.js → TooltipPopup-B4masxDW.js} +1 -1
  47. package/dashboard/dist/assets/{TrendMonitor-H73lyGEf.js → TrendMonitor-CceYpa2O.js} +1 -1
  48. package/dashboard/dist/assets/{WidgetsPage-_7iCvyTk.js → WidgetsPage-CSN0829H.js} +1 -1
  49. package/dashboard/dist/assets/{WrappedPage-DEXNb6-k.js → WrappedPage-gP4WfO_m.js} +1 -1
  50. package/dashboard/dist/assets/{__vite-browser-external-BkNP5Ecj.js → __vite-browser-external-BtJVmciH.js} +2 -2
  51. package/dashboard/dist/assets/{agent-logos-OVBc_0cF.js → agent-logos-wxccxfWz.js} +1 -1
  52. package/dashboard/dist/assets/{arrow-left-DDphsclm.js → arrow-left-Bd5C77R2.js} +1 -1
  53. package/dashboard/dist/assets/{arrow-right-B1aNq0Ki.js → arrow-right-C1RqrK4A.js} +1 -1
  54. package/dashboard/dist/assets/{arrow-up-right-yTM9azz_.js → arrow-up-right-B_b2i8hn.js} +1 -1
  55. package/dashboard/dist/assets/{calendar-days-D22ithNF.js → calendar-days-C8eYygme.js} +1 -1
  56. package/dashboard/dist/assets/{check-Dk7tknvE.js → check-BlBHefQ7.js} +1 -1
  57. package/dashboard/dist/assets/{chevron-down-DdyEzQ4f.js → chevron-down-mjUspqZv.js} +1 -1
  58. package/dashboard/dist/assets/{cloud-checkout-BJjbipnH.js → cloud-checkout-CEkMnWXf.js} +1 -1
  59. package/dashboard/dist/assets/{composite-DEqP00XV.js → composite-CzXFY9IC.js} +1 -1
  60. package/dashboard/dist/assets/{download-C9ixNyzn.js → download-CQvg59w1.js} +1 -1
  61. package/dashboard/dist/assets/{external-link-DL4HSsLw.js → external-link-CDYfIZ3Z.js} +1 -1
  62. package/dashboard/dist/assets/{flame-DqNH65nB.js → flame-C9NXQRil.js} +1 -1
  63. package/dashboard/dist/assets/{format-tokens-CyVjKz4I.js → format-tokens-fKy_3qpW.js} +1 -1
  64. package/dashboard/dist/assets/{gift-ChJQQe_G.js → gift-WmV4SBGR.js} +1 -1
  65. package/dashboard/dist/assets/{host-mode-DpUDpoOz.js → host-mode-C5MvZ7SV.js} +1 -1
  66. package/dashboard/dist/assets/{icons-CJiHeOaU.js → icons-B1EtsaZs.js} +1 -1
  67. package/dashboard/dist/assets/{index-72LQsAaf.js → index-9EZ3o2RV.js} +1 -1
  68. package/dashboard/dist/assets/{index-CrFlTSra.js → index-BEecBW06.js} +1 -1
  69. package/dashboard/dist/assets/{index-BucEg3fu.js → index-DXNwBFNi.js} +1 -1
  70. package/dashboard/dist/assets/{info-DReYqxC7.js → info-CWDhggIW.js} +1 -1
  71. package/dashboard/dist/assets/{link-2-kIZbhK2S.js → link-2-DEWNkK7s.js} +1 -1
  72. package/dashboard/dist/assets/{loader-circle-1An-X85y.js → loader-circle-DotT5gVp.js} +1 -1
  73. package/dashboard/dist/assets/{modifiers.esm-FoVheEKT.js → modifiers.esm-qZnGgJAz.js} +1 -1
  74. package/dashboard/dist/assets/{monitor-smartphone-Ch6lr_P2.js → monitor-smartphone-DOP5eqBD.js} +1 -1
  75. package/dashboard/dist/assets/{play-CbJ6ZF1K.js → play-BUsybi9m.js} +1 -1
  76. package/dashboard/dist/assets/{plus-C-5ID3a9.js → plus-DAjojh_m.js} +1 -1
  77. package/dashboard/dist/assets/{provider-display-BFzRtoL2.js → provider-display-BCQQYPWD.js} +1 -1
  78. package/dashboard/dist/assets/{react-D4CR_fLQ.js → react-BgpqhoCj.js} +1 -1
  79. package/dashboard/dist/assets/{safePolygon-DP21Ibqj.js → safePolygon-C-PFpZSA.js} +1 -1
  80. package/dashboard/dist/assets/{search-CaznkY7U.js → search-W1A-6ugo.js} +1 -1
  81. package/dashboard/dist/assets/{server-CUOmC6xZ.js → server-CE7pFjDr.js} +1 -1
  82. package/dashboard/dist/assets/{shield-check-Dr2KBMmA.js → shield-check-KL5xc2FR.js} +1 -1
  83. package/dashboard/dist/assets/{skills-api-BAz_fblS.js → skills-api-DL_zLjKA.js} +1 -1
  84. package/dashboard/dist/assets/{sortable.esm-knEfm5hE.js → sortable.esm-CehJQvFH.js} +1 -1
  85. package/dashboard/dist/assets/{store-CL97jcij.js → store-BHAXkHPR.js} +1 -1
  86. package/dashboard/dist/assets/{terminal-EjFyreWj.js → terminal-Br5vyD6Q.js} +1 -1
  87. package/dashboard/dist/assets/{trash-ByqaZXkQ.js → trash-CzaCJP6G.js} +1 -1
  88. package/dashboard/dist/assets/{use-community-stats-Bs4RDJZE.js → use-community-stats-DbJrecQw.js} +1 -1
  89. package/dashboard/dist/assets/{use-latest-request-guard-CG3Ir1cP.js → use-latest-request-guard-DGhwmlX8.js} +1 -1
  90. package/dashboard/dist/assets/{use-limits-display-prefs-tACgCxeR.js → use-limits-display-prefs-T7KWAWZ6.js} +1 -1
  91. package/dashboard/dist/assets/{use-native-settings-CWjXyJXi.js → use-native-settings-MZJhS328.js} +1 -1
  92. package/dashboard/dist/assets/{use-ordered-list-DsuC9JQa.js → use-ordered-list-BDN24weA.js} +1 -1
  93. package/dashboard/dist/assets/use-reduced-motion-CfCY-K-a.js +1 -0
  94. package/dashboard/dist/assets/{use-session-efficiency-pref-NeoJE8BL.js → use-session-efficiency-pref-DUu16y8Z.js} +1 -1
  95. package/dashboard/dist/assets/{use-transform-BWGKOsya.js → use-transform-BczE46xm.js} +1 -1
  96. package/dashboard/dist/assets/{use-usage-limits-CFWFNwHS.js → use-usage-limits-CjyDfH-M.js} +1 -1
  97. package/dashboard/dist/assets/{useCurrency-B_C4_P5x.js → useCurrency-BgZmWbkx.js} +1 -1
  98. package/dashboard/dist/assets/{usePositioner-B0L5_o38.js → usePositioner-dWENyY8z.js} +1 -1
  99. package/dashboard/dist/assets/{useTokenFormat-DH1GWHSU.js → useTokenFormat-D7s1-Zuk.js} +1 -1
  100. package/dashboard/dist/assets/{zap-Chv1p7pS.js → zap-Dr__bKlq.js} +1 -1
  101. package/dashboard/dist/index.html +1 -1
  102. package/dashboard/dist/ip-check.html +1 -1
  103. package/dashboard/dist/leaderboard.html +1 -1
  104. package/dashboard/dist/share.html +1 -1
  105. package/package.json +1 -1
  106. package/src/lib/pricing/seed-snapshot.json +1 -1
  107. package/dashboard/dist/assets/DialogDescription-Di5ev5K6.js +0 -1
  108. package/dashboard/dist/assets/use-reduced-motion-CwFguzkm.js +0 -1
@@ -1 +1 @@
1
- import{o as br,r as c,j as e,L as Go,dy as Yo,W as ht,aA as Gt,aB as Be,dz as Zo,dA as Jo,ay as Wr,dB as ha,aG as Bs,aH as Os,aI as kr,dC as Qo,dD as Xo,dE as ei,aK as _r,aJ as Vt,dF as ti,dG as ai,dH as ee,c as l,V as vt,X as wr,i as Ie,az as Yt,bh as Wt,z as Us,dI as ri,an as si,l as Kt,cb as _a,y as Nt,dJ as ni,U as Hs,Q as Ks,aM as oi,ao as ii,B as li,R as ci,h as di,dK as ui,dL as mi,dM as hi,dN as xi,am as qr,_ as gi,a as fi,dO as Gr,g as pi,Z as yi,co as bi,dP as ki,dQ as _i,dR as wi,dS as vi,dT as ji,cc as Yr,cP as Zr,dU as Ni,dV as Si,aT as Ci,d1 as Ga,dW as Jr,aR as Qr,dX as Ti,dY as Ai,dZ as Di}from"./__vite-browser-external-BkNP5Ecj.js";import{u as st}from"./use-latest-request-guard-CG3Ir1cP.js";import{u as Xr}from"./use-ordered-list-DsuC9JQa.js";import{t as es,T as Vs,g as Mi,u as Li}from"./TrendMonitor-H73lyGEf.js";import{u as Ei}from"./use-usage-limits-CFWFNwHS.js";import{u as ja}from"./useCurrency-B_C4_P5x.js";import{u as Se}from"./useTokenFormat-DH1GWHSU.js";import{f as jt,A as Ri}from"./provider-display-BFzRtoL2.js";import{g as Ii,q as Ws,J as Fi,M as $i,m as Ke}from"./react-D4CR_fLQ.js";import{u as Pi,C as zi,a as Bi,b as ts,D as Oi,S as Ui,v as Hi,s as Ki,K as Vi,P as Wi}from"./sortable.esm-knEfm5hE.js";import{D as qi,a as Gi,b as Yi,c as Zi,d as Ji,e as Qi}from"./DialogTitle-DI21oZxH.js";import{D as Xi}from"./DialogClose-Ci5mPZ6X.js";import{C as Te}from"./Card-DWdL7d1T.js";import{S as qs}from"./Select-BbooQ3sa.js";import{P as Ct}from"./ProviderIcon-CHxhYzK-.js";import{u as Gs}from"./use-reduced-motion-CwFguzkm.js";import{a as Ys,u as Zs}from"./use-transform-BWGKOsya.js";import{f as xa,D as el,g as tl}from"./DateRangePopover-vfTUePPg.js";import{I as Js}from"./info-DReYqxC7.js";import{A as Qs}from"./index-CrFlTSra.js";import{L as al}from"./loader-circle-1An-X85y.js";import{C as rl}from"./chevron-down-DdyEzQ4f.js";import{P as sl,a as nl,b as ol,c as il,d as ll}from"./PopoverPopup-Dw811N-_.js";import{F as ot}from"./FadeIn-C7SIILTc.js";import{u as cl,a as dl,P as ul}from"./use-session-efficiency-pref-NeoJE8BL.js";import{L as as}from"./LoginCard-Wz0uJKXx.js";import{L as ml,A as hl}from"./agent-logos-OVBc_0cF.js";import{M as Xs}from"./monitor-smartphone-Ch6lr_P2.js";import{C as xl}from"./check-Dk7tknvE.js";import"./terminal-EjFyreWj.js";import"./use-limits-display-prefs-tACgCxeR.js";import"./play-CbJ6ZF1K.js";import"./composite-DEqP00XV.js";import"./store-CL97jcij.js";import"./SelectItemText-DBiW70wi.js";import"./usePositioner-B0L5_o38.js";import"./safePolygon-DP21Ibqj.js";import"./arrow-left-DDphsclm.js";const en={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"}]]};en.node;const gl=br(en);const tn={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"}]]};tn.node;const fl=br(tn);const an={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"]};an.node;const pl=br(an);function yl(t,a,r={}){const s=t.get();let n=null,o=s,i;const d=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,u=()=>{n&&(n.stop(),n=null),t.animation=void 0},m=()=>{const f=rs(t.get()),h=rs(o);if(f===h){u();return}const g=n?n.getGeneratorVelocity():t.getVelocity();u(),n=new Fi({keyframes:[f,h],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:i})},x=()=>{m(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((f,h)=>{o=f,i=g=>h(Ya(g,d)),Ii.postRender(x)},u),Ws(a)){let f=r.skipInitialAnimation===!0;const h=a.on("change",p=>{f?(f=!1,t.jump(Ya(p,d),!1)):t.set(Ya(p,d))}),g=t.on("destroy",h);return()=>{h(),g()}}return u}function Ya(t,a){return a?t+a:t}function rs(t){return typeof t=="number"?t:parseFloat(t)}function bl(t,a={}){const{isStatic:r}=c.useContext($i),s=()=>Ws(t)?t.get():t;if(r)return Ys(s);const n=Zs(s());return c.useInsertionEffect(()=>yl(n,t,a),[n,JSON.stringify(a)]),n}function kl(t,a={}){return bl(t,{type:"spring",...a})}function _l(){return e.jsxs(Go,{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 wl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:o=!1,bare:i=!1}){return i?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!o&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(_l,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!o&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function vl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",o={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},i={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},d=`${n} ${o[a]} ${i[r]} ${s}`.trim();return e.jsx("span",{className:d,children:t})}var jl={};function Nl(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 Sl({mv:t,digit:a,height:r}){const s=Ys(t,n=>{const o=(n%10+10)%10,i=(10+a-o)%10;let d=i*r;return i>5&&(d-=10*r),d});return e.jsx(Ke.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Cl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Tl(t,a){const r=t/a;return Math.floor(Cl(r))}function Al(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((d,u)=>/\d/.test(d)&&(s===-1||u<s)).length,o=0,i=!1;return r.map(d=>{if(!/\d/.test(d))return d==="."&&(i=!0),d;if(!i){const u=10**Math.max(n-1,0);return n-=1,u}return o+=1,10**-o})}function Dl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const u=Nl(t,r),m=t!=="."&&t!==",",x=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...u,...s,...m?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...x?{width:u.width}:null},children:t})}const o=Tl(a,t),i=Zs(0),d=kl(i,{stiffness:220,damping:26,mass:.8});return c.useEffect(()=>{i.set(o)},[i,o]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(o)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(u,m)=>e.jsx(Sl,{mv:d,digit:m,height:r},m))})}function Ml({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:o=6,borderRadius:i=4,horizontalPadding:d=0,textColor:u="inherit",fontWeight:m="inherit",containerStyle:x,counterStyle:f,digitStyle:h,gradientHeight:g=14,gradientFrom:p="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const _=String(a??t??""),S=c.useMemo(()=>Array.isArray(n)&&n.length?n:Al(_),[n,_]),C=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&jl?.VITEST==="true",D=Gs()||C,M=Number.isFinite(Number(t))?Math.abs(Number(t)):0,z=r+s;return D?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:u,fontSize:r,fontWeight:m,lineHeight:1,...x,...f},children:_}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...x},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:o,overflow:"hidden",borderRadius:i,paddingLeft:d,paddingRight:d,lineHeight:1,color:u,fontWeight:m,...f},children:S.map((N,v)=>e.jsx(Dl,{place:N,value:M,height:z,digitStyle:h,shouldReduceMotion:D},`${String(N)}-${v}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:g,background:`linear-gradient(to bottom, ${p}, ${b})`}}),e.jsx("span",{style:j??{height:g,background:`linear-gradient(to top, ${p}, ${b})`}})]})]})}function Ll({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:o,timeZone:i,tzOffsetMinutes:d,now:u,accountView:m=!1,accountAccessToken:x=null,accountRevision:f=0,accountViewResolving:h=!1,deviceId:g=null}={}){const p=!!(m&&x),b=p?"cloud":"local",k=c.useMemo(()=>Yo({weeks:s,weekStartsOn:n,now:u}),[u,s,n]),[j,_]=c.useState([]),[S,C]=c.useState(null),[D,M]=c.useState("edge"),[z,N]=c.useState(!1),[v,T]=c.useState(null),F=ht(),O=Gt(a),$=!r,R=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=st([t,k.from,k.to,s,n,b,a,x,f,h,g,i,d,r,F,$,O,R]),K=c.useMemo(()=>{if(!o)return null;const W=kr({timeZone:i,offsetMinutes:d});return`tokentracker.heatmap.${o}.${b}.${s}.${n}.${W}.${g||"all"}`},[o,g,b,i,d,s,n]),G=c.useCallback(()=>{if(!K||typeof window>"u")return null;try{const W=window.localStorage.getItem(K);if(!W)return null;const ne=JSON.parse(W);return!ne||!ne.heatmap?null:ne}catch{return null}},[K]),w=c.useCallback(W=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(W))}catch{}},[K]),P=c.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=c.useRef(b);c.useEffect(()=>{H.current!==b&&(H.current=b,_([]),C(null),M("edge"),T(null),N(!0))},[b]);const te=c.useCallback(async()=>{const W=B(),ne=await Be(a),le=p?await Be(x):null;if(!W()||!ne&&!F&&!R&&!p)return;if(p&&!le){T("Your session expired. Please sign in again to view account data."),N(!1);return}const je=p?le:ne,ye=p?Zo:Jo,Ae=p?Bs:Os;N(!0),T(null);try{try{const X=await ye({baseUrl:t,accessToken:je,weeks:s,to:k.to,weekStartsOn:n,device:g,timeZone:i,tzOffsetMinutes:d}),ae=Array.isArray(X?.weeks)?X.weeks:[];if(!W())return;if(!ae.length&&$){const V=G();if(V?.heatmap){if(!W())return;C(V.heatmap),_(V.daily||[]),M("cache");return}}if(!ae.some(V=>(Array.isArray(V)?V:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&ae.length){const V=[];for(const Q of ae)for(const xe of Array.isArray(Q)?Q:[])xe?.day&&V.push({day:xe.day,total_tokens:xe.total_tokens??xe.value??0,billable_total_tokens:xe.billable_total_tokens??xe.value??xe.total_tokens??0});const Y=Wr({dailyRows:V,weeks:s,to:X?.to||k.to,weekStartsOn:n});if(!W())return;_(V),C({...Y,week_starts_on:n,active_days:V.filter(Q=>Number(Q?.billable_total_tokens??Q?.total_tokens)>0).length,streak_days:ha({dailyRows:V,to:X?.to||k.to})}),M("client"),$?w({heatmap:{...Y,week_starts_on:n,active_days:V.filter(Q=>Number(Q?.billable_total_tokens??Q?.total_tokens)>0).length,streak_days:ha({dailyRows:V,to:X?.to||k.to})},daily:V,fetchedAt:new Date().toISOString()}):P();return}if(!W())return;C(X||null),_([]),M("edge"),X&&$?w({heatmap:X,daily:[],fetchedAt:new Date().toISOString()}):$||P();return}catch(X){const ae=X,pe=ae?.status??ae?.statusCode;if(pe===401||pe===403)throw X}if(!W())return;const J=await Ae({baseUrl:t,accessToken:je,from:k.from,to:k.to,device:g,timeZone:i,tzOffsetMinutes:d}),U=Array.isArray(J?.data)?J.data:[];if(!W())return;_(U);const oe=Wr({dailyRows:U,weeks:s,to:k.to,weekStartsOn:n});if(!W())return;C({...oe,week_starts_on:n,active_days:U.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:k.to})}),M("client"),$?w({heatmap:{...oe,week_starts_on:n,active_days:U.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:k.to})},daily:U,fetchedAt:new Date().toISOString()}):P()}catch(J){if(!W())return;if($){const U=G();if(U?.heatmap){if(!W())return;C(U.heatmap),_(U.daily||[]),M("cache"),T(null)}else{const oe=J;T(oe?.message||String(oe)),_([]),C(null),M("edge")}}else{const U=J;T(U?.message||String(U)),_([]),C(null),M("edge")}}finally{W()&&N(!1)}},[a,t,F,r,$,k.from,k.to,G,O,i,d,n,s,P,w,R,p,x,f,g,B]);return c.useEffect(()=>{if(h){N(!0);return}if(!O&&!r&&!F&&!R&&!p){_([]),N(!1),T(null),C(null),M("edge");return}if(!$)P(),_([]),T(null),C(null),M("edge");else{const W=G();W?.heatmap&&(C(W.heatmap),_(W.daily||[]),M("cache"))}te()},[a,F,G,te,O,r,$,P,R,h]),{range:k,daily:j,heatmap:S,source:F?"mock":D==="client"?"edge":D,loading:z,error:v,refresh:te}}const El="tokentracker.dashboard.leftCardOrder.v1",Rl="tokentracker.dashboard.rightCardOrder.v1";function Il(t,a){const r=Xr(El,t),s=Xr(Rl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),o=c.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:o}}const Fl=10;function $l({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i}={}){const[d,u]=c.useState([]),[m,x]=c.useState(!1),[f,h]=c.useState(null),g=ht(),p=Gt(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,o,i]),j=c.useCallback(async()=>{const _=k(),S=await Be(a);if(_()){if(!S&&!g&&!b){u([]),h(null),x(!1);return}x(!0),h(null);try{const C=await Qo({baseUrl:t,accessToken:S,limit:Fl,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i});if(!_())return;u(Array.isArray(C?.entries)?C.entries:[])}catch(C){if(!_())return;const D=C?.message||String(C);h(D),u([])}finally{_()&&x(!1)}}},[a,t,r,g,n,o,s,i,b,k]);return c.useEffect(()=>{if(!p&&!g&&!b){u([]),h(null),x(!1);return}u([]),h(null),x(!0),j()},[g,j,p,b]),{entries:d,loading:m,error:f,refresh:j}}const ss="tokentracker.usage-cache-index",ns=24;function os({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:o=!0,includeSummary:i=!0,cacheKey:d,timeZone:u,tzOffsetMinutes:m,now:x,accountView:f=!1,accountAccessToken:h=null,accountRevision:g=0,accountViewResolving:p=!1,deviceId:b=null}={}){const k=!!(f&&h),j=k?"cloud":"local",[_,S]=c.useState([]),[C,D]=c.useState(null),[M,z]=c.useState(null),[N,v]=c.useState("edge"),[T,F]=c.useState(null),[O,$]=c.useState(!1),[R,B]=c.useState(null),K=ht(),G=Gt(a),w=!r&&!K,P=b||"all",H=(()=>{if(!d)return null;const J=Pl(t)||"default",U=o?i?"daily-summary":"daily-only":"summary",oe=kr({timeZone:u,offsetMinutes:m});return`tokentracker.usage.${d}.${j}.${J}.${s}.${n}.${U}.${oe}.${P}`})(),te=c.useRef(j);c.useEffect(()=>{te.current!==j&&(te.current=j,S([]),D(null),z(null),v("edge"),F(null),B(null),$(!0))},[j]);const ue=c.useCallback(()=>{if(!H||typeof window>"u")return null;try{const J=window.localStorage.getItem(H);if(!J)return null;const U=JSON.parse(J),oe=i?!!U?.summary:Array.isArray(U?.daily);return!U||!oe?null:(es(ss,H,ns),U)}catch{return null}},[i,H]),W=c.useCallback(J=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(J)),es(ss,H,ns)}catch{}},[H]),ne=c.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),je=st([t,s,n,o,i,j,a,h,g,b,u,m,r,K,w,p,G,le]),ye=c.useCallback(async()=>{const J=je(),U=await Be(a),oe=k?await Be(h):null;if(!J()||!U&&!K&&!le&&!k)return;if(k&&!oe){B("Your session expired. Please sign in again to view account data."),$(!1);return}const X=k?Bs:Os,ae=k?Xo:ei,pe=k?oe:U;$(!0),B(null);try{let V=null,Y=null;if(o)if(i){const[De,ce]=await Promise.allSettled([X({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m}),ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0})]);if(De.status==="rejected")throw De.reason;V=De.value,Y=ce.status==="fulfilled"?ce.value:null}else V=await X({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m});else i&&(Y=await ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0}));let Q=o&&Array.isArray(V?.data)?V.data:[];o&&(Q=Ja(Q,s,n,{timeZone:u,offsetMinutes:m,now:x}));let xe=i&&(Y?.totals||V?.summary?.totals)||null,Ne=i&&(Y?.rolling||V?.summary?.rolling)||null;if(i&&o&&!xe&&!Y)try{const De=await ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0});xe=De?.totals||null,Ne=De?.rolling||Ne}catch{}const Ce=new Date().toISOString();if(!J())return;S(Q),D(xe),z(Ne),v("edge"),F(Ce),(xe||!i&&o)&&w?W({summary:xe,rolling:Ne,daily:Q,from:s,to:n,includeDaily:o,includeSummary:i,fetchedAt:Ce}):w||ne()}catch(V){if(!J())return;if(w){const Y=ue();if(Y?.summary||!i&&Array.isArray(Y?.daily)){D(Y.summary),z(Y.rolling||null);const Q=Array.isArray(Y.daily)?Y.daily:[],xe=o?Ja(Q,Y.from||s,Y.to||n,{timeZone:u,offsetMinutes:m,now:x}):Q;S(xe),v("cache"),F(Y.fetchedAt||null),B(null)}else{const Q=V;B(Q?.message||String(Q)),S([]),D(null),z(null),v("edge"),F(null)}}else{const Y=V;B(Y?.message||String(Y)),S([]),D(null),z(null),v("edge"),F(null)}}finally{J()&&$(!1)}},[a,t,s,o,i,K,r,w,x,ue,G,u,n,m,ne,W,le,k,h,g,b,je]);return c.useEffect(()=>{if(p){$(!0);return}const J=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!G&&!r&&!K&&!J&&!k){S([]),D(null),z(null),B(null),$(!1),v("edge"),F(null);return}if(!w)ne(),S([]),D(null),z(null),B(null),v("edge"),F(null);else{const U=ue();if(U?.summary||!i&&Array.isArray(U?.daily)){D(U.summary),z(U.rolling||null);const oe=Array.isArray(U.daily)?U.daily:[],X=o?Ja(oe,U.from||s,U.to||n,{timeZone:u,offsetMinutes:m,now:x}):oe;S(X),v("cache"),F(U.fetchedAt||null),B(null)}else S([]),D(null),z(null),v("edge"),F(null),B(null)}$(!0),ye()},[a,K,ue,ye,G,r,w,ne,le,p,i]),c.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const J=15e3;let U=Date.now();const oe=()=>{if(document.visibilityState!=="visible")return;const X=Date.now();X-U<J||(U=X,ye())};return window.addEventListener("focus",oe),document.addEventListener("visibilitychange",oe),()=>{window.removeEventListener("focus",oe),document.removeEventListener("visibilitychange",oe)}},[ye]),{daily:_,summary:C,rolling:M,source:K?"mock":N,fetchedAt:T,loading:O,error:R,refresh:ye}}function Pl(t){try{return new URL(t).host}catch{return null}}function Za(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,o=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n,o));return Number.isFinite(i.getTime())&&Vt(i)===a?i:null}function zl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Ja(t,a,r,{timeZone:s,offsetMinutes:n,now:o}={}){const i=Za(a),d=Za(r);if(!i||!d||d<i)return Array.isArray(t)?t:[];const u=o instanceof Date&&Number.isFinite(o.getTime())?o:new Date,m=_r({timeZone:s,offsetMinutes:n,date:u}),x=Za(m),f=x?x.getTime():u.getTime(),h=new Map;for(const p of t||[])p?.day&&h.set(p.day,p);const g=[];for(let p=i;p<=d;p=zl(p,1)){const b=Vt(p),k=h.get(b),j=p.getTime()>f;if(k){g.push({...k,missing:!1,future:j});continue}g.push({day:b,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!j,future:j})}return g}function Bl({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:o,timeZone:i,tzOffsetMinutes:d,accountView:u=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:f=!1,deviceId:h=null}={}){const g=!!(u&&m),p=g?"cloud":"local",[b,k]=c.useState(null),[j,_]=c.useState("edge"),[S,C]=c.useState(!1),[D,M]=c.useState(null),z=ht(),N=Gt(a),v=!r,T=c.useMemo(()=>{if(!o)return null;const P=Ol(t)||"default",H=kr({timeZone:i,offsetMinutes:d});return`tokentracker.modelBreakdown.${o}.${p}.${P}.${s}.${n}.${H}.${h||"all"}`},[t,o,h,s,p,i,n,d]),F=c.useCallback(()=>{if(!T||typeof window>"u")return null;try{const P=window.localStorage.getItem(T);if(!P)return null;const H=JSON.parse(P);return!H||!H.breakdown?null:H}catch{return null}},[T]),O=c.useCallback(P=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(P))}catch{}},[T]),$=c.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),R=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=st([t,s,n,p,a,m,x,h,i,d,r,z,v,f,N,R]),K=c.useRef(p);c.useEffect(()=>{K.current!==p&&(K.current=p,k(null),_("edge"),M(null),C(!0))},[p]);const G=c.useCallback(async()=>{const P=B(),H=await Be(a),te=g?await Be(m):null;if(!P()||!H&&!z&&!R&&!g)return;if(g&&!te){M("Your session expired. Please sign in again to view account data."),C(!1);return}const ue=g?te:H,W=g?ti:ai;C(!0),M(null);try{const ne=await W({baseUrl:t,accessToken:ue,from:s,to:n,device:h,timeZone:i,tzOffsetMinutes:d});if(!P())return;k(ne||null),_("edge"),ne&&v?O({breakdown:ne,fetchedAt:new Date().toISOString()}):v||$()}catch(ne){if(!P())return;if(v){const le=F();if(le?.breakdown)k(le.breakdown),_("cache"),M(null);else{k(null),_("edge");const je=ne;M(je?.message||String(je))}}else{k(null),_("edge");const le=ne;M(le?.message||String(le))}}finally{P()&&C(!1)}},[a,t,s,z,r,v,F,i,n,N,d,$,O,R,g,m,x,h,B]);return c.useEffect(()=>{if(f){C(!0);return}if(!N&&!r&&!z&&!R&&!g){k(null),_("edge"),M(null),C(!1);return}if(!v)$(),k(null),_("edge"),M(null);else{const P=F();P?.breakdown?(k(P.breakdown),_("cache"),M(null)):(k(null),_("edge"),M(null))}C(!0),G()},[a,z,F,G,N,r,v,$,R,f]),{breakdown:b,source:z?"mock":j,loading:S,error:D,refresh:G}}function Ol(t){try{return new URL(t).host}catch{return null}}const rn=new Set(["day","hour","month"]);function Ul(t){return rn.has(t)}function is(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 Hl(t,a){const r=is(t),s=is(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=ee(t),o=ee(a);return n==null&&o==null?0:n==null?1:o==null?-1:n===o?0:n<o?-1:1}function Kl(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 Vl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),o=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n-1,o));return!Number.isFinite(i.getTime())||i.getUTCFullYear()!==s||i.getUTCMonth()+1!==n||i.getUTCDate()!==o?null:i.getTime()}function Wl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const o=new Date(Date.UTC(s,n-1,1));return Number.isFinite(o.getTime())?o.getTime():null}function ql(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),o=Number(r[3]),i=Number(r[4]),d=Number(r[5]),u=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(d)||!Number.isFinite(u)||n<1||n>12||o<1||o>31||i<0||i>23||d<0||d>59||u<0||u>59)return null;const m=new Date(Date.UTC(s,n-1,o,i,d,u));return Number.isFinite(m.getTime())?m.getTime():null}function Gl(t,a,r){const s=r==="hour"?ql:r==="month"?Wl:Vl,n=s(t),o=s(a);return n!=null&&o!=null?n===o?0:n<o?-1:1:Kl(t,a)}function sn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],o=rn.has(a)?(d,u)=>Gl(d,u,a):Hl,i=d=>a==="total_tokens"&&d?.billable_total_tokens!=null?d.billable_total_tokens:d?.[a];return n.map((d,u)=>({row:d,index:u})).sort((d,u)=>{const m=i(d.row),x=i(u.row),f=m==null,h=x==null;if(f&&h)return d.index-u.index;if(f)return 1;if(h)return-1;const g=o(m,x);return g!==0?g*s:d.index-u.index}).map(d=>d.row)}function Yl(){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 ls(t){const a=Ul(t)?t:"day";return Yl().map((r,s)=>s===0?{...r,key:a}:r)}function cs(t,{key:a,dir:r}){return sn(t,{key:a,dir:r})}const wa=12,Zl=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function Jl(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 Ql(t){return Zl.some(a=>Jl(t?.[a]))}function Xl(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=sn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&Ql(n));return s===-1?a:r.slice(s)}function ec(t,a,r=wa){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:wa,i=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(i,i+n)}function tc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:o,hasActiveDeviceToken:i}={}){return t||a?!1:r?!0:s&&!n&&o===0&&!i}const ga=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function ac({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ga.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ga.active:s<=60*6e4?ga.warm:ga.idle}const rc=3e4;function sc({refresh:t,intervalMs:a=rc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let o=!1,i=null,d=Date.now(),u=0;const m=()=>{if(o||s.visibilityState!=="visible"||i)return i;const g=Promise.resolve().then(()=>t()).catch(p=>n(p)).then(()=>{}).finally(()=>{i===g&&(i=null)});return i=g,g},x=r.setInterval(()=>{const g=Date.now();g<u||(u=g+ac({visible:s.visibilityState==="visible",lastInteractionAt:d,now:g}),m())},a),f=()=>{s.visibilityState==="visible"&&(d=Date.now(),u=0,m())},h=()=>{d=Date.now()};return r.addEventListener("focus",f),r.addEventListener("pointerdown",h),r.addEventListener("keydown",h),s.addEventListener("visibilitychange",f),{run:m,stop(){o=!0,r.clearInterval(x),r.removeEventListener("focus",f),r.removeEventListener("pointerdown",h),r.removeEventListener("keydown",h),s.removeEventListener("visibilitychange",f)}}}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 Vt(r)===t?r:null}function oc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=nc(s)||new Date,o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Vt(o),to:Vt(n)}}function ic(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 vr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function lc(t){const a=vr(t?.model_id);return a||null}function nn(t,a){return t?.model?String(t.model):a}function on(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",o=vr(n);if(!o||o.includes("/"))continue;const i=Math.max(0,ee(s?.weight)??0);(!a.has(o)||i>=(r.get(o)||0))&&(a.set(o,n),r.set(o,i))}return a}function ln(t,a){const r=vr(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function St(t,a=0){const r=ee(t?.billable_total_tokens),s=ee(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const cc={deepseek:"dsh"};function dc(t){const a=typeof t=="string"?t:"";return cc[a]||a}const uc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"],cn=["input","output","cached","cacheCreate","reasoning"];function mc(t){let a=0;for(const r of cn)a+=Math.max(0,Number(t?.[r])||0);return a}function hc(t){return mc(t?.tokens)>0}function ds(t,a){for(const r of uc)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 us(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,total_cost_usd:"0"}}function xc(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:us(),models:new Map},a.set(s,n)),ds(n.totals,r?.totals);for(const o of Array.isArray(r?.models)?r.models:[]){const i=o?.model_id||o?.model||"";if(!i)continue;let d=n.models.get(i);d||(d={...o,model:o?.model||i,model_id:i,totals:us()},n.models.set(i,d)),ds(d.totals,o?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function gc(t,{copyFn:a}={}){const r=typeof a=="function"?a:i=>i,n=xc(Array.isArray(t?.sources)?t.sources:[]).map(i=>{const d=St(i?.totals),u=ee(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(d)?d:0,totalCost:Number.isFinite(u)?u:0,inputTokens:Math.max(0,ee(i?.totals?.input_tokens)??0),cacheRead:Math.max(0,ee(i?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,ee(i?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!n.length)return[];const o=n.reduce((i,d)=>i+d.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((i,d)=>d.totalTokens-i.totalTokens).map(i=>{const d=i.source?String(i.source).toUpperCase():r("shared.placeholder.short"),u=o>0?i.totalTokens/o*100:0,m=Number.isFinite(u)?u.toFixed(2):"0.00",x=i.models.map(p=>{const b=St(p?.totals);if(!Number.isFinite(b)||b<=0)return null;const k=i.totalTokens>0?Math.round(b/i.totalTokens*1e3)/10:0,j=nn(p,r("shared.placeholder.short")),_=lc(p),S=ee(p?.totals?.total_cost_usd),C=S??(i.totalCost>0&&i.totalTokens>0?b/i.totalTokens*i.totalCost:null),D=p?.totals||{};return{id:_,name:j,share:k,usage:b,cost:C,tokens:{input:Math.max(0,ee(D?.input_tokens)??0),output:Math.max(0,ee(D?.output_tokens)??0),cached:Math.max(0,ee(D?.cached_input_tokens)??0),cacheCreate:Math.max(0,ee(D?.cache_creation_input_tokens)??0),reasoning:Math.max(0,ee(D?.reasoning_output_tokens)??0)},pricing:p?.pricing||null,costSource:p?.cost_source||null}}).filter(Boolean),f=i.inputTokens+i.cacheRead+i.cacheCreate,g=i.cacheRead+i.cacheCreate>0&&f>0?Math.round(i.cacheRead/f*100):null;return{source:i.source,label:d,totalPercent:String(m),totalPercentValue:u,usd:i.totalCost,usage:i.totalTokens,cacheHitRate:g,cacheReusedTokens:i.cacheRead,cacheInputTokens:f,models:x}})}function fc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const i of a){const d=Array.isArray(i?.models)?i.models:[];for(const u of d){const m=ee(u?.usage);if(m==null||m<=0)continue;const x=typeof u?.name=="string"&&u.name.trim()?u.name.trim():typeof u?.id=="string"&&u.id.trim()?u.id.trim():null;x&&s.push({model:u,name:x,usage:m})}}const n=on(s.map(i=>({name:i.name,weight:i.usage})));for(const{model:i,name:d,usage:u}of s){const m=ln(d,n);if(!m)continue;const{key:x}=m,f=r.get(x)||{id:x,name:m.name,usage:0,cost:0,hasCost:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0}};f.usage+=u;const h=i?.tokens||{};for(const p of cn)f.tokens[p]+=Math.max(0,Number(h[p])||0);const g=ee(i?.cost);g!=null&&(f.cost+=g,f.hasCost=!0),n.has(x)?f.name=n.get(x):u>=f.nameWeight&&(f.name=d,f.nameWeight=u),r.set(x,f)}const o=Array.from(r.values()).reduce((i,d)=>i+d.usage,0);return Array.from(r.values()).map(i=>({id:i.id,name:i.name,usage:i.usage,cost:i.hasCost?i.cost:null,tokens:{...i.tokens},share:o>0?Math.round(i.usage/o*1e3)/10:0})).sort((i,d)=>d.usage!==i.usage?d.usage-i.usage:String(i.name).localeCompare(String(d.name)))}function pc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:p=>p,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const o=new Map,i=new Map,d=new Map,u=[];let m=0;for(const p of n){const b=Array.isArray(p?.models)?p.models:[];for(const k of b){const j=St(k?.totals);if(!Number.isFinite(j)||j<=0)continue;m+=j;const _=nn(k,s("shared.placeholder.short"));u.push({name:_,tokens:j})}}const x=on(u.map(p=>({name:p.name,weight:p.tokens})));for(const{name:p,tokens:b}of u){const k=ln(p,x);if(!k)continue;const{key:j}=k;o.set(j,(o.get(j)||0)+b),x.has(j)?i.set(j,x.get(j)):b>=(d.get(j)||0)&&(d.set(j,b),i.set(j,p))}if(!o.size)return[];const f=Array.from(o.values()).reduce((p,b)=>p+b,0),h=m>0?m:f,g=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(o.entries()).map(([p,b])=>{const k=h>0?(b/h*100).toFixed(1):"0.0";return{id:p,name:i.get(p)||s("shared.placeholder.short"),tokens:b,percent:String(k)}}).sort((p,b)=>b.tokens!==p.tokens?b.tokens-p.tokens:String(p.name).localeCompare(String(b.name))).slice(0,g)}function yc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Yt(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function ms(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Wt(a);return(a===Us?t:t*r)<.01?`<${s}0.01`:Yt(t,{decimals:2,currency:a,rate:r})}function hs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const bc=vt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:o}=ja(),i=c.useMemo(()=>(Array.isArray(s)?s:[]).map(m=>{const x=ee(m?.usd)??0,f=ee(m?.usage)??0,h=Array.isArray(m?.models)?m.models:[];return{label:m?.label?String(m.label):"",usdValue:x,costLabel:ms(x,n,o),tokensLabel:hs(f),models:h.map(g=>{const p=ee(g?.usage)??0,b=ee(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:hs(p),costLabel:ms(b,n,o),sortCost:b,pricing:g?.pricing,costSource:g?.costSource,tokens:g?.tokens}}).filter(g=>g.costLabel||g.tokensLabel).sort((g,p)=>p.sortCost-g.sortCost)}}).filter(m=>m.usdValue>0||m.models.length>0).sort((m,x)=>x.usdValue-m.usdValue),[s,n,o]),d=i.some(m=>m.models.some(x=>x.costSource!=="provider_reported"&&x.pricing?.status==="unpriced")),u=c.useMemo(()=>{const m=i.reduce((x,f)=>x+f.usdValue,0);return d&&m===0?l("dashboard.cost_breakdown.unpriced_label"):`${d?"≥":""}${yc(m,n,o)}`},[i,n,o,d]);return e.jsx(qi,{open:a,onOpenChange:m=>{m||r?.()},children:e.jsxs(Gi,{children:[e.jsx(Yi,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(Zi,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(Ji,{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(Qi,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(Xi,{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(wr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:d?l("dashboard.cost_breakdown.known_subtotal"):l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:u}),e.jsx("p",{className:"mb-4 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.method")}),i.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),i.map((m,x)=>{const f=`fleet-${x}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":f,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:f,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:m.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:m.costLabel||"—"})]}),m.models.map((h,g)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:h.name,children:h.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:h.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):h.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),h.pricing?.status==="unpriced"&&h.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,h.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,h.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(h.tokens.input)||0),output:Ie(Number(h.tokens.output)||0),read:Ie(Number(h.tokens.cached)||0),write:Ie(Number(h.tokens.cacheCreate)||0)})}):null,h.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:h.pricing.input,output:h.pricing.output,read:h.pricing.cache_read,write:h.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:h.costLabel||(h.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):h.pricing?.status==="free"?Yt(0,{currency:n,rate:o}):l("dashboard.cost_breakdown.rate_unknown"))})]},h.id||`${h.name}-${g}`))]},`${m.label}-${x}`)})]})]})})]})})]})})});function kc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[o,i]=c.useState(null),[d,u]=c.useState(!1),[m,x]=c.useState(null),f=ht(),h=st([t,a,r,s,n,f]);return c.useEffect(()=>{const g=h();if(!t){i(null),x(null),u(!1);return}u(!0),i(null),x(null),ri({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(p=>{g()&&i(p||null)}).catch(p=>{g()&&(x(p?.message||String(p)),i(null))}).finally(()=>{g()&&u(!1)})},[t,a,r,s,n,f,h]),{data:o,loading:d,error:m}}function dn(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 un(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function mn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function hn(t,a){return a&&mn(un(t))==="github"?a:""}function xn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=c.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const xs="#10b981",Qa=[{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"}],Xa=60;function _c(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(h=>[h.day,h]));let o=a||t[0].day,i=r||t[t.length-1].day;o>i&&([o,i]=[i,o]),s&&i>s&&(i=s);const d=t[t.length-1].day;i<d&&(i=d);const u=new Date(`${o}T00:00:00Z`),m=new Date(`${i}T00:00:00Z`);if(!Number.isFinite(u.getTime())||!Number.isFinite(m.getTime()))return t;const x=Math.round((m.getTime()-u.getTime())/864e5)+1;x>Xa&&u.setUTCDate(u.getUTCDate()+(x-Xa));const f=[];for(;u.getTime()<=m.getTime()&&f.length<Xa;){const h=u.toISOString().slice(0,10);f.push(n.get(h)||{day:h,total_tokens:0,billable_total_tokens:0}),u.setUTCDate(u.getUTCDate()+1)}return f}function er(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function wt({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 wc({host:t}){if(!t)return null;let a;const r=mn(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(gl,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function tr({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]=vt.useState(!1),o=typeof t?.project_key=="string"?t.project_key:"",{owner:i,repo:d}=dn(o),u=typeof t?.project_ref=="string"?t.project_ref:"",m=un(u),{data:x,loading:f,error:h}=kc({projectKey:o,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:g,formatTokensTooltip:p}=Se(),b=vt.useCallback(()=>n(!0),[]),k=R=>{R.target===R.currentTarget&&s&&r()};vt.useEffect(()=>{const R=B=>{B.key==="Escape"&&b()};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[b]);const j=x?.totals||null,_=ee(j?.billable_total_tokens)??0,S=Number(x?.days_active||0),C=ee(j?.input_tokens)??0,D=ee(j?.cached_input_tokens)??0,M=C+D>0?D/(C+D):null,z=ee(x?.range_total_tokens)??0,N=ee(j?.total_tokens)??0,v=z>0?N/z:null,T=vt.useMemo(()=>_c(x?.daily,x?.from,x?.to,_r({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[x,a.timeZone,a.tzOffsetMinutes]),F=Qa.reduce((R,B)=>R+(ee(j?.[B.key])??0),0),O=Array.isArray(x?.sources)?x.sources:[],$=!f&&!h&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:R=>{R.target===R.currentTarget&&b()},className:Nt("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":o,className:Nt("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:b,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(wr,{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:xs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:xs}})]}),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(xn,{githubOwner:hn(u,i),letter:(d?.[0]||o?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[i?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[i,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:d||o||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(wc,{host:m}),m&&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]})]}),$?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(wt,{label:l("dashboard.projects.detail.stat_total"),value:g(_),title:p(_)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_share"),value:v==null?"—":er(v)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:M==null?"—":er(M)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_conversations"),value:_a(j.conversation_count)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_active_days"),value:_a(S)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_avg_day"),value:S>0?g(Math.round(_/S)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[f&&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"})]}),!f&&h&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!f&&!h&&!$&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.empty_range")}),$&&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(tr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(Vs,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),F>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(tr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:Qa.map(R=>{const B=ee(j[R.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/F*100}%`,backgroundColor:R.color,minWidth:"2px"}},R.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:Qa.map(R=>{const B=ee(j[R.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:R.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(R.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:p(B),children:g(B)})]},R.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(tr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(R=>{const B=Number(R.total_tokens||0),K=N>0?B/N:0,G=K*100,w=Number(R.conversation_count||0),P=Mi(R.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Ct,{provider:R.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:jt(R.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(R.days_active||0)}),w>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:w})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:p(B),children:g(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:er(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(G,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:P}})})]},R.source)})})]})]})]})]})})}function jc(t){return e.jsx(si,{mode:Kt.COMPACT,children:e.jsx(vc,{...t})})}const Nc=5;function Sc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:o}){const i=typeof t?.project_key=="string"?t.project_key:"",d=typeof t?.project_ref=="string"?t.project_ref:"",{owner:u,repo:m}=dn(i),x=hn(d,u),f=ee(t?.billable_total_tokens??t?.total_tokens)??0,h=a>0?Math.min(100,Math.max(2,f/a*100)):0,g=Array.isArray(t?.sources)?t.sources:[],p=g.slice(0,Nc),b=g.length-p.length;return e.jsxs("button",{type:"button",onClick:()=>o?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(xn,{githubOwner:x,letter:(m?.[0]||i?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[u?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[u,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:m||i||"—"})]}),p.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[p.map(k=>e.jsx(Ct,{provider:k.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},k.source)),b>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:b})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(f),children:s(f)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${h}%`,minWidth:f>0?"3px":0}})})]})]})}function Cc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:o,dailyEmptyPrefix:i,installSyncCmd:d,dailyEmptySuffix:u,detailsColumns:m,ariaSortFor:x,toggleSort:f,sortIconFor:h,pagedDetails:g,dailyBreakdownRows:p=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:_="day",detailsDateKey:S,renderDetailDate:C,renderDailyBreakdownDate:D,renderDetailCell:M,DETAILS_PAGED_PERIODS:z,period:N,detailsPageCount:v,detailsPage:T,setDetailsPage:F}){const[O,$]=c.useState("daily"),[R,B]=c.useState(null),{formatTokens:K,formatTokensTooltip:G}=Se();return e.jsxs(Te,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":O==="daily",type:"button",onClick:()=>$("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":O==="projects",type:"button",onClick:()=>$("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),O==="projects"&&e.jsx(qs,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:w=>r?.(Number(w)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),O==="projects"&&(()=>{const w=t.slice(0,a);if(w.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 P=w.reduce((H,te)=>{const ue=ee(te?.billable_total_tokens??te?.total_tokens)??0;return ue>H?ue:H},0);return e.jsx("div",{className:"space-y-1",children:w.map((H,te)=>e.jsx(Sc,{entry:H,maxTokens:P,copy:n,formatTokens:K,formatTokensTooltip:G,onSelect:B},H?.project_key||H?.project_ref||`entry-${te}`))})})(),R&&e.jsx(jc,{entry:R,query:s,onClose:()=>B(null)}),O==="daily"&&e.jsxs("div",{children:[p?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[i,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:d}),u]}):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(w=>e.jsx("th",{"aria-sort":k?.(w.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>f(w.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:w.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(w.key)||""})]})})},w.key))})}),e.jsx("tbody",{children:p.map(w=>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 ${w.missing?"text-oai-gray-400 dark:text-oai-gray-400":w.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:D?D(w):C(w)}),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:M(w,"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:M(w,"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:M(w,"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:M(w,"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:M(w,"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:M(w,"conversation_count")})]},String(w?.[_]||w?.day||w?.hour||w?.month||"")))})]})}),O!=="daily"&&z.has(N)&&v>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>F(w=>Math.max(0,w-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," / ",v]}),e.jsx("button",{type:"button",onClick:()=>F(w=>Math.min(v-1,w+1)),disabled:T+1>=v,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function ka(t){return typeof t!="string"?"":t.trim()}function gs(t){const a=ka(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Tc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=ka(r.tool),n=ka(r.planType)||ka(r.plan_type);if(!s||!n)continue;const o=gs(s)||s,i=gs(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:o,plan:i})}return Array.from(a.values())}function Ac({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:o=[],className:i=""}){const{formatTokensTooltip:d}=Se(),u=l("shared.placeholder.short"),m=l("shared.unit.percent"),x=t??l("identity_card.rank_placeholder"),f=Number.isFinite(Number(a))?Number(a):0,h=f?l("identity_card.streak_value",{days:f}):l("identity_card.rank_placeholder"),g=Tc(r),p={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=_=>{if(_==null)return u;const S=Ie(_,p);return S==="-"?u:S},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=o.slice(0,3);return e.jsxs(Te,{className:`h-full ${i}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),j.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:j.map((_,S)=>{const C=_?.name?String(_.name):u,D=_?.percent?String(_.percent):"",M=S===j.length-1,z=S+1;return e.jsxs("div",{className:`flex items-center py-2 ${M?"":"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:z}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:C,children:C}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[D,m]})]},_.id||C)})}),g.length>0&&e.jsx("div",{className:"mt-3 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex flex-wrap gap-1.5",children:g.map((_,S)=>e.jsxs(vl,{variant:"secondary",size:"sm",children:[_.tool," ",_.plan]},`${_.tool}:${_.plan}:${S}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children: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:h})]})]})]})}let fa=null;function Dc(){if(fa===null)try{fa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{fa=!1}return fa}function Mc(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),o=a*Math.sin(s),i=t+.3963377774*n+.2158037573*o,d=t-.1055613458*n-.0638541728*o,u=t-.0894841775*n-1.291485548*o,m=i*i*i,x=d*d*d,f=u*u*u;return[4.0767416621*m-3.3077115913*x+.2309699292*f,-1.2684380046*m+2.6097574011*x-.3413193965*f,-.0041960863*m-.7034186147*x+1.707614701*f].map(g=>{const p=Math.min(1,Math.max(0,g)),b=p<=.0031308?12.92*p:1.055*Math.pow(p,1/2.4)-.055;return Math.round(b*255)})}function gn(t,a,r,s){if(Dc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,o,i]=Mc(t,a,r);return s==null?`rgb(${n} ${o} ${i})`:`rgb(${n} ${o} ${i} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?gn(Number(a[1]),Number(a[2]),Number(a[3])):t}const fs={claude:35,codex:250,grok:200},ps={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 Lc(t,a){const r=fs[a]??fs.claude,s=ps[t]||ps.system_prompt;return gn(s.l,s.c,r)}const Ec=[{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"]}],Rc=[["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"]],Ic={duration:.18,ease:[.4,0,.2,1]},Fc={height:0,opacity:0},$c={height:"auto",opacity:1},Pc={height:0,opacity:0};function zc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function Bc(t,a){const r={};for(const s of["input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens","total_tokens"])r[s]=Math.round(Number(t?.[s]||0)*a);return r}function fn(t,a=null){const r=t.reduce((i,d)=>i+Number(d.totals.total_tokens||0),0),s=zc(a),n=s||r,o=s&&r>0?s/r:1;return t.map(i=>{const d=o===1?i.totals:Bc(i.totals,o);return{...i,totals:d,percent:n>0?Number((d.total_tokens/n*100).toFixed(2)):0}}).sort((i,d)=>d.totals.total_tokens-i.totals.total_tokens)}function Oc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=Ec.map(n=>{const o={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const i of n.from){const d=r.get(i);if(!d)continue;const u=d.totals||{};o.input_tokens+=u.input_tokens||0,o.cached_input_tokens+=u.cached_input_tokens||0,o.cache_creation_input_tokens+=u.cache_creation_input_tokens||0,o.output_tokens+=u.output_tokens||0,o.reasoning_output_tokens+=u.reasoning_output_tokens||0,o.total_tokens+=u.total_tokens||0}return{key:n.key,totals:o}});return fn(s,a)}function Uc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((m,x)=>x?.name==="Text Response"?m:m+Number(x?.totals?.total_tokens||0),0),o=Number(r.total_tokens||0),i=Math.min(Math.max(0,n),Math.max(0,o-s)),u=[{key:"messages",totals:{total_tokens:Math.max(0,o-s-i)}},{key:"tool_calls",totals:{total_tokens:i}},{key:"reasoning",totals:{total_tokens:s}}];return fn(u,a)}const ys="MCP: ";function Hc(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const o=String(n?.name||"");o.startsWith(ys)?(a.push({...n,name:o.slice(ys.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,o)=>(o.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function bs(t){return l(`dashboard.context_breakdown.category.${t}`)}function Kc(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function Vc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),o=Number(r?r.cached_input_tokens||0:a?.cache_read||0),i=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),d=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:Kc(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:o,cache_creation:i,total_tokens:Number(d||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function Wc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),o=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),d=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:o,cached_input_tokens:i,cache_creation_input_tokens:d,total_tokens:Number(r.total_tokens||n+o)},tools:Vc(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function qc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:o,cache_creation_input_tokens:i,total_tokens:Number(r.total_tokens||s+n+o+i)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Gc(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 Yc(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 Zc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:o,cache_creation_input_tokens:i,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function ks(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 Jc(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 _s(t){return t==="exec_command"||t==="Bash"}function pn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function Qc(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function Xc(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const ed=10;function Xe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:o=!1,open:i=!1,onToggle:d,tokens:u,percent:m=null,children:x,share:f=null,fillColor:h=null}){const g=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",p=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:ed},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[p,e.jsx("span",{className:g,children:r}),s,o&&e.jsx(Ke.span,{animate:{rotate:i?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(oi,{size:11})})]}),k=h&&f!=null&&f>0,j=k?Math.max(0,Math.min(100,f)):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, ${h.replace(/\)\s*$/," / 0.10)")} 0%, ${h.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[o?e.jsx("button",{type:"button",onClick:d,"aria-expanded":i,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:b}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:b}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:u||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:m||""})]}),o&&x?e.jsx(Qs,{initial:!1,children:i&&e.jsx(Ke.div,{initial:Fc,animate:$c,exit:Pc,transition:Ic,style:{overflow:"hidden"},children:x},"content")}):null]})}function ws({execDetails:t,source:a="claude"}){const{formatTokens:r}=Se(),[s,n]=c.useState("by_type"),o=Zc(Jc(t,s)),i=a==="codex"||a==="grok",d=i?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:Rc.map(([u,m])=>e.jsx("button",{type:"button",onClick:()=>n(u),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===u?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(m)},u))}),o.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:i?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${d} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),i&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),o.map((u,m)=>e.jsxs(Ke.div,{role:"row",className:`grid ${d} gap-2 py-1.5`,title:u.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:m*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:u.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(u.calls||0)}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(u.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:ks(u.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:ks(u.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(u.totals.total_tokens||0)}),i&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(u.output_lines||0)})]},u.name))]})})]})}function Ut({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Se(),[o,i]=c.useState({}),[d,u]=c.useState(!1),m=Wc(t?.categories||[]);function x(f){i(h=>({...h,[f]:!h[f]}))}return m.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(pn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:m.map(f=>{const h=f.toolCount>0,g=f.name==="Execution"&&a,p=g&&f.tools.some(k=>_s(k.name)),b=!!o[f.name];return e.jsxs(Xe,{level:1,label:f.name,labelTone:"strong",hasChevron:h||g&&!p,open:b||g&&!p&&d,onToggle:()=>{h?x(f.name):g&&!p&&u(k=>!k)},tokens:n(f.totals.total_tokens||0),percent:null,children:[h&&e.jsx("ul",{className:"space-y-0.5",children:f.tools.map(k=>{const j=g&&_s(k.name);return e.jsx(Xe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:d,onToggle:()=>u(_=>!_),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(ws,{execDetails:a,source:r})},k.name)})}),g&&!p&&e.jsx(ws,{execDetails:a,source:r})]},f.name)})})}function td({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:o}=Se(),[i,d]=c.useState(null),[u,m]=c.useState(!1),[x,f]=c.useState(null),[h,g]=c.useState({}),p=c.useRef({});function b(w){g(P=>({...P,[w]:!P[w]}))}if(c.useEffect(()=>{let w=!1;const P=`${t||""}|${a||""}|${r||"claude"}`,H=p.current[P];return d(H||null),m(!0),n?.(!0),f(null),ni({from:t,to:a,source:r,timeZone:Ks(),tzOffsetMinutes:Hs()}).then(te=>{w||(p.current[P]=te,d(te))}).catch(te=>{w||f(te?.message||String(te))}).finally(()=>{w||(m(!1),n?.(!1))}),()=>{w=!0}},[t,a,r]),u&&!i)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(w=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${w*80}ms`}},w))}),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(x)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(Qc(r))});if(!i||i.scope!=="supported"||!i.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(pn(r))});const k=r==="claude"?Oc(i.categories||[],s):Uc(i,s),j=i.tool_calls_breakdown||null,_=i.skills_breakdown||null,S=i.message_breakdown||null,C=i.configured_resources||null,D=i.exec_command_breakdown||null,M=Gc(_?.skills||[]),z=qc(S?.categories||[]),N=r==="codex"&&(i?.breakdown_status==="queue_fallback"||i?.fallback==="queue_totals"),v=r==="claude"?j?.tool_calls||null:j||null,{mcpSet:T,residualSet:F,mcpTotalTokens:O}=Hc(v),$=r==="claude"&&j?.subagents||null,R=$?.categories?.length>0||(C?.custom_agents_count||0)>0,B=r==="claude"?(F?.categories||[]).reduce((w,P)=>w+Number(P?.totals?.total_tokens||0),0):0,K=r==="claude"?($?.categories||[]).reduce((w,P)=>w+Number(P?.totals?.total_tokens||0),0):0,G=[...k].sort((w,P)=>(P.totals?.total_tokens||0)-(w.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:k.filter(w=>w.percent>0).filter(w=>!(r==="claude"&&(w.key==="tool_calls"||w.key==="custom_agents"))).map(w=>`${bs(w.key)} ${w.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[G.map(w=>{const P=w.key==="system_prompt",H=w.key==="messages",te=w.key==="tool_calls",ue=w.key==="custom_agents";if(w.key,r==="claude"&&(te||ue))return null;const W=H&&z.length>0||te&&(F?.categories?.length>0||N)||ue&&R&&$,ne=!!h[w.key],le=Lc(w.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:le},"aria-hidden":"true"}),ye=P?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(Js,{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,Ae=w.percent>0?`${w.percent.toFixed(w.percent<.1&&w.percent>0?2:1)}%`:"0.0%";return e.jsxs(Xe,{level:0,colorSquare:je,label:bs(w.key),labelSuffix:ye,tokens:o(w.totals?.total_tokens||0),percent:Ae,hasChevron:W,open:ne,onToggle:()=>b(w.key),share:w.percent,fillColor:le,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:z.map(J=>e.jsx(Xe,{level:1,label:Yc(J),tokens:o(J.totals.total_tokens||0),percent:null},J.key||J.name))}),te&&F&&e.jsx(Ut,{toolSet:F,execDetails:D,source:r,codexQueueFallback:N}),te&&N&&!F&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),ue&&$&&e.jsx(Ut,{toolSet:$,execDetails:null,source:r,codexQueueFallback:!1})]},w.key)}),r==="claude"&&F?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(B),percent:null,hasChevron:!0,open:!!h.tool_calls_aux,onToggle:()=>b("tool_calls_aux"),children:e.jsx(Ut,{toolSet:F,execDetails:D,source:r,codexQueueFallback:!1})}),r==="claude"&&$?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(K),percent:null,hasChevron:!0,open:!!h.custom_agents_aux,onToggle:()=>b("custom_agents_aux"),children:e.jsx(Ut,{toolSet:$,execDetails:null,source:r,codexQueueFallback:!1})}),T?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(O),percent:null,hasChevron:!0,open:!!h.mcp_servers,onToggle:()=>b("mcp_servers"),children:e.jsx(Ut,{toolSet:T,execDetails:null,source:r,codexQueueFallback:!1})}),M.length>0&&e.jsx(Xe,{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(M.reduce((w,P)=>w+(P.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!h.skills,onToggle:()=>b("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:M.slice(0,12).map(w=>e.jsx(Xe,{level:1,label:w.name,tokens:o(w.total_tokens),percent:null},w.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(Xc(r))}),N?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,C?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(C.skills_count||0)," skills ·"," ",Ie(C.mcp_servers_count||0)," MCP servers ·"," ",Ie(C.custom_agents_count||0)," agents ·"," ",Ie(C.memory_files_count||0)," memory files"]}):null]})}function yn({size:t=15,className:a=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:a,"aria-hidden":"true",children:[e.jsx("path",{d:"M12 1.6 23 7.4 12 13.2 1 7.4 12 1.6Z"}),e.jsx("path",{d:"m4 10.3-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.72"}),e.jsx("path",{d:"m4 14.6-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.45"})]})}const it="__all__",ad=`${100 .toFixed(2)}%`;function qt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function hr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Wt(a);return(a===Us?s:s*r)<.01?`<${n}0.01`:Yt(s,{decimals:2,currency:a,rate:r})}function rd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:vs(a)}:{key:a.key,label:a.label||vs(a.key)}):[]}function sd(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 nd={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 ar(t,a){const r=t?.toUpperCase?.()||"";return nd[r]||`hsl(${150+a*40}, 60%, 45%)`}function od(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 id(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 ld(t){return!!t?.models?.length}function bn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function rr(t){const a=bn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const cd={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function vs(t){const a=cd[t];return a?l(a):String(t).toUpperCase()}function dd({loading:t,onClick:a}){const r=Gs();return e.jsx(li,{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(ci,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function ud(){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 md(){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 hd({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:o,summaryLabel:i,summaryCostValue:d,onCostInfo:u,fleetData:m=[],onRefresh:x,loading:f,announceLoading:h=!1,summaryLoading:g=!1,providersLoading:p=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:_,onCustomRangeApply:S,customRangeOpen:C,onCustomRangeOpenChange:D,onOpenShare:M,from:z,to:N,deviceOptions:v=[],selectedDevice:T="",onDeviceChange:F}){const O=rd(a),$=tl(di()),R=sd(String(s??"")),B=t==="week"&&typeof z=="string"&&typeof N=="string"&&z.slice(0,7)!==N.slice(0,7),K=t!=="day"&&z&&N?`${xa(z,$)} — ${xa(N,$)}`:null,G=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[w,P]=c.useState(G);c.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const A=window.matchMedia("(max-width: 639px)"),L=re=>P(re.matches);return A.addEventListener("change",L),()=>A.removeEventListener("change",L)},[]);const H=R!=null&&!w,te=c.useRef(null);c.useEffect(()=>{const A=te.current?.querySelector('[aria-selected="true"]');A&&typeof A.scrollIntoView=="function"&&A.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,W]=c.useState(null),{resolvedTheme:ne}=ii(),{currency:le,rate:je}=ja(),{formatTokens:ye}=Se(),Ae=ne==="dark",J=Ae?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Ae?"rgba(10,10,10,0)":"rgba(255,255,255,0)",oe=g&&!b,X=p&&!m.some(ld);c.useEffect(()=>{W(null)},[t,z,N,T]);const ae=A=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(A.key))return;const L=Array.from(A.currentTarget.querySelectorAll('[role="tab"]')).filter(ie=>!ie.disabled),re=L.indexOf(A.target.closest('[role="tab"]'));if(re===-1||L.length===0)return;A.preventDefault();let se=re;A.key==="Home"?se=0:A.key==="End"?se=L.length-1:A.key==="ArrowRight"?se=(re+1)%L.length:se=(re-1+L.length)%L.length,L[se].focus(),L[se].click()},pe=H?e.jsx(Ml,{value:R,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Ae?0:8,gradientFrom:J,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,V=m.filter(A=>A.models?.length>0),Y=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="devin"),Q=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="kiro"),xe=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="trae"),Ne=c.useMemo(()=>fc(m),[m]),Ce=Ne.reduce((A,L)=>A+(Number(L.usage)||0),0),De=V.reduce((A,L)=>A+(Number(L.usd)||0),0),ce=ue==null?null:ue===it||V.some(function(L){return L.label===ue})?ue:null;return e.jsx(Te,{className:k,children:e.jsxs("div",{"aria-busy":f||oe||X,children:[h?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:te,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:ae,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(A=>{const L=t===A.key,re=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${L?"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(A.key==="custom"){const se=L&&j&&_?`${xa(j,$)} — ${xa(_,$)}`:A.label;return e.jsxs(sl,{open:C,onOpenChange:ie=>{ie?r?.("custom"):D?.(ie)},children:[e.jsx(nl,{render:e.jsx("button",{role:"tab","aria-selected":L,tabIndex:L?0:-1,type:"button",className:re}),children:se}),e.jsx(ol,{children:e.jsx(il,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(ll,{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(el,{from:j,to:_,onApply:S,onCancel:()=>D?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":L,tabIndex:L?0:-1,type:"button",className:re,onClick:()=>r?.(A.key),children:A.label},A.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[v.length>1?e.jsx(qs,{value:T,onValueChange:F,options:v,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,M?e.jsxs("button",{type:"button",onClick:M,"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(pl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,x&&e.jsx(dd,{loading:f,onClick:x})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:i}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:oe?"invisible":void 0,children:o?e.jsx("button",{type:"button",onClick:o,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:pe}):e.jsx("span",{title:n||void 0,children:pe})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${oe?"":"hidden"}`,children:e.jsx(ud,{})})]}),d&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:u?e.jsxs("button",{type:"button",onClick:u,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[d,e.jsx(Js,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:d})}),xe&&e.jsxs("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("span",{className:"font-medium",children:[l("usage.overview.trae_notice_title"),"."]})," ",l("usage.overview.trae_notice_body")]}),K?e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-1 text-[11px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{className:"tabular-nums",children:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:X?void 0:"hidden",children:e.jsx(md,{})}),V.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:V.map(A=>l("usage.overview.distribution_item",{label:jt(A.label),percent:rr(A)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:V.map((A,L)=>{const re=ar(A.label,L),se=jt(A.label),ie=rr(A);return e.jsx(Ke.div,{initial:{width:0},animate:{width:`${bn(A)}%`},transition:{duration:.5,delay:.45+L*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:re},title:`${se}: ${ie}%`},A.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":ce===it,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:qt(ye,Ce)||String(0),cost:hr(De,le,je)||`${Wt(le)}0`,count:Ne.length}),onClick:()=>W(ce===it?null:it),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${ce===it?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(yn,{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:ad}),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:Ne.length})})]}),V.map((A,L)=>{const re=ar(A.label,L),se=ce===A.label,ie=jt(A.label),Ve=rr(A);return e.jsxs("button",{"aria-expanded":se,"aria-controls":`provider-details-${A.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:ie,percent:Ve,tokens:qt(ye,A.usage)||String(0),cost:hr(A.usd,le,je)||`${Wt(le)}0`,action:l(se?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>W(se?null:A.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${se?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(Ct,{provider:A.label,size:15,color:re,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:ie,children:ie})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[Ve,"%"]}),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:A.models.length})})]},A.label)})]}),ce===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Y&&e.jsx(_n,{}),Q&&e.jsx(wn,{}),e.jsx(pd,{models:Ne})]}),ce!=null&&ce!==it&&e.jsx("div",{id:`provider-details-${ce}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:ce}),className:"mt-2",children:V.filter(A=>A.label===ce).map(A=>{const L=ar(A.label,0),re=od(A),se=[...A.models].sort((Ve,me)=>(me.share||0)-(Ve.share||0)),ie=re?id(re):jt(A.label);return e.jsx(yd,{provider:A,color:L,providerHeading:ie,contextSource:re,from:z,to:N,sortedModels:se},A.label)})})]})]})})}const xd=[{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"}],gd="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 fd({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Se();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:xd.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 js({model:t,tokensLabel:a,costLabel:r,expandable:s,isExpanded:n}){const{formatTokensTooltip:o}=Se();return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:t.name,children:t.name}),e.jsx("span",{title:o(t.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:a}),e.jsx("span",{className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(n?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(rl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${n?"rotate-180":""}`})]})]})]})}function kn({models:t,color:a}){const{currency:r,rate:s}=ja(),{formatTokens:n}=Se(),[o,i]=c.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(d=>{const u=qt(n,d.usage),m=hr(d.cost,r,s),x=Math.max(0,Math.min(100,Number(d.share)||0)),f=d.id||d.name,h=hc(d),g=h&&o===f,p=gd,b={model:d,tokensLabel:u,costLabel:m,expandable:h,isExpanded:g};return e.jsxs("div",{"data-model-rank-row":!0,children:[h?e.jsx("button",{type:"button",onClick:()=>i(g?null:f),"aria-expanded":g,className:`${p} w-full cursor-pointer text-left`,children:e.jsx(js,{...b})}):e.jsx("div",{className:p,children:e.jsx(js,{...b})}),g&&e.jsx(fd,{tokens:d.tokens}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":x,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${x}%`,backgroundColor:a,opacity:.45}})})]},f)})})}function pd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(yn,{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(kn,{models:t,color:"var(--oai-blue)"})]})}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.devin_notice_title"),"."]})," ",l("usage.overview.devin_notice_body")]})}function wn(){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 yd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:o,sortedModels:i}){const{formatTokens:d}=Se(),[u,m]=c.useState(!1),x=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",f=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",h=String(t?.source||t?.label||"").trim().toLowerCase()==="kiro";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Ct,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&u&&e.jsx(al,{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:qt(d,t.cacheReusedTokens)||String(0),input:qt(d,t.cacheInputTokens)||String(0)})]}),x&&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")]}),f&&e.jsx(_n,{}),h&&e.jsx(wn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(td,{from:n,to:o,source:s,referenceTotalTokens:t.usage,onLoadingChange:m})}):null,e.jsx(kn,{models:i,color:a})]})}function bd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:o,transform:i,transition:d,isDragging:u}=Pi({id:t}),m=c.useRef(null),x=c.useRef(null);c.useLayoutEffect(()=>{if(!r)return;const h=m.current?m.current.childNodes.length===0:!0;x.current!==h&&(x.current=h,r(t,h))});const f={transform:zi.Transform.toString(i)||void 0,transition:d,zIndex:u?20:void 0};return e.jsxs("div",{ref:o,style:f,className:Nt("group/sortable relative has-[[data-sortable-body]:empty]:hidden",u&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:Nt("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",u&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:m,"data-sortable-body":!0,className:Nt("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",u&&"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 kd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[o,i]=c.useState(null),[d,u]=c.useState(!1),[m,x]=c.useState(null),f=st([t,a,r,s,n]),h=c.useCallback(async()=>{if(!t)return;const g=f();u(!0),x(null);try{const p=await Be(s);if(!g())return;const b=await ui({from:a,to:r,device:n,accessToken:p});if(!g())return;i(b||null)}catch(p){if(!g())return;x(p?.message||String(p)),i(null)}finally{g()&&u(!1)}},[t,a,r,s,n,f]);return c.useEffect(()=>{if(!t){i(null),x(null),u(!1);return}i(null),x(null),u(!0),h()},[t,h]),{data:o,loading:d,error:m,refresh:h}}function vn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function jn(t){return t==null?"—":`${Math.round(t*100)}%`}function _d(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 wd({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:vn(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:jn(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:_d(t.cost_usd,t.accepted)})]})}function vd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Se(),{enabled:o}=cl(),{data:i,loading:d}=kd({enabled:o,from:t,to:a,deviceId:r});if(!o)return null;const u=(i&&i.available&&Array.isArray(i.by_model)?i.by_model:[]).filter(h=>h.outcomes>0&&h.key!=="unknown");if(!u.length)return null;const m=u.slice(0,6),x=i.totals||{},f=`${l("qpd.card.subtitle")}${d?` ${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:f}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:m.map(h=>e.jsx(wd,{row:h},h.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:x.accepted??0,outcomes:x.outcomes??0,cost:vn(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:jn(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 jd=new Set(["unknown","synthetic","openai"]);function sr(t){return t==null?"—":`${Math.round(t*100)}%`}function Nd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Qe(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function Sd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!jd.has(r)&&Number(t?.edit_turns||0)>0}function Ns(){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 Cd({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=c.useState({requestKey:null,loading:!0,sessions:null,context:null}),o=s.requestKey===r?s:{loading:!0,sessions:null,context:null},i=c.useId(),{enabled:d}=dl(),u=st([d,t,a]),{formatTokens:m}=Se(),x=S=>m(S,{mode:Kt.COMPACT});c.useEffect(()=>{const S=u();if(!d){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([mi({from:t,to:a}),hi()]).then(([C,D])=>{S()&&n({requestKey:r,loading:!1,sessions:C,context:D})}).catch(()=>{S()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[d,t,a,r,u]);const f=c.useMemo(()=>(o.sessions?.by_model||[]).filter(Sd).slice(0,5),[o.sessions]),h=c.useMemo(()=>(o.sessions?.subagents||[]).slice(0,3),[o.sessions]);if(!d||!o.loading&&!o.sessions?.available&&!o.context?.estimated_fixed_tokens)return null;const g=o.sessions?.summary||{},p=g.edit_session_rate??g.productive_rate,b=g.first_pass_rate??g.one_shot_rate,k=g.edit_sessions??g.productive_sessions??0,j=g.sessions??o.sessions?.session_count??0,_=g.edit_turns??0;return o.loading&&!o.sessions&&!o.context?e.jsxs(Te,{children:[e.jsx(Ns,{}),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(Ns,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(nr,{label:l("sessions.card.edit_sessions"),value:sr(p),detail:l("sessions.card.edit_session_value",{edits:Qe(k),sessions:Qe(j)})}),e.jsx(nr,{label:l("sessions.card.first_pass"),value:sr(b),detail:l("sessions.card.edit_session_value",{edits:Qe(g.first_pass_sessions??g.one_shot_sessions??0),sessions:Qe(k)})}),e.jsx(nr,{label:l("sessions.card.cost_edit"),value:Nd(g.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Qe(_)})})]}),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:Qe(j),edits:Qe(_)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":i,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:i,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!f.length&&e.jsx("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:f.map(S=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:S.model,children:S.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Qe(S.edit_sessions??S.productive_sessions??0),sessions:Qe(S.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:sr(S.first_pass_rate??S.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:x(S.tokens_per_edit)})]},S.model))})]})}),o.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:x(o.context.estimated_fixed_tokens)})]}):null,!!h.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")}),h.map(S=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:S.name,calls:Math.round(S.calls)})},S.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function nr({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 de({className:t}){return e.jsx("div",{className:Nt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Td(){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(de,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function Ad(){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(de,{className:"h-4 w-32"}),e.jsx(de,{className:"h-6 w-24"})]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{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(de,{className:"h-3 w-20"}),e.jsx(de,{className:"h-3 w-12"})]},a))]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{className:"h-3.5 w-20"}),e.jsx(Td,{})]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{className:"h-3.5 w-28"}),e.jsx(de,{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(de,{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(de,{className:"h-8 w-20 rounded-md"}),e.jsx(de,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(de,{className:"h-3 w-28"}),e.jsx(de,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(de,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(de,{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(de,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(de,{className:"h-3 w-12"})]}),e.jsx(de,{className:"h-5 w-10"}),e.jsx(de,{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(de,{className:"h-7 w-16 rounded"}),e.jsx(de,{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(de,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(de,{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(de,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(de,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const Dd=hl.slice(0,10),Ss=.06,Md=.11,Ld=.05;function Cs({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:Dd,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 Ed(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:o,identityDisplayName:i,identityStartDate:d,activeDays:u,identitySubscriptions:m,identityScrambleDurationMs:x,projectUsageEntries:f,projectUsageLimit:h,setProjectUsageLimit:g,projectDetailQuery:p,topModels:b,signedIn:k,publicMode:j,isLocalMode:_,shouldShowInstall:S,installPrompt:C,handleCopyInstall:D,installCopied:M,installInitCmdDisplay:z,trendRowsForDisplay:N,trendFromForDisplay:v,trendToForDisplay:T,trendZoomConfig:F,usageFrom:O,usageTo:$,period:R,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:G,setSelectedPeriod:w,customFrom:P,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,summaryLabel:ne,summaryValue:le,summaryFullValue:je,hasSummary:ye,summaryLoading:Ae,providersLoading:J,onToggleSummaryFormat:U,summaryTotalTokensRaw:oe,summaryCostValue:X,summaryConversationsValue:ae,rollingUsage:pe,costInfoEnabled:V,openCostModal:Y,costModalOpen:Q,closeCostModal:xe,allowBreakdownToggle:Ne,refreshAll:Ce,usageLoadingState:De,announceUsageLoading:ce,initialDashboardLoading:A,fleetData:L,hasDetailsActual:re,dailyEmptyPrefix:se,installSyncCmd:ie,dailyEmptySuffix:Ve,detailsColumns:me,ariaSortFor:ge,toggleSort:Fe,sortIconFor:$e,pagedDetails:At,dailyBreakdownRows:xt,dailyBreakdownColumns:We,dailyBreakdownAriaSortFor:Na,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Sa,detailsDateKey:Ca,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:be,detailsPageCount:ke,detailsPage:ve,setDetailsPage:ft,deviceOptions:Dt,selectedDevice:Jt,onDeviceChange:Qt,deviceUsageBlock:Mt,leftCardOrder:Ta,onLeftReorder:qe,rightCardOrder:Xt,onRightReorder:nt}=t,Lt=null,Aa=null,Da={statsPanel:!0,installCopy:S,activityHeatmap:!!K,deviceUsage:!!Mt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:_&&!s},ea=(Ta||[]).filter(_e=>Da[_e]),Et={usageOverview:!0,dataDetails:!s},Ma=(Xt||[]).filter(_e=>Et[_e]);function Rt(_e,fe){switch(_e){case"statsPanel":return e.jsx(ot,{delay:fe,children:e.jsx(Ac,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:R,startDate:d??a("identity_card.rank_placeholder"),streakDays:u,subscriptions:m,periodConversations:ae,rolling:pe,topModels:b})});case"installCopy":return e.jsx(ot,{delay:fe,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:C}),e.jsxs(Ke.button,{onClick:D,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:z}),e.jsx(Ke.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:M?"Copied ✓":"Copy"},M?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:fe,children:K});case"deviceUsage":return e.jsx(ot,{delay:fe,children:Mt});case"trendMonitor":return e.jsx(ot,{delay:fe,children:e.jsx(Vs,{rows:N,from:v,to:T,period:R,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:F})});case"qualityPerDollar":return e.jsx(vd,{from:O,to:$,deviceId:Jt});case"sessionInsights":return e.jsx(Cd,{from:O,to:$});default:return null}}function It(_e,fe){switch(_e){case"usageOverview":return e.jsx(ot,{delay:fe,children:e.jsx(hd,{period:R,periods:G,onPeriodChange:w,summaryLabel:ne,summaryValue:le,summaryFullValue:je,hasSummary:ye,summaryLoading:Ae,providersLoading:J,onToggleSummaryFormat:ye?U:null,summaryCostValue:X,onCostInfo:V?Y:null,fleetData:L,onRefresh:s?null:Ce,loading:De,announceLoading:ce,onOpenShare:s?null:r,customFrom:P,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,from:O,to:$,deviceOptions:Dt,selectedDevice:Jt,onDeviceChange:Qt})});case"dataDetails":return e.jsx(ot,{delay:fe,children:e.jsx(Cc,{projectEntries:f,projectLimit:h,onProjectLimitChange:g,projectDetailQuery:p,copy:a,hasDetailsActual:re,dailyEmptyPrefix:se,installSyncCmd:ie,dailyEmptySuffix:Ve,detailsColumns:me,ariaSortFor:ge,toggleSort:Fe,sortIconFor:$e,pagedDetails:At,dailyBreakdownRows:xt,dailyBreakdownColumns:We,dailyBreakdownAriaSortFor:Na,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Sa,detailsDateKey:Ca,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:be,period:R,detailsPageCount:ke,detailsPage:ve,setDetailsPage:ft})});default:return null}}const La=Bi(ts(Wi,{activationConstraint:{distance:6}}),ts(Vi,{coordinateGetter:Ki})),Ye=c.useCallback(_e=>{const{active:fe,over:Pe}=_e;!Pe||fe.id===Pe.id||qe?.(String(fe.id),String(Pe.id))},[qe]),ta=c.useCallback(_e=>{const{active:fe,over:Pe}=_e;!Pe||fe.id===Pe.id||nt?.(String(fe.id),String(Pe.id))},[nt]);function Oe(_e,fe,Pe,aa){return s?e.jsx(e.Fragment,{children:_e.map((Ze,Ft)=>e.jsx(vt.Fragment,{children:fe(Ze,Pe+Ss*Ft)},Ze))}):e.jsx(Oi,{sensors:La,onDragEnd:aa,children:e.jsx(Ui,{items:_e,strategy:Hi,children:_e.map((Ze,Ft)=>e.jsx(bd,{id:Ze,children:fe(Ze,Pe+Ss*Ft)},Ze))})})}const he=Oe(ea,Rt,Md,Ye),Ea=Oe(Ma,It,Ld,ta);return e.jsxs(e.Fragment,{children:[e.jsxs(wl,{bare:!s,hideHeader:s,header:Lt,footer:s?null:Aa,className:s?"screenshot-mode":"",children:[o&&e.jsx(Cs,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(as,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Cs,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(as,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!o&&!n&&A&&e.jsx(Ad,{}),!o&&!n&&!A&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:he}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ea})]})})]}),e.jsx(bc,{isOpen:Q,onClose:xe,fleetData:L})]})}function Rd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:o=null,accountRevision:i=0}={}){const d=!!(n&&o),[u,m]=c.useState([]),[x,f]=c.useState([]),[h,g]=c.useState(!1),[p,b]=c.useState(null),k=st([d,t,a,r,s,o,i]),j=c.useCallback(async()=>{const _=k();if(!d){m([]),f([]),g(!1),b(null);return}g(!0),b(null);try{const S=await Be(o);if(!_())return;const C=await xi({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:S});if(!_())return;m(Array.isArray(C?.devices)?C.devices:[]),f(Array.isArray(C?.account_sources)?C.account_sources:[])}catch(S){if(!_())return;b(S?.message||String(S)),m([]),f([])}finally{_()&&g(!1)}},[d,o,t,a,r,s,i,k]);return c.useEffect(()=>{m([]),f([]),b(null),d&&g(!0),j()},[d,j]),{devices:u,accountSources:x,loading:h,error:p,refresh:j}}const Id=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Ts(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 xr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(Id);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Ts(t.platform)} · ${s}`:Ts(t.platform)}const As=" · ",Ds="%";function Ms({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(qr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(qr,{className:a,"aria-hidden":!0}):e.jsx(Xs,{className:a,"aria-hidden":!0})}function Ls(t,a){return a===t?.id||t?.isCurrent===!0}function Fd({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:o}){const{formatTokens:i,formatTokensTooltip:d}=Se(),[u,m]=c.useState(""),[x,f]=c.useState(""),[h,g]=c.useState(!1),[p,b]=c.useState(""),k=typeof o=="function",j=typeof n=="function",_=!!s,S=t.reduce((v,T)=>v+(Number(T.total_tokens)||0),0)+a.reduce((v,T)=>v+(Number(T.total_tokens)||0),0),C=c.useMemo(()=>t.filter(v=>(Number(v.total_tokens)||0)>0).sort((v,T)=>(Number(T.total_tokens)||0)-(Number(v.total_tokens)||0)),[t]);function D(v){b(""),m(v.id);const T=typeof v.device_name=="string"?v.device_name:"";f(xr(v)===T?T:"")}function M(){m(""),f(""),b("")}async function z(v){const T=x.trim();if(!(!T||h)){g(!0),b("");try{await o(v.id,T),m(""),f("")}catch{b(v.id)}finally{g(!1)}}}const N=a.filter(v=>(Number(v.total_tokens)||0)>0);return C.length===0&&N.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(Xs,{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")}),j&&_&&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:[C.map(v=>{const T=Number(v.total_tokens)||0,F=S>0?(T/S*100).toFixed(1):"0.0",O=s===v.id,$=xr(v)||l("dashboard.device_card.unnamed"),R=u===v.id,B=O?"bg-oai-brand":_?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=_&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[R?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(Ms,{platform:v.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:x,disabled:h,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:G=>f(G.target.value),onKeyDown:G=>{G.key==="Enter"?z(v):G.key==="Escape"&&M()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:h||!x.trim(),onClick:()=>z(v),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(xl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:h,onClick:M,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(wr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${F}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${$}${Ls(v,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":v.id),className:`w-full text-left rounded-md px-2 py-1.5 transition-all duration-200 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-oai-brand/50 ${K} ${O?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Ms,{platform:v.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:$,children:$}),Ls(v,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")})]}),e.jsxs("span",{title:d(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[As,F,Ds]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${F}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>D(v),className:"absolute right-2 top-1.5 flex h-4 items-center text-oai-gray-400 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-oai-brand focus:outline-none transition-opacity duration-150",children:e.jsx(ul,{className:"h-3 w-3"})})]}),p===v.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},v.id)}),N.map(v=>{const T=Number(v.total_tokens)||0,F=S>0?(T/S*100).toFixed(1):"0.0",O=_?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(Ct,{provider:v.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:jt(v.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:d(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[As,F,Ds]})]})]}),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 ${_?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${F}%`}})})]},`account-${v.source}`)})]})]})}function Nn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function Sn(){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 $d(t){if(!Nn()||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"};Sn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{mt.has(r)&&(mt.delete(r),s({ok:!1,error:"timeout"}))},8e3);mt.set(r,o=>{window.clearTimeout(n),s(o)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(o){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:o?.message||String(o)})}})}async function Es(t,a){if(!Nn()||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"};Sn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const o=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,i=>{window.clearTimeout(o),n(i)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(i){ut.delete(s),window.clearTimeout(o),n({ok:!1,error:i?.message||String(i)})}})}const Cn=1200,Tn=1630,An={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},Pd="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 or=!1;function zd(){if(typeof document>"u"||or)return;if(document.querySelector('link[data-share-card-fonts="true"]')){or=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=Pd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),or=!0}async function Bd(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function Od(t,a={}){if(typeof window>"u"||!t)return null;zd(),await Bd(),await new Promise(u=>requestAnimationFrame(()=>u(null)));const{toBlob:r,toPng:s}=await gi(async()=>{const{toBlob:u,toPng:m}=await import("./index-BFIcLxb4.js");return{toBlob:u,toPng:m}},[]),n=a.pixelRatio??2,o=t.offsetWidth||Cn,i=t.offsetHeight||Tn,d={pixelRatio:n,cacheBust:!0,width:o,height:i,style:{width:`${o}px`,height:`${i}px`},skipFonts:!1,filter:u=>!(u instanceof HTMLElement)||u.dataset?.screenshotExclude!=="true"};try{const u=await r(t,d);if(u)return u}catch{}try{const u=await s(t,d);return u?await(await fetch(u)).blob():null}catch{return null}}async function ir(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 Rs(t,a){if(typeof window>"u"||!t)return!1;try{const r=URL.createObjectURL(t),s=document.createElement("a");return s.href=r,s.download=a,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),!0}catch{return!1}}function gr(t){const a=ee(t);return Number.isFinite(a)?a:0}function Ud(t){return t?gr(t.billable_total_tokens??t.total_tokens):0}function Hd(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(o=>(Array.isArray(o)?o:[]).slice(0,7).map(d=>{const u=!!d?.future,m=Number.isFinite(d?.level)?Math.max(0,Math.min(4,Math.round(d.level))):0;d?.day&&!u&&(r+=1,m>0&&(s+=1));const x=d?.billable_total_tokens??d?.total_tokens??d?.value??0,f=Number.isFinite(x)?Math.max(0,x):0;return{day:typeof d?.day=="string"?d.day:"",level:m,value:f,future:u}})),totalDays:r,activeDays:s}}function Kd(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:o,rank:i,period:d,periodFrom:u,periodTo:m,heatmap:x,capturedAt:f,currency:h,exchangeRate:g}=t,p=Ud(n),b=gr(n?.total_cost_usd),k=Array.isArray(o)?o.slice(0,3).map(_=>({id:_?.id??null,name:typeof _?.name=="string"&&_.name?_.name:"—",tokens:gr(_?.tokens),percent:typeof _?.percent=="string"&&_.percent?_.percent:"0.0"})):[],j=Hd(x);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:p,totalCost:b,period:d,periodFrom:u,periodTo:m,topModels:k,rank:typeof i=="number"&&Number.isFinite(i)&&i>0?Math.floor(i):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:f||new Date().toISOString(),currency:typeof h=="string"&&h.length>0?h.toUpperCase():"USD",exchangeRate:Number.isFinite(g)&&g>0?g:1}}const Vd=["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 Wd(t){const a=Vd[t];return a?l(a):"—"}function Dn(t,a){return l("share.date.month_year",{month:Wd(t),year:a})}function qd(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:Dn(n,r)}function Gd(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 Dn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function fr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Mn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Wt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const o=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return o>=1e3?`${n}${Math.round(o).toLocaleString("en-US")}`:`${n}${o.toFixed(2)}`}function Yd(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 Zd(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 Jd(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 Qd({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:o}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const i=a||["#eee","#ccc","#999","#666","#333"],d=o||i[0],u=t.length,m=(u-1)*s,x=Math.max(4,(r-m)/u),f=7*x+6*s;return e.jsx("svg",{width:r,height:f,viewBox:`0 0 ${r} ${f}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((h,g)=>(Array.isArray(h)?h:[]).map((b,k)=>{if(k>=7)return null;const j=Jd(b),_=g*(x+s),S=k*(x+s),C=j===null?d:i[j];return e.jsx("rect",{x:_,y:S,width:x,height:x,rx:n,ry:n,fill:C},`${g}-${k}`)}))})}const Xd=Tt("oklch(0.97 0.01 85)"),Re=Tt("oklch(0.18 0.02 85)"),at=Tt("oklch(0.38 0.015 85)"),Is=Tt("oklch(0.55 0.012 85)"),lt=Tt("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',eu='"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(Tt);function Ln({data:t}){const a=Gd(t),r=fr(t.totalTokens),s=Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=qd(t.startDate),o=Zd(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),i=Yd(t),d=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Xd,color:Re,fontFamily:eu,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 ${Is}`},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:lt}}),"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:ct,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:lt,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:ct,fontSize:o,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",i,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:lt,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color: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})})]})]}),d?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color: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(Qd,{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:ct,fontStyle:"italic",fontSize:26,color:at,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((u,m)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Is}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(m+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:ct,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:fr(u.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[u.percent,"%"]})]},u.id||u.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:lt},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:lt},children:l("share.card.broadsheet.days_count",{days:t.activeDays})})]})]}),e.jsxs("div",{children:[l("share.card.broadsheet.track_yours")," ",e.jsx("span",{style:{color:lt},children:"→ tokentracker.cc"})]})]})]})}const au=An["annual-report"].width,ru="#0a0820",rt="#ffffffee",dt="rgba(255,255,255,0.45)",lr="#a78bfa",su={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(40px)",WebkitBackdropFilter:"blur(40px)",border:"1px solid rgba(255,255,255,0.05)",boxShadow:["0 39px 56px -36px rgba(255,255,255,0.10) inset","0 7px 11px -4px rgba(255,255,255,0.06) inset","0 -82px 68px -64px rgba(101,67,149,0.08) inset","0 98px 100px -48px rgba(208,171,255,0.06) inset","0 4px 18px 0 rgba(156,146,215,0.06) inset","0 1px 40px 0 rgba(228,222,255,0.04) inset"].join(", ")},pa={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},pr='"Space Grotesk", "Inter Tight", sans-serif',cr='"Inter Tight", sans-serif',nu="rgba(255,255,255,0.06)",En=[nu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Rn=48,In=28,va=4,Fn=20,ou=au-Rn*2-In*2,iu=(ou-Fn*2)/3,yr=Math.min(Math.floor((iu-va*6)/7),40),lu=yr*7+va*6;function cu(t){if(!Array.isArray(t))return t;const a=[];for(const d of t)if(Array.isArray(d))for(const u of d)u?.day&&!u.future&&u.value>0&&a.push(u.value);if(!a.length)return t;a.sort((d,u)=>d-u);const r=d=>{const u=a.length,m=(u-1)*d,x=Math.floor(m);return Math.round((a[x]??0)+((a[Math.min(u-1,x+1)]??0)-(a[x]??0))*(m-x))},s=r(.5),n=r(.75),o=r(.9),i=d=>!d||d<=0?0:d<=s?1:d<=n?2:d<=o?3:4;return t.map(d=>Array.isArray(d)?d.map(u=>u?.day&&!u.future&&typeof u.value=="number"?{...u,level:i(u.value)}:u):d)}function du(t){if(!Array.isArray(t))return[];const a={},r=cu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const o=n.day.split("-");if(o.length<2)continue;const i=`${o[0]}-${o[1]}`;(a[i]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function uu(t){if(!t.length)return[];const a=[...t].sort((i,d)=>i.day.localeCompare(d.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let i=0;i<s.length;i+=7)n.push(s.slice(i,i+7));const o=n[n.length-1];for(;o&&o.length<7;)o.push(null);return n.slice(0,6)}const mu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function hu(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const o of n)o?.day&&!o.future&&a.push(o);a.sort((n,o)=>n.day.localeCompare(o.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Fs(t){const[a,r]=c.useState(null);return c.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const o=document.createElement("canvas");o.width=n.naturalWidth,o.height=n.naturalHeight,o.getContext("2d").drawImage(n,0,0),r(o.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function xu({data:t}){const a=uu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:pr,marginBottom:4},children:mu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:va},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:va},children:r.map((n,o)=>{const i=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:yr,height:yr,borderRadius:4,background:i<0?"transparent":En[i]}},o)})},s))})]})}function gu({data:t}){const a=du(t.heatmapWeeks),r=hu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,o=Fs(n),i=Fs("/neon_bg.png"),d=(t.handle||"?")[0].toUpperCase(),u=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:ru,fontFamily:pr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:i||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Rn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:u*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color: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:o?e.jsx("img",{src:o,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:d})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...su,borderRadius:22,padding:In,marginBottom:u},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),En.map((m,x)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:m}},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,${lu}px)`,gap:`8px ${Fn}px`,justifyContent:"center"},children:a.map(m=>e.jsx(xu,{data:m},m.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:u,marginBottom:u},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:cr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:fr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:cr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:u},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:lr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:cr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:lr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:pr,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:lr},children:"tokentracker.cc"})]})]})]})}const $n=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],fu={broadsheet:Ln,"annual-report":gu};function Pn(t){return An[t]||{width:Cn,height:Tn}}function pu(t){const a=$n.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const $s=c.forwardRef(function({data:a,variant:r},s){const n=fu[r]||Ln,{width:o,height:i}=Pn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:o,height:i,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function ya(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const yu=440;function bu(){const[t,a]=c.useState(null),r=c.useRef(null),s=c.useCallback((n,o="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:o,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return c.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function dr({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 ku({open:t,onClose:a,data:r,twitterText:s}){const[n,o]=c.useState(null),[i,d]=c.useState(""),[u,m]=c.useState("annual-report"),x=c.useRef(null),{toast:f,push:h}=bu(),g=fi(),p=c.useMemo(()=>{const N=g?.user;if(!N||typeof N!="object")return null;const v=N.user_metadata||{},T=N.profile||{},F=v.avatar_url||v.picture||T.avatar_url||N.avatar_url;return typeof F=="string"&&F.trim()?F.trim():null},[g?.user]);c.useEffect(()=>{t&&(o(null),d(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:i||r.handle,avatarUrl:p},{width:k,height:j}=Pn(u),_=yu/k;c.useEffect(()=>{if(!t)return;const N=v=>{v.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const S=c.useCallback(async()=>{const N=x.current;if(!N)return null;try{return await Od(N)}catch(v){return console.warn("[share] capture failed",v),null}},[]),C=c.useCallback(async()=>{if(n)return;o("copy");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}let v=!1;if(ya()){const T=await ir(N);T&&(v=(await $d(T)).ok)}else v=await Gr(N);h(v?l("share.toast.copied"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,h]),D=c.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),M=c.useCallback(async()=>{if(n)return;o("download");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}if(ya()){const T=await ir(N);if(T&&(await Es(T,D())).ok){h(l("share.toast.downloaded"),"success"),o(null);return}}const v=Rs(N,D());h(v?l("share.toast.downloaded"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,D,h]),z=c.useCallback(async()=>{if(n)return;o("x");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}if(ya()){const O=await ir(N);O&&(await Es(O,D()),h(l("share.toast.downloaded"),"success"))}else await Gr(N)?h(l("share.toast.copied"),"success"):Rs(N,D());const v=new URL("https://twitter.com/intent/tweet");s&&v.searchParams.set("text",s);const T=g?.user?.id,F=typeof T=="string"&&T?`/u/${T}`:"/";if(v.searchParams.set("url",`https://www.tokentracker.cc${F}?ref=share`),ya())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:v.toString()})}catch{window.open(v.toString(),"_blank","noopener,noreferrer")}else window.open(v.toString(),"_blank","noopener,noreferrer");o(null)},[n,S,h,s,D,g]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:j,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx($s,{ref:x,data:b,variant:u})}),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*_,height:j*_,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:j,transform:`scale(${_})`,transformOrigin:"top left"},children:e.jsx($s,{data:b,variant:u})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:i,onChange:N=>d(N.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:$n.map(N=>e.jsx("button",{type:"button",onClick:()=>m(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",u===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:pu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(dr,{onClick:z,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(dr,{onClick:M,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(dr,{onClick:C,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(Qs,{children:f?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",f.kind==="error"?"bg-red-600 text-white":f.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:f.text})},f.id):null})]})]}):null}function _u(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:o,topModels:i,period:d,periodFrom:u,periodTo:m,heatmap:x,accessToken:f,userId:h,currency:g,exchangeRate:p}=t,[b,k]=c.useState(null),j=p;return c.useEffect(()=>{if(!a||!h&&!ht())return;let _=!1;return(async()=>{try{const C=await pi({accessToken:f,userId:h,period:d==="day"||d==="custom"?"week":d,metric:"all",limit:100,offset:0});if(_)return;const M=(Array.isArray(C?.entries)?C.entries:Array.isArray(C)?C:[]).find(N=>N?.is_me===!0),z=typeof M?.rank=="number"?M.rank:null;k(z)}catch{_||k(null)}})(),()=>{_=!0}},[a,f,h,d]),c.useMemo(()=>Kd({handle:r,startDate:s,activeDays:n,summary:o,topModels:i,rank:b,period:d,periodFrom:u,periodTo:m,heatmap:x,currency:g,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,o,i,b,d,u,m,x,g,j])}function Ps(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),o={key:a,promise:n};t.current=o;const i=()=>{t.current===o&&(t.current=null)};return n.then(i,i),n}const wu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function vu({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const ju=["day","week","month","total","custom"],ur=new Set(["day","hour","month"]),Ht=new Set(["day","total","custom"]),Nu=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Su=["usageOverview","dataDetails"];function mr(t,a){if(typeof a=="number"&&a>0)return!0;if(typeof t=="bigint")return t>0n;if(typeof t=="number")return Number.isFinite(t)&&t>0;if(typeof t=="string"){const r=t.trim();if(!r)return!1;if(/^[0-9]+$/.test(r))try{return BigInt(r)>0n}catch{return!1}const s=Number(r);return Number.isFinite(s)&&s>0}return!1}function ba(t){return t?St(t,null):null}function zs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function Cu(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function Tu(){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:!Cu(window.location.hostname)}function gm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:o=!1,publicToken:i=null,signInUrl:d="/sign-in",signUpUrl:u="/sign-up",onMainContentVisible:m}){const{resolvedLocale:x}=yi(),{currency:f,rate:h}=ja(),{mode:g,setMode:p,formatTokens:b,formatTokensTooltip:k}=Se(),[j,_]=c.useState(!1),[S,C]=c.useState(null),[D,M]=c.useState(null),[z,N]=c.useState(!1),[v,T]=c.useState(null),[F,O]=c.useState(0),[$,R]=c.useState(0),[B,K]=c.useState(null),G=c.useMemo(()=>typeof window>"u"?!1:bi(window.location.search),[]),w=c.useMemo(()=>Tu(),[]),[P,H]=c.useState(!1),te=2200,[ue,W]=c.useState(!0),[ne,le]=c.useState(!1),[je,ye]=c.useState(!1),[Ae,J]=c.useState(!1),[U,oe]=c.useState(!1),X=c.useRef(!1),ae=ht(),pe=r&&!s,V=c.useMemo(()=>pe&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,pe]),Y=pe?V:null,Q=o?ki(i):Y,xe=r||ae||o,Ne=pe&&Gt(Y),Ce=r&&s&&!o,{accountView:De,revision:ce,resolving:A}=_i(),L=De&&!o,re=L?Y:null,se=A&&!o;c.useEffect(()=>{if(!r||ae){C(null),M(null),N(!1),T(null);return}if(o)return;if(!Ne){C(null),M(null),N(!1),T(null);return}let y=!0;const E=()=>{C(null),M(null),N(!1),T(null)};return N(!0),T(null),(async()=>{let I=null;try{I=await Be(Y)}catch{I=null}if(y){if(!I){E();return}try{const q={link_code:null,expires_at:null};if(!y)return;C(typeof q?.link_code=="string"?q.link_code:null),M(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;C(null),M(null),T(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,ae,r,o,Ne,Y,$]);const ie=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");c.useEffect(()=>{if(!ie&&(!r||ae||o)){K(null);return}if(!ie&&!Ne){K(null);return}let y=!0;return(async()=>{let E=null;try{E=await Be(Y)}catch{E=null}if(y){if(!E&&!ie){K(null);return}try{const I=await wi({baseUrl:t,accessToken:E});if(!y)return;K(I&&typeof I=="object"?I:null)}catch{if(!y)return;K(null)}}})(),()=>{y=!1}},[Ne,t,Y,ae,o,r]);const Ve=c.useMemo(()=>{if(!D)return!1;const y=Date.parse(D);if(!Number.isFinite(y))return!1;const E=F||Date.now();return y<=E},[D,F]);c.useEffect(()=>{!r||ae||o||!D||!Ve||z||(C(null),M(null),T(null),R(y=>y+1))},[Ve,D,z,ae,r]),c.useEffect(()=>{if(!D||o)return;const y=Date.parse(D);if(!Number.isFinite(y))return;const E=Date.now();if(O(E),y<=E)return;const I=window.setTimeout(()=>O(Date.now()),y-E),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(I),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[D]);const me=c.useMemo(()=>Ks(),[]),ge=c.useMemo(()=>Hs(),[]),Fe=c.useMemo(()=>vi(),[]),$e=o?null:a?.userId||a?.email||"default",[At,xt]=c.useState("month"),[We,Na]=c.useState(null),[et,Sa]=c.useState(null),[Ca,gt]=c.useState(!1),Z=G?"total":At,Zt=c.useMemo(()=>Z==="custom"&&We&&et?{from:We,to:et}:ji(Z,{timeZone:me,offsetMinutes:ge,now:Fe}),[Fe,Z,me,ge,We,et]),be=Zt.from,ke=Zt.to,[ve,ft]=c.useState(null),[Dt,Jt]=c.useState(()=>Yr());c.useEffect(()=>{const y=()=>Jt(Yr());return window.addEventListener(Zr,y),window.addEventListener("storage",y),()=>{window.removeEventListener(Zr,y),window.removeEventListener("storage",y)}},[]);const{devices:Qt,accountSources:Mt,refresh:Ta}=Rd({from:be,to:ke,timeZone:me,tzOffsetMinutes:ge,accountView:L,accountAccessToken:re,accountRevision:ce}),qe=c.useMemo(()=>Qt.filter(y=>(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.id===Dt})),[Qt,Dt]),Xt=c.useMemo(()=>Mt.filter(y=>(Number(y.total_tokens)||0)>0),[Mt]),nt=L&&qe.length>=2,Lt=L&&qe.length+Xt.length>=2;c.useEffect(()=>{if(!nt&&!Lt){ve!==null&&ft(null);return}ve&&!qe.some(y=>y.id===ve)&&ft(null)},[nt,Lt,qe,ve]);const Aa=c.useMemo(()=>nt?[{value:"",label:l("dashboard.device_filter.all")},...qe.map(y=>{const E=xr(y)||l("dashboard.device_card.unnamed"),I=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${E}${I}`}})]:[],[nt,qe,x]),Da=Lt?e.jsx(Fd,{devices:qe,accountSources:Xt,currentDeviceId:Dt,selectedDeviceId:ve||"",onSelectDevice:y=>ft(y||null),onRenameDevice:async(y,E)=>{const I=await Be(re);await Di({deviceId:y,name:E,accessToken:I}),await Ta()}}):null,ea=c.useMemo(()=>Ni({timeZone:me,offsetMinutes:ge}),[me,ge]),Et=c.useMemo(()=>Si({timeZone:me,offsetMinutes:ge}),[me,ge]),Ma=c.useMemo(()=>`Local time (${Et})`,[Et]),Rt=me,It=ge,La=ea,Ye=c.useMemo(()=>_r({timeZone:me,offsetMinutes:ge,date:Fe||new Date}),[Fe,me,ge]),ta=c.useMemo(()=>oc({period:Z,selectedFrom:be,selectedTo:ke,todayKey:Ye}),[be,Z,ke,Ye]),{daily:Oe,summary:he,rolling:Ea,source:_e,loading:fe,error:Pe,refresh:aa}=os({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:be,to:ke,includeDaily:Z!=="total",cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{daily:Ze,loading:Ft,refresh:jr}=os({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:ta.from,to:ta.to,includeDaily:!0,includeSummary:!1,cacheKey:$e?`${$e}.daily-breakdown`:"daily-breakdown",timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{breakdown:tt,loading:Nr,refresh:Sr}=Bl({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:be,to:ke,cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),[zn,Bn]=c.useState(3),{entries:On,loading:Un,refresh:Cr}=$l({baseUrl:t,accessToken:Q,from:be,to:ke,timeZone:me,tzOffsetMinutes:ge}),Tr=Z==="week"||Z==="month",ra=Z==="week"||Z==="month",Ar=c.useMemo(()=>Oe.filter(y=>y?.future?!1:!y?.day||!Ye?!0:String(y.day)<=String(Ye)),[Oe,Ye]),{rows:Je,from:Hn,to:Kn,loading:Vn,refresh:Dr}=Li({baseUrl:t,accessToken:Q,guestAllowed:Ce,period:Z,from:be,to:ke,months:24,cacheKey:$e,timeZone:Rt,tzOffsetMinutes:It,now:Fe,sharedRows:Tr?Oe:null,sharedRange:Tr?{from:be,to:ke}:null,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),Wn=c.useMemo(()=>({baseUrl:t,accessToken:Q,guestAllowed:Ce,cacheKey:$e,timeZone:Rt,tzOffsetMinutes:It,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),[t,Q,Ce,$e,Rt,It,Fe,L,re,ce,se,ve]),{daily:pt,heatmap:Ge,loading:Mr,refresh:Lr}=Ll({baseUrl:t,accessToken:Q,guestAllowed:Ce,weeks:52,cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{data:sa,refresh:Er}=Ei();c.useEffect(()=>{sa&&typeof sa=="object"&&Ci(sa)},[sa]);const Ue=c.useMemo(()=>Z==="day"?"hour":Z==="total"?"month":"day",[Z]),qn=c.useMemo(()=>ls(Ue),[Ue]),na="day",Gn=c.useMemo(()=>ls(na),[]),[He,Rr]=c.useState(()=>({key:"day",dir:"desc"}));c.useEffect(()=>{Rr(y=>!ur.has(y.key)||y.key===Ue?y:{key:Ue,dir:y.dir})},[Ue]);const yt=c.useMemo(()=>ur.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),oa=c.useMemo(()=>{if(Z==="day")return Array.isArray(Je)?Je.filter(I=>I?.hour&&!I?.future):[];if(Z==="total"){const I=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return Xl(I)}const y=Ar;return!y.some(I=>!I?.missing&&!I?.future)&&Oe.length>0?Oe.filter(I=>!I?.future).slice(-30).filter(I=>I?.day):y},[Z,Je,Ar,Oe]),$t=c.useMemo(()=>cs(oa,yt),[oa,yt]),Ir=c.useMemo(()=>oa.some(y=>!y?.missing&&!y?.future),[oa]),Ra=c.useMemo(()=>{if(!Ht.has(Z))return 1;const y=Math.ceil($t.length/wa);return y>0?y:1},[Z,$t.length]),[Ia,ia]=c.useState(0);c.useEffect(()=>{if(!Ht.has(Z)){ia(0);return}ia(y=>Math.min(y,Ra-1))},[Ra,Z]),c.useEffect(()=>{Ht.has(Z)&&ia(0)},[Z,He.dir,He.key]);const Yn=c.useMemo(()=>Ht.has(Z)?ec($t,Ia,wa):$t,[Ia,Z,$t]),Fr=c.useMemo(()=>ic(Ze,{period:Z}),[Ze,Z]),bt=c.useMemo(()=>ur.has(He.key)?{...He,key:na}:He,[He]),Zn=c.useMemo(()=>cs(Fr,bt),[Fr,bt]),Jn=c.useMemo(()=>ra?Oe:Z==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[Oe,Z,Je,ra]),Qn=ra?be:Hn,Xn=ra?ke:Kn;function eo(y,E){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(E.endsWith("_tokens")){const I=E==="total_tokens"?ba(y):y?.[E];return e.jsx("span",{title:k(I),children:b(I)})}return _a(y?.[E])}function to(y){const E=y?.[Ue];if(E==null)return"";const I=String(E);if(Ue==="hour"){const[q,Le]=I.split("T");if(q&&Le)return`${q} ${Le.slice(0,5)}`}return I}function ao(y){const E=y?.[na];return E==null?"":String(E)}function ro(y){Rr(E=>E.key===y?{key:y,dir:E.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function so(y){return yt.key!==y?"none":yt.dir==="asc"?"ascending":"descending"}function no(y){return yt.key!==y?"":yt.dir==="asc"?"▲":"▼"}function oo(y){return bt.key!==y?"none":bt.dir==="asc"?"ascending":"descending"}function io(y){return bt.key!==y?"":bt.dir==="asc"?"▲":"▼"}const Fa=c.useMemo(()=>{if(!r&&!ae&&!o&&!ie)return 0;const y=Number(Ge?.active_days);if(Number.isFinite(y))return y;let E=0;const I=new Set,q=(we,ze,Ee)=>{typeof we!="string"||!we||I.has(we)||mr(ze,Ee)&&(I.add(we),E+=1)};if(Array.isArray(pt))for(const we of pt)q(we?.day,ba(we));const Le=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const we of Le)for(const ze of Array.isArray(we)?we:[]){const Ee=zs(ze);q(ze?.day,Ee,ze?.level)}return E},[r,ae,Ge?.active_days,Ge?.weeks,pt]),[$r,Pr]=c.useState("month"),lo=c.useCallback(y=>{L&&!o&&Ga(a?.userId,"history"),y==="custom"?(Pr(E=>E==="custom"?"month":E),xt(E=>We&&et?"custom":E),gt(!0)):(xt(y),Pr(y),gt(!1))},[We,et,L,o,a?.userId]),co=c.useCallback((y,E)=>{L&&!o&&Ga(a?.userId,"history"),Na(y),Sa(E),xt("custom"),gt(!1)},[L,o,a?.userId]),uo=c.useCallback(y=>{gt(y),!y&&At==="custom"&&!We&&xt($r)},[At,We,$r]),mo=c.useRef(null),la=c.useMemo(()=>[t||"",$e||"",L?"cloud":"local",ce??"",Z||"",be||"",ke||"",Ye||"",ve||"all",me||"",ge??""].join(""),[ce,L,t,$e,be,Z,ve,me,Ye,ke,ge]),Pt=c.useCallback(async()=>Ps(mo,la,async()=>{L&&Ti(),L||Ai(),await Promise.all([aa(),Lr(),Dr(),Sr(),Cr(),jr()])}),[L,jr,Lr,Sr,Cr,Dr,aa,la]),ho=c.useRef(null),zr=c.useCallback(async()=>Ps(ho,la,async()=>{await vu({refreshUsageStats:Pt,refreshUsageLimits:Er})}),[la,Er,Pt]),$a=c.useRef(Pt);c.useEffect(()=>{$a.current=Pt},[Pt]);const Pa=c.useRef(null);c.useEffect(()=>{if(!ie||ae||L)return;Pa.current||(Pa.current=Jr({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Pa.current.then(()=>{if(y)return $a.current()}).catch(E=>{y&&console.warn("[DashboardPage] Reload sync failed:",E)}),()=>{y=!1}},[ie,ae,L]),c.useEffect(()=>{if(!ie||ae||L)return;const y=sc({refresh:()=>$a.current(),onError:E=>console.warn("[DashboardPage] Automatic usage refresh failed:",E)});return()=>y.stop()},[ie,ae,L]);const xo=c.useCallback(async()=>{J(!0);try{ie&&await Jr(wu),await zr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{J(!1)}},[ie,zr]),ca=Ae||fe||Ft||Mr||Vn||Nr||Un,za=!U&&(se||L&&ca&&!Ir),go=c.useMemo(()=>l("shared.data_source",{source:String(_e||"edge").toUpperCase()}),[_e,x]),da=c.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),fo="",Br=c.useMemo(()=>!da||da.includes("@")?l("dashboard.identity.fallback"):da,[da]),Or=c.useMemo(()=>Br.replace(/[^a-zA-Z0-9._-]/g,"_"),[Br]),Ur=c.useMemo(()=>o?l("dashboard.identity.fallback"):Or,[Or,fo,o]),Hr=c.useMemo(()=>{let y=null;const E=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(pt))for(const q of pt)q?.day&&mr(ba(q))&&E(q.day);const I=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const q of I)for(const Le of Array.isArray(q)?q:[]){if(!Le?.day)continue;const we=zs(Le),ze=Le?.level;mr(we,ze)&&E(Le.day)}return y},[Ge?.weeks,pt]),po=c.useMemo(()=>o?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(I=>{const q=typeof I?.tool=="string"?I.tool.trim():"",we=(typeof I?.plan_type=="string"?I.plan_type:typeof I?.planType=="string"?I.planType:"").trim();return!q||!we?null:{tool:q,planType:we,provider:typeof I?.provider=="string"?I.provider.trim():"",product:typeof I?.product=="string"?I.product.trim():"",rateLimitTier:typeof I?.rate_limit_tier=="string"?I.rate_limit_tier.trim():typeof I?.rateLimitTier=="string"?I.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[o,B]),yo=e.jsx(Ri,{heatmap:Ge,timeZoneLabel:ea,timeZoneShortLabel:Et,hideLegend:G,defaultToLatestMonth:G}),bo=c.useMemo(()=>`${be}..${ke}`,[be,Z,ke]),ko=l("usage.summary.total"),Me=he!=null,kt=Me?ba(he):0,_o=b(kt),wo=c.useCallback(()=>{p(g===Kt.COMPACT?Kt.FULL:Kt.COMPACT)},[p,g]),vo=l("dashboard.core_index.collapse_label"),jo=l("dashboard.core_index.expand_label"),No=l("dashboard.core_index.collapse_aria"),So=l("dashboard.core_index.expand_aria"),Co=!G,_t=l("shared.placeholder.short"),Ba=c.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let E=null,I=0;for(const ze of y){const Ee=St(ze?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>I&&(I=Ee,E=ze)}let q=_t,Le=_t,we="0.0";if(E&&I>0){q=E?.source?String(E.source).toUpperCase():_t;const ze=Array.isArray(E?.models)?E.models:[];let Ee=0;for(const qa of ze){const ma=St(qa?.totals);!Number.isFinite(ma)||ma<=0||ma>Ee&&(Ee=ma,Le=qa?.model?String(qa.model):_t)}Ee>0&&(we=(Ee/I*100).toFixed(1))}return{agentName:q,modelName:Le,modelPercent:we}},[tt,_t]),Oa=_a(kt),To=l("dashboard.screenshot.twitter_text",{total_tokens:Oa==="-"?_t:Oa,agent_name:Ba.agentName,model_name:Ba.modelName,model_percent:Ba.modelPercent}),Ao=c.useMemo(()=>G?[]:ju,[G]),Do=c.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(kt):"—",title:Me?k(kt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(he?.input_tokens):"—",title:Me?k(he?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(he?.output_tokens):"—",title:Me?k(he?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(he?.cached_input_tokens):"—",title:Me?k(he?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(he?.reasoning_output_tokens):"—",title:Me?k(he?.reasoning_output_tokens):void 0}],[he?.cached_input_tokens,he?.input_tokens,he?.output_tokens,he?.reasoning_output_tokens,kt,Me,b,k]),Ua=(tt?.sources||[]).some(y=>(y.models||[]).some(E=>E.pricing?.status==="unpriced"&&E.cost_source!=="provider_reported"&&Number(E.totals?.total_tokens)>0)),Ha=c.useMemo(()=>{if(Ua&&Number(he?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=Yt(he?.total_cost_usd,{currency:f,rate:h});return Ua&&y!=="-"?`≥${y}`:y},[he?.total_cost_usd,f,h,Ua]),Mo=c.useMemo(()=>he?.conversation_count??null,[he?.conversation_count]),Kr=c.useMemo(()=>gc(tt,{copyFn:l}),[tt]),Vr=c.useMemo(()=>pc(tt,{limit:3,copyFn:l}),[tt]),Lo=_u({enabled:P,handle:Ur,startDate:Hr,activeDays:Fa,summary:he,topModels:Vr,period:Z,periodFrom:be,periodTo:ke,heatmap:Ge,accessToken:typeof Q=="string"?Q:null,userId:a?.userId||null,currency:f,exchangeRate:h}),Eo=c.useCallback(()=>H(!0),[]),Ro=c.useCallback(()=>H(!1),[]),Io=c.useCallback(()=>_(!0),[]),Fo=c.useCallback(()=>_(!1),[]),$o=Ha&&Ha!=="-"&&Kr.length>0,zt=l("dashboard.install.cmd.init"),Ka=Ve?null:S,Va=Ka?l("dashboard.install.cmd.init_link_code",{link_code:Ka}):zt,Po=zt,zo=l("dashboard.install.cmd.sync"),Bo=Ka?l("dashboard.install.copy"):l("dashboard.install.copy_base"),Oo=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const Uo=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),Ho=tc({publicMode:o,screenshotMode:G,forceInstall:w,accessEnabled:xe,heatmapLoading:Mr,activeDays:Fa,hasActiveDeviceToken:Uo}),Ko=l("dashboard.install.prompt"),Vo=c.useCallback(async()=>{!Va||!await Qr(Va)||(le(!0),window.setTimeout(()=>le(!1),2e3))},[Va]);c.useCallback(async()=>{!zt||!await Qr(zt)||(ye(!0),window.setTimeout(()=>ye(!1),2e3))},[zt]);const Wa=c.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[x]),[Wo,qo]=c.useMemo(()=>{const y=Wa.split("{{cmd}}");return y.length===1?[Wa,""]:[y[0],y.slice(1).join("{{cmd}}")]},[Wa]),Bt=s&&!o,Ot=!r&&!ae&&!s&&!ie&&!o;c.useEffect(()=>{Bt||Ot||za||oe(!0)},[za,Ot,Bt]);const ua=Il(Nu,Su);return c.useEffect(()=>{X.current||Bt||Ot||ca||(X.current=!0,m?.())},[m,Ot,Bt,ca]),e.jsxs(e.Fragment,{children:[e.jsx(Ed,{copy:l,onOpenShare:Eo,screenshotMode:G,showExpiredGate:Bt,showAuthGate:Ot,identityDisplayName:Ur,identityStartDate:Hr,activeDays:Fa,identitySubscriptions:po,identityScrambleDurationMs:te,projectUsageEntries:On,projectUsageLimit:zn,setProjectUsageLimit:Bn,projectDetailQuery:{from:be,to:ke,timeZone:me,tzOffsetMinutes:ge},topModels:Vr,signedIn:r,publicMode:o,isLocalMode:ie,shouldShowInstall:Ho,installPrompt:Ko,handleCopyInstall:Vo,installCopied:ne,installCopiedLabel:Oo,installCopyLabel:Bo,installInitCmdDisplay:Po,linkCodeLoading:z,linkCodeError:v,trendRowsForDisplay:Jn,trendFromForDisplay:Qn,trendToForDisplay:Xn,trendZoomConfig:Wn,usageFrom:be,usageTo:ke,period:Z,trendTimeZoneLabel:La,activityHeatmapBlock:yo,periodsForDisplay:Ao,setSelectedPeriod:lo,customFrom:We,customTo:et,onCustomRangeApply:co,customRangeOpen:Ca,onCustomRangeOpenChange:uo,metricsRows:Do,summaryLabel:ko,summaryValue:_o,hasSummary:Me,summaryLoading:fe,providersLoading:Nr,summaryFullValue:Oa,onToggleSummaryFormat:wo,summaryTotalTokensRaw:ee(kt)||0,summaryCostValue:Ha,summaryConversationsValue:Mo,rollingUsage:Ea,costInfoEnabled:$o,openCostModal:Io,allowBreakdownToggle:Co,coreIndexCollapsed:ue,setCoreIndexCollapsed:W,coreIndexCollapseLabel:vo,coreIndexExpandLabel:jo,coreIndexCollapseAria:No,coreIndexExpandAria:So,refreshAll:xo,usageLoadingState:ca,announceUsageLoading:Ae,initialDashboardLoading:za,usageError:Pe,rangeLabel:bo,timeZoneRangeLabel:Ma,usageSourceLabel:go,fleetData:Kr,hasDetailsActual:Ir,dailyEmptyPrefix:Wo,installSyncCmd:zo,dailyEmptySuffix:qo,detailsColumns:qn,ariaSortFor:so,toggleSort:ro,sortIconFor:no,pagedDetails:Yn,dailyBreakdownRows:Zn,dailyBreakdownColumns:Gn,dailyBreakdownAriaSortFor:oo,dailyBreakdownSortIconFor:io,dailyBreakdownDateKey:na,detailsDateKey:Ue,renderDetailDate:to,renderDailyBreakdownDate:ao,renderDetailCell:eo,DETAILS_PAGED_PERIODS:Ht,detailsPageCount:Ra,detailsPage:Ia,setDetailsPage:ia,costModalOpen:j,closeCostModal:Fo,deviceOptions:Aa,selectedDevice:ve||"",onDeviceChange:y=>{L&&!o&&Ga(a?.userId,"view"),ft(y||null)},deviceUsageBlock:Da,leftCardOrder:ua.left.order,onLeftReorder:ua.left.reorder,rightCardOrder:ua.right.order,onRightReorder:ua.right.reorder}),e.jsx(ku,{open:P,onClose:Ro,data:Lo,twitterText:To})]})}export{gm as DashboardPage};
1
+ import{o as br,r as c,j as e,L as Go,dy as Yo,W as ht,aA as Gt,aB as Be,dz as Zo,dA as Jo,ay as Wr,dB as ha,aG as Bs,aH as Os,aI as kr,dC as Qo,dD as Xo,dE as ei,aK as _r,aJ as Vt,dF as ti,dG as ai,dH as ee,c as l,V as vt,X as wr,i as Ie,az as Yt,bh as Wt,z as Us,dI as ri,an as si,l as Kt,cb as _a,y as Nt,dJ as ni,U as Hs,Q as Ks,aM as oi,ao as ii,B as li,R as ci,h as di,dK as ui,dL as mi,dM as hi,dN as xi,am as qr,_ as gi,a as fi,dO as Gr,g as pi,Z as yi,co as bi,dP as ki,dQ as _i,dR as wi,dS as vi,dT as ji,cc as Yr,cP as Zr,dU as Ni,dV as Si,aT as Ci,d1 as Ga,dW as Jr,aR as Qr,dX as Ti,dY as Ai,dZ as Di}from"./__vite-browser-external-BtJVmciH.js";import{u as st}from"./use-latest-request-guard-DGhwmlX8.js";import{u as Xr}from"./use-ordered-list-BDN24weA.js";import{t as es,T as Vs,g as Mi,u as Li}from"./TrendMonitor-CceYpa2O.js";import{u as Ei}from"./use-usage-limits-CjyDfH-M.js";import{u as ja}from"./useCurrency-BgZmWbkx.js";import{u as Se}from"./useTokenFormat-D7s1-Zuk.js";import{f as jt,A as Ri}from"./provider-display-BCQQYPWD.js";import{g as Ii,q as Ws,J as Fi,M as $i,m as Ke}from"./react-BgpqhoCj.js";import{u as Pi,C as zi,a as Bi,b as ts,D as Oi,S as Ui,v as Hi,s as Ki,K as Vi,P as Wi}from"./sortable.esm-CehJQvFH.js";import{D as qi,a as Gi,b as Yi,c as Zi,d as Ji,e as Qi}from"./DialogTitle-DoQgdh5w.js";import{D as Xi}from"./DialogClose-BpWoD5h9.js";import{C as Te}from"./Card-LJX3G3zo.js";import{S as qs}from"./Select-pZDawyxt.js";import{P as Ct}from"./ProviderIcon-Da90GDcM.js";import{u as Gs}from"./use-reduced-motion-CfCY-K-a.js";import{a as Ys,u as Zs}from"./use-transform-BczE46xm.js";import{f as xa,D as el,g as tl}from"./DateRangePopover-PQXB8v0k.js";import{I as Js}from"./info-CWDhggIW.js";import{A as Qs}from"./index-BEecBW06.js";import{L as al}from"./loader-circle-DotT5gVp.js";import{C as rl}from"./chevron-down-mjUspqZv.js";import{P as sl,a as nl,b as ol,c as il,d as ll}from"./PopoverPopup-DDnISLKM.js";import{F as ot}from"./FadeIn-9ph1h_AG.js";import{u as cl,a as dl,P as ul}from"./use-session-efficiency-pref-DUu16y8Z.js";import{L as as}from"./LoginCard-Cv2ijoJx.js";import{L as ml,A as hl}from"./agent-logos-wxccxfWz.js";import{M as Xs}from"./monitor-smartphone-DOP5eqBD.js";import{C as xl}from"./check-BlBHefQ7.js";import"./terminal-Br5vyD6Q.js";import"./use-limits-display-prefs-T7KWAWZ6.js";import"./play-BUsybi9m.js";import"./composite-CzXFY9IC.js";import"./store-BHAXkHPR.js";import"./SelectItemText-D5wuuN7G.js";import"./usePositioner-dWENyY8z.js";import"./safePolygon-C-PFpZSA.js";import"./arrow-left-Bd5C77R2.js";const en={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"}]]};en.node;const gl=br(en);const tn={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"}]]};tn.node;const fl=br(tn);const an={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"]};an.node;const pl=br(an);function yl(t,a,r={}){const s=t.get();let n=null,o=s,i;const d=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,u=()=>{n&&(n.stop(),n=null),t.animation=void 0},m=()=>{const f=rs(t.get()),h=rs(o);if(f===h){u();return}const g=n?n.getGeneratorVelocity():t.getVelocity();u(),n=new Fi({keyframes:[f,h],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:i})},x=()=>{m(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((f,h)=>{o=f,i=g=>h(Ya(g,d)),Ii.postRender(x)},u),Ws(a)){let f=r.skipInitialAnimation===!0;const h=a.on("change",p=>{f?(f=!1,t.jump(Ya(p,d),!1)):t.set(Ya(p,d))}),g=t.on("destroy",h);return()=>{h(),g()}}return u}function Ya(t,a){return a?t+a:t}function rs(t){return typeof t=="number"?t:parseFloat(t)}function bl(t,a={}){const{isStatic:r}=c.useContext($i),s=()=>Ws(t)?t.get():t;if(r)return Ys(s);const n=Zs(s());return c.useInsertionEffect(()=>yl(n,t,a),[n,JSON.stringify(a)]),n}function kl(t,a={}){return bl(t,{type:"spring",...a})}function _l(){return e.jsxs(Go,{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 wl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:o=!1,bare:i=!1}){return i?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!o&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(_l,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!o&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function vl({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",o={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},i={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},d=`${n} ${o[a]} ${i[r]} ${s}`.trim();return e.jsx("span",{className:d,children:t})}var jl={};function Nl(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 Sl({mv:t,digit:a,height:r}){const s=Ys(t,n=>{const o=(n%10+10)%10,i=(10+a-o)%10;let d=i*r;return i>5&&(d-=10*r),d});return e.jsx(Ke.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Cl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Tl(t,a){const r=t/a;return Math.floor(Cl(r))}function Al(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((d,u)=>/\d/.test(d)&&(s===-1||u<s)).length,o=0,i=!1;return r.map(d=>{if(!/\d/.test(d))return d==="."&&(i=!0),d;if(!i){const u=10**Math.max(n-1,0);return n-=1,u}return o+=1,10**-o})}function Dl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const u=Nl(t,r),m=t!=="."&&t!==",",x=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...u,...s,...m?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...x?{width:u.width}:null},children:t})}const o=Tl(a,t),i=Zs(0),d=kl(i,{stiffness:220,damping:26,mass:.8});return c.useEffect(()=>{i.set(o)},[i,o]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(o)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(u,m)=>e.jsx(Sl,{mv:d,digit:m,height:r},m))})}function Ml({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:o=6,borderRadius:i=4,horizontalPadding:d=0,textColor:u="inherit",fontWeight:m="inherit",containerStyle:x,counterStyle:f,digitStyle:h,gradientHeight:g=14,gradientFrom:p="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const _=String(a??t??""),S=c.useMemo(()=>Array.isArray(n)&&n.length?n:Al(_),[n,_]),C=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&jl?.VITEST==="true",D=Gs()||C,M=Number.isFinite(Number(t))?Math.abs(Number(t)):0,z=r+s;return D?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:u,fontSize:r,fontWeight:m,lineHeight:1,...x,...f},children:_}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...x},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:o,overflow:"hidden",borderRadius:i,paddingLeft:d,paddingRight:d,lineHeight:1,color:u,fontWeight:m,...f},children:S.map((N,v)=>e.jsx(Dl,{place:N,value:M,height:z,digitStyle:h,shouldReduceMotion:D},`${String(N)}-${v}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:g,background:`linear-gradient(to bottom, ${p}, ${b})`}}),e.jsx("span",{style:j??{height:g,background:`linear-gradient(to top, ${p}, ${b})`}})]})]})}function Ll({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:o,timeZone:i,tzOffsetMinutes:d,now:u,accountView:m=!1,accountAccessToken:x=null,accountRevision:f=0,accountViewResolving:h=!1,deviceId:g=null}={}){const p=!!(m&&x),b=p?"cloud":"local",k=c.useMemo(()=>Yo({weeks:s,weekStartsOn:n,now:u}),[u,s,n]),[j,_]=c.useState([]),[S,C]=c.useState(null),[D,M]=c.useState("edge"),[z,N]=c.useState(!1),[v,T]=c.useState(null),F=ht(),O=Gt(a),$=!r,R=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=st([t,k.from,k.to,s,n,b,a,x,f,h,g,i,d,r,F,$,O,R]),K=c.useMemo(()=>{if(!o)return null;const W=kr({timeZone:i,offsetMinutes:d});return`tokentracker.heatmap.${o}.${b}.${s}.${n}.${W}.${g||"all"}`},[o,g,b,i,d,s,n]),G=c.useCallback(()=>{if(!K||typeof window>"u")return null;try{const W=window.localStorage.getItem(K);if(!W)return null;const ne=JSON.parse(W);return!ne||!ne.heatmap?null:ne}catch{return null}},[K]),w=c.useCallback(W=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(W))}catch{}},[K]),P=c.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=c.useRef(b);c.useEffect(()=>{H.current!==b&&(H.current=b,_([]),C(null),M("edge"),T(null),N(!0))},[b]);const te=c.useCallback(async()=>{const W=B(),ne=await Be(a),le=p?await Be(x):null;if(!W()||!ne&&!F&&!R&&!p)return;if(p&&!le){T("Your session expired. Please sign in again to view account data."),N(!1);return}const je=p?le:ne,ye=p?Zo:Jo,Ae=p?Bs:Os;N(!0),T(null);try{try{const X=await ye({baseUrl:t,accessToken:je,weeks:s,to:k.to,weekStartsOn:n,device:g,timeZone:i,tzOffsetMinutes:d}),ae=Array.isArray(X?.weeks)?X.weeks:[];if(!W())return;if(!ae.length&&$){const V=G();if(V?.heatmap){if(!W())return;C(V.heatmap),_(V.daily||[]),M("cache");return}}if(!ae.some(V=>(Array.isArray(V)?V:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&ae.length){const V=[];for(const Q of ae)for(const xe of Array.isArray(Q)?Q:[])xe?.day&&V.push({day:xe.day,total_tokens:xe.total_tokens??xe.value??0,billable_total_tokens:xe.billable_total_tokens??xe.value??xe.total_tokens??0});const Y=Wr({dailyRows:V,weeks:s,to:X?.to||k.to,weekStartsOn:n});if(!W())return;_(V),C({...Y,week_starts_on:n,active_days:V.filter(Q=>Number(Q?.billable_total_tokens??Q?.total_tokens)>0).length,streak_days:ha({dailyRows:V,to:X?.to||k.to})}),M("client"),$?w({heatmap:{...Y,week_starts_on:n,active_days:V.filter(Q=>Number(Q?.billable_total_tokens??Q?.total_tokens)>0).length,streak_days:ha({dailyRows:V,to:X?.to||k.to})},daily:V,fetchedAt:new Date().toISOString()}):P();return}if(!W())return;C(X||null),_([]),M("edge"),X&&$?w({heatmap:X,daily:[],fetchedAt:new Date().toISOString()}):$||P();return}catch(X){const ae=X,pe=ae?.status??ae?.statusCode;if(pe===401||pe===403)throw X}if(!W())return;const J=await Ae({baseUrl:t,accessToken:je,from:k.from,to:k.to,device:g,timeZone:i,tzOffsetMinutes:d}),U=Array.isArray(J?.data)?J.data:[];if(!W())return;_(U);const oe=Wr({dailyRows:U,weeks:s,to:k.to,weekStartsOn:n});if(!W())return;C({...oe,week_starts_on:n,active_days:U.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:k.to})}),M("client"),$?w({heatmap:{...oe,week_starts_on:n,active_days:U.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ha({dailyRows:U,to:k.to})},daily:U,fetchedAt:new Date().toISOString()}):P()}catch(J){if(!W())return;if($){const U=G();if(U?.heatmap){if(!W())return;C(U.heatmap),_(U.daily||[]),M("cache"),T(null)}else{const oe=J;T(oe?.message||String(oe)),_([]),C(null),M("edge")}}else{const U=J;T(U?.message||String(U)),_([]),C(null),M("edge")}}finally{W()&&N(!1)}},[a,t,F,r,$,k.from,k.to,G,O,i,d,n,s,P,w,R,p,x,f,g,B]);return c.useEffect(()=>{if(h){N(!0);return}if(!O&&!r&&!F&&!R&&!p){_([]),N(!1),T(null),C(null),M("edge");return}if(!$)P(),_([]),T(null),C(null),M("edge");else{const W=G();W?.heatmap&&(C(W.heatmap),_(W.daily||[]),M("cache"))}te()},[a,F,G,te,O,r,$,P,R,h]),{range:k,daily:j,heatmap:S,source:F?"mock":D==="client"?"edge":D,loading:z,error:v,refresh:te}}const El="tokentracker.dashboard.leftCardOrder.v1",Rl="tokentracker.dashboard.rightCardOrder.v1";function Il(t,a){const r=Xr(El,t),s=Xr(Rl,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),o=c.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:o}}const Fl=10;function $l({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i}={}){const[d,u]=c.useState([]),[m,x]=c.useState(!1),[f,h]=c.useState(null),g=ht(),p=Gt(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,o,i]),j=c.useCallback(async()=>{const _=k(),S=await Be(a);if(_()){if(!S&&!g&&!b){u([]),h(null),x(!1);return}x(!0),h(null);try{const C=await Qo({baseUrl:t,accessToken:S,limit:Fl,from:r,to:s,source:n,timeZone:o,tzOffsetMinutes:i});if(!_())return;u(Array.isArray(C?.entries)?C.entries:[])}catch(C){if(!_())return;const D=C?.message||String(C);h(D),u([])}finally{_()&&x(!1)}}},[a,t,r,g,n,o,s,i,b,k]);return c.useEffect(()=>{if(!p&&!g&&!b){u([]),h(null),x(!1);return}u([]),h(null),x(!0),j()},[g,j,p,b]),{entries:d,loading:m,error:f,refresh:j}}const ss="tokentracker.usage-cache-index",ns=24;function os({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:o=!0,includeSummary:i=!0,cacheKey:d,timeZone:u,tzOffsetMinutes:m,now:x,accountView:f=!1,accountAccessToken:h=null,accountRevision:g=0,accountViewResolving:p=!1,deviceId:b=null}={}){const k=!!(f&&h),j=k?"cloud":"local",[_,S]=c.useState([]),[C,D]=c.useState(null),[M,z]=c.useState(null),[N,v]=c.useState("edge"),[T,F]=c.useState(null),[O,$]=c.useState(!1),[R,B]=c.useState(null),K=ht(),G=Gt(a),w=!r&&!K,P=b||"all",H=(()=>{if(!d)return null;const J=Pl(t)||"default",U=o?i?"daily-summary":"daily-only":"summary",oe=kr({timeZone:u,offsetMinutes:m});return`tokentracker.usage.${d}.${j}.${J}.${s}.${n}.${U}.${oe}.${P}`})(),te=c.useRef(j);c.useEffect(()=>{te.current!==j&&(te.current=j,S([]),D(null),z(null),v("edge"),F(null),B(null),$(!0))},[j]);const ue=c.useCallback(()=>{if(!H||typeof window>"u")return null;try{const J=window.localStorage.getItem(H);if(!J)return null;const U=JSON.parse(J),oe=i?!!U?.summary:Array.isArray(U?.daily);return!U||!oe?null:(es(ss,H,ns),U)}catch{return null}},[i,H]),W=c.useCallback(J=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(J)),es(ss,H,ns)}catch{}},[H]),ne=c.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),je=st([t,s,n,o,i,j,a,h,g,b,u,m,r,K,w,p,G,le]),ye=c.useCallback(async()=>{const J=je(),U=await Be(a),oe=k?await Be(h):null;if(!J()||!U&&!K&&!le&&!k)return;if(k&&!oe){B("Your session expired. Please sign in again to view account data."),$(!1);return}const X=k?Bs:Os,ae=k?Xo:ei,pe=k?oe:U;$(!0),B(null);try{let V=null,Y=null;if(o)if(i){const[De,ce]=await Promise.allSettled([X({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m}),ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0})]);if(De.status==="rejected")throw De.reason;V=De.value,Y=ce.status==="fulfilled"?ce.value:null}else V=await X({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m});else i&&(Y=await ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0}));let Q=o&&Array.isArray(V?.data)?V.data:[];o&&(Q=Ja(Q,s,n,{timeZone:u,offsetMinutes:m,now:x}));let xe=i&&(Y?.totals||V?.summary?.totals)||null,Ne=i&&(Y?.rolling||V?.summary?.rolling)||null;if(i&&o&&!xe&&!Y)try{const De=await ae({baseUrl:t,accessToken:pe,from:s,to:n,device:b,timeZone:u,tzOffsetMinutes:m,rolling:!0});xe=De?.totals||null,Ne=De?.rolling||Ne}catch{}const Ce=new Date().toISOString();if(!J())return;S(Q),D(xe),z(Ne),v("edge"),F(Ce),(xe||!i&&o)&&w?W({summary:xe,rolling:Ne,daily:Q,from:s,to:n,includeDaily:o,includeSummary:i,fetchedAt:Ce}):w||ne()}catch(V){if(!J())return;if(w){const Y=ue();if(Y?.summary||!i&&Array.isArray(Y?.daily)){D(Y.summary),z(Y.rolling||null);const Q=Array.isArray(Y.daily)?Y.daily:[],xe=o?Ja(Q,Y.from||s,Y.to||n,{timeZone:u,offsetMinutes:m,now:x}):Q;S(xe),v("cache"),F(Y.fetchedAt||null),B(null)}else{const Q=V;B(Q?.message||String(Q)),S([]),D(null),z(null),v("edge"),F(null)}}else{const Y=V;B(Y?.message||String(Y)),S([]),D(null),z(null),v("edge"),F(null)}}finally{J()&&$(!1)}},[a,t,s,o,i,K,r,w,x,ue,G,u,n,m,ne,W,le,k,h,g,b,je]);return c.useEffect(()=>{if(p){$(!0);return}const J=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!G&&!r&&!K&&!J&&!k){S([]),D(null),z(null),B(null),$(!1),v("edge"),F(null);return}if(!w)ne(),S([]),D(null),z(null),B(null),v("edge"),F(null);else{const U=ue();if(U?.summary||!i&&Array.isArray(U?.daily)){D(U.summary),z(U.rolling||null);const oe=Array.isArray(U.daily)?U.daily:[],X=o?Ja(oe,U.from||s,U.to||n,{timeZone:u,offsetMinutes:m,now:x}):oe;S(X),v("cache"),F(U.fetchedAt||null),B(null)}else S([]),D(null),z(null),v("edge"),F(null),B(null)}$(!0),ye()},[a,K,ue,ye,G,r,w,ne,le,p,i]),c.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const J=15e3;let U=Date.now();const oe=()=>{if(document.visibilityState!=="visible")return;const X=Date.now();X-U<J||(U=X,ye())};return window.addEventListener("focus",oe),document.addEventListener("visibilitychange",oe),()=>{window.removeEventListener("focus",oe),document.removeEventListener("visibilitychange",oe)}},[ye]),{daily:_,summary:C,rolling:M,source:K?"mock":N,fetchedAt:T,loading:O,error:R,refresh:ye}}function Pl(t){try{return new URL(t).host}catch{return null}}function Za(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,o=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n,o));return Number.isFinite(i.getTime())&&Vt(i)===a?i:null}function zl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Ja(t,a,r,{timeZone:s,offsetMinutes:n,now:o}={}){const i=Za(a),d=Za(r);if(!i||!d||d<i)return Array.isArray(t)?t:[];const u=o instanceof Date&&Number.isFinite(o.getTime())?o:new Date,m=_r({timeZone:s,offsetMinutes:n,date:u}),x=Za(m),f=x?x.getTime():u.getTime(),h=new Map;for(const p of t||[])p?.day&&h.set(p.day,p);const g=[];for(let p=i;p<=d;p=zl(p,1)){const b=Vt(p),k=h.get(b),j=p.getTime()>f;if(k){g.push({...k,missing:!1,future:j});continue}g.push({day:b,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!j,future:j})}return g}function Bl({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:o,timeZone:i,tzOffsetMinutes:d,accountView:u=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:f=!1,deviceId:h=null}={}){const g=!!(u&&m),p=g?"cloud":"local",[b,k]=c.useState(null),[j,_]=c.useState("edge"),[S,C]=c.useState(!1),[D,M]=c.useState(null),z=ht(),N=Gt(a),v=!r,T=c.useMemo(()=>{if(!o)return null;const P=Ol(t)||"default",H=kr({timeZone:i,offsetMinutes:d});return`tokentracker.modelBreakdown.${o}.${p}.${P}.${s}.${n}.${H}.${h||"all"}`},[t,o,h,s,p,i,n,d]),F=c.useCallback(()=>{if(!T||typeof window>"u")return null;try{const P=window.localStorage.getItem(T);if(!P)return null;const H=JSON.parse(P);return!H||!H.breakdown?null:H}catch{return null}},[T]),O=c.useCallback(P=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(P))}catch{}},[T]),$=c.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),R=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=st([t,s,n,p,a,m,x,h,i,d,r,z,v,f,N,R]),K=c.useRef(p);c.useEffect(()=>{K.current!==p&&(K.current=p,k(null),_("edge"),M(null),C(!0))},[p]);const G=c.useCallback(async()=>{const P=B(),H=await Be(a),te=g?await Be(m):null;if(!P()||!H&&!z&&!R&&!g)return;if(g&&!te){M("Your session expired. Please sign in again to view account data."),C(!1);return}const ue=g?te:H,W=g?ti:ai;C(!0),M(null);try{const ne=await W({baseUrl:t,accessToken:ue,from:s,to:n,device:h,timeZone:i,tzOffsetMinutes:d});if(!P())return;k(ne||null),_("edge"),ne&&v?O({breakdown:ne,fetchedAt:new Date().toISOString()}):v||$()}catch(ne){if(!P())return;if(v){const le=F();if(le?.breakdown)k(le.breakdown),_("cache"),M(null);else{k(null),_("edge");const je=ne;M(je?.message||String(je))}}else{k(null),_("edge");const le=ne;M(le?.message||String(le))}}finally{P()&&C(!1)}},[a,t,s,z,r,v,F,i,n,N,d,$,O,R,g,m,x,h,B]);return c.useEffect(()=>{if(f){C(!0);return}if(!N&&!r&&!z&&!R&&!g){k(null),_("edge"),M(null),C(!1);return}if(!v)$(),k(null),_("edge"),M(null);else{const P=F();P?.breakdown?(k(P.breakdown),_("cache"),M(null)):(k(null),_("edge"),M(null))}C(!0),G()},[a,z,F,G,N,r,v,$,R,f]),{breakdown:b,source:z?"mock":j,loading:S,error:D,refresh:G}}function Ol(t){try{return new URL(t).host}catch{return null}}const rn=new Set(["day","hour","month"]);function Ul(t){return rn.has(t)}function is(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 Hl(t,a){const r=is(t),s=is(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=ee(t),o=ee(a);return n==null&&o==null?0:n==null?1:o==null?-1:n===o?0:n<o?-1:1}function Kl(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 Vl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),o=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o))return null;const i=new Date(Date.UTC(s,n-1,o));return!Number.isFinite(i.getTime())||i.getUTCFullYear()!==s||i.getUTCMonth()+1!==n||i.getUTCDate()!==o?null:i.getTime()}function Wl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const o=new Date(Date.UTC(s,n-1,1));return Number.isFinite(o.getTime())?o.getTime():null}function ql(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),o=Number(r[3]),i=Number(r[4]),d=Number(r[5]),u=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(o)||!Number.isFinite(i)||!Number.isFinite(d)||!Number.isFinite(u)||n<1||n>12||o<1||o>31||i<0||i>23||d<0||d>59||u<0||u>59)return null;const m=new Date(Date.UTC(s,n-1,o,i,d,u));return Number.isFinite(m.getTime())?m.getTime():null}function Gl(t,a,r){const s=r==="hour"?ql:r==="month"?Wl:Vl,n=s(t),o=s(a);return n!=null&&o!=null?n===o?0:n<o?-1:1:Kl(t,a)}function sn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],o=rn.has(a)?(d,u)=>Gl(d,u,a):Hl,i=d=>a==="total_tokens"&&d?.billable_total_tokens!=null?d.billable_total_tokens:d?.[a];return n.map((d,u)=>({row:d,index:u})).sort((d,u)=>{const m=i(d.row),x=i(u.row),f=m==null,h=x==null;if(f&&h)return d.index-u.index;if(f)return 1;if(h)return-1;const g=o(m,x);return g!==0?g*s:d.index-u.index}).map(d=>d.row)}function Yl(){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 ls(t){const a=Ul(t)?t:"day";return Yl().map((r,s)=>s===0?{...r,key:a}:r)}function cs(t,{key:a,dir:r}){return sn(t,{key:a,dir:r})}const wa=12,Zl=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function Jl(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 Ql(t){return Zl.some(a=>Jl(t?.[a]))}function Xl(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=sn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&Ql(n));return s===-1?a:r.slice(s)}function ec(t,a,r=wa){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:wa,i=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(i,i+n)}function tc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:o,hasActiveDeviceToken:i}={}){return t||a?!1:r?!0:s&&!n&&o===0&&!i}const ga=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function ac({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return ga.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?ga.active:s<=60*6e4?ga.warm:ga.idle}const rc=3e4;function sc({refresh:t,intervalMs:a=rc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let o=!1,i=null,d=Date.now(),u=0;const m=()=>{if(o||s.visibilityState!=="visible"||i)return i;const g=Promise.resolve().then(()=>t()).catch(p=>n(p)).then(()=>{}).finally(()=>{i===g&&(i=null)});return i=g,g},x=r.setInterval(()=>{const g=Date.now();g<u||(u=g+ac({visible:s.visibilityState==="visible",lastInteractionAt:d,now:g}),m())},a),f=()=>{s.visibilityState==="visible"&&(d=Date.now(),u=0,m())},h=()=>{d=Date.now()};return r.addEventListener("focus",f),r.addEventListener("pointerdown",h),r.addEventListener("keydown",h),s.addEventListener("visibilitychange",f),{run:m,stop(){o=!0,r.clearInterval(x),r.removeEventListener("focus",f),r.removeEventListener("pointerdown",h),r.removeEventListener("keydown",h),s.removeEventListener("visibilitychange",f)}}}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 Vt(r)===t?r:null}function oc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=nc(s)||new Date,o=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Vt(o),to:Vt(n)}}function ic(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 vr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function lc(t){const a=vr(t?.model_id);return a||null}function nn(t,a){return t?.model?String(t.model):a}function on(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",o=vr(n);if(!o||o.includes("/"))continue;const i=Math.max(0,ee(s?.weight)??0);(!a.has(o)||i>=(r.get(o)||0))&&(a.set(o,n),r.set(o,i))}return a}function ln(t,a){const r=vr(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function St(t,a=0){const r=ee(t?.billable_total_tokens),s=ee(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const cc={deepseek:"dsh"};function dc(t){const a=typeof t=="string"?t:"";return cc[a]||a}const uc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"],cn=["input","output","cached","cacheCreate","reasoning"];function mc(t){let a=0;for(const r of cn)a+=Math.max(0,Number(t?.[r])||0);return a}function hc(t){return mc(t?.tokens)>0}function ds(t,a){for(const r of uc)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 us(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,total_cost_usd:"0"}}function xc(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:us(),models:new Map},a.set(s,n)),ds(n.totals,r?.totals);for(const o of Array.isArray(r?.models)?r.models:[]){const i=o?.model_id||o?.model||"";if(!i)continue;let d=n.models.get(i);d||(d={...o,model:o?.model||i,model_id:i,totals:us()},n.models.set(i,d)),ds(d.totals,o?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function gc(t,{copyFn:a}={}){const r=typeof a=="function"?a:i=>i,n=xc(Array.isArray(t?.sources)?t.sources:[]).map(i=>{const d=St(i?.totals),u=ee(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(d)?d:0,totalCost:Number.isFinite(u)?u:0,inputTokens:Math.max(0,ee(i?.totals?.input_tokens)??0),cacheRead:Math.max(0,ee(i?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,ee(i?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!n.length)return[];const o=n.reduce((i,d)=>i+d.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((i,d)=>d.totalTokens-i.totalTokens).map(i=>{const d=i.source?String(i.source).toUpperCase():r("shared.placeholder.short"),u=o>0?i.totalTokens/o*100:0,m=Number.isFinite(u)?u.toFixed(2):"0.00",x=i.models.map(p=>{const b=St(p?.totals);if(!Number.isFinite(b)||b<=0)return null;const k=i.totalTokens>0?Math.round(b/i.totalTokens*1e3)/10:0,j=nn(p,r("shared.placeholder.short")),_=lc(p),S=ee(p?.totals?.total_cost_usd),C=S??(i.totalCost>0&&i.totalTokens>0?b/i.totalTokens*i.totalCost:null),D=p?.totals||{};return{id:_,name:j,share:k,usage:b,cost:C,tokens:{input:Math.max(0,ee(D?.input_tokens)??0),output:Math.max(0,ee(D?.output_tokens)??0),cached:Math.max(0,ee(D?.cached_input_tokens)??0),cacheCreate:Math.max(0,ee(D?.cache_creation_input_tokens)??0),reasoning:Math.max(0,ee(D?.reasoning_output_tokens)??0)},pricing:p?.pricing||null,costSource:p?.cost_source||null}}).filter(Boolean),f=i.inputTokens+i.cacheRead+i.cacheCreate,g=i.cacheRead+i.cacheCreate>0&&f>0?Math.round(i.cacheRead/f*100):null;return{source:i.source,label:d,totalPercent:String(m),totalPercentValue:u,usd:i.totalCost,usage:i.totalTokens,cacheHitRate:g,cacheReusedTokens:i.cacheRead,cacheInputTokens:f,models:x}})}function fc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const i of a){const d=Array.isArray(i?.models)?i.models:[];for(const u of d){const m=ee(u?.usage);if(m==null||m<=0)continue;const x=typeof u?.name=="string"&&u.name.trim()?u.name.trim():typeof u?.id=="string"&&u.id.trim()?u.id.trim():null;x&&s.push({model:u,name:x,usage:m})}}const n=on(s.map(i=>({name:i.name,weight:i.usage})));for(const{model:i,name:d,usage:u}of s){const m=ln(d,n);if(!m)continue;const{key:x}=m,f=r.get(x)||{id:x,name:m.name,usage:0,cost:0,hasCost:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0}};f.usage+=u;const h=i?.tokens||{};for(const p of cn)f.tokens[p]+=Math.max(0,Number(h[p])||0);const g=ee(i?.cost);g!=null&&(f.cost+=g,f.hasCost=!0),n.has(x)?f.name=n.get(x):u>=f.nameWeight&&(f.name=d,f.nameWeight=u),r.set(x,f)}const o=Array.from(r.values()).reduce((i,d)=>i+d.usage,0);return Array.from(r.values()).map(i=>({id:i.id,name:i.name,usage:i.usage,cost:i.hasCost?i.cost:null,tokens:{...i.tokens},share:o>0?Math.round(i.usage/o*1e3)/10:0})).sort((i,d)=>d.usage!==i.usage?d.usage-i.usage:String(i.name).localeCompare(String(d.name)))}function pc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:p=>p,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const o=new Map,i=new Map,d=new Map,u=[];let m=0;for(const p of n){const b=Array.isArray(p?.models)?p.models:[];for(const k of b){const j=St(k?.totals);if(!Number.isFinite(j)||j<=0)continue;m+=j;const _=nn(k,s("shared.placeholder.short"));u.push({name:_,tokens:j})}}const x=on(u.map(p=>({name:p.name,weight:p.tokens})));for(const{name:p,tokens:b}of u){const k=ln(p,x);if(!k)continue;const{key:j}=k;o.set(j,(o.get(j)||0)+b),x.has(j)?i.set(j,x.get(j)):b>=(d.get(j)||0)&&(d.set(j,b),i.set(j,p))}if(!o.size)return[];const f=Array.from(o.values()).reduce((p,b)=>p+b,0),h=m>0?m:f,g=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(o.entries()).map(([p,b])=>{const k=h>0?(b/h*100).toFixed(1):"0.0";return{id:p,name:i.get(p)||s("shared.placeholder.short"),tokens:b,percent:String(k)}}).sort((p,b)=>b.tokens!==p.tokens?b.tokens-p.tokens:String(p.name).localeCompare(String(b.name))).slice(0,g)}function yc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Yt(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function ms(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Wt(a);return(a===Us?t:t*r)<.01?`<${s}0.01`:Yt(t,{decimals:2,currency:a,rate:r})}function hs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const bc=vt.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:o}=ja(),i=c.useMemo(()=>(Array.isArray(s)?s:[]).map(m=>{const x=ee(m?.usd)??0,f=ee(m?.usage)??0,h=Array.isArray(m?.models)?m.models:[];return{label:m?.label?String(m.label):"",usdValue:x,costLabel:ms(x,n,o),tokensLabel:hs(f),models:h.map(g=>{const p=ee(g?.usage)??0,b=ee(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:hs(p),costLabel:ms(b,n,o),sortCost:b,pricing:g?.pricing,costSource:g?.costSource,tokens:g?.tokens}}).filter(g=>g.costLabel||g.tokensLabel).sort((g,p)=>p.sortCost-g.sortCost)}}).filter(m=>m.usdValue>0||m.models.length>0).sort((m,x)=>x.usdValue-m.usdValue),[s,n,o]),d=i.some(m=>m.models.some(x=>x.costSource!=="provider_reported"&&x.pricing?.status==="unpriced")),u=c.useMemo(()=>{const m=i.reduce((x,f)=>x+f.usdValue,0);return d&&m===0?l("dashboard.cost_breakdown.unpriced_label"):`${d?"≥":""}${yc(m,n,o)}`},[i,n,o,d]);return e.jsx(qi,{open:a,onOpenChange:m=>{m||r?.()},children:e.jsxs(Gi,{children:[e.jsx(Yi,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(Zi,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(Ji,{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(Qi,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(Xi,{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(wr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:d?l("dashboard.cost_breakdown.known_subtotal"):l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:u}),e.jsx("p",{className:"mb-4 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.method")}),i.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),i.map((m,x)=>{const f=`fleet-${x}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":f,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:f,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:m.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:m.costLabel||"—"})]}),m.models.map((h,g)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:h.name,children:h.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:h.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):h.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),h.pricing?.status==="unpriced"&&h.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,h.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,h.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(h.tokens.input)||0),output:Ie(Number(h.tokens.output)||0),read:Ie(Number(h.tokens.cached)||0),write:Ie(Number(h.tokens.cacheCreate)||0)})}):null,h.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:h.pricing.input,output:h.pricing.output,read:h.pricing.cache_read,write:h.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:h.costLabel||(h.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):h.pricing?.status==="free"?Yt(0,{currency:n,rate:o}):l("dashboard.cost_breakdown.rate_unknown"))})]},h.id||`${h.name}-${g}`))]},`${m.label}-${x}`)})]})]})})]})})]})})});function kc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[o,i]=c.useState(null),[d,u]=c.useState(!1),[m,x]=c.useState(null),f=ht(),h=st([t,a,r,s,n,f]);return c.useEffect(()=>{const g=h();if(!t){i(null),x(null),u(!1);return}u(!0),i(null),x(null),ri({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(p=>{g()&&i(p||null)}).catch(p=>{g()&&(x(p?.message||String(p)),i(null))}).finally(()=>{g()&&u(!1)})},[t,a,r,s,n,f,h]),{data:o,loading:d,error:m}}function dn(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 un(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function mn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function hn(t,a){return a&&mn(un(t))==="github"?a:""}function xn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=c.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const xs="#10b981",Qa=[{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"}],Xa=60;function _c(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(h=>[h.day,h]));let o=a||t[0].day,i=r||t[t.length-1].day;o>i&&([o,i]=[i,o]),s&&i>s&&(i=s);const d=t[t.length-1].day;i<d&&(i=d);const u=new Date(`${o}T00:00:00Z`),m=new Date(`${i}T00:00:00Z`);if(!Number.isFinite(u.getTime())||!Number.isFinite(m.getTime()))return t;const x=Math.round((m.getTime()-u.getTime())/864e5)+1;x>Xa&&u.setUTCDate(u.getUTCDate()+(x-Xa));const f=[];for(;u.getTime()<=m.getTime()&&f.length<Xa;){const h=u.toISOString().slice(0,10);f.push(n.get(h)||{day:h,total_tokens:0,billable_total_tokens:0}),u.setUTCDate(u.getUTCDate()+1)}return f}function er(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function wt({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 wc({host:t}){if(!t)return null;let a;const r=mn(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(gl,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function tr({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]=vt.useState(!1),o=typeof t?.project_key=="string"?t.project_key:"",{owner:i,repo:d}=dn(o),u=typeof t?.project_ref=="string"?t.project_ref:"",m=un(u),{data:x,loading:f,error:h}=kc({projectKey:o,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:g,formatTokensTooltip:p}=Se(),b=vt.useCallback(()=>n(!0),[]),k=R=>{R.target===R.currentTarget&&s&&r()};vt.useEffect(()=>{const R=B=>{B.key==="Escape"&&b()};return window.addEventListener("keydown",R),()=>window.removeEventListener("keydown",R)},[b]);const j=x?.totals||null,_=ee(j?.billable_total_tokens)??0,S=Number(x?.days_active||0),C=ee(j?.input_tokens)??0,D=ee(j?.cached_input_tokens)??0,M=C+D>0?D/(C+D):null,z=ee(x?.range_total_tokens)??0,N=ee(j?.total_tokens)??0,v=z>0?N/z:null,T=vt.useMemo(()=>_c(x?.daily,x?.from,x?.to,_r({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[x,a.timeZone,a.tzOffsetMinutes]),F=Qa.reduce((R,B)=>R+(ee(j?.[B.key])??0),0),O=Array.isArray(x?.sources)?x.sources:[],$=!f&&!h&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:R=>{R.target===R.currentTarget&&b()},className:Nt("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":o,className:Nt("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:b,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(wr,{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:xs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:xs}})]}),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(xn,{githubOwner:hn(u,i),letter:(d?.[0]||o?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[i?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[i,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:d||o||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(wc,{host:m}),m&&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]})]}),$?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(wt,{label:l("dashboard.projects.detail.stat_total"),value:g(_),title:p(_)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_share"),value:v==null?"—":er(v)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:M==null?"—":er(M)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_conversations"),value:_a(j.conversation_count)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_active_days"),value:_a(S)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_avg_day"),value:S>0?g(Math.round(_/S)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[f&&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"})]}),!f&&h&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!f&&!h&&!$&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.empty_range")}),$&&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(tr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(Vs,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),F>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(tr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:Qa.map(R=>{const B=ee(j[R.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/F*100}%`,backgroundColor:R.color,minWidth:"2px"}},R.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:Qa.map(R=>{const B=ee(j[R.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:R.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(R.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:p(B),children:g(B)})]},R.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(tr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(R=>{const B=Number(R.total_tokens||0),K=N>0?B/N:0,G=K*100,w=Number(R.conversation_count||0),P=Mi(R.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Ct,{provider:R.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:jt(R.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(R.days_active||0)}),w>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:w})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:p(B),children:g(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:er(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(G,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:P}})})]},R.source)})})]})]})]})]})})}function jc(t){return e.jsx(si,{mode:Kt.COMPACT,children:e.jsx(vc,{...t})})}const Nc=5;function Sc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:o}){const i=typeof t?.project_key=="string"?t.project_key:"",d=typeof t?.project_ref=="string"?t.project_ref:"",{owner:u,repo:m}=dn(i),x=hn(d,u),f=ee(t?.billable_total_tokens??t?.total_tokens)??0,h=a>0?Math.min(100,Math.max(2,f/a*100)):0,g=Array.isArray(t?.sources)?t.sources:[],p=g.slice(0,Nc),b=g.length-p.length;return e.jsxs("button",{type:"button",onClick:()=>o?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(xn,{githubOwner:x,letter:(m?.[0]||i?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[u?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[u,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:m||i||"—"})]}),p.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[p.map(k=>e.jsx(Ct,{provider:k.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},k.source)),b>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:b})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(f),children:s(f)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${h}%`,minWidth:f>0?"3px":0}})})]})]})}function Cc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:o,dailyEmptyPrefix:i,installSyncCmd:d,dailyEmptySuffix:u,detailsColumns:m,ariaSortFor:x,toggleSort:f,sortIconFor:h,pagedDetails:g,dailyBreakdownRows:p=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:_="day",detailsDateKey:S,renderDetailDate:C,renderDailyBreakdownDate:D,renderDetailCell:M,DETAILS_PAGED_PERIODS:z,period:N,detailsPageCount:v,detailsPage:T,setDetailsPage:F}){const[O,$]=c.useState("daily"),[R,B]=c.useState(null),{formatTokens:K,formatTokensTooltip:G}=Se();return e.jsxs(Te,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":O==="daily",type:"button",onClick:()=>$("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":O==="projects",type:"button",onClick:()=>$("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),O==="projects"&&e.jsx(qs,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:w=>r?.(Number(w)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),O==="projects"&&(()=>{const w=t.slice(0,a);if(w.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 P=w.reduce((H,te)=>{const ue=ee(te?.billable_total_tokens??te?.total_tokens)??0;return ue>H?ue:H},0);return e.jsx("div",{className:"space-y-1",children:w.map((H,te)=>e.jsx(Sc,{entry:H,maxTokens:P,copy:n,formatTokens:K,formatTokensTooltip:G,onSelect:B},H?.project_key||H?.project_ref||`entry-${te}`))})})(),R&&e.jsx(jc,{entry:R,query:s,onClose:()=>B(null)}),O==="daily"&&e.jsxs("div",{children:[p?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[i,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:d}),u]}):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(w=>e.jsx("th",{"aria-sort":k?.(w.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>f(w.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:w.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(w.key)||""})]})})},w.key))})}),e.jsx("tbody",{children:p.map(w=>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 ${w.missing?"text-oai-gray-400 dark:text-oai-gray-400":w.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:D?D(w):C(w)}),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:M(w,"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:M(w,"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:M(w,"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:M(w,"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:M(w,"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:M(w,"conversation_count")})]},String(w?.[_]||w?.day||w?.hour||w?.month||"")))})]})}),O!=="daily"&&z.has(N)&&v>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>F(w=>Math.max(0,w-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," / ",v]}),e.jsx("button",{type:"button",onClick:()=>F(w=>Math.min(v-1,w+1)),disabled:T+1>=v,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function ka(t){return typeof t!="string"?"":t.trim()}function gs(t){const a=ka(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Tc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=ka(r.tool),n=ka(r.planType)||ka(r.plan_type);if(!s||!n)continue;const o=gs(s)||s,i=gs(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:o,plan:i})}return Array.from(a.values())}function Ac({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:o=[],className:i=""}){const{formatTokensTooltip:d}=Se(),u=l("shared.placeholder.short"),m=l("shared.unit.percent"),x=t??l("identity_card.rank_placeholder"),f=Number.isFinite(Number(a))?Number(a):0,h=f?l("identity_card.streak_value",{days:f}):l("identity_card.rank_placeholder"),g=Tc(r),p={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=_=>{if(_==null)return u;const S=Ie(_,p);return S==="-"?u:S},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=o.slice(0,3);return e.jsxs(Te,{className:`h-full ${i}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:d(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),j.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:j.map((_,S)=>{const C=_?.name?String(_.name):u,D=_?.percent?String(_.percent):"",M=S===j.length-1,z=S+1;return e.jsxs("div",{className:`flex items-center py-2 ${M?"":"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:z}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:C,children:C}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[D,m]})]},_.id||C)})}),g.length>0&&e.jsx("div",{className:"mt-3 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex flex-wrap gap-1.5",children:g.map((_,S)=>e.jsxs(vl,{variant:"secondary",size:"sm",children:[_.tool," ",_.plan]},`${_.tool}:${_.plan}:${S}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children: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:h})]})]})]})}let fa=null;function Dc(){if(fa===null)try{fa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{fa=!1}return fa}function Mc(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),o=a*Math.sin(s),i=t+.3963377774*n+.2158037573*o,d=t-.1055613458*n-.0638541728*o,u=t-.0894841775*n-1.291485548*o,m=i*i*i,x=d*d*d,f=u*u*u;return[4.0767416621*m-3.3077115913*x+.2309699292*f,-1.2684380046*m+2.6097574011*x-.3413193965*f,-.0041960863*m-.7034186147*x+1.707614701*f].map(g=>{const p=Math.min(1,Math.max(0,g)),b=p<=.0031308?12.92*p:1.055*Math.pow(p,1/2.4)-.055;return Math.round(b*255)})}function gn(t,a,r,s){if(Dc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,o,i]=Mc(t,a,r);return s==null?`rgb(${n} ${o} ${i})`:`rgb(${n} ${o} ${i} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?gn(Number(a[1]),Number(a[2]),Number(a[3])):t}const fs={claude:35,codex:250,grok:200},ps={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 Lc(t,a){const r=fs[a]??fs.claude,s=ps[t]||ps.system_prompt;return gn(s.l,s.c,r)}const Ec=[{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"]}],Rc=[["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"]],Ic={duration:.18,ease:[.4,0,.2,1]},Fc={height:0,opacity:0},$c={height:"auto",opacity:1},Pc={height:0,opacity:0};function zc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function Bc(t,a){const r={};for(const s of["input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens","total_tokens"])r[s]=Math.round(Number(t?.[s]||0)*a);return r}function fn(t,a=null){const r=t.reduce((i,d)=>i+Number(d.totals.total_tokens||0),0),s=zc(a),n=s||r,o=s&&r>0?s/r:1;return t.map(i=>{const d=o===1?i.totals:Bc(i.totals,o);return{...i,totals:d,percent:n>0?Number((d.total_tokens/n*100).toFixed(2)):0}}).sort((i,d)=>d.totals.total_tokens-i.totals.total_tokens)}function Oc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=Ec.map(n=>{const o={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const i of n.from){const d=r.get(i);if(!d)continue;const u=d.totals||{};o.input_tokens+=u.input_tokens||0,o.cached_input_tokens+=u.cached_input_tokens||0,o.cache_creation_input_tokens+=u.cache_creation_input_tokens||0,o.output_tokens+=u.output_tokens||0,o.reasoning_output_tokens+=u.reasoning_output_tokens||0,o.total_tokens+=u.total_tokens||0}return{key:n.key,totals:o}});return fn(s,a)}function Uc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((m,x)=>x?.name==="Text Response"?m:m+Number(x?.totals?.total_tokens||0),0),o=Number(r.total_tokens||0),i=Math.min(Math.max(0,n),Math.max(0,o-s)),u=[{key:"messages",totals:{total_tokens:Math.max(0,o-s-i)}},{key:"tool_calls",totals:{total_tokens:i}},{key:"reasoning",totals:{total_tokens:s}}];return fn(u,a)}const ys="MCP: ";function Hc(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const o=String(n?.name||"");o.startsWith(ys)?(a.push({...n,name:o.slice(ys.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,o)=>(o.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function bs(t){return l(`dashboard.context_breakdown.category.${t}`)}function Kc(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function Vc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),o=Number(r?r.cached_input_tokens||0:a?.cache_read||0),i=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),d=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:Kc(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:o,cache_creation:i,total_tokens:Number(d||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function Wc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),o=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),d=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:o,cached_input_tokens:i,cache_creation_input_tokens:d,total_tokens:Number(r.total_tokens||n+o)},tools:Vc(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function qc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:o,cache_creation_input_tokens:i,total_tokens:Number(r.total_tokens||s+n+o+i)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Gc(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 Yc(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 Zc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),i=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:o,cache_creation_input_tokens:i,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function ks(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 Jc(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 _s(t){return t==="exec_command"||t==="Bash"}function pn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function Qc(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function Xc(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const ed=10;function Xe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:o=!1,open:i=!1,onToggle:d,tokens:u,percent:m=null,children:x,share:f=null,fillColor:h=null}){const g=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",p=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:ed},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[p,e.jsx("span",{className:g,children:r}),s,o&&e.jsx(Ke.span,{animate:{rotate:i?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(oi,{size:11})})]}),k=h&&f!=null&&f>0,j=k?Math.max(0,Math.min(100,f)):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, ${h.replace(/\)\s*$/," / 0.10)")} 0%, ${h.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[o?e.jsx("button",{type:"button",onClick:d,"aria-expanded":i,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:b}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:b}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:u||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:m||""})]}),o&&x?e.jsx(Qs,{initial:!1,children:i&&e.jsx(Ke.div,{initial:Fc,animate:$c,exit:Pc,transition:Ic,style:{overflow:"hidden"},children:x},"content")}):null]})}function ws({execDetails:t,source:a="claude"}){const{formatTokens:r}=Se(),[s,n]=c.useState("by_type"),o=Zc(Jc(t,s)),i=a==="codex"||a==="grok",d=i?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:Rc.map(([u,m])=>e.jsx("button",{type:"button",onClick:()=>n(u),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===u?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(m)},u))}),o.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:i?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${d} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),i&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),o.map((u,m)=>e.jsxs(Ke.div,{role:"row",className:`grid ${d} gap-2 py-1.5`,title:u.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:m*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:u.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(u.calls||0)}),i&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(u.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:ks(u.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:ks(u.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(u.totals.total_tokens||0)}),i&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(u.output_lines||0)})]},u.name))]})})]})}function Ut({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Se(),[o,i]=c.useState({}),[d,u]=c.useState(!1),m=Wc(t?.categories||[]);function x(f){i(h=>({...h,[f]:!h[f]}))}return m.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(pn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:m.map(f=>{const h=f.toolCount>0,g=f.name==="Execution"&&a,p=g&&f.tools.some(k=>_s(k.name)),b=!!o[f.name];return e.jsxs(Xe,{level:1,label:f.name,labelTone:"strong",hasChevron:h||g&&!p,open:b||g&&!p&&d,onToggle:()=>{h?x(f.name):g&&!p&&u(k=>!k)},tokens:n(f.totals.total_tokens||0),percent:null,children:[h&&e.jsx("ul",{className:"space-y-0.5",children:f.tools.map(k=>{const j=g&&_s(k.name);return e.jsx(Xe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:d,onToggle:()=>u(_=>!_),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(ws,{execDetails:a,source:r})},k.name)})}),g&&!p&&e.jsx(ws,{execDetails:a,source:r})]},f.name)})})}function td({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:o}=Se(),[i,d]=c.useState(null),[u,m]=c.useState(!1),[x,f]=c.useState(null),[h,g]=c.useState({}),p=c.useRef({});function b(w){g(P=>({...P,[w]:!P[w]}))}if(c.useEffect(()=>{let w=!1;const P=`${t||""}|${a||""}|${r||"claude"}`,H=p.current[P];return d(H||null),m(!0),n?.(!0),f(null),ni({from:t,to:a,source:r,timeZone:Ks(),tzOffsetMinutes:Hs()}).then(te=>{w||(p.current[P]=te,d(te))}).catch(te=>{w||f(te?.message||String(te))}).finally(()=>{w||(m(!1),n?.(!1))}),()=>{w=!0}},[t,a,r]),u&&!i)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(w=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${w*80}ms`}},w))}),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(x)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(Qc(r))});if(!i||i.scope!=="supported"||!i.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(pn(r))});const k=r==="claude"?Oc(i.categories||[],s):Uc(i,s),j=i.tool_calls_breakdown||null,_=i.skills_breakdown||null,S=i.message_breakdown||null,C=i.configured_resources||null,D=i.exec_command_breakdown||null,M=Gc(_?.skills||[]),z=qc(S?.categories||[]),N=r==="codex"&&(i?.breakdown_status==="queue_fallback"||i?.fallback==="queue_totals"),v=r==="claude"?j?.tool_calls||null:j||null,{mcpSet:T,residualSet:F,mcpTotalTokens:O}=Hc(v),$=r==="claude"&&j?.subagents||null,R=$?.categories?.length>0||(C?.custom_agents_count||0)>0,B=r==="claude"?(F?.categories||[]).reduce((w,P)=>w+Number(P?.totals?.total_tokens||0),0):0,K=r==="claude"?($?.categories||[]).reduce((w,P)=>w+Number(P?.totals?.total_tokens||0),0):0,G=[...k].sort((w,P)=>(P.totals?.total_tokens||0)-(w.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:k.filter(w=>w.percent>0).filter(w=>!(r==="claude"&&(w.key==="tool_calls"||w.key==="custom_agents"))).map(w=>`${bs(w.key)} ${w.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[G.map(w=>{const P=w.key==="system_prompt",H=w.key==="messages",te=w.key==="tool_calls",ue=w.key==="custom_agents";if(w.key,r==="claude"&&(te||ue))return null;const W=H&&z.length>0||te&&(F?.categories?.length>0||N)||ue&&R&&$,ne=!!h[w.key],le=Lc(w.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:le},"aria-hidden":"true"}),ye=P?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(Js,{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,Ae=w.percent>0?`${w.percent.toFixed(w.percent<.1&&w.percent>0?2:1)}%`:"0.0%";return e.jsxs(Xe,{level:0,colorSquare:je,label:bs(w.key),labelSuffix:ye,tokens:o(w.totals?.total_tokens||0),percent:Ae,hasChevron:W,open:ne,onToggle:()=>b(w.key),share:w.percent,fillColor:le,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:z.map(J=>e.jsx(Xe,{level:1,label:Yc(J),tokens:o(J.totals.total_tokens||0),percent:null},J.key||J.name))}),te&&F&&e.jsx(Ut,{toolSet:F,execDetails:D,source:r,codexQueueFallback:N}),te&&N&&!F&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),ue&&$&&e.jsx(Ut,{toolSet:$,execDetails:null,source:r,codexQueueFallback:!1})]},w.key)}),r==="claude"&&F?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(B),percent:null,hasChevron:!0,open:!!h.tool_calls_aux,onToggle:()=>b("tool_calls_aux"),children:e.jsx(Ut,{toolSet:F,execDetails:D,source:r,codexQueueFallback:!1})}),r==="claude"&&$?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(K),percent:null,hasChevron:!0,open:!!h.custom_agents_aux,onToggle:()=>b("custom_agents_aux"),children:e.jsx(Ut,{toolSet:$,execDetails:null,source:r,codexQueueFallback:!1})}),T?.categories?.length>0&&e.jsx(Xe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(O),percent:null,hasChevron:!0,open:!!h.mcp_servers,onToggle:()=>b("mcp_servers"),children:e.jsx(Ut,{toolSet:T,execDetails:null,source:r,codexQueueFallback:!1})}),M.length>0&&e.jsx(Xe,{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(M.reduce((w,P)=>w+(P.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!h.skills,onToggle:()=>b("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:M.slice(0,12).map(w=>e.jsx(Xe,{level:1,label:w.name,tokens:o(w.total_tokens),percent:null},w.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(Xc(r))}),N?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,C?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(C.skills_count||0)," skills ·"," ",Ie(C.mcp_servers_count||0)," MCP servers ·"," ",Ie(C.custom_agents_count||0)," agents ·"," ",Ie(C.memory_files_count||0)," memory files"]}):null]})}function yn({size:t=15,className:a=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:a,"aria-hidden":"true",children:[e.jsx("path",{d:"M12 1.6 23 7.4 12 13.2 1 7.4 12 1.6Z"}),e.jsx("path",{d:"m4 10.3-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.72"}),e.jsx("path",{d:"m4 14.6-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.45"})]})}const it="__all__",ad=`${100 .toFixed(2)}%`;function qt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function hr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Wt(a);return(a===Us?s:s*r)<.01?`<${n}0.01`:Yt(s,{decimals:2,currency:a,rate:r})}function rd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:vs(a)}:{key:a.key,label:a.label||vs(a.key)}):[]}function sd(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 nd={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 ar(t,a){const r=t?.toUpperCase?.()||"";return nd[r]||`hsl(${150+a*40}, 60%, 45%)`}function od(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 id(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 ld(t){return!!t?.models?.length}function bn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function rr(t){const a=bn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const cd={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function vs(t){const a=cd[t];return a?l(a):String(t).toUpperCase()}function dd({loading:t,onClick:a}){const r=Gs();return e.jsx(li,{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(ci,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function ud(){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 md(){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 hd({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:o,summaryLabel:i,summaryCostValue:d,onCostInfo:u,fleetData:m=[],onRefresh:x,loading:f,announceLoading:h=!1,summaryLoading:g=!1,providersLoading:p=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:_,onCustomRangeApply:S,customRangeOpen:C,onCustomRangeOpenChange:D,onOpenShare:M,from:z,to:N,deviceOptions:v=[],selectedDevice:T="",onDeviceChange:F}){const O=rd(a),$=tl(di()),R=sd(String(s??"")),B=t==="week"&&typeof z=="string"&&typeof N=="string"&&z.slice(0,7)!==N.slice(0,7),K=t!=="day"&&z&&N?`${xa(z,$)} — ${xa(N,$)}`:null,G=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[w,P]=c.useState(G);c.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const A=window.matchMedia("(max-width: 639px)"),L=re=>P(re.matches);return A.addEventListener("change",L),()=>A.removeEventListener("change",L)},[]);const H=R!=null&&!w,te=c.useRef(null);c.useEffect(()=>{const A=te.current?.querySelector('[aria-selected="true"]');A&&typeof A.scrollIntoView=="function"&&A.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,W]=c.useState(null),{resolvedTheme:ne}=ii(),{currency:le,rate:je}=ja(),{formatTokens:ye}=Se(),Ae=ne==="dark",J=Ae?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Ae?"rgba(10,10,10,0)":"rgba(255,255,255,0)",oe=g&&!b,X=p&&!m.some(ld);c.useEffect(()=>{W(null)},[t,z,N,T]);const ae=A=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(A.key))return;const L=Array.from(A.currentTarget.querySelectorAll('[role="tab"]')).filter(ie=>!ie.disabled),re=L.indexOf(A.target.closest('[role="tab"]'));if(re===-1||L.length===0)return;A.preventDefault();let se=re;A.key==="Home"?se=0:A.key==="End"?se=L.length-1:A.key==="ArrowRight"?se=(re+1)%L.length:se=(re-1+L.length)%L.length,L[se].focus(),L[se].click()},pe=H?e.jsx(Ml,{value:R,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Ae?0:8,gradientFrom:J,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,V=m.filter(A=>A.models?.length>0),Y=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="devin"),Q=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="kiro"),xe=V.some(A=>String(A?.source||A?.label||"").trim().toLowerCase()==="trae"),Ne=c.useMemo(()=>fc(m),[m]),Ce=Ne.reduce((A,L)=>A+(Number(L.usage)||0),0),De=V.reduce((A,L)=>A+(Number(L.usd)||0),0),ce=ue==null?null:ue===it||V.some(function(L){return L.label===ue})?ue:null;return e.jsx(Te,{className:k,children:e.jsxs("div",{"aria-busy":f||oe||X,children:[h?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:te,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:ae,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(A=>{const L=t===A.key,re=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${L?"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(A.key==="custom"){const se=L&&j&&_?`${xa(j,$)} — ${xa(_,$)}`:A.label;return e.jsxs(sl,{open:C,onOpenChange:ie=>{ie?r?.("custom"):D?.(ie)},children:[e.jsx(nl,{render:e.jsx("button",{role:"tab","aria-selected":L,tabIndex:L?0:-1,type:"button",className:re}),children:se}),e.jsx(ol,{children:e.jsx(il,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(ll,{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(el,{from:j,to:_,onApply:S,onCancel:()=>D?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":L,tabIndex:L?0:-1,type:"button",className:re,onClick:()=>r?.(A.key),children:A.label},A.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[v.length>1?e.jsx(qs,{value:T,onValueChange:F,options:v,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,M?e.jsxs("button",{type:"button",onClick:M,"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(pl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,x&&e.jsx(dd,{loading:f,onClick:x})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:i}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:oe?"invisible":void 0,children:o?e.jsx("button",{type:"button",onClick:o,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:pe}):e.jsx("span",{title:n||void 0,children:pe})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${oe?"":"hidden"}`,children:e.jsx(ud,{})})]}),d&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:u?e.jsxs("button",{type:"button",onClick:u,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[d,e.jsx(Js,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:d})}),xe&&e.jsxs("p",{className:"mx-auto mt-3 max-w-xl text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsxs("span",{className:"font-medium",children:[l("usage.overview.trae_notice_title"),"."]})," ",l("usage.overview.trae_notice_body")]}),K?e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-1 text-[11px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{className:"tabular-nums",children:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:X?void 0:"hidden",children:e.jsx(md,{})}),V.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:V.map(A=>l("usage.overview.distribution_item",{label:jt(A.label),percent:rr(A)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:V.map((A,L)=>{const re=ar(A.label,L),se=jt(A.label),ie=rr(A);return e.jsx(Ke.div,{initial:{width:0},animate:{width:`${bn(A)}%`},transition:{duration:.5,delay:.45+L*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:re},title:`${se}: ${ie}%`},A.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":ce===it,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:qt(ye,Ce)||String(0),cost:hr(De,le,je)||`${Wt(le)}0`,count:Ne.length}),onClick:()=>W(ce===it?null:it),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${ce===it?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(yn,{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:ad}),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:Ne.length})})]}),V.map((A,L)=>{const re=ar(A.label,L),se=ce===A.label,ie=jt(A.label),Ve=rr(A);return e.jsxs("button",{"aria-expanded":se,"aria-controls":`provider-details-${A.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:ie,percent:Ve,tokens:qt(ye,A.usage)||String(0),cost:hr(A.usd,le,je)||`${Wt(le)}0`,action:l(se?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>W(se?null:A.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${se?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(Ct,{provider:A.label,size:15,color:re,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:ie,children:ie})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[Ve,"%"]}),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:A.models.length})})]},A.label)})]}),ce===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Y&&e.jsx(_n,{}),Q&&e.jsx(wn,{}),e.jsx(pd,{models:Ne})]}),ce!=null&&ce!==it&&e.jsx("div",{id:`provider-details-${ce}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:ce}),className:"mt-2",children:V.filter(A=>A.label===ce).map(A=>{const L=ar(A.label,0),re=od(A),se=[...A.models].sort((Ve,me)=>(me.share||0)-(Ve.share||0)),ie=re?id(re):jt(A.label);return e.jsx(yd,{provider:A,color:L,providerHeading:ie,contextSource:re,from:z,to:N,sortedModels:se},A.label)})})]})]})})}const xd=[{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"}],gd="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 fd({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Se();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:xd.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 js({model:t,tokensLabel:a,costLabel:r,expandable:s,isExpanded:n}){const{formatTokensTooltip:o}=Se();return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:t.name,children:t.name}),e.jsx("span",{title:o(t.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:a}),e.jsx("span",{className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",s&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(n?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(rl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${n?"rotate-180":""}`})]})]})]})}function kn({models:t,color:a}){const{currency:r,rate:s}=ja(),{formatTokens:n}=Se(),[o,i]=c.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(d=>{const u=qt(n,d.usage),m=hr(d.cost,r,s),x=Math.max(0,Math.min(100,Number(d.share)||0)),f=d.id||d.name,h=hc(d),g=h&&o===f,p=gd,b={model:d,tokensLabel:u,costLabel:m,expandable:h,isExpanded:g};return e.jsxs("div",{"data-model-rank-row":!0,children:[h?e.jsx("button",{type:"button",onClick:()=>i(g?null:f),"aria-expanded":g,className:`${p} w-full cursor-pointer text-left`,children:e.jsx(js,{...b})}):e.jsx("div",{className:p,children:e.jsx(js,{...b})}),g&&e.jsx(fd,{tokens:d.tokens}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":x,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${x}%`,backgroundColor:a,opacity:.45}})})]},f)})})}function pd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(yn,{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(kn,{models:t,color:"var(--oai-blue)"})]})}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.devin_notice_title"),"."]})," ",l("usage.overview.devin_notice_body")]})}function wn(){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 yd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:o,sortedModels:i}){const{formatTokens:d}=Se(),[u,m]=c.useState(!1),x=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",f=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",h=String(t?.source||t?.label||"").trim().toLowerCase()==="kiro";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Ct,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&u&&e.jsx(al,{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:qt(d,t.cacheReusedTokens)||String(0),input:qt(d,t.cacheInputTokens)||String(0)})]}),x&&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")]}),f&&e.jsx(_n,{}),h&&e.jsx(wn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(td,{from:n,to:o,source:s,referenceTotalTokens:t.usage,onLoadingChange:m})}):null,e.jsx(kn,{models:i,color:a})]})}function bd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:o,transform:i,transition:d,isDragging:u}=Pi({id:t}),m=c.useRef(null),x=c.useRef(null);c.useLayoutEffect(()=>{if(!r)return;const h=m.current?m.current.childNodes.length===0:!0;x.current!==h&&(x.current=h,r(t,h))});const f={transform:zi.Transform.toString(i)||void 0,transition:d,zIndex:u?20:void 0};return e.jsxs("div",{ref:o,style:f,className:Nt("group/sortable relative has-[[data-sortable-body]:empty]:hidden",u&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:Nt("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",u&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:m,"data-sortable-body":!0,className:Nt("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",u&&"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 kd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[o,i]=c.useState(null),[d,u]=c.useState(!1),[m,x]=c.useState(null),f=st([t,a,r,s,n]),h=c.useCallback(async()=>{if(!t)return;const g=f();u(!0),x(null);try{const p=await Be(s);if(!g())return;const b=await ui({from:a,to:r,device:n,accessToken:p});if(!g())return;i(b||null)}catch(p){if(!g())return;x(p?.message||String(p)),i(null)}finally{g()&&u(!1)}},[t,a,r,s,n,f]);return c.useEffect(()=>{if(!t){i(null),x(null),u(!1);return}i(null),x(null),u(!0),h()},[t,h]),{data:o,loading:d,error:m,refresh:h}}function vn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function jn(t){return t==null?"—":`${Math.round(t*100)}%`}function _d(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 wd({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:vn(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:jn(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:_d(t.cost_usd,t.accepted)})]})}function vd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Se(),{enabled:o}=cl(),{data:i,loading:d}=kd({enabled:o,from:t,to:a,deviceId:r});if(!o)return null;const u=(i&&i.available&&Array.isArray(i.by_model)?i.by_model:[]).filter(h=>h.outcomes>0&&h.key!=="unknown");if(!u.length)return null;const m=u.slice(0,6),x=i.totals||{},f=`${l("qpd.card.subtitle")}${d?` ${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:f}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:m.map(h=>e.jsx(wd,{row:h},h.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:x.accepted??0,outcomes:x.outcomes??0,cost:vn(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:jn(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 jd=new Set(["unknown","synthetic","openai"]);function sr(t){return t==null?"—":`${Math.round(t*100)}%`}function Nd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Qe(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function Sd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!jd.has(r)&&Number(t?.edit_turns||0)>0}function Ns(){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 Cd({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=c.useState({requestKey:null,loading:!0,sessions:null,context:null}),o=s.requestKey===r?s:{loading:!0,sessions:null,context:null},i=c.useId(),{enabled:d}=dl(),u=st([d,t,a]),{formatTokens:m}=Se(),x=S=>m(S,{mode:Kt.COMPACT});c.useEffect(()=>{const S=u();if(!d){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([mi({from:t,to:a}),hi()]).then(([C,D])=>{S()&&n({requestKey:r,loading:!1,sessions:C,context:D})}).catch(()=>{S()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[d,t,a,r,u]);const f=c.useMemo(()=>(o.sessions?.by_model||[]).filter(Sd).slice(0,5),[o.sessions]),h=c.useMemo(()=>(o.sessions?.subagents||[]).slice(0,3),[o.sessions]);if(!d||!o.loading&&!o.sessions?.available&&!o.context?.estimated_fixed_tokens)return null;const g=o.sessions?.summary||{},p=g.edit_session_rate??g.productive_rate,b=g.first_pass_rate??g.one_shot_rate,k=g.edit_sessions??g.productive_sessions??0,j=g.sessions??o.sessions?.session_count??0,_=g.edit_turns??0;return o.loading&&!o.sessions&&!o.context?e.jsxs(Te,{children:[e.jsx(Ns,{}),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(Ns,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(nr,{label:l("sessions.card.edit_sessions"),value:sr(p),detail:l("sessions.card.edit_session_value",{edits:Qe(k),sessions:Qe(j)})}),e.jsx(nr,{label:l("sessions.card.first_pass"),value:sr(b),detail:l("sessions.card.edit_session_value",{edits:Qe(g.first_pass_sessions??g.one_shot_sessions??0),sessions:Qe(k)})}),e.jsx(nr,{label:l("sessions.card.cost_edit"),value:Nd(g.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Qe(_)})})]}),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:Qe(j),edits:Qe(_)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":i,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:i,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!f.length&&e.jsx("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:f.map(S=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:S.model,children:S.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Qe(S.edit_sessions??S.productive_sessions??0),sessions:Qe(S.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:sr(S.first_pass_rate??S.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:x(S.tokens_per_edit)})]},S.model))})]})}),o.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:x(o.context.estimated_fixed_tokens)})]}):null,!!h.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")}),h.map(S=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:S.name,calls:Math.round(S.calls)})},S.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function nr({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 de({className:t}){return e.jsx("div",{className:Nt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Td(){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(de,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function Ad(){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(de,{className:"h-4 w-32"}),e.jsx(de,{className:"h-6 w-24"})]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{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(de,{className:"h-3 w-20"}),e.jsx(de,{className:"h-3 w-12"})]},a))]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{className:"h-3.5 w-20"}),e.jsx(Td,{})]})}),e.jsx(Te,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(de,{className:"h-3.5 w-28"}),e.jsx(de,{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(de,{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(de,{className:"h-8 w-20 rounded-md"}),e.jsx(de,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(de,{className:"h-3 w-28"}),e.jsx(de,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(de,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(de,{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(de,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(de,{className:"h-3 w-12"})]}),e.jsx(de,{className:"h-5 w-10"}),e.jsx(de,{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(de,{className:"h-7 w-16 rounded"}),e.jsx(de,{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(de,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(de,{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(de,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(de,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const Dd=hl.slice(0,10),Ss=.06,Md=.11,Ld=.05;function Cs({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:Dd,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 Ed(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:o,identityDisplayName:i,identityStartDate:d,activeDays:u,identitySubscriptions:m,identityScrambleDurationMs:x,projectUsageEntries:f,projectUsageLimit:h,setProjectUsageLimit:g,projectDetailQuery:p,topModels:b,signedIn:k,publicMode:j,isLocalMode:_,shouldShowInstall:S,installPrompt:C,handleCopyInstall:D,installCopied:M,installInitCmdDisplay:z,trendRowsForDisplay:N,trendFromForDisplay:v,trendToForDisplay:T,trendZoomConfig:F,usageFrom:O,usageTo:$,period:R,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:G,setSelectedPeriod:w,customFrom:P,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,summaryLabel:ne,summaryValue:le,summaryFullValue:je,hasSummary:ye,summaryLoading:Ae,providersLoading:J,onToggleSummaryFormat:U,summaryTotalTokensRaw:oe,summaryCostValue:X,summaryConversationsValue:ae,rollingUsage:pe,costInfoEnabled:V,openCostModal:Y,costModalOpen:Q,closeCostModal:xe,allowBreakdownToggle:Ne,refreshAll:Ce,usageLoadingState:De,announceUsageLoading:ce,initialDashboardLoading:A,fleetData:L,hasDetailsActual:re,dailyEmptyPrefix:se,installSyncCmd:ie,dailyEmptySuffix:Ve,detailsColumns:me,ariaSortFor:ge,toggleSort:Fe,sortIconFor:$e,pagedDetails:At,dailyBreakdownRows:xt,dailyBreakdownColumns:We,dailyBreakdownAriaSortFor:Na,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Sa,detailsDateKey:Ca,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:be,detailsPageCount:ke,detailsPage:ve,setDetailsPage:ft,deviceOptions:Dt,selectedDevice:Jt,onDeviceChange:Qt,deviceUsageBlock:Mt,leftCardOrder:Ta,onLeftReorder:qe,rightCardOrder:Xt,onRightReorder:nt}=t,Lt=null,Aa=null,Da={statsPanel:!0,installCopy:S,activityHeatmap:!!K,deviceUsage:!!Mt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:_&&!s},ea=(Ta||[]).filter(_e=>Da[_e]),Et={usageOverview:!0,dataDetails:!s},Ma=(Xt||[]).filter(_e=>Et[_e]);function Rt(_e,fe){switch(_e){case"statsPanel":return e.jsx(ot,{delay:fe,children:e.jsx(Ac,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:R,startDate:d??a("identity_card.rank_placeholder"),streakDays:u,subscriptions:m,periodConversations:ae,rolling:pe,topModels:b})});case"installCopy":return e.jsx(ot,{delay:fe,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:C}),e.jsxs(Ke.button,{onClick:D,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:z}),e.jsx(Ke.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:M?"Copied ✓":"Copy"},M?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:fe,children:K});case"deviceUsage":return e.jsx(ot,{delay:fe,children:Mt});case"trendMonitor":return e.jsx(ot,{delay:fe,children:e.jsx(Vs,{rows:N,from:v,to:T,period:R,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:F})});case"qualityPerDollar":return e.jsx(vd,{from:O,to:$,deviceId:Jt});case"sessionInsights":return e.jsx(Cd,{from:O,to:$});default:return null}}function It(_e,fe){switch(_e){case"usageOverview":return e.jsx(ot,{delay:fe,children:e.jsx(hd,{period:R,periods:G,onPeriodChange:w,summaryLabel:ne,summaryValue:le,summaryFullValue:je,hasSummary:ye,summaryLoading:Ae,providersLoading:J,onToggleSummaryFormat:ye?U:null,summaryCostValue:X,onCostInfo:V?Y:null,fleetData:L,onRefresh:s?null:Ce,loading:De,announceLoading:ce,onOpenShare:s?null:r,customFrom:P,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,from:O,to:$,deviceOptions:Dt,selectedDevice:Jt,onDeviceChange:Qt})});case"dataDetails":return e.jsx(ot,{delay:fe,children:e.jsx(Cc,{projectEntries:f,projectLimit:h,onProjectLimitChange:g,projectDetailQuery:p,copy:a,hasDetailsActual:re,dailyEmptyPrefix:se,installSyncCmd:ie,dailyEmptySuffix:Ve,detailsColumns:me,ariaSortFor:ge,toggleSort:Fe,sortIconFor:$e,pagedDetails:At,dailyBreakdownRows:xt,dailyBreakdownColumns:We,dailyBreakdownAriaSortFor:Na,dailyBreakdownSortIconFor:et,dailyBreakdownDateKey:Sa,detailsDateKey:Ca,renderDetailDate:gt,renderDailyBreakdownDate:Z,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:be,period:R,detailsPageCount:ke,detailsPage:ve,setDetailsPage:ft})});default:return null}}const La=Bi(ts(Wi,{activationConstraint:{distance:6}}),ts(Vi,{coordinateGetter:Ki})),Ye=c.useCallback(_e=>{const{active:fe,over:Pe}=_e;!Pe||fe.id===Pe.id||qe?.(String(fe.id),String(Pe.id))},[qe]),ta=c.useCallback(_e=>{const{active:fe,over:Pe}=_e;!Pe||fe.id===Pe.id||nt?.(String(fe.id),String(Pe.id))},[nt]);function Oe(_e,fe,Pe,aa){return s?e.jsx(e.Fragment,{children:_e.map((Ze,Ft)=>e.jsx(vt.Fragment,{children:fe(Ze,Pe+Ss*Ft)},Ze))}):e.jsx(Oi,{sensors:La,onDragEnd:aa,children:e.jsx(Ui,{items:_e,strategy:Hi,children:_e.map((Ze,Ft)=>e.jsx(bd,{id:Ze,children:fe(Ze,Pe+Ss*Ft)},Ze))})})}const he=Oe(ea,Rt,Md,Ye),Ea=Oe(Ma,It,Ld,ta);return e.jsxs(e.Fragment,{children:[e.jsxs(wl,{bare:!s,hideHeader:s,header:Lt,footer:s?null:Aa,className:s?"screenshot-mode":"",children:[o&&e.jsx(Cs,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(as,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Cs,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(as,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!o&&!n&&A&&e.jsx(Ad,{}),!o&&!n&&!A&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:he}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ea})]})})]}),e.jsx(bc,{isOpen:Q,onClose:xe,fleetData:L})]})}function Rd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:o=null,accountRevision:i=0}={}){const d=!!(n&&o),[u,m]=c.useState([]),[x,f]=c.useState([]),[h,g]=c.useState(!1),[p,b]=c.useState(null),k=st([d,t,a,r,s,o,i]),j=c.useCallback(async()=>{const _=k();if(!d){m([]),f([]),g(!1),b(null);return}g(!0),b(null);try{const S=await Be(o);if(!_())return;const C=await xi({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:S});if(!_())return;m(Array.isArray(C?.devices)?C.devices:[]),f(Array.isArray(C?.account_sources)?C.account_sources:[])}catch(S){if(!_())return;b(S?.message||String(S)),m([]),f([])}finally{_()&&g(!1)}},[d,o,t,a,r,s,i,k]);return c.useEffect(()=>{m([]),f([]),b(null),d&&g(!0),j()},[d,j]),{devices:u,accountSources:x,loading:h,error:p,refresh:j}}const Id=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Ts(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 xr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(Id);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Ts(t.platform)} · ${s}`:Ts(t.platform)}const As=" · ",Ds="%";function Ms({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(qr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(qr,{className:a,"aria-hidden":!0}):e.jsx(Xs,{className:a,"aria-hidden":!0})}function Ls(t,a){return a===t?.id||t?.isCurrent===!0}function Fd({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:o}){const{formatTokens:i,formatTokensTooltip:d}=Se(),[u,m]=c.useState(""),[x,f]=c.useState(""),[h,g]=c.useState(!1),[p,b]=c.useState(""),k=typeof o=="function",j=typeof n=="function",_=!!s,S=t.reduce((v,T)=>v+(Number(T.total_tokens)||0),0)+a.reduce((v,T)=>v+(Number(T.total_tokens)||0),0),C=c.useMemo(()=>t.filter(v=>(Number(v.total_tokens)||0)>0).sort((v,T)=>(Number(T.total_tokens)||0)-(Number(v.total_tokens)||0)),[t]);function D(v){b(""),m(v.id);const T=typeof v.device_name=="string"?v.device_name:"";f(xr(v)===T?T:"")}function M(){m(""),f(""),b("")}async function z(v){const T=x.trim();if(!(!T||h)){g(!0),b("");try{await o(v.id,T),m(""),f("")}catch{b(v.id)}finally{g(!1)}}}const N=a.filter(v=>(Number(v.total_tokens)||0)>0);return C.length===0&&N.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(Xs,{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")}),j&&_&&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:[C.map(v=>{const T=Number(v.total_tokens)||0,F=S>0?(T/S*100).toFixed(1):"0.0",O=s===v.id,$=xr(v)||l("dashboard.device_card.unnamed"),R=u===v.id,B=O?"bg-oai-brand":_?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=_&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[R?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(Ms,{platform:v.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:x,disabled:h,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:G=>f(G.target.value),onKeyDown:G=>{G.key==="Enter"?z(v):G.key==="Escape"&&M()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:h||!x.trim(),onClick:()=>z(v),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(xl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:h,onClick:M,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(wr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${F}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${$}${Ls(v,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":v.id),className:`w-full text-left rounded-md px-2 py-1.5 transition-all duration-200 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-oai-brand/50 ${K} ${O?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(Ms,{platform:v.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:$,children:$}),Ls(v,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")})]}),e.jsxs("span",{title:d(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[As,F,Ds]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${F}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>D(v),className:"absolute right-2 top-1.5 flex h-4 items-center text-oai-gray-400 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-oai-brand focus:outline-none transition-opacity duration-150",children:e.jsx(ul,{className:"h-3 w-3"})})]}),p===v.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},v.id)}),N.map(v=>{const T=Number(v.total_tokens)||0,F=S>0?(T/S*100).toFixed(1):"0.0",O=_?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(Ct,{provider:v.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:jt(v.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:d(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[i(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[As,F,Ds]})]})]}),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 ${_?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${F}%`}})})]},`account-${v.source}`)})]})]})}function Nn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ut=new Map,mt=new Map;function Sn(){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 $d(t){if(!Nn()||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"};Sn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{mt.has(r)&&(mt.delete(r),s({ok:!1,error:"timeout"}))},8e3);mt.set(r,o=>{window.clearTimeout(n),s(o)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(o){mt.delete(r),window.clearTimeout(n),s({ok:!1,error:o?.message||String(o)})}})}async function Es(t,a){if(!Nn()||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"};Sn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const o=window.setTimeout(()=>{ut.has(s)&&(ut.delete(s),n({ok:!1,error:"timeout"}))},8e3);ut.set(s,i=>{window.clearTimeout(o),n(i)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(i){ut.delete(s),window.clearTimeout(o),n({ok:!1,error:i?.message||String(i)})}})}const Cn=1200,Tn=1630,An={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},Pd="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 or=!1;function zd(){if(typeof document>"u"||or)return;if(document.querySelector('link[data-share-card-fonts="true"]')){or=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=Pd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),or=!0}async function Bd(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function Od(t,a={}){if(typeof window>"u"||!t)return null;zd(),await Bd(),await new Promise(u=>requestAnimationFrame(()=>u(null)));const{toBlob:r,toPng:s}=await gi(async()=>{const{toBlob:u,toPng:m}=await import("./index-BFIcLxb4.js");return{toBlob:u,toPng:m}},[]),n=a.pixelRatio??2,o=t.offsetWidth||Cn,i=t.offsetHeight||Tn,d={pixelRatio:n,cacheBust:!0,width:o,height:i,style:{width:`${o}px`,height:`${i}px`},skipFonts:!1,filter:u=>!(u instanceof HTMLElement)||u.dataset?.screenshotExclude!=="true"};try{const u=await r(t,d);if(u)return u}catch{}try{const u=await s(t,d);return u?await(await fetch(u)).blob():null}catch{return null}}async function ir(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 Rs(t,a){if(typeof window>"u"||!t)return!1;try{const r=URL.createObjectURL(t),s=document.createElement("a");return s.href=r,s.download=a,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),!0}catch{return!1}}function gr(t){const a=ee(t);return Number.isFinite(a)?a:0}function Ud(t){return t?gr(t.billable_total_tokens??t.total_tokens):0}function Hd(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(o=>(Array.isArray(o)?o:[]).slice(0,7).map(d=>{const u=!!d?.future,m=Number.isFinite(d?.level)?Math.max(0,Math.min(4,Math.round(d.level))):0;d?.day&&!u&&(r+=1,m>0&&(s+=1));const x=d?.billable_total_tokens??d?.total_tokens??d?.value??0,f=Number.isFinite(x)?Math.max(0,x):0;return{day:typeof d?.day=="string"?d.day:"",level:m,value:f,future:u}})),totalDays:r,activeDays:s}}function Kd(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:o,rank:i,period:d,periodFrom:u,periodTo:m,heatmap:x,capturedAt:f,currency:h,exchangeRate:g}=t,p=Ud(n),b=gr(n?.total_cost_usd),k=Array.isArray(o)?o.slice(0,3).map(_=>({id:_?.id??null,name:typeof _?.name=="string"&&_.name?_.name:"—",tokens:gr(_?.tokens),percent:typeof _?.percent=="string"&&_.percent?_.percent:"0.0"})):[],j=Hd(x);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:p,totalCost:b,period:d,periodFrom:u,periodTo:m,topModels:k,rank:typeof i=="number"&&Number.isFinite(i)&&i>0?Math.floor(i):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:f||new Date().toISOString(),currency:typeof h=="string"&&h.length>0?h.toUpperCase():"USD",exchangeRate:Number.isFinite(g)&&g>0?g:1}}const Vd=["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 Wd(t){const a=Vd[t];return a?l(a):"—"}function Dn(t,a){return l("share.date.month_year",{month:Wd(t),year:a})}function qd(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:Dn(n,r)}function Gd(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 Dn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function fr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Mn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Wt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const o=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return o>=1e3?`${n}${Math.round(o).toLocaleString("en-US")}`:`${n}${o.toFixed(2)}`}function Yd(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 Zd(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 Jd(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 Qd({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:o}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const i=a||["#eee","#ccc","#999","#666","#333"],d=o||i[0],u=t.length,m=(u-1)*s,x=Math.max(4,(r-m)/u),f=7*x+6*s;return e.jsx("svg",{width:r,height:f,viewBox:`0 0 ${r} ${f}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((h,g)=>(Array.isArray(h)?h:[]).map((b,k)=>{if(k>=7)return null;const j=Jd(b),_=g*(x+s),S=k*(x+s),C=j===null?d:i[j];return e.jsx("rect",{x:_,y:S,width:x,height:x,rx:n,ry:n,fill:C},`${g}-${k}`)}))})}const Xd=Tt("oklch(0.97 0.01 85)"),Re=Tt("oklch(0.18 0.02 85)"),at=Tt("oklch(0.38 0.015 85)"),Is=Tt("oklch(0.55 0.012 85)"),lt=Tt("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',eu='"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(Tt);function Ln({data:t}){const a=Gd(t),r=fr(t.totalTokens),s=Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=qd(t.startDate),o=Zd(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),i=Yd(t),d=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Xd,color:Re,fontFamily:eu,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 ${Is}`},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:lt}}),"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:ct,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:lt,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:ct,fontSize:o,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",i,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:lt,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color: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})})]})]}),d?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color: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(Qd,{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:ct,fontStyle:"italic",fontSize:26,color:at,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((u,m)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Is}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(m+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:ct,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:u.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:fr(u.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[u.percent,"%"]})]},u.id||u.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:lt},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:lt},children:l("share.card.broadsheet.days_count",{days:t.activeDays})})]})]}),e.jsxs("div",{children:[l("share.card.broadsheet.track_yours")," ",e.jsx("span",{style:{color:lt},children:"→ tokentracker.cc"})]})]})]})}const au=An["annual-report"].width,ru="#0a0820",rt="#ffffffee",dt="rgba(255,255,255,0.45)",lr="#a78bfa",su={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(40px)",WebkitBackdropFilter:"blur(40px)",border:"1px solid rgba(255,255,255,0.05)",boxShadow:["0 39px 56px -36px rgba(255,255,255,0.10) inset","0 7px 11px -4px rgba(255,255,255,0.06) inset","0 -82px 68px -64px rgba(101,67,149,0.08) inset","0 98px 100px -48px rgba(208,171,255,0.06) inset","0 4px 18px 0 rgba(156,146,215,0.06) inset","0 1px 40px 0 rgba(228,222,255,0.04) inset"].join(", ")},pa={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},pr='"Space Grotesk", "Inter Tight", sans-serif',cr='"Inter Tight", sans-serif',nu="rgba(255,255,255,0.06)",En=[nu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Rn=48,In=28,va=4,Fn=20,ou=au-Rn*2-In*2,iu=(ou-Fn*2)/3,yr=Math.min(Math.floor((iu-va*6)/7),40),lu=yr*7+va*6;function cu(t){if(!Array.isArray(t))return t;const a=[];for(const d of t)if(Array.isArray(d))for(const u of d)u?.day&&!u.future&&u.value>0&&a.push(u.value);if(!a.length)return t;a.sort((d,u)=>d-u);const r=d=>{const u=a.length,m=(u-1)*d,x=Math.floor(m);return Math.round((a[x]??0)+((a[Math.min(u-1,x+1)]??0)-(a[x]??0))*(m-x))},s=r(.5),n=r(.75),o=r(.9),i=d=>!d||d<=0?0:d<=s?1:d<=n?2:d<=o?3:4;return t.map(d=>Array.isArray(d)?d.map(u=>u?.day&&!u.future&&typeof u.value=="number"?{...u,level:i(u.value)}:u):d)}function du(t){if(!Array.isArray(t))return[];const a={},r=cu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const o=n.day.split("-");if(o.length<2)continue;const i=`${o[0]}-${o[1]}`;(a[i]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function uu(t){if(!t.length)return[];const a=[...t].sort((i,d)=>i.day.localeCompare(d.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let i=0;i<s.length;i+=7)n.push(s.slice(i,i+7));const o=n[n.length-1];for(;o&&o.length<7;)o.push(null);return n.slice(0,6)}const mu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function hu(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const o of n)o?.day&&!o.future&&a.push(o);a.sort((n,o)=>n.day.localeCompare(o.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Fs(t){const[a,r]=c.useState(null);return c.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const o=document.createElement("canvas");o.width=n.naturalWidth,o.height=n.naturalHeight,o.getContext("2d").drawImage(n,0,0),r(o.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function xu({data:t}){const a=uu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:pr,marginBottom:4},children:mu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:va},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:va},children:r.map((n,o)=>{const i=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:yr,height:yr,borderRadius:4,background:i<0?"transparent":En[i]}},o)})},s))})]})}function gu({data:t}){const a=du(t.heatmapWeeks),r=hu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,o=Fs(n),i=Fs("/neon_bg.png"),d=(t.handle||"?")[0].toUpperCase(),u=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:ru,fontFamily:pr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:i||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Rn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:u*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color: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:o?e.jsx("img",{src:o,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:d})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...su,borderRadius:22,padding:In,marginBottom:u},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),En.map((m,x)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:m}},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,${lu}px)`,gap:`8px ${Fn}px`,justifyContent:"center"},children:a.map(m=>e.jsx(xu,{data:m},m.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:u,marginBottom:u},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:cr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:fr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:cr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:u},children:[e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:lr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:cr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...pa,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:lr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:pr,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:lr},children:"tokentracker.cc"})]})]})]})}const $n=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],fu={broadsheet:Ln,"annual-report":gu};function Pn(t){return An[t]||{width:Cn,height:Tn}}function pu(t){const a=$n.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const $s=c.forwardRef(function({data:a,variant:r},s){const n=fu[r]||Ln,{width:o,height:i}=Pn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:o,height:i,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function ya(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const yu=440;function bu(){const[t,a]=c.useState(null),r=c.useRef(null),s=c.useCallback((n,o="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:o,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return c.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function dr({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 ku({open:t,onClose:a,data:r,twitterText:s}){const[n,o]=c.useState(null),[i,d]=c.useState(""),[u,m]=c.useState("annual-report"),x=c.useRef(null),{toast:f,push:h}=bu(),g=fi(),p=c.useMemo(()=>{const N=g?.user;if(!N||typeof N!="object")return null;const v=N.user_metadata||{},T=N.profile||{},F=v.avatar_url||v.picture||T.avatar_url||N.avatar_url;return typeof F=="string"&&F.trim()?F.trim():null},[g?.user]);c.useEffect(()=>{t&&(o(null),d(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:i||r.handle,avatarUrl:p},{width:k,height:j}=Pn(u),_=yu/k;c.useEffect(()=>{if(!t)return;const N=v=>{v.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const S=c.useCallback(async()=>{const N=x.current;if(!N)return null;try{return await Od(N)}catch(v){return console.warn("[share] capture failed",v),null}},[]),C=c.useCallback(async()=>{if(n)return;o("copy");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}let v=!1;if(ya()){const T=await ir(N);T&&(v=(await $d(T)).ok)}else v=await Gr(N);h(v?l("share.toast.copied"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,h]),D=c.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),M=c.useCallback(async()=>{if(n)return;o("download");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}if(ya()){const T=await ir(N);if(T&&(await Es(T,D())).ok){h(l("share.toast.downloaded"),"success"),o(null);return}}const v=Rs(N,D());h(v?l("share.toast.downloaded"):l("share.toast.failed"),v?"success":"error"),o(null)},[n,S,D,h]),z=c.useCallback(async()=>{if(n)return;o("x");const N=await S();if(!N){h(l("share.toast.failed"),"error"),o(null);return}if(ya()){const O=await ir(N);O&&(await Es(O,D()),h(l("share.toast.downloaded"),"success"))}else await Gr(N)?h(l("share.toast.copied"),"success"):Rs(N,D());const v=new URL("https://twitter.com/intent/tweet");s&&v.searchParams.set("text",s);const T=g?.user?.id,F=typeof T=="string"&&T?`/u/${T}`:"/";if(v.searchParams.set("url",`https://www.tokentracker.cc${F}?ref=share`),ya())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:v.toString()})}catch{window.open(v.toString(),"_blank","noopener,noreferrer")}else window.open(v.toString(),"_blank","noopener,noreferrer");o(null)},[n,S,h,s,D,g]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:k,height:j,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx($s,{ref:x,data:b,variant:u})}),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*_,height:j*_,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:j,transform:`scale(${_})`,transformOrigin:"top left"},children:e.jsx($s,{data:b,variant:u})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:i,onChange:N=>d(N.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:$n.map(N=>e.jsx("button",{type:"button",onClick:()=>m(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",u===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:pu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(dr,{onClick:z,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(dr,{onClick:M,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(dr,{onClick:C,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(Qs,{children:f?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",f.kind==="error"?"bg-red-600 text-white":f.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:f.text})},f.id):null})]})]}):null}function _u(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:o,topModels:i,period:d,periodFrom:u,periodTo:m,heatmap:x,accessToken:f,userId:h,currency:g,exchangeRate:p}=t,[b,k]=c.useState(null),j=p;return c.useEffect(()=>{if(!a||!h&&!ht())return;let _=!1;return(async()=>{try{const C=await pi({accessToken:f,userId:h,period:d==="day"||d==="custom"?"week":d,metric:"all",limit:100,offset:0});if(_)return;const M=(Array.isArray(C?.entries)?C.entries:Array.isArray(C)?C:[]).find(N=>N?.is_me===!0),z=typeof M?.rank=="number"?M.rank:null;k(z)}catch{_||k(null)}})(),()=>{_=!0}},[a,f,h,d]),c.useMemo(()=>Kd({handle:r,startDate:s,activeDays:n,summary:o,topModels:i,rank:b,period:d,periodFrom:u,periodTo:m,heatmap:x,currency:g,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,o,i,b,d,u,m,x,g,j])}function Ps(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),o={key:a,promise:n};t.current=o;const i=()=>{t.current===o&&(t.current=null)};return n.then(i,i),n}const wu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function vu({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const ju=["day","week","month","total","custom"],ur=new Set(["day","hour","month"]),Ht=new Set(["day","total","custom"]),Nu=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Su=["usageOverview","dataDetails"];function mr(t,a){if(typeof a=="number"&&a>0)return!0;if(typeof t=="bigint")return t>0n;if(typeof t=="number")return Number.isFinite(t)&&t>0;if(typeof t=="string"){const r=t.trim();if(!r)return!1;if(/^[0-9]+$/.test(r))try{return BigInt(r)>0n}catch{return!1}const s=Number(r);return Number.isFinite(s)&&s>0}return!1}function ba(t){return t?St(t,null):null}function zs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function Cu(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function Tu(){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:!Cu(window.location.hostname)}function gm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:o=!1,publicToken:i=null,signInUrl:d="/sign-in",signUpUrl:u="/sign-up",onMainContentVisible:m}){const{resolvedLocale:x}=yi(),{currency:f,rate:h}=ja(),{mode:g,setMode:p,formatTokens:b,formatTokensTooltip:k}=Se(),[j,_]=c.useState(!1),[S,C]=c.useState(null),[D,M]=c.useState(null),[z,N]=c.useState(!1),[v,T]=c.useState(null),[F,O]=c.useState(0),[$,R]=c.useState(0),[B,K]=c.useState(null),G=c.useMemo(()=>typeof window>"u"?!1:bi(window.location.search),[]),w=c.useMemo(()=>Tu(),[]),[P,H]=c.useState(!1),te=2200,[ue,W]=c.useState(!0),[ne,le]=c.useState(!1),[je,ye]=c.useState(!1),[Ae,J]=c.useState(!1),[U,oe]=c.useState(!1),X=c.useRef(!1),ae=ht(),pe=r&&!s,V=c.useMemo(()=>pe&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,pe]),Y=pe?V:null,Q=o?ki(i):Y,xe=r||ae||o,Ne=pe&&Gt(Y),Ce=r&&s&&!o,{accountView:De,revision:ce,resolving:A}=_i(),L=De&&!o,re=L?Y:null,se=A&&!o;c.useEffect(()=>{if(!r||ae){C(null),M(null),N(!1),T(null);return}if(o)return;if(!Ne){C(null),M(null),N(!1),T(null);return}let y=!0;const E=()=>{C(null),M(null),N(!1),T(null)};return N(!0),T(null),(async()=>{let I=null;try{I=await Be(Y)}catch{I=null}if(y){if(!I){E();return}try{const q={link_code:null,expires_at:null};if(!y)return;C(typeof q?.link_code=="string"?q.link_code:null),M(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;C(null),M(null),T(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,ae,r,o,Ne,Y,$]);const ie=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");c.useEffect(()=>{if(!ie&&(!r||ae||o)){K(null);return}if(!ie&&!Ne){K(null);return}let y=!0;return(async()=>{let E=null;try{E=await Be(Y)}catch{E=null}if(y){if(!E&&!ie){K(null);return}try{const I=await wi({baseUrl:t,accessToken:E});if(!y)return;K(I&&typeof I=="object"?I:null)}catch{if(!y)return;K(null)}}})(),()=>{y=!1}},[Ne,t,Y,ae,o,r]);const Ve=c.useMemo(()=>{if(!D)return!1;const y=Date.parse(D);if(!Number.isFinite(y))return!1;const E=F||Date.now();return y<=E},[D,F]);c.useEffect(()=>{!r||ae||o||!D||!Ve||z||(C(null),M(null),T(null),R(y=>y+1))},[Ve,D,z,ae,r]),c.useEffect(()=>{if(!D||o)return;const y=Date.parse(D);if(!Number.isFinite(y))return;const E=Date.now();if(O(E),y<=E)return;const I=window.setTimeout(()=>O(Date.now()),y-E),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(I),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[D]);const me=c.useMemo(()=>Ks(),[]),ge=c.useMemo(()=>Hs(),[]),Fe=c.useMemo(()=>vi(),[]),$e=o?null:a?.userId||a?.email||"default",[At,xt]=c.useState("month"),[We,Na]=c.useState(null),[et,Sa]=c.useState(null),[Ca,gt]=c.useState(!1),Z=G?"total":At,Zt=c.useMemo(()=>Z==="custom"&&We&&et?{from:We,to:et}:ji(Z,{timeZone:me,offsetMinutes:ge,now:Fe}),[Fe,Z,me,ge,We,et]),be=Zt.from,ke=Zt.to,[ve,ft]=c.useState(null),[Dt,Jt]=c.useState(()=>Yr());c.useEffect(()=>{const y=()=>Jt(Yr());return window.addEventListener(Zr,y),window.addEventListener("storage",y),()=>{window.removeEventListener(Zr,y),window.removeEventListener("storage",y)}},[]);const{devices:Qt,accountSources:Mt,refresh:Ta}=Rd({from:be,to:ke,timeZone:me,tzOffsetMinutes:ge,accountView:L,accountAccessToken:re,accountRevision:ce}),qe=c.useMemo(()=>Qt.filter(y=>(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.id===Dt})),[Qt,Dt]),Xt=c.useMemo(()=>Mt.filter(y=>(Number(y.total_tokens)||0)>0),[Mt]),nt=L&&qe.length>=2,Lt=L&&qe.length+Xt.length>=2;c.useEffect(()=>{if(!nt&&!Lt){ve!==null&&ft(null);return}ve&&!qe.some(y=>y.id===ve)&&ft(null)},[nt,Lt,qe,ve]);const Aa=c.useMemo(()=>nt?[{value:"",label:l("dashboard.device_filter.all")},...qe.map(y=>{const E=xr(y)||l("dashboard.device_card.unnamed"),I=y.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:y.id,label:`${E}${I}`}})]:[],[nt,qe,x]),Da=Lt?e.jsx(Fd,{devices:qe,accountSources:Xt,currentDeviceId:Dt,selectedDeviceId:ve||"",onSelectDevice:y=>ft(y||null),onRenameDevice:async(y,E)=>{const I=await Be(re);await Di({deviceId:y,name:E,accessToken:I}),await Ta()}}):null,ea=c.useMemo(()=>Ni({timeZone:me,offsetMinutes:ge}),[me,ge]),Et=c.useMemo(()=>Si({timeZone:me,offsetMinutes:ge}),[me,ge]),Ma=c.useMemo(()=>`Local time (${Et})`,[Et]),Rt=me,It=ge,La=ea,Ye=c.useMemo(()=>_r({timeZone:me,offsetMinutes:ge,date:Fe||new Date}),[Fe,me,ge]),ta=c.useMemo(()=>oc({period:Z,selectedFrom:be,selectedTo:ke,todayKey:Ye}),[be,Z,ke,Ye]),{daily:Oe,summary:he,rolling:Ea,source:_e,loading:fe,error:Pe,refresh:aa}=os({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:be,to:ke,includeDaily:Z!=="total",cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{daily:Ze,loading:Ft,refresh:jr}=os({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:ta.from,to:ta.to,includeDaily:!0,includeSummary:!1,cacheKey:$e?`${$e}.daily-breakdown`:"daily-breakdown",timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{breakdown:tt,loading:Nr,refresh:Sr}=Bl({baseUrl:t,accessToken:Q,guestAllowed:Ce,from:be,to:ke,cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),[zn,Bn]=c.useState(3),{entries:On,loading:Un,refresh:Cr}=$l({baseUrl:t,accessToken:Q,from:be,to:ke,timeZone:me,tzOffsetMinutes:ge}),Tr=Z==="week"||Z==="month",ra=Z==="week"||Z==="month",Ar=c.useMemo(()=>Oe.filter(y=>y?.future?!1:!y?.day||!Ye?!0:String(y.day)<=String(Ye)),[Oe,Ye]),{rows:Je,from:Hn,to:Kn,loading:Vn,refresh:Dr}=Li({baseUrl:t,accessToken:Q,guestAllowed:Ce,period:Z,from:be,to:ke,months:24,cacheKey:$e,timeZone:Rt,tzOffsetMinutes:It,now:Fe,sharedRows:Tr?Oe:null,sharedRange:Tr?{from:be,to:ke}:null,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),Wn=c.useMemo(()=>({baseUrl:t,accessToken:Q,guestAllowed:Ce,cacheKey:$e,timeZone:Rt,tzOffsetMinutes:It,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),[t,Q,Ce,$e,Rt,It,Fe,L,re,ce,se,ve]),{daily:pt,heatmap:Ge,loading:Mr,refresh:Lr}=Ll({baseUrl:t,accessToken:Q,guestAllowed:Ce,weeks:52,cacheKey:$e,timeZone:me,tzOffsetMinutes:ge,now:Fe,accountView:L,accountAccessToken:re,accountRevision:ce,accountViewResolving:se,deviceId:ve}),{data:sa,refresh:Er}=Ei();c.useEffect(()=>{sa&&typeof sa=="object"&&Ci(sa)},[sa]);const Ue=c.useMemo(()=>Z==="day"?"hour":Z==="total"?"month":"day",[Z]),qn=c.useMemo(()=>ls(Ue),[Ue]),na="day",Gn=c.useMemo(()=>ls(na),[]),[He,Rr]=c.useState(()=>({key:"day",dir:"desc"}));c.useEffect(()=>{Rr(y=>!ur.has(y.key)||y.key===Ue?y:{key:Ue,dir:y.dir})},[Ue]);const yt=c.useMemo(()=>ur.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),oa=c.useMemo(()=>{if(Z==="day")return Array.isArray(Je)?Je.filter(I=>I?.hour&&!I?.future):[];if(Z==="total"){const I=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return Xl(I)}const y=Ar;return!y.some(I=>!I?.missing&&!I?.future)&&Oe.length>0?Oe.filter(I=>!I?.future).slice(-30).filter(I=>I?.day):y},[Z,Je,Ar,Oe]),$t=c.useMemo(()=>cs(oa,yt),[oa,yt]),Ir=c.useMemo(()=>oa.some(y=>!y?.missing&&!y?.future),[oa]),Ra=c.useMemo(()=>{if(!Ht.has(Z))return 1;const y=Math.ceil($t.length/wa);return y>0?y:1},[Z,$t.length]),[Ia,ia]=c.useState(0);c.useEffect(()=>{if(!Ht.has(Z)){ia(0);return}ia(y=>Math.min(y,Ra-1))},[Ra,Z]),c.useEffect(()=>{Ht.has(Z)&&ia(0)},[Z,He.dir,He.key]);const Yn=c.useMemo(()=>Ht.has(Z)?ec($t,Ia,wa):$t,[Ia,Z,$t]),Fr=c.useMemo(()=>ic(Ze,{period:Z}),[Ze,Z]),bt=c.useMemo(()=>ur.has(He.key)?{...He,key:na}:He,[He]),Zn=c.useMemo(()=>cs(Fr,bt),[Fr,bt]),Jn=c.useMemo(()=>ra?Oe:Z==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[Oe,Z,Je,ra]),Qn=ra?be:Hn,Xn=ra?ke:Kn;function eo(y,E){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(E.endsWith("_tokens")){const I=E==="total_tokens"?ba(y):y?.[E];return e.jsx("span",{title:k(I),children:b(I)})}return _a(y?.[E])}function to(y){const E=y?.[Ue];if(E==null)return"";const I=String(E);if(Ue==="hour"){const[q,Le]=I.split("T");if(q&&Le)return`${q} ${Le.slice(0,5)}`}return I}function ao(y){const E=y?.[na];return E==null?"":String(E)}function ro(y){Rr(E=>E.key===y?{key:y,dir:E.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function so(y){return yt.key!==y?"none":yt.dir==="asc"?"ascending":"descending"}function no(y){return yt.key!==y?"":yt.dir==="asc"?"▲":"▼"}function oo(y){return bt.key!==y?"none":bt.dir==="asc"?"ascending":"descending"}function io(y){return bt.key!==y?"":bt.dir==="asc"?"▲":"▼"}const Fa=c.useMemo(()=>{if(!r&&!ae&&!o&&!ie)return 0;const y=Number(Ge?.active_days);if(Number.isFinite(y))return y;let E=0;const I=new Set,q=(we,ze,Ee)=>{typeof we!="string"||!we||I.has(we)||mr(ze,Ee)&&(I.add(we),E+=1)};if(Array.isArray(pt))for(const we of pt)q(we?.day,ba(we));const Le=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const we of Le)for(const ze of Array.isArray(we)?we:[]){const Ee=zs(ze);q(ze?.day,Ee,ze?.level)}return E},[r,ae,Ge?.active_days,Ge?.weeks,pt]),[$r,Pr]=c.useState("month"),lo=c.useCallback(y=>{L&&!o&&Ga(a?.userId,"history"),y==="custom"?(Pr(E=>E==="custom"?"month":E),xt(E=>We&&et?"custom":E),gt(!0)):(xt(y),Pr(y),gt(!1))},[We,et,L,o,a?.userId]),co=c.useCallback((y,E)=>{L&&!o&&Ga(a?.userId,"history"),Na(y),Sa(E),xt("custom"),gt(!1)},[L,o,a?.userId]),uo=c.useCallback(y=>{gt(y),!y&&At==="custom"&&!We&&xt($r)},[At,We,$r]),mo=c.useRef(null),la=c.useMemo(()=>[t||"",$e||"",L?"cloud":"local",ce??"",Z||"",be||"",ke||"",Ye||"",ve||"all",me||"",ge??""].join(""),[ce,L,t,$e,be,Z,ve,me,Ye,ke,ge]),Pt=c.useCallback(async()=>Ps(mo,la,async()=>{L&&Ti(),L||Ai(),await Promise.all([aa(),Lr(),Dr(),Sr(),Cr(),jr()])}),[L,jr,Lr,Sr,Cr,Dr,aa,la]),ho=c.useRef(null),zr=c.useCallback(async()=>Ps(ho,la,async()=>{await vu({refreshUsageStats:Pt,refreshUsageLimits:Er})}),[la,Er,Pt]),$a=c.useRef(Pt);c.useEffect(()=>{$a.current=Pt},[Pt]);const Pa=c.useRef(null);c.useEffect(()=>{if(!ie||ae||L)return;Pa.current||(Pa.current=Jr({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Pa.current.then(()=>{if(y)return $a.current()}).catch(E=>{y&&console.warn("[DashboardPage] Reload sync failed:",E)}),()=>{y=!1}},[ie,ae,L]),c.useEffect(()=>{if(!ie||ae||L)return;const y=sc({refresh:()=>$a.current(),onError:E=>console.warn("[DashboardPage] Automatic usage refresh failed:",E)});return()=>y.stop()},[ie,ae,L]);const xo=c.useCallback(async()=>{J(!0);try{ie&&await Jr(wu),await zr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{J(!1)}},[ie,zr]),ca=Ae||fe||Ft||Mr||Vn||Nr||Un,za=!U&&(se||L&&ca&&!Ir),go=c.useMemo(()=>l("shared.data_source",{source:String(_e||"edge").toUpperCase()}),[_e,x]),da=c.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),fo="",Br=c.useMemo(()=>!da||da.includes("@")?l("dashboard.identity.fallback"):da,[da]),Or=c.useMemo(()=>Br.replace(/[^a-zA-Z0-9._-]/g,"_"),[Br]),Ur=c.useMemo(()=>o?l("dashboard.identity.fallback"):Or,[Or,fo,o]),Hr=c.useMemo(()=>{let y=null;const E=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(pt))for(const q of pt)q?.day&&mr(ba(q))&&E(q.day);const I=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const q of I)for(const Le of Array.isArray(q)?q:[]){if(!Le?.day)continue;const we=zs(Le),ze=Le?.level;mr(we,ze)&&E(Le.day)}return y},[Ge?.weeks,pt]),po=c.useMemo(()=>o?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(I=>{const q=typeof I?.tool=="string"?I.tool.trim():"",we=(typeof I?.plan_type=="string"?I.plan_type:typeof I?.planType=="string"?I.planType:"").trim();return!q||!we?null:{tool:q,planType:we,provider:typeof I?.provider=="string"?I.provider.trim():"",product:typeof I?.product=="string"?I.product.trim():"",rateLimitTier:typeof I?.rate_limit_tier=="string"?I.rate_limit_tier.trim():typeof I?.rateLimitTier=="string"?I.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[o,B]),yo=e.jsx(Ri,{heatmap:Ge,timeZoneLabel:ea,timeZoneShortLabel:Et,hideLegend:G,defaultToLatestMonth:G}),bo=c.useMemo(()=>`${be}..${ke}`,[be,Z,ke]),ko=l("usage.summary.total"),Me=he!=null,kt=Me?ba(he):0,_o=b(kt),wo=c.useCallback(()=>{p(g===Kt.COMPACT?Kt.FULL:Kt.COMPACT)},[p,g]),vo=l("dashboard.core_index.collapse_label"),jo=l("dashboard.core_index.expand_label"),No=l("dashboard.core_index.collapse_aria"),So=l("dashboard.core_index.expand_aria"),Co=!G,_t=l("shared.placeholder.short"),Ba=c.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let E=null,I=0;for(const ze of y){const Ee=St(ze?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>I&&(I=Ee,E=ze)}let q=_t,Le=_t,we="0.0";if(E&&I>0){q=E?.source?String(E.source).toUpperCase():_t;const ze=Array.isArray(E?.models)?E.models:[];let Ee=0;for(const qa of ze){const ma=St(qa?.totals);!Number.isFinite(ma)||ma<=0||ma>Ee&&(Ee=ma,Le=qa?.model?String(qa.model):_t)}Ee>0&&(we=(Ee/I*100).toFixed(1))}return{agentName:q,modelName:Le,modelPercent:we}},[tt,_t]),Oa=_a(kt),To=l("dashboard.screenshot.twitter_text",{total_tokens:Oa==="-"?_t:Oa,agent_name:Ba.agentName,model_name:Ba.modelName,model_percent:Ba.modelPercent}),Ao=c.useMemo(()=>G?[]:ju,[G]),Do=c.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(kt):"—",title:Me?k(kt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(he?.input_tokens):"—",title:Me?k(he?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(he?.output_tokens):"—",title:Me?k(he?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(he?.cached_input_tokens):"—",title:Me?k(he?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(he?.reasoning_output_tokens):"—",title:Me?k(he?.reasoning_output_tokens):void 0}],[he?.cached_input_tokens,he?.input_tokens,he?.output_tokens,he?.reasoning_output_tokens,kt,Me,b,k]),Ua=(tt?.sources||[]).some(y=>(y.models||[]).some(E=>E.pricing?.status==="unpriced"&&E.cost_source!=="provider_reported"&&Number(E.totals?.total_tokens)>0)),Ha=c.useMemo(()=>{if(Ua&&Number(he?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=Yt(he?.total_cost_usd,{currency:f,rate:h});return Ua&&y!=="-"?`≥${y}`:y},[he?.total_cost_usd,f,h,Ua]),Mo=c.useMemo(()=>he?.conversation_count??null,[he?.conversation_count]),Kr=c.useMemo(()=>gc(tt,{copyFn:l}),[tt]),Vr=c.useMemo(()=>pc(tt,{limit:3,copyFn:l}),[tt]),Lo=_u({enabled:P,handle:Ur,startDate:Hr,activeDays:Fa,summary:he,topModels:Vr,period:Z,periodFrom:be,periodTo:ke,heatmap:Ge,accessToken:typeof Q=="string"?Q:null,userId:a?.userId||null,currency:f,exchangeRate:h}),Eo=c.useCallback(()=>H(!0),[]),Ro=c.useCallback(()=>H(!1),[]),Io=c.useCallback(()=>_(!0),[]),Fo=c.useCallback(()=>_(!1),[]),$o=Ha&&Ha!=="-"&&Kr.length>0,zt=l("dashboard.install.cmd.init"),Ka=Ve?null:S,Va=Ka?l("dashboard.install.cmd.init_link_code",{link_code:Ka}):zt,Po=zt,zo=l("dashboard.install.cmd.sync"),Bo=Ka?l("dashboard.install.copy"):l("dashboard.install.copy_base"),Oo=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const Uo=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),Ho=tc({publicMode:o,screenshotMode:G,forceInstall:w,accessEnabled:xe,heatmapLoading:Mr,activeDays:Fa,hasActiveDeviceToken:Uo}),Ko=l("dashboard.install.prompt"),Vo=c.useCallback(async()=>{!Va||!await Qr(Va)||(le(!0),window.setTimeout(()=>le(!1),2e3))},[Va]);c.useCallback(async()=>{!zt||!await Qr(zt)||(ye(!0),window.setTimeout(()=>ye(!1),2e3))},[zt]);const Wa=c.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[x]),[Wo,qo]=c.useMemo(()=>{const y=Wa.split("{{cmd}}");return y.length===1?[Wa,""]:[y[0],y.slice(1).join("{{cmd}}")]},[Wa]),Bt=s&&!o,Ot=!r&&!ae&&!s&&!ie&&!o;c.useEffect(()=>{Bt||Ot||za||oe(!0)},[za,Ot,Bt]);const ua=Il(Nu,Su);return c.useEffect(()=>{X.current||Bt||Ot||ca||(X.current=!0,m?.())},[m,Ot,Bt,ca]),e.jsxs(e.Fragment,{children:[e.jsx(Ed,{copy:l,onOpenShare:Eo,screenshotMode:G,showExpiredGate:Bt,showAuthGate:Ot,identityDisplayName:Ur,identityStartDate:Hr,activeDays:Fa,identitySubscriptions:po,identityScrambleDurationMs:te,projectUsageEntries:On,projectUsageLimit:zn,setProjectUsageLimit:Bn,projectDetailQuery:{from:be,to:ke,timeZone:me,tzOffsetMinutes:ge},topModels:Vr,signedIn:r,publicMode:o,isLocalMode:ie,shouldShowInstall:Ho,installPrompt:Ko,handleCopyInstall:Vo,installCopied:ne,installCopiedLabel:Oo,installCopyLabel:Bo,installInitCmdDisplay:Po,linkCodeLoading:z,linkCodeError:v,trendRowsForDisplay:Jn,trendFromForDisplay:Qn,trendToForDisplay:Xn,trendZoomConfig:Wn,usageFrom:be,usageTo:ke,period:Z,trendTimeZoneLabel:La,activityHeatmapBlock:yo,periodsForDisplay:Ao,setSelectedPeriod:lo,customFrom:We,customTo:et,onCustomRangeApply:co,customRangeOpen:Ca,onCustomRangeOpenChange:uo,metricsRows:Do,summaryLabel:ko,summaryValue:_o,hasSummary:Me,summaryLoading:fe,providersLoading:Nr,summaryFullValue:Oa,onToggleSummaryFormat:wo,summaryTotalTokensRaw:ee(kt)||0,summaryCostValue:Ha,summaryConversationsValue:Mo,rollingUsage:Ea,costInfoEnabled:$o,openCostModal:Io,allowBreakdownToggle:Co,coreIndexCollapsed:ue,setCoreIndexCollapsed:W,coreIndexCollapseLabel:vo,coreIndexExpandLabel:jo,coreIndexCollapseAria:No,coreIndexExpandAria:So,refreshAll:xo,usageLoadingState:ca,announceUsageLoading:Ae,initialDashboardLoading:za,usageError:Pe,rangeLabel:bo,timeZoneRangeLabel:Ma,usageSourceLabel:go,fleetData:Kr,hasDetailsActual:Ir,dailyEmptyPrefix:Wo,installSyncCmd:zo,dailyEmptySuffix:qo,detailsColumns:qn,ariaSortFor:so,toggleSort:ro,sortIconFor:no,pagedDetails:Yn,dailyBreakdownRows:Zn,dailyBreakdownColumns:Gn,dailyBreakdownAriaSortFor:oo,dailyBreakdownSortIconFor:io,dailyBreakdownDateKey:na,detailsDateKey:Ue,renderDetailDate:to,renderDailyBreakdownDate:ao,renderDetailCell:eo,DETAILS_PAGED_PERIODS:Ht,detailsPageCount:Ra,detailsPage:Ia,setDetailsPage:ia,costModalOpen:j,closeCostModal:Fo,deviceOptions:Aa,selectedDevice:ve||"",onDeviceChange:y=>{L&&!o&&Ga(a?.userId,"view"),ft(y||null)},deviceUsageBlock:Da,leftCardOrder:ua.left.order,onLeftReorder:ua.left.reorder,rightCardOrder:ua.right.order,onRightReorder:ua.right.reorder}),e.jsx(ku,{open:P,onClose:Ro,data:Lo,twitterText:To})]})}export{gm as DashboardPage};