tokentracker-cli 1.5.14 → 1.5.15

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 (114) hide show
  1. package/dashboard/dist/assets/{AchievementBadge-DqJWve1h.js → AchievementBadge-CwjI28oT.js} +1 -1
  2. package/dashboard/dist/assets/{AchievementsPage-CnuBayj3.js → AchievementsPage-Dq544fjX.js} +2 -2
  3. package/dashboard/dist/assets/{AchievementsSection-WRU5TxAB.js → AchievementsSection-DufV6nod.js} +1 -1
  4. package/dashboard/dist/assets/{BadgeDetailModal-B5ikEQik.js → BadgeDetailModal-vw8xydKu.js} +1 -1
  5. package/dashboard/dist/assets/{BotAnimated-CaMG6j-6.js → BotAnimated-De0anwsh.js} +1 -1
  6. package/dashboard/dist/assets/{Card-BL3vxENk.js → Card-CuSeWBDM.js} +1 -1
  7. package/dashboard/dist/assets/{CloudCheckoutPage-CsUb8CJ7.js → CloudCheckoutPage-CxFcOwAj.js} +1 -1
  8. package/dashboard/dist/assets/{CloudPage-5ZiPFzeC.js → CloudPage-Beb7_JLW.js} +2 -2
  9. package/dashboard/dist/assets/{CommandPalette-CYd9nXW-.js → CommandPalette-PsUq2iRS.js} +1 -1
  10. package/dashboard/dist/assets/{CommunityStatsModal-BItox7Sz.js → CommunityStatsModal-b54WaPbK.js} +1 -1
  11. package/dashboard/dist/assets/{ConfirmModal-BE1ABR4z.js → ConfirmModal-_NdunIh5.js} +1 -1
  12. package/dashboard/dist/assets/{Controls-BRqIsaHT.js → Controls-5Is6MWln.js} +1 -1
  13. package/dashboard/dist/assets/{DashboardPage-Cm0YuBlx.js → DashboardPage-C0n0qC7h.js} +1 -1
  14. package/dashboard/dist/assets/{DateRangePopover-CRwEu66e.js → DateRangePopover-C3WfGy-0.js} +1 -1
  15. package/dashboard/dist/assets/{DevicePage-DFUPsGb_.js → DevicePage-Vn6k-mGd.js} +1 -1
  16. package/dashboard/dist/assets/{DialogClose-DALl4GmP.js → DialogClose-CXttnna-.js} +1 -1
  17. package/dashboard/dist/assets/DialogDescription-C3KGos_G.js +1 -0
  18. package/dashboard/dist/assets/{DialogTitle-BSR8ozyn.js → DialogTitle-B0cNIo0E.js} +1 -1
  19. package/dashboard/dist/assets/{ElectricLogo-BtrycBUW.js → ElectricLogo-DC3XSfIu.js} +1 -1
  20. package/dashboard/dist/assets/{FadeIn-CfhgvLVd.js → FadeIn-H7S3TMHi.js} +1 -1
  21. package/dashboard/dist/assets/{HeaderGithubStar-N8wqAdOf.js → HeaderGithubStar-xgbIo5OP.js} +1 -1
  22. package/dashboard/dist/assets/{HoverTooltip-CwdMYIzZ.js → HoverTooltip-CpzM5Dju.js} +1 -1
  23. package/dashboard/dist/assets/{IpCheckPage-DCRor9cb.js → IpCheckPage-BdV7S4dY.js} +1 -1
  24. package/dashboard/dist/assets/{LandingPage-s9xvTHSp.js → LandingPage-D9f28ryO.js} +2 -2
  25. package/dashboard/dist/assets/{LeaderboardPage-CUj3WLMo.js → LeaderboardPage--WUFpkBI.js} +2 -2
  26. package/dashboard/dist/assets/{LeaderboardProBadge-N4NOKZWj.js → LeaderboardProBadge-CEvrQ75Y.js} +1 -1
  27. package/dashboard/dist/assets/{LeaderboardProfileModal-09HiUyxm.js → LeaderboardProfileModal-Bn0HFr5h.js} +3 -3
  28. package/dashboard/dist/assets/{LeaderboardProfilePage-Cw9_rodG.js → LeaderboardProfilePage-DJ7fQI68.js} +1 -1
  29. package/dashboard/dist/assets/{LimitsPage-F8b6kZa0.js → LimitsPage-7tPDheuX.js} +1 -1
  30. package/dashboard/dist/assets/{LocalOnlyNotice-D1eEzDEv.js → LocalOnlyNotice-DlGbVQS8.js} +1 -1
  31. package/dashboard/dist/assets/{LoginCard-0sIovG_J.js → LoginCard-BZZmzUGh.js} +1 -1
  32. package/dashboard/dist/assets/{LoginModal-BT3oMVak.js → LoginModal-BT5_bIxU.js} +1 -1
  33. package/dashboard/dist/assets/{LoginPage-CDsXdaE5.js → LoginPage-DMjDUPPi.js} +1 -1
  34. package/dashboard/dist/assets/{PetPage-BEnC1azp.js → PetPage-Dk3j6ITn.js} +2 -2
  35. package/dashboard/dist/assets/{PopoverPopup-Dwzp-hyf.js → PopoverPopup-pugRu3RC.js} +1 -1
  36. package/dashboard/dist/assets/{ProviderIcon-Cu_lcuuu.js → ProviderIcon-CtmL1CmY.js} +1 -1
  37. package/dashboard/dist/assets/{ResetPasswordPage-DrpEscm1.js → ResetPasswordPage-BB6U7t8P.js} +1 -1
  38. package/dashboard/dist/assets/{Select-wIR4qvEI.js → Select-7w1su8lw.js} +1 -1
  39. package/dashboard/dist/assets/{SelectItemText-CNuJgYps.js → SelectItemText-CaEUmWkj.js} +1 -1
  40. package/dashboard/dist/assets/{SelfHostPage-CWNLygpL.js → SelfHostPage-DctWoF-A.js} +1 -1
  41. package/dashboard/dist/assets/{ServiceStatusPage-BId9t16Q.js → ServiceStatusPage-Dg3ljEXC.js} +1 -1
  42. package/dashboard/dist/assets/{SessionsPage-C_klx7d8.js → SessionsPage-B1dvW-be.js} +1 -1
  43. package/dashboard/dist/assets/{SettingsPage-nC73JaZ4.js → SettingsPage-DuXSX1R2.js} +3 -3
  44. package/dashboard/dist/assets/{SkillsPage-B2agou8Y.js → SkillsPage-CvXQFgc9.js} +1 -1
  45. package/dashboard/dist/assets/{TokenGalaxy-BNXUWRwa.js → TokenGalaxy-DKC8Rk_Y.js} +1 -1
  46. package/dashboard/dist/assets/{TooltipPopup--X2kExQ0.js → TooltipPopup-Dp9EpHLG.js} +1 -1
  47. package/dashboard/dist/assets/{TrendMonitor-BELHsTnz.js → TrendMonitor-DWnlBn3H.js} +1 -1
  48. package/dashboard/dist/assets/{WidgetsPage-DWp0SMXA.js → WidgetsPage-GECNmb1Q.js} +1 -1
  49. package/dashboard/dist/assets/{WrappedPage-DgwczKHe.js → WrappedPage-Dq_1lOnb.js} +1 -1
  50. package/dashboard/dist/assets/{__vite-browser-external-BHphZRSC.js → __vite-browser-external-CkF0pdTJ.js} +2 -2
  51. package/dashboard/dist/assets/{agent-logos-Cfx5WzU5.js → agent-logos-Dqe3Vrah.js} +1 -1
  52. package/dashboard/dist/assets/{arrow-left-D83SdANw.js → arrow-left-Cr_2QnDu.js} +1 -1
  53. package/dashboard/dist/assets/{arrow-right-D7ye9bmJ.js → arrow-right-BsK2sJgt.js} +1 -1
  54. package/dashboard/dist/assets/{arrow-up-right-CLmwEwwC.js → arrow-up-right-DkWMGqXo.js} +1 -1
  55. package/dashboard/dist/assets/{calendar-days-D1qLlvh4.js → calendar-days-BB9VV438.js} +1 -1
  56. package/dashboard/dist/assets/{check-BHJvi4ey.js → check-bpSCJZWh.js} +1 -1
  57. package/dashboard/dist/assets/{chevron-down-6RBPKNpt.js → chevron-down-CtECtDmx.js} +1 -1
  58. package/dashboard/dist/assets/{cloud-checkout-DgWcF-at.js → cloud-checkout-C4PrzKhN.js} +1 -1
  59. package/dashboard/dist/assets/{composite-D-0pfyMY.js → composite-BHisG82k.js} +1 -1
  60. package/dashboard/dist/assets/{copy-B6mJSQsD.js → copy-Dmxzd-Sw.js} +1 -1
  61. package/dashboard/dist/assets/{download-D31Nn-bI.js → download-CkdQzw2w.js} +1 -1
  62. package/dashboard/dist/assets/{external-link-C_lK9S3p.js → external-link-C971FjvC.js} +1 -1
  63. package/dashboard/dist/assets/{flame-1ZxhHshT.js → flame-mKbp7kxw.js} +1 -1
  64. package/dashboard/dist/assets/{format-tokens-DJk25SkD.js → format-tokens-C35FrJnH.js} +1 -1
  65. package/dashboard/dist/assets/{gift-BUZzFh-1.js → gift-BX2lSOmc.js} +1 -1
  66. package/dashboard/dist/assets/{icons-BVPThCa4.js → icons-ov92u52T.js} +1 -1
  67. package/dashboard/dist/assets/{index-CjPsyTl7.js → index-9OCL-BL8.js} +1 -1
  68. package/dashboard/dist/assets/{index-C0zFsOWh.js → index-Bgm38oHe.js} +1 -1
  69. package/dashboard/dist/assets/{index-CzstoU6d.js → index-Ca5xkNrK.js} +1 -1
  70. package/dashboard/dist/assets/{index-B-mxrdIz.js → index-DF03nIHb.js} +1 -1
  71. package/dashboard/dist/assets/{info-DmU-vlJ6.js → info-B-f9hWcw.js} +1 -1
  72. package/dashboard/dist/assets/{link-2-BlBM7uw7.js → link-2-l1wuezTo.js} +1 -1
  73. package/dashboard/dist/assets/{loader-circle-Dhrb_Ocy.js → loader-circle-Lmjrs8XX.js} +1 -1
  74. package/dashboard/dist/assets/{local-usage-transfer-BudmMtkd.js → local-usage-transfer-Ds6cF41d.js} +1 -1
  75. package/dashboard/dist/assets/{modifiers.esm-kmw1VM8W.js → modifiers.esm-tVlltJXO.js} +1 -1
  76. package/dashboard/dist/assets/{monitor-smartphone-DtjXNC_x.js → monitor-smartphone-XRiYiY8u.js} +1 -1
  77. package/dashboard/dist/assets/{play-9w46lbjy.js → play-DaD9EMjk.js} +1 -1
  78. package/dashboard/dist/assets/{plus-DAf_WGKT.js → plus-D30fbsKQ.js} +1 -1
  79. package/dashboard/dist/assets/{provider-display-BZ0XlB2q.js → provider-display-CKdhBOwz.js} +1 -1
  80. package/dashboard/dist/assets/{react-B01ZJuZY.js → react-BY0y0K4x.js} +1 -1
  81. package/dashboard/dist/assets/{safePolygon-B6_x12Gb.js → safePolygon-CSG_P7rG.js} +1 -1
  82. package/dashboard/dist/assets/{search-D3dW9GbV.js → search-Kiq8wVHA.js} +1 -1
  83. package/dashboard/dist/assets/{server-C2XZBar7.js → server-CjovGBGz.js} +1 -1
  84. package/dashboard/dist/assets/{shield-check-4FX5vbS7.js → shield-check-DF9MmMCq.js} +1 -1
  85. package/dashboard/dist/assets/{skills-api-BvW_MUyg.js → skills-api-CEzr6p92.js} +1 -1
  86. package/dashboard/dist/assets/{sortable.esm-CAa_BJgh.js → sortable.esm-D7jd9mE_.js} +1 -1
  87. package/dashboard/dist/assets/{store-2AX2MNkz.js → store-D9_jo_do.js} +1 -1
  88. package/dashboard/dist/assets/{terminal-CON7n_ir.js → terminal-CLOlvzR-.js} +1 -1
  89. package/dashboard/dist/assets/{trash-C2f88jSi.js → trash-DIe0fsDD.js} +1 -1
  90. package/dashboard/dist/assets/{use-community-stats-CgQu43xV.js → use-community-stats-gDkdiRBz.js} +1 -1
  91. package/dashboard/dist/assets/{use-latest-request-guard-lShM46-3.js → use-latest-request-guard-tXGuKvua.js} +1 -1
  92. package/dashboard/dist/assets/{use-limits-display-prefs-8o7pbEg0.js → use-limits-display-prefs-CCuLFy00.js} +1 -1
  93. package/dashboard/dist/assets/{use-native-settings-dN8shG3M.js → use-native-settings-hgYqaiR7.js} +1 -1
  94. package/dashboard/dist/assets/{use-ordered-list-beJy2IqQ.js → use-ordered-list-D6-YzYJI.js} +1 -1
  95. package/dashboard/dist/assets/use-reduced-motion-DfbDxs5a.js +1 -0
  96. package/dashboard/dist/assets/{use-transform-cJpAQr2d.js → use-transform-BEiXvAuE.js} +1 -1
  97. package/dashboard/dist/assets/{use-usage-limits-CuusZA6b.js → use-usage-limits-BlwtyPtT.js} +1 -1
  98. package/dashboard/dist/assets/{useCurrency-Cx9UsKJK.js → useCurrency-CwCGJLHb.js} +1 -1
  99. package/dashboard/dist/assets/{usePositioner-TEClK6mF.js → usePositioner-BqHtRIrE.js} +1 -1
  100. package/dashboard/dist/assets/{useTokenFormat-BNwTLiac.js → useTokenFormat-BUNBUX-x.js} +1 -1
  101. package/dashboard/dist/assets/{zap-CFgbVEhC.js → zap-C0RFs2qQ.js} +1 -1
  102. package/dashboard/dist/index.html +1 -1
  103. package/dashboard/dist/ip-check.html +1 -1
  104. package/dashboard/dist/leaderboard.html +1 -1
  105. package/dashboard/dist/share.html +1 -1
  106. package/package.json +1 -1
  107. package/src/lib/limits-cache.js +475 -0
  108. package/src/lib/pricing/curated-overrides.json +24 -0
  109. package/src/lib/pricing/matcher.js +4 -1
  110. package/src/lib/pricing/seed-snapshot.json +1 -1
  111. package/src/lib/rollout.js +43 -47
  112. package/src/lib/usage-limits.js +370 -1063
  113. package/dashboard/dist/assets/DialogDescription-CO0hykis.js +0 -1
  114. package/dashboard/dist/assets/use-reduced-motion-S0bR_G1B.js +0 -1
@@ -1 +1 @@
1
- import{o as Nr,r as u,j as e,L as mi,dD as hi,W as pt,aB as ea,aC as He,dE as pi,dF as xi,az as ss,dG as ka,aH as en,aI as tn,aJ as Sr,dH as gi,dI as fi,dJ as yi,aL as Cr,aK as Jt,dK as bi,dL as ki,dM as H,c as l,V as St,X as Tr,i as Ie,aA as ta,bi as Zt,z as an,dN as _i,an as wi,l as Yt,cg as Aa,y as Ct,dO as vi,U as rn,Q as sn,aN as ji,ao as Ni,B as Si,R as Ci,h as Ti,dP as Ai,dQ as Di,dR as Mi,dS as Li,am as ns,_ as Ei,a as Ri,dT as os,g as Ii,Z as Fi,ct as $i,dU as Pi,dV as Oi,dW as zi,dX as Bi,dY as Ui,ch as is,cU as ls,dZ as Hi,d_ as Ki,aU as qi,d6 as _a,d$ as cs,aS as ds,e0 as Vi,e1 as Wi,e2 as Gi}from"./__vite-browser-external-BHphZRSC.js";import{u as st}from"./use-latest-request-guard-lShM46-3.js";import{u as us,L as Yi}from"./use-ordered-list-beJy2IqQ.js";import{t as ms,T as nn,g as Ji,u as Zi}from"./TrendMonitor-BELHsTnz.js";import{u as Qi}from"./use-usage-limits-CuusZA6b.js";import{u as aa}from"./useCurrency-Cx9UsKJK.js";import{u as Ne}from"./useTokenFormat-BNwTLiac.js";import{f as ut,A as Xi}from"./provider-display-BZ0XlB2q.js";import{g as el,q as on,J as tl,M as al,m as Ve}from"./react-B01ZJuZY.js";import{u as rl,C as sl,a as nl,b as hs,D as ol,S as il,v as ll,s as cl,K as dl,P as ul}from"./sortable.esm-CAa_BJgh.js";import{D as ml,a as hl,b as pl,c as xl,d as gl,e as fl}from"./DialogTitle-BSR8ozyn.js";import{D as yl}from"./DialogClose-DALl4GmP.js";import{C as De}from"./Card-BL3vxENk.js";import{S as ln}from"./Select-wIR4qvEI.js";import{P as At}from"./ProviderIcon-Cu_lcuuu.js";import{a as cn,u as dn}from"./use-transform-cJpAQr2d.js";import{u as un}from"./use-reduced-motion-S0bR_G1B.js";import{f as wa,D as bl,g as kl}from"./DateRangePopover-CRwEu66e.js";import{I as mn}from"./info-DmU-vlJ6.js";import{A as hn}from"./index-CjPsyTl7.js";import{L as _l}from"./loader-circle-Dhrb_Ocy.js";import{C as wl}from"./chevron-down-6RBPKNpt.js";import{P as vl,a as jl,b as Nl,c as Sl,d as Cl}from"./PopoverPopup-Dwzp-hyf.js";import{F as ot}from"./FadeIn-CfhgvLVd.js";import{u as Tl,a as Al,r as Dl,b as ps,P as Ml,c as Ll}from"./local-usage-transfer-BudmMtkd.js";import{L as xs}from"./LoginCard-0sIovG_J.js";import{L as El,A as Rl}from"./agent-logos-Cfx5WzU5.js";import{i as Il}from"./host-mode-Bc_iTzHk.js";import{M as pn}from"./monitor-smartphone-DtjXNC_x.js";import{C as Fl}from"./check-BHJvi4ey.js";import"./terminal-CON7n_ir.js";import"./use-limits-display-prefs-8o7pbEg0.js";import"./play-9w46lbjy.js";import"./composite-D-0pfyMY.js";import"./store-2AX2MNkz.js";import"./SelectItemText-CNuJgYps.js";import"./usePositioner-TEClK6mF.js";import"./safePolygon-B6_x12Gb.js";import"./arrow-left-D83SdANw.js";const xn={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};xn.node;const $l=Nr(xn);const gn={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"}]]};gn.node;const Pl=Nr(gn);const fn={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"]};fn.node;const Ol=Nr(fn);function zl(t,a,r={}){const s=t.get();let n=null,i=s,o;const c=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const g=gs(t.get()),m=gs(i);if(g===m){d();return}const x=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new tl({keyframes:[g,m],velocity:x,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},p=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((g,m)=>{i=g,o=x=>m(ar(x,c)),el.postRender(p)},d),on(a)){let g=r.skipInitialAnimation===!0;const m=a.on("change",f=>{g?(g=!1,t.jump(ar(f,c),!1)):t.set(ar(f,c))}),x=t.on("destroy",m);return()=>{m(),x()}}return d}function ar(t,a){return a?t+a:t}function gs(t){return typeof t=="number"?t:parseFloat(t)}function Bl(t,a={}){const{isStatic:r}=u.useContext(al),s=()=>on(t)?t.get():t;if(r)return cn(s);const n=dn(s());return u.useInsertionEffect(()=>zl(n,t,a),[n,JSON.stringify(a)]),n}function Ul(t,a={}){return Bl(t,{type:"spring",...a})}function Hl(){return e.jsxs(mi,{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 Kl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Hl,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function ql({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},c=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:c,children:t})}var Vl={};function Wl(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 Gl({mv:t,digit:a,height:r}){const s=cn(t,n=>{const i=(n%10+10)%10,o=(10+a-i)%10;let c=o*r;return o>5&&(c-=10*r),c});return e.jsx(Ve.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Yl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Jl(t,a){const r=t/a;return Math.floor(Yl(r))}function Zl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((c,d)=>/\d/.test(c)&&(s===-1||d<s)).length,i=0,o=!1;return r.map(c=>{if(!/\d/.test(c))return c==="."&&(o=!0),c;if(!o){const d=10**Math.max(n-1,0);return n-=1,d}return i+=1,10**-i})}function Ql({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=Wl(t,r),h=t!=="."&&t!==",",p=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...p?{width:d.width}:null},children:t})}const i=Jl(a,t),o=dn(0),c=Ul(o,{stiffness:220,damping:26,mass:.8});return u.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(d,h)=>e.jsx(Gl,{mv:c,digit:h,height:r},h))})}function Xl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:c=0,textColor:d="inherit",fontWeight:h="inherit",containerStyle:p,counterStyle:g,digitStyle:m,gradientHeight:x=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const v=String(a??t??""),C=u.useMemo(()=>Array.isArray(n)&&n.length?n:Zl(v),[n,v]),D=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Vl?.VITEST==="true",M=un()||D,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,I=r+s;return M?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:h,lineHeight:1,...p,...g},children:v}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...p},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:c,paddingRight:c,lineHeight:1,color:d,fontWeight:h,...g},children:C.map((N,w)=>e.jsx(Ql,{place:N,value:A,height:I,digitStyle:m,shouldReduceMotion:M},`${String(N)}-${w}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:x,background:`linear-gradient(to bottom, ${f}, ${b})`}}),e.jsx("span",{style:j??{height:x,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function ec({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:c,now:d,accountView:h=!1,accountAccessToken:p=null,accountRevision:g=0,accountViewResolving:m=!1,deviceId:x=null}={}){const f=!!(h&&p),b=f?"cloud":"local",k=u.useMemo(()=>hi({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[j,v]=u.useState([]),[C,D]=u.useState(null),[M,A]=u.useState("edge"),[I,N]=u.useState(!1),[w,T]=u.useState(null),P=pt(),z=ea(a),K=!r,E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=st([t,k.from,k.to,s,n,b,a,p,g,m,x,o,c,r,P,K,z,E]),U=u.useMemo(()=>{if(!i)return null;const G=Sr({timeZone:o,offsetMinutes:c});return`tokentracker.heatmap.${i}.${b}.${s}.${n}.${G}.${x||"all"}${f||!g?"":`.r${g}`}`},[i,x,b,o,c,s,n,f,g]),W=u.useCallback(()=>{if(!U||typeof window>"u")return null;try{const G=window.localStorage.getItem(U);if(!G)return null;const se=JSON.parse(G);return!se||!se.heatmap?null:se}catch{return null}},[U]),F=u.useCallback(G=>{if(!(!U||typeof window>"u"))try{window.localStorage.setItem(U,JSON.stringify(G))}catch{}},[U]),S=u.useCallback(()=>{if(!(!U||typeof window>"u"))try{window.localStorage.removeItem(U)}catch{}},[U]),$=u.useRef(b);u.useEffect(()=>{$.current!==b&&($.current=b,v([]),D(null),A("edge"),T(null),N(!0))},[b]);const de=u.useCallback(async()=>{const G=O(),se=await He(a),ue=f?await He(p):null;if(!G()||!se&&!P&&!E&&!f)return;if(f&&!ue){T("Your session expired. Please sign in again to view account data."),N(!1);return}const ke=f?ue:se,je=f?pi:xi,Te=f?en:tn;N(!0),T(null);try{try{const X=await je({baseUrl:t,accessToken:ke,weeks:s,to:k.to,weekStartsOn:n,device:x,timeZone:o,tzOffsetMinutes:c}),te=Array.isArray(X?.weeks)?X.weeks:[];if(!G())return;if(!te.length&&K){const ee=W();if(ee?.heatmap){if(!G())return;D(ee.heatmap),v(ee.daily||[]),A("cache");return}}if(!te.some(ee=>(Array.isArray(ee)?ee:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&te.length){const ee=[];for(const Z of te)for(const ae of Array.isArray(Z)?Z:[])ae?.day&&ee.push({day:ae.day,total_tokens:ae.total_tokens??ae.value??0,billable_total_tokens:ae.billable_total_tokens??ae.value??ae.total_tokens??0});const Y=ss({dailyRows:ee,weeks:s,to:X?.to||k.to,weekStartsOn:n});if(!G())return;v(ee),D({...Y,week_starts_on:n,active_days:ee.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ka({dailyRows:ee,to:X?.to||k.to})}),A("client"),K?F({heatmap:{...Y,week_starts_on:n,active_days:ee.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ka({dailyRows:ee,to:X?.to||k.to})},daily:ee,fetchedAt:new Date().toISOString()}):S();return}if(!G())return;D(X||null),v([]),A("edge"),X&&K?F({heatmap:X,daily:[],fetchedAt:new Date().toISOString()}):K||S();return}catch(X){const te=X,xe=te?.status??te?.statusCode;if(xe===401||xe===403)throw X}if(!G())return;const Q=await Te({baseUrl:t,accessToken:ke,from:k.from,to:k.to,device:x,timeZone:o,tzOffsetMinutes:c}),B=Array.isArray(Q?.data)?Q.data:[];if(!G())return;v(B);const ne=ss({dailyRows:B,weeks:s,to:k.to,weekStartsOn:n});if(!G())return;D({...ne,week_starts_on:n,active_days:B.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ka({dailyRows:B,to:k.to})}),A("client"),K?F({heatmap:{...ne,week_starts_on:n,active_days:B.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ka({dailyRows:B,to:k.to})},daily:B,fetchedAt:new Date().toISOString()}):S()}catch(Q){if(!G())return;if(K){const B=W();if(B?.heatmap){if(!G())return;D(B.heatmap),v(B.daily||[]),A("cache"),T(null)}else{const ne=Q;T(ne?.message||String(ne)),v([]),D(null),A("edge")}}else{const B=Q;T(B?.message||String(B)),v([]),D(null),A("edge")}}finally{G()&&N(!1)}},[a,t,P,r,K,k.from,k.to,W,z,o,c,n,s,S,F,E,f,p,g,x,O]);return u.useEffect(()=>{if(m){N(!0);return}if(!z&&!r&&!P&&!E&&!f){v([]),N(!1),T(null),D(null),A("edge");return}if(!K)S(),v([]),T(null),D(null),A("edge");else{const G=W();G?.heatmap&&(D(G.heatmap),v(G.daily||[]),A("cache"))}de()},[a,P,W,de,z,r,K,S,E,m]),{range:k,daily:j,heatmap:C,source:P?"mock":M==="client"?"edge":M,loading:I,error:w,refresh:de}}const tc="tokentracker.dashboard.leftCardOrder.v1",ac="tokentracker.dashboard.rightCardOrder.v1";function rc(t,a){const r=us(tc,t),s=us(ac,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=u.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const sc=10;function nc({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[c,d]=u.useState([]),[h,p]=u.useState(!1),[g,m]=u.useState(null),x=pt(),f=ea(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,i,o]),j=u.useCallback(async()=>{const v=k(),C=await He(a);if(v()){if(!C&&!x&&!b){d([]),m(null),p(!1);return}p(!0),m(null);try{const D=await gi({baseUrl:t,accessToken:C,limit:sc,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!v())return;d(Array.isArray(D?.entries)?D.entries:[])}catch(D){if(!v())return;const M=D?.message||String(D);m(M),d([])}finally{v()&&p(!1)}}},[a,t,r,x,n,i,s,o,b,k]);return u.useEffect(()=>{if(!f&&!x&&!b){d([]),m(null),p(!1);return}d([]),m(null),p(!0),j()},[x,j,f,b]),{entries:c,loading:h,error:g,refresh:j}}const fs="tokentracker.usage-cache-index",ys=24;function bs({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:c,timeZone:d,tzOffsetMinutes:h,now:p,accountView:g=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(g&&m),j=k?"cloud":"local",[v,C]=u.useState([]),[D,M]=u.useState(null),[A,I]=u.useState(null),[N,w]=u.useState("edge"),[T,P]=u.useState(null),[z,K]=u.useState(!1),[E,O]=u.useState(null),U=pt(),W=ea(a),F=!r&&!U,S=b||"all",$=(()=>{if(!c)return null;const Q=oc(t)||"default",B=i?o?"daily-summary":"daily-only":"summary",ne=Sr({timeZone:d,offsetMinutes:h});return`tokentracker.usage.${c}.${j}.${Q}.${s}.${n}.${B}.${ne}.${S}${k||!x?"":`.r${x}`}`})(),de=u.useRef(j);u.useEffect(()=>{de.current!==j&&(de.current=j,C([]),M(null),I(null),w("edge"),P(null),O(null),K(!0))},[j]);const ie=u.useCallback(()=>{if(!$||typeof window>"u")return null;try{const Q=window.localStorage.getItem($);if(!Q)return null;const B=JSON.parse(Q),ne=o?!!B?.summary:Array.isArray(B?.daily);return!B||!ne?null:(ms(fs,$,ys),B)}catch{return null}},[o,$]),G=u.useCallback(Q=>{if(!(!$||typeof window>"u"))try{window.localStorage.setItem($,JSON.stringify(Q)),ms(fs,$,ys)}catch{}},[$]),se=u.useCallback(()=>{if(!(!$||typeof window>"u"))try{window.localStorage.removeItem($)}catch{}},[$]),ue=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),ke=st([t,s,n,i,o,j,a,m,x,b,d,h,r,U,F,f,W,ue]),je=u.useCallback(async()=>{const Q=ke(),B=await He(a),ne=k?await He(m):null;if(!Q()||!B&&!U&&!ue&&!k)return;if(k&&!ne){O("Your session expired. Please sign in again to view account data."),K(!1);return}const X=k?en:tn,te=k?fi:yi,xe=k?ne:B;K(!0),O(null);try{let ee=null,Y=null;if(i)if(o){const[Fe,$e]=await Promise.allSettled([X({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h}),te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0})]);if(Fe.status==="rejected")throw Fe.reason;ee=Fe.value,Y=$e.status==="fulfilled"?$e.value:null}else ee=await X({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h});else o&&(Y=await te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0}));let Z=i&&Array.isArray(ee?.data)?ee.data:[];i&&(Z=sr(Z,s,n,{timeZone:d,offsetMinutes:h,now:p}));let ae=o&&(Y?.totals||ee?.summary?.totals)||null,Se=o&&(Y?.rolling||ee?.summary?.rolling)||null;if(o&&i&&!ae&&!Y)try{const Fe=await te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0});ae=Fe?.totals||null,Se=Fe?.rolling||Se}catch{}const Ae=new Date().toISOString();if(!Q())return;C(Z),M(ae),I(Se),w("edge"),P(Ae),(ae||!o&&i)&&F?G({summary:ae,rolling:Se,daily:Z,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:Ae}):F||se()}catch(ee){if(!Q())return;if(F){const Y=ie();if(Y?.summary||!o&&Array.isArray(Y?.daily)){M(Y.summary),I(Y.rolling||null);const Z=Array.isArray(Y.daily)?Y.daily:[],ae=i?sr(Z,Y.from||s,Y.to||n,{timeZone:d,offsetMinutes:h,now:p}):Z;C(ae),w("cache"),P(Y.fetchedAt||null),O(null)}else{const Z=ee;O(Z?.message||String(Z)),C([]),M(null),I(null),w("edge"),P(null)}}else{const Y=ee;O(Y?.message||String(Y)),C([]),M(null),I(null),w("edge"),P(null)}}finally{Q()&&K(!1)}},[a,t,s,i,o,U,r,F,p,ie,W,d,n,h,se,G,ue,k,m,x,b,ke]);return u.useEffect(()=>{if(f){K(!0);return}const Q=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!W&&!r&&!U&&!Q&&!k){C([]),M(null),I(null),O(null),K(!1),w("edge"),P(null);return}if(!F)se(),C([]),M(null),I(null),O(null),w("edge"),P(null);else{const B=ie();if(B?.summary||!o&&Array.isArray(B?.daily)){M(B.summary),I(B.rolling||null);const ne=Array.isArray(B.daily)?B.daily:[],X=i?sr(ne,B.from||s,B.to||n,{timeZone:d,offsetMinutes:h,now:p}):ne;C(X),w("cache"),P(B.fetchedAt||null),O(null)}else C([]),M(null),I(null),w("edge"),P(null),O(null)}K(!0),je()},[a,U,ie,je,W,r,F,se,ue,f,o]),u.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const Q=15e3;let B=Date.now();const ne=()=>{if(document.visibilityState!=="visible")return;const X=Date.now();X-B<Q||(B=X,je())};return window.addEventListener("focus",ne),document.addEventListener("visibilitychange",ne),()=>{window.removeEventListener("focus",ne),document.removeEventListener("visibilitychange",ne)}},[je]),{daily:v,summary:D,rolling:A,source:U?"mock":N,fetchedAt:T,loading:z,error:E,refresh:je}}function oc(t){try{return new URL(t).host}catch{return null}}function rr(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Jt(o)===a?o:null}function ic(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function sr(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=rr(a),c=rr(r);if(!o||!c||c<o)return Array.isArray(t)?t:[];const d=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=Cr({timeZone:s,offsetMinutes:n,date:d}),p=rr(h),g=p?p.getTime():d.getTime(),m=new Map;for(const f of t||[])f?.day&&m.set(f.day,f);const x=[];for(let f=o;f<=c;f=ic(f,1)){const b=Jt(f),k=m.get(b),j=f.getTime()>g;if(k){x.push({...k,missing:!1,future:j});continue}x.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 x}function lc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:c,accountView:d=!1,accountAccessToken:h=null,accountRevision:p=0,accountViewResolving:g=!1,deviceId:m=null}={}){const x=!!(d&&h),f=x?"cloud":"local",[b,k]=u.useState(null),[j,v]=u.useState("edge"),[C,D]=u.useState(!1),[M,A]=u.useState(null),I=pt(),N=ea(a),w=!r,T=u.useMemo(()=>{if(!i)return null;const S=cc(t)||"default",$=Sr({timeZone:o,offsetMinutes:c});return`tokentracker.modelBreakdown.${i}.${f}.${S}.${s}.${n}.${$}.${m||"all"}${x||!p?"":`.r${p}`}`},[t,i,m,s,f,o,n,c,x,p]),P=u.useCallback(()=>{if(!T||typeof window>"u")return null;try{const S=window.localStorage.getItem(T);if(!S)return null;const $=JSON.parse(S);return!$||!$.breakdown?null:$}catch{return null}},[T]),z=u.useCallback(S=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(S))}catch{}},[T]),K=u.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=st([t,s,n,f,a,h,p,m,o,c,r,I,w,g,N,E]),U=u.useRef(f);u.useEffect(()=>{U.current!==f&&(U.current=f,k(null),v("edge"),A(null),D(!0))},[f]);const W=u.useCallback(async()=>{const S=O(),$=await He(a),de=x?await He(h):null;if(!S()||!$&&!I&&!E&&!x)return;if(x&&!de){A("Your session expired. Please sign in again to view account data."),D(!1);return}const ie=x?de:$,G=x?bi:ki;D(!0),A(null);try{const se=await G({baseUrl:t,accessToken:ie,from:s,to:n,device:m,timeZone:o,tzOffsetMinutes:c});if(!S())return;k(se||null),v("edge"),se&&w?z({breakdown:se,fetchedAt:new Date().toISOString()}):w||K()}catch(se){if(!S())return;if(w){const ue=P();if(ue?.breakdown)k(ue.breakdown),v("cache"),A(null);else{k(null),v("edge");const ke=se;A(ke?.message||String(ke))}}else{k(null),v("edge");const ue=se;A(ue?.message||String(ue))}}finally{S()&&D(!1)}},[a,t,s,I,r,w,P,o,n,N,c,K,z,E,x,h,p,m,O]);return u.useEffect(()=>{if(g){D(!0);return}if(!N&&!r&&!I&&!E&&!x){k(null),v("edge"),A(null),D(!1);return}if(!w)K(),k(null),v("edge"),A(null);else{const S=P();S?.breakdown?(k(S.breakdown),v("cache"),A(null)):(k(null),v("edge"),A(null))}D(!0),W()},[a,I,P,W,N,r,w,K,E,g]),{breakdown:b,source:I?"mock":j,loading:C,error:M,refresh:W}}function cc(t){try{return new URL(t).host}catch{return null}}const yn=new Set(["day","hour","month"]);function dc(t){return yn.has(t)}function ks(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 uc(t,a){const r=ks(t),s=ks(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=H(t),i=H(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function mc(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 hc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function pc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function xc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),c=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(c)||!Number.isFinite(d)||n<1||n>12||i<1||i>31||o<0||o>23||c<0||c>59||d<0||d>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,c,d));return Number.isFinite(h.getTime())?h.getTime():null}function gc(t,a,r){const s=r==="hour"?xc:r==="month"?pc:hc,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:mc(t,a)}function bn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=yn.has(a)?(c,d)=>gc(c,d,a):uc,o=c=>a==="total_tokens"&&c?.billable_total_tokens!=null?c.billable_total_tokens:c?.[a];return n.map((c,d)=>({row:c,index:d})).sort((c,d)=>{const h=o(c.row),p=o(d.row),g=h==null,m=p==null;if(g&&m)return c.index-d.index;if(g)return 1;if(m)return-1;const x=i(h,p);return x!==0?x*s:c.index-d.index}).map(c=>c.row)}function fc(){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 _s(t){const a=dc(t)?t:"day";return fc().map((r,s)=>s===0?{...r,key:a}:r)}function ws(t,{key:a,dir:r}){return bn(t,{key:a,dir:r})}const Da=12,yc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function bc(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 kc(t){return yc.some(a=>bc(t?.[a]))}function _c(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=bn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&kc(n));return s===-1?a:r.slice(s)}function wc(t,a,r=Da){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Da,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function vc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const va=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function jc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return va.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?va.active:s<=60*6e4?va.warm:va.idle}const Nc=3e4;function Sc({refresh:t,intervalMs:a=Nc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,c=Date.now(),d=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const x=Promise.resolve().then(()=>t()).catch(f=>n(f)).then(()=>{}).finally(()=>{o===x&&(o=null)});return o=x,x},p=r.setInterval(()=>{const x=Date.now();x<d||(d=x+jc({visible:s.visibilityState==="visible",lastInteractionAt:c,now:x}),h())},a),g=()=>{s.visibilityState==="visible"&&(c=Date.now(),d=0,h())},m=()=>{c=Date.now()};return r.addEventListener("focus",g),r.addEventListener("pointerdown",m),r.addEventListener("keydown",m),s.addEventListener("visibilitychange",g),{run:h,stop(){i=!0,r.clearInterval(p),r.removeEventListener("focus",g),r.removeEventListener("pointerdown",m),r.removeEventListener("keydown",m),s.removeEventListener("visibilitychange",g)}}}function Cc(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 Jt(r)===t?r:null}function Tc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=Cc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Jt(i),to:Jt(n)}}function Ac(t,{period:a}={}){const r=(Array.isArray(t)?t:[]).filter(n=>!n?.future&&n?.day);return(a==="total"?r.filter(n=>!n?.missing):r).slice(-30)}function Ar(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Dc(t){const a=Ar(t?.model_id);return a||null}function kn(t,a){return t?.model?String(t.model):a}function _n(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Ar(n);if(!i||i.includes("/"))continue;const o=Math.max(0,H(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function wn(t,a){const r=Ar(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function Tt(t,a=0){const r=H(t?.billable_total_tokens),s=H(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Mc={deepseek:"dsh"};function Lc(t){const a=typeof t=="string"?t:"";return Mc[a]||a}const Ec=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count"],Dr=["input","output","cached","cacheCreate","reasoning"];function Ma(t){let a=0;for(const r of Dr)a+=Math.max(0,Number(t?.[r])||0);return a}function Rc(t){return Ma(t?.tokens)>0}const Qt=["priority","ultrafast"],vn=Dr,Ic={priority:{tokens:{input:"priority_input_tokens",cached:"priority_cached_input_tokens",cacheCreate:"priority_cache_creation_input_tokens",output:"priority_output_tokens",reasoning:"priority_reasoning_output_tokens"},cost:"priority_cost_usd"},ultrafast:{tokens:{input:"ultrafast_input_tokens",cached:"ultrafast_cached_input_tokens",cacheCreate:"ultrafast_cache_creation_input_tokens",output:"ultrafast_output_tokens",reasoning:"ultrafast_reasoning_output_tokens"},cost:"ultrafast_cost_usd"}};function Fc(t){const a={};let r=!1;for(const s of Qt){const n=Ic[s],i={input:Math.max(0,H(t?.[n.tokens.input])??0),output:Math.max(0,H(t?.[n.tokens.output])??0),cached:Math.max(0,H(t?.[n.tokens.cached])??0),cacheCreate:Math.max(0,H(t?.[n.tokens.cacheCreate])??0),reasoning:Math.max(0,H(t?.[n.tokens.reasoning])??0)},o=Math.max(0,H(t?.[n.cost])??0);Ma(i)<=0&&o<=0||(a[s]={tokens:i,cost:o},r=!0)}return r?a:null}function jn(t,a){if(!a||!Object.keys(a).length)return t;const r={...t||{}};for(const s of Qt){const n=a[s];if(!n)continue;const i=r[s];if(!i){r[s]={tokens:{...n.tokens},cost:n.cost};continue}for(const o of vn)i.tokens[o]+=n.tokens[o]||0;i.cost+=n.cost||0}return r}function Nn(t){return!!(t?.tiers?.priority||t?.tiers?.ultrafast)}function $c(t,a){const r=Number(t?.pricing?.[`${a}_multiplier`]);return Number.isFinite(r)&&r>1?r:0}function Pc(t){if(!Nn(t))return null;const a={input:0,output:0,cached:0,cacheCreate:0,reasoning:0};let r=!1;for(const n of vn){let i=Math.max(0,Number(t?.tokens?.[n])||0);for(const o of Qt)i-=Math.max(0,Number(t?.tiers?.[o]?.tokens?.[n])||0);a[n]=Math.max(0,i),a[n]>0&&(r=!0)}let s=Math.max(0,H(t?.cost)??0);for(const n of Qt)s-=Math.max(0,Number(t?.tiers?.[n]?.cost)||0);return s=Math.max(0,s),!r&&s<=0?null:{tokens:a,cost:s}}function Mr(t){return t?.unpriced===!0?!0:t?.costSource!=="provider_reported"&&t?.pricing?.status==="unpriced"}function vs(t,a){for(const r of Ec)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 js(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,conversation_count:0,total_cost_usd:"0"}}function Oc(t){const a=new Map;for(const r of t||[]){const s=Lc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:js(),models:new Map},a.set(s,n)),vs(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let c=n.models.get(o);const d=Fc(i?.totals);c?c.tiers=jn(c.tiers??null,d):(c={...i,model:i?.model||o,model_id:o,totals:js()},c.tiers=d,n.models.set(o,c)),vs(c.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function zc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=Oc(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const c=Tt(o?.totals),d=H(o?.totals?.total_cost_usd)??0,h=Math.max(0,H(o?.totals?.conversation_count)??0);return{source:o?.source,totalTokens:Number.isFinite(c)?c:0,totalRequests:h,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,H(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,H(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,H(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0||o.totalRequests>0);if(!n.length)return[];const i=n.reduce((o,c)=>o+c.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,c)=>c.totalTokens-o.totalTokens||c.totalRequests-o.totalRequests).map(o=>{const c=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),d=i>0?o.totalTokens/i*100:0,h=Number.isFinite(d)?d.toFixed(2):"0.00",p=o.models.map(f=>{const b=Tt(f?.totals),k=Math.max(0,H(f?.totals?.conversation_count)??0);if((!Number.isFinite(b)||b<=0)&&k<=0)return null;const j=o.totalTokens>0?Math.round(b/o.totalTokens*1e3)/10:0,v=kn(f,r("shared.placeholder.short")),C=Dc(f),D=H(f?.totals?.total_cost_usd),M=b<=0?null:D??(o.totalCost>0&&o.totalTokens>0?b/o.totalTokens*o.totalCost:null),A=f?.totals||{};return{id:C,name:v,share:j,usage:b,requests:k,cost:M,tokens:{input:Math.max(0,H(A?.input_tokens)??0),output:Math.max(0,H(A?.output_tokens)??0),cached:Math.max(0,H(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,H(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,H(A?.reasoning_output_tokens)??0)},tiers:f?.tiers??null,pricing:f?.pricing||null,costSource:f?.cost_source||null}}).filter(Boolean),g=o.inputTokens+o.cacheRead+o.cacheCreate,x=o.cacheRead+o.cacheCreate>0&&g>0?Math.round(o.cacheRead/g*100):null;return{source:o.source,label:c,totalPercent:String(h),totalPercentValue:d,usd:o.totalCost,usage:o.totalTokens,requests:o.totalRequests,cacheHitRate:x,cacheReusedTokens:o.cacheRead,cacheInputTokens:g,models:p}})}function Bc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const c=Array.isArray(o?.models)?o.models:[];for(const d of c){const h=H(d?.usage),p=Math.max(0,H(d?.requests)??0);if((h==null||h<=0)&&p<=0)continue;const g=h??0,m=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;m&&s.push({model:d,name:m,usage:g,requests:p})}}const n=_n(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:c,usage:d,requests:h}of s){const p=wn(c,n);if(!p)continue;const{key:g}=p,m=r.get(g)||{id:g,name:p.name,usage:0,requests:0,cost:0,hasCost:!1,unpriced:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0},tiers:null,pricing:null};m.usage+=d,m.requests+=h;const x=o?.tokens||{};for(const b of Dr)m.tokens[b]+=Math.max(0,Number(x[b])||0);m.tiers=jn(m.tiers,o?.tiers??null),!m.pricing&&o?.pricing&&(m.pricing=o.pricing),d>0&&Mr(o)&&(m.unpriced=!0);const f=H(o?.cost);f!=null&&(m.cost+=f,m.hasCost=!0),n.has(g)?m.name=n.get(g):d>=m.nameWeight&&(m.name=c,m.nameWeight=d),r.set(g,m)}const i=Array.from(r.values()).reduce((o,c)=>o+c.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,requests:o.requests,cost:o.hasCost?o.cost:null,unpriced:o.unpriced===!0,tokens:{...o.tokens},tiers:o.tiers,pricing:o.pricing,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,c)=>c.usage!==o.usage?c.usage-o.usage:String(o.name).localeCompare(String(c.name)))}function Uc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:f=>f,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const i=new Map,o=new Map,c=new Map,d=[];let h=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const j=Tt(k?.totals);if(!Number.isFinite(j)||j<=0)continue;h+=j;const v=kn(k,s("shared.placeholder.short"));d.push({name:v,tokens:j})}}const p=_n(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=wn(f,p);if(!k)continue;const{key:j}=k;i.set(j,(i.get(j)||0)+b),p.has(j)?o.set(j,p.get(j)):b>=(c.get(j)||0)&&(c.set(j,b),o.set(j,f))}if(!i.size)return[];const g=Array.from(i.values()).reduce((f,b)=>f+b,0),m=h>0?h:g,x=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([f,b])=>{const k=m>0?(b/m*100).toFixed(1):"0.0";return{id:f,name:o.get(f)||s("shared.placeholder.short"),tokens:b,percent:String(k)}}).sort((f,b)=>b.tokens!==f.tokens?b.tokens-f.tokens:String(f.name).localeCompare(String(b.name))).slice(0,x)}function Hc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=ta(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function Ns(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Zt(a);return(a===an?t:t*r)<.01?`<${s}0.01`:ta(t,{decimals:2,currency:a,rate:r})}function Ss(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const Kc=St.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=aa(),o=u.useMemo(()=>(Array.isArray(s)?s:[]).map(h=>{const p=H(h?.usd)??0,g=H(h?.usage)??0,m=Array.isArray(h?.models)?h.models:[];return{label:h?.label?String(h.label):"",usdValue:p,costLabel:Ns(p,n,i),tokensLabel:Ss(g),models:m.map(x=>{const f=H(x?.usage)??0,b=H(x?.cost)??0;return{id:x?.id?String(x.id):"",name:x?.name?String(x.name):"",tokensLabel:Ss(f),costLabel:Ns(b,n,i),sortCost:b,pricing:x?.pricing,costSource:x?.costSource,tokens:x?.tokens}}).filter(x=>x.costLabel||x.tokensLabel).sort((x,f)=>f.sortCost-x.sortCost)}}).filter(h=>h.usdValue>0||h.models.length>0).sort((h,p)=>p.usdValue-h.usdValue),[s,n,i]),c=o.some(h=>h.models.some(p=>Mr(p))),d=u.useMemo(()=>{const h=o.reduce((p,g)=>p+g.usdValue,0);return c&&h===0?l("dashboard.cost_breakdown.unpriced_label"):`${c?"≥":""}${Hc(h,n,i)}`},[o,n,i,c]);return e.jsx(ml,{open:a,onOpenChange:h=>{h||r?.()},children:e.jsxs(hl,{children:[e.jsx(pl,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(xl,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(gl,{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(fl,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(yl,{type:"button",className:"absolute top-3 right-3 flex h-9 w-9 items-center justify-center rounded-md text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-100 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50 transition-colors z-10","aria-label":l("dashboard.cost_breakdown.close"),children:e.jsx(Tr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:c?l("dashboard.cost_breakdown.known_subtotal"):l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:d}),e.jsx("p",{className:"mb-4 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.method")}),o.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),o.map((h,p)=>{const g=`fleet-${p}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":g,className:p>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:g,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:h.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:h.costLabel||"—"})]}),h.models.map((m,x)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:m.name,children:m.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:m.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):m.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),m.pricing?.status==="unpriced"&&m.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,m.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,m.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(m.tokens.input)||0),output:Ie(Number(m.tokens.output)||0),read:Ie(Number(m.tokens.cached)||0),write:Ie(Number(m.tokens.cacheCreate)||0)})}):null,m.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:m.pricing.input,output:m.pricing.output,read:m.pricing.cache_read,write:m.pricing.cache_write})}):null]})]}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:m.costLabel||(m.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):m.pricing?.status==="free"?ta(0,{currency:n,rate:i}):l("dashboard.cost_breakdown.rate_unknown"))})]},m.id||`${m.name}-${x}`))]},`${h.label}-${p}`)})]})]})})]})})]})})});function qc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,p]=u.useState(null),g=pt(),m=st([t,a,r,s,n,g]);return u.useEffect(()=>{const x=m();if(!t){o(null),p(null),d(!1);return}d(!0),o(null),p(null),_i({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{x()&&o(f||null)}).catch(f=>{x()&&(p(f?.message||String(f)),o(null))}).finally(()=>{x()&&d(!1)})},[t,a,r,s,n,g,m]),{data:i,loading:c,error:h}}function Sn(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 Cn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function Tn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function An(t,a){return a&&Tn(Cn(t))==="github"?a:""}function Dn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=u.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const Cs="#10b981",nr=[{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"}],or=60;function Vc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(m=>[m.day,m]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const c=t[t.length-1].day;o<c&&(o=c);const d=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(h.getTime()))return t;const p=Math.round((h.getTime()-d.getTime())/864e5)+1;p>or&&d.setUTCDate(d.getUTCDate()+(p-or));const g=[];for(;d.getTime()<=h.getTime()&&g.length<or;){const m=d.toISOString().slice(0,10);g.push(n.get(m)||{day:m,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return g}function ir(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function Nt({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=Tn(t);return r==="github"||r==="gitlab"?a=e.jsx(At,{provider:r,size:12,className:"fill-current"}):a=e.jsx($l,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function lr({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 Gc({entry:t,query:a={},onClose:r}){const[s,n]=St.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:c}=Sn(i),d=typeof t?.project_ref=="string"?t.project_ref:"",h=Cn(d),{data:p,loading:g,error:m}=qc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:x,formatTokensTooltip:f}=Ne(),b=St.useCallback(()=>n(!0),[]),k=E=>{E.target===E.currentTarget&&s&&r()};St.useEffect(()=>{const E=O=>{O.key==="Escape"&&b()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[b]);const j=p?.totals||null,v=H(j?.billable_total_tokens)??0,C=Number(p?.days_active||0),D=H(j?.input_tokens)??0,M=H(j?.cached_input_tokens)??0,A=D+M>0?M/(D+M):null,I=H(p?.range_total_tokens)??0,N=H(j?.total_tokens)??0,w=I>0?N/I:null,T=St.useMemo(()=>Vc(p?.daily,p?.from,p?.to,Cr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[p,a.timeZone,a.tzOffsetMinutes]),P=nr.reduce((E,O)=>E+(H(j?.[O.key])??0),0),z=Array.isArray(p?.sources)?p.sources:[],K=!g&&!m&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:E=>{E.target===E.currentTarget&&b()},className:Ct("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i,className:Ct("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:b,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(Tr,{size:16})}),e.jsxs("div",{className:"w-full md:w-[300px] shrink-0 border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-5 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:Cs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:Cs}})]}),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(Dn,{githubOwner:An(d,o),letter:(c?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:c||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(Wc,{host:h}),h&&p?.from&&p?.to?e.jsx("span",{children:"·"}):null,p?.from&&p?.to?e.jsxs("span",{className:"tabular-nums",children:[p.from," – ",p.to]}):null]})]}),K?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(Nt,{label:l("dashboard.projects.detail.stat_total"),value:x(v),title:f(v)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_share"),value:w==null?"—":ir(w)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":ir(A)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_conversations"),value:Aa(j.conversation_count)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_active_days"),value:Aa(C)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_avg_day"),value:C>0?x(Math.round(v/C)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[g&&e.jsxs("div",{className:"space-y-4 p-5 md:p-6",children:[e.jsx("div",{className:"h-32 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-24 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"})]}),!g&&m&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!g&&!m&&!K&&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")}),K&&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(lr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(nn,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),P>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(lr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:nr.map(E=>{const O=H(j[E.key])??0;return O<=0?null:e.jsx("div",{style:{width:`${O/P*100}%`,backgroundColor:E.color,minWidth:"2px"}},E.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:nr.map(E=>{const O=H(j[E.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:E.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(E.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:x(O)})]},E.key)})})]}),z.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(lr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:z.map(E=>{const O=Number(E.total_tokens||0),U=N>0?O/N:0,W=U*100,F=Number(E.conversation_count||0),S=Ji(E.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(At,{provider:E.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:ut(E.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(E.days_active||0)}),F>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:F})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:x(O)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:ir(U)})]}),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(W,O>0?1:0))}%`,minWidth:O>0?"3px":0,backgroundColor:S}})})]},E.source)})})]})]})]})]})})}function Yc(t){return e.jsx(wi,{mode:Yt.COMPACT,children:e.jsx(Gc,{...t})})}const Jc=5;function Zc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",c=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:h}=Sn(o),p=An(c,d),g=H(t?.billable_total_tokens??t?.total_tokens)??0,m=a>0?Math.min(100,Math.max(2,g/a*100)):0,x=Array.isArray(t?.sources)?t.sources:[],f=x.slice(0,Jc),b=x.length-f.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(Dn,{githubOwner:p,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[d?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[d,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:h||o||"—"})]}),f.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[f.map(k=>e.jsx(At,{provider:k.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},k.source)),b>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:b})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(g),children:s(g)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${m}%`,minWidth:g>0?"3px":0}})})]})]})}function Qc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:c,dailyEmptySuffix:d,detailsColumns:h,ariaSortFor:p,toggleSort:g,sortIconFor:m,pagedDetails:x,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:v="day",detailsDateKey:C,renderDetailDate:D,renderDailyBreakdownDate:M,renderDetailCell:A,DETAILS_PAGED_PERIODS:I,period:N,detailsPageCount:w,detailsPage:T,setDetailsPage:P}){const[z,K]=u.useState("daily"),[E,O]=u.useState(null),{formatTokens:U,formatTokensTooltip:W}=Ne();return e.jsxs(De,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${z==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":z==="daily",type:"button",onClick:()=>K("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":z==="projects",type:"button",onClick:()=>K("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),z==="projects"&&e.jsx(ln,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:F=>r?.(Number(F)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),z==="projects"&&(()=>{const F=t.slice(0,a);if(F.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const S=F.reduce(($,de)=>{const ie=H(de?.billable_total_tokens??de?.total_tokens)??0;return ie>$?ie:$},0);return e.jsx("div",{className:"space-y-1",children:F.map(($,de)=>e.jsx(Zc,{entry:$,maxTokens:S,copy:n,formatTokens:U,formatTokensTooltip:W,onSelect:O},$?.project_key||$?.project_ref||`entry-${de}`))})})(),E&&e.jsx(Yc,{entry:E,query:s,onClose:()=>O(null)}),z==="daily"&&e.jsxs("div",{children:[f?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:c}),d]}):e.jsx("div",{className:"overflow-auto max-h-[384px] -mx-4 oai-scrollbar",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsx("tr",{className:"border-b border-oai-gray-200 dark:border-oai-gray-700",children:b.map(F=>e.jsx("th",{"aria-sort":k?.(F.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>g(F.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:F.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(F.key)||""})]})})},F.key))})}),e.jsx("tbody",{children:f.map(F=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${F.missing?"text-oai-gray-400 dark:text-oai-gray-400":F.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:M?M(F):D(F)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(F,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"conversation_count")})]},String(F?.[v]||F?.day||F?.hour||F?.month||"")))})]})}),z!=="daily"&&I.has(N)&&w>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>P(F=>Math.max(0,F-1)),disabled:T===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[T+1," / ",w]}),e.jsx("button",{type:"button",onClick:()=>P(F=>Math.min(w-1,F+1)),disabled:T+1>=w,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 Ta(t){return typeof t!="string"?"":t.trim()}function Ts(t){const a=Ta(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Xc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Ta(r.tool),n=Ta(r.planType)||Ta(r.plan_type);if(!s||!n)continue;const i=Ts(s)||s,o=Ts(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function ed({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:c}=Ne(),d=l("shared.placeholder.short"),h=l("shared.unit.percent"),p=t??l("identity_card.rank_placeholder"),g=Number.isFinite(Number(a))?Number(a):0,m=g?l("identity_card.streak_value",{days:g}):l("identity_card.rank_placeholder"),x=Xc(r),f={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev"),trillionSuffix:l("shared.unit.trillion_abbrev")},b=v=>{if(v==null)return d;const C=Ie(v,f);return C==="-"?d:C},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=i.slice(0,3);return e.jsxs(De,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),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((v,C)=>{const D=v?.name?String(v.name):d,M=v?.percent?String(v.percent):"",A=C===j.length-1,I=C+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:I}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:D,children:D}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[M,h]})]},v.id||D)})}),x.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:x.map((v,C)=>e.jsxs(ql,{variant:"secondary",size:"sm",children:[v.tool," ",v.plan]},`${v.tool}:${v.plan}:${C}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:p})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]})]})]})}let ja=null;function td(){if(ja===null)try{ja=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{ja=!1}return ja}function ad(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,c=t-.1055613458*n-.0638541728*i,d=t-.0894841775*n-1.291485548*i,h=o*o*o,p=c*c*c,g=d*d*d;return[4.0767416621*h-3.3077115913*p+.2309699292*g,-1.2684380046*h+2.6097574011*p-.3413193965*g,-.0041960863*h-.7034186147*p+1.707614701*g].map(x=>{const f=Math.min(1,Math.max(0,x)),b=f<=.0031308?12.92*f:1.055*Math.pow(f,1/2.4)-.055;return Math.round(b*255)})}function Mn(t,a,r,s){if(td())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=ad(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function Dt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Mn(Number(a[1]),Number(a[2]),Number(a[3])):t}const As={claude:35,codex:250,grok:200},Ds={system_prompt:{l:.55,c:.05},messages:{l:.65,c:.18},tool_calls:{l:.6,c:.14},custom_agents:{l:.55,c:.1},reasoning:{l:.7,c:.08}};function rd(t,a){const r=As[a]??As.claude,s=Ds[t]||Ds.system_prompt;return Mn(s.l,s.c,r)}const sd=[{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"]}],nd=[["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"]],od={duration:.18,ease:[.4,0,.2,1]},id={height:0,opacity:0},ld={height:"auto",opacity:1},cd={height:0,opacity:0};function dd(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function ud(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 Ln(t,a=null){const r=t.reduce((o,c)=>o+Number(c.totals.total_tokens||0),0),s=dd(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const c=i===1?o.totals:ud(o.totals,i);return{...o,totals:c,percent:n>0?Number((c.total_tokens/n*100).toFixed(2)):0}}).sort((o,c)=>c.totals.total_tokens-o.totals.total_tokens)}function md(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=sd.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const c=r.get(o);if(!c)continue;const d=c.totals||{};i.input_tokens+=d.input_tokens||0,i.cached_input_tokens+=d.cached_input_tokens||0,i.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,i.output_tokens+=d.output_tokens||0,i.reasoning_output_tokens+=d.reasoning_output_tokens||0,i.total_tokens+=d.total_tokens||0}return{key:n.key,totals:i}});return Ln(s,a)}function hd(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,p)=>p?.name==="Text Response"?h:h+Number(p?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),d=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return Ln(d,a)}const Ms="MCP: ";function pd(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(Ms)?(a.push({...n,name:i.slice(Ms.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function Ls(t){return l(`dashboard.context_breakdown.category.${t}`)}function xd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function gd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),c=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:xd(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(c||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function fd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),c=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:c,total_tokens:Number(r.total_tokens||n+i)},tools:gd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function yd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function bd(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 kd(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 _d(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function Es(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 wd(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 Rs(t){return t==="exec_command"||t==="Bash"}function En(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function vd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function jd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const Nd=10;function Qe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:c,tokens:d,percent:h=null,children:p,share:g=null,fillColor:m=null}){const x=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",f=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:Nd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:x,children:r}),s,i&&e.jsx(Ve.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(ji,{size:11})})]}),k=m&&g!=null&&g>0,j=k?Math.max(0,Math.min(100,g)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:k?{backgroundImage:`linear-gradient(to right, ${m.replace(/\)\s*$/," / 0.10)")} 0%, ${m.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:c,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:b}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:b}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:d||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:h||""})]}),i&&p?e.jsx(hn,{initial:!1,children:o&&e.jsx(Ve.div,{initial:id,animate:ld,exit:cd,transition:od,style:{overflow:"hidden"},children:p},"content")}):null]})}function Is({execDetails:t,source:a="claude"}){const{formatTokens:r}=Ne(),[s,n]=u.useState("by_type"),i=_d(wd(t,s)),o=a==="codex"||a==="grok",c=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:nd.map(([d,h])=>e.jsx("button",{type:"button",onClick:()=>n(d),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===d?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(h)},d))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${c} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((d,h)=>e.jsxs(Ve.div,{role:"row",className:`grid ${c} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:d.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.failures||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Es(d.duration_ms||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Es(d.max_duration_ms||0)})]}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:r(d.totals.total_tokens||0)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.output_lines||0)})]},d.name))]})})]})}function Wt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Ne(),[i,o]=u.useState({}),[c,d]=u.useState(!1),h=fd(t?.categories||[]);function p(g){o(m=>({...m,[g]:!m[g]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(En(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(g=>{const m=g.toolCount>0,x=g.name==="Execution"&&a,f=x&&g.tools.some(k=>Rs(k.name)),b=!!i[g.name];return e.jsxs(Qe,{level:1,label:g.name,labelTone:"strong",hasChevron:m||x&&!f,open:b||x&&!f&&c,onToggle:()=>{m?p(g.name):x&&!f&&d(k=>!k)},tokens:n(g.totals.total_tokens||0),percent:null,children:[m&&e.jsx("ul",{className:"space-y-0.5",children:g.tools.map(k=>{const j=x&&Rs(k.name);return e.jsx(Qe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:c,onToggle:()=>d(v=>!v),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(Is,{execDetails:a,source:r})},k.name)})}),x&&!f&&e.jsx(Is,{execDetails:a,source:r})]},g.name)})})}function Sd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null,deviceId:i=null}){const{formatTokens:o}=Ne(),[c,d]=u.useState(null),[h,p]=u.useState(!1),[g,m]=u.useState(null),[x,f]=u.useState({}),b=u.useRef({});function k(S){f($=>({...$,[S]:!$[S]}))}if(u.useEffect(()=>{let S=!1;const $=`${t||""}|${a||""}|${r||"claude"}|${i||""}`,de=b.current[$];return d(de||null),p(!0),n?.(!0),m(null),vi({from:t,to:a,source:r,device:i,timeZone:sn(),tzOffsetMinutes:rn()}).then(ie=>{S||(b.current[$]=ie,d(ie))}).catch(ie=>{S||m(ie?.message||String(ie))}).finally(()=>{S||(p(!1),n?.(!1))}),()=>{S=!0}},[t,a,r,i]),h&&!c)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(S=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${S*80}ms`}},S))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(g)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(vd(r))});if(!c||c.scope!=="supported"||!c.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(c?.reason==="local_history_only"?"settings.local_data.local_history_only":En(r))});const j=r==="claude"?md(c.categories||[],s):hd(c,s),v=c.tool_calls_breakdown||null,C=c.skills_breakdown||null,D=c.message_breakdown||null,M=c.configured_resources||null,A=c.exec_command_breakdown||null,I=bd(C?.skills||[]),N=yd(D?.categories||[]),w=r==="codex"&&(c?.breakdown_status==="queue_fallback"||c?.fallback==="queue_totals"),T=r==="claude"?v?.tool_calls||null:v||null,{mcpSet:P,residualSet:z,mcpTotalTokens:K}=pd(T),E=r==="claude"&&v?.subagents||null,O=E?.categories?.length>0||(M?.custom_agents_count||0)>0,U=r==="claude"?(z?.categories||[]).reduce((S,$)=>S+Number($?.totals?.total_tokens||0),0):0,W=r==="claude"?(E?.categories||[]).reduce((S,$)=>S+Number($?.totals?.total_tokens||0),0):0,F=[...j].sort((S,$)=>($.totals?.total_tokens||0)-(S.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:j.filter(S=>S.percent>0).filter(S=>!(r==="claude"&&(S.key==="tool_calls"||S.key==="custom_agents"))).map(S=>`${Ls(S.key)} ${S.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[F.map(S=>{const $=S.key==="system_prompt",de=S.key==="messages",ie=S.key==="tool_calls",G=S.key==="custom_agents";if(S.key,r==="claude"&&(ie||G))return null;const se=de&&N.length>0||ie&&(z?.categories?.length>0||w)||G&&O&&E,ue=!!x[S.key],ke=rd(S.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:ke},"aria-hidden":"true"}),Te=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(mn,{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,Q=S.percent>0?`${S.percent.toFixed(S.percent<.1&&S.percent>0?2:1)}%`:"0.0%";return e.jsxs(Qe,{level:0,colorSquare:je,label:Ls(S.key),labelSuffix:Te,tokens:o(S.totals?.total_tokens||0),percent:Q,hasChevron:se,open:ue,onToggle:()=>k(S.key),share:S.percent,fillColor:ke,children:[de&&e.jsx("ul",{className:"space-y-0.5",children:N.map(B=>e.jsx(Qe,{level:1,label:kd(B),tokens:o(B.totals.total_tokens||0),percent:null},B.key||B.name))}),ie&&z&&e.jsx(Wt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:w}),ie&&w&&!z&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),G&&E&&e.jsx(Wt,{toolSet:E,execDetails:null,source:r,codexQueueFallback:!1})]},S.key)}),r==="claude"&&z?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(U),percent:null,hasChevron:!0,open:!!x.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Wt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&E?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(W),percent:null,hasChevron:!0,open:!!x.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Wt,{toolSet:E,execDetails:null,source:r,codexQueueFallback:!1})}),P?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(K),percent:null,hasChevron:!0,open:!!x.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Wt,{toolSet:P,execDetails:null,source:r,codexQueueFallback:!1})}),I.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:o(I.reduce((S,$)=>S+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!x.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:I.slice(0,12).map(S=>e.jsx(Qe,{level:1,label:S.name,tokens:o(S.total_tokens),percent:null},S.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(jd(r))}),w?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,M?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(M.skills_count||0)," skills ·"," ",Ie(M.mcp_servers_count||0)," MCP servers ·"," ",Ie(M.custom_agents_count||0)," agents ·"," ",Ie(M.memory_files_count||0)," memory files"]}):null]})}function Rn({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__",Cd=`${100 .toFixed(2)}%`;function Xt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function La(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Zt(a);return(a===an?s:s*r)<.01?`<${n}0.01`:ta(s,{decimals:2,currency:a,rate:r})}function Td(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:$s(a)}:{key:a.key,label:a.label||$s(a.key)}):[]}function Ad(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 Dd={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 cr(t,a){const r=t?.toUpperCase?.()||"";return Dd[r]||`hsl(${150+a*40}, 60%, 45%)`}function Md(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 Ld(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 Ed(t){return!!t?.models?.length}function In(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function dr(t){const a=In(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}function Fs(t){return(Number(t?.requests)||0)>0&&!(Number(t?.usage)>0)}function Rd(t,a){const r=Xt(a,t?.usage),s=Math.max(0,Number(t?.requests)||0);return r&&s>0?`${r} · ${l("usage.overview.request_count",{count:s})}`:r||(s>0?l("usage.overview.request_count",{count:s}):null)}const Id={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function $s(t){const a=Id[t];return a?l(a):String(t).toUpperCase()}function Fd({loading:t,onClick:a}){const r=un();return e.jsx(Si,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(Ve.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 $d(){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 Pd(){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 Od({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:c,onCostInfo:d,fleetData:h=[],onRefresh:p,loading:g,announceLoading:m=!1,summaryLoading:x=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:v,onCustomRangeApply:C,customRangeOpen:D,onCustomRangeOpenChange:M,onOpenShare:A,from:I,to:N,deviceOptions:w=[],selectedDevice:T="",dataRevision:P=0,onDeviceChange:z,accountView:K=!1,accountScopeSwitchable:E=!1}){const O=Td(a),U=kl(Ti()),W=Ad(String(s??"")),F=t==="week"&&typeof I=="string"&&typeof N=="string"&&I.slice(0,7)!==N.slice(0,7),S=t!=="day"&&I&&N?`${wa(I,U)} — ${wa(N,U)}`:null,$=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[de,ie]=u.useState($);u.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const _=window.matchMedia("(max-width: 639px)"),V=re=>ie(re.matches);return _.addEventListener("change",V),()=>_.removeEventListener("change",V)},[]);const G=W!=null&&!de,se=u.useRef(null);u.useEffect(()=>{const _=se.current?.querySelector('[aria-selected="true"]');_&&typeof _.scrollIntoView=="function"&&_.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,ke]=u.useState(null),{resolvedTheme:je}=Ni(),{currency:Te,rate:Q}=aa(),{formatTokens:B}=Ne(),ne=je==="dark",X=ne?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",te=ne?"rgba(10,10,10,0)":"rgba(255,255,255,0)",xe=x&&!b,ee=f&&!h.some(Ed);u.useEffect(()=>{ke(null)},[t,I,N,T,P]);const Y=_=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(_.key))return;const V=Array.from(_.currentTarget.querySelectorAll('[role="tab"]')).filter(le=>!le.disabled),re=V.indexOf(_.target.closest('[role="tab"]'));if(re===-1||V.length===0)return;_.preventDefault();let oe=re;_.key==="Home"?oe=0:_.key==="End"?oe=V.length-1:_.key==="ArrowRight"?oe=(re+1)%V.length:oe=(re-1+V.length)%V.length,V[oe].focus(),V[oe].click()},Z=G?e.jsx(Xl,{value:W,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:ne?0:8,gradientFrom:X,gradientTo:te,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,ae=h.filter(_=>_.models?.length>0&&!Fs(_)),Se=h.filter(_=>_.models?.length>0&&Fs(_)),Ae=ae.some(_=>String(_?.source||_?.label||"").trim().toLowerCase()==="devin"),Fe=ae.some(_=>String(_?.source||_?.label||"").trim().toLowerCase()==="kiro"),$e=u.useMemo(()=>Bc(h),[h]),Mt=$e.reduce((_,V)=>_+(Number(V.usage)||0),0),Lt=ae.reduce((_,V)=>_+(Number(V.usd)||0),0),Ce=ue==null?null:ue===it||ae.some(function(V){return V.label===ue})?ue:null;return e.jsx(De,{className:k,children:e.jsxs("div",{"aria-busy":g||xe||ee,children:[m?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:se,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:Y,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(_=>{const V=t===_.key,re=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${V?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(_.key==="custom"){const oe=V&&j&&v?`${wa(j,U)} — ${wa(v,U)}`:_.label;return e.jsxs(vl,{open:D,onOpenChange:le=>{le?r?.("custom"):M?.(le)},children:[e.jsx(jl,{render:e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:re}),children:oe}),e.jsx(Nl,{children:e.jsx(Sl,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(Cl,{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(bl,{from:j,to:v,onApply:C,onCancel:()=>M?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:re,onClick:()=>r?.(_.key),children:_.label},_.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[!E&&K?e.jsx("span",{title:l("usage.overview.scope_account_tip"),className:"inline-flex shrink-0 items-center h-8 px-2.5 text-xs font-medium rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-700 dark:text-oai-gray-300",children:l("usage.overview.scope_account")}):null,w.length>1?e.jsx(ln,{value:T,onValueChange:z,options:w,ariaLabel:E?l("usage.overview.scope_switch_aria"):l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Ol,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,p&&e.jsx(Fd,{loading:g,onClick:p})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:xe?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:Z}):e.jsx("span",{title:n||void 0,children:Z})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${xe?"":"hidden"}`,children:e.jsx($d,{})})]}),c&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:d?e.jsxs("button",{type:"button",onClick:d,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[c,e.jsx(mn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:c})}),S?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:S}),F?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(Pd,{})}),(ae.length>0||Se.length>0)&&e.jsxs("div",{className:"space-y-6",children:[ae.length>0&&e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:ae.map(_=>l("usage.overview.distribution_item",{label:ut(_.label),percent:dr(_)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:ae.map((_,V)=>{const re=cr(_.label,V),oe=ut(_.label),le=dr(_);return e.jsx(Ve.div,{initial:{width:0},animate:{width:`${In(_)}%`},transition:{duration:.5,delay:.45+V*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:re},title:`${oe}: ${le}%`},_.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:Xt(B,Mt)||String(0),cost:La(Lt,Te,Q)||`${Zt(Te)}0`,count:$e.length}),onClick:()=>ke(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(Rn,{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:Cd}),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:$e.length})})]}),ae.map((_,V)=>{const re=cr(_.label,V),oe=Ce===_.label,le=ut(_.label),We=dr(_);return e.jsxs("button",{"aria-expanded":oe,"aria-controls":`provider-details-${_.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:le,percent:We,tokens:Xt(B,_.usage)||String(0),cost:La(_.usd,Te,Q)||`${Zt(Te)}0`,action:l(oe?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>ke(oe?null:_.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${oe?"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(At,{provider:_.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:le,children:le})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[We,"%"]}),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:_.models.length})})]},_.label)})]}),Ce===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Ae&&e.jsx($n,{}),Fe&&e.jsx(Pn,{}),e.jsx(qd,{models:$e})]}),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:ae.filter(_=>_.label===Ce).map(_=>{const V=cr(_.label,0),re=Md(_),oe=[..._.models].sort((We,he)=>(he.share||0)-(We.share||0)),le=re?Ld(re):ut(_.label);return e.jsx(Wd,{provider:_,color:V,providerHeading:le,contextSource:re,deviceId:T,from:I,to:N,sortedModels:oe},_.label)})})]}),Se.length>0&&e.jsx(Vd,{providers:Se})]})})}const zd=[{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"}],Bd="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 Ud({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Ne();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:zd.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 Hd(t,a){const r=l(t==="priority"?"usage.overview.tier_fast":t==="ultrafast"?"usage.overview.tier_ultrafast":"usage.overview.tier_standard"),s=t==="standard"?0:$c(a,t);if(!(s>1))return r;const n=Number.isInteger(s)?String(s):String(Math.round(s*100)/100);return l("usage.overview.tier_rate_label",{label:r,rate:n})}function Kd({model:t}){const{currency:a,rate:r}=aa(),{formatTokens:s,formatTokensTooltip:n}=Ne();if(!Nn(t))return null;const i=[{key:"standard",split:Pc(t)},...Qt.map(o=>({key:o,split:t?.tiers?.[o]||null}))].filter(o=>o.split&&(Ma(o.split.tokens)>0||o.split.cost>0));return i.length?e.jsx("div",{className:"mb-1.5 flex flex-col gap-y-1","data-model-speed-tiers":!0,children:i.map(o=>{const c=Ma(o.split.tokens);return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 text-[11px] tabular-nums",children:[e.jsx("span",{className:"min-w-[8rem] text-oai-gray-500 dark:text-oai-gray-400",children:Hd(o.key,t)}),e.jsx("span",{title:n(c),className:"text-oai-gray-600 dark:text-oai-gray-300",children:s(c)}),e.jsx("span",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:La(o.split.cost,a,r)})]},o.key)})}):null}function Ps({model:t,tokensLabel:a,costLabel:r,unpricedLabel:s,expandable:n,isExpanded:i}){const{formatTokensTooltip:o}=Ne();return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:t.name,children:t.name}),e.jsx("span",{title:o(t.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:a}),e.jsx("span",{title:s?l("dashboard.cost_breakdown.unpriced"):void 0,className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r??s}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(i?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(wl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${i?"rotate-180":""}`})]})]})]})}function Fn({models:t,color:a}){const{currency:r,rate:s}=aa(),{formatTokens:n}=Ne(),[i,o]=u.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(c=>{const d=Rd(c,n),h=La(c.cost,r,s),p=!h&&Number(c.usage)>0&&Mr(c)?l("dashboard.cost_breakdown.unpriced_label"):null,g=Math.max(0,Math.min(100,Number(c.share)||0)),m=c.id||c.name,x=Rc(c),f=x&&i===m,b=Bd,k={model:c,tokensLabel:d,costLabel:h,unpricedLabel:p,expandable:x,isExpanded:f};return e.jsxs("div",{"data-model-rank-row":!0,children:[x?e.jsx("button",{type:"button",onClick:()=>o(f?null:m),"aria-expanded":f,className:`${b} w-full cursor-pointer text-left`,children:e.jsx(Ps,{...k})}):e.jsx("div",{className:b,children:e.jsx(Ps,{...k})}),f&&e.jsxs(e.Fragment,{children:[e.jsx(Ud,{tokens:c.tokens}),e.jsx(Kd,{model:c})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":g,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${g}%`,backgroundColor:a,opacity:.45}})})]},m)})})}function qd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(Rn,{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(Fn,{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 Pn(){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 Vd({providers:t}){const a=t.map(r=>l("usage.overview.request_only_item",{label:ut(r.label),count:Math.max(0,Number(r.requests)||0)})).join(l("usage.overview.request_only_separator"));return e.jsx("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:l("usage.overview.request_only_note",{items:a})})}function Wd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o,deviceId:c}){const{formatTokens:d}=Ne(),[h,p]=u.useState(!1),g=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",m=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",x=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(At,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&h&&e.jsx(_l,{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:Xt(d,t.cacheReusedTokens)||String(0),input:Xt(d,t.cacheInputTokens)||String(0)})]}),g&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),m&&e.jsx($n,{}),x&&e.jsx(Pn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(Sd,{from:n,to:i,source:s,deviceId:c,referenceTotalTokens:t.usage,onLoadingChange:p})}):null,e.jsx(Fn,{models:o,color:a})]})}function Gd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:c,isDragging:d}=rl({id:t}),h=u.useRef(null),p=u.useRef(null);u.useLayoutEffect(()=>{if(!r)return;const m=h.current?h.current.childNodes.length===0:!0;p.current!==m&&(p.current=m,r(t,m))});const g={transform:sl.Transform.toString(o)||void 0,transition:c,zIndex:d?20:void 0};return e.jsxs("div",{ref:i,style:g,className:Ct("group/sortable relative has-[[data-sortable-body]:empty]:hidden",d&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:Ct("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",d&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:h,"data-sortable-body":!0,className:Ct("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",d&&"shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]"),children:a})]})}function Yd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,p]=u.useState(null),g=st([t,a,r,s,n]),m=u.useCallback(async()=>{if(!t)return;const x=g();d(!0),p(null);try{const f=await He(s);if(!x())return;const b=await Ai({from:a,to:r,device:n,accessToken:f});if(!x())return;o(b||null)}catch(f){if(!x())return;p(f?.message||String(f)),o(null)}finally{x()&&d(!1)}},[t,a,r,s,n,g]);return u.useEffect(()=>{if(!t){o(null),p(null),d(!1);return}o(null),p(null),d(!0),m()},[t,m]),{data:i,loading:c,error:h,refresh:m}}function On(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function zn(t){return t==null?"—":`${Math.round(t*100)}%`}function Jd(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 Zd({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:On(t.cost_usd)}),e.jsxs("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:[t.accepted,"/",t.outcomes]}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:zn(t.acceptance_rate)}),e.jsx("td",{className:"py-2.5 pl-2 pr-2 text-right tabular-nums font-semibold text-oai-black dark:text-oai-white",children:Jd(t.cost_usd,t.accepted)})]})}function Qd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Ne(),{enabled:i}=Tl(),{data:o,loading:c}=Yd({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const d=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(m=>m.outcomes>0&&m.key!=="unknown");if(!d.length)return null;const h=d.slice(0,6),p=o.totals||{},g=`${l("qpd.card.subtitle")}${c?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(De,{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("qpd.card.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:g}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(m=>e.jsx(Zd,{row:m},m.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:p.accepted??0,outcomes:p.outcomes??0,cost:On(p.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(p.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(p.effective_tokens),rate:zn(p.acceptance_rate)})})]}),p.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 Xd=new Set(["unknown","synthetic","openai"]);function ur(t){return t==null?"—":`${Math.round(t*100)}%`}function eu(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function tu(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Xd.has(r)&&Number(t?.edit_turns||0)>0}function Os(){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 au({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=u.useState({requestKey:null,loading:!0,sessions:null,context:null}),i=s.requestKey===r?s:{loading:!0,sessions:null,context:null},o=u.useId(),{enabled:c}=Al(),d=st([c,t,a]),{formatTokens:h}=Ne(),p=C=>h(C,{mode:Yt.COMPACT});u.useEffect(()=>{const C=d();if(!c){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Di({from:t,to:a}),Mi()]).then(([D,M])=>{C()&&n({requestKey:r,loading:!1,sessions:D,context:M})}).catch(()=>{C()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[c,t,a,r,d]);const g=u.useMemo(()=>(i.sessions?.by_model||[]).filter(tu).slice(0,5),[i.sessions]),m=u.useMemo(()=>(i.sessions?.subagents||[]).slice(0,3),[i.sessions]);if(!c||!i.loading&&!i.sessions?.available&&!i.context?.estimated_fixed_tokens)return null;const x=i.sessions?.summary||{},f=x.edit_session_rate??x.productive_rate,b=x.first_pass_rate??x.one_shot_rate,k=x.edit_sessions??x.productive_sessions??0,j=x.sessions??i.sessions?.session_count??0,v=x.edit_turns??0;return i.loading&&!i.sessions&&!i.context?e.jsxs(De,{children:[e.jsx(Os,{}),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(De,{children:[e.jsx(Os,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(mr,{label:l("sessions.card.edit_sessions"),value:ur(f),detail:l("sessions.card.edit_session_value",{edits:Ze(k),sessions:Ze(j)})}),e.jsx(mr,{label:l("sessions.card.first_pass"),value:ur(b),detail:l("sessions.card.edit_session_value",{edits:Ze(x.first_pass_sessions??x.one_shot_sessions??0),sessions:Ze(k)})}),e.jsx(mr,{label:l("sessions.card.cost_edit"),value:eu(x.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(v)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Ze(j),edits:Ze(v)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":o,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:o,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!g.length&&e.jsx(Yi,{wrapperClassName:"w-full",label:l("sessions.card.scroll"),children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium whitespace-nowrap",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:g.map(C=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:C.model,children:C.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:l("sessions.card.edit_session_value",{edits:Ze(C.edit_sessions??C.productive_sessions??0),sessions:Ze(C.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:ur(C.first_pass_rate??C.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums whitespace-nowrap",children:p(C.tokens_per_edit)})]},C.model))})]})}),i.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:p(i.context.estimated_fixed_tokens)})]}):null,!!m.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),m.map(C=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:C.name,calls:Math.round(C.calls)})},C.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function mr({label:t,value:a,detail:r}){return e.jsxs("div",{className:"rounded-lg bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 truncate",children:t}),e.jsx("div",{className:"mt-0.5 text-sm font-semibold tabular-nums text-oai-black dark:text-white",children:a}),e.jsx("div",{className:"mt-0.5 text-[9px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 truncate",children:r})]})}function ce({className:t}){return e.jsx("div",{className:Ct("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function ru(){return e.jsx("div",{className:"flex gap-1 overflow-hidden",children:Array.from({length:20},(t,a)=>e.jsx("div",{className:"flex flex-col gap-1",children:Array.from({length:7},(r,s)=>e.jsx(ce,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function su(){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(De,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(ce,{className:"h-4 w-32"}),e.jsx(ce,{className:"h-6 w-24"})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-24"}),Array.from({length:4},(t,a)=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(ce,{className:"h-3 w-20"}),e.jsx(ce,{className:"h-3 w-12"})]},a))]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(ru,{})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-28"}),e.jsx(ce,{className:"h-32 w-full"})]})})]}),e.jsxs("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex flex-1 min-w-0 gap-1",children:Array.from({length:5},(t,a)=>e.jsx(ce,{className:"h-7 w-14 rounded-md shrink-0"},a))}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(ce,{className:"h-8 w-20 rounded-md"}),e.jsx(ce,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(ce,{className:"h-3 w-28"}),e.jsx(ce,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(ce,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ce,{className:"h-1.5 w-full rounded-full"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-3",children:Array.from({length:5},(t,a)=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ce,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(ce,{className:"h-3 w-12"})]}),e.jsx(ce,{className:"h-5 w-10"}),e.jsx(ce,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(ce,{className:"h-7 w-16 rounded"}),e.jsx(ce,{className:"h-7 w-20 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-200 dark:border-oai-gray-700 pb-2",children:[e.jsx(ce,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(ce,{className:"h-3 flex-1"},a))]}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:8},(t,a)=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-100 dark:border-oai-gray-800 py-2.5 last:border-b-0",children:[e.jsx(ce,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(ce,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const nu=Rl.slice(0,10),zs=.06,ou=.11,iu=.05;function Bs({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(El,{logos:nu,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(Ve.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 lu(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:c,activeDays:d,identitySubscriptions:h,identityScrambleDurationMs:p,projectUsageEntries:g,projectUsageLimit:m,setProjectUsageLimit:x,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:j,isLocalMode:v,accountView:C,accountScopeSwitchable:D,shouldShowInstall:M,installPrompt:A,handleCopyInstall:I,installCopied:N,installInitCmdDisplay:w,trendRowsForDisplay:T,trendFromForDisplay:P,trendToForDisplay:z,trendZoomConfig:K,usageFrom:E,usageTo:O,period:U,trendTimeZoneLabel:W,activityHeatmapBlock:F,periodsForDisplay:S,setSelectedPeriod:$,customFrom:de,customTo:ie,onCustomRangeApply:G,customRangeOpen:se,onCustomRangeOpenChange:ue,summaryLabel:ke,summaryValue:je,summaryFullValue:Te,hasSummary:Q,summaryLoading:B,providersLoading:ne,onToggleSummaryFormat:X,summaryTotalTokensRaw:te,summaryCostValue:xe,summaryConversationsValue:ee,rollingUsage:Y,costInfoEnabled:Z,openCostModal:ae,costModalOpen:Se,closeCostModal:Ae,allowBreakdownToggle:Fe,refreshAll:$e,usageLoadingState:Mt,announceUsageLoading:Lt,initialDashboardLoading:Ce,fleetData:_,hasDetailsActual:V,dailyEmptyPrefix:re,installSyncCmd:oe,dailyEmptySuffix:le,detailsColumns:We,ariaSortFor:he,toggleSort:ge,sortIconFor:Pe,pagedDetails:Oe,dailyBreakdownRows:Et,dailyBreakdownColumns:xt,dailyBreakdownAriaSortFor:Ge,dailyBreakdownSortIconFor:Ra,dailyBreakdownDateKey:Xe,detailsDateKey:Ia,renderDetailDate:Fa,renderDailyBreakdownDate:gt,renderDetailCell:J,DETAILS_PAGED_PERIODS:ra,detailsPageCount:_e,detailsPage:we,setDetailsPage:Rt,deviceOptions:nt,selectedDevice:ye,onDeviceChange:It,deviceUsageBlock:sa,localHistoryOnly:na,localHistoryRevision:oa,leftCardOrder:Ft,onLeftReorder:$t,rightCardOrder:ia,onRightReorder:ze}=t,Be=null,Pt=null,ft={statsPanel:!0,installCopy:M,activityHeatmap:!!F,deviceUsage:!!sa,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:v&&!s},Ot=(Ft||[]).filter(me=>ft[me]),$a={usageOverview:!0,dataDetails:!s},Pa=(ia||[]).filter(me=>$a[me]);function la(me,fe){switch(me){case"statsPanel":return e.jsx(ot,{delay:fe,children:e.jsx(ed,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:U,startDate:c??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:h,periodConversations:ee,rolling:Y,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:A}),e.jsxs(Ve.button,{onClick:I,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:w}),e.jsx(Ve.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:N?"Copied ✓":"Copy"},N?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:fe,children:F});case"deviceUsage":return e.jsx(ot,{delay:fe,children:sa});case"trendMonitor":return e.jsx(ot,{delay:fe,children:e.jsx(nn,{rows:T,from:P,to:z,period:U,timeZoneLabel:W,showTimeZoneLabel:!1,zoomConfig:K})});case"qualityPerDollar":return e.jsx(Qd,{from:E,to:O,deviceId:ye});case"sessionInsights":return e.jsx(au,{from:E,to:O});default:return null}}function Oa(me,fe){switch(me){case"usageOverview":return e.jsx(ot,{delay:fe,children:e.jsx(Od,{accountView:C,accountScopeSwitchable:D,period:U,periods:S,onPeriodChange:$,summaryLabel:ke,summaryValue:je,summaryFullValue:Te,hasSummary:Q,summaryLoading:B,providersLoading:ne,onToggleSummaryFormat:Q?X:null,summaryCostValue:xe,onCostInfo:Z?ae:null,fleetData:_,onRefresh:s?null:$e,loading:Mt,announceLoading:Lt,onOpenShare:s?null:r,customFrom:de,customTo:ie,onCustomRangeApply:G,customRangeOpen:se,onCustomRangeOpenChange:ue,from:E,to:O,deviceOptions:nt,selectedDevice:ye,dataRevision:oa,onDeviceChange:It})});case"dataDetails":return e.jsx(ot,{delay:fe,children:e.jsx(Qc,{projectEntries:g,projectLimit:m,onProjectLimitChange:x,projectDetailQuery:f,copy:a,hasDetailsActual:V,dailyEmptyPrefix:re,installSyncCmd:oe,dailyEmptySuffix:le,detailsColumns:We,ariaSortFor:he,toggleSort:ge,sortIconFor:Pe,pagedDetails:Oe,dailyBreakdownRows:Et,dailyBreakdownColumns:xt,dailyBreakdownAriaSortFor:Ge,dailyBreakdownSortIconFor:Ra,dailyBreakdownDateKey:Xe,detailsDateKey:Ia,renderDetailDate:Fa,renderDailyBreakdownDate:gt,renderDetailCell:J,DETAILS_PAGED_PERIODS:ra,period:U,detailsPageCount:_e,detailsPage:we,setDetailsPage:Rt})});default:return null}}const ca=nl(hs(ul,{activationConstraint:{distance:6}}),hs(dl,{coordinateGetter:cl})),zt=u.useCallback(me=>{const{active:fe,over:be}=me;!be||fe.id===be.id||$t?.(String(fe.id),String(be.id))},[$t]),za=u.useCallback(me=>{const{active:fe,over:be}=me;!be||fe.id===be.id||ze?.(String(fe.id),String(be.id))},[ze]);function yt(me,fe,be,pe){return s?e.jsx(e.Fragment,{children:me.map((et,bt)=>e.jsx(St.Fragment,{children:fe(et,be+zs*bt)},et))}):e.jsx(ol,{sensors:ca,onDragEnd:pe,children:e.jsx(il,{items:me,strategy:ll,children:me.map((et,bt)=>e.jsx(Gd,{id:et,children:fe(et,be+zs*bt)},et))})})}const Bt=yt(Ot,la,ou,zt),Ba=yt(Pa,Oa,iu,za);return e.jsxs(e.Fragment,{children:[e.jsxs(Kl,{bare:!s,hideHeader:s,header:Be,footer:s?null:Pt,className:s?"screenshot-mode":"",children:[i&&e.jsx(Bs,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Bs,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&Ce&&e.jsx(su,{}),!i&&!n&&!Ce&&e.jsxs(e.Fragment,{children:[na&&e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.local_data.local_history_only")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:Bt}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ba})]})]})]}),e.jsx(Kc,{isOpen:Se,onClose:Ae,fleetData:_})]})}function cu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0,localView:c=!1}={}){const d=c&&!n&&Il(),h=!!(d||n&&i),[p,g]=u.useState(0),[m,x]=u.useState([]),[f,b]=u.useState([]),[k,j]=u.useState(!1),[v,C]=u.useState(null),D=st([h,d,t,a,r,s,i,o]),M=u.useCallback(async()=>{const A=D();if(!h){x([]),b([]),j(!1),C(null);return}j(!0),C(null);try{const I=d?null:await He(i);if(!A())return;const N=d?await Dl({from:t,to:a,timeZone:r,tzOffsetMinutes:s}):await Li({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:I});if(!A())return;x(Array.isArray(N?.devices)?N.devices:[]),b(Array.isArray(N?.account_sources)?N.account_sources:[]),g(d&&Number(N?.revision)||0)}catch(I){if(!A())return;C(I?.message||String(I)),x([]),b([])}finally{A()&&j(!1)}},[h,d,i,t,a,r,s,o,D]);return u.useEffect(()=>{if(d)return window.addEventListener(ps,M),()=>window.removeEventListener(ps,M)},[d,M]),u.useEffect(()=>{x([]),b([]),C(null),h&&j(!0),M()},[h,M]),{devices:m,accountSources:f,loading:k,error:v,refresh:M,revision:p}}const du=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Us(t){const a=String(t||"").toLowerCase();return/iphone|ipad|ios/.test(a)?"iOS":/android/.test(a)?"Android":/mac|darwin/.test(a)?"Mac":/win/.test(a)?"Windows":/linux/.test(a)?"Linux":"Web"}function kr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(du);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Us(t.platform)} · ${s}`:Us(t.platform)}const Hs=" · ",Ks="%";function qs({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Pl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(ns,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(ns,{className:a,"aria-hidden":!0}):e.jsx(pn,{className:a,"aria-hidden":!0})}function Vs(t,a){return a===t?.id||t?.isCurrent===!0}function uu({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:c}=Ne(),[d,h]=u.useState(""),[p,g]=u.useState(""),[m,x]=u.useState(!1),[f,b]=u.useState(""),k=typeof i=="function",j=typeof n=="function",v=!!s,C=t.reduce((w,T)=>w+(Number(T.total_tokens)||0),0)+a.reduce((w,T)=>w+(Number(T.total_tokens)||0),0),D=u.useMemo(()=>t.filter(w=>(Number(w.total_tokens)||0)>0||w.id===s).sort((w,T)=>(Number(T.total_tokens)||0)-(Number(w.total_tokens)||0)),[t,s]);function M(w){b(""),h(w.id);const T=typeof w.device_name=="string"?w.device_name:"";g(kr(w)===T?T:"")}function A(){h(""),g(""),b("")}async function I(w){const T=p.trim();if(!(!T||m)){x(!0),b("");try{await i(w.id,T),h(""),g("")}catch{b(w.id)}finally{x(!1)}}}const N=a.filter(w=>(Number(w.total_tokens)||0)>0);return D.length===0&&N.length===0?e.jsxs(De,{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(pn,{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(De,{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&&v&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[D.map(w=>{const T=Number(w.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=s===w.id,K=kr(w)||l("dashboard.device_card.unnamed"),E=d===w.id,O=z?"bg-oai-brand":v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",U=v&&!z?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[E?e.jsxs("div",{className:"w-full rounded-md px-2 py-1.5 bg-oai-gray-50/50 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(qs,{platform:w.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:p,disabled:m,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:W=>g(W.target.value),onKeyDown:W=>{W.key==="Enter"?I(w):W.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:m||!p.trim(),onClick:()=>I(w),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Fl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:m,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Tr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${O}`,style:{width:`${P}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":z,"aria-label":`${l("dashboard.device_filter.aria")}: ${K}${Vs(w,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(z?"":w.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 ${U} ${z?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(qs,{platform:w.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:K,children:K}),Vs(w,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")}),w.imported_at&&e.jsx("span",{className:"shrink-0 whitespace-nowrap text-xs text-oai-gray-500",title:l("settings.local_data.snapshot_time",{time:new Date(w.exported_at).toLocaleString()}),children:l("settings.local_data.imported_label")})]}),e.jsxs("span",{title:c(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Hs,P,Ks]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${O}`,style:{width:`${P}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>M(w),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(Ml,{className:"h-3 w-3"})})]}),f===w.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},w.id)}),N.map(w=>{const T=Number(w.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=v?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${z}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(At,{provider:w.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:ut(w.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:c(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Hs,P,Ks]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${P}%`}})})]},`account-${w.source}`)})]})]})}const Lr="__scope:local__";function mu(t){return t===Lr?{scopeOverride:"local",deviceId:null}:t?String(t).startsWith("local:")?{scopeOverride:"local",deviceId:t}:{scopeOverride:null,deviceId:t}:{scopeOverride:null,deviceId:null}}function hu({accountScopeSwitchable:t,accountView:a,selectedDevice:r}){return t?r||(a?"":Lr):r||""}function Bn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const mt=new Map,ht=new Map;function Un(){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||!mt.has(r))return;const s=mt.get(r);mt.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||!ht.has(r))return;const s=ht.get(r);ht.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function pu(t){if(!Bn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const a=window?.webkit?.messageHandlers?.nativeBridge;if(!a)return{ok:!1,error:"native bridge unavailable"};Un();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{ht.has(r)&&(ht.delete(r),s({ok:!1,error:"timeout"}))},8e3);ht.set(r,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){ht.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Ws(t,a){if(!Bn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const r=window?.webkit?.messageHandlers?.nativeBridge;if(!r)return{ok:!1,error:"native bridge unavailable"};Un();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{mt.has(s)&&(mt.delete(s),n({ok:!1,error:"timeout"}))},8e3);mt.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){mt.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Hn=1200,Kn=1630,qn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},xu="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 hr=!1;function gu(){if(typeof document>"u"||hr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){hr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=xu,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),hr=!0}async function fu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function yu(t,a={}){if(typeof window>"u"||!t)return null;gu(),await fu(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Ei(async()=>{const{toBlob:d,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Hn,o=t.offsetHeight||Kn,c={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,c);if(d)return d}catch{}try{const d=await s(t,c);return d?await(await fetch(d)).blob():null}catch{return null}}async function pr(t){return new Promise(a=>{const r=new FileReader;r.onload=()=>{const s=typeof r.result=="string"?r.result:null;a(s)},r.onerror=()=>a(null),r.readAsDataURL(t)})}function Gs(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 _r(t){const a=H(t);return Number.isFinite(a)?a:0}function bu(t){return t?_r(t.billable_total_tokens??t.total_tokens):0}function ku(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(c=>{const d=!!c?.future,h=Number.isFinite(c?.level)?Math.max(0,Math.min(4,Math.round(c.level))):0;c?.day&&!d&&(r+=1,h>0&&(s+=1));const p=c?.billable_total_tokens??c?.total_tokens??c?.value??0,g=Number.isFinite(p)?Math.max(0,p):0;return{day:typeof c?.day=="string"?c.day:"",level:h,value:g,future:d}})),totalDays:r,activeDays:s}}function _u(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:c,periodFrom:d,periodTo:h,heatmap:p,capturedAt:g,currency:m,exchangeRate:x}=t,f=bu(n),b=_r(n?.total_cost_usd),k=Array.isArray(i)?i.slice(0,3).map(v=>({id:v?.id??null,name:typeof v?.name=="string"&&v.name?v.name:"—",tokens:_r(v?.tokens),percent:typeof v?.percent=="string"&&v.percent?v.percent:"0.0"})):[],j=ku(p);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:c,periodFrom:d,periodTo:h,topModels:k,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:g||new Date().toISOString(),currency:typeof m=="string"&&m.length>0?m.toUpperCase():"USD",exchangeRate:Number.isFinite(x)&&x>0?x:1}}const wu=["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 vu(t){const a=wu[t];return a?l(a):"—"}function Vn(t,a){return l("share.date.month_year",{month:vu(t),year:a})}function ju(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:Vn(n,r)}function Nu(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 Vn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function wr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Wn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Zt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function Su(t){const a=t.topModels[0];if(a){const r=parseFloat(a.percent);return Number.isFinite(r)&&r>=60?l("share.hook.top_loyal",{percent:Math.round(r),name:a.name}):t.activeDays>=60?l("share.hook.days_record",{days:t.activeDays}):Number.isFinite(r)&&r>=30?l("share.hook.top_led",{name:a.name,percent:Math.round(r)}):t.topModels.length>1?l("share.hook.multi_models",{count:t.topModels.length,days:t.activeDays}):l("share.hook.days_with_model",{days:t.activeDays,name:a.name})}return t.activeDays>0?l("share.hook.days_record",{days:t.activeDays}):l("share.hook.new_chapter")}function Cu(t,a){const r=(t||"").length;if(r<=a.baseChars)return a.baseSize;const s=a.baseSize-(r-a.baseChars)*a.shrinkPerChar;return Math.max(a.minSize,s)}function Tu(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 Au({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],c=i||o[0],d=t.length,h=(d-1)*s,p=Math.max(4,(r-h)/d),g=7*p+6*s;return e.jsx("svg",{width:r,height:g,viewBox:`0 0 ${r} ${g}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((m,x)=>(Array.isArray(m)?m:[]).map((b,k)=>{if(k>=7)return null;const j=Tu(b),v=x*(p+s),C=k*(p+s),D=j===null?c:o[j];return e.jsx("rect",{x:v,y:C,width:p,height:p,rx:n,ry:n,fill:D},`${x}-${k}`)}))})}const Du=Dt("oklch(0.97 0.01 85)"),Re=Dt("oklch(0.18 0.02 85)"),at=Dt("oklch(0.38 0.015 85)"),Ys=Dt("oklch(0.55 0.012 85)"),lt=Dt("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',Mu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Lu=["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(Dt);function Gn({data:t}){const a=Nu(t),r=wr(t.totalTokens),s=Wn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=ju(t.startDate),i=Cu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=Su(t),c=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Du,color:Re,fontFamily:Mu,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 ${Ys}`},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:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background: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})})]})]}),c?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Au,{weeks:t.heatmapWeeks,palette:Lu,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((d,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Ys}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(h+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:d.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:wr(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsxs("div",{style:{display:"flex",gap:28},children:[e.jsxs("span",{children:[l("share.card.broadsheet.global_rank")," ",e.jsxs("span",{style:{color: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 Eu=qn["annual-report"].width,Ru="#0a0820",rt="#ffffffee",dt="rgba(255,255,255,0.45)",xr="#a78bfa",Iu={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(", ")},Na={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},vr='"Space Grotesk", "Inter Tight", sans-serif',gr='"Inter Tight", sans-serif',Fu="rgba(255,255,255,0.06)",Yn=[Fu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Jn=48,Zn=28,Ea=4,Qn=20,$u=Eu-Jn*2-Zn*2,Pu=($u-Qn*2)/3,jr=Math.min(Math.floor((Pu-Ea*6)/7),40),Ou=jr*7+Ea*6;function zu(t){if(!Array.isArray(t))return t;const a=[];for(const c of t)if(Array.isArray(c))for(const d of c)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((c,d)=>c-d);const r=c=>{const d=a.length,h=(d-1)*c,p=Math.floor(h);return Math.round((a[p]??0)+((a[Math.min(d-1,p+1)]??0)-(a[p]??0))*(h-p))},s=r(.5),n=r(.75),i=r(.9),o=c=>!c||c<=0?0:c<=s?1:c<=n?2:c<=i?3:4;return t.map(c=>Array.isArray(c)?c.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:o(d.value)}:d):c)}function Bu(t){if(!Array.isArray(t))return[];const a={},r=zu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Uu(t){if(!t.length)return[];const a=[...t].sort((o,c)=>o.day.localeCompare(c.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const Hu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ku(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Js(t){const[a,r]=u.useState(null);return u.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function qu({data:t}){const a=Uu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:vr,marginBottom:4},children:Hu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ea},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ea},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:jr,height:jr,borderRadius:4,background:o<0?"transparent":Yn[o]}},i)})},s))})]})}function Vu({data:t}){const a=Bu(t.heatmapWeeks),r=Ku(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Js(n),o=Js("/neon_bg.png"),c=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Ru,fontFamily:vr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Jn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:d*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:rt},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:c})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...Iu,borderRadius:22,padding:Zn,marginBottom:d},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),Yn.map((h,p)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},p)),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,${Ou}px)`,gap:`8px ${Qn}px`,justifyContent:"center"},children:a.map(h=>e.jsx(qu,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{...Na,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:wr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...Na,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Wn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},children:[e.jsxs("div",{style:{...Na,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:xr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:gr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...Na,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:xr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:vr,fontSize:28,fontWeight:700,color: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:xr},children:"tokentracker.cc"})]})]})]})}const Xn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Wu={broadsheet:Gn,"annual-report":Vu};function eo(t){return qn[t]||{width:Hn,height:Kn}}function Gu(t){const a=Xn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Zs=u.forwardRef(function({data:a,variant:r},s){const n=Wu[r]||Gn,{width:i,height:o}=eo(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function Sa(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const Yu=440;function Ju(){const[t,a]=u.useState(null),r=u.useRef(null),s=u.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return u.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function fr({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 Zu({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState("annual-report"),p=u.useRef(null),{toast:g,push:m}=Ju(),x=Ri(),f=u.useMemo(()=>{const N=x?.user;if(!N||typeof N!="object")return null;const w=N.user_metadata||{},T=N.profile||{},P=w.avatar_url||w.picture||T.avatar_url||N.avatar_url;return typeof P=="string"&&P.trim()?P.trim():null},[x?.user]);u.useEffect(()=>{t&&(i(null),c(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:o||r.handle,avatarUrl:f},{width:k,height:j}=eo(d),v=Yu/k;u.useEffect(()=>{if(!t)return;const N=w=>{w.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const C=u.useCallback(async()=>{const N=p.current;if(!N)return null;try{return await yu(N)}catch(w){return console.warn("[share] capture failed",w),null}},[]),D=u.useCallback(async()=>{if(n)return;i("copy");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}let w=!1;if(Sa()){const T=await pr(N);T&&(w=(await pu(T)).ok)}else w=await os(N);m(w?l("share.toast.copied"):l("share.toast.failed"),w?"success":"error"),i(null)},[n,C,m]),M=u.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=u.useCallback(async()=>{if(n)return;i("download");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}if(Sa()){const T=await pr(N);if(T&&(await Ws(T,M())).ok){m(l("share.toast.downloaded"),"success"),i(null);return}}const w=Gs(N,M());m(w?l("share.toast.downloaded"):l("share.toast.failed"),w?"success":"error"),i(null)},[n,C,M,m]),I=u.useCallback(async()=>{if(n)return;i("x");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}if(Sa()){const z=await pr(N);z&&(await Ws(z,M()),m(l("share.toast.downloaded"),"success"))}else await os(N)?m(l("share.toast.copied"),"success"):Gs(N,M());const w=new URL("https://twitter.com/intent/tweet");s&&w.searchParams.set("text",s);const T=x?.user?.id,P=typeof T=="string"&&T?`/u/${T}`:"/";if(w.searchParams.set("url",`https://www.tokentracker.cc${P}?ref=share`),Sa())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:w.toString()})}catch{window.open(w.toString(),"_blank","noopener,noreferrer")}else window.open(w.toString(),"_blank","noopener,noreferrer");i(null)},[n,C,m,s,M,x]);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(Zs,{ref:p,data:b,variant:d})}),e.jsxs(Ve.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*v,height:j*v,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:j,transform:`scale(${v})`,transformOrigin:"top left"},children:e.jsx(Zs,{data:b,variant:d})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:o,onChange:N=>c(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:Xn.map(N=>e.jsx("button",{type:"button",onClick:()=>h(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Gu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(fr,{onClick:I,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(fr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(fr,{onClick:D,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(hn,{children:g?e.jsx(Ve.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},className:"pointer-events-none absolute left-1/2 bottom-4 -translate-x-1/2",children:e.jsx("div",{className:["px-4 py-2 rounded-full text-xs font-medium shadow-oai-md",g.kind==="error"?"bg-red-600 text-white":g.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:g.text})},g.id):null})]})]}):null}function Qu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:c,periodFrom:d,periodTo:h,heatmap:p,accessToken:g,userId:m,currency:x,exchangeRate:f}=t,[b,k]=u.useState(null),j=f;return u.useEffect(()=>{if(!a||!m&&!pt())return;let v=!1;return(async()=>{try{const D=await Ii({accessToken:g,userId:m,period:c==="day"||c==="custom"?"week":c,metric:"all",limit:100,offset:0});if(v)return;const A=(Array.isArray(D?.entries)?D.entries:Array.isArray(D)?D:[]).find(N=>N?.is_me===!0),I=typeof A?.rank=="number"?A.rank:null;k(I)}catch{v||k(null)}})(),()=>{v=!0}},[a,g,m,c]),u.useMemo(()=>_u({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:b,period:c,periodFrom:d,periodTo:h,heatmap:p,currency:x,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,i,o,b,c,d,h,p,x,j])}function Qs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const Xu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function em({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const tm=["day","week","month","total","custom"],yr=new Set(["day","hour","month"]),Gt=new Set(["day","total","custom"]),am=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],rm=["usageOverview","dataDetails"];function br(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 Ca(t){return t?Tt(t,null):null}function Xs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function sm(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function nm(){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:!sm(window.location.hostname)}function Wm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:c="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:h}){const{resolvedLocale:p}=Fi(),{currency:g,rate:m}=aa(),{mode:x,setMode:f,formatTokens:b,formatTokensTooltip:k}=Ne(),[j,v]=u.useState(!1),[C,D]=u.useState(null),[M,A]=u.useState(null),[I,N]=u.useState(!1),[w,T]=u.useState(null),[P,z]=u.useState(0),[K,E]=u.useState(0),[O,U]=u.useState(null),W=u.useMemo(()=>typeof window>"u"?!1:$i(window.location.search),[]),F=u.useMemo(()=>nm(),[]),[S,$]=u.useState(!1),de=2200,[ie,G]=u.useState(!0),[se,ue]=u.useState(!1),[ke,je]=u.useState(!1),[Te,Q]=u.useState(!1),[B,ne]=u.useState(!1),X=u.useRef(!1),te=pt(),xe=r&&!s,ee=u.useMemo(()=>xe&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,xe]),Y=xe?ee:null,Z=i?Pi(o):Y,ae=r||te||i,Se=xe&&ea(Y),Ae=r&&s&&!i,{accountView:Fe,revision:$e,resolving:Mt,scopeSwitchable:Lt,setScopeOverride:Ce}=Oi(),_=Fe&&!i,V=Lt&&!i,re=_?Y:null,oe=Mt&&!i;u.useEffect(()=>{if(!r||te){D(null),A(null),N(!1),T(null);return}if(i)return;if(!Se){D(null),A(null),N(!1),T(null);return}let y=!0;const L=()=>{D(null),A(null),N(!1),T(null)};return N(!0),T(null),(async()=>{let R=null;try{R=await He(Y)}catch{R=null}if(y){if(!R){L();return}try{const q={link_code:null,expires_at:null};if(!y)return;D(typeof q?.link_code=="string"?q.link_code:null),A(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;D(null),A(null),T(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,te,r,i,Se,Y,K]);const le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");u.useEffect(()=>{if(!le&&(!r||te||i)){U(null);return}if(!le&&!Se){U(null);return}let y=!0;return(async()=>{let L=null;try{L=await He(Y)}catch{L=null}if(y){if(!L&&!le){U(null);return}try{const R=await zi({baseUrl:t,accessToken:L});if(!y)return;U(R&&typeof R=="object"?R:null)}catch{if(!y)return;U(null)}}})(),()=>{y=!1}},[Se,t,Y,te,i,r]);const We=u.useMemo(()=>{if(!M)return!1;const y=Date.parse(M);if(!Number.isFinite(y))return!1;const L=P||Date.now();return y<=L},[M,P]);u.useEffect(()=>{!r||te||i||!M||!We||I||(D(null),A(null),T(null),E(y=>y+1))},[We,M,I,te,r]),u.useEffect(()=>{if(!M||i)return;const y=Date.parse(M);if(!Number.isFinite(y))return;const L=Date.now();if(z(L),y<=L)return;const R=window.setTimeout(()=>z(Date.now()),y-L),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&z(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(R),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[M]);const he=u.useMemo(()=>sn(),[]),ge=u.useMemo(()=>rn(),[]),Pe=u.useMemo(()=>Bi(),[]),Oe=i?null:a?.userId||a?.email||"default",[Et,xt]=u.useState("month"),[Ge,Ra]=u.useState(null),[Xe,Ia]=u.useState(null),[Fa,gt]=u.useState(!1),J=W?"total":Et,ra=u.useMemo(()=>J==="custom"&&Ge&&Xe?{from:Ge,to:Xe}:Ui(J,{timeZone:he,offsetMinutes:ge,now:Pe}),[Pe,J,he,ge,Ge,Xe]),_e=ra.from,we=ra.to,[Rt,nt]=u.useState(null),ye=Rt&&Rt.startsWith("local:")!==_?Rt:null,[It,sa]=u.useState(()=>is());u.useEffect(()=>{const y=()=>sa(is());return window.addEventListener(ls,y),window.addEventListener("storage",y),()=>{window.removeEventListener(ls,y),window.removeEventListener("storage",y)}},[]);const{devices:na,accountSources:oa,refresh:Ft,loading:$t,revision:ia}=cu({from:_e,to:we,timeZone:he,tzOffsetMinutes:ge,accountView:_,accountAccessToken:re,accountRevision:$e,localView:!i&&!te}),ze=_?$e:ia,Be=u.useMemo(()=>na.filter(y=>!_||(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.isCurrent||y.id===It})),[na,It,_]),Pt=u.useMemo(()=>oa.filter(y=>(Number(y.total_tokens)||0)>0),[oa]),ft=V||Be.length>=2,Ot=(_||Be.length>=2)&&Be.length+Pt.length>=2;u.useEffect(()=>{if(!$t){if(!ft&&!Ot){ye!==null&&nt(null);return}ye&&!Be.some(y=>y.id===ye)&&nt(null)}},[ft,Ot,Be,ye,$t]);const $a=u.useMemo(()=>{if(!ft)return[];const y=Be.map(L=>{const R=kr(L)||l("dashboard.device_card.unnamed"),q=L.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:L.id,label:`${R}${q}`}});return V?[{value:Lr,label:l("usage.overview.scope_local")},...y,{value:"",label:l("usage.overview.scope_account")}]:[{value:"",label:l("dashboard.device_filter.all")},...y]},[ft,V,Be,p]),Pa=hu({accountScopeSwitchable:V,accountView:_,selectedDevice:ye}),la=_?{devices:Be,accountSources:Pt}:Ll(Be,Pt,ye),Oa=Ot?e.jsx(uu,{devices:la.devices,accountSources:la.accountSources,currentDeviceId:It,selectedDeviceId:ye||"",onSelectDevice:y=>nt(y||null),onRenameDevice:_?async(y,L)=>{const R=await He(re);await Gi({deviceId:y,name:L,accessToken:R}),await Ft()}:void 0}):null,ca=u.useMemo(()=>Hi({timeZone:he,offsetMinutes:ge}),[he,ge]),zt=u.useMemo(()=>Ki({timeZone:he,offsetMinutes:ge}),[he,ge]),za=u.useMemo(()=>`Local time (${zt})`,[zt]),yt=he,Bt=ge,Ba=ca,me=u.useMemo(()=>Cr({timeZone:he,offsetMinutes:ge,date:Pe||new Date}),[Pe,he,ge]),fe=u.useMemo(()=>Tc({period:J,selectedFrom:_e,selectedTo:we,todayKey:me}),[_e,J,we,me]),{daily:be,summary:pe,rolling:et,source:bt,loading:Er,error:to,refresh:Rr}=bs({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:_e,to:we,includeDaily:J!=="total",cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{daily:Ir,loading:ao,refresh:Fr}=bs({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:fe.from,to:fe.to,includeDaily:!0,includeSummary:!1,cacheKey:Oe?`${Oe}.daily-breakdown`:"daily-breakdown",timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{breakdown:tt,loading:$r,refresh:Pr}=lc({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:_e,to:we,cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),[ro,so]=u.useState(3),{entries:no,loading:oo,refresh:Or}=nc({baseUrl:t,accessToken:Z,from:_e,to:we,timeZone:he,tzOffsetMinutes:ge}),zr=J==="week"||J==="month",da=J==="week"||J==="month",Br=u.useMemo(()=>be.filter(y=>y?.future?!1:!y?.day||!me?!0:String(y.day)<=String(me)),[be,me]),{rows:Je,from:io,to:lo,loading:co,refresh:Ur}=Zi({baseUrl:t,accessToken:Z,guestAllowed:Ae,period:J,from:_e,to:we,months:24,cacheKey:Oe,timeZone:yt,tzOffsetMinutes:Bt,now:Pe,sharedRows:zr?be:null,sharedRange:zr?{from:_e,to:we}:null,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),uo=u.useMemo(()=>({baseUrl:t,accessToken:Z,guestAllowed:Ae,cacheKey:Oe,timeZone:yt,tzOffsetMinutes:Bt,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),[t,Z,Ae,Oe,yt,Bt,Pe,_,re,ze,oe,ye]),{daily:kt,heatmap:Ye,loading:Hr,refresh:Kr}=ec({baseUrl:t,accessToken:Z,guestAllowed:Ae,weeks:52,cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{data:ua,refresh:qr}=Qi();u.useEffect(()=>{ua&&typeof ua=="object"&&qi(ua)},[ua]);const Ke=u.useMemo(()=>J==="day"?"hour":J==="total"?"month":"day",[J]),mo=u.useMemo(()=>_s(Ke),[Ke]),ma="day",ho=u.useMemo(()=>_s(ma),[]),[qe,Vr]=u.useState(()=>({key:"day",dir:"desc"}));u.useEffect(()=>{Vr(y=>!yr.has(y.key)||y.key===Ke?y:{key:Ke,dir:y.dir})},[Ke]);const _t=u.useMemo(()=>yr.has(qe.key)&&qe.key!==Ke?{...qe,key:Ke}:qe,[Ke,qe]),ha=u.useMemo(()=>{if(J==="day")return Array.isArray(Je)?Je.filter(R=>R?.hour&&!R?.future):[];if(J==="total"){const R=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return _c(R)}const y=Br;return!y.some(R=>!R?.missing&&!R?.future)&&be.length>0?be.filter(R=>!R?.future).slice(-30).filter(R=>R?.day):y},[J,Je,Br,be]),Ut=u.useMemo(()=>ws(ha,_t),[ha,_t]),Wr=u.useMemo(()=>ha.some(y=>!y?.missing&&!y?.future),[ha]),Ua=u.useMemo(()=>{if(!Gt.has(J))return 1;const y=Math.ceil(Ut.length/Da);return y>0?y:1},[J,Ut.length]),[Ha,pa]=u.useState(0);u.useEffect(()=>{if(!Gt.has(J)){pa(0);return}pa(y=>Math.min(y,Ua-1))},[Ua,J]),u.useEffect(()=>{Gt.has(J)&&pa(0)},[J,qe.dir,qe.key]);const po=u.useMemo(()=>Gt.has(J)?wc(Ut,Ha,Da):Ut,[Ha,J,Ut]),Gr=u.useMemo(()=>Ac(Ir,{period:J}),[Ir,J]),wt=u.useMemo(()=>yr.has(qe.key)?{...qe,key:ma}:qe,[qe]),xo=u.useMemo(()=>ws(Gr,wt),[Gr,wt]),go=u.useMemo(()=>da?be:J==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[be,J,Je,da]),fo=da?_e:io,yo=da?we:lo;function bo(y,L){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(L.endsWith("_tokens")){const R=L==="total_tokens"?Ca(y):y?.[L];return e.jsx("span",{title:k(R),children:b(R)})}return Aa(y?.[L])}function ko(y){const L=y?.[Ke];if(L==null)return"";const R=String(L);if(Ke==="hour"){const[q,Le]=R.split("T");if(q&&Le)return`${q} ${Le.slice(0,5)}`}return R}function _o(y){const L=y?.[ma];return L==null?"":String(L)}function wo(y){Vr(L=>L.key===y?{key:y,dir:L.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function vo(y){return _t.key!==y?"none":_t.dir==="asc"?"ascending":"descending"}function jo(y){return _t.key!==y?"":_t.dir==="asc"?"▲":"▼"}function No(y){return wt.key!==y?"none":wt.dir==="asc"?"ascending":"descending"}function So(y){return wt.key!==y?"":wt.dir==="asc"?"▲":"▼"}const Ka=u.useMemo(()=>{if(!r&&!te&&!i&&!le)return 0;const y=Number(Ye?.active_days);if(Number.isFinite(y))return y;let L=0;const R=new Set,q=(ve,Ue,Ee)=>{typeof ve!="string"||!ve||R.has(ve)||br(Ue,Ee)&&(R.add(ve),L+=1)};if(Array.isArray(kt))for(const ve of kt)q(ve?.day,Ca(ve));const Le=Array.isArray(Ye?.weeks)?Ye.weeks:[];for(const ve of Le)for(const Ue of Array.isArray(ve)?ve:[]){const Ee=Xs(Ue);q(Ue?.day,Ee,Ue?.level)}return L},[r,te,Ye?.active_days,Ye?.weeks,kt]),[Yr,Jr]=u.useState("month"),Co=u.useCallback(y=>{_&&!i&&_a(a?.userId,"history"),y==="custom"?(Jr(L=>L==="custom"?"month":L),xt(L=>Ge&&Xe?"custom":L),gt(!0)):(xt(y),Jr(y),gt(!1))},[Ge,Xe,_,i,a?.userId]),To=u.useCallback((y,L)=>{_&&!i&&_a(a?.userId,"history"),Ra(y),Ia(L),xt("custom"),gt(!1)},[_,i,a?.userId]),Ao=u.useCallback(y=>{gt(y),!y&&Et==="custom"&&!Ge&&xt(Yr)},[Et,Ge,Yr]),Do=u.useRef(null),xa=u.useMemo(()=>[t||"",Oe||"",_?"cloud":"local",ze??"",J||"",_e||"",we||"",me||"",ye||"all",he||"",ge??""].join(""),[ze,_,t,Oe,_e,J,ye,he,me,we,ge]),Ht=u.useCallback(async()=>Qs(Do,xa,async()=>{_&&Vi(),_||Wi(),await Promise.all([Rr(),Kr(),Ur(),Pr(),Or(),Fr(),..._?[]:[Ft()]])}),[_,Fr,Ft,Kr,Pr,Or,Ur,Rr,xa]),Mo=u.useRef(null),Zr=u.useCallback(async()=>Qs(Mo,xa,async()=>{await em({refreshUsageStats:Ht,refreshUsageLimits:qr})}),[xa,qr,Ht]),qa=u.useRef(Ht);u.useEffect(()=>{qa.current=Ht},[Ht]);const Va=u.useRef(null);u.useEffect(()=>{if(!le||te||_)return;Va.current||(Va.current=cs({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Va.current.then(()=>{if(y)return qa.current()}).catch(L=>{y&&console.warn("[DashboardPage] Reload sync failed:",L)}),()=>{y=!1}},[le,te,_]),u.useEffect(()=>{if(!le||te||_)return;const y=Sc({refresh:()=>qa.current(),onError:L=>console.warn("[DashboardPage] Automatic usage refresh failed:",L)});return()=>y.stop()},[le,te,_]);const Lo=u.useCallback(async()=>{Q(!0);try{le&&await cs(Xu),await Zr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{Q(!1)}},[le,Zr]),ga=Te||Er||ao||Hr||co||$r||oo,Wa=!B&&(oe||_&&ga&&!Wr),Eo=u.useMemo(()=>l("shared.data_source",{source:String(bt||"edge").toUpperCase()}),[bt,p]),fa=u.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Ro="",Qr=u.useMemo(()=>!fa||fa.includes("@")?l("dashboard.identity.fallback"):fa,[fa]),Xr=u.useMemo(()=>Qr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Qr]),es=u.useMemo(()=>i?l("dashboard.identity.fallback"):Xr,[Xr,Ro,i]),ts=u.useMemo(()=>{let y=null;const L=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(kt))for(const q of kt)q?.day&&br(Ca(q))&&L(q.day);const R=Array.isArray(Ye?.weeks)?Ye.weeks:[];for(const q of R)for(const Le of Array.isArray(q)?q:[]){if(!Le?.day)continue;const ve=Xs(Le),Ue=Le?.level;br(ve,Ue)&&L(Le.day)}return y},[Ye?.weeks,kt]),Io=u.useMemo(()=>i?[]:(Array.isArray(O?.subscriptions?.items)?O.subscriptions.items:[]).map(R=>{const q=typeof R?.tool=="string"?R.tool.trim():"",ve=(typeof R?.plan_type=="string"?R.plan_type:typeof R?.planType=="string"?R.planType:"").trim();return!q||!ve?null:{tool:q,planType:ve,provider:typeof R?.provider=="string"?R.provider.trim():"",product:typeof R?.product=="string"?R.product.trim():"",rateLimitTier:typeof R?.rate_limit_tier=="string"?R.rate_limit_tier.trim():typeof R?.rateLimitTier=="string"?R.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,O]),Fo=e.jsx(Xi,{heatmap:Ye,timeZoneLabel:ca,timeZoneShortLabel:zt,hideLegend:W,defaultToLatestMonth:W}),$o=u.useMemo(()=>`${_e}..${we}`,[_e,J,we]),Po=l("usage.summary.total"),Me=pe!=null,vt=Me?Ca(pe):0,Oo=b(vt),zo=u.useCallback(()=>{f(x===Yt.COMPACT?Yt.FULL:Yt.COMPACT)},[f,x]),Bo=l("dashboard.core_index.collapse_label"),Uo=l("dashboard.core_index.expand_label"),Ho=l("dashboard.core_index.collapse_aria"),Ko=l("dashboard.core_index.expand_aria"),qo=!W,jt=l("shared.placeholder.short"),Ga=u.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let L=null,R=0;for(const Ue of y){const Ee=Tt(Ue?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>R&&(R=Ee,L=Ue)}let q=jt,Le=jt,ve="0.0";if(L&&R>0){q=L?.source?String(L.source).toUpperCase():jt;const Ue=Array.isArray(L?.models)?L.models:[];let Ee=0;for(const tr of Ue){const ba=Tt(tr?.totals);!Number.isFinite(ba)||ba<=0||ba>Ee&&(Ee=ba,Le=tr?.model?String(tr.model):jt)}Ee>0&&(ve=(Ee/R*100).toFixed(1))}return{agentName:q,modelName:Le,modelPercent:ve}},[tt,jt]),Ya=Aa(vt),Vo=l("dashboard.screenshot.twitter_text",{total_tokens:Ya==="-"?jt:Ya,agent_name:Ga.agentName,model_name:Ga.modelName,model_percent:Ga.modelPercent}),Wo=u.useMemo(()=>W?[]:tm,[W]),Go=u.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(vt):"—",title:Me?k(vt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(pe?.input_tokens):"—",title:Me?k(pe?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(pe?.output_tokens):"—",title:Me?k(pe?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(pe?.cached_input_tokens):"—",title:Me?k(pe?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(pe?.reasoning_output_tokens):"—",title:Me?k(pe?.reasoning_output_tokens):void 0}],[pe?.cached_input_tokens,pe?.input_tokens,pe?.output_tokens,pe?.reasoning_output_tokens,vt,Me,b,k]),Ja=(tt?.sources||[]).some(y=>(y.models||[]).some(L=>L.pricing?.status==="unpriced"&&L.cost_source!=="provider_reported"&&Number(L.totals?.total_tokens)>0)),Za=u.useMemo(()=>{if(Ja&&Number(pe?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=ta(pe?.total_cost_usd,{currency:g,rate:m});return Ja&&y!=="-"?`≥${y}`:y},[pe?.total_cost_usd,g,m,Ja]),Yo=u.useMemo(()=>pe?.conversation_count??null,[pe?.conversation_count]),as=u.useMemo(()=>zc(tt,{copyFn:l}),[tt]),rs=u.useMemo(()=>Uc(tt,{limit:3,copyFn:l}),[tt]),Jo=Qu({enabled:S,handle:es,startDate:ts,activeDays:Ka,summary:pe,topModels:rs,period:J,periodFrom:_e,periodTo:we,heatmap:Ye,accessToken:typeof Z=="string"?Z:null,userId:a?.userId||null,currency:g,exchangeRate:m}),Zo=u.useCallback(()=>$(!0),[]),Qo=u.useCallback(()=>$(!1),[]),Xo=u.useCallback(()=>v(!0),[]),ei=u.useCallback(()=>v(!1),[]),ti=Za&&Za!=="-"&&as.length>0,Kt=l("dashboard.install.cmd.init"),Qa=We?null:C,Xa=Qa?l("dashboard.install.cmd.init_link_code",{link_code:Qa}):Kt,ai=Kt,ri=l("dashboard.install.cmd.sync"),si=Qa?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ni=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const oi=!!(O?.install?.has_active_device_token??O?.install?.hasActiveDeviceToken),ii=vc({publicMode:i,screenshotMode:W,forceInstall:F,accessEnabled:ae,heatmapLoading:Hr,activeDays:Ka,hasActiveDeviceToken:oi}),li=l("dashboard.install.prompt"),ci=u.useCallback(async()=>{!Xa||!await ds(Xa)||(ue(!0),window.setTimeout(()=>ue(!1),2e3))},[Xa]);u.useCallback(async()=>{!Kt||!await ds(Kt)||(je(!0),window.setTimeout(()=>je(!1),2e3))},[Kt]);const er=u.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[p]),[di,ui]=u.useMemo(()=>{const y=er.split("{{cmd}}");return y.length===1?[er,""]:[y[0],y.slice(1).join("{{cmd}}")]},[er]),qt=s&&!i,Vt=!r&&!te&&!s&&!le&&!i;u.useEffect(()=>{qt||Vt||Wa||ne(!0)},[Wa,Vt,qt]);const ya=rc(am,rm);return u.useEffect(()=>{X.current||qt||Vt||ga||(X.current=!0,h?.())},[h,Vt,qt,ga]),e.jsxs(e.Fragment,{children:[e.jsx(lu,{copy:l,accountView:_,accountScopeSwitchable:V,onOpenShare:Zo,screenshotMode:W,showExpiredGate:qt,showAuthGate:Vt,identityDisplayName:es,identityStartDate:ts,activeDays:Ka,identitySubscriptions:Io,identityScrambleDurationMs:de,projectUsageEntries:no,projectUsageLimit:ro,setProjectUsageLimit:so,projectDetailQuery:{from:_e,to:we,timeZone:he,tzOffsetMinutes:ge},topModels:rs,signedIn:r,publicMode:i,isLocalMode:le,shouldShowInstall:ii,installPrompt:li,handleCopyInstall:ci,installCopied:se,installCopiedLabel:ni,installCopyLabel:si,installInitCmdDisplay:ai,linkCodeLoading:I,linkCodeError:w,trendRowsForDisplay:go,trendFromForDisplay:fo,trendToForDisplay:yo,trendZoomConfig:uo,usageFrom:_e,usageTo:we,period:J,trendTimeZoneLabel:Ba,activityHeatmapBlock:Fo,periodsForDisplay:Wo,setSelectedPeriod:Co,customFrom:Ge,customTo:Xe,onCustomRangeApply:To,customRangeOpen:Fa,onCustomRangeOpenChange:Ao,metricsRows:Go,summaryLabel:Po,summaryValue:Oo,hasSummary:Me,summaryLoading:Er,providersLoading:$r,summaryFullValue:Ya,onToggleSummaryFormat:zo,summaryTotalTokensRaw:H(vt)||0,summaryCostValue:Za,summaryConversationsValue:Yo,rollingUsage:et,costInfoEnabled:ti,openCostModal:Xo,allowBreakdownToggle:qo,coreIndexCollapsed:ie,setCoreIndexCollapsed:G,coreIndexCollapseLabel:Bo,coreIndexExpandLabel:Uo,coreIndexCollapseAria:Ho,coreIndexExpandAria:Ko,refreshAll:Lo,usageLoadingState:ga,announceUsageLoading:Te,initialDashboardLoading:Wa,usageError:to,rangeLabel:$o,timeZoneRangeLabel:za,usageSourceLabel:Eo,fleetData:as,hasDetailsActual:Wr,dailyEmptyPrefix:di,installSyncCmd:ri,dailyEmptySuffix:ui,detailsColumns:mo,ariaSortFor:vo,toggleSort:wo,sortIconFor:jo,pagedDetails:po,dailyBreakdownRows:xo,dailyBreakdownColumns:ho,dailyBreakdownAriaSortFor:No,dailyBreakdownSortIconFor:So,dailyBreakdownDateKey:ma,detailsDateKey:Ke,renderDetailDate:ko,renderDailyBreakdownDate:_o,renderDetailCell:bo,DETAILS_PAGED_PERIODS:Gt,detailsPageCount:Ua,detailsPage:Ha,setDetailsPage:pa,costModalOpen:j,closeCostModal:ei,deviceOptions:$a,selectedDevice:Pa,onDeviceChange:y=>{if(V){const L=mu(y);Ce(L.scopeOverride),L.scopeOverride===null&&!i&&_a(a?.userId,"view"),nt(L.deviceId);return}_&&!i&&_a(a?.userId,"view"),nt(y||null)},deviceUsageBlock:Oa,localHistoryOnly:!_&&Be.some(y=>y.imported_at),localHistoryRevision:_?0:ia,leftCardOrder:ya.left.order,onLeftReorder:ya.left.reorder,rightCardOrder:ya.right.order,onRightReorder:ya.right.reorder}),e.jsx(Zu,{open:S,onClose:Qo,data:Jo,twitterText:Vo})]})}export{Wm as DashboardPage};
1
+ import{o as Nr,r as u,j as e,L as mi,dD as hi,W as pt,aB as ea,aC as He,dE as pi,dF as xi,az as ss,dG as ka,aH as en,aI as tn,aJ as Sr,dH as gi,dI as fi,dJ as yi,aL as Cr,aK as Jt,dK as bi,dL as ki,dM as H,c as l,V as St,X as Tr,i as Ie,aA as ta,bi as Zt,z as an,dN as _i,an as wi,l as Yt,cg as Aa,y as Ct,dO as vi,U as rn,Q as sn,aN as ji,ao as Ni,B as Si,R as Ci,h as Ti,dP as Ai,dQ as Di,dR as Mi,dS as Li,am as ns,_ as Ei,a as Ri,dT as os,g as Ii,Z as Fi,ct as $i,dU as Pi,dV as Oi,dW as zi,dX as Bi,dY as Ui,ch as is,cU as ls,dZ as Hi,d_ as Ki,aU as qi,d6 as _a,d$ as cs,aS as ds,e0 as Vi,e1 as Wi,e2 as Gi}from"./__vite-browser-external-CkF0pdTJ.js";import{u as st}from"./use-latest-request-guard-tXGuKvua.js";import{u as us,L as Yi}from"./use-ordered-list-D6-YzYJI.js";import{t as ms,T as nn,g as Ji,u as Zi}from"./TrendMonitor-DWnlBn3H.js";import{u as Qi}from"./use-usage-limits-BlwtyPtT.js";import{u as aa}from"./useCurrency-CwCGJLHb.js";import{u as Ne}from"./useTokenFormat-BUNBUX-x.js";import{f as ut,A as Xi}from"./provider-display-CKdhBOwz.js";import{g as el,q as on,J as tl,M as al,m as Ve}from"./react-BY0y0K4x.js";import{u as rl,C as sl,a as nl,b as hs,D as ol,S as il,v as ll,s as cl,K as dl,P as ul}from"./sortable.esm-D7jd9mE_.js";import{D as ml,a as hl,b as pl,c as xl,d as gl,e as fl}from"./DialogTitle-B0cNIo0E.js";import{D as yl}from"./DialogClose-CXttnna-.js";import{C as De}from"./Card-CuSeWBDM.js";import{S as ln}from"./Select-7w1su8lw.js";import{P as At}from"./ProviderIcon-CtmL1CmY.js";import{a as cn,u as dn}from"./use-transform-BEiXvAuE.js";import{u as un}from"./use-reduced-motion-DfbDxs5a.js";import{f as wa,D as bl,g as kl}from"./DateRangePopover-C3WfGy-0.js";import{I as mn}from"./info-B-f9hWcw.js";import{A as hn}from"./index-9OCL-BL8.js";import{L as _l}from"./loader-circle-Lmjrs8XX.js";import{C as wl}from"./chevron-down-CtECtDmx.js";import{P as vl,a as jl,b as Nl,c as Sl,d as Cl}from"./PopoverPopup-pugRu3RC.js";import{F as ot}from"./FadeIn-H7S3TMHi.js";import{u as Tl,a as Al,r as Dl,b as ps,P as Ml,c as Ll}from"./local-usage-transfer-Ds6cF41d.js";import{L as xs}from"./LoginCard-BZZmzUGh.js";import{L as El,A as Rl}from"./agent-logos-Dqe3Vrah.js";import{i as Il}from"./host-mode-Bc_iTzHk.js";import{M as pn}from"./monitor-smartphone-XRiYiY8u.js";import{C as Fl}from"./check-bpSCJZWh.js";import"./terminal-CLOlvzR-.js";import"./use-limits-display-prefs-CCuLFy00.js";import"./play-DaD9EMjk.js";import"./composite-BHisG82k.js";import"./store-D9_jo_do.js";import"./SelectItemText-CaEUmWkj.js";import"./usePositioner-BqHtRIrE.js";import"./safePolygon-CSG_P7rG.js";import"./arrow-left-Cr_2QnDu.js";const xn={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};xn.node;const $l=Nr(xn);const gn={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"}]]};gn.node;const Pl=Nr(gn);const fn={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"]};fn.node;const Ol=Nr(fn);function zl(t,a,r={}){const s=t.get();let n=null,i=s,o;const c=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const g=gs(t.get()),m=gs(i);if(g===m){d();return}const x=n?n.getGeneratorVelocity():t.getVelocity();d(),n=new tl({keyframes:[g,m],velocity:x,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},p=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((g,m)=>{i=g,o=x=>m(ar(x,c)),el.postRender(p)},d),on(a)){let g=r.skipInitialAnimation===!0;const m=a.on("change",f=>{g?(g=!1,t.jump(ar(f,c),!1)):t.set(ar(f,c))}),x=t.on("destroy",m);return()=>{m(),x()}}return d}function ar(t,a){return a?t+a:t}function gs(t){return typeof t=="number"?t:parseFloat(t)}function Bl(t,a={}){const{isStatic:r}=u.useContext(al),s=()=>on(t)?t.get():t;if(r)return cn(s);const n=dn(s());return u.useInsertionEffect(()=>zl(n,t,a),[n,JSON.stringify(a)]),n}function Ul(t,a={}){return Bl(t,{type:"spring",...a})}function Hl(){return e.jsxs(mi,{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 Kl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Hl,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function ql({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},c=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:c,children:t})}var Vl={};function Wl(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 Gl({mv:t,digit:a,height:r}){const s=cn(t,n=>{const i=(n%10+10)%10,o=(10+a-i)%10;let c=o*r;return o>5&&(c-=10*r),c});return e.jsx(Ve.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Yl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Jl(t,a){const r=t/a;return Math.floor(Yl(r))}function Zl(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((c,d)=>/\d/.test(c)&&(s===-1||d<s)).length,i=0,o=!1;return r.map(c=>{if(!/\d/.test(c))return c==="."&&(o=!0),c;if(!o){const d=10**Math.max(n-1,0);return n-=1,d}return i+=1,10**-i})}function Ql({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const d=Wl(t,r),h=t!=="."&&t!==",",p=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...d,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...p?{width:d.width}:null},children:t})}const i=Jl(a,t),o=dn(0),c=Ul(o,{stiffness:220,damping:26,mass:.8});return u.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(d,h)=>e.jsx(Gl,{mv:c,digit:h,height:r},h))})}function Xl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:c=0,textColor:d="inherit",fontWeight:h="inherit",containerStyle:p,counterStyle:g,digitStyle:m,gradientHeight:x=14,gradientFrom:f="rgba(255,255,255,0.95)",gradientTo:b="rgba(255,255,255,0)",topGradientStyle:k,bottomGradientStyle:j}){const v=String(a??t??""),C=u.useMemo(()=>Array.isArray(n)&&n.length?n:Zl(v),[n,v]),D=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Vl?.VITEST==="true",M=un()||D,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,I=r+s;return M?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:d,fontSize:r,fontWeight:h,lineHeight:1,...p,...g},children:v}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...p},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:c,paddingRight:c,lineHeight:1,color:d,fontWeight:h,...g},children:C.map((N,w)=>e.jsx(Ql,{place:N,value:A,height:I,digitStyle:m,shouldReduceMotion:M},`${String(N)}-${w}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:k??{height:x,background:`linear-gradient(to bottom, ${f}, ${b})`}}),e.jsx("span",{style:j??{height:x,background:`linear-gradient(to top, ${f}, ${b})`}})]})]})}function ec({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:c,now:d,accountView:h=!1,accountAccessToken:p=null,accountRevision:g=0,accountViewResolving:m=!1,deviceId:x=null}={}){const f=!!(h&&p),b=f?"cloud":"local",k=u.useMemo(()=>hi({weeks:s,weekStartsOn:n,now:d}),[d,s,n]),[j,v]=u.useState([]),[C,D]=u.useState(null),[M,A]=u.useState("edge"),[I,N]=u.useState(!1),[w,T]=u.useState(null),P=pt(),z=ea(a),K=!r,E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=st([t,k.from,k.to,s,n,b,a,p,g,m,x,o,c,r,P,K,z,E]),U=u.useMemo(()=>{if(!i)return null;const G=Sr({timeZone:o,offsetMinutes:c});return`tokentracker.heatmap.${i}.${b}.${s}.${n}.${G}.${x||"all"}${f||!g?"":`.r${g}`}`},[i,x,b,o,c,s,n,f,g]),W=u.useCallback(()=>{if(!U||typeof window>"u")return null;try{const G=window.localStorage.getItem(U);if(!G)return null;const se=JSON.parse(G);return!se||!se.heatmap?null:se}catch{return null}},[U]),F=u.useCallback(G=>{if(!(!U||typeof window>"u"))try{window.localStorage.setItem(U,JSON.stringify(G))}catch{}},[U]),S=u.useCallback(()=>{if(!(!U||typeof window>"u"))try{window.localStorage.removeItem(U)}catch{}},[U]),$=u.useRef(b);u.useEffect(()=>{$.current!==b&&($.current=b,v([]),D(null),A("edge"),T(null),N(!0))},[b]);const de=u.useCallback(async()=>{const G=O(),se=await He(a),ue=f?await He(p):null;if(!G()||!se&&!P&&!E&&!f)return;if(f&&!ue){T("Your session expired. Please sign in again to view account data."),N(!1);return}const ke=f?ue:se,je=f?pi:xi,Te=f?en:tn;N(!0),T(null);try{try{const X=await je({baseUrl:t,accessToken:ke,weeks:s,to:k.to,weekStartsOn:n,device:x,timeZone:o,tzOffsetMinutes:c}),te=Array.isArray(X?.weeks)?X.weeks:[];if(!G())return;if(!te.length&&K){const ee=W();if(ee?.heatmap){if(!G())return;D(ee.heatmap),v(ee.daily||[]),A("cache");return}}if(!te.some(ee=>(Array.isArray(ee)?ee:[]).some(Y=>Y&&Number.isFinite(Number(Y.level))))&&te.length){const ee=[];for(const Z of te)for(const ae of Array.isArray(Z)?Z:[])ae?.day&&ee.push({day:ae.day,total_tokens:ae.total_tokens??ae.value??0,billable_total_tokens:ae.billable_total_tokens??ae.value??ae.total_tokens??0});const Y=ss({dailyRows:ee,weeks:s,to:X?.to||k.to,weekStartsOn:n});if(!G())return;v(ee),D({...Y,week_starts_on:n,active_days:ee.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ka({dailyRows:ee,to:X?.to||k.to})}),A("client"),K?F({heatmap:{...Y,week_starts_on:n,active_days:ee.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ka({dailyRows:ee,to:X?.to||k.to})},daily:ee,fetchedAt:new Date().toISOString()}):S();return}if(!G())return;D(X||null),v([]),A("edge"),X&&K?F({heatmap:X,daily:[],fetchedAt:new Date().toISOString()}):K||S();return}catch(X){const te=X,xe=te?.status??te?.statusCode;if(xe===401||xe===403)throw X}if(!G())return;const Q=await Te({baseUrl:t,accessToken:ke,from:k.from,to:k.to,device:x,timeZone:o,tzOffsetMinutes:c}),B=Array.isArray(Q?.data)?Q.data:[];if(!G())return;v(B);const ne=ss({dailyRows:B,weeks:s,to:k.to,weekStartsOn:n});if(!G())return;D({...ne,week_starts_on:n,active_days:B.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ka({dailyRows:B,to:k.to})}),A("client"),K?F({heatmap:{...ne,week_starts_on:n,active_days:B.filter(X=>Number(X?.billable_total_tokens??X?.total_tokens)>0).length,streak_days:ka({dailyRows:B,to:k.to})},daily:B,fetchedAt:new Date().toISOString()}):S()}catch(Q){if(!G())return;if(K){const B=W();if(B?.heatmap){if(!G())return;D(B.heatmap),v(B.daily||[]),A("cache"),T(null)}else{const ne=Q;T(ne?.message||String(ne)),v([]),D(null),A("edge")}}else{const B=Q;T(B?.message||String(B)),v([]),D(null),A("edge")}}finally{G()&&N(!1)}},[a,t,P,r,K,k.from,k.to,W,z,o,c,n,s,S,F,E,f,p,g,x,O]);return u.useEffect(()=>{if(m){N(!0);return}if(!z&&!r&&!P&&!E&&!f){v([]),N(!1),T(null),D(null),A("edge");return}if(!K)S(),v([]),T(null),D(null),A("edge");else{const G=W();G?.heatmap&&(D(G.heatmap),v(G.daily||[]),A("cache"))}de()},[a,P,W,de,z,r,K,S,E,m]),{range:k,daily:j,heatmap:C,source:P?"mock":M==="client"?"edge":M,loading:I,error:w,refresh:de}}const tc="tokentracker.dashboard.leftCardOrder.v1",ac="tokentracker.dashboard.rightCardOrder.v1";function rc(t,a){const r=us(tc,t),s=us(ac,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=u.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const sc=10;function nc({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[c,d]=u.useState([]),[h,p]=u.useState(!1),[g,m]=u.useState(null),x=pt(),f=ea(a),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=st([t,a,r,s,n,i,o]),j=u.useCallback(async()=>{const v=k(),C=await He(a);if(v()){if(!C&&!x&&!b){d([]),m(null),p(!1);return}p(!0),m(null);try{const D=await gi({baseUrl:t,accessToken:C,limit:sc,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!v())return;d(Array.isArray(D?.entries)?D.entries:[])}catch(D){if(!v())return;const M=D?.message||String(D);m(M),d([])}finally{v()&&p(!1)}}},[a,t,r,x,n,i,s,o,b,k]);return u.useEffect(()=>{if(!f&&!x&&!b){d([]),m(null),p(!1);return}d([]),m(null),p(!0),j()},[x,j,f,b]),{entries:c,loading:h,error:g,refresh:j}}const fs="tokentracker.usage-cache-index",ys=24;function bs({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:c,timeZone:d,tzOffsetMinutes:h,now:p,accountView:g=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:f=!1,deviceId:b=null}={}){const k=!!(g&&m),j=k?"cloud":"local",[v,C]=u.useState([]),[D,M]=u.useState(null),[A,I]=u.useState(null),[N,w]=u.useState("edge"),[T,P]=u.useState(null),[z,K]=u.useState(!1),[E,O]=u.useState(null),U=pt(),W=ea(a),F=!r&&!U,S=b||"all",$=(()=>{if(!c)return null;const Q=oc(t)||"default",B=i?o?"daily-summary":"daily-only":"summary",ne=Sr({timeZone:d,offsetMinutes:h});return`tokentracker.usage.${c}.${j}.${Q}.${s}.${n}.${B}.${ne}.${S}${k||!x?"":`.r${x}`}`})(),de=u.useRef(j);u.useEffect(()=>{de.current!==j&&(de.current=j,C([]),M(null),I(null),w("edge"),P(null),O(null),K(!0))},[j]);const ie=u.useCallback(()=>{if(!$||typeof window>"u")return null;try{const Q=window.localStorage.getItem($);if(!Q)return null;const B=JSON.parse(Q),ne=o?!!B?.summary:Array.isArray(B?.daily);return!B||!ne?null:(ms(fs,$,ys),B)}catch{return null}},[o,$]),G=u.useCallback(Q=>{if(!(!$||typeof window>"u"))try{window.localStorage.setItem($,JSON.stringify(Q)),ms(fs,$,ys)}catch{}},[$]),se=u.useCallback(()=>{if(!(!$||typeof window>"u"))try{window.localStorage.removeItem($)}catch{}},[$]),ue=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),ke=st([t,s,n,i,o,j,a,m,x,b,d,h,r,U,F,f,W,ue]),je=u.useCallback(async()=>{const Q=ke(),B=await He(a),ne=k?await He(m):null;if(!Q()||!B&&!U&&!ue&&!k)return;if(k&&!ne){O("Your session expired. Please sign in again to view account data."),K(!1);return}const X=k?en:tn,te=k?fi:yi,xe=k?ne:B;K(!0),O(null);try{let ee=null,Y=null;if(i)if(o){const[Fe,$e]=await Promise.allSettled([X({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h}),te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0})]);if(Fe.status==="rejected")throw Fe.reason;ee=Fe.value,Y=$e.status==="fulfilled"?$e.value:null}else ee=await X({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h});else o&&(Y=await te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0}));let Z=i&&Array.isArray(ee?.data)?ee.data:[];i&&(Z=sr(Z,s,n,{timeZone:d,offsetMinutes:h,now:p}));let ae=o&&(Y?.totals||ee?.summary?.totals)||null,Se=o&&(Y?.rolling||ee?.summary?.rolling)||null;if(o&&i&&!ae&&!Y)try{const Fe=await te({baseUrl:t,accessToken:xe,from:s,to:n,device:b,timeZone:d,tzOffsetMinutes:h,rolling:!0});ae=Fe?.totals||null,Se=Fe?.rolling||Se}catch{}const Ae=new Date().toISOString();if(!Q())return;C(Z),M(ae),I(Se),w("edge"),P(Ae),(ae||!o&&i)&&F?G({summary:ae,rolling:Se,daily:Z,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:Ae}):F||se()}catch(ee){if(!Q())return;if(F){const Y=ie();if(Y?.summary||!o&&Array.isArray(Y?.daily)){M(Y.summary),I(Y.rolling||null);const Z=Array.isArray(Y.daily)?Y.daily:[],ae=i?sr(Z,Y.from||s,Y.to||n,{timeZone:d,offsetMinutes:h,now:p}):Z;C(ae),w("cache"),P(Y.fetchedAt||null),O(null)}else{const Z=ee;O(Z?.message||String(Z)),C([]),M(null),I(null),w("edge"),P(null)}}else{const Y=ee;O(Y?.message||String(Y)),C([]),M(null),I(null),w("edge"),P(null)}}finally{Q()&&K(!1)}},[a,t,s,i,o,U,r,F,p,ie,W,d,n,h,se,G,ue,k,m,x,b,ke]);return u.useEffect(()=>{if(f){K(!0);return}const Q=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!W&&!r&&!U&&!Q&&!k){C([]),M(null),I(null),O(null),K(!1),w("edge"),P(null);return}if(!F)se(),C([]),M(null),I(null),O(null),w("edge"),P(null);else{const B=ie();if(B?.summary||!o&&Array.isArray(B?.daily)){M(B.summary),I(B.rolling||null);const ne=Array.isArray(B.daily)?B.daily:[],X=i?sr(ne,B.from||s,B.to||n,{timeZone:d,offsetMinutes:h,now:p}):ne;C(X),w("cache"),P(B.fetchedAt||null),O(null)}else C([]),M(null),I(null),w("edge"),P(null),O(null)}K(!0),je()},[a,U,ie,je,W,r,F,se,ue,f,o]),u.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const Q=15e3;let B=Date.now();const ne=()=>{if(document.visibilityState!=="visible")return;const X=Date.now();X-B<Q||(B=X,je())};return window.addEventListener("focus",ne),document.addEventListener("visibilitychange",ne),()=>{window.removeEventListener("focus",ne),document.removeEventListener("visibilitychange",ne)}},[je]),{daily:v,summary:D,rolling:A,source:U?"mock":N,fetchedAt:T,loading:z,error:E,refresh:je}}function oc(t){try{return new URL(t).host}catch{return null}}function rr(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Jt(o)===a?o:null}function ic(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function sr(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=rr(a),c=rr(r);if(!o||!c||c<o)return Array.isArray(t)?t:[];const d=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=Cr({timeZone:s,offsetMinutes:n,date:d}),p=rr(h),g=p?p.getTime():d.getTime(),m=new Map;for(const f of t||[])f?.day&&m.set(f.day,f);const x=[];for(let f=o;f<=c;f=ic(f,1)){const b=Jt(f),k=m.get(b),j=f.getTime()>g;if(k){x.push({...k,missing:!1,future:j});continue}x.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 x}function lc({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:c,accountView:d=!1,accountAccessToken:h=null,accountRevision:p=0,accountViewResolving:g=!1,deviceId:m=null}={}){const x=!!(d&&h),f=x?"cloud":"local",[b,k]=u.useState(null),[j,v]=u.useState("edge"),[C,D]=u.useState(!1),[M,A]=u.useState(null),I=pt(),N=ea(a),w=!r,T=u.useMemo(()=>{if(!i)return null;const S=cc(t)||"default",$=Sr({timeZone:o,offsetMinutes:c});return`tokentracker.modelBreakdown.${i}.${f}.${S}.${s}.${n}.${$}.${m||"all"}${x||!p?"":`.r${p}`}`},[t,i,m,s,f,o,n,c,x,p]),P=u.useCallback(()=>{if(!T||typeof window>"u")return null;try{const S=window.localStorage.getItem(T);if(!S)return null;const $=JSON.parse(S);return!$||!$.breakdown?null:$}catch{return null}},[T]),z=u.useCallback(S=>{if(!(!T||typeof window>"u"))try{window.localStorage.setItem(T,JSON.stringify(S))}catch{}},[T]),K=u.useCallback(()=>{if(!(!T||typeof window>"u"))try{window.localStorage.removeItem(T)}catch{}},[T]),E=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),O=st([t,s,n,f,a,h,p,m,o,c,r,I,w,g,N,E]),U=u.useRef(f);u.useEffect(()=>{U.current!==f&&(U.current=f,k(null),v("edge"),A(null),D(!0))},[f]);const W=u.useCallback(async()=>{const S=O(),$=await He(a),de=x?await He(h):null;if(!S()||!$&&!I&&!E&&!x)return;if(x&&!de){A("Your session expired. Please sign in again to view account data."),D(!1);return}const ie=x?de:$,G=x?bi:ki;D(!0),A(null);try{const se=await G({baseUrl:t,accessToken:ie,from:s,to:n,device:m,timeZone:o,tzOffsetMinutes:c});if(!S())return;k(se||null),v("edge"),se&&w?z({breakdown:se,fetchedAt:new Date().toISOString()}):w||K()}catch(se){if(!S())return;if(w){const ue=P();if(ue?.breakdown)k(ue.breakdown),v("cache"),A(null);else{k(null),v("edge");const ke=se;A(ke?.message||String(ke))}}else{k(null),v("edge");const ue=se;A(ue?.message||String(ue))}}finally{S()&&D(!1)}},[a,t,s,I,r,w,P,o,n,N,c,K,z,E,x,h,p,m,O]);return u.useEffect(()=>{if(g){D(!0);return}if(!N&&!r&&!I&&!E&&!x){k(null),v("edge"),A(null),D(!1);return}if(!w)K(),k(null),v("edge"),A(null);else{const S=P();S?.breakdown?(k(S.breakdown),v("cache"),A(null)):(k(null),v("edge"),A(null))}D(!0),W()},[a,I,P,W,N,r,w,K,E,g]),{breakdown:b,source:I?"mock":j,loading:C,error:M,refresh:W}}function cc(t){try{return new URL(t).host}catch{return null}}const yn=new Set(["day","hour","month"]);function dc(t){return yn.has(t)}function ks(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 uc(t,a){const r=ks(t),s=ks(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=H(t),i=H(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function mc(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 hc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function pc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function xc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),c=Number(r[5]),d=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(c)||!Number.isFinite(d)||n<1||n>12||i<1||i>31||o<0||o>23||c<0||c>59||d<0||d>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,c,d));return Number.isFinite(h.getTime())?h.getTime():null}function gc(t,a,r){const s=r==="hour"?xc:r==="month"?pc:hc,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:mc(t,a)}function bn(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=yn.has(a)?(c,d)=>gc(c,d,a):uc,o=c=>a==="total_tokens"&&c?.billable_total_tokens!=null?c.billable_total_tokens:c?.[a];return n.map((c,d)=>({row:c,index:d})).sort((c,d)=>{const h=o(c.row),p=o(d.row),g=h==null,m=p==null;if(g&&m)return c.index-d.index;if(g)return 1;if(m)return-1;const x=i(h,p);return x!==0?x*s:c.index-d.index}).map(c=>c.row)}function fc(){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 _s(t){const a=dc(t)?t:"day";return fc().map((r,s)=>s===0?{...r,key:a}:r)}function ws(t,{key:a,dir:r}){return bn(t,{key:a,dir:r})}const Da=12,yc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function bc(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 kc(t){return yc.some(a=>bc(t?.[a]))}function _c(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=bn(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&kc(n));return s===-1?a:r.slice(s)}function wc(t,a,r=Da){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:Da,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function vc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const va=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function jc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return va.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?va.active:s<=60*6e4?va.warm:va.idle}const Nc=3e4;function Sc({refresh:t,intervalMs:a=Nc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,c=Date.now(),d=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const x=Promise.resolve().then(()=>t()).catch(f=>n(f)).then(()=>{}).finally(()=>{o===x&&(o=null)});return o=x,x},p=r.setInterval(()=>{const x=Date.now();x<d||(d=x+jc({visible:s.visibilityState==="visible",lastInteractionAt:c,now:x}),h())},a),g=()=>{s.visibilityState==="visible"&&(c=Date.now(),d=0,h())},m=()=>{c=Date.now()};return r.addEventListener("focus",g),r.addEventListener("pointerdown",m),r.addEventListener("keydown",m),s.addEventListener("visibilitychange",g),{run:h,stop(){i=!0,r.clearInterval(p),r.removeEventListener("focus",g),r.removeEventListener("pointerdown",m),r.removeEventListener("keydown",m),s.removeEventListener("visibilitychange",g)}}}function Cc(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 Jt(r)===t?r:null}function Tc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=Cc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Jt(i),to:Jt(n)}}function Ac(t,{period:a}={}){const r=(Array.isArray(t)?t:[]).filter(n=>!n?.future&&n?.day);return(a==="total"?r.filter(n=>!n?.missing):r).slice(-30)}function Ar(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function Dc(t){const a=Ar(t?.model_id);return a||null}function kn(t,a){return t?.model?String(t.model):a}function _n(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Ar(n);if(!i||i.includes("/"))continue;const o=Math.max(0,H(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function wn(t,a){const r=Ar(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function Tt(t,a=0){const r=H(t?.billable_total_tokens),s=H(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const Mc={deepseek:"dsh"};function Lc(t){const a=typeof t=="string"?t:"";return Mc[a]||a}const Ec=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens","conversation_count"],Dr=["input","output","cached","cacheCreate","reasoning"];function Ma(t){let a=0;for(const r of Dr)a+=Math.max(0,Number(t?.[r])||0);return a}function Rc(t){return Ma(t?.tokens)>0}const Qt=["priority","ultrafast"],vn=Dr,Ic={priority:{tokens:{input:"priority_input_tokens",cached:"priority_cached_input_tokens",cacheCreate:"priority_cache_creation_input_tokens",output:"priority_output_tokens",reasoning:"priority_reasoning_output_tokens"},cost:"priority_cost_usd"},ultrafast:{tokens:{input:"ultrafast_input_tokens",cached:"ultrafast_cached_input_tokens",cacheCreate:"ultrafast_cache_creation_input_tokens",output:"ultrafast_output_tokens",reasoning:"ultrafast_reasoning_output_tokens"},cost:"ultrafast_cost_usd"}};function Fc(t){const a={};let r=!1;for(const s of Qt){const n=Ic[s],i={input:Math.max(0,H(t?.[n.tokens.input])??0),output:Math.max(0,H(t?.[n.tokens.output])??0),cached:Math.max(0,H(t?.[n.tokens.cached])??0),cacheCreate:Math.max(0,H(t?.[n.tokens.cacheCreate])??0),reasoning:Math.max(0,H(t?.[n.tokens.reasoning])??0)},o=Math.max(0,H(t?.[n.cost])??0);Ma(i)<=0&&o<=0||(a[s]={tokens:i,cost:o},r=!0)}return r?a:null}function jn(t,a){if(!a||!Object.keys(a).length)return t;const r={...t||{}};for(const s of Qt){const n=a[s];if(!n)continue;const i=r[s];if(!i){r[s]={tokens:{...n.tokens},cost:n.cost};continue}for(const o of vn)i.tokens[o]+=n.tokens[o]||0;i.cost+=n.cost||0}return r}function Nn(t){return!!(t?.tiers?.priority||t?.tiers?.ultrafast)}function $c(t,a){const r=Number(t?.pricing?.[`${a}_multiplier`]);return Number.isFinite(r)&&r>1?r:0}function Pc(t){if(!Nn(t))return null;const a={input:0,output:0,cached:0,cacheCreate:0,reasoning:0};let r=!1;for(const n of vn){let i=Math.max(0,Number(t?.tokens?.[n])||0);for(const o of Qt)i-=Math.max(0,Number(t?.tiers?.[o]?.tokens?.[n])||0);a[n]=Math.max(0,i),a[n]>0&&(r=!0)}let s=Math.max(0,H(t?.cost)??0);for(const n of Qt)s-=Math.max(0,Number(t?.tiers?.[n]?.cost)||0);return s=Math.max(0,s),!r&&s<=0?null:{tokens:a,cost:s}}function Mr(t){return t?.unpriced===!0?!0:t?.costSource!=="provider_reported"&&t?.pricing?.status==="unpriced"}function vs(t,a){for(const r of Ec)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 js(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,conversation_count:0,total_cost_usd:"0"}}function Oc(t){const a=new Map;for(const r of t||[]){const s=Lc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:js(),models:new Map},a.set(s,n)),vs(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let c=n.models.get(o);const d=Fc(i?.totals);c?c.tiers=jn(c.tiers??null,d):(c={...i,model:i?.model||o,model_id:o,totals:js()},c.tiers=d,n.models.set(o,c)),vs(c.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function zc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=Oc(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const c=Tt(o?.totals),d=H(o?.totals?.total_cost_usd)??0,h=Math.max(0,H(o?.totals?.conversation_count)??0);return{source:o?.source,totalTokens:Number.isFinite(c)?c:0,totalRequests:h,totalCost:Number.isFinite(d)?d:0,inputTokens:Math.max(0,H(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,H(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,H(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0||o.totalRequests>0);if(!n.length)return[];const i=n.reduce((o,c)=>o+c.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,c)=>c.totalTokens-o.totalTokens||c.totalRequests-o.totalRequests).map(o=>{const c=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),d=i>0?o.totalTokens/i*100:0,h=Number.isFinite(d)?d.toFixed(2):"0.00",p=o.models.map(f=>{const b=Tt(f?.totals),k=Math.max(0,H(f?.totals?.conversation_count)??0);if((!Number.isFinite(b)||b<=0)&&k<=0)return null;const j=o.totalTokens>0?Math.round(b/o.totalTokens*1e3)/10:0,v=kn(f,r("shared.placeholder.short")),C=Dc(f),D=H(f?.totals?.total_cost_usd),M=b<=0?null:D??(o.totalCost>0&&o.totalTokens>0?b/o.totalTokens*o.totalCost:null),A=f?.totals||{};return{id:C,name:v,share:j,usage:b,requests:k,cost:M,tokens:{input:Math.max(0,H(A?.input_tokens)??0),output:Math.max(0,H(A?.output_tokens)??0),cached:Math.max(0,H(A?.cached_input_tokens)??0),cacheCreate:Math.max(0,H(A?.cache_creation_input_tokens)??0),reasoning:Math.max(0,H(A?.reasoning_output_tokens)??0)},tiers:f?.tiers??null,pricing:f?.pricing||null,costSource:f?.cost_source||null}}).filter(Boolean),g=o.inputTokens+o.cacheRead+o.cacheCreate,x=o.cacheRead+o.cacheCreate>0&&g>0?Math.round(o.cacheRead/g*100):null;return{source:o.source,label:c,totalPercent:String(h),totalPercentValue:d,usd:o.totalCost,usage:o.totalTokens,requests:o.totalRequests,cacheHitRate:x,cacheReusedTokens:o.cacheRead,cacheInputTokens:g,models:p}})}function Bc(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const c=Array.isArray(o?.models)?o.models:[];for(const d of c){const h=H(d?.usage),p=Math.max(0,H(d?.requests)??0);if((h==null||h<=0)&&p<=0)continue;const g=h??0,m=typeof d?.name=="string"&&d.name.trim()?d.name.trim():typeof d?.id=="string"&&d.id.trim()?d.id.trim():null;m&&s.push({model:d,name:m,usage:g,requests:p})}}const n=_n(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:c,usage:d,requests:h}of s){const p=wn(c,n);if(!p)continue;const{key:g}=p,m=r.get(g)||{id:g,name:p.name,usage:0,requests:0,cost:0,hasCost:!1,unpriced:!1,nameWeight:0,tokens:{input:0,output:0,cached:0,cacheCreate:0,reasoning:0},tiers:null,pricing:null};m.usage+=d,m.requests+=h;const x=o?.tokens||{};for(const b of Dr)m.tokens[b]+=Math.max(0,Number(x[b])||0);m.tiers=jn(m.tiers,o?.tiers??null),!m.pricing&&o?.pricing&&(m.pricing=o.pricing),d>0&&Mr(o)&&(m.unpriced=!0);const f=H(o?.cost);f!=null&&(m.cost+=f,m.hasCost=!0),n.has(g)?m.name=n.get(g):d>=m.nameWeight&&(m.name=c,m.nameWeight=d),r.set(g,m)}const i=Array.from(r.values()).reduce((o,c)=>o+c.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,requests:o.requests,cost:o.hasCost?o.cost:null,unpriced:o.unpriced===!0,tokens:{...o.tokens},tiers:o.tiers,pricing:o.pricing,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,c)=>c.usage!==o.usage?c.usage-o.usage:String(o.name).localeCompare(String(c.name)))}function Uc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:f=>f,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const i=new Map,o=new Map,c=new Map,d=[];let h=0;for(const f of n){const b=Array.isArray(f?.models)?f.models:[];for(const k of b){const j=Tt(k?.totals);if(!Number.isFinite(j)||j<=0)continue;h+=j;const v=kn(k,s("shared.placeholder.short"));d.push({name:v,tokens:j})}}const p=_n(d.map(f=>({name:f.name,weight:f.tokens})));for(const{name:f,tokens:b}of d){const k=wn(f,p);if(!k)continue;const{key:j}=k;i.set(j,(i.get(j)||0)+b),p.has(j)?o.set(j,p.get(j)):b>=(c.get(j)||0)&&(c.set(j,b),o.set(j,f))}if(!i.size)return[];const g=Array.from(i.values()).reduce((f,b)=>f+b,0),m=h>0?h:g,x=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([f,b])=>{const k=m>0?(b/m*100).toFixed(1):"0.0";return{id:f,name:o.get(f)||s("shared.placeholder.short"),tokens:b,percent:String(k)}}).sort((f,b)=>b.tokens!==f.tokens?b.tokens-f.tokens:String(f.name).localeCompare(String(b.name))).slice(0,x)}function Hc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=ta(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function Ns(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Zt(a);return(a===an?t:t*r)<.01?`<${s}0.01`:ta(t,{decimals:2,currency:a,rate:r})}function Ss(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Ie(a,{decimals:1})}const Kc=St.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=aa(),o=u.useMemo(()=>(Array.isArray(s)?s:[]).map(h=>{const p=H(h?.usd)??0,g=H(h?.usage)??0,m=Array.isArray(h?.models)?h.models:[];return{label:h?.label?String(h.label):"",usdValue:p,costLabel:Ns(p,n,i),tokensLabel:Ss(g),models:m.map(x=>{const f=H(x?.usage)??0,b=H(x?.cost)??0;return{id:x?.id?String(x.id):"",name:x?.name?String(x.name):"",tokensLabel:Ss(f),costLabel:Ns(b,n,i),sortCost:b,pricing:x?.pricing,costSource:x?.costSource,tokens:x?.tokens}}).filter(x=>x.costLabel||x.tokensLabel).sort((x,f)=>f.sortCost-x.sortCost)}}).filter(h=>h.usdValue>0||h.models.length>0).sort((h,p)=>p.usdValue-h.usdValue),[s,n,i]),c=o.some(h=>h.models.some(p=>Mr(p))),d=u.useMemo(()=>{const h=o.reduce((p,g)=>p+g.usdValue,0);return c&&h===0?l("dashboard.cost_breakdown.unpriced_label"):`${c?"≥":""}${Hc(h,n,i)}`},[o,n,i,c]);return e.jsx(ml,{open:a,onOpenChange:h=>{h||r?.()},children:e.jsxs(hl,{children:[e.jsx(pl,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(xl,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(gl,{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(fl,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(yl,{type:"button",className:"absolute top-3 right-3 flex h-9 w-9 items-center justify-center rounded-md text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-100 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50 transition-colors z-10","aria-label":l("dashboard.cost_breakdown.close"),children:e.jsx(Tr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:c?l("dashboard.cost_breakdown.known_subtotal"):l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:d}),e.jsx("p",{className:"mb-4 text-xs leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.method")}),o.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),o.map((h,p)=>{const g=`fleet-${p}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":g,className:p>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:g,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:h.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:h.costLabel||"—"})]}),h.models.map((m,x)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsxs("details",{className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("summary",{className:"cursor-pointer truncate py-1 leading-normal",title:m.name,children:m.name}),e.jsxs("div",{className:"space-y-2 py-2 pr-2 text-xs leading-relaxed",children:[e.jsx("p",{children:m.costSource==="provider_reported"?l("dashboard.cost_breakdown.reported"):m.costSource==="mixed"?l("dashboard.cost_breakdown.mixed"):l("dashboard.cost_breakdown.estimated")}),m.pricing?.status==="unpriced"&&m.costSource!=="provider_reported"?e.jsx("p",{children:l("dashboard.cost_breakdown.unpriced")}):null,m.pricing?.status==="free"?e.jsx("p",{children:l("dashboard.cost_breakdown.no_token_charge")}):null,m.tokens?e.jsx("p",{children:l("dashboard.cost_breakdown.token_mix",{input:Ie(Number(m.tokens.input)||0),output:Ie(Number(m.tokens.output)||0),read:Ie(Number(m.tokens.cached)||0),write:Ie(Number(m.tokens.cacheCreate)||0)})}):null,m.pricing?.status==="priced"?e.jsx("p",{children:l("dashboard.cost_breakdown.rates",{input:m.pricing.input,output:m.pricing.output,read:m.pricing.cache_read,write:m.pricing.cache_write})}):null]})]}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:m.costLabel||(m.pricing?.status==="unpriced"?l("dashboard.cost_breakdown.unpriced_label"):m.pricing?.status==="free"?ta(0,{currency:n,rate:i}):l("dashboard.cost_breakdown.rate_unknown"))})]},m.id||`${m.name}-${x}`))]},`${h.label}-${p}`)})]})]})})]})})]})})});function qc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,p]=u.useState(null),g=pt(),m=st([t,a,r,s,n,g]);return u.useEffect(()=>{const x=m();if(!t){o(null),p(null),d(!1);return}d(!0),o(null),p(null),_i({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(f=>{x()&&o(f||null)}).catch(f=>{x()&&(p(f?.message||String(f)),o(null))}).finally(()=>{x()&&d(!1)})},[t,a,r,s,n,g,m]),{data:i,loading:c,error:h}}function Sn(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 Cn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function Tn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function An(t,a){return a&&Tn(Cn(t))==="github"?a:""}function Dn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=u.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const Cs="#10b981",nr=[{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"}],or=60;function Vc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(m=>[m.day,m]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const c=t[t.length-1].day;o<c&&(o=c);const d=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(d.getTime())||!Number.isFinite(h.getTime()))return t;const p=Math.round((h.getTime()-d.getTime())/864e5)+1;p>or&&d.setUTCDate(d.getUTCDate()+(p-or));const g=[];for(;d.getTime()<=h.getTime()&&g.length<or;){const m=d.toISOString().slice(0,10);g.push(n.get(m)||{day:m,total_tokens:0,billable_total_tokens:0}),d.setUTCDate(d.getUTCDate()+1)}return g}function ir(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function Nt({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=Tn(t);return r==="github"||r==="gitlab"?a=e.jsx(At,{provider:r,size:12,className:"fill-current"}):a=e.jsx($l,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function lr({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 Gc({entry:t,query:a={},onClose:r}){const[s,n]=St.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:c}=Sn(i),d=typeof t?.project_ref=="string"?t.project_ref:"",h=Cn(d),{data:p,loading:g,error:m}=qc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:x,formatTokensTooltip:f}=Ne(),b=St.useCallback(()=>n(!0),[]),k=E=>{E.target===E.currentTarget&&s&&r()};St.useEffect(()=>{const E=O=>{O.key==="Escape"&&b()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[b]);const j=p?.totals||null,v=H(j?.billable_total_tokens)??0,C=Number(p?.days_active||0),D=H(j?.input_tokens)??0,M=H(j?.cached_input_tokens)??0,A=D+M>0?M/(D+M):null,I=H(p?.range_total_tokens)??0,N=H(j?.total_tokens)??0,w=I>0?N/I:null,T=St.useMemo(()=>Vc(p?.daily,p?.from,p?.to,Cr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[p,a.timeZone,a.tzOffsetMinutes]),P=nr.reduce((E,O)=>E+(H(j?.[O.key])??0),0),z=Array.isArray(p?.sources)?p.sources:[],K=!g&&!m&&j&&N>0;return e.jsx("div",{onAnimationEnd:k,onClick:E=>{E.target===E.currentTarget&&b()},className:Ct("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i,className:Ct("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:b,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(Tr,{size:16})}),e.jsxs("div",{className:"w-full md:w-[300px] shrink-0 border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-5 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:Cs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:Cs}})]}),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(Dn,{githubOwner:An(d,o),letter:(c?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:c||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(Wc,{host:h}),h&&p?.from&&p?.to?e.jsx("span",{children:"·"}):null,p?.from&&p?.to?e.jsxs("span",{className:"tabular-nums",children:[p.from," – ",p.to]}):null]})]}),K?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(Nt,{label:l("dashboard.projects.detail.stat_total"),value:x(v),title:f(v)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_share"),value:w==null?"—":ir(w)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":ir(A)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_conversations"),value:Aa(j.conversation_count)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_active_days"),value:Aa(C)}),e.jsx(Nt,{label:l("dashboard.projects.detail.stat_avg_day"),value:C>0?x(Math.round(v/C)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[g&&e.jsxs("div",{className:"space-y-4 p-5 md:p-6",children:[e.jsx("div",{className:"h-32 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-24 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"})]}),!g&&m&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!g&&!m&&!K&&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")}),K&&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(lr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(nn,{embedded:!0,rows:T,from:T[0]?.day,to:T[T.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),P>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(lr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:nr.map(E=>{const O=H(j[E.key])??0;return O<=0?null:e.jsx("div",{style:{width:`${O/P*100}%`,backgroundColor:E.color,minWidth:"2px"}},E.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:nr.map(E=>{const O=H(j[E.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:E.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(E.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:x(O)})]},E.key)})})]}),z.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(lr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:z.map(E=>{const O=Number(E.total_tokens||0),U=N>0?O/N:0,W=U*100,F=Number(E.conversation_count||0),S=Ji(E.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(At,{provider:E.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:ut(E.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(E.days_active||0)}),F>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:F})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:f(O),children:x(O)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:ir(U)})]}),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(W,O>0?1:0))}%`,minWidth:O>0?"3px":0,backgroundColor:S}})})]},E.source)})})]})]})]})]})})}function Yc(t){return e.jsx(wi,{mode:Yt.COMPACT,children:e.jsx(Gc,{...t})})}const Jc=5;function Zc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",c=typeof t?.project_ref=="string"?t.project_ref:"",{owner:d,repo:h}=Sn(o),p=An(c,d),g=H(t?.billable_total_tokens??t?.total_tokens)??0,m=a>0?Math.min(100,Math.max(2,g/a*100)):0,x=Array.isArray(t?.sources)?t.sources:[],f=x.slice(0,Jc),b=x.length-f.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(Dn,{githubOwner:p,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[d?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[d,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:h||o||"—"})]}),f.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[f.map(k=>e.jsx(At,{provider:k.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},k.source)),b>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:b})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(g),children:s(g)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${m}%`,minWidth:g>0?"3px":0}})})]})]})}function Qc({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:c,dailyEmptySuffix:d,detailsColumns:h,ariaSortFor:p,toggleSort:g,sortIconFor:m,pagedDetails:x,dailyBreakdownRows:f=[],dailyBreakdownColumns:b=[],dailyBreakdownAriaSortFor:k,dailyBreakdownSortIconFor:j,dailyBreakdownDateKey:v="day",detailsDateKey:C,renderDetailDate:D,renderDailyBreakdownDate:M,renderDetailCell:A,DETAILS_PAGED_PERIODS:I,period:N,detailsPageCount:w,detailsPage:T,setDetailsPage:P}){const[z,K]=u.useState("daily"),[E,O]=u.useState(null),{formatTokens:U,formatTokensTooltip:W}=Ne();return e.jsxs(De,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${z==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":z==="daily",type:"button",onClick:()=>K("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":z==="projects",type:"button",onClick:()=>K("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${z==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),z==="projects"&&e.jsx(ln,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:F=>r?.(Number(F)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),z==="projects"&&(()=>{const F=t.slice(0,a);if(F.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const S=F.reduce(($,de)=>{const ie=H(de?.billable_total_tokens??de?.total_tokens)??0;return ie>$?ie:$},0);return e.jsx("div",{className:"space-y-1",children:F.map(($,de)=>e.jsx(Zc,{entry:$,maxTokens:S,copy:n,formatTokens:U,formatTokensTooltip:W,onSelect:O},$?.project_key||$?.project_ref||`entry-${de}`))})})(),E&&e.jsx(Yc,{entry:E,query:s,onClose:()=>O(null)}),z==="daily"&&e.jsxs("div",{children:[f?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:c}),d]}):e.jsx("div",{className:"overflow-auto max-h-[384px] -mx-4 oai-scrollbar",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsx("tr",{className:"border-b border-oai-gray-200 dark:border-oai-gray-700",children:b.map(F=>e.jsx("th",{"aria-sort":k?.(F.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>g(F.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:F.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:j?.(F.key)||""})]})})},F.key))})}),e.jsx("tbody",{children:f.map(F=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${F.missing?"text-oai-gray-400 dark:text-oai-gray-400":F.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:M?M(F):D(F)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(F,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(F,"conversation_count")})]},String(F?.[v]||F?.day||F?.hour||F?.month||"")))})]})}),z!=="daily"&&I.has(N)&&w>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>P(F=>Math.max(0,F-1)),disabled:T===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[T+1," / ",w]}),e.jsx("button",{type:"button",onClick:()=>P(F=>Math.min(w-1,F+1)),disabled:T+1>=w,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 Ta(t){return typeof t!="string"?"":t.trim()}function Ts(t){const a=Ta(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Xc(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=Ta(r.tool),n=Ta(r.planType)||Ta(r.plan_type);if(!s||!n)continue;const i=Ts(s)||s,o=Ts(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function ed({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:c}=Ne(),d=l("shared.placeholder.short"),h=l("shared.unit.percent"),p=t??l("identity_card.rank_placeholder"),g=Number.isFinite(Number(a))?Number(a):0,m=g?l("identity_card.streak_value",{days:g}):l("identity_card.rank_placeholder"),x=Xc(r),f={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev"),trillionSuffix:l("shared.unit.trillion_abbrev")},b=v=>{if(v==null)return d;const C=Ie(v,f);return C==="-"?d:C},k={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},j=i.slice(0,3);return e.jsxs(De,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:c(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:b(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:k.convs})]})]}),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((v,C)=>{const D=v?.name?String(v.name):d,M=v?.percent?String(v.percent):"",A=C===j.length-1,I=C+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:I}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:D,children:D}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[M,h]})]},v.id||D)})}),x.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:x.map((v,C)=>e.jsxs(ql,{variant:"secondary",size:"sm",children:[v.tool," ",v.plan]},`${v.tool}:${v.plan}:${C}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:p})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]})]})]})}let ja=null;function td(){if(ja===null)try{ja=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{ja=!1}return ja}function ad(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,c=t-.1055613458*n-.0638541728*i,d=t-.0894841775*n-1.291485548*i,h=o*o*o,p=c*c*c,g=d*d*d;return[4.0767416621*h-3.3077115913*p+.2309699292*g,-1.2684380046*h+2.6097574011*p-.3413193965*g,-.0041960863*h-.7034186147*p+1.707614701*g].map(x=>{const f=Math.min(1,Math.max(0,x)),b=f<=.0031308?12.92*f:1.055*Math.pow(f,1/2.4)-.055;return Math.round(b*255)})}function Mn(t,a,r,s){if(td())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=ad(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function Dt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?Mn(Number(a[1]),Number(a[2]),Number(a[3])):t}const As={claude:35,codex:250,grok:200},Ds={system_prompt:{l:.55,c:.05},messages:{l:.65,c:.18},tool_calls:{l:.6,c:.14},custom_agents:{l:.55,c:.1},reasoning:{l:.7,c:.08}};function rd(t,a){const r=As[a]??As.claude,s=Ds[t]||Ds.system_prompt;return Mn(s.l,s.c,r)}const sd=[{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"]}],nd=[["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"]],od={duration:.18,ease:[.4,0,.2,1]},id={height:0,opacity:0},ld={height:"auto",opacity:1},cd={height:0,opacity:0};function dd(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function ud(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 Ln(t,a=null){const r=t.reduce((o,c)=>o+Number(c.totals.total_tokens||0),0),s=dd(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const c=i===1?o.totals:ud(o.totals,i);return{...o,totals:c,percent:n>0?Number((c.total_tokens/n*100).toFixed(2)):0}}).sort((o,c)=>c.totals.total_tokens-o.totals.total_tokens)}function md(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=sd.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const c=r.get(o);if(!c)continue;const d=c.totals||{};i.input_tokens+=d.input_tokens||0,i.cached_input_tokens+=d.cached_input_tokens||0,i.cache_creation_input_tokens+=d.cache_creation_input_tokens||0,i.output_tokens+=d.output_tokens||0,i.reasoning_output_tokens+=d.reasoning_output_tokens||0,i.total_tokens+=d.total_tokens||0}return{key:n.key,totals:i}});return Ln(s,a)}function hd(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,p)=>p?.name==="Text Response"?h:h+Number(p?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),d=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return Ln(d,a)}const Ms="MCP: ";function pd(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(Ms)?(a.push({...n,name:i.slice(Ms.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function Ls(t){return l(`dashboard.context_breakdown.category.${t}`)}function xd(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function gd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),c=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:xd(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(c||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function fd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),c=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:c,total_tokens:Number(r.total_tokens||n+i)},tools:gd(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function yd(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function bd(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 kd(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 _d(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function Es(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 wd(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 Rs(t){return t==="exec_command"||t==="Bash"}function En(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function vd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function jd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const Nd=10;function Qe({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:c,tokens:d,percent:h=null,children:p,share:g=null,fillColor:m=null}){const x=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",f=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:Nd},"aria-hidden":!a,children:a}),b=e.jsxs(e.Fragment,{children:[f,e.jsx("span",{className:x,children:r}),s,i&&e.jsx(Ve.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(ji,{size:11})})]}),k=m&&g!=null&&g>0,j=k?Math.max(0,Math.min(100,g)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:k?{backgroundImage:`linear-gradient(to right, ${m.replace(/\)\s*$/," / 0.10)")} 0%, ${m.replace(/\)\s*$/," / 0.10)")} ${j}%, transparent ${j}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:c,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:b}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:b}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:d||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:h||""})]}),i&&p?e.jsx(hn,{initial:!1,children:o&&e.jsx(Ve.div,{initial:id,animate:ld,exit:cd,transition:od,style:{overflow:"hidden"},children:p},"content")}):null]})}function Is({execDetails:t,source:a="claude"}){const{formatTokens:r}=Ne(),[s,n]=u.useState("by_type"),i=_d(wd(t,s)),o=a==="codex"||a==="grok",c=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:nd.map(([d,h])=>e.jsx("button",{type:"button",onClick:()=>n(d),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===d?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(h)},d))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${c} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((d,h)=>e.jsxs(Ve.div,{role:"row",className:`grid ${c} gap-2 py-1.5`,title:d.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:d.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.failures||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Es(d.duration_ms||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Es(d.max_duration_ms||0)})]}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:r(d.totals.total_tokens||0)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Ie(d.output_lines||0)})]},d.name))]})})]})}function Wt({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Ne(),[i,o]=u.useState({}),[c,d]=u.useState(!1),h=fd(t?.categories||[]);function p(g){o(m=>({...m,[g]:!m[g]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(En(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(g=>{const m=g.toolCount>0,x=g.name==="Execution"&&a,f=x&&g.tools.some(k=>Rs(k.name)),b=!!i[g.name];return e.jsxs(Qe,{level:1,label:g.name,labelTone:"strong",hasChevron:m||x&&!f,open:b||x&&!f&&c,onToggle:()=>{m?p(g.name):x&&!f&&d(k=>!k)},tokens:n(g.totals.total_tokens||0),percent:null,children:[m&&e.jsx("ul",{className:"space-y-0.5",children:g.tools.map(k=>{const j=x&&Rs(k.name);return e.jsx(Qe,{level:2,label:k.name,labelTone:j?"accent":"default",hasChevron:j,open:c,onToggle:()=>d(v=>!v),tokens:n(k.total_tokens||0),percent:null,children:j&&e.jsx(Is,{execDetails:a,source:r})},k.name)})}),x&&!f&&e.jsx(Is,{execDetails:a,source:r})]},g.name)})})}function Sd({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null,deviceId:i=null}){const{formatTokens:o}=Ne(),[c,d]=u.useState(null),[h,p]=u.useState(!1),[g,m]=u.useState(null),[x,f]=u.useState({}),b=u.useRef({});function k(S){f($=>({...$,[S]:!$[S]}))}if(u.useEffect(()=>{let S=!1;const $=`${t||""}|${a||""}|${r||"claude"}|${i||""}`,de=b.current[$];return d(de||null),p(!0),n?.(!0),m(null),vi({from:t,to:a,source:r,device:i,timeZone:sn(),tzOffsetMinutes:rn()}).then(ie=>{S||(b.current[$]=ie,d(ie))}).catch(ie=>{S||m(ie?.message||String(ie))}).finally(()=>{S||(p(!1),n?.(!1))}),()=>{S=!0}},[t,a,r,i]),h&&!c)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(S=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${S*80}ms`}},S))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(g)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(vd(r))});if(!c||c.scope!=="supported"||!c.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(c?.reason==="local_history_only"?"settings.local_data.local_history_only":En(r))});const j=r==="claude"?md(c.categories||[],s):hd(c,s),v=c.tool_calls_breakdown||null,C=c.skills_breakdown||null,D=c.message_breakdown||null,M=c.configured_resources||null,A=c.exec_command_breakdown||null,I=bd(C?.skills||[]),N=yd(D?.categories||[]),w=r==="codex"&&(c?.breakdown_status==="queue_fallback"||c?.fallback==="queue_totals"),T=r==="claude"?v?.tool_calls||null:v||null,{mcpSet:P,residualSet:z,mcpTotalTokens:K}=pd(T),E=r==="claude"&&v?.subagents||null,O=E?.categories?.length>0||(M?.custom_agents_count||0)>0,U=r==="claude"?(z?.categories||[]).reduce((S,$)=>S+Number($?.totals?.total_tokens||0),0):0,W=r==="claude"?(E?.categories||[]).reduce((S,$)=>S+Number($?.totals?.total_tokens||0),0):0,F=[...j].sort((S,$)=>($.totals?.total_tokens||0)-(S.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:j.filter(S=>S.percent>0).filter(S=>!(r==="claude"&&(S.key==="tool_calls"||S.key==="custom_agents"))).map(S=>`${Ls(S.key)} ${S.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[F.map(S=>{const $=S.key==="system_prompt",de=S.key==="messages",ie=S.key==="tool_calls",G=S.key==="custom_agents";if(S.key,r==="claude"&&(ie||G))return null;const se=de&&N.length>0||ie&&(z?.categories?.length>0||w)||G&&O&&E,ue=!!x[S.key],ke=rd(S.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:ke},"aria-hidden":"true"}),Te=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(mn,{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,Q=S.percent>0?`${S.percent.toFixed(S.percent<.1&&S.percent>0?2:1)}%`:"0.0%";return e.jsxs(Qe,{level:0,colorSquare:je,label:Ls(S.key),labelSuffix:Te,tokens:o(S.totals?.total_tokens||0),percent:Q,hasChevron:se,open:ue,onToggle:()=>k(S.key),share:S.percent,fillColor:ke,children:[de&&e.jsx("ul",{className:"space-y-0.5",children:N.map(B=>e.jsx(Qe,{level:1,label:kd(B),tokens:o(B.totals.total_tokens||0),percent:null},B.key||B.name))}),ie&&z&&e.jsx(Wt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:w}),ie&&w&&!z&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),G&&E&&e.jsx(Wt,{toolSet:E,execDetails:null,source:r,codexQueueFallback:!1})]},S.key)}),r==="claude"&&z?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:o(U),percent:null,hasChevron:!0,open:!!x.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Wt,{toolSet:z,execDetails:A,source:r,codexQueueFallback:!1})}),r==="claude"&&E?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:o(W),percent:null,hasChevron:!0,open:!!x.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Wt,{toolSet:E,execDetails:null,source:r,codexQueueFallback:!1})}),P?.categories?.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:o(K),percent:null,hasChevron:!0,open:!!x.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Wt,{toolSet:P,execDetails:null,source:r,codexQueueFallback:!1})}),I.length>0&&e.jsx(Qe,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:o(I.reduce((S,$)=>S+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!x.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:I.slice(0,12).map(S=>e.jsx(Qe,{level:1,label:S.name,tokens:o(S.total_tokens),percent:null},S.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(jd(r))}),w?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,M?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Ie(M.skills_count||0)," skills ·"," ",Ie(M.mcp_servers_count||0)," MCP servers ·"," ",Ie(M.custom_agents_count||0)," agents ·"," ",Ie(M.memory_files_count||0)," memory files"]}):null]})}function Rn({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__",Cd=`${100 .toFixed(2)}%`;function Xt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function La(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Zt(a);return(a===an?s:s*r)<.01?`<${n}0.01`:ta(s,{decimals:2,currency:a,rate:r})}function Td(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:$s(a)}:{key:a.key,label:a.label||$s(a.key)}):[]}function Ad(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 Dd={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 cr(t,a){const r=t?.toUpperCase?.()||"";return Dd[r]||`hsl(${150+a*40}, 60%, 45%)`}function Md(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 Ld(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 Ed(t){return!!t?.models?.length}function In(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function dr(t){const a=In(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}function Fs(t){return(Number(t?.requests)||0)>0&&!(Number(t?.usage)>0)}function Rd(t,a){const r=Xt(a,t?.usage),s=Math.max(0,Number(t?.requests)||0);return r&&s>0?`${r} · ${l("usage.overview.request_count",{count:s})}`:r||(s>0?l("usage.overview.request_count",{count:s}):null)}const Id={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function $s(t){const a=Id[t];return a?l(a):String(t).toUpperCase()}function Fd({loading:t,onClick:a}){const r=un();return e.jsx(Si,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(Ve.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 $d(){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 Pd(){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 Od({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:c,onCostInfo:d,fleetData:h=[],onRefresh:p,loading:g,announceLoading:m=!1,summaryLoading:x=!1,providersLoading:f=!1,hasSummary:b=!0,className:k="",customFrom:j,customTo:v,onCustomRangeApply:C,customRangeOpen:D,onCustomRangeOpenChange:M,onOpenShare:A,from:I,to:N,deviceOptions:w=[],selectedDevice:T="",dataRevision:P=0,onDeviceChange:z,accountView:K=!1,accountScopeSwitchable:E=!1}){const O=Td(a),U=kl(Ti()),W=Ad(String(s??"")),F=t==="week"&&typeof I=="string"&&typeof N=="string"&&I.slice(0,7)!==N.slice(0,7),S=t!=="day"&&I&&N?`${wa(I,U)} — ${wa(N,U)}`:null,$=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[de,ie]=u.useState($);u.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const _=window.matchMedia("(max-width: 639px)"),V=re=>ie(re.matches);return _.addEventListener("change",V),()=>_.removeEventListener("change",V)},[]);const G=W!=null&&!de,se=u.useRef(null);u.useEffect(()=>{const _=se.current?.querySelector('[aria-selected="true"]');_&&typeof _.scrollIntoView=="function"&&_.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,ke]=u.useState(null),{resolvedTheme:je}=Ni(),{currency:Te,rate:Q}=aa(),{formatTokens:B}=Ne(),ne=je==="dark",X=ne?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",te=ne?"rgba(10,10,10,0)":"rgba(255,255,255,0)",xe=x&&!b,ee=f&&!h.some(Ed);u.useEffect(()=>{ke(null)},[t,I,N,T,P]);const Y=_=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(_.key))return;const V=Array.from(_.currentTarget.querySelectorAll('[role="tab"]')).filter(le=>!le.disabled),re=V.indexOf(_.target.closest('[role="tab"]'));if(re===-1||V.length===0)return;_.preventDefault();let oe=re;_.key==="Home"?oe=0:_.key==="End"?oe=V.length-1:_.key==="ArrowRight"?oe=(re+1)%V.length:oe=(re-1+V.length)%V.length,V[oe].focus(),V[oe].click()},Z=G?e.jsx(Xl,{value:W,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:ne?0:8,gradientFrom:X,gradientTo:te,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,ae=h.filter(_=>_.models?.length>0&&!Fs(_)),Se=h.filter(_=>_.models?.length>0&&Fs(_)),Ae=ae.some(_=>String(_?.source||_?.label||"").trim().toLowerCase()==="devin"),Fe=ae.some(_=>String(_?.source||_?.label||"").trim().toLowerCase()==="kiro"),$e=u.useMemo(()=>Bc(h),[h]),Mt=$e.reduce((_,V)=>_+(Number(V.usage)||0),0),Lt=ae.reduce((_,V)=>_+(Number(V.usd)||0),0),Ce=ue==null?null:ue===it||ae.some(function(V){return V.label===ue})?ue:null;return e.jsx(De,{className:k,children:e.jsxs("div",{"aria-busy":g||xe||ee,children:[m?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:se,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:Y,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(_=>{const V=t===_.key,re=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${V?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(_.key==="custom"){const oe=V&&j&&v?`${wa(j,U)} — ${wa(v,U)}`:_.label;return e.jsxs(vl,{open:D,onOpenChange:le=>{le?r?.("custom"):M?.(le)},children:[e.jsx(jl,{render:e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:re}),children:oe}),e.jsx(Nl,{children:e.jsx(Sl,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(Cl,{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(bl,{from:j,to:v,onApply:C,onCancel:()=>M?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":V,tabIndex:V?0:-1,type:"button",className:re,onClick:()=>r?.(_.key),children:_.label},_.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[!E&&K?e.jsx("span",{title:l("usage.overview.scope_account_tip"),className:"inline-flex shrink-0 items-center h-8 px-2.5 text-xs font-medium rounded-md bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-700 dark:text-oai-gray-300",children:l("usage.overview.scope_account")}):null,w.length>1?e.jsx(ln,{value:T,onValueChange:z,options:w,ariaLabel:E?l("usage.overview.scope_switch_aria"):l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Ol,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,p&&e.jsx(Fd,{loading:g,onClick:p})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:xe?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:Z}):e.jsx("span",{title:n||void 0,children:Z})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${xe?"":"hidden"}`,children:e.jsx($d,{})})]}),c&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:d?e.jsxs("button",{type:"button",onClick:d,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[c,e.jsx(mn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:c})}),S?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:S}),F?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(Pd,{})}),(ae.length>0||Se.length>0)&&e.jsxs("div",{className:"space-y-6",children:[ae.length>0&&e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:ae.map(_=>l("usage.overview.distribution_item",{label:ut(_.label),percent:dr(_)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:ae.map((_,V)=>{const re=cr(_.label,V),oe=ut(_.label),le=dr(_);return e.jsx(Ve.div,{initial:{width:0},animate:{width:`${In(_)}%`},transition:{duration:.5,delay:.45+V*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:re},title:`${oe}: ${le}%`},_.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:Xt(B,Mt)||String(0),cost:La(Lt,Te,Q)||`${Zt(Te)}0`,count:$e.length}),onClick:()=>ke(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(Rn,{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:Cd}),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:$e.length})})]}),ae.map((_,V)=>{const re=cr(_.label,V),oe=Ce===_.label,le=ut(_.label),We=dr(_);return e.jsxs("button",{"aria-expanded":oe,"aria-controls":`provider-details-${_.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:le,percent:We,tokens:Xt(B,_.usage)||String(0),cost:La(_.usd,Te,Q)||`${Zt(Te)}0`,action:l(oe?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>ke(oe?null:_.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${oe?"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(At,{provider:_.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:le,children:le})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[We,"%"]}),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:_.models.length})})]},_.label)})]}),Ce===it&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[Ae&&e.jsx($n,{}),Fe&&e.jsx(Pn,{}),e.jsx(qd,{models:$e})]}),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:ae.filter(_=>_.label===Ce).map(_=>{const V=cr(_.label,0),re=Md(_),oe=[..._.models].sort((We,he)=>(he.share||0)-(We.share||0)),le=re?Ld(re):ut(_.label);return e.jsx(Wd,{provider:_,color:V,providerHeading:le,contextSource:re,deviceId:T,from:I,to:N,sortedModels:oe},_.label)})})]}),Se.length>0&&e.jsx(Vd,{providers:Se})]})})}const zd=[{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"}],Bd="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 Ud({tokens:t}){const{formatTokens:a,formatTokensTooltip:r}=Ne();return e.jsx("div",{className:"mb-1.5 flex flex-wrap gap-x-4 gap-y-1",children:zd.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 Hd(t,a){const r=l(t==="priority"?"usage.overview.tier_fast":t==="ultrafast"?"usage.overview.tier_ultrafast":"usage.overview.tier_standard"),s=t==="standard"?0:$c(a,t);if(!(s>1))return r;const n=Number.isInteger(s)?String(s):String(Math.round(s*100)/100);return l("usage.overview.tier_rate_label",{label:r,rate:n})}function Kd({model:t}){const{currency:a,rate:r}=aa(),{formatTokens:s,formatTokensTooltip:n}=Ne();if(!Nn(t))return null;const i=[{key:"standard",split:Pc(t)},...Qt.map(o=>({key:o,split:t?.tiers?.[o]||null}))].filter(o=>o.split&&(Ma(o.split.tokens)>0||o.split.cost>0));return i.length?e.jsx("div",{className:"mb-1.5 flex flex-col gap-y-1","data-model-speed-tiers":!0,children:i.map(o=>{const c=Ma(o.split.tokens);return e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 text-[11px] tabular-nums",children:[e.jsx("span",{className:"min-w-[8rem] text-oai-gray-500 dark:text-oai-gray-400",children:Hd(o.key,t)}),e.jsx("span",{title:n(c),className:"text-oai-gray-600 dark:text-oai-gray-300",children:s(c)}),e.jsx("span",{className:"text-oai-gray-600 dark:text-oai-gray-300",children:La(o.split.cost,a,r)})]},o.key)})}):null}function Ps({model:t,tokensLabel:a,costLabel:r,unpricedLabel:s,expandable:n,isExpanded:i}){const{formatTokensTooltip:o}=Ne();return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:t.name,children:t.name}),e.jsx("span",{title:o(t.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:a}),e.jsx("span",{title:s?l("dashboard.cost_breakdown.unpriced"):void 0,className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:r??s}),e.jsxs("span",{className:"col-start-4 row-start-1 flex w-full items-center justify-end gap-1 whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[t.share,"%",n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:l(i?"usage.overview.collapse":"usage.overview.expand")}),e.jsx(wl,{size:14,"aria-hidden":!0,className:`shrink-0 text-oai-gray-400 transition-transform duration-200 ease-out motion-reduce:transition-none dark:text-oai-gray-500 ${i?"rotate-180":""}`})]})]})]})}function Fn({models:t,color:a}){const{currency:r,rate:s}=aa(),{formatTokens:n}=Ne(),[i,o]=u.useState(null);return e.jsx("div",{className:"space-y-3",children:t.map(c=>{const d=Rd(c,n),h=La(c.cost,r,s),p=!h&&Number(c.usage)>0&&Mr(c)?l("dashboard.cost_breakdown.unpriced_label"):null,g=Math.max(0,Math.min(100,Number(c.share)||0)),m=c.id||c.name,x=Rc(c),f=x&&i===m,b=Bd,k={model:c,tokensLabel:d,costLabel:h,unpricedLabel:p,expandable:x,isExpanded:f};return e.jsxs("div",{"data-model-rank-row":!0,children:[x?e.jsx("button",{type:"button",onClick:()=>o(f?null:m),"aria-expanded":f,className:`${b} w-full cursor-pointer text-left`,children:e.jsx(Ps,{...k})}):e.jsx("div",{className:b,children:e.jsx(Ps,{...k})}),f&&e.jsxs(e.Fragment,{children:[e.jsx(Ud,{tokens:c.tokens}),e.jsx(Kd,{model:c})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":g,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${g}%`,backgroundColor:a,opacity:.45}})})]},m)})})}function qd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(Rn,{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(Fn,{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 Pn(){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 Vd({providers:t}){const a=t.map(r=>l("usage.overview.request_only_item",{label:ut(r.label),count:Math.max(0,Number(r.requests)||0)})).join(l("usage.overview.request_only_separator"));return e.jsx("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:l("usage.overview.request_only_note",{items:a})})}function Wd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o,deviceId:c}){const{formatTokens:d}=Ne(),[h,p]=u.useState(!1),g=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",m=String(t?.source||t?.label||"").trim().toLowerCase()==="devin",x=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(At,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&h&&e.jsx(_l,{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:Xt(d,t.cacheReusedTokens)||String(0),input:Xt(d,t.cacheInputTokens)||String(0)})]}),g&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),m&&e.jsx($n,{}),x&&e.jsx(Pn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(Sd,{from:n,to:i,source:s,deviceId:c,referenceTotalTokens:t.usage,onLoadingChange:p})}):null,e.jsx(Fn,{models:o,color:a})]})}function Gd({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:c,isDragging:d}=rl({id:t}),h=u.useRef(null),p=u.useRef(null);u.useLayoutEffect(()=>{if(!r)return;const m=h.current?h.current.childNodes.length===0:!0;p.current!==m&&(p.current=m,r(t,m))});const g={transform:sl.Transform.toString(o)||void 0,transition:c,zIndex:d?20:void 0};return e.jsxs("div",{ref:i,style:g,className:Ct("group/sortable relative has-[[data-sortable-body]:empty]:hidden",d&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:Ct("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",d&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:h,"data-sortable-body":!0,className:Ct("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",d&&"shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]"),children:a})]})}function Yd({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=u.useState(null),[c,d]=u.useState(!1),[h,p]=u.useState(null),g=st([t,a,r,s,n]),m=u.useCallback(async()=>{if(!t)return;const x=g();d(!0),p(null);try{const f=await He(s);if(!x())return;const b=await Ai({from:a,to:r,device:n,accessToken:f});if(!x())return;o(b||null)}catch(f){if(!x())return;p(f?.message||String(f)),o(null)}finally{x()&&d(!1)}},[t,a,r,s,n,g]);return u.useEffect(()=>{if(!t){o(null),p(null),d(!1);return}o(null),p(null),d(!0),m()},[t,m]),{data:i,loading:c,error:h,refresh:m}}function On(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function zn(t){return t==null?"—":`${Math.round(t*100)}%`}function Jd(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 Zd({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:On(t.cost_usd)}),e.jsxs("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:[t.accepted,"/",t.outcomes]}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:zn(t.acceptance_rate)}),e.jsx("td",{className:"py-2.5 pl-2 pr-2 text-right tabular-nums font-semibold text-oai-black dark:text-oai-white",children:Jd(t.cost_usd,t.accepted)})]})}function Qd({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Ne(),{enabled:i}=Tl(),{data:o,loading:c}=Yd({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const d=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(m=>m.outcomes>0&&m.key!=="unknown");if(!d.length)return null;const h=d.slice(0,6),p=o.totals||{},g=`${l("qpd.card.subtitle")}${c?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(De,{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("qpd.card.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:g}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(m=>e.jsx(Zd,{row:m},m.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:p.accepted??0,outcomes:p.outcomes??0,cost:On(p.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(p.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(p.effective_tokens),rate:zn(p.acceptance_rate)})})]}),p.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 Xd=new Set(["unknown","synthetic","openai"]);function ur(t){return t==null?"—":`${Math.round(t*100)}%`}function eu(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function tu(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Xd.has(r)&&Number(t?.edit_turns||0)>0}function Os(){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 au({from:t,to:a}){const r=JSON.stringify([t,a]),[s,n]=u.useState({requestKey:null,loading:!0,sessions:null,context:null}),i=s.requestKey===r?s:{loading:!0,sessions:null,context:null},o=u.useId(),{enabled:c}=Al(),d=st([c,t,a]),{formatTokens:h}=Ne(),p=C=>h(C,{mode:Yt.COMPACT});u.useEffect(()=>{const C=d();if(!c){n({requestKey:r,loading:!1,sessions:null,context:null});return}n({requestKey:r,loading:!0,sessions:null,context:null}),Promise.all([Di({from:t,to:a}),Mi()]).then(([D,M])=>{C()&&n({requestKey:r,loading:!1,sessions:D,context:M})}).catch(()=>{C()&&n({requestKey:r,loading:!1,sessions:null,context:null})})},[c,t,a,r,d]);const g=u.useMemo(()=>(i.sessions?.by_model||[]).filter(tu).slice(0,5),[i.sessions]),m=u.useMemo(()=>(i.sessions?.subagents||[]).slice(0,3),[i.sessions]);if(!c||!i.loading&&!i.sessions?.available&&!i.context?.estimated_fixed_tokens)return null;const x=i.sessions?.summary||{},f=x.edit_session_rate??x.productive_rate,b=x.first_pass_rate??x.one_shot_rate,k=x.edit_sessions??x.productive_sessions??0,j=x.sessions??i.sessions?.session_count??0,v=x.edit_turns??0;return i.loading&&!i.sessions&&!i.context?e.jsxs(De,{children:[e.jsx(Os,{}),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(De,{children:[e.jsx(Os,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(mr,{label:l("sessions.card.edit_sessions"),value:ur(f),detail:l("sessions.card.edit_session_value",{edits:Ze(k),sessions:Ze(j)})}),e.jsx(mr,{label:l("sessions.card.first_pass"),value:ur(b),detail:l("sessions.card.edit_session_value",{edits:Ze(x.first_pass_sessions??x.one_shot_sessions??0),sessions:Ze(k)})}),e.jsx(mr,{label:l("sessions.card.cost_edit"),value:eu(x.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(v)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Ze(j),edits:Ze(v)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":o,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:o,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!g.length&&e.jsx(Yi,{wrapperClassName:"w-full",label:l("sessions.card.scroll"),children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium whitespace-nowrap",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium whitespace-nowrap",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:g.map(C=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:C.model,children:C.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:l("sessions.card.edit_session_value",{edits:Ze(C.edit_sessions??C.productive_sessions??0),sessions:Ze(C.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums whitespace-nowrap",children:ur(C.first_pass_rate??C.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums whitespace-nowrap",children:p(C.tokens_per_edit)})]},C.model))})]})}),i.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:p(i.context.estimated_fixed_tokens)})]}):null,!!m.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),m.map(C=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:C.name,calls:Math.round(C.calls)})},C.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function mr({label:t,value:a,detail:r}){return e.jsxs("div",{className:"rounded-lg bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 truncate",children:t}),e.jsx("div",{className:"mt-0.5 text-sm font-semibold tabular-nums text-oai-black dark:text-white",children:a}),e.jsx("div",{className:"mt-0.5 text-[9px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 truncate",children:r})]})}function ce({className:t}){return e.jsx("div",{className:Ct("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function ru(){return e.jsx("div",{className:"flex gap-1 overflow-hidden",children:Array.from({length:20},(t,a)=>e.jsx("div",{className:"flex flex-col gap-1",children:Array.from({length:7},(r,s)=>e.jsx(ce,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function su(){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(De,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(ce,{className:"h-4 w-32"}),e.jsx(ce,{className:"h-6 w-24"})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-24"}),Array.from({length:4},(t,a)=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(ce,{className:"h-3 w-20"}),e.jsx(ce,{className:"h-3 w-12"})]},a))]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-20"}),e.jsx(ru,{})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ce,{className:"h-3.5 w-28"}),e.jsx(ce,{className:"h-32 w-full"})]})})]}),e.jsxs("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex flex-1 min-w-0 gap-1",children:Array.from({length:5},(t,a)=>e.jsx(ce,{className:"h-7 w-14 rounded-md shrink-0"},a))}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(ce,{className:"h-8 w-20 rounded-md"}),e.jsx(ce,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(ce,{className:"h-3 w-28"}),e.jsx(ce,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(ce,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ce,{className:"h-1.5 w-full rounded-full"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-3",children:Array.from({length:5},(t,a)=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ce,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(ce,{className:"h-3 w-12"})]}),e.jsx(ce,{className:"h-5 w-10"}),e.jsx(ce,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(ce,{className:"h-7 w-16 rounded"}),e.jsx(ce,{className:"h-7 w-20 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-200 dark:border-oai-gray-700 pb-2",children:[e.jsx(ce,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(ce,{className:"h-3 flex-1"},a))]}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:8},(t,a)=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-100 dark:border-oai-gray-800 py-2.5 last:border-b-0",children:[e.jsx(ce,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(ce,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const nu=Rl.slice(0,10),zs=.06,ou=.11,iu=.05;function Bs({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(El,{logos:nu,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(Ve.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 lu(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:c,activeDays:d,identitySubscriptions:h,identityScrambleDurationMs:p,projectUsageEntries:g,projectUsageLimit:m,setProjectUsageLimit:x,projectDetailQuery:f,topModels:b,signedIn:k,publicMode:j,isLocalMode:v,accountView:C,accountScopeSwitchable:D,shouldShowInstall:M,installPrompt:A,handleCopyInstall:I,installCopied:N,installInitCmdDisplay:w,trendRowsForDisplay:T,trendFromForDisplay:P,trendToForDisplay:z,trendZoomConfig:K,usageFrom:E,usageTo:O,period:U,trendTimeZoneLabel:W,activityHeatmapBlock:F,periodsForDisplay:S,setSelectedPeriod:$,customFrom:de,customTo:ie,onCustomRangeApply:G,customRangeOpen:se,onCustomRangeOpenChange:ue,summaryLabel:ke,summaryValue:je,summaryFullValue:Te,hasSummary:Q,summaryLoading:B,providersLoading:ne,onToggleSummaryFormat:X,summaryTotalTokensRaw:te,summaryCostValue:xe,summaryConversationsValue:ee,rollingUsage:Y,costInfoEnabled:Z,openCostModal:ae,costModalOpen:Se,closeCostModal:Ae,allowBreakdownToggle:Fe,refreshAll:$e,usageLoadingState:Mt,announceUsageLoading:Lt,initialDashboardLoading:Ce,fleetData:_,hasDetailsActual:V,dailyEmptyPrefix:re,installSyncCmd:oe,dailyEmptySuffix:le,detailsColumns:We,ariaSortFor:he,toggleSort:ge,sortIconFor:Pe,pagedDetails:Oe,dailyBreakdownRows:Et,dailyBreakdownColumns:xt,dailyBreakdownAriaSortFor:Ge,dailyBreakdownSortIconFor:Ra,dailyBreakdownDateKey:Xe,detailsDateKey:Ia,renderDetailDate:Fa,renderDailyBreakdownDate:gt,renderDetailCell:J,DETAILS_PAGED_PERIODS:ra,detailsPageCount:_e,detailsPage:we,setDetailsPage:Rt,deviceOptions:nt,selectedDevice:ye,onDeviceChange:It,deviceUsageBlock:sa,localHistoryOnly:na,localHistoryRevision:oa,leftCardOrder:Ft,onLeftReorder:$t,rightCardOrder:ia,onRightReorder:ze}=t,Be=null,Pt=null,ft={statsPanel:!0,installCopy:M,activityHeatmap:!!F,deviceUsage:!!sa,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:v&&!s},Ot=(Ft||[]).filter(me=>ft[me]),$a={usageOverview:!0,dataDetails:!s},Pa=(ia||[]).filter(me=>$a[me]);function la(me,fe){switch(me){case"statsPanel":return e.jsx(ot,{delay:fe,children:e.jsx(ed,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:U,startDate:c??a("identity_card.rank_placeholder"),streakDays:d,subscriptions:h,periodConversations:ee,rolling:Y,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:A}),e.jsxs(Ve.button,{onClick:I,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:w}),e.jsx(Ve.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:N?"Copied ✓":"Copy"},N?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(ot,{delay:fe,children:F});case"deviceUsage":return e.jsx(ot,{delay:fe,children:sa});case"trendMonitor":return e.jsx(ot,{delay:fe,children:e.jsx(nn,{rows:T,from:P,to:z,period:U,timeZoneLabel:W,showTimeZoneLabel:!1,zoomConfig:K})});case"qualityPerDollar":return e.jsx(Qd,{from:E,to:O,deviceId:ye});case"sessionInsights":return e.jsx(au,{from:E,to:O});default:return null}}function Oa(me,fe){switch(me){case"usageOverview":return e.jsx(ot,{delay:fe,children:e.jsx(Od,{accountView:C,accountScopeSwitchable:D,period:U,periods:S,onPeriodChange:$,summaryLabel:ke,summaryValue:je,summaryFullValue:Te,hasSummary:Q,summaryLoading:B,providersLoading:ne,onToggleSummaryFormat:Q?X:null,summaryCostValue:xe,onCostInfo:Z?ae:null,fleetData:_,onRefresh:s?null:$e,loading:Mt,announceLoading:Lt,onOpenShare:s?null:r,customFrom:de,customTo:ie,onCustomRangeApply:G,customRangeOpen:se,onCustomRangeOpenChange:ue,from:E,to:O,deviceOptions:nt,selectedDevice:ye,dataRevision:oa,onDeviceChange:It})});case"dataDetails":return e.jsx(ot,{delay:fe,children:e.jsx(Qc,{projectEntries:g,projectLimit:m,onProjectLimitChange:x,projectDetailQuery:f,copy:a,hasDetailsActual:V,dailyEmptyPrefix:re,installSyncCmd:oe,dailyEmptySuffix:le,detailsColumns:We,ariaSortFor:he,toggleSort:ge,sortIconFor:Pe,pagedDetails:Oe,dailyBreakdownRows:Et,dailyBreakdownColumns:xt,dailyBreakdownAriaSortFor:Ge,dailyBreakdownSortIconFor:Ra,dailyBreakdownDateKey:Xe,detailsDateKey:Ia,renderDetailDate:Fa,renderDailyBreakdownDate:gt,renderDetailCell:J,DETAILS_PAGED_PERIODS:ra,period:U,detailsPageCount:_e,detailsPage:we,setDetailsPage:Rt})});default:return null}}const ca=nl(hs(ul,{activationConstraint:{distance:6}}),hs(dl,{coordinateGetter:cl})),zt=u.useCallback(me=>{const{active:fe,over:be}=me;!be||fe.id===be.id||$t?.(String(fe.id),String(be.id))},[$t]),za=u.useCallback(me=>{const{active:fe,over:be}=me;!be||fe.id===be.id||ze?.(String(fe.id),String(be.id))},[ze]);function yt(me,fe,be,pe){return s?e.jsx(e.Fragment,{children:me.map((et,bt)=>e.jsx(St.Fragment,{children:fe(et,be+zs*bt)},et))}):e.jsx(ol,{sensors:ca,onDragEnd:pe,children:e.jsx(il,{items:me,strategy:ll,children:me.map((et,bt)=>e.jsx(Gd,{id:et,children:fe(et,be+zs*bt)},et))})})}const Bt=yt(Ot,la,ou,zt),Ba=yt(Pa,Oa,iu,za);return e.jsxs(e.Fragment,{children:[e.jsxs(Kl,{bare:!s,hideHeader:s,header:Be,footer:s?null:Pt,className:s?"screenshot-mode":"",children:[i&&e.jsx(Bs,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Bs,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(xs,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&Ce&&e.jsx(su,{}),!i&&!n&&!Ce&&e.jsxs(e.Fragment,{children:[na&&e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:a("settings.local_data.local_history_only")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:Bt}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:Ba})]})]})]}),e.jsx(Kc,{isOpen:Se,onClose:Ae,fleetData:_})]})}function cu({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0,localView:c=!1}={}){const d=c&&!n&&Il(),h=!!(d||n&&i),[p,g]=u.useState(0),[m,x]=u.useState([]),[f,b]=u.useState([]),[k,j]=u.useState(!1),[v,C]=u.useState(null),D=st([h,d,t,a,r,s,i,o]),M=u.useCallback(async()=>{const A=D();if(!h){x([]),b([]),j(!1),C(null);return}j(!0),C(null);try{const I=d?null:await He(i);if(!A())return;const N=d?await Dl({from:t,to:a,timeZone:r,tzOffsetMinutes:s}):await Li({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:I});if(!A())return;x(Array.isArray(N?.devices)?N.devices:[]),b(Array.isArray(N?.account_sources)?N.account_sources:[]),g(d&&Number(N?.revision)||0)}catch(I){if(!A())return;C(I?.message||String(I)),x([]),b([])}finally{A()&&j(!1)}},[h,d,i,t,a,r,s,o,D]);return u.useEffect(()=>{if(d)return window.addEventListener(ps,M),()=>window.removeEventListener(ps,M)},[d,M]),u.useEffect(()=>{x([]),b([]),C(null),h&&j(!0),M()},[h,M]),{devices:m,accountSources:f,loading:k,error:v,refresh:M,revision:p}}const du=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Us(t){const a=String(t||"").toLowerCase();return/iphone|ipad|ios/.test(a)?"iOS":/android/.test(a)?"Android":/mac|darwin/.test(a)?"Mac":/win/.test(a)?"Windows":/linux/.test(a)?"Linux":"Web"}function kr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(du);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Us(t.platform)} · ${s}`:Us(t.platform)}const Hs=" · ",Ks="%";function qs({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(Pl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(ns,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(ns,{className:a,"aria-hidden":!0}):e.jsx(pn,{className:a,"aria-hidden":!0})}function Vs(t,a){return a===t?.id||t?.isCurrent===!0}function uu({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:c}=Ne(),[d,h]=u.useState(""),[p,g]=u.useState(""),[m,x]=u.useState(!1),[f,b]=u.useState(""),k=typeof i=="function",j=typeof n=="function",v=!!s,C=t.reduce((w,T)=>w+(Number(T.total_tokens)||0),0)+a.reduce((w,T)=>w+(Number(T.total_tokens)||0),0),D=u.useMemo(()=>t.filter(w=>(Number(w.total_tokens)||0)>0||w.id===s).sort((w,T)=>(Number(T.total_tokens)||0)-(Number(w.total_tokens)||0)),[t,s]);function M(w){b(""),h(w.id);const T=typeof w.device_name=="string"?w.device_name:"";g(kr(w)===T?T:"")}function A(){h(""),g(""),b("")}async function I(w){const T=p.trim();if(!(!T||m)){x(!0),b("");try{await i(w.id,T),h(""),g("")}catch{b(w.id)}finally{x(!1)}}}const N=a.filter(w=>(Number(w.total_tokens)||0)>0);return D.length===0&&N.length===0?e.jsxs(De,{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(pn,{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(De,{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&&v&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[D.map(w=>{const T=Number(w.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=s===w.id,K=kr(w)||l("dashboard.device_card.unnamed"),E=d===w.id,O=z?"bg-oai-brand":v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",U=v&&!z?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[E?e.jsxs("div",{className:"w-full rounded-md px-2 py-1.5 bg-oai-gray-50/50 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(qs,{platform:w.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:p,disabled:m,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:W=>g(W.target.value),onKeyDown:W=>{W.key==="Enter"?I(w):W.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:m||!p.trim(),onClick:()=>I(w),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Fl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:m,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(Tr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${O}`,style:{width:`${P}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":z,"aria-label":`${l("dashboard.device_filter.aria")}: ${K}${Vs(w,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(z?"":w.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 ${U} ${z?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(qs,{platform:w.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:K,children:K}),Vs(w,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")}),w.imported_at&&e.jsx("span",{className:"shrink-0 whitespace-nowrap text-xs text-oai-gray-500",title:l("settings.local_data.snapshot_time",{time:new Date(w.exported_at).toLocaleString()}),children:l("settings.local_data.imported_label")})]}),e.jsxs("span",{title:c(T),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${k?"group-hover:opacity-0":""}`,children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Hs,P,Ks]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${O}`,style:{width:`${P}%`}})})]}),k&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>M(w),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(Ml,{className:"h-3 w-3"})})]}),f===w.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},w.id)}),N.map(w=>{const T=Number(w.total_tokens)||0,P=C>0?(T/C*100).toFixed(1):"0.0",z=v?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${z}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(At,{provider:w.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:ut(w.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:c(T),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(T),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Hs,P,Ks]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${v?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${P}%`}})})]},`account-${w.source}`)})]})]})}const Lr="__scope:local__";function mu(t){return t===Lr?{scopeOverride:"local",deviceId:null}:t?String(t).startsWith("local:")?{scopeOverride:"local",deviceId:t}:{scopeOverride:null,deviceId:t}:{scopeOverride:null,deviceId:null}}function hu({accountScopeSwitchable:t,accountView:a,selectedDevice:r}){return t?r||(a?"":Lr):r||""}function Bn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const mt=new Map,ht=new Map;function Un(){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||!mt.has(r))return;const s=mt.get(r);mt.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||!ht.has(r))return;const s=ht.get(r);ht.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function pu(t){if(!Bn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const a=window?.webkit?.messageHandlers?.nativeBridge;if(!a)return{ok:!1,error:"native bridge unavailable"};Un();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{ht.has(r)&&(ht.delete(r),s({ok:!1,error:"timeout"}))},8e3);ht.set(r,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){ht.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Ws(t,a){if(!Bn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const r=window?.webkit?.messageHandlers?.nativeBridge;if(!r)return{ok:!1,error:"native bridge unavailable"};Un();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{mt.has(s)&&(mt.delete(s),n({ok:!1,error:"timeout"}))},8e3);mt.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){mt.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Hn=1200,Kn=1630,qn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},xu="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 hr=!1;function gu(){if(typeof document>"u"||hr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){hr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=xu,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),hr=!0}async function fu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function yu(t,a={}){if(typeof window>"u"||!t)return null;gu(),await fu(),await new Promise(d=>requestAnimationFrame(()=>d(null)));const{toBlob:r,toPng:s}=await Ei(async()=>{const{toBlob:d,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:d,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Hn,o=t.offsetHeight||Kn,c={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:d=>!(d instanceof HTMLElement)||d.dataset?.screenshotExclude!=="true"};try{const d=await r(t,c);if(d)return d}catch{}try{const d=await s(t,c);return d?await(await fetch(d)).blob():null}catch{return null}}async function pr(t){return new Promise(a=>{const r=new FileReader;r.onload=()=>{const s=typeof r.result=="string"?r.result:null;a(s)},r.onerror=()=>a(null),r.readAsDataURL(t)})}function Gs(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 _r(t){const a=H(t);return Number.isFinite(a)?a:0}function bu(t){return t?_r(t.billable_total_tokens??t.total_tokens):0}function ku(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(c=>{const d=!!c?.future,h=Number.isFinite(c?.level)?Math.max(0,Math.min(4,Math.round(c.level))):0;c?.day&&!d&&(r+=1,h>0&&(s+=1));const p=c?.billable_total_tokens??c?.total_tokens??c?.value??0,g=Number.isFinite(p)?Math.max(0,p):0;return{day:typeof c?.day=="string"?c.day:"",level:h,value:g,future:d}})),totalDays:r,activeDays:s}}function _u(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:c,periodFrom:d,periodTo:h,heatmap:p,capturedAt:g,currency:m,exchangeRate:x}=t,f=bu(n),b=_r(n?.total_cost_usd),k=Array.isArray(i)?i.slice(0,3).map(v=>({id:v?.id??null,name:typeof v?.name=="string"&&v.name?v.name:"—",tokens:_r(v?.tokens),percent:typeof v?.percent=="string"&&v.percent?v.percent:"0.0"})):[],j=ku(p);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:f,totalCost:b,period:c,periodFrom:d,periodTo:h,topModels:k,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:j.weeks,heatmapTotalDays:j.totalDays,heatmapActiveDays:j.activeDays,capturedAt:g||new Date().toISOString(),currency:typeof m=="string"&&m.length>0?m.toUpperCase():"USD",exchangeRate:Number.isFinite(x)&&x>0?x:1}}const wu=["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 vu(t){const a=wu[t];return a?l(a):"—"}function Vn(t,a){return l("share.date.month_year",{month:vu(t),year:a})}function ju(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:Vn(n,r)}function Nu(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 Vn(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function wr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Wn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Zt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function Su(t){const a=t.topModels[0];if(a){const r=parseFloat(a.percent);return Number.isFinite(r)&&r>=60?l("share.hook.top_loyal",{percent:Math.round(r),name:a.name}):t.activeDays>=60?l("share.hook.days_record",{days:t.activeDays}):Number.isFinite(r)&&r>=30?l("share.hook.top_led",{name:a.name,percent:Math.round(r)}):t.topModels.length>1?l("share.hook.multi_models",{count:t.topModels.length,days:t.activeDays}):l("share.hook.days_with_model",{days:t.activeDays,name:a.name})}return t.activeDays>0?l("share.hook.days_record",{days:t.activeDays}):l("share.hook.new_chapter")}function Cu(t,a){const r=(t||"").length;if(r<=a.baseChars)return a.baseSize;const s=a.baseSize-(r-a.baseChars)*a.shrinkPerChar;return Math.max(a.minSize,s)}function Tu(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 Au({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],c=i||o[0],d=t.length,h=(d-1)*s,p=Math.max(4,(r-h)/d),g=7*p+6*s;return e.jsx("svg",{width:r,height:g,viewBox:`0 0 ${r} ${g}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((m,x)=>(Array.isArray(m)?m:[]).map((b,k)=>{if(k>=7)return null;const j=Tu(b),v=x*(p+s),C=k*(p+s),D=j===null?c:o[j];return e.jsx("rect",{x:v,y:C,width:p,height:p,rx:n,ry:n,fill:D},`${x}-${k}`)}))})}const Du=Dt("oklch(0.97 0.01 85)"),Re=Dt("oklch(0.18 0.02 85)"),at=Dt("oklch(0.38 0.015 85)"),Ys=Dt("oklch(0.55 0.012 85)"),lt=Dt("oklch(0.55 0.22 25)"),ct='"Instrument Serif", "Times New Roman", Georgia, serif',Mu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',Lu=["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(Dt);function Gn({data:t}){const a=Nu(t),r=wr(t.totalTokens),s=Wn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=ju(t.startDate),i=Cu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=Su(t),c=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Du,color:Re,fontFamily:Mu,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 ${Ys}`},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:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:ct,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background: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})})]})]}),c?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:at},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(Au,{weeks:t.heatmapWeeks,palette:Lu,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((d,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Ys}`},children:[e.jsx("div",{style:{fontFamily:ct,fontSize:34,fontStyle:"italic",color:lt,lineHeight:1},children:String(h+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:d.name}),e.jsx("div",{style:{fontFamily:ct,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:wr(d.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:at,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[d.percent,"%"]})]},d.id||d.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsxs("div",{style:{display:"flex",gap:28},children:[e.jsxs("span",{children:[l("share.card.broadsheet.global_rank")," ",e.jsxs("span",{style:{color: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 Eu=qn["annual-report"].width,Ru="#0a0820",rt="#ffffffee",dt="rgba(255,255,255,0.45)",xr="#a78bfa",Iu={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(", ")},Na={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},vr='"Space Grotesk", "Inter Tight", sans-serif',gr='"Inter Tight", sans-serif',Fu="rgba(255,255,255,0.06)",Yn=[Fu,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Jn=48,Zn=28,Ea=4,Qn=20,$u=Eu-Jn*2-Zn*2,Pu=($u-Qn*2)/3,jr=Math.min(Math.floor((Pu-Ea*6)/7),40),Ou=jr*7+Ea*6;function zu(t){if(!Array.isArray(t))return t;const a=[];for(const c of t)if(Array.isArray(c))for(const d of c)d?.day&&!d.future&&d.value>0&&a.push(d.value);if(!a.length)return t;a.sort((c,d)=>c-d);const r=c=>{const d=a.length,h=(d-1)*c,p=Math.floor(h);return Math.round((a[p]??0)+((a[Math.min(d-1,p+1)]??0)-(a[p]??0))*(h-p))},s=r(.5),n=r(.75),i=r(.9),o=c=>!c||c<=0?0:c<=s?1:c<=n?2:c<=i?3:4;return t.map(c=>Array.isArray(c)?c.map(d=>d?.day&&!d.future&&typeof d.value=="number"?{...d,level:o(d.value)}:d):c)}function Bu(t){if(!Array.isArray(t))return[];const a={},r=zu(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Uu(t){if(!t.length)return[];const a=[...t].sort((o,c)=>o.day.localeCompare(c.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const Hu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ku(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Js(t){const[a,r]=u.useState(null);return u.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function qu({data:t}){const a=Uu(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:dt,fontFamily:vr,marginBottom:4},children:Hu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Ea},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Ea},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:jr,height:jr,borderRadius:4,background:o<0?"transparent":Yn[o]}},i)})},s))})]})}function Vu({data:t}){const a=Bu(t.heatmapWeeks),r=Ku(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Js(n),o=Js("/neon_bg.png"),c=(t.handle||"?")[0].toUpperCase(),d=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:Ru,fontFamily:vr,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Jn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:d*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:dt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:rt},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:rt},children:c})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:rt},children:t.handle})]})]}),e.jsxs("div",{style:{...Iu,borderRadius:22,padding:Zn,marginBottom:d},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:dt},children:[e.jsx("span",{children:l("share.card.annual.less")}),Yn.map((h,p)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},p)),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,${Ou}px)`,gap:`8px ${Qn}px`,justifyContent:"center"},children:a.map(h=>e.jsx(qu,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:d,marginBottom:d},children:[e.jsxs("div",{style:{...Na,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:wr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...Na,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:gr,fontSize:52,fontWeight:700,color:rt,letterSpacing:"-0.02em",lineHeight:1},children:Wn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:dt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:d},children:[e.jsxs("div",{style:{...Na,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:xr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:gr,fontSize:28,fontWeight:700,color:rt},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...Na,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:xr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:dt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:vr,fontSize:28,fontWeight:700,color: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:xr},children:"tokentracker.cc"})]})]})]})}const Xn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Wu={broadsheet:Gn,"annual-report":Vu};function eo(t){return qn[t]||{width:Hn,height:Kn}}function Gu(t){const a=Xn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Zs=u.forwardRef(function({data:a,variant:r},s){const n=Wu[r]||Gn,{width:i,height:o}=eo(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function Sa(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const Yu=440;function Ju(){const[t,a]=u.useState(null),r=u.useRef(null),s=u.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return u.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function fr({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 Zu({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=u.useState(null),[o,c]=u.useState(""),[d,h]=u.useState("annual-report"),p=u.useRef(null),{toast:g,push:m}=Ju(),x=Ri(),f=u.useMemo(()=>{const N=x?.user;if(!N||typeof N!="object")return null;const w=N.user_metadata||{},T=N.profile||{},P=w.avatar_url||w.picture||T.avatar_url||N.avatar_url;return typeof P=="string"&&P.trim()?P.trim():null},[x?.user]);u.useEffect(()=>{t&&(i(null),c(r?.handle||""))},[t,r?.handle]);const b=r&&{...r,handle:o||r.handle,avatarUrl:f},{width:k,height:j}=eo(d),v=Yu/k;u.useEffect(()=>{if(!t)return;const N=w=>{w.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const C=u.useCallback(async()=>{const N=p.current;if(!N)return null;try{return await yu(N)}catch(w){return console.warn("[share] capture failed",w),null}},[]),D=u.useCallback(async()=>{if(n)return;i("copy");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}let w=!1;if(Sa()){const T=await pr(N);T&&(w=(await pu(T)).ok)}else w=await os(N);m(w?l("share.toast.copied"):l("share.toast.failed"),w?"success":"error"),i(null)},[n,C,m]),M=u.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=u.useCallback(async()=>{if(n)return;i("download");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}if(Sa()){const T=await pr(N);if(T&&(await Ws(T,M())).ok){m(l("share.toast.downloaded"),"success"),i(null);return}}const w=Gs(N,M());m(w?l("share.toast.downloaded"):l("share.toast.failed"),w?"success":"error"),i(null)},[n,C,M,m]),I=u.useCallback(async()=>{if(n)return;i("x");const N=await C();if(!N){m(l("share.toast.failed"),"error"),i(null);return}if(Sa()){const z=await pr(N);z&&(await Ws(z,M()),m(l("share.toast.downloaded"),"success"))}else await os(N)?m(l("share.toast.copied"),"success"):Gs(N,M());const w=new URL("https://twitter.com/intent/tweet");s&&w.searchParams.set("text",s);const T=x?.user?.id,P=typeof T=="string"&&T?`/u/${T}`:"/";if(w.searchParams.set("url",`https://www.tokentracker.cc${P}?ref=share`),Sa())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:w.toString()})}catch{window.open(w.toString(),"_blank","noopener,noreferrer")}else window.open(w.toString(),"_blank","noopener,noreferrer");i(null)},[n,C,m,s,M,x]);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(Zs,{ref:p,data:b,variant:d})}),e.jsxs(Ve.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*v,height:j*v,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:k,height:j,transform:`scale(${v})`,transformOrigin:"top left"},children:e.jsx(Zs,{data:b,variant:d})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:o,onChange:N=>c(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:Xn.map(N=>e.jsx("button",{type:"button",onClick:()=>h(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",d===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Gu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(fr,{onClick:I,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(fr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(fr,{onClick:D,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(hn,{children:g?e.jsx(Ve.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},className:"pointer-events-none absolute left-1/2 bottom-4 -translate-x-1/2",children:e.jsx("div",{className:["px-4 py-2 rounded-full text-xs font-medium shadow-oai-md",g.kind==="error"?"bg-red-600 text-white":g.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:g.text})},g.id):null})]})]}):null}function Qu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:c,periodFrom:d,periodTo:h,heatmap:p,accessToken:g,userId:m,currency:x,exchangeRate:f}=t,[b,k]=u.useState(null),j=f;return u.useEffect(()=>{if(!a||!m&&!pt())return;let v=!1;return(async()=>{try{const D=await Ii({accessToken:g,userId:m,period:c==="day"||c==="custom"?"week":c,metric:"all",limit:100,offset:0});if(v)return;const A=(Array.isArray(D?.entries)?D.entries:Array.isArray(D)?D:[]).find(N=>N?.is_me===!0),I=typeof A?.rank=="number"?A.rank:null;k(I)}catch{v||k(null)}})(),()=>{v=!0}},[a,g,m,c]),u.useMemo(()=>_u({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:b,period:c,periodFrom:d,periodTo:h,heatmap:p,currency:x,exchangeRate:typeof j=="number"?j:void 0}),[r,s,n,i,o,b,c,d,h,p,x,j])}function Qs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const Xu=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function em({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const tm=["day","week","month","total","custom"],yr=new Set(["day","hour","month"]),Gt=new Set(["day","total","custom"]),am=["statsPanel","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],rm=["usageOverview","dataDetails"];function br(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 Ca(t){return t?Tt(t,null):null}function Xs(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function sm(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function nm(){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:!sm(window.location.hostname)}function Wm({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:c="/sign-in",signUpUrl:d="/sign-up",onMainContentVisible:h}){const{resolvedLocale:p}=Fi(),{currency:g,rate:m}=aa(),{mode:x,setMode:f,formatTokens:b,formatTokensTooltip:k}=Ne(),[j,v]=u.useState(!1),[C,D]=u.useState(null),[M,A]=u.useState(null),[I,N]=u.useState(!1),[w,T]=u.useState(null),[P,z]=u.useState(0),[K,E]=u.useState(0),[O,U]=u.useState(null),W=u.useMemo(()=>typeof window>"u"?!1:$i(window.location.search),[]),F=u.useMemo(()=>nm(),[]),[S,$]=u.useState(!1),de=2200,[ie,G]=u.useState(!0),[se,ue]=u.useState(!1),[ke,je]=u.useState(!1),[Te,Q]=u.useState(!1),[B,ne]=u.useState(!1),X=u.useRef(!1),te=pt(),xe=r&&!s,ee=u.useMemo(()=>xe&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,xe]),Y=xe?ee:null,Z=i?Pi(o):Y,ae=r||te||i,Se=xe&&ea(Y),Ae=r&&s&&!i,{accountView:Fe,revision:$e,resolving:Mt,scopeSwitchable:Lt,setScopeOverride:Ce}=Oi(),_=Fe&&!i,V=Lt&&!i,re=_?Y:null,oe=Mt&&!i;u.useEffect(()=>{if(!r||te){D(null),A(null),N(!1),T(null);return}if(i)return;if(!Se){D(null),A(null),N(!1),T(null);return}let y=!0;const L=()=>{D(null),A(null),N(!1),T(null)};return N(!0),T(null),(async()=>{let R=null;try{R=await He(Y)}catch{R=null}if(y){if(!R){L();return}try{const q={link_code:null,expires_at:null};if(!y)return;D(typeof q?.link_code=="string"?q.link_code:null),A(typeof q?.expires_at=="string"?q.expires_at:null)}catch(q){if(!y)return;D(null),A(null),T(q?.message||"Failed to load link code")}finally{if(!y)return;N(!1)}}})(),()=>{y=!1}},[t,te,r,i,Se,Y,K]);const le=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");u.useEffect(()=>{if(!le&&(!r||te||i)){U(null);return}if(!le&&!Se){U(null);return}let y=!0;return(async()=>{let L=null;try{L=await He(Y)}catch{L=null}if(y){if(!L&&!le){U(null);return}try{const R=await zi({baseUrl:t,accessToken:L});if(!y)return;U(R&&typeof R=="object"?R:null)}catch{if(!y)return;U(null)}}})(),()=>{y=!1}},[Se,t,Y,te,i,r]);const We=u.useMemo(()=>{if(!M)return!1;const y=Date.parse(M);if(!Number.isFinite(y))return!1;const L=P||Date.now();return y<=L},[M,P]);u.useEffect(()=>{!r||te||i||!M||!We||I||(D(null),A(null),T(null),E(y=>y+1))},[We,M,I,te,r]),u.useEffect(()=>{if(!M||i)return;const y=Date.parse(M);if(!Number.isFinite(y))return;const L=Date.now();if(z(L),y<=L)return;const R=window.setTimeout(()=>z(Date.now()),y-L),q=()=>{typeof document>"u"||document.visibilityState==="visible"&&z(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",q),window.addEventListener("focus",q),()=>{window.clearTimeout(R),typeof document<"u"&&document.removeEventListener("visibilitychange",q),window.removeEventListener("focus",q)}},[M]);const he=u.useMemo(()=>sn(),[]),ge=u.useMemo(()=>rn(),[]),Pe=u.useMemo(()=>Bi(),[]),Oe=i?null:a?.userId||a?.email||"default",[Et,xt]=u.useState("month"),[Ge,Ra]=u.useState(null),[Xe,Ia]=u.useState(null),[Fa,gt]=u.useState(!1),J=W?"total":Et,ra=u.useMemo(()=>J==="custom"&&Ge&&Xe?{from:Ge,to:Xe}:Ui(J,{timeZone:he,offsetMinutes:ge,now:Pe}),[Pe,J,he,ge,Ge,Xe]),_e=ra.from,we=ra.to,[Rt,nt]=u.useState(null),ye=Rt&&Rt.startsWith("local:")!==_?Rt:null,[It,sa]=u.useState(()=>is());u.useEffect(()=>{const y=()=>sa(is());return window.addEventListener(ls,y),window.addEventListener("storage",y),()=>{window.removeEventListener(ls,y),window.removeEventListener("storage",y)}},[]);const{devices:na,accountSources:oa,refresh:Ft,loading:$t,revision:ia}=cu({from:_e,to:we,timeZone:he,tzOffsetMinutes:ge,accountView:_,accountAccessToken:re,accountRevision:$e,localView:!i&&!te}),ze=_?$e:ia,Be=u.useMemo(()=>na.filter(y=>!_||(Number(y.total_tokens)||0)>0).map(y=>({...y,isCurrent:y.isCurrent||y.id===It})),[na,It,_]),Pt=u.useMemo(()=>oa.filter(y=>(Number(y.total_tokens)||0)>0),[oa]),ft=V||Be.length>=2,Ot=(_||Be.length>=2)&&Be.length+Pt.length>=2;u.useEffect(()=>{if(!$t){if(!ft&&!Ot){ye!==null&&nt(null);return}ye&&!Be.some(y=>y.id===ye)&&nt(null)}},[ft,Ot,Be,ye,$t]);const $a=u.useMemo(()=>{if(!ft)return[];const y=Be.map(L=>{const R=kr(L)||l("dashboard.device_card.unnamed"),q=L.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:L.id,label:`${R}${q}`}});return V?[{value:Lr,label:l("usage.overview.scope_local")},...y,{value:"",label:l("usage.overview.scope_account")}]:[{value:"",label:l("dashboard.device_filter.all")},...y]},[ft,V,Be,p]),Pa=hu({accountScopeSwitchable:V,accountView:_,selectedDevice:ye}),la=_?{devices:Be,accountSources:Pt}:Ll(Be,Pt,ye),Oa=Ot?e.jsx(uu,{devices:la.devices,accountSources:la.accountSources,currentDeviceId:It,selectedDeviceId:ye||"",onSelectDevice:y=>nt(y||null),onRenameDevice:_?async(y,L)=>{const R=await He(re);await Gi({deviceId:y,name:L,accessToken:R}),await Ft()}:void 0}):null,ca=u.useMemo(()=>Hi({timeZone:he,offsetMinutes:ge}),[he,ge]),zt=u.useMemo(()=>Ki({timeZone:he,offsetMinutes:ge}),[he,ge]),za=u.useMemo(()=>`Local time (${zt})`,[zt]),yt=he,Bt=ge,Ba=ca,me=u.useMemo(()=>Cr({timeZone:he,offsetMinutes:ge,date:Pe||new Date}),[Pe,he,ge]),fe=u.useMemo(()=>Tc({period:J,selectedFrom:_e,selectedTo:we,todayKey:me}),[_e,J,we,me]),{daily:be,summary:pe,rolling:et,source:bt,loading:Er,error:to,refresh:Rr}=bs({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:_e,to:we,includeDaily:J!=="total",cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{daily:Ir,loading:ao,refresh:Fr}=bs({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:fe.from,to:fe.to,includeDaily:!0,includeSummary:!1,cacheKey:Oe?`${Oe}.daily-breakdown`:"daily-breakdown",timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{breakdown:tt,loading:$r,refresh:Pr}=lc({baseUrl:t,accessToken:Z,guestAllowed:Ae,from:_e,to:we,cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),[ro,so]=u.useState(3),{entries:no,loading:oo,refresh:Or}=nc({baseUrl:t,accessToken:Z,from:_e,to:we,timeZone:he,tzOffsetMinutes:ge}),zr=J==="week"||J==="month",da=J==="week"||J==="month",Br=u.useMemo(()=>be.filter(y=>y?.future?!1:!y?.day||!me?!0:String(y.day)<=String(me)),[be,me]),{rows:Je,from:io,to:lo,loading:co,refresh:Ur}=Zi({baseUrl:t,accessToken:Z,guestAllowed:Ae,period:J,from:_e,to:we,months:24,cacheKey:Oe,timeZone:yt,tzOffsetMinutes:Bt,now:Pe,sharedRows:zr?be:null,sharedRange:zr?{from:_e,to:we}:null,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),uo=u.useMemo(()=>({baseUrl:t,accessToken:Z,guestAllowed:Ae,cacheKey:Oe,timeZone:yt,tzOffsetMinutes:Bt,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),[t,Z,Ae,Oe,yt,Bt,Pe,_,re,ze,oe,ye]),{daily:kt,heatmap:Ye,loading:Hr,refresh:Kr}=ec({baseUrl:t,accessToken:Z,guestAllowed:Ae,weeks:52,cacheKey:Oe,timeZone:he,tzOffsetMinutes:ge,now:Pe,accountView:_,accountAccessToken:re,accountRevision:ze,accountViewResolving:oe,deviceId:ye}),{data:ua,refresh:qr}=Qi();u.useEffect(()=>{ua&&typeof ua=="object"&&qi(ua)},[ua]);const Ke=u.useMemo(()=>J==="day"?"hour":J==="total"?"month":"day",[J]),mo=u.useMemo(()=>_s(Ke),[Ke]),ma="day",ho=u.useMemo(()=>_s(ma),[]),[qe,Vr]=u.useState(()=>({key:"day",dir:"desc"}));u.useEffect(()=>{Vr(y=>!yr.has(y.key)||y.key===Ke?y:{key:Ke,dir:y.dir})},[Ke]);const _t=u.useMemo(()=>yr.has(qe.key)&&qe.key!==Ke?{...qe,key:Ke}:qe,[Ke,qe]),ha=u.useMemo(()=>{if(J==="day")return Array.isArray(Je)?Je.filter(R=>R?.hour&&!R?.future):[];if(J==="total"){const R=Array.isArray(Je)?Je.filter(q=>q?.month&&!q?.future):[];return _c(R)}const y=Br;return!y.some(R=>!R?.missing&&!R?.future)&&be.length>0?be.filter(R=>!R?.future).slice(-30).filter(R=>R?.day):y},[J,Je,Br,be]),Ut=u.useMemo(()=>ws(ha,_t),[ha,_t]),Wr=u.useMemo(()=>ha.some(y=>!y?.missing&&!y?.future),[ha]),Ua=u.useMemo(()=>{if(!Gt.has(J))return 1;const y=Math.ceil(Ut.length/Da);return y>0?y:1},[J,Ut.length]),[Ha,pa]=u.useState(0);u.useEffect(()=>{if(!Gt.has(J)){pa(0);return}pa(y=>Math.min(y,Ua-1))},[Ua,J]),u.useEffect(()=>{Gt.has(J)&&pa(0)},[J,qe.dir,qe.key]);const po=u.useMemo(()=>Gt.has(J)?wc(Ut,Ha,Da):Ut,[Ha,J,Ut]),Gr=u.useMemo(()=>Ac(Ir,{period:J}),[Ir,J]),wt=u.useMemo(()=>yr.has(qe.key)?{...qe,key:ma}:qe,[qe]),xo=u.useMemo(()=>ws(Gr,wt),[Gr,wt]),go=u.useMemo(()=>da?be:J==="day"?Array.isArray(Je)?Je.filter(y=>y?.hour):[]:Je,[be,J,Je,da]),fo=da?_e:io,yo=da?we:lo;function bo(y,L){if(y?.future)return"—";if(y?.missing)return l("shared.status.unsynced");if(L.endsWith("_tokens")){const R=L==="total_tokens"?Ca(y):y?.[L];return e.jsx("span",{title:k(R),children:b(R)})}return Aa(y?.[L])}function ko(y){const L=y?.[Ke];if(L==null)return"";const R=String(L);if(Ke==="hour"){const[q,Le]=R.split("T");if(q&&Le)return`${q} ${Le.slice(0,5)}`}return R}function _o(y){const L=y?.[ma];return L==null?"":String(L)}function wo(y){Vr(L=>L.key===y?{key:y,dir:L.dir==="asc"?"desc":"asc"}:{key:y,dir:"desc"})}function vo(y){return _t.key!==y?"none":_t.dir==="asc"?"ascending":"descending"}function jo(y){return _t.key!==y?"":_t.dir==="asc"?"▲":"▼"}function No(y){return wt.key!==y?"none":wt.dir==="asc"?"ascending":"descending"}function So(y){return wt.key!==y?"":wt.dir==="asc"?"▲":"▼"}const Ka=u.useMemo(()=>{if(!r&&!te&&!i&&!le)return 0;const y=Number(Ye?.active_days);if(Number.isFinite(y))return y;let L=0;const R=new Set,q=(ve,Ue,Ee)=>{typeof ve!="string"||!ve||R.has(ve)||br(Ue,Ee)&&(R.add(ve),L+=1)};if(Array.isArray(kt))for(const ve of kt)q(ve?.day,Ca(ve));const Le=Array.isArray(Ye?.weeks)?Ye.weeks:[];for(const ve of Le)for(const Ue of Array.isArray(ve)?ve:[]){const Ee=Xs(Ue);q(Ue?.day,Ee,Ue?.level)}return L},[r,te,Ye?.active_days,Ye?.weeks,kt]),[Yr,Jr]=u.useState("month"),Co=u.useCallback(y=>{_&&!i&&_a(a?.userId,"history"),y==="custom"?(Jr(L=>L==="custom"?"month":L),xt(L=>Ge&&Xe?"custom":L),gt(!0)):(xt(y),Jr(y),gt(!1))},[Ge,Xe,_,i,a?.userId]),To=u.useCallback((y,L)=>{_&&!i&&_a(a?.userId,"history"),Ra(y),Ia(L),xt("custom"),gt(!1)},[_,i,a?.userId]),Ao=u.useCallback(y=>{gt(y),!y&&Et==="custom"&&!Ge&&xt(Yr)},[Et,Ge,Yr]),Do=u.useRef(null),xa=u.useMemo(()=>[t||"",Oe||"",_?"cloud":"local",ze??"",J||"",_e||"",we||"",me||"",ye||"all",he||"",ge??""].join(""),[ze,_,t,Oe,_e,J,ye,he,me,we,ge]),Ht=u.useCallback(async()=>Qs(Do,xa,async()=>{_&&Vi(),_||Wi(),await Promise.all([Rr(),Kr(),Ur(),Pr(),Or(),Fr(),..._?[]:[Ft()]])}),[_,Fr,Ft,Kr,Pr,Or,Ur,Rr,xa]),Mo=u.useRef(null),Zr=u.useCallback(async()=>Qs(Mo,xa,async()=>{await em({refreshUsageStats:Ht,refreshUsageLimits:qr})}),[xa,qr,Ht]),qa=u.useRef(Ht);u.useEffect(()=>{qa.current=Ht},[Ht]);const Va=u.useRef(null);u.useEffect(()=>{if(!le||te||_)return;Va.current||(Va.current=cs({auto:!0,background:!0,allLocalSources:!0}));let y=!0;return Va.current.then(()=>{if(y)return qa.current()}).catch(L=>{y&&console.warn("[DashboardPage] Reload sync failed:",L)}),()=>{y=!1}},[le,te,_]),u.useEffect(()=>{if(!le||te||_)return;const y=Sc({refresh:()=>qa.current(),onError:L=>console.warn("[DashboardPage] Automatic usage refresh failed:",L)});return()=>y.stop()},[le,te,_]);const Lo=u.useCallback(async()=>{Q(!0);try{le&&await cs(Xu),await Zr()}catch(y){console.error("[DashboardPage] Refresh failed:",y)}finally{Q(!1)}},[le,Zr]),ga=Te||Er||ao||Hr||co||$r||oo,Wa=!B&&(oe||_&&ga&&!Wr),Eo=u.useMemo(()=>l("shared.data_source",{source:String(bt||"edge").toUpperCase()}),[bt,p]),fa=u.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),Ro="",Qr=u.useMemo(()=>!fa||fa.includes("@")?l("dashboard.identity.fallback"):fa,[fa]),Xr=u.useMemo(()=>Qr.replace(/[^a-zA-Z0-9._-]/g,"_"),[Qr]),es=u.useMemo(()=>i?l("dashboard.identity.fallback"):Xr,[Xr,Ro,i]),ts=u.useMemo(()=>{let y=null;const L=q=>{typeof q!="string"||!q||(!y||q<y)&&(y=q)};if(Array.isArray(kt))for(const q of kt)q?.day&&br(Ca(q))&&L(q.day);const R=Array.isArray(Ye?.weeks)?Ye.weeks:[];for(const q of R)for(const Le of Array.isArray(q)?q:[]){if(!Le?.day)continue;const ve=Xs(Le),Ue=Le?.level;br(ve,Ue)&&L(Le.day)}return y},[Ye?.weeks,kt]),Io=u.useMemo(()=>i?[]:(Array.isArray(O?.subscriptions?.items)?O.subscriptions.items:[]).map(R=>{const q=typeof R?.tool=="string"?R.tool.trim():"",ve=(typeof R?.plan_type=="string"?R.plan_type:typeof R?.planType=="string"?R.planType:"").trim();return!q||!ve?null:{tool:q,planType:ve,provider:typeof R?.provider=="string"?R.provider.trim():"",product:typeof R?.product=="string"?R.product.trim():"",rateLimitTier:typeof R?.rate_limit_tier=="string"?R.rate_limit_tier.trim():typeof R?.rateLimitTier=="string"?R.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,O]),Fo=e.jsx(Xi,{heatmap:Ye,timeZoneLabel:ca,timeZoneShortLabel:zt,hideLegend:W,defaultToLatestMonth:W}),$o=u.useMemo(()=>`${_e}..${we}`,[_e,J,we]),Po=l("usage.summary.total"),Me=pe!=null,vt=Me?Ca(pe):0,Oo=b(vt),zo=u.useCallback(()=>{f(x===Yt.COMPACT?Yt.FULL:Yt.COMPACT)},[f,x]),Bo=l("dashboard.core_index.collapse_label"),Uo=l("dashboard.core_index.expand_label"),Ho=l("dashboard.core_index.collapse_aria"),Ko=l("dashboard.core_index.expand_aria"),qo=!W,jt=l("shared.placeholder.short"),Ga=u.useMemo(()=>{const y=Array.isArray(tt?.sources)?tt.sources:[];let L=null,R=0;for(const Ue of y){const Ee=Tt(Ue?.totals);!Number.isFinite(Ee)||Ee<=0||Ee>R&&(R=Ee,L=Ue)}let q=jt,Le=jt,ve="0.0";if(L&&R>0){q=L?.source?String(L.source).toUpperCase():jt;const Ue=Array.isArray(L?.models)?L.models:[];let Ee=0;for(const tr of Ue){const ba=Tt(tr?.totals);!Number.isFinite(ba)||ba<=0||ba>Ee&&(Ee=ba,Le=tr?.model?String(tr.model):jt)}Ee>0&&(ve=(Ee/R*100).toFixed(1))}return{agentName:q,modelName:Le,modelPercent:ve}},[tt,jt]),Ya=Aa(vt),Vo=l("dashboard.screenshot.twitter_text",{total_tokens:Ya==="-"?jt:Ya,agent_name:Ga.agentName,model_name:Ga.modelName,model_percent:Ga.modelPercent}),Wo=u.useMemo(()=>W?[]:tm,[W]),Go=u.useMemo(()=>[{label:l("usage.metric.total"),value:Me?b(vt):"—",title:Me?k(vt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?b(pe?.input_tokens):"—",title:Me?k(pe?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?b(pe?.output_tokens):"—",title:Me?k(pe?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?b(pe?.cached_input_tokens):"—",title:Me?k(pe?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?b(pe?.reasoning_output_tokens):"—",title:Me?k(pe?.reasoning_output_tokens):void 0}],[pe?.cached_input_tokens,pe?.input_tokens,pe?.output_tokens,pe?.reasoning_output_tokens,vt,Me,b,k]),Ja=(tt?.sources||[]).some(y=>(y.models||[]).some(L=>L.pricing?.status==="unpriced"&&L.cost_source!=="provider_reported"&&Number(L.totals?.total_tokens)>0)),Za=u.useMemo(()=>{if(Ja&&Number(pe?.total_cost_usd)===0)return l("dashboard.cost_breakdown.unpriced_label");const y=ta(pe?.total_cost_usd,{currency:g,rate:m});return Ja&&y!=="-"?`≥${y}`:y},[pe?.total_cost_usd,g,m,Ja]),Yo=u.useMemo(()=>pe?.conversation_count??null,[pe?.conversation_count]),as=u.useMemo(()=>zc(tt,{copyFn:l}),[tt]),rs=u.useMemo(()=>Uc(tt,{limit:3,copyFn:l}),[tt]),Jo=Qu({enabled:S,handle:es,startDate:ts,activeDays:Ka,summary:pe,topModels:rs,period:J,periodFrom:_e,periodTo:we,heatmap:Ye,accessToken:typeof Z=="string"?Z:null,userId:a?.userId||null,currency:g,exchangeRate:m}),Zo=u.useCallback(()=>$(!0),[]),Qo=u.useCallback(()=>$(!1),[]),Xo=u.useCallback(()=>v(!0),[]),ei=u.useCallback(()=>v(!1),[]),ti=Za&&Za!=="-"&&as.length>0,Kt=l("dashboard.install.cmd.init"),Qa=We?null:C,Xa=Qa?l("dashboard.install.cmd.init_link_code",{link_code:Qa}):Kt,ai=Kt,ri=l("dashboard.install.cmd.sync"),si=Qa?l("dashboard.install.copy"):l("dashboard.install.copy_base"),ni=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const oi=!!(O?.install?.has_active_device_token??O?.install?.hasActiveDeviceToken),ii=vc({publicMode:i,screenshotMode:W,forceInstall:F,accessEnabled:ae,heatmapLoading:Hr,activeDays:Ka,hasActiveDeviceToken:oi}),li=l("dashboard.install.prompt"),ci=u.useCallback(async()=>{!Xa||!await ds(Xa)||(ue(!0),window.setTimeout(()=>ue(!1),2e3))},[Xa]);u.useCallback(async()=>{!Kt||!await ds(Kt)||(je(!0),window.setTimeout(()=>je(!1),2e3))},[Kt]);const er=u.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[p]),[di,ui]=u.useMemo(()=>{const y=er.split("{{cmd}}");return y.length===1?[er,""]:[y[0],y.slice(1).join("{{cmd}}")]},[er]),qt=s&&!i,Vt=!r&&!te&&!s&&!le&&!i;u.useEffect(()=>{qt||Vt||Wa||ne(!0)},[Wa,Vt,qt]);const ya=rc(am,rm);return u.useEffect(()=>{X.current||qt||Vt||ga||(X.current=!0,h?.())},[h,Vt,qt,ga]),e.jsxs(e.Fragment,{children:[e.jsx(lu,{copy:l,accountView:_,accountScopeSwitchable:V,onOpenShare:Zo,screenshotMode:W,showExpiredGate:qt,showAuthGate:Vt,identityDisplayName:es,identityStartDate:ts,activeDays:Ka,identitySubscriptions:Io,identityScrambleDurationMs:de,projectUsageEntries:no,projectUsageLimit:ro,setProjectUsageLimit:so,projectDetailQuery:{from:_e,to:we,timeZone:he,tzOffsetMinutes:ge},topModels:rs,signedIn:r,publicMode:i,isLocalMode:le,shouldShowInstall:ii,installPrompt:li,handleCopyInstall:ci,installCopied:se,installCopiedLabel:ni,installCopyLabel:si,installInitCmdDisplay:ai,linkCodeLoading:I,linkCodeError:w,trendRowsForDisplay:go,trendFromForDisplay:fo,trendToForDisplay:yo,trendZoomConfig:uo,usageFrom:_e,usageTo:we,period:J,trendTimeZoneLabel:Ba,activityHeatmapBlock:Fo,periodsForDisplay:Wo,setSelectedPeriod:Co,customFrom:Ge,customTo:Xe,onCustomRangeApply:To,customRangeOpen:Fa,onCustomRangeOpenChange:Ao,metricsRows:Go,summaryLabel:Po,summaryValue:Oo,hasSummary:Me,summaryLoading:Er,providersLoading:$r,summaryFullValue:Ya,onToggleSummaryFormat:zo,summaryTotalTokensRaw:H(vt)||0,summaryCostValue:Za,summaryConversationsValue:Yo,rollingUsage:et,costInfoEnabled:ti,openCostModal:Xo,allowBreakdownToggle:qo,coreIndexCollapsed:ie,setCoreIndexCollapsed:G,coreIndexCollapseLabel:Bo,coreIndexExpandLabel:Uo,coreIndexCollapseAria:Ho,coreIndexExpandAria:Ko,refreshAll:Lo,usageLoadingState:ga,announceUsageLoading:Te,initialDashboardLoading:Wa,usageError:to,rangeLabel:$o,timeZoneRangeLabel:za,usageSourceLabel:Eo,fleetData:as,hasDetailsActual:Wr,dailyEmptyPrefix:di,installSyncCmd:ri,dailyEmptySuffix:ui,detailsColumns:mo,ariaSortFor:vo,toggleSort:wo,sortIconFor:jo,pagedDetails:po,dailyBreakdownRows:xo,dailyBreakdownColumns:ho,dailyBreakdownAriaSortFor:No,dailyBreakdownSortIconFor:So,dailyBreakdownDateKey:ma,detailsDateKey:Ke,renderDetailDate:ko,renderDailyBreakdownDate:_o,renderDetailCell:bo,DETAILS_PAGED_PERIODS:Gt,detailsPageCount:Ua,detailsPage:Ha,setDetailsPage:pa,costModalOpen:j,closeCostModal:ei,deviceOptions:$a,selectedDevice:Pa,onDeviceChange:y=>{if(V){const L=mu(y);Ce(L.scopeOverride),L.scopeOverride===null&&!i&&_a(a?.userId,"view"),nt(L.deviceId);return}_&&!i&&_a(a?.userId,"view"),nt(y||null)},deviceUsageBlock:Oa,localHistoryOnly:!_&&Be.some(y=>y.imported_at),localHistoryRevision:_?0:ia,leftCardOrder:ya.left.order,onLeftReorder:ya.left.reorder,rightCardOrder:ya.right.order,onRightReorder:ya.right.reorder}),e.jsx(Zu,{open:S,onClose:Qo,data:Jo,twitterText:Vo})]})}export{Wm as DashboardPage};