tokentracker-cli 0.22.0 → 0.22.1

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 (35) hide show
  1. package/README.ja.md +6 -4
  2. package/README.ko.md +6 -4
  3. package/README.md +6 -4
  4. package/README.zh-CN.md +6 -4
  5. package/dashboard/dist/assets/{Card-CD18G4Ge.js → Card-DdDoM-Gd.js} +1 -1
  6. package/dashboard/dist/assets/{DashboardPage-DKY_Mi9v.js → DashboardPage-DqsLRhn6.js} +1 -1
  7. package/dashboard/dist/assets/{DevicePage-BkavlAal.js → DevicePage-Dz2WacAK.js} +1 -1
  8. package/dashboard/dist/assets/{FadeIn-CVNJ4aZy.js → FadeIn-CoY8tCtI.js} +1 -1
  9. package/dashboard/dist/assets/{HeaderGithubStar-COu1Xy3I.js → HeaderGithubStar-hr5WjsdY.js} +1 -1
  10. package/dashboard/dist/assets/{IpCheckPage-B2HjZ3vY.js → IpCheckPage-Dkp3KLz5.js} +1 -1
  11. package/dashboard/dist/assets/{LandingPage-9PSLFnys.js → LandingPage-BrXJJj3l.js} +1 -1
  12. package/dashboard/dist/assets/{LeaderboardPage-CQT5dBHU.js → LeaderboardPage-DvrAcWn2.js} +1 -1
  13. package/dashboard/dist/assets/{LeaderboardProfilePage-aPP-Raey.js → LeaderboardProfilePage-KRQhdatN.js} +1 -1
  14. package/dashboard/dist/assets/{LimitsPage-eFrAHmoA.js → LimitsPage-Ds-pKbQw.js} +1 -1
  15. package/dashboard/dist/assets/{LoginPage-CczTNZ_P.js → LoginPage-t-VKaIRw.js} +1 -1
  16. package/dashboard/dist/assets/{PopoverPopup-CEvWSWgZ.js → PopoverPopup-Cyf_sjKX.js} +1 -1
  17. package/dashboard/dist/assets/{ProviderIcon-ewev19y3.js → ProviderIcon-Dqb9ThUH.js} +1 -1
  18. package/dashboard/dist/assets/{SettingsPage-taBxq6ux.js → SettingsPage-DhiG9bbD.js} +1 -1
  19. package/dashboard/dist/assets/{SkillsPage-cqHO3rMB.js → SkillsPage-BdtuTu9f.js} +1 -1
  20. package/dashboard/dist/assets/{WidgetsPage-B53b1hwG.js → WidgetsPage--n-BUbXK.js} +1 -1
  21. package/dashboard/dist/assets/{WrappedPage-DwAhprTa.js → WrappedPage-DRoff4y0.js} +1 -1
  22. package/dashboard/dist/assets/check-BuIsQw1B.js +1 -0
  23. package/dashboard/dist/assets/{chevron-down-zOKEzHdv.js → chevron-down-DvuPNrFG.js} +1 -1
  24. package/dashboard/dist/assets/{download-BZZ4vKc1.js → download-LwtMKzsl.js} +1 -1
  25. package/dashboard/dist/assets/{leaderboard-columns-BNGlMUsD.js → leaderboard-columns-C01mJBwn.js} +1 -1
  26. package/dashboard/dist/assets/{main-D0Irg9xR.js → main-Csid8osN.js} +2 -2
  27. package/dashboard/dist/assets/{use-limits-display-prefs-BTuSZo27.js → use-limits-display-prefs-BP17xuqs.js} +1 -1
  28. package/dashboard/dist/assets/{use-native-settings-BPXVZrWe.js → use-native-settings-C-RMuUxI.js} +1 -1
  29. package/dashboard/dist/assets/{use-reduced-motion-HUOV_JD1.js → use-reduced-motion-CPJKbom2.js} +1 -1
  30. package/dashboard/dist/assets/{use-usage-limits-G6-vCBcN.js → use-usage-limits-DIE-GP0H.js} +1 -1
  31. package/dashboard/dist/index.html +1 -1
  32. package/dashboard/dist/share.html +1 -1
  33. package/package.json +1 -1
  34. package/src/lib/pricing/seed-snapshot.json +1 -1
  35. package/dashboard/dist/assets/check-JnFJsHgI.js +0 -1
package/README.ja.md CHANGED
@@ -14,7 +14,7 @@
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
15
15
  [![Platform](https://img.shields.io/badge/macOS-supported-lightgrey.svg)](https://www.apple.com/macos/)
16
16
  [![GitHub stars](https://img.shields.io/github/stars/mm7894215/TokenTracker?style=social)](https://github.com/mm7894215/TokenTracker/stargazers)
17
- [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://www.tokentracker.cc/leaderboard/u/0652839f-d19f-4f67-af85-6b7675875443)
17
+ [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://github.com/mm7894215/TokenTracker)
18
18
 
19
19
  <br/>
20
20
 
@@ -404,11 +404,13 @@ GitHub プロフィールやプロジェクトの README で自分のトーク
404
404
  以下のどれかを貼り付けてください:
405
405
 
406
406
  ```markdown
407
- ![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)
408
- ![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)
409
- ![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)
407
+ [![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)](https://github.com/mm7894215/TokenTracker)
408
+ [![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)](https://github.com/mm7894215/TokenTracker)
409
+ [![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)](https://github.com/mm7894215/TokenTracker)
410
410
  ```
411
411
 
412
+ > リンク先はデフォルトで TokenTracker リポジトリに設定してあり、クリックがそのまま他の開発者の発見につながります。あなた自身の leaderboard プロフィール、個人サイト、または `https://www.tokentracker.cc` に飛ばしたい場合は URL を差し替えてください。
413
+
412
414
  現在の合計を反映した shields.io 互換バッジが描画されます(60 秒キャッシュ):
413
415
 
414
416
  | パラメータ | 値 | デフォルト |
package/README.ko.md CHANGED
@@ -14,7 +14,7 @@
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
15
15
  [![Platform](https://img.shields.io/badge/macOS-supported-lightgrey.svg)](https://www.apple.com/macos/)
16
16
  [![GitHub stars](https://img.shields.io/github/stars/mm7894215/TokenTracker?style=social)](https://github.com/mm7894215/TokenTracker/stargazers)
17
- [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://www.tokentracker.cc/leaderboard/u/0652839f-d19f-4f67-af85-6b7675875443)
17
+ [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://github.com/mm7894215/TokenTracker)
18
18
 
19
19
  <br/>
20
20
 
@@ -404,11 +404,13 @@ GitHub 프로필이나 프로젝트 README에서 토큰 사용량을 자랑해
404
404
  아래 중 하나를 붙여넣으세요:
405
405
 
406
406
  ```markdown
407
- ![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)
408
- ![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)
409
- ![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)
407
+ [![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)](https://github.com/mm7894215/TokenTracker)
408
+ [![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)](https://github.com/mm7894215/TokenTracker)
409
+ [![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)](https://github.com/mm7894215/TokenTracker)
410
410
  ```
411
411
 
412
+ > 링크 대상은 기본적으로 TokenTracker 리포지토리로 설정되어 있어, 클릭 한 번이 다른 개발자의 발견으로 이어집니다. 본인의 leaderboard 프로필, 개인 사이트, 또는 `https://www.tokentracker.cc`로 보내고 싶다면 URL만 바꾸면 됩니다.
413
+
412
414
  현재 합계를 반영한 shields.io 호환 배지가 렌더링됩니다 (60초 캐시):
413
415
 
414
416
  | 파라미터 | 값 | 기본값 |
package/README.md CHANGED
@@ -14,7 +14,7 @@ Auto-collect token counts from **22 AI coding tools**, aggregate them locally, a
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
15
15
  [![Platform](https://img.shields.io/badge/macOS-supported-lightgrey.svg)](https://www.apple.com/macos/)
16
16
  [![GitHub stars](https://img.shields.io/github/stars/mm7894215/TokenTracker?style=social)](https://github.com/mm7894215/TokenTracker/stargazers)
17
- [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://www.tokentracker.cc/leaderboard/u/0652839f-d19f-4f67-af85-6b7675875443)
17
+ [![Author tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://github.com/mm7894215/TokenTracker)
18
18
 
19
19
  <br/>
20
20
 
@@ -406,11 +406,13 @@ To get `YOUR_USER_ID`:
406
406
  Then drop one of these in:
407
407
 
408
408
  ```markdown
409
- ![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)
410
- ![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)
411
- ![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)
409
+ [![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=tokens)](https://github.com/mm7894215/TokenTracker)
410
+ [![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=cost)](https://github.com/mm7894215/TokenTracker)
411
+ [![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=YOUR_USER_ID&metric=rank)](https://github.com/mm7894215/TokenTracker)
412
412
  ```
413
413
 
414
+ > The link target defaults to the TokenTracker repo so every click helps other developers discover the tool. Swap it for your leaderboard profile, personal site, or `https://www.tokentracker.cc` if you'd rather route clicks elsewhere.
415
+
414
416
  Renders shields.io-compatible badges with your current totals (60s cache):
415
417
 
416
418
  | Param | Values | Default |
package/README.zh-CN.md CHANGED
@@ -14,7 +14,7 @@
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
15
15
  [![Platform](https://img.shields.io/badge/macOS-supported-lightgrey.svg)](https://www.apple.com/macos/)
16
16
  [![GitHub stars](https://img.shields.io/github/stars/mm7894215/TokenTracker?style=social)](https://github.com/mm7894215/TokenTracker/stargazers)
17
- [![作者 tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://www.tokentracker.cc/leaderboard/u/0652839f-d19f-4f67-af85-6b7675875443)
17
+ [![作者 tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=0652839f-d19f-4f67-af85-6b7675875443&metric=tokens&compact=1&label=author%20tokens)](https://github.com/mm7894215/TokenTracker)
18
18
 
19
19
  <br/>
20
20
 
@@ -406,11 +406,13 @@ xattr -cr /Applications/TokenTrackerBar.app
406
406
  然后贴一段:
407
407
 
408
408
  ```markdown
409
- ![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=tokens)
410
- ![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=cost)
411
- ![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=rank)
409
+ [![tokens](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=tokens)](https://github.com/mm7894215/TokenTracker)
410
+ [![cost](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=cost)](https://github.com/mm7894215/TokenTracker)
411
+ [![rank](https://srctyff5.us-east.insforge.app/functions/tokentracker-badge-svg?user_id=你的_USER_ID&metric=rank)](https://github.com/mm7894215/TokenTracker)
412
412
  ```
413
413
 
414
+ > 链接默认指向 TokenTracker 仓库,每次点击都能帮其他开发者发现 TokenTracker。如果你想让点击跳到你自己的 leaderboard profile、个人主页或 `https://www.tokentracker.cc`,改 URL 即可。
415
+
414
416
  输出 shields.io 兼容的徽章 SVG,含你当前的累计数据(60 秒缓存):
415
417
 
416
418
  | 参数 | 取值 | 默认 |
@@ -1 +1 @@
1
- import{C as r}from"./main-D0Irg9xR.js";function t({children:i,title:a,subtitle:o,className:s="",bodyClassName:d=""}){return r.jsxs("div",{className:`rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 transition-colors duration-200 ${s}`,children:[(a||o)&&r.jsxs("div",{className:"px-5 py-4 border-b border-oai-gray-200 dark:border-oai-gray-800 transition-colors duration-200",children:[a&&r.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide transition-colors duration-200",children:a}),o&&r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-300 mt-1 transition-colors duration-200",children:o})]}),r.jsx("div",{className:`p-5 ${d}`,children:i})]})}export{t as C};
1
+ import{C as r}from"./main-Csid8osN.js";function t({children:i,title:a,subtitle:o,className:s="",bodyClassName:d=""}){return r.jsxs("div",{className:`rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 transition-colors duration-200 ${s}`,children:[(a||o)&&r.jsxs("div",{className:"px-5 py-4 border-b border-oai-gray-200 dark:border-oai-gray-800 transition-colors duration-200",children:[a&&r.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide transition-colors duration-200",children:a}),o&&r.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-300 mt-1 transition-colors duration-200",children:o})]}),r.jsx("div",{className:`p-5 ${d}`,children:i})]})}export{t as C};
@@ -1,4 +1,4 @@
1
- import{c as Kt,i as Mi,f as Jr,a as Zr,J as Ci,u as eo,m as Di,r as m,M as to,b as Ti,d as Ai,e as Yn,g as Oi,h as It,j as Xt,k as Pt,l as Ei,n as fa,o as bn,p as ba,q as Cn,s as Fi,t as Wi,v as Pi,w as ka,x as qt,y as zn,z as Ii,A as ze,B as h,C as o,D as no,X as ao,E as He,L as Li,F as $e,R as $,G as Dn,H as jn,I as $i,K as ro,N as oo,O as wa,P as Ri,Q as so,_ as io,S as ma,T as Bi,U as Yi,V as zi,W as Hi,Y as Ui,Z as qi,$ as Gi,a0 as Vi,a1 as Ki,a2 as Xi,a3 as dt,a4 as sr}from"./main-D0Irg9xR.js";import{u as Qi}from"./use-usage-limits-G6-vCBcN.js";import{I as va,u as Ji,a as Zi,b as el,c as tl,d as nl,D as al,e as rl,f as ol,g as sl,h as il,i as ll,C as cl,P as dl,j as ul,k as fl,l as ml,m as hl,L as gl}from"./PopoverPopup-CEvWSWgZ.js";import{C as _a}from"./Card-CD18G4Ge.js";import{u as Na}from"./use-reduced-motion-HUOV_JD1.js";import{P as lo}from"./ProviderIcon-ewev19y3.js";import{F as Yt}from"./FadeIn-CVNJ4aZy.js";const yl=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],pl=Kt("maximize-2",yl);const xl=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],bl=Kt("pause",xl);const kl=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],wl=Kt("play",kl);const vl=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],_l=Kt("rotate-ccw",vl);const Nl=[["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"}]],jl=Kt("square-arrow-out-up-right",Nl);const Sl=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Ml=Kt("terminal",Sl);function Cl(...e){const t=!Array.isArray(e[0]),n=t?0:-1,a=e[0+n],r=e[1+n],s=e[2+n],i=e[3+n],l=Mi(r,s,i);return t?l(a):l}function Dl(e,t,n={}){const a=e.get();let r=null,s=a,i;const l=typeof a=="string"?a.replace(/[\d.-]/g,""):void 0,c=()=>{r&&(r.stop(),r=null),e.animation=void 0},d=()=>{const u=ir(e.get()),y=ir(s);if(u===y){c();return}const g=r?r.getGeneratorVelocity():e.getVelocity();c(),r=new Ci({keyframes:[u,y],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...n,onUpdate:i})},f=()=>{d(),e.animation=r??void 0,e.events.animationStart?.notify(),r?.then(()=>{e.animation=void 0,e.events.animationComplete?.notify()})};if(e.attach((u,y)=>{s=u,i=g=>y(Hn(g,l)),Jr.postRender(f)},c),Zr(t)){let u=n.skipInitialAnimation===!0;const y=t.on("change",x=>{u?(u=!1,e.jump(Hn(x,l),!1)):e.set(Hn(x,l))}),g=e.on("destroy",y);return()=>{y(),g()}}return c}function Hn(e,t){return t?e+t:e}function ir(e){return typeof e=="number"?e:parseFloat(e)}function ja(e){const t=eo(()=>Di(e)),{isStatic:n}=m.useContext(to);if(n){const[,a]=m.useState(e);m.useEffect(()=>t.on("change",a),[])}return t}function co(e,t){const n=ja(t()),a=()=>n.set(t());return a(),Ti(()=>{const r=()=>Jr.preRender(a,!1,!0),s=e.map(i=>i.on("change",r));return()=>{s.forEach(i=>i()),Ai(a)}}),n}function Tl(e){Yn.current=[],e();const t=co(Yn.current,e);return Yn.current=void 0,t}function uo(e,t,n,a){if(typeof e=="function")return Tl(e);const s=typeof t=="function"?t:Cl(t,n,a),i=Array.isArray(e)?lr(e,s):lr([e],([c])=>s(c)),l=Array.isArray(e)?void 0:e.accelerate;return l&&!l.isTransformed&&typeof t!="function"&&Array.isArray(n)&&a?.clamp!==!1&&(i.accelerate={...l,times:t,keyframes:n,isTransformed:!0}),i}function lr(e,t){const n=eo(()=>[]);return co(e,()=>{n.length=0;const a=e.length;for(let r=0;r<a;r++)n[r]=e[r].get();return t(n)})}function Al(e,t={}){const{isStatic:n}=m.useContext(to),a=()=>Zr(e)?e.get():e;if(n)return uo(a);const r=ja(a());return m.useInsertionEffect(()=>Dl(r,e,t),[r,JSON.stringify(t)]),r}function Ol(e,t={}){return Al(e,{type:"spring",...t})}function El({baseUrl:e,accessToken:t,guestAllowed:n=!1,weeks:a=52,weekStartsOn:r="sun",cacheKey:s,timeZone:i,tzOffsetMinutes:l,now:c}={}){const d=m.useMemo(()=>Oi({weeks:a,weekStartsOn:r,now:c}),[c,a,r]),[f,u]=m.useState([]),[y,g]=m.useState(null),[x,p]=m.useState("edge"),[b,k]=m.useState(!1),[v,w]=m.useState(null),C=It(),D=Xt(t),S=!n,I=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),N=m.useMemo(()=>{if(!s)return null;const L=Cn({timeZone:i,offsetMinutes:l});return`tokentracker.heatmap.${s}.${a}.${r}.${L}`},[s,i,l,a,r]),O=m.useCallback(()=>{if(!N||typeof window>"u")return null;try{const L=window.localStorage.getItem(N);if(!L)return null;const B=JSON.parse(L);return!B||!B.heatmap?null:B}catch{return null}},[N]),E=m.useCallback(L=>{if(!(!N||typeof window>"u"))try{window.localStorage.setItem(N,JSON.stringify(L))}catch{}},[N]),F=m.useCallback(()=>{if(!(!N||typeof window>"u"))try{window.localStorage.removeItem(N)}catch{}},[N]),Q=m.useCallback(async()=>{const L=await Pt(t);if(!(!L&&!C&&!I)){k(!0),w(null);try{try{const Y=await Ei({baseUrl:e,accessToken:L,weeks:a,to:d.to,weekStartsOn:r,timeZone:i,tzOffsetMinutes:l}),P=Array.isArray(Y?.weeks)?Y.weeks:[];if(!P.length&&S){const G=O();if(G?.heatmap){g(G.heatmap),u(G.daily||[]),p("cache");return}}if(!P.some(G=>(Array.isArray(G)?G:[]).some(de=>de&&Number.isFinite(Number(de.level))))&&P.length){const G=[];for(const W of P)for(const V of Array.isArray(W)?W:[])V?.day&&G.push({day:V.day,total_tokens:V.total_tokens??V.value??0,billable_total_tokens:V.billable_total_tokens??V.value??V.total_tokens??0});const de=fa({dailyRows:G,weeks:a,to:Y?.to||d.to,weekStartsOn:r});u(G),g({...de,week_starts_on:r,active_days:G.filter(W=>Number(W?.billable_total_tokens??W?.total_tokens)>0).length,streak_days:bn({dailyRows:G,to:Y?.to||d.to})}),p("client"),S?E({heatmap:{...de,week_starts_on:r,active_days:G.filter(W=>Number(W?.billable_total_tokens??W?.total_tokens)>0).length,streak_days:bn({dailyRows:G,to:Y?.to||d.to})},daily:G,fetchedAt:new Date().toISOString()}):F();return}g(Y||null),u([]),p("edge"),Y&&S?E({heatmap:Y,daily:[],fetchedAt:new Date().toISOString()}):S||F();return}catch(Y){const P=Y,z=P?.status??P?.statusCode;if(z===401||z===403)throw Y}const B=await ba({baseUrl:e,accessToken:L,from:d.from,to:d.to,timeZone:i,tzOffsetMinutes:l}),M=Array.isArray(B?.data)?B.data:[];u(M);const Z=fa({dailyRows:M,weeks:a,to:d.to,weekStartsOn:r});g({...Z,week_starts_on:r,active_days:M.filter(Y=>Number(Y?.billable_total_tokens??Y?.total_tokens)>0).length,streak_days:bn({dailyRows:M,to:d.to})}),p("client"),S?E({heatmap:{...Z,week_starts_on:r,active_days:M.filter(Y=>Number(Y?.billable_total_tokens??Y?.total_tokens)>0).length,streak_days:bn({dailyRows:M,to:d.to})},daily:M,fetchedAt:new Date().toISOString()}):F()}catch(B){if(S){const M=O();if(M?.heatmap)g(M.heatmap),u(M.daily||[]),p("cache"),w(null);else{const Z=B;w(Z?.message||String(Z)),u([]),g(null),p("edge")}}else{const M=B;w(M?.message||String(M)),u([]),g(null),p("edge")}}finally{k(!1)}}},[t,e,C,n,S,d.from,d.to,O,D,i,l,r,a,F,E,I]);return m.useEffect(()=>{if(!D&&!n&&!C&&!I){u([]),k(!1),w(null),g(null),p("edge");return}if(!S)F(),u([]),w(null),g(null),p("edge");else{const L=O();L?.heatmap&&(g(L.heatmap),u(L.daily||[]),p("cache"))}Q()},[t,C,O,Q,D,n,S,F,I]),{range:d,daily:f,heatmap:y,source:C?"mock":x==="client"?"edge":x,loading:b,error:v,refresh:Q}}function Fl({baseUrl:e,accessToken:t,limit:n=3,from:a,to:r,source:s,timeZone:i,tzOffsetMinutes:l}={}){const[c,d]=m.useState([]),[f,u]=m.useState(!1),[y,g]=m.useState(null),x=It(),p=Xt(t),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=m.useCallback(async()=>{const v=await Pt(t);if(!v&&!x&&!b){d([]),g(null),u(!1);return}u(!0),g(null);try{const w=await Fi({baseUrl:e,accessToken:v,limit:n,from:a,to:r,source:s,timeZone:i,tzOffsetMinutes:l});d(Array.isArray(w?.entries)?w.entries:[])}catch(w){const C=w?.message||String(w);g(C),d([])}finally{u(!1)}},[t,e,a,n,x,s,i,r,l,b]);return m.useEffect(()=>{if(!p&&!x&&!b){d([]),g(null),u(!1);return}k()},[x,k,p,b]),{entries:c,loading:f,error:y,refresh:k}}const Wl=24;function Pl({baseUrl:e,accessToken:t,guestAllowed:n=!1,period:a,from:r,to:s,months:i=Wl,cacheKey:l,timeZone:c,tzOffsetMinutes:d,now:f,sharedRows:u,sharedRange:y}={}){const[g,x]=m.useState([]),[p,b]=m.useState(()=>({from:r,to:s})),[k,v]=m.useState("edge"),[w,C]=m.useState(null),[D,S]=m.useState(!1),[I,N]=m.useState(null),O=It(),E=Xt(t),F=!n,Q=Array.isArray(u),j=y?.from||r,L=y?.to||s,B=m.useMemo(()=>a==="day"?"hourly":a==="total"?"monthly":"daily",[a]),M=(()=>{if(!l)return null;const W=Il(e)||"default",V=Cn({timeZone:c,offsetMinutes:d});if(B==="hourly")return`tokentracker.trend.${l}.${W}.hourly.${s||r||"day"}.${V}`;if(B==="monthly")return`tokentracker.trend.${l}.${W}.monthly.${i}.${s||"today"}.${V}`;const ue=`${r||""}.${s||""}`;return`tokentracker.trend.${l}.${W}.daily.${ue}.${V}`})(),Z=m.useCallback(()=>{if(!M||typeof window>"u")return null;try{const W=window.localStorage.getItem(M);if(!W)return null;const V=JSON.parse(W);return!V||!Array.isArray(V.rows)?null:V}catch{return null}},[M]),Y=m.useCallback(W=>{if(!(!M||typeof window>"u"))try{window.localStorage.setItem(M,JSON.stringify(W))}catch{}},[M]),P=m.useCallback(()=>{if(!(!M||typeof window>"u"))try{window.localStorage.removeItem(M)}catch{}},[M]),z=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),G=m.useCallback(async()=>{if(Q){x(Array.isArray(u)?u:[]),b({from:j,to:L}),v("shared"),C(null),S(!1),N(null);return}const W=await Pt(t);if(!(!W&&!O&&!z)){S(!0),N(null);try{let V;B==="hourly"?V=await Wi({baseUrl:e,accessToken:W,day:s||r,timeZone:c,tzOffsetMinutes:d}):B==="monthly"?V=await Pi({baseUrl:e,accessToken:W,months:i,to:s,timeZone:c,tzOffsetMinutes:d}):V=await ba({baseUrl:e,accessToken:W,from:r,to:s,timeZone:c,tzOffsetMinutes:d});const ue=V?.from||r||V?.day||null,me=V?.to||s||V?.day||null;let T=Array.isArray(V?.data)?V.data:[];B==="daily"?T=qn(T,ue||r,me||s,{timeZone:c,offsetMinutes:d,now:f}):B==="hourly"?T=Gn(T,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(T=Vn(T,{timeZone:c,offsetMinutes:d,now:f}));const oe=new Date().toISOString();x(T),b({from:ue,to:me}),v("edge"),C(oe),F?Y({rows:T,from:ue,to:me,mode:B,fetchedAt:oe}):P()}catch(V){if(F){const ue=Z();if(ue?.rows){let me=B==="daily"?qn(ue.rows||[],ue.from||r,ue.to||s,{timeZone:c,offsetMinutes:d,now:f}):Array.isArray(ue.rows)?ue.rows:[];B==="hourly"?me=Gn(me,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(me=Vn(me,{timeZone:c,offsetMinutes:d,now:f})),x(me),b({from:ue.from||r,to:ue.to||s}),v("cache"),C(ue.fetchedAt||null),N(null)}else{x([]),b({from:r,to:s}),v("edge"),C(null);const me=V;N(me?.message||String(me))}}else{x([]),b({from:r,to:s}),v("edge"),C(null);const ue=V;N(ue?.message||String(ue))}}finally{S(!1)}}},[t,e,r,O,n,F,B,i,Z,E,Q,j,u,L,c,s,d,f,P,Y,z]);m.useEffect(()=>{if(Q){x(Array.isArray(u)?u:[]),b({from:j,to:L}),v("shared"),C(null),S(!1),N(null);return}if(!E&&!n&&!O&&!z){x([]),b({from:r,to:s}),N(null),S(!1),v("edge"),C(null);return}if(!F)P(),x([]),b({from:r,to:s}),N(null),v("edge"),C(null);else{const W=Z();if(W?.rows){let V=B==="daily"?qn(W.rows||[],W.from||r,W.to||s,{timeZone:c,offsetMinutes:d,now:f}):Array.isArray(W.rows)?W.rows:[];B==="hourly"?V=Gn(V,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(V=Vn(V,{timeZone:c,offsetMinutes:d,now:f})),x(V),b({from:W.from||r,to:W.to||s}),v("cache"),C(W.fetchedAt||null)}}G()},[t,O,Z,G,Q,j,u,L,E,n,F,P,z]);const de=O?"mock":k;return{rows:g,from:p.from||r,to:p.to||s,source:de,fetchedAt:w,loading:D,error:I,refresh:G}}function Il(e){try{return new URL(e).host}catch{return null}}function Un(e){if(!e)return null;const t=String(e).trim(),n=t.split("-");if(n.length!==3)return null;const a=Number(n[0]),r=Number(n[1])-1,s=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r,s));return Number.isFinite(i.getTime())&&qt(i)===t?i:null}function Ll(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function qn(e,t,n,{timeZone:a,offsetMinutes:r,now:s}={}){const i=Un(t),l=Un(n);if(!i||!l||l<i)return Array.isArray(e)?e:[];const c=s instanceof Date&&Number.isFinite(s.getTime())?s:new Date,d=ka({timeZone:a,offsetMinutes:r,date:c}),f=Un(d),u=f?f.getTime():c.getTime(),y=new Map;for(const x of e||[])x?.day&&y.set(x.day,x);const g=[];for(let x=i;x<=l;x=Ll(x,1)){const p=qt(x),b=y.get(p),k=x.getTime()>u;if(b){g.push({...b,missing:!1,future:k});continue}g.push({day:p,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!k,future:k})}return g}function Gn(e,{timeZone:t,offsetMinutes:n,now:a}={}){if(!Array.isArray(e))return[];const r=fo({timeZone:t,offsetMinutes:n,now:a});return r?e.map(s=>{const i=s?.hour||s?.label||"",l=$l(i);if(!l)return{...s,future:!1};const c=l.dayNum>r.dayNum||l.dayNum===r.dayNum&&l.slot>r.slot;return{...s,future:c}}):e}function Vn(e,{timeZone:t,offsetMinutes:n,now:a}={}){if(!Array.isArray(e))return[];const r=fo({timeZone:t,offsetMinutes:n,now:a});return r?e.map(s=>{const i=s?.month||s?.label||"",l=Rl(i);if(!l)return{...s,future:!1};const c=l.year>r.year||l.year===r.year&&l.month>r.month;return{...s,future:c}}):e}function fo({timeZone:e,offsetMinutes:t,now:n}={}){const a=n instanceof Date&&Number.isFinite(n.getTime())?n:new Date;if(e&&typeof Intl<"u"&&Intl.DateTimeFormat)try{const y=new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(a).reduce((v,w)=>(w.type&&w.value&&(v[w.type]=w.value),v),{}),g=Number(y.year),x=Number(y.month),p=Number(y.day),b=Number(y.hour),k=Number(y.minute);if(Number.isFinite(g)&&Number.isFinite(x)&&Number.isFinite(p)&&Number.isFinite(b)&&Number.isFinite(k)){const v=b*2+(k>=30?1:0);return{year:g,month:x,day:p,hour:b,minute:k,dayNum:g*1e4+x*100+p,slot:v}}}catch{}if(Number.isFinite(t)){const f=new Date(a.getTime()+t*60*1e3),u=f.getUTCFullYear(),y=f.getUTCMonth()+1,g=f.getUTCDate(),x=f.getUTCHours(),p=f.getUTCMinutes(),b=x*2+(p>=30?1:0);return{year:u,month:y,day:g,hour:x,minute:p,dayNum:u*1e4+y*100+g,slot:b}}const r=a.getFullYear(),s=a.getMonth()+1,i=a.getDate(),l=a.getHours(),c=a.getMinutes(),d=l*2+(c>=30?1:0);return{year:r,month:s,day:i,hour:l,minute:c,dayNum:r*1e4+s*100+i,slot:d}}function $l(e){if(!e)return null;const t=String(e).trim(),[n,a]=t.split("T");if(!n||!a)return null;const r=n.split("-");if(r.length!==3)return null;const s=Number(r[0]),i=Number(r[1]),l=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(l))return null;const c=a.split(":"),d=Number(c[0]),f=Number(c[1]);if(!Number.isFinite(d)||d<0||d>23||!Number.isFinite(f)||f<0||f>59)return null;const u=d*2+(f>=30?1:0);return{dayNum:s*1e4+i*100+l,slot:u}}function Rl(e){if(!e)return null;const n=String(e).trim().split("-");if(n.length!==2)return null;const a=Number(n[0]),r=Number(n[1]);return!Number.isFinite(a)||!Number.isFinite(r)||r<1||r>12?null:{year:a,month:r}}function cr({baseUrl:e,accessToken:t,guestAllowed:n=!1,from:a,to:r,includeDaily:s=!0,cacheKey:i,timeZone:l,tzOffsetMinutes:c,now:d}={}){const[f,u]=m.useState([]),[y,g]=m.useState(null),[x,p]=m.useState(null),[b,k]=m.useState("edge"),[v,w]=m.useState(null),[C,D]=m.useState(!1),[S,I]=m.useState(null),N=It(),O=Xt(t),E=!n,F=(()=>{if(!i)return null;const Y=Bl(e)||"default",P=s?"daily":"summary",z=Cn({timeZone:l,offsetMinutes:c});return`tokentracker.usage.${i}.${Y}.${a}.${r}.${P}.${z}`})(),Q=m.useCallback(()=>{if(!F||typeof window>"u")return null;try{const Y=window.localStorage.getItem(F);if(!Y)return null;const P=JSON.parse(Y);return!P||!P.summary?null:P}catch{return null}},[F]),j=m.useCallback(Y=>{if(!(!F||typeof window>"u"))try{window.localStorage.setItem(F,JSON.stringify(Y))}catch{}},[F]),L=m.useCallback(()=>{if(!(!F||typeof window>"u"))try{window.localStorage.removeItem(F)}catch{}},[F]),B=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),M=m.useCallback(async()=>{const Y=await Pt(t);if(!(!Y&&!N&&!B)){D(!0),I(null);try{let P=null,z=null;if(s){const[ue,me]=await Promise.allSettled([ba({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c}),zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0})]);if(ue.status==="rejected")throw ue.reason;P=ue.value,z=me.status==="fulfilled"?me.value:null}else z=await zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0});let G=s&&Array.isArray(P?.data)?P.data:[];s&&(G=Xn(G,a,r,{timeZone:l,offsetMinutes:c,now:d}));let de=z?.totals||P?.summary?.totals||null,W=z?.rolling||P?.summary?.rolling||null;if(s&&!de&&!z)try{const ue=await zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0});de=ue?.totals||null,W=ue?.rolling||W}catch{}const V=new Date().toISOString();u(G),g(de),p(W),k("edge"),w(V),de&&E?j({summary:de,rolling:W,daily:G,from:a,to:r,includeDaily:s,fetchedAt:V}):E||L()}catch(P){if(E){const z=Q();if(z?.summary){g(z.summary),p(z.rolling||null);const G=Array.isArray(z.daily)?z.daily:[],de=s?Xn(G,z.from||a,z.to||r,{timeZone:l,offsetMinutes:c,now:d}):G;u(de),k("cache"),w(z.fetchedAt||null),I(null)}else{const G=P;I(G?.message||String(G)),u([]),g(null),p(null),k("edge"),w(null)}}else{const z=P;I(z?.message||String(z)),u([]),g(null),p(null),k("edge"),w(null)}}finally{D(!1)}}},[t,e,a,s,N,n,E,d,Q,O,l,r,c,L,j,B]);return m.useEffect(()=>{const Y=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!O&&!n&&!N&&!Y){u([]),g(null),p(null),I(null),D(!1),k("edge"),w(null);return}if(!E)L(),u([]),g(null),p(null),I(null),k("edge"),w(null);else{const P=Q();if(P?.summary){g(P.summary),p(P.rolling||null);const z=Array.isArray(P.daily)?P.daily:[],G=s?Xn(z,P.from||a,P.to||r,{timeZone:l,offsetMinutes:c,now:d}):z;u(G),k("cache"),w(P.fetchedAt||null)}}M()},[t,N,Q,M,O,n,E,L,B]),{daily:f,summary:y,rolling:x,source:N?"mock":b,fetchedAt:v,loading:C,error:S,refresh:M}}function Bl(e){try{return new URL(e).host}catch{return null}}function Kn(e){if(!e)return null;const t=String(e).trim(),n=t.split("-");if(n.length!==3)return null;const a=Number(n[0]),r=Number(n[1])-1,s=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r,s));return Number.isFinite(i.getTime())&&qt(i)===t?i:null}function Yl(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function Xn(e,t,n,{timeZone:a,offsetMinutes:r,now:s}={}){const i=Kn(t),l=Kn(n);if(!i||!l||l<i)return Array.isArray(e)?e:[];const c=s instanceof Date&&Number.isFinite(s.getTime())?s:new Date,d=ka({timeZone:a,offsetMinutes:r,date:c}),f=Kn(d),u=f?f.getTime():c.getTime(),y=new Map;for(const x of e||[])x?.day&&y.set(x.day,x);const g=[];for(let x=i;x<=l;x=Yl(x,1)){const p=qt(x),b=y.get(p),k=x.getTime()>u;if(b){g.push({...b,missing:!1,future:k});continue}g.push({day:p,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!k,future:k})}return g}function zl({baseUrl:e,accessToken:t,guestAllowed:n=!1,from:a,to:r,cacheKey:s,timeZone:i,tzOffsetMinutes:l}={}){const[c,d]=m.useState(null),[f,u]=m.useState("edge"),[y,g]=m.useState(!1),[x,p]=m.useState(null),b=It(),k=Xt(t),v=!n,w=m.useMemo(()=>{if(!s)return null;const E=Hl(e)||"default",F=Cn({timeZone:i,offsetMinutes:l});return`tokentracker.modelBreakdown.${s}.${E}.${a}.${r}.${F}`},[e,s,a,i,r,l]),C=m.useCallback(()=>{if(!w||typeof window>"u")return null;try{const E=window.localStorage.getItem(w);if(!E)return null;const F=JSON.parse(E);return!F||!F.breakdown?null:F}catch{return null}},[w]),D=m.useCallback(E=>{if(!(!w||typeof window>"u"))try{window.localStorage.setItem(w,JSON.stringify(E))}catch{}},[w]),S=m.useCallback(()=>{if(!(!w||typeof window>"u"))try{window.localStorage.removeItem(w)}catch{}},[w]),I=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),N=m.useCallback(async()=>{const E=await Pt(t);if(!(!E&&!b&&!I)){g(!0),p(null);try{const F=await Ii({baseUrl:e,accessToken:E,from:a,to:r,timeZone:i,tzOffsetMinutes:l});d(F||null),u("edge"),F&&v?D({breakdown:F,fetchedAt:new Date().toISOString()}):v||S()}catch(F){if(v){const Q=C();if(Q?.breakdown)d(Q.breakdown),u("cache"),p(null);else{d(null),u("edge");const j=F;p(j?.message||String(j))}}else{d(null),u("edge");const Q=F;p(Q?.message||String(Q))}}finally{g(!1)}}},[t,e,a,b,n,v,C,i,r,k,l,S,D,I]);return m.useEffect(()=>{if(!k&&!n&&!b&&!I){d(null),u("edge"),p(null),g(!1);return}if(!v)S(),d(null),u("edge"),p(null);else{const E=C();E?.breakdown&&(d(E.breakdown),u("cache"))}N()},[t,b,C,N,k,n,v,S,I]),{breakdown:c,source:b?"mock":f,loading:y,error:x,refresh:N}}function Hl(e){try{return new URL(e).host}catch{return null}}const mo=new Set(["day","hour","month"]);function Ul(e){return mo.has(e)}function dr(e){if(e==null)return null;const t=String(e).trim();if(!/^[0-9]+$/.test(t))return null;const n=t.replace(/^0+/,"");return n.length===0?"0":n}function ql(e,t){const n=dr(e),a=dr(t);if(n&&a)return n.length!==a.length?n.length<a.length?-1:1:n===a?0:n<a?-1:1;const r=ze(e),s=ze(t);return r==null&&s==null?0:r==null?1:s==null?-1:r===s?0:r<s?-1:1}function Gl(e,t){const n=typeof e=="string"?e:String(e||""),a=typeof t=="string"?t:String(t||"");return n===a?0:n<a?-1:1}function Vl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]),s=Number(n[3]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r-1,s));return!Number.isFinite(i.getTime())||i.getUTCFullYear()!==a||i.getUTCMonth()+1!==r||i.getUTCDate()!==s?null:i.getTime()}function Kl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||r<1||r>12)return null;const s=new Date(Date.UTC(a,r-1,1));return Number.isFinite(s.getTime())?s.getTime():null}function Xl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]),s=Number(n[3]),i=Number(n[4]),l=Number(n[5]),c=Number(n[6]||0);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(l)||!Number.isFinite(c)||r<1||r>12||s<1||s>31||i<0||i>23||l<0||l>59||c<0||c>59)return null;const d=new Date(Date.UTC(a,r-1,s,i,l,c));return Number.isFinite(d.getTime())?d.getTime():null}function Ql(e,t,n){const a=n==="hour"?Xl:n==="month"?Kl:Vl,r=a(e),s=a(t);return r!=null&&s!=null?r===s?0:r<s?-1:1:Gl(e,t)}function ho(e,{key:t,dir:n}){const a=n==="asc"?1:-1,r=Array.isArray(e)?e:[],s=mo.has(t)?(l,c)=>Ql(l,c,t):ql,i=l=>t==="total_tokens"&&l?.billable_total_tokens!=null?l.billable_total_tokens:l?.[t];return r.map((l,c)=>({row:l,index:c})).sort((l,c)=>{const d=i(l.row),f=i(c.row),u=d==null,y=f==null;if(u&&y)return l.index-c.index;if(u)return 1;if(y)return-1;const g=s(d,f);return g!==0?g*a:l.index-c.index}).map(l=>l.row)}function Jl(){return[{key:"day",label:h("daily.sort.date.label"),title:h("daily.sort.date.title")},{key:"total_tokens",label:h("daily.sort.total.label"),title:h("daily.sort.total.title")},{key:"input_tokens",label:h("daily.sort.input.label"),title:h("daily.sort.input.title")},{key:"output_tokens",label:h("daily.sort.output.label"),title:h("daily.sort.output.title")},{key:"cached_input_tokens",label:h("daily.sort.cached.label"),title:h("daily.sort.cached.title")},{key:"reasoning_output_tokens",label:h("daily.sort.reasoning.label"),title:h("daily.sort.reasoning.title")},{key:"conversation_count",label:h("daily.sort.conversations.label"),title:h("daily.sort.conversations.title")}]}function ur(e){const t=Ul(e)?e:"day";return Jl().map((n,a)=>a===0?{...n,key:t}:n)}function fr(e,{key:t,dir:n}){return ho(e,{key:t,dir:n})}const Sn=12,Zl=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function ec(e){if(typeof e=="bigint")return e!==0n;if(typeof e=="number")return Number.isFinite(e)&&e!==0;if(e==null)return!1;const t=String(e).trim();if(!t||!/^-?\d+$/.test(t))return!1;const n=t.startsWith("-")?t.slice(1):t;return/[1-9]/.test(n)}function tc(e){return Zl.some(t=>ec(e?.[t]))}function nc(e){const t=Array.isArray(e)?e:[];if(!t.length)return[];const n=ho(t,{key:"month",dir:"asc"}),a=n.findIndex(r=>r?.month&&tc(r));return a===-1?t:n.slice(a)}function ac(e,t,n=Sn){const a=Array.isArray(e)?e:[],r=Number.isFinite(n)&&n>0?n:Sn,i=(Number.isFinite(t)&&t>=0?Math.floor(t):0)*r;return a.slice(i,i+r)}function rc({publicMode:e,screenshotMode:t,forceInstall:n,accessEnabled:a,heatmapLoading:r,activeDays:s,hasActiveDeviceToken:i}={}){return e||t?!1:n?!0:a&&!r&&s===0&&!i}function go(e){if(typeof e!="string")return null;const t=e.trim();return t?t.toLowerCase():null}function oc(e){const t=go(e?.model_id);return t||null}function yo(e,t){return e?.model?String(e.model):t}function Gt(e,t=0){const n=ze(e?.billable_total_tokens),a=ze(e?.total_tokens);return n!=null&&n>0?n:a!=null&&a>0?a:n??a??t}function sc(e,{copyFn:t}={}){const n=typeof t=="function"?t:i=>i,r=(Array.isArray(e?.sources)?e.sources:[]).map(i=>{const l=Gt(i?.totals),c=ze(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(l)?l:0,totalCost:Number.isFinite(c)?c:0,models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!r.length)return[];const s=r.reduce((i,l)=>i+l.totalTokens,0);return typeof e?.pricing?.pricing_mode=="string"&&e.pricing.pricing_mode.toUpperCase(),r.slice().sort((i,l)=>l.totalTokens-i.totalTokens).map(i=>{const l=i.source?String(i.source).toUpperCase():n("shared.placeholder.short"),c=s>0?i.totalTokens/s*100:0,d=Number.isFinite(c)?c.toFixed(1):"0.0",f=i.models.map(u=>{const y=Gt(u?.totals);if(!Number.isFinite(y)||y<=0)return null;const g=i.totalTokens>0?Math.round(y/i.totalTokens*1e3)/10:0,x=yo(u,n("shared.placeholder.short")),p=oc(u),b=ze(u?.totals?.total_cost_usd),k=b??(i.totalCost>0&&i.totalTokens>0?y/i.totalTokens*i.totalCost:null);return{id:p,name:x,share:g,usage:y,cost:k}}).filter(Boolean);return{source:i.source,label:l,totalPercent:String(d),usd:i.totalCost,usage:i.totalTokens,models:f}})}function ic(e,{limit:t=3,copyFn:n}={}){const a=typeof n=="function"?n:y=>y,r=Array.isArray(e?.sources)?e.sources:[];if(!r.length)return[];const s=new Map,i=new Map,l=new Map;let c=0;for(const y of r){const g=Array.isArray(y?.models)?y.models:[];for(const x of g){const p=Gt(x?.totals);if(!Number.isFinite(p)||p<=0)continue;c+=p;const b=yo(x,a("shared.placeholder.short")),k=go(b);if(!k)continue;s.set(k,(s.get(k)||0)+p);const v=l.get(k)||0;p>=v&&(l.set(k,p),i.set(k,b))}}if(!s.size)return[];const d=Array.from(s.values()).reduce((y,g)=>y+g,0),f=c>0?c:d,u=Number.isFinite(t)?Math.max(0,Math.floor(t)):3;return Array.from(s.entries()).map(([y,g])=>{const x=f>0?(g/f*100).toFixed(1):"0.0";return{id:y,name:i.get(y)||a("shared.placeholder.short"),tokens:g,percent:String(x)}}).sort((y,g)=>g.tokens!==y.tokens?g.tokens-y.tokens:String(y.name).localeCompare(String(g.name))).slice(0,u)}const ft={emerald:{light:["#ebedf0","#a7f3d0","#6ee7b7","#34d399","#10b981"],dark:["#2d333b","#065f46","#059669","#10b981","#34d399"],gridColor:{light:"rgba(16, 185, 129, 0.12)",dark:"rgba(52, 211, 153, 0.08)"}},ocean:{light:["#f1f5f9","#93c5fd","#60a5fa","#3b82f6","#1d4ed8"],dark:["#1e293b","#1e3a8a","#2563eb","#3b82f6","#60a5fa"],gridColor:{light:"rgba(59, 130, 246, 0.12)",dark:"rgba(96, 165, 250, 0.08)"}},neon:{light:["#faf5ff","#ebd5ff","#c084fc","#a855f7","#7e22ce"],dark:["#2e1065","#581c87","#8b5cf6","#a855f7","#c084fc"],gridColor:{light:"rgba(168, 85, 247, 0.12)",dark:"rgba(192, 132, 252, 0.08)"}},amber:{light:["#fffbeb","#fde68a","#f59e0b","#d97706","#b45309"],dark:["#451a03","#78350f","#b45309","#d97706","#f59e0b"],gridColor:{light:"rgba(245, 158, 11, 0.12)",dark:"rgba(245, 158, 11, 0.08)"}}};function lc(e,t){const n=/^#([0-9a-f]{6})$/i.exec(e);if(!n)return e;const a=parseInt(n[1],16),r=a>>16&255,s=a>>8&255,i=a&255,l=c=>Math.max(0,Math.min(255,Math.round(c*t)));return`rgb(${l(r)}, ${l(s)}, ${l(i)})`}function Ze(e,t,n,a,r){const s=Math.cos(a),i=Math.sin(a),l=e*s-t*i,c=e*i+t*s,d=n,f=Math.cos(r),u=Math.sin(r),y=l,g=c*f-d*u,x=c*u+d*f;return{x:y,y:g,z:x}}function cc(e,t,n,a,r){return Ze(e,t,n,a,r)}function po(e,t){const n=Number(t).toLocaleString();if(e>=4){const a=Math.floor(Math.random()*3)+1;return h(`heatmap.3d.voxel.joke.${a}`,{value:n})}else return e===3?h("heatmap.3d.voxel.level3",{value:n}):e===2?h("heatmap.3d.voxel.level2",{value:n}):e===1?h("heatmap.3d.voxel.level1",{value:n}):h("heatmap.3d.voxel.level0")}function mr({weeks:e,palette:t="auto",isDark:n=!1,interactive:a=!1,autoRotateInit:r=!1,onResetViewRef:s=null}){const i=ft[t]||(t==="auto"?ft.emerald:null),l=i?n?i.dark:i.light:Array.isArray(t)?t:n?ft.emerald.dark:ft.emerald.light,c=i?n?i.gridColor.dark:i.gridColor.light:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",d=-.2,f=.88,[u,y]=m.useState({yaw:d,pitch:f}),[g,x]=m.useState(r),[p,b]=m.useState(1),k=a?13:10.5,v=m.useMemo(()=>{const A=[],R=e.length;if(R===0||!a)return[];for(let J=0;J<=7;J++){const H=(J-3.5)*k,ie=Ze(-R/2*k,H,0,u.yaw,u.pitch),se=Ze(R/2*k,H,0,u.yaw,u.pitch);A.push({d:`M${ie.x},${ie.y} L${se.x},${se.y}`,key:`horiz-${J}`})}for(let J=0;J<=R;J+=4){const H=(J-R/2)*k,ie=Ze(H,-3.5*k,0,u.yaw,u.pitch),se=Ze(H,3.5*k,0,u.yaw,u.pitch);A.push({d:`M${ie.x},${ie.y} L${se.x},${se.y}`,key:`vert-${J}`})}if(R%4!==0){const J=(R-R/2)*k,H=Ze(J,-3.5*k,0,u.yaw,u.pitch),ie=Ze(J,3.5*k,0,u.yaw,u.pitch);A.push({d:`M${H.x},${H.y} L${ie.x},${ie.y}`,key:"vert-last"})}return A},[e.length,u,k,a]);m.useEffect(()=>{s&&(s.current={reset:()=>{y({yaw:d,pitch:f}),x(!1),b(1),B()},toggleAutoRotate:A=>{x(A)}})},[s]);const w=m.useRef(null),C=m.useRef(null),D=m.useRef(!1),S=m.useRef({x:0,y:0}),I=m.useRef({yaw:d,pitch:f}),N=m.useRef({x:0,y:0}),O=m.useRef({x:0,y:0,time:0}),E=m.useRef(null),[F,Q]=m.useState(0),j=m.useRef(null),L=m.useRef(!0);m.useEffect(()=>(L.current=!0,()=>{L.current=!1}),[]);const B=()=>{j.current&&cancelAnimationFrame(j.current),Q(0);const A=performance.now(),R=1200,J=H=>{if(!L.current)return;const ie=H-A,se=Math.min(1,ie/R),xe=1-Math.pow(1-se,3);Q(xe),se<1?j.current=requestAnimationFrame(J):j.current=null};j.current=requestAnimationFrame(J)};m.useEffect(()=>(B(),()=>{j.current&&cancelAnimationFrame(j.current)}),[a]),m.useEffect(()=>{if(!g||D.current||typeof window>"u"||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let R;const J=()=>{if(typeof document<"u"&&document.visibilityState==="hidden"){R=requestAnimationFrame(J);return}y(H=>({yaw:H.yaw+.002,pitch:H.pitch})),R=requestAnimationFrame(J)};return R=requestAnimationFrame(J),()=>cancelAnimationFrame(R)},[g]);const M=(A,R)=>{a&&(D.current=!0,S.current={x:A,y:R},I.current={yaw:u.yaw,pitch:u.pitch},N.current={x:0,y:0},O.current={x:A,y:R,time:performance.now()},E.current&&cancelAnimationFrame(E.current))},Z=(A,R)=>{if(!D.current)return;const J=A-S.current.x,H=R-S.current.y,ie=performance.now(),se=ie-O.current.time;se>0&&(N.current={x:(A-O.current.x)/se,y:(R-O.current.y)/se}),O.current={x:A,y:R,time:ie};const xe=.005,_e=I.current.yaw-J*xe,Ne=Math.PI/2.3,ae=Math.max(-Ne,Math.min(Ne,I.current.pitch-H*xe));y({yaw:_e,pitch:ae})},Y=()=>{if(!D.current)return;D.current=!1;let A=-N.current.x*12,R=-N.current.y*12;const J=.95,H=()=>{D.current||(A*=J,R*=J,!(Math.abs(A)<.01&&Math.abs(R)<.01)&&(y(ie=>{const se=ie.yaw+A*.005,xe=Math.PI/2.3,_e=Math.max(-xe,Math.min(xe,ie.pitch+R*.005));return{yaw:se,pitch:_e}}),E.current=requestAnimationFrame(H)))};E.current=requestAnimationFrame(H)},[P,z]=m.useState(null),[G,de]=m.useState({x:0,y:0,shiftX:0}),W=m.useRef(null);m.useEffect(()=>()=>{W.current&&clearTimeout(W.current)},[]),m.useEffect(()=>{if(!a||!C.current)return;const A=J=>{J.preventDefault();const H=-J.deltaY*.0025;b(ie=>{const se=ie+H;return Math.max(.5,Math.min(3,se))})},R=C.current;return R.addEventListener("wheel",A,{passive:!1}),()=>{R.removeEventListener("wheel",A)}},[a]);const V=m.useMemo(()=>{const A=[];return e.forEach((R,J)=>{(Array.isArray(R)?R:[]).forEach((H,ie)=>{H&&A.push({key:H.day||`${J}-${ie}`,col:J,row:ie,level:H.level||0,value:H.value||0,day:H.day,models:H.models||null})})}),A},[e]),me=k-(a?1.8:1.5),T=a?38:28,oe=A=>Math.max(1.8,Number(A)/4*T),pe=m.useMemo(()=>{if(V.length===0)return[];const A=e.length;return V.map(R=>{const J=oe(R.level),H=Math.sqrt(Math.pow(R.col-A/2,2)+Math.pow(R.row-3.5,2)),ie=Math.sqrt(Math.pow(A/2,2)+Math.pow(3.5,2)),se=H/ie*.4,xe=Math.min(1,Math.max(0,(F-se)*(1/.6))),_e=J*xe,Ne=(R.col-A/2)*k,ae=(R.row-3.5)*k,ge=me/2,we=[{x:Ne-ge,y:ae-ge,z:0},{x:Ne+ge,y:ae-ge,z:0},{x:Ne+ge,y:ae+ge,z:0},{x:Ne-ge,y:ae+ge,z:0},{x:Ne-ge,y:ae-ge,z:_e},{x:Ne+ge,y:ae-ge,z:_e},{x:Ne+ge,y:ae+ge,z:_e},{x:Ne-ge,y:ae+ge,z:_e}].map(ne=>Ze(ne.x,ne.y,ne.z,u.yaw,u.pitch)),Re=Ze(Ne,ae,_e/2,u.yaw,u.pitch),ot=[{name:"top",indices:[4,5,6,7],scale:1,normal:[0,0,1]},{name:"bottom",indices:[3,2,1,0],scale:.4,normal:[0,0,-1]},{name:"left",indices:[3,0,4,7],scale:.55,normal:[-1,0,0]},{name:"right",indices:[1,2,6,5],scale:.75,normal:[1,0,0]},{name:"front",indices:[0,1,5,4],scale:.85,normal:[0,-1,0]},{name:"back",indices:[2,3,7,6],scale:.65,normal:[0,1,0]}],Nt=l[Math.min(4,Math.max(0,Number(R.level)||0))],gt=[],yt=.35,jt=-.4,ee=.83;return ot.forEach(ne=>{const U=cc(ne.normal[0],ne.normal[1],ne.normal[2],u.yaw,u.pitch);if(U.z>.001){const te=we[ne.indices[0]],Oe=we[ne.indices[1]],ce=we[ne.indices[2]],pt=we[ne.indices[3]],xt=`M${te.x},${te.y} L${Oe.x},${Oe.y} L${ce.x},${ce.y} L${pt.x},${pt.y} Z`,bt=U.x*yt+U.y*jt+U.z*ee,Ge=n?.18:0,st=ne.scale*(.82+.28*Math.max(0,bt))+Ge;gt.push({name:ne.name,d:xt,fill:lc(Nt,st)})}}),{...R,centerProj:Re,renderedFaces:gt}})},[V,u,l,e.length,F,k,me,T]),fe=m.useMemo(()=>[...pe].sort((A,R)=>A.centerProj.z-R.centerProj.z),[pe]),le=m.useMemo(()=>{if(fe.length===0)return{minX:-100,minY:-100,maxX:100,maxY:100};let A=1/0,R=1/0,J=-1/0,H=-1/0;return fe.forEach(ie=>{const se=k*2,xe=ie.centerProj.x,_e=ie.centerProj.y;xe-se<A&&(A=xe-se),xe+se>J&&(J=xe+se),_e-se<R&&(R=_e-se),_e+se>H&&(H=_e+se)}),{minX:A,minY:R,maxX:J,maxY:H}},[fe,k]),he=12,Pe=le.maxX-le.minX+he*2,De=le.maxY-le.minY+he*2,ke=Pe/p,Ie=De/p,je=le.minX-he+(Pe-ke)/2,Te=le.minY-he+(De-Ie)/2,Ce=`${je} ${Te} ${ke} ${Ie}`;return V.length===0?o.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:h("heatmap.empty")}):o.jsxs("div",{ref:C,className:`relative select-none outline-none ${a?"cursor-grab active:cursor-grabbing w-full h-full flex items-center justify-center":"w-full overflow-hidden flex justify-center"}`,onMouseDown:A=>{if(!a)return;M(A.clientX,A.clientY);const R=H=>Z(H.clientX,H.clientY),J=()=>{Y(),window.removeEventListener("mousemove",R),window.removeEventListener("mouseup",J)};window.addEventListener("mousemove",R),window.addEventListener("mouseup",J)},onTouchStart:A=>{!a||A.touches.length===0||M(A.touches[0].clientX,A.touches[0].clientY)},onTouchMove:A=>{!a||A.touches.length===0||Z(A.touches[0].clientX,A.touches[0].clientY)},onTouchEnd:()=>{a&&Y()},children:[o.jsxs("svg",{ref:w,viewBox:Ce,width:a?"95%":"100%",height:a?"95%":"auto",role:"img","aria-label":h("heatmap.iso.aria")||"3D interactive activity heatmap",style:{display:"block",width:"100%",height:"auto",maxWidth:a?"none":`${Pe}px`,maxHeight:a?"78vh":"none"},className:"transition-transform duration-300 ease-out",children:[a&&v.map(A=>o.jsx("path",{d:A.d,fill:"none",stroke:c,strokeWidth:.25,strokeDasharray:"1.5 2.5",strokeLinecap:"round"},A.key)),fe.map(A=>{const R=P&&P.key===A.key;return o.jsxs("g",{onMouseEnter:J=>{if(W.current&&(clearTimeout(W.current),W.current=null),z(A),a&&w.current){const H=Ze((A.col-e.length/2)*k,(A.row-3.5)*k,oe(A.level),u.yaw,u.pitch);let ie=0,se=0;const xe=w.current;if(C.current&&typeof xe.createSVGPoint=="function"&&typeof xe.getScreenCTM=="function")try{const ge=xe.createSVGPoint();ge.x=H.x,ge.y=H.y;const Se=xe.getScreenCTM();if(Se){const we=ge.matrixTransform(Se),Re=C.current.getBoundingClientRect();ie=we.x-Re.left,se=we.y-Re.top}}catch{const Se=xe.getBoundingClientRect(),we=le.maxX-le.minX+he*2,Re=le.maxY-le.minY+he*2;ie=(H.x-(le.minX-he))/we*Se.width,se=(H.y-(le.minY-he))/Re*Se.height}else{const ge=xe.getBoundingClientRect(),Se=le.maxX-le.minX+he*2,we=le.maxY-le.minY+he*2;ie=(H.x-(le.minX-he))/Se*ge.width,se=(H.y-(le.minY-he))/we*ge.height}const _e=140;let Ne=0;const ae=C.current?C.current.getBoundingClientRect().width:xe.getBoundingClientRect().width;ie<_e?Ne=_e-ie:ie>ae-_e&&(Ne=ae-_e-ie),de({x:ie,y:se,shiftX:Ne})}},onMouseLeave:()=>{W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{z(null)},150)},className:"transition-all duration-200",style:{filter:R?"brightness(1.15) drop-shadow(0 4px 6px rgba(0,0,0,0.15))":"none",cursor:a?"pointer":"default"},children:[!a&&A.day&&o.jsx("title",{children:`${A.day}: ${Number(A.value).toLocaleString()} tokens`}),A.renderedFaces.map((J,H)=>o.jsx("path",{d:J.d,fill:J.fill,stroke:J.fill,strokeWidth:.25,strokeLinejoin:"round"},H))]},A.key)})]}),a&&P&&o.jsxs("div",{onMouseEnter:()=>{W.current&&(clearTimeout(W.current),W.current=null)},onMouseLeave:()=>{W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{z(null)},150)},className:"absolute z-[9999] w-0 h-0 transition-all duration-100 ease-out",style:{left:`${G.x}px`,top:`${G.y}px`},children:[o.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${G.shiftX}px))`},children:[o.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:P.day}),(()=>{const A=P.level===0?n?"#9ca3af":"#6b7280":l[P.level];return o.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:A+"22",color:A,border:`1px solid ${A}44`},children:["Level ",P.level]})})()]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-baseline gap-1",children:[o.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none",children:Number(P.value).toLocaleString()}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Tokens"})]}),P.models&&Object.keys(P.models).length>0?o.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[o.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),o.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 scrollbar-thin",children:Object.entries(P.models).map(([A,R])=>({name:A,val:Number(R)})).sort((A,R)=>R.val-A.val).map(({name:A,val:R})=>{const J=Number(P.value)||1,H=Math.round(R/J*100);return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[o.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:A,children:A}),o.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[o.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:R.toLocaleString()}),o.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[H,"%"]})]})]}),o.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${H}%`,backgroundColor:l[4],boxShadow:`0 0 4px ${l[4]}55`}})})]},A)})})]}):o.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:po(P.level,P.value)})]})]}),o.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]})]})}const Ct=12,tn=3,Qn=26,dc=["#ebedf0","#a7f3d0","#6ee7b7","#34d399","#10b981"],uc=["#30363d","#065f46","#059669","#10b981","#34d399"];function hr(e){const t=Number(e);return Number.isFinite(t)?t<1e3?t.toLocaleString():He(t,{decimals:2}):"0"}function fc(e){if(typeof e!="string")return null;const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(!t)return null;const n=new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])));return Number.isFinite(n.getTime())?n:null}function xo(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function mc(e,t){return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()))/864e5)}function hc(e,t){const n=t==="mon"?1:0,a=e.getUTCDay();return xo(e,-((a-n+7)%7))}function gc(e,t,n,a){if(!e)return[];const r=fc(t)||new Date,s=[];for(let f=11;f>=0;f-=1)s.push(new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()-f,1)));const i=hc(r,n),l=xo(i,-(e-1)*7),c=[],d=new Set;for(const f of s){const u=Math.floor(mc(l,f)/7);u<0||u>=e||d.has(u)||(d.add(u),c.push({label:a[f.getUTCMonth()],index:u}))}return c}function yc({heatmap:e,timeZoneLabel:t,timeZoneShortLabel:n,hideLegend:a=!1}){const{resolvedTheme:r}=no(),s=r==="dark",i=s?uc:dc,l=m.useRef(null),c=m.useRef(null),[d,f]=m.useState(null),[u,y]=m.useState({x:0,y:0,shiftX:0}),g=m.useRef(null);m.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]);const[x,p]=m.useState(!1),[b,k]=m.useState(!1),[v,w]=m.useState(!1),C=m.useRef(null),[D,S]=m.useState("emerald"),I=[h("heatmap.month.jan"),h("heatmap.month.feb"),h("heatmap.month.mar"),h("heatmap.month.apr"),h("heatmap.month.may"),h("heatmap.month.jun"),h("heatmap.month.jul"),h("heatmap.month.aug"),h("heatmap.month.sep"),h("heatmap.month.oct"),h("heatmap.month.nov"),h("heatmap.month.dec")],N=(T,oe)=>{if(!oe||!oe.day)return;g.current&&(clearTimeout(g.current),g.current=null),f(oe);const pe=T.currentTarget.getBoundingClientRect(),fe=c.current;if(!fe)return;const le=fe.getBoundingClientRect(),he=pe.left-le.left+pe.width/2,Pe=pe.top-le.top,De=140;let ke=0;he<De?ke=De-he:he>le.width-De&&(ke=le.width-De-he),y({x:he,y:Pe,shiftX:ke})},O=()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{f(null)},150)},E=()=>{g.current&&(clearTimeout(g.current),g.current=null)},F=()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{f(null)},150)},Q=()=>{k(!1),p(!0)},j=()=>{k(!0)},L=T=>{T.target===T.currentTarget&&b&&(p(!1),k(!1))};m.useEffect(()=>{if(!x||b)return;const T=oe=>{oe.key==="Escape"&&j()};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T)}},[x,b]);const B=m.useMemo(()=>({emerald:{accentText:"text-emerald-500 dark:text-emerald-400",accentBg:"bg-emerald-500/10 dark:bg-emerald-400/10",accentBorder:"border-emerald-500/20 dark:border-emerald-400/15",hoverBorder:"hover:border-emerald-500/30 dark:hover:border-emerald-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(16,185,129,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(52,211,153,0.25)]",rawColor:"#10b981"},ocean:{accentText:"text-blue-500 dark:text-blue-400",accentBg:"bg-blue-500/10 dark:bg-blue-400/10",accentBorder:"border-blue-500/20 dark:border-blue-400/15",hoverBorder:"hover:border-blue-500/30 dark:hover:border-blue-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(59,130,246,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(96,165,250,0.25)]",rawColor:"#3b82f6"},neon:{accentText:"text-purple-500 dark:text-purple-400",accentBg:"bg-purple-500/10 dark:bg-purple-400/10",accentBorder:"border-purple-500/20 dark:border-purple-400/15",hoverBorder:"hover:border-purple-500/30 dark:hover:border-purple-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(168,85,247,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(192,132,252,0.25)]",rawColor:"#a855f7"},amber:{accentText:"text-amber-500 dark:text-amber-400",accentBg:"bg-amber-500/10 dark:bg-amber-400/10",accentBorder:"border-amber-500/20 dark:border-amber-400/15",hoverBorder:"hover:border-amber-500/30 dark:hover:border-amber-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(245,158,11,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(245,158,11,0.25)]",rawColor:"#f59e0b"}}),[]),M=B[D]||B.emerald,Z=ft[D]?s?ft[D].dark:ft[D].light:s?ft.emerald.dark:ft.emerald.light,[Y,P]=m.useState(()=>{try{return window.localStorage?.getItem("tt:heatmap-view")==="3d"?"3d":"2d"}catch{return"2d"}});m.useEffect(()=>{try{window.localStorage?.setItem("tt:heatmap-view",Y)}catch{}},[Y]),m.useEffect(()=>{const T=l.current;T&&(T.scrollLeft=T.scrollWidth)},[e?.weeks]),m.useEffect(()=>{const T=l.current;if(!T)return;const oe=()=>{g.current&&(clearTimeout(g.current),g.current=null),f(null)};return T.addEventListener("scroll",oe),()=>T.removeEventListener("scroll",oe)},[]);const z=e?.week_starts_on==="mon"?"mon":"sun",G=m.useMemo(()=>{const T=Array.isArray(e?.weeks)?e.weeks:[];if(!T.length)return{weeks:[]};const oe=[];for(const pe of T)for(const fe of Array.isArray(pe)?pe:[])fe?.day&&oe.push({day:fe.day,total_tokens:fe.total_tokens??fe.value??0,billable_total_tokens:fe.billable_total_tokens??fe.value??fe.total_tokens??0,models:fe.models??null});return fa({dailyRows:oe,weeks:Math.max(52,T.length),to:e?.to,weekStartsOn:z})},[e?.to,e?.weeks,z]),de=G?.weeks||[],W=m.useMemo(()=>{let T=0,oe=0,pe={day:"无数据",value:0},fe=0,le=0;const he=[];de.forEach(Ce=>{(Array.isArray(Ce)?Ce:[]).forEach(A=>{A&&A.day&&he.push(A)})}),he.sort((Ce,A)=>Ce.day.localeCompare(A.day)),he.forEach(Ce=>{const A=Number(Ce.value)||0;T+=A,A>0?(oe++,fe++,fe>le&&(le=fe)):fe=0,A>pe.value&&(pe={day:Ce.day,value:A})});const Pe=he.length||365,De=(oe/Pe*100).toFixed(1);let ke="heatmap.3d.modal.ai.eval.default",Ie="heatmap.3d.modal.ai.title.default";T>=15e6?(Ie="heatmap.3d.modal.ai.title.peak",ke="heatmap.3d.modal.ai.eval.peak"):T>=5e6?(Ie="heatmap.3d.modal.ai.title.heavy",ke="heatmap.3d.modal.ai.eval.heavy"):T>=1e6?(Ie="heatmap.3d.modal.ai.title.core",ke="heatmap.3d.modal.ai.eval.core"):T>=2e4&&(Ie="heatmap.3d.modal.ai.title.steady",ke="heatmap.3d.modal.ai.eval.steady");const je=e?.total_cost_usd,Te=je!=null?Number(je):T/15e5;return{totalTokens:T,activeDays:oe,activeRate:De,maxSingleDay:pe,maxStreak:le,aiEvaluationTitleKey:Ie,aiEvaluationKey:ke,totalCostUsd:Te}},[de,e?.total_cost_usd]),V=z==="mon"?["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(T=>h(`heatmap.day.${T.toLowerCase()}`)):["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(T=>h(`heatmap.day.${T.toLowerCase()}`)),ue=m.useMemo(()=>gc(de.length,G?.to,z,I),[G?.to,de.length,z,I]);if(!de.length)return o.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:h("heatmap.empty")});const me=Qn+de.length*Ct+Math.max(0,de.length-1)*tn;return o.jsxs("div",{ref:c,className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-5",children:[o.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[o.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:h("heatmap.title")}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("div",{role:"tablist","aria-label":"Heatmap view",className:"flex rounded-md border border-oai-gray-200 dark:border-oai-gray-800 p-0.5 text-[10px]",children:[o.jsx("button",{type:"button",role:"tab","aria-selected":Y==="2d",onClick:()=>P("2d"),className:Y==="2d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:h("heatmap.view.2d")}),o.jsx("button",{type:"button",role:"tab","aria-selected":Y==="3d",onClick:()=>P("3d"),className:Y==="3d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:h("heatmap.view.3d")})]}),o.jsx("span",{className:"text-xs text-oai-gray-400 dark:text-oai-gray-450",children:n||h("heatmap.legend.utc")})]})]}),Y==="3d"&&o.jsxs("div",{onClick:Q,className:"cursor-pointer group relative overflow-hidden rounded-lg hover:border-oai-gray-350 dark:hover:border-oai-gray-700 border border-transparent transition-all",title:h("heatmap.3d.hover_tip"),children:[o.jsx(mr,{weeks:de,isDark:s,palette:D}),o.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-oai-gray-900/5 to-transparent pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity flex items-end justify-center pb-2",children:o.jsxs("span",{className:"text-[10px] bg-white/95 dark:bg-oai-gray-900/95 shadow border border-oai-gray-200/60 dark:border-oai-gray-800/80 px-2.5 py-1 rounded-full font-medium text-oai-gray-500 dark:text-oai-gray-400 flex items-center gap-1 transform translate-y-2 group-hover:translate-y-0 transition-transform duration-200",children:[o.jsx(pl,{size:9}),h("heatmap.3d.hover_tip")]})})]}),Y==="2d"&&o.jsx("div",{ref:l,className:"overflow-x-auto overflow-y-hidden heatmap-scroll-thin",children:o.jsxs("div",{style:{minWidth:me},children:[o.jsxs("div",{className:"grid text-[10px] uppercase text-oai-gray-400 dark:text-oai-gray-400 mb-1",style:{gridTemplateColumns:`${Qn}px repeat(${de.length}, ${Ct}px)`,columnGap:tn},children:[o.jsx("span",{}),ue.map(T=>o.jsx("span",{style:{gridColumnStart:T.index+2},className:"whitespace-nowrap",children:T.label},`${T.label}-${T.index}`))]}),o.jsxs("div",{className:"grid",style:{gridTemplateColumns:`${Qn}px repeat(${de.length}, ${Ct}px)`,columnGap:tn},children:[o.jsx("div",{className:"grid text-[10px] text-oai-gray-400 dark:text-oai-gray-400 sticky left-0 bg-white dark:bg-oai-gray-900 pr-2",style:{gridTemplateRows:`repeat(7, ${Ct}px)`,rowGap:tn},children:V.map(T=>o.jsx("span",{className:"leading-none",children:T},T))}),o.jsx("div",{className:"grid",style:{gridAutoFlow:"column",gridTemplateRows:`repeat(7, ${Ct}px)`,gap:tn},children:de.map((T,oe)=>(Array.isArray(T)?T:[]).map((pe,fe)=>{if(!pe)return null;const le=pe.day||`e-${oe}-${fe}`,he=Number(pe.level)||0,Pe=i[he]||i[0];return o.jsx("span",{onMouseEnter:De=>N(De,pe),onMouseLeave:O,className:"rounded-[2px] transition-transform hover:scale-125 hover:z-10 cursor-pointer",style:{width:Ct,height:Ct,background:Pe}},le)}))})]})]})}),!a&&o.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[o.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:h("heatmap.legend.less")}),o.jsx("div",{className:"flex gap-0.5",children:i.map((T,oe)=>o.jsx("span",{className:"rounded-[1px]",style:{width:10,height:10,background:T}},oe))}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:h("heatmap.legend.more")})]}),x&&o.jsx("div",{onAnimationEnd:L,onClick:T=>{T.target===T.currentTarget&&j()},className:`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 ${b?"animate-tt-fade-out":"animate-tt-fade-in"}`,children:o.jsxs("div",{className:`relative w-full max-w-6xl 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 ${b?"animate-tt-modal-exit":"animate-tt-modal"}`,children:[o.jsx("button",{type:"button",onClick:j,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 transition-all duration-300",children:o.jsx(ao,{size:16})}),o.jsxs("div",{className:"w-full md:w-[340px] 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-6 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[o.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[o.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:M.rawColor}}),o.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:M.rawColor}})]}),o.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:"3D Insight"})]}),o.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-none mt-2 select-none",children:h("heatmap.3d.modal.title")}),o.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-400 dark:text-zinc-500 mt-2 font-normal select-none",children:h("heatmap.3d.modal.desc")})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-y border-zinc-200/50 dark:border-zinc-800/50 py-5 select-none",children:[o.jsxs("div",{className:"flex flex-col gap-1 relative group cursor-help",children:[o.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:o.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[o.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:h("heatmap.3d.modal.stats.precision_total_tokens")}),o.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[W.totalTokens.toLocaleString()," Tokens"]})]})}),o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.total_tokens")}),o.jsxs("div",{className:"flex items-baseline gap-1.5",children:[o.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:hr(W.totalTokens)}),o.jsx("div",{className:"opacity-30 group-hover:opacity-60 transition-opacity",children:o.jsx("svg",{width:"24",height:"10",viewBox:"0 0 24 10",fill:"none",children:o.jsx("path",{d:"M1 9C3 7 5 7 7 4C9 1 11 0 13 2C15 4 17 0 23 0",stroke:M.rawColor,strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.estimated_cost")}),o.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:"$"+W.totalCostUsd.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.active_rate_days")}),o.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.activeRate,"% ",o.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",W.activeDays,"D)"]})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.max_streak")}),o.jsxs("span",{className:"text-xl font-black text-amber-500 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.maxStreak," ",o.jsx("span",{className:"text-[10px] font-bold text-amber-500/80 font-mono",children:h("heatmap.3d.modal.stats.days_suffix")})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 col-span-2 relative group cursor-help",children:[o.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:o.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[o.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:h("heatmap.3d.modal.stats.precision_peak_value")}),o.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[W.maxSingleDay.value>0?W.maxSingleDay.value.toLocaleString():h("heatmap.3d.modal.stats.no_data")," Tokens"]}),o.jsx("span",{className:"text-[8px] text-zinc-400 dark:text-zinc-500 mt-0.5",children:W.maxSingleDay.day!=="无数据"?W.maxSingleDay.day:h("heatmap.3d.modal.stats.no_data")})]})}),o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.peak_day")}),o.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.maxSingleDay.value>0?hr(W.maxSingleDay.value):h("heatmap.3d.modal.stats.no_data")," ",o.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",W.maxSingleDay.day!=="无数据"?W.maxSingleDay.day:h("heatmap.3d.modal.stats.no_data"),")"]})]})]})]}),o.jsxs("div",{className:"flex flex-col gap-2.5 py-1",children:[o.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[o.jsx(Ml,{size:11,style:{color:M.rawColor}}),o.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono",style:{color:M.rawColor},children:h(W.aiEvaluationTitleKey)})]}),o.jsxs("div",{className:"pl-3.5 border-l-2 relative transition-all duration-300 group",style:{borderColor:M.rawColor},children:[o.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px] blur-[2px] opacity-15 pointer-events-none rounded-full",style:{backgroundColor:M.rawColor}}),o.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-600 dark:text-zinc-400 font-normal",children:h(W.aiEvaluationKey)})]})]}),o.jsx("div",{className:"mt-auto border-t border-zinc-200/50 dark:border-zinc-800/50 pt-4 select-none",children:o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.legend.title")}),o.jsx("span",{className:"text-[10px] font-medium text-zinc-500 dark:text-zinc-400",children:h(`heatmap.3d.modal.palette.${D}`)})]}),o.jsx("div",{className:"flex gap-1",children:Z.map((T,oe)=>o.jsx("div",{className:"flex-1 h-1 rounded-[2px]",style:{backgroundColor:T},title:`Level ${oe}`},oe))})]})})]}),o.jsxs("div",{className:"flex-1 h-full relative flex items-center justify-center overflow-hidden p-4",children:[o.jsx("div",{className:"absolute top-1/4 left-1/3 w-96 h-96 rounded-full blur-[130px] pointer-events-none -translate-x-1/2 -translate-y-1/2 transition-all duration-500",style:{backgroundColor:M.rawColor+"15"}}),o.jsx("div",{className:"absolute bottom-1/4 right-1/3 w-80 h-80 rounded-full blur-[120px] pointer-events-none translate-x-1/2 translate-y-1/2 bg-purple-500/[0.04] dark:bg-purple-500/[0.08]"}),o.jsxs("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 flex items-center gap-3 p-1.5 backdrop-blur-md bg-white/70 dark:bg-oai-gray-900/75 border border-oai-gray-200/60 dark:border-oai-gray-800/80 rounded-full shadow-lg z-30 select-none",children:[o.jsx("div",{className:"flex items-center gap-1.5 px-2",children:Object.keys(B).map(T=>{const oe=D===T;return o.jsx("button",{type:"button",onClick:()=>S(T),title:h(`heatmap.3d.modal.palette.${T}`),className:`w-3.5 h-3.5 rounded-full transition-all duration-200 relative hover:scale-125 ${T==="emerald"?"bg-[#10b981]":T==="ocean"?"bg-[#3b82f6]":T==="neon"?"bg-[#a855f7]":"bg-[#f59e0b]"}`,children:oe&&o.jsx("span",{className:"absolute inset-0 rounded-full ring-2 ring-offset-1 ring-offset-white dark:ring-offset-oai-gray-900 ring-oai-gray-900 dark:ring-white scale-110"})},T)})}),o.jsx("div",{className:"w-[1px] h-4 bg-oai-gray-200 dark:bg-oai-gray-800"}),o.jsxs("div",{className:"flex items-center gap-1 pr-1",children:[o.jsx("button",{type:"button",onClick:()=>{const T=!v;w(T),C.current&&C.current.toggleAutoRotate(T)},title:v?h("heatmap.3d.modal.control.pause"):h("heatmap.3d.modal.control.play"),className:`p-1.5 rounded-full transition-all duration-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 ${v?M.accentText:"text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250"}`,children:v?o.jsx(bl,{size:12}):o.jsx(wl,{size:12})}),o.jsx("button",{type:"button",onClick:()=>{w(!1),C.current&&C.current.reset()},title:h("heatmap.3d.modal.control.reset"),className:"p-1.5 rounded-full text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-all duration-200",children:o.jsx(_l,{size:12})})]})]}),o.jsx(mr,{weeks:de,isDark:s,interactive:!0,palette:D,autoRotateInit:v,onResetViewRef:C}),o.jsxs("div",{className:"absolute bottom-4 right-4 flex items-center gap-1.5 text-[9px] font-bold text-oai-gray-400 bg-white/80 dark:bg-oai-gray-900/80 border border-oai-gray-200/50 dark:border-oai-gray-800/80 rounded-md px-2.5 py-1.5 select-none pointer-events-none backdrop-blur-md shadow-sm",children:[o.jsx(va,{size:10,className:M.accentText}),o.jsx("span",{children:h("heatmap.3d.modal.footer.tip")})]})]})]})}),d&&!x&&o.jsxs("div",{onMouseEnter:E,onMouseLeave:F,className:"absolute z-[9999] w-0 h-0 transition-all duration-100 ease-out",style:{left:`${u.x}px`,top:`${u.y}px`},children:[o.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/95 dark:bg-oai-gray-900/95 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${u.shiftX}px))`},children:[o.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:d.day}),(()=>{const T=d.level===0?s?"#9ca3af":"#6b7280":i[d.level];return o.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:T+"22",color:T,border:`1px solid ${T}44`},children:["Level ",d.level]})})()]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-baseline gap-1",children:[o.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none",children:Number(d.total_tokens??d.value).toLocaleString()}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Tokens"})]}),d.models&&Object.keys(d.models).length>0?o.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[o.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),o.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 scrollbar-thin",children:Object.entries(d.models).map(([T,oe])=>({name:T,val:Number(oe)})).sort((T,oe)=>oe.val-T.val).map(({name:T,val:oe})=>{const pe=Number(d.total_tokens??d.value)||1,fe=Math.round(oe/pe*100);return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[o.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:T,children:T}),o.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[o.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:oe.toLocaleString()}),o.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[fe,"%"]})]})]}),o.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${fe}%`,backgroundColor:i[4],boxShadow:`0 0 4px ${i[4]}55`}})})]},T)})})]}):o.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:po(d.level,d.total_tokens??d.value)})]})]}),o.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]}),o.jsx("style",{children:`
1
+ import{c as Kt,i as Mi,f as Jr,a as Zr,J as Ci,u as eo,m as Di,r as m,M as to,b as Ti,d as Ai,e as Yn,g as Oi,h as It,j as Xt,k as Pt,l as Ei,n as fa,o as bn,p as ba,q as Cn,s as Fi,t as Wi,v as Pi,w as ka,x as qt,y as zn,z as Ii,A as ze,B as h,C as o,D as no,X as ao,E as He,L as Li,F as $e,R as $,G as Dn,H as jn,I as $i,K as ro,N as oo,O as wa,P as Ri,Q as so,_ as io,S as ma,T as Bi,U as Yi,V as zi,W as Hi,Y as Ui,Z as qi,$ as Gi,a0 as Vi,a1 as Ki,a2 as Xi,a3 as dt,a4 as sr}from"./main-Csid8osN.js";import{u as Qi}from"./use-usage-limits-DIE-GP0H.js";import{I as va,u as Ji,a as Zi,b as el,c as tl,d as nl,D as al,e as rl,f as ol,g as sl,h as il,i as ll,C as cl,P as dl,j as ul,k as fl,l as ml,m as hl,L as gl}from"./PopoverPopup-Cyf_sjKX.js";import{C as _a}from"./Card-DdDoM-Gd.js";import{u as Na}from"./use-reduced-motion-CPJKbom2.js";import{P as lo}from"./ProviderIcon-Dqb9ThUH.js";import{F as Yt}from"./FadeIn-CoY8tCtI.js";const yl=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],pl=Kt("maximize-2",yl);const xl=[["rect",{x:"14",y:"3",width:"5",height:"18",rx:"1",key:"kaeet6"}],["rect",{x:"5",y:"3",width:"5",height:"18",rx:"1",key:"1wsw3u"}]],bl=Kt("pause",xl);const kl=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],wl=Kt("play",kl);const vl=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],_l=Kt("rotate-ccw",vl);const Nl=[["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"}]],jl=Kt("square-arrow-out-up-right",Nl);const Sl=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],Ml=Kt("terminal",Sl);function Cl(...e){const t=!Array.isArray(e[0]),n=t?0:-1,a=e[0+n],r=e[1+n],s=e[2+n],i=e[3+n],l=Mi(r,s,i);return t?l(a):l}function Dl(e,t,n={}){const a=e.get();let r=null,s=a,i;const l=typeof a=="string"?a.replace(/[\d.-]/g,""):void 0,c=()=>{r&&(r.stop(),r=null),e.animation=void 0},d=()=>{const u=ir(e.get()),y=ir(s);if(u===y){c();return}const g=r?r.getGeneratorVelocity():e.getVelocity();c(),r=new Ci({keyframes:[u,y],velocity:g,type:"spring",restDelta:.001,restSpeed:.01,...n,onUpdate:i})},f=()=>{d(),e.animation=r??void 0,e.events.animationStart?.notify(),r?.then(()=>{e.animation=void 0,e.events.animationComplete?.notify()})};if(e.attach((u,y)=>{s=u,i=g=>y(Hn(g,l)),Jr.postRender(f)},c),Zr(t)){let u=n.skipInitialAnimation===!0;const y=t.on("change",x=>{u?(u=!1,e.jump(Hn(x,l),!1)):e.set(Hn(x,l))}),g=e.on("destroy",y);return()=>{y(),g()}}return c}function Hn(e,t){return t?e+t:e}function ir(e){return typeof e=="number"?e:parseFloat(e)}function ja(e){const t=eo(()=>Di(e)),{isStatic:n}=m.useContext(to);if(n){const[,a]=m.useState(e);m.useEffect(()=>t.on("change",a),[])}return t}function co(e,t){const n=ja(t()),a=()=>n.set(t());return a(),Ti(()=>{const r=()=>Jr.preRender(a,!1,!0),s=e.map(i=>i.on("change",r));return()=>{s.forEach(i=>i()),Ai(a)}}),n}function Tl(e){Yn.current=[],e();const t=co(Yn.current,e);return Yn.current=void 0,t}function uo(e,t,n,a){if(typeof e=="function")return Tl(e);const s=typeof t=="function"?t:Cl(t,n,a),i=Array.isArray(e)?lr(e,s):lr([e],([c])=>s(c)),l=Array.isArray(e)?void 0:e.accelerate;return l&&!l.isTransformed&&typeof t!="function"&&Array.isArray(n)&&a?.clamp!==!1&&(i.accelerate={...l,times:t,keyframes:n,isTransformed:!0}),i}function lr(e,t){const n=eo(()=>[]);return co(e,()=>{n.length=0;const a=e.length;for(let r=0;r<a;r++)n[r]=e[r].get();return t(n)})}function Al(e,t={}){const{isStatic:n}=m.useContext(to),a=()=>Zr(e)?e.get():e;if(n)return uo(a);const r=ja(a());return m.useInsertionEffect(()=>Dl(r,e,t),[r,JSON.stringify(t)]),r}function Ol(e,t={}){return Al(e,{type:"spring",...t})}function El({baseUrl:e,accessToken:t,guestAllowed:n=!1,weeks:a=52,weekStartsOn:r="sun",cacheKey:s,timeZone:i,tzOffsetMinutes:l,now:c}={}){const d=m.useMemo(()=>Oi({weeks:a,weekStartsOn:r,now:c}),[c,a,r]),[f,u]=m.useState([]),[y,g]=m.useState(null),[x,p]=m.useState("edge"),[b,k]=m.useState(!1),[v,w]=m.useState(null),C=It(),D=Xt(t),S=!n,I=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),N=m.useMemo(()=>{if(!s)return null;const L=Cn({timeZone:i,offsetMinutes:l});return`tokentracker.heatmap.${s}.${a}.${r}.${L}`},[s,i,l,a,r]),O=m.useCallback(()=>{if(!N||typeof window>"u")return null;try{const L=window.localStorage.getItem(N);if(!L)return null;const B=JSON.parse(L);return!B||!B.heatmap?null:B}catch{return null}},[N]),E=m.useCallback(L=>{if(!(!N||typeof window>"u"))try{window.localStorage.setItem(N,JSON.stringify(L))}catch{}},[N]),F=m.useCallback(()=>{if(!(!N||typeof window>"u"))try{window.localStorage.removeItem(N)}catch{}},[N]),Q=m.useCallback(async()=>{const L=await Pt(t);if(!(!L&&!C&&!I)){k(!0),w(null);try{try{const Y=await Ei({baseUrl:e,accessToken:L,weeks:a,to:d.to,weekStartsOn:r,timeZone:i,tzOffsetMinutes:l}),P=Array.isArray(Y?.weeks)?Y.weeks:[];if(!P.length&&S){const G=O();if(G?.heatmap){g(G.heatmap),u(G.daily||[]),p("cache");return}}if(!P.some(G=>(Array.isArray(G)?G:[]).some(de=>de&&Number.isFinite(Number(de.level))))&&P.length){const G=[];for(const W of P)for(const V of Array.isArray(W)?W:[])V?.day&&G.push({day:V.day,total_tokens:V.total_tokens??V.value??0,billable_total_tokens:V.billable_total_tokens??V.value??V.total_tokens??0});const de=fa({dailyRows:G,weeks:a,to:Y?.to||d.to,weekStartsOn:r});u(G),g({...de,week_starts_on:r,active_days:G.filter(W=>Number(W?.billable_total_tokens??W?.total_tokens)>0).length,streak_days:bn({dailyRows:G,to:Y?.to||d.to})}),p("client"),S?E({heatmap:{...de,week_starts_on:r,active_days:G.filter(W=>Number(W?.billable_total_tokens??W?.total_tokens)>0).length,streak_days:bn({dailyRows:G,to:Y?.to||d.to})},daily:G,fetchedAt:new Date().toISOString()}):F();return}g(Y||null),u([]),p("edge"),Y&&S?E({heatmap:Y,daily:[],fetchedAt:new Date().toISOString()}):S||F();return}catch(Y){const P=Y,z=P?.status??P?.statusCode;if(z===401||z===403)throw Y}const B=await ba({baseUrl:e,accessToken:L,from:d.from,to:d.to,timeZone:i,tzOffsetMinutes:l}),M=Array.isArray(B?.data)?B.data:[];u(M);const Z=fa({dailyRows:M,weeks:a,to:d.to,weekStartsOn:r});g({...Z,week_starts_on:r,active_days:M.filter(Y=>Number(Y?.billable_total_tokens??Y?.total_tokens)>0).length,streak_days:bn({dailyRows:M,to:d.to})}),p("client"),S?E({heatmap:{...Z,week_starts_on:r,active_days:M.filter(Y=>Number(Y?.billable_total_tokens??Y?.total_tokens)>0).length,streak_days:bn({dailyRows:M,to:d.to})},daily:M,fetchedAt:new Date().toISOString()}):F()}catch(B){if(S){const M=O();if(M?.heatmap)g(M.heatmap),u(M.daily||[]),p("cache"),w(null);else{const Z=B;w(Z?.message||String(Z)),u([]),g(null),p("edge")}}else{const M=B;w(M?.message||String(M)),u([]),g(null),p("edge")}}finally{k(!1)}}},[t,e,C,n,S,d.from,d.to,O,D,i,l,r,a,F,E,I]);return m.useEffect(()=>{if(!D&&!n&&!C&&!I){u([]),k(!1),w(null),g(null),p("edge");return}if(!S)F(),u([]),w(null),g(null),p("edge");else{const L=O();L?.heatmap&&(g(L.heatmap),u(L.daily||[]),p("cache"))}Q()},[t,C,O,Q,D,n,S,F,I]),{range:d,daily:f,heatmap:y,source:C?"mock":x==="client"?"edge":x,loading:b,error:v,refresh:Q}}function Fl({baseUrl:e,accessToken:t,limit:n=3,from:a,to:r,source:s,timeZone:i,tzOffsetMinutes:l}={}){const[c,d]=m.useState([]),[f,u]=m.useState(!1),[y,g]=m.useState(null),x=It(),p=Xt(t),b=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),k=m.useCallback(async()=>{const v=await Pt(t);if(!v&&!x&&!b){d([]),g(null),u(!1);return}u(!0),g(null);try{const w=await Fi({baseUrl:e,accessToken:v,limit:n,from:a,to:r,source:s,timeZone:i,tzOffsetMinutes:l});d(Array.isArray(w?.entries)?w.entries:[])}catch(w){const C=w?.message||String(w);g(C),d([])}finally{u(!1)}},[t,e,a,n,x,s,i,r,l,b]);return m.useEffect(()=>{if(!p&&!x&&!b){d([]),g(null),u(!1);return}k()},[x,k,p,b]),{entries:c,loading:f,error:y,refresh:k}}const Wl=24;function Pl({baseUrl:e,accessToken:t,guestAllowed:n=!1,period:a,from:r,to:s,months:i=Wl,cacheKey:l,timeZone:c,tzOffsetMinutes:d,now:f,sharedRows:u,sharedRange:y}={}){const[g,x]=m.useState([]),[p,b]=m.useState(()=>({from:r,to:s})),[k,v]=m.useState("edge"),[w,C]=m.useState(null),[D,S]=m.useState(!1),[I,N]=m.useState(null),O=It(),E=Xt(t),F=!n,Q=Array.isArray(u),j=y?.from||r,L=y?.to||s,B=m.useMemo(()=>a==="day"?"hourly":a==="total"?"monthly":"daily",[a]),M=(()=>{if(!l)return null;const W=Il(e)||"default",V=Cn({timeZone:c,offsetMinutes:d});if(B==="hourly")return`tokentracker.trend.${l}.${W}.hourly.${s||r||"day"}.${V}`;if(B==="monthly")return`tokentracker.trend.${l}.${W}.monthly.${i}.${s||"today"}.${V}`;const ue=`${r||""}.${s||""}`;return`tokentracker.trend.${l}.${W}.daily.${ue}.${V}`})(),Z=m.useCallback(()=>{if(!M||typeof window>"u")return null;try{const W=window.localStorage.getItem(M);if(!W)return null;const V=JSON.parse(W);return!V||!Array.isArray(V.rows)?null:V}catch{return null}},[M]),Y=m.useCallback(W=>{if(!(!M||typeof window>"u"))try{window.localStorage.setItem(M,JSON.stringify(W))}catch{}},[M]),P=m.useCallback(()=>{if(!(!M||typeof window>"u"))try{window.localStorage.removeItem(M)}catch{}},[M]),z=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),G=m.useCallback(async()=>{if(Q){x(Array.isArray(u)?u:[]),b({from:j,to:L}),v("shared"),C(null),S(!1),N(null);return}const W=await Pt(t);if(!(!W&&!O&&!z)){S(!0),N(null);try{let V;B==="hourly"?V=await Wi({baseUrl:e,accessToken:W,day:s||r,timeZone:c,tzOffsetMinutes:d}):B==="monthly"?V=await Pi({baseUrl:e,accessToken:W,months:i,to:s,timeZone:c,tzOffsetMinutes:d}):V=await ba({baseUrl:e,accessToken:W,from:r,to:s,timeZone:c,tzOffsetMinutes:d});const ue=V?.from||r||V?.day||null,me=V?.to||s||V?.day||null;let T=Array.isArray(V?.data)?V.data:[];B==="daily"?T=qn(T,ue||r,me||s,{timeZone:c,offsetMinutes:d,now:f}):B==="hourly"?T=Gn(T,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(T=Vn(T,{timeZone:c,offsetMinutes:d,now:f}));const oe=new Date().toISOString();x(T),b({from:ue,to:me}),v("edge"),C(oe),F?Y({rows:T,from:ue,to:me,mode:B,fetchedAt:oe}):P()}catch(V){if(F){const ue=Z();if(ue?.rows){let me=B==="daily"?qn(ue.rows||[],ue.from||r,ue.to||s,{timeZone:c,offsetMinutes:d,now:f}):Array.isArray(ue.rows)?ue.rows:[];B==="hourly"?me=Gn(me,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(me=Vn(me,{timeZone:c,offsetMinutes:d,now:f})),x(me),b({from:ue.from||r,to:ue.to||s}),v("cache"),C(ue.fetchedAt||null),N(null)}else{x([]),b({from:r,to:s}),v("edge"),C(null);const me=V;N(me?.message||String(me))}}else{x([]),b({from:r,to:s}),v("edge"),C(null);const ue=V;N(ue?.message||String(ue))}}finally{S(!1)}}},[t,e,r,O,n,F,B,i,Z,E,Q,j,u,L,c,s,d,f,P,Y,z]);m.useEffect(()=>{if(Q){x(Array.isArray(u)?u:[]),b({from:j,to:L}),v("shared"),C(null),S(!1),N(null);return}if(!E&&!n&&!O&&!z){x([]),b({from:r,to:s}),N(null),S(!1),v("edge"),C(null);return}if(!F)P(),x([]),b({from:r,to:s}),N(null),v("edge"),C(null);else{const W=Z();if(W?.rows){let V=B==="daily"?qn(W.rows||[],W.from||r,W.to||s,{timeZone:c,offsetMinutes:d,now:f}):Array.isArray(W.rows)?W.rows:[];B==="hourly"?V=Gn(V,{timeZone:c,offsetMinutes:d,now:f}):B==="monthly"&&(V=Vn(V,{timeZone:c,offsetMinutes:d,now:f})),x(V),b({from:W.from||r,to:W.to||s}),v("cache"),C(W.fetchedAt||null)}}G()},[t,O,Z,G,Q,j,u,L,E,n,F,P,z]);const de=O?"mock":k;return{rows:g,from:p.from||r,to:p.to||s,source:de,fetchedAt:w,loading:D,error:I,refresh:G}}function Il(e){try{return new URL(e).host}catch{return null}}function Un(e){if(!e)return null;const t=String(e).trim(),n=t.split("-");if(n.length!==3)return null;const a=Number(n[0]),r=Number(n[1])-1,s=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r,s));return Number.isFinite(i.getTime())&&qt(i)===t?i:null}function Ll(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function qn(e,t,n,{timeZone:a,offsetMinutes:r,now:s}={}){const i=Un(t),l=Un(n);if(!i||!l||l<i)return Array.isArray(e)?e:[];const c=s instanceof Date&&Number.isFinite(s.getTime())?s:new Date,d=ka({timeZone:a,offsetMinutes:r,date:c}),f=Un(d),u=f?f.getTime():c.getTime(),y=new Map;for(const x of e||[])x?.day&&y.set(x.day,x);const g=[];for(let x=i;x<=l;x=Ll(x,1)){const p=qt(x),b=y.get(p),k=x.getTime()>u;if(b){g.push({...b,missing:!1,future:k});continue}g.push({day:p,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!k,future:k})}return g}function Gn(e,{timeZone:t,offsetMinutes:n,now:a}={}){if(!Array.isArray(e))return[];const r=fo({timeZone:t,offsetMinutes:n,now:a});return r?e.map(s=>{const i=s?.hour||s?.label||"",l=$l(i);if(!l)return{...s,future:!1};const c=l.dayNum>r.dayNum||l.dayNum===r.dayNum&&l.slot>r.slot;return{...s,future:c}}):e}function Vn(e,{timeZone:t,offsetMinutes:n,now:a}={}){if(!Array.isArray(e))return[];const r=fo({timeZone:t,offsetMinutes:n,now:a});return r?e.map(s=>{const i=s?.month||s?.label||"",l=Rl(i);if(!l)return{...s,future:!1};const c=l.year>r.year||l.year===r.year&&l.month>r.month;return{...s,future:c}}):e}function fo({timeZone:e,offsetMinutes:t,now:n}={}){const a=n instanceof Date&&Number.isFinite(n.getTime())?n:new Date;if(e&&typeof Intl<"u"&&Intl.DateTimeFormat)try{const y=new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(a).reduce((v,w)=>(w.type&&w.value&&(v[w.type]=w.value),v),{}),g=Number(y.year),x=Number(y.month),p=Number(y.day),b=Number(y.hour),k=Number(y.minute);if(Number.isFinite(g)&&Number.isFinite(x)&&Number.isFinite(p)&&Number.isFinite(b)&&Number.isFinite(k)){const v=b*2+(k>=30?1:0);return{year:g,month:x,day:p,hour:b,minute:k,dayNum:g*1e4+x*100+p,slot:v}}}catch{}if(Number.isFinite(t)){const f=new Date(a.getTime()+t*60*1e3),u=f.getUTCFullYear(),y=f.getUTCMonth()+1,g=f.getUTCDate(),x=f.getUTCHours(),p=f.getUTCMinutes(),b=x*2+(p>=30?1:0);return{year:u,month:y,day:g,hour:x,minute:p,dayNum:u*1e4+y*100+g,slot:b}}const r=a.getFullYear(),s=a.getMonth()+1,i=a.getDate(),l=a.getHours(),c=a.getMinutes(),d=l*2+(c>=30?1:0);return{year:r,month:s,day:i,hour:l,minute:c,dayNum:r*1e4+s*100+i,slot:d}}function $l(e){if(!e)return null;const t=String(e).trim(),[n,a]=t.split("T");if(!n||!a)return null;const r=n.split("-");if(r.length!==3)return null;const s=Number(r[0]),i=Number(r[1]),l=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(l))return null;const c=a.split(":"),d=Number(c[0]),f=Number(c[1]);if(!Number.isFinite(d)||d<0||d>23||!Number.isFinite(f)||f<0||f>59)return null;const u=d*2+(f>=30?1:0);return{dayNum:s*1e4+i*100+l,slot:u}}function Rl(e){if(!e)return null;const n=String(e).trim().split("-");if(n.length!==2)return null;const a=Number(n[0]),r=Number(n[1]);return!Number.isFinite(a)||!Number.isFinite(r)||r<1||r>12?null:{year:a,month:r}}function cr({baseUrl:e,accessToken:t,guestAllowed:n=!1,from:a,to:r,includeDaily:s=!0,cacheKey:i,timeZone:l,tzOffsetMinutes:c,now:d}={}){const[f,u]=m.useState([]),[y,g]=m.useState(null),[x,p]=m.useState(null),[b,k]=m.useState("edge"),[v,w]=m.useState(null),[C,D]=m.useState(!1),[S,I]=m.useState(null),N=It(),O=Xt(t),E=!n,F=(()=>{if(!i)return null;const Y=Bl(e)||"default",P=s?"daily":"summary",z=Cn({timeZone:l,offsetMinutes:c});return`tokentracker.usage.${i}.${Y}.${a}.${r}.${P}.${z}`})(),Q=m.useCallback(()=>{if(!F||typeof window>"u")return null;try{const Y=window.localStorage.getItem(F);if(!Y)return null;const P=JSON.parse(Y);return!P||!P.summary?null:P}catch{return null}},[F]),j=m.useCallback(Y=>{if(!(!F||typeof window>"u"))try{window.localStorage.setItem(F,JSON.stringify(Y))}catch{}},[F]),L=m.useCallback(()=>{if(!(!F||typeof window>"u"))try{window.localStorage.removeItem(F)}catch{}},[F]),B=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),M=m.useCallback(async()=>{const Y=await Pt(t);if(!(!Y&&!N&&!B)){D(!0),I(null);try{let P=null,z=null;if(s){const[ue,me]=await Promise.allSettled([ba({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c}),zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0})]);if(ue.status==="rejected")throw ue.reason;P=ue.value,z=me.status==="fulfilled"?me.value:null}else z=await zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0});let G=s&&Array.isArray(P?.data)?P.data:[];s&&(G=Xn(G,a,r,{timeZone:l,offsetMinutes:c,now:d}));let de=z?.totals||P?.summary?.totals||null,W=z?.rolling||P?.summary?.rolling||null;if(s&&!de&&!z)try{const ue=await zn({baseUrl:e,accessToken:Y,from:a,to:r,timeZone:l,tzOffsetMinutes:c,rolling:!0});de=ue?.totals||null,W=ue?.rolling||W}catch{}const V=new Date().toISOString();u(G),g(de),p(W),k("edge"),w(V),de&&E?j({summary:de,rolling:W,daily:G,from:a,to:r,includeDaily:s,fetchedAt:V}):E||L()}catch(P){if(E){const z=Q();if(z?.summary){g(z.summary),p(z.rolling||null);const G=Array.isArray(z.daily)?z.daily:[],de=s?Xn(G,z.from||a,z.to||r,{timeZone:l,offsetMinutes:c,now:d}):G;u(de),k("cache"),w(z.fetchedAt||null),I(null)}else{const G=P;I(G?.message||String(G)),u([]),g(null),p(null),k("edge"),w(null)}}else{const z=P;I(z?.message||String(z)),u([]),g(null),p(null),k("edge"),w(null)}}finally{D(!1)}}},[t,e,a,s,N,n,E,d,Q,O,l,r,c,L,j,B]);return m.useEffect(()=>{const Y=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!O&&!n&&!N&&!Y){u([]),g(null),p(null),I(null),D(!1),k("edge"),w(null);return}if(!E)L(),u([]),g(null),p(null),I(null),k("edge"),w(null);else{const P=Q();if(P?.summary){g(P.summary),p(P.rolling||null);const z=Array.isArray(P.daily)?P.daily:[],G=s?Xn(z,P.from||a,P.to||r,{timeZone:l,offsetMinutes:c,now:d}):z;u(G),k("cache"),w(P.fetchedAt||null)}}M()},[t,N,Q,M,O,n,E,L,B]),{daily:f,summary:y,rolling:x,source:N?"mock":b,fetchedAt:v,loading:C,error:S,refresh:M}}function Bl(e){try{return new URL(e).host}catch{return null}}function Kn(e){if(!e)return null;const t=String(e).trim(),n=t.split("-");if(n.length!==3)return null;const a=Number(n[0]),r=Number(n[1])-1,s=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r,s));return Number.isFinite(i.getTime())&&qt(i)===t?i:null}function Yl(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function Xn(e,t,n,{timeZone:a,offsetMinutes:r,now:s}={}){const i=Kn(t),l=Kn(n);if(!i||!l||l<i)return Array.isArray(e)?e:[];const c=s instanceof Date&&Number.isFinite(s.getTime())?s:new Date,d=ka({timeZone:a,offsetMinutes:r,date:c}),f=Kn(d),u=f?f.getTime():c.getTime(),y=new Map;for(const x of e||[])x?.day&&y.set(x.day,x);const g=[];for(let x=i;x<=l;x=Yl(x,1)){const p=qt(x),b=y.get(p),k=x.getTime()>u;if(b){g.push({...b,missing:!1,future:k});continue}g.push({day:p,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!k,future:k})}return g}function zl({baseUrl:e,accessToken:t,guestAllowed:n=!1,from:a,to:r,cacheKey:s,timeZone:i,tzOffsetMinutes:l}={}){const[c,d]=m.useState(null),[f,u]=m.useState("edge"),[y,g]=m.useState(!1),[x,p]=m.useState(null),b=It(),k=Xt(t),v=!n,w=m.useMemo(()=>{if(!s)return null;const E=Hl(e)||"default",F=Cn({timeZone:i,offsetMinutes:l});return`tokentracker.modelBreakdown.${s}.${E}.${a}.${r}.${F}`},[e,s,a,i,r,l]),C=m.useCallback(()=>{if(!w||typeof window>"u")return null;try{const E=window.localStorage.getItem(w);if(!E)return null;const F=JSON.parse(E);return!F||!F.breakdown?null:F}catch{return null}},[w]),D=m.useCallback(E=>{if(!(!w||typeof window>"u"))try{window.localStorage.setItem(w,JSON.stringify(E))}catch{}},[w]),S=m.useCallback(()=>{if(!(!w||typeof window>"u"))try{window.localStorage.removeItem(w)}catch{}},[w]),I=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),N=m.useCallback(async()=>{const E=await Pt(t);if(!(!E&&!b&&!I)){g(!0),p(null);try{const F=await Ii({baseUrl:e,accessToken:E,from:a,to:r,timeZone:i,tzOffsetMinutes:l});d(F||null),u("edge"),F&&v?D({breakdown:F,fetchedAt:new Date().toISOString()}):v||S()}catch(F){if(v){const Q=C();if(Q?.breakdown)d(Q.breakdown),u("cache"),p(null);else{d(null),u("edge");const j=F;p(j?.message||String(j))}}else{d(null),u("edge");const Q=F;p(Q?.message||String(Q))}}finally{g(!1)}}},[t,e,a,b,n,v,C,i,r,k,l,S,D,I]);return m.useEffect(()=>{if(!k&&!n&&!b&&!I){d(null),u("edge"),p(null),g(!1);return}if(!v)S(),d(null),u("edge"),p(null);else{const E=C();E?.breakdown&&(d(E.breakdown),u("cache"))}N()},[t,b,C,N,k,n,v,S,I]),{breakdown:c,source:b?"mock":f,loading:y,error:x,refresh:N}}function Hl(e){try{return new URL(e).host}catch{return null}}const mo=new Set(["day","hour","month"]);function Ul(e){return mo.has(e)}function dr(e){if(e==null)return null;const t=String(e).trim();if(!/^[0-9]+$/.test(t))return null;const n=t.replace(/^0+/,"");return n.length===0?"0":n}function ql(e,t){const n=dr(e),a=dr(t);if(n&&a)return n.length!==a.length?n.length<a.length?-1:1:n===a?0:n<a?-1:1;const r=ze(e),s=ze(t);return r==null&&s==null?0:r==null?1:s==null?-1:r===s?0:r<s?-1:1}function Gl(e,t){const n=typeof e=="string"?e:String(e||""),a=typeof t=="string"?t:String(t||"");return n===a?0:n<a?-1:1}function Vl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]),s=Number(n[3]);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s))return null;const i=new Date(Date.UTC(a,r-1,s));return!Number.isFinite(i.getTime())||i.getUTCFullYear()!==a||i.getUTCMonth()+1!==r||i.getUTCDate()!==s?null:i.getTime()}function Kl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]);if(!Number.isFinite(a)||!Number.isFinite(r)||r<1||r>12)return null;const s=new Date(Date.UTC(a,r-1,1));return Number.isFinite(s.getTime())?s.getTime():null}function Xl(e){if(!e)return null;const n=String(e).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!n)return null;const a=Number(n[1]),r=Number(n[2]),s=Number(n[3]),i=Number(n[4]),l=Number(n[5]),c=Number(n[6]||0);if(!Number.isFinite(a)||!Number.isFinite(r)||!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(l)||!Number.isFinite(c)||r<1||r>12||s<1||s>31||i<0||i>23||l<0||l>59||c<0||c>59)return null;const d=new Date(Date.UTC(a,r-1,s,i,l,c));return Number.isFinite(d.getTime())?d.getTime():null}function Ql(e,t,n){const a=n==="hour"?Xl:n==="month"?Kl:Vl,r=a(e),s=a(t);return r!=null&&s!=null?r===s?0:r<s?-1:1:Gl(e,t)}function ho(e,{key:t,dir:n}){const a=n==="asc"?1:-1,r=Array.isArray(e)?e:[],s=mo.has(t)?(l,c)=>Ql(l,c,t):ql,i=l=>t==="total_tokens"&&l?.billable_total_tokens!=null?l.billable_total_tokens:l?.[t];return r.map((l,c)=>({row:l,index:c})).sort((l,c)=>{const d=i(l.row),f=i(c.row),u=d==null,y=f==null;if(u&&y)return l.index-c.index;if(u)return 1;if(y)return-1;const g=s(d,f);return g!==0?g*a:l.index-c.index}).map(l=>l.row)}function Jl(){return[{key:"day",label:h("daily.sort.date.label"),title:h("daily.sort.date.title")},{key:"total_tokens",label:h("daily.sort.total.label"),title:h("daily.sort.total.title")},{key:"input_tokens",label:h("daily.sort.input.label"),title:h("daily.sort.input.title")},{key:"output_tokens",label:h("daily.sort.output.label"),title:h("daily.sort.output.title")},{key:"cached_input_tokens",label:h("daily.sort.cached.label"),title:h("daily.sort.cached.title")},{key:"reasoning_output_tokens",label:h("daily.sort.reasoning.label"),title:h("daily.sort.reasoning.title")},{key:"conversation_count",label:h("daily.sort.conversations.label"),title:h("daily.sort.conversations.title")}]}function ur(e){const t=Ul(e)?e:"day";return Jl().map((n,a)=>a===0?{...n,key:t}:n)}function fr(e,{key:t,dir:n}){return ho(e,{key:t,dir:n})}const Sn=12,Zl=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function ec(e){if(typeof e=="bigint")return e!==0n;if(typeof e=="number")return Number.isFinite(e)&&e!==0;if(e==null)return!1;const t=String(e).trim();if(!t||!/^-?\d+$/.test(t))return!1;const n=t.startsWith("-")?t.slice(1):t;return/[1-9]/.test(n)}function tc(e){return Zl.some(t=>ec(e?.[t]))}function nc(e){const t=Array.isArray(e)?e:[];if(!t.length)return[];const n=ho(t,{key:"month",dir:"asc"}),a=n.findIndex(r=>r?.month&&tc(r));return a===-1?t:n.slice(a)}function ac(e,t,n=Sn){const a=Array.isArray(e)?e:[],r=Number.isFinite(n)&&n>0?n:Sn,i=(Number.isFinite(t)&&t>=0?Math.floor(t):0)*r;return a.slice(i,i+r)}function rc({publicMode:e,screenshotMode:t,forceInstall:n,accessEnabled:a,heatmapLoading:r,activeDays:s,hasActiveDeviceToken:i}={}){return e||t?!1:n?!0:a&&!r&&s===0&&!i}function go(e){if(typeof e!="string")return null;const t=e.trim();return t?t.toLowerCase():null}function oc(e){const t=go(e?.model_id);return t||null}function yo(e,t){return e?.model?String(e.model):t}function Gt(e,t=0){const n=ze(e?.billable_total_tokens),a=ze(e?.total_tokens);return n!=null&&n>0?n:a!=null&&a>0?a:n??a??t}function sc(e,{copyFn:t}={}){const n=typeof t=="function"?t:i=>i,r=(Array.isArray(e?.sources)?e.sources:[]).map(i=>{const l=Gt(i?.totals),c=ze(i?.totals?.total_cost_usd)??0;return{source:i?.source,totalTokens:Number.isFinite(l)?l:0,totalCost:Number.isFinite(c)?c:0,models:Array.isArray(i?.models)?i.models:[]}}).filter(i=>i.totalTokens>0);if(!r.length)return[];const s=r.reduce((i,l)=>i+l.totalTokens,0);return typeof e?.pricing?.pricing_mode=="string"&&e.pricing.pricing_mode.toUpperCase(),r.slice().sort((i,l)=>l.totalTokens-i.totalTokens).map(i=>{const l=i.source?String(i.source).toUpperCase():n("shared.placeholder.short"),c=s>0?i.totalTokens/s*100:0,d=Number.isFinite(c)?c.toFixed(1):"0.0",f=i.models.map(u=>{const y=Gt(u?.totals);if(!Number.isFinite(y)||y<=0)return null;const g=i.totalTokens>0?Math.round(y/i.totalTokens*1e3)/10:0,x=yo(u,n("shared.placeholder.short")),p=oc(u),b=ze(u?.totals?.total_cost_usd),k=b??(i.totalCost>0&&i.totalTokens>0?y/i.totalTokens*i.totalCost:null);return{id:p,name:x,share:g,usage:y,cost:k}}).filter(Boolean);return{source:i.source,label:l,totalPercent:String(d),usd:i.totalCost,usage:i.totalTokens,models:f}})}function ic(e,{limit:t=3,copyFn:n}={}){const a=typeof n=="function"?n:y=>y,r=Array.isArray(e?.sources)?e.sources:[];if(!r.length)return[];const s=new Map,i=new Map,l=new Map;let c=0;for(const y of r){const g=Array.isArray(y?.models)?y.models:[];for(const x of g){const p=Gt(x?.totals);if(!Number.isFinite(p)||p<=0)continue;c+=p;const b=yo(x,a("shared.placeholder.short")),k=go(b);if(!k)continue;s.set(k,(s.get(k)||0)+p);const v=l.get(k)||0;p>=v&&(l.set(k,p),i.set(k,b))}}if(!s.size)return[];const d=Array.from(s.values()).reduce((y,g)=>y+g,0),f=c>0?c:d,u=Number.isFinite(t)?Math.max(0,Math.floor(t)):3;return Array.from(s.entries()).map(([y,g])=>{const x=f>0?(g/f*100).toFixed(1):"0.0";return{id:y,name:i.get(y)||a("shared.placeholder.short"),tokens:g,percent:String(x)}}).sort((y,g)=>g.tokens!==y.tokens?g.tokens-y.tokens:String(y.name).localeCompare(String(g.name))).slice(0,u)}const ft={emerald:{light:["#ebedf0","#a7f3d0","#6ee7b7","#34d399","#10b981"],dark:["#2d333b","#065f46","#059669","#10b981","#34d399"],gridColor:{light:"rgba(16, 185, 129, 0.12)",dark:"rgba(52, 211, 153, 0.08)"}},ocean:{light:["#f1f5f9","#93c5fd","#60a5fa","#3b82f6","#1d4ed8"],dark:["#1e293b","#1e3a8a","#2563eb","#3b82f6","#60a5fa"],gridColor:{light:"rgba(59, 130, 246, 0.12)",dark:"rgba(96, 165, 250, 0.08)"}},neon:{light:["#faf5ff","#ebd5ff","#c084fc","#a855f7","#7e22ce"],dark:["#2e1065","#581c87","#8b5cf6","#a855f7","#c084fc"],gridColor:{light:"rgba(168, 85, 247, 0.12)",dark:"rgba(192, 132, 252, 0.08)"}},amber:{light:["#fffbeb","#fde68a","#f59e0b","#d97706","#b45309"],dark:["#451a03","#78350f","#b45309","#d97706","#f59e0b"],gridColor:{light:"rgba(245, 158, 11, 0.12)",dark:"rgba(245, 158, 11, 0.08)"}}};function lc(e,t){const n=/^#([0-9a-f]{6})$/i.exec(e);if(!n)return e;const a=parseInt(n[1],16),r=a>>16&255,s=a>>8&255,i=a&255,l=c=>Math.max(0,Math.min(255,Math.round(c*t)));return`rgb(${l(r)}, ${l(s)}, ${l(i)})`}function Ze(e,t,n,a,r){const s=Math.cos(a),i=Math.sin(a),l=e*s-t*i,c=e*i+t*s,d=n,f=Math.cos(r),u=Math.sin(r),y=l,g=c*f-d*u,x=c*u+d*f;return{x:y,y:g,z:x}}function cc(e,t,n,a,r){return Ze(e,t,n,a,r)}function po(e,t){const n=Number(t).toLocaleString();if(e>=4){const a=Math.floor(Math.random()*3)+1;return h(`heatmap.3d.voxel.joke.${a}`,{value:n})}else return e===3?h("heatmap.3d.voxel.level3",{value:n}):e===2?h("heatmap.3d.voxel.level2",{value:n}):e===1?h("heatmap.3d.voxel.level1",{value:n}):h("heatmap.3d.voxel.level0")}function mr({weeks:e,palette:t="auto",isDark:n=!1,interactive:a=!1,autoRotateInit:r=!1,onResetViewRef:s=null}){const i=ft[t]||(t==="auto"?ft.emerald:null),l=i?n?i.dark:i.light:Array.isArray(t)?t:n?ft.emerald.dark:ft.emerald.light,c=i?n?i.gridColor.dark:i.gridColor.light:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",d=-.2,f=.88,[u,y]=m.useState({yaw:d,pitch:f}),[g,x]=m.useState(r),[p,b]=m.useState(1),k=a?13:10.5,v=m.useMemo(()=>{const A=[],R=e.length;if(R===0||!a)return[];for(let J=0;J<=7;J++){const H=(J-3.5)*k,ie=Ze(-R/2*k,H,0,u.yaw,u.pitch),se=Ze(R/2*k,H,0,u.yaw,u.pitch);A.push({d:`M${ie.x},${ie.y} L${se.x},${se.y}`,key:`horiz-${J}`})}for(let J=0;J<=R;J+=4){const H=(J-R/2)*k,ie=Ze(H,-3.5*k,0,u.yaw,u.pitch),se=Ze(H,3.5*k,0,u.yaw,u.pitch);A.push({d:`M${ie.x},${ie.y} L${se.x},${se.y}`,key:`vert-${J}`})}if(R%4!==0){const J=(R-R/2)*k,H=Ze(J,-3.5*k,0,u.yaw,u.pitch),ie=Ze(J,3.5*k,0,u.yaw,u.pitch);A.push({d:`M${H.x},${H.y} L${ie.x},${ie.y}`,key:"vert-last"})}return A},[e.length,u,k,a]);m.useEffect(()=>{s&&(s.current={reset:()=>{y({yaw:d,pitch:f}),x(!1),b(1),B()},toggleAutoRotate:A=>{x(A)}})},[s]);const w=m.useRef(null),C=m.useRef(null),D=m.useRef(!1),S=m.useRef({x:0,y:0}),I=m.useRef({yaw:d,pitch:f}),N=m.useRef({x:0,y:0}),O=m.useRef({x:0,y:0,time:0}),E=m.useRef(null),[F,Q]=m.useState(0),j=m.useRef(null),L=m.useRef(!0);m.useEffect(()=>(L.current=!0,()=>{L.current=!1}),[]);const B=()=>{j.current&&cancelAnimationFrame(j.current),Q(0);const A=performance.now(),R=1200,J=H=>{if(!L.current)return;const ie=H-A,se=Math.min(1,ie/R),xe=1-Math.pow(1-se,3);Q(xe),se<1?j.current=requestAnimationFrame(J):j.current=null};j.current=requestAnimationFrame(J)};m.useEffect(()=>(B(),()=>{j.current&&cancelAnimationFrame(j.current)}),[a]),m.useEffect(()=>{if(!g||D.current||typeof window>"u"||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let R;const J=()=>{if(typeof document<"u"&&document.visibilityState==="hidden"){R=requestAnimationFrame(J);return}y(H=>({yaw:H.yaw+.002,pitch:H.pitch})),R=requestAnimationFrame(J)};return R=requestAnimationFrame(J),()=>cancelAnimationFrame(R)},[g]);const M=(A,R)=>{a&&(D.current=!0,S.current={x:A,y:R},I.current={yaw:u.yaw,pitch:u.pitch},N.current={x:0,y:0},O.current={x:A,y:R,time:performance.now()},E.current&&cancelAnimationFrame(E.current))},Z=(A,R)=>{if(!D.current)return;const J=A-S.current.x,H=R-S.current.y,ie=performance.now(),se=ie-O.current.time;se>0&&(N.current={x:(A-O.current.x)/se,y:(R-O.current.y)/se}),O.current={x:A,y:R,time:ie};const xe=.005,_e=I.current.yaw-J*xe,Ne=Math.PI/2.3,ae=Math.max(-Ne,Math.min(Ne,I.current.pitch-H*xe));y({yaw:_e,pitch:ae})},Y=()=>{if(!D.current)return;D.current=!1;let A=-N.current.x*12,R=-N.current.y*12;const J=.95,H=()=>{D.current||(A*=J,R*=J,!(Math.abs(A)<.01&&Math.abs(R)<.01)&&(y(ie=>{const se=ie.yaw+A*.005,xe=Math.PI/2.3,_e=Math.max(-xe,Math.min(xe,ie.pitch+R*.005));return{yaw:se,pitch:_e}}),E.current=requestAnimationFrame(H)))};E.current=requestAnimationFrame(H)},[P,z]=m.useState(null),[G,de]=m.useState({x:0,y:0,shiftX:0}),W=m.useRef(null);m.useEffect(()=>()=>{W.current&&clearTimeout(W.current)},[]),m.useEffect(()=>{if(!a||!C.current)return;const A=J=>{J.preventDefault();const H=-J.deltaY*.0025;b(ie=>{const se=ie+H;return Math.max(.5,Math.min(3,se))})},R=C.current;return R.addEventListener("wheel",A,{passive:!1}),()=>{R.removeEventListener("wheel",A)}},[a]);const V=m.useMemo(()=>{const A=[];return e.forEach((R,J)=>{(Array.isArray(R)?R:[]).forEach((H,ie)=>{H&&A.push({key:H.day||`${J}-${ie}`,col:J,row:ie,level:H.level||0,value:H.value||0,day:H.day,models:H.models||null})})}),A},[e]),me=k-(a?1.8:1.5),T=a?38:28,oe=A=>Math.max(1.8,Number(A)/4*T),pe=m.useMemo(()=>{if(V.length===0)return[];const A=e.length;return V.map(R=>{const J=oe(R.level),H=Math.sqrt(Math.pow(R.col-A/2,2)+Math.pow(R.row-3.5,2)),ie=Math.sqrt(Math.pow(A/2,2)+Math.pow(3.5,2)),se=H/ie*.4,xe=Math.min(1,Math.max(0,(F-se)*(1/.6))),_e=J*xe,Ne=(R.col-A/2)*k,ae=(R.row-3.5)*k,ge=me/2,we=[{x:Ne-ge,y:ae-ge,z:0},{x:Ne+ge,y:ae-ge,z:0},{x:Ne+ge,y:ae+ge,z:0},{x:Ne-ge,y:ae+ge,z:0},{x:Ne-ge,y:ae-ge,z:_e},{x:Ne+ge,y:ae-ge,z:_e},{x:Ne+ge,y:ae+ge,z:_e},{x:Ne-ge,y:ae+ge,z:_e}].map(ne=>Ze(ne.x,ne.y,ne.z,u.yaw,u.pitch)),Re=Ze(Ne,ae,_e/2,u.yaw,u.pitch),ot=[{name:"top",indices:[4,5,6,7],scale:1,normal:[0,0,1]},{name:"bottom",indices:[3,2,1,0],scale:.4,normal:[0,0,-1]},{name:"left",indices:[3,0,4,7],scale:.55,normal:[-1,0,0]},{name:"right",indices:[1,2,6,5],scale:.75,normal:[1,0,0]},{name:"front",indices:[0,1,5,4],scale:.85,normal:[0,-1,0]},{name:"back",indices:[2,3,7,6],scale:.65,normal:[0,1,0]}],Nt=l[Math.min(4,Math.max(0,Number(R.level)||0))],gt=[],yt=.35,jt=-.4,ee=.83;return ot.forEach(ne=>{const U=cc(ne.normal[0],ne.normal[1],ne.normal[2],u.yaw,u.pitch);if(U.z>.001){const te=we[ne.indices[0]],Oe=we[ne.indices[1]],ce=we[ne.indices[2]],pt=we[ne.indices[3]],xt=`M${te.x},${te.y} L${Oe.x},${Oe.y} L${ce.x},${ce.y} L${pt.x},${pt.y} Z`,bt=U.x*yt+U.y*jt+U.z*ee,Ge=n?.18:0,st=ne.scale*(.82+.28*Math.max(0,bt))+Ge;gt.push({name:ne.name,d:xt,fill:lc(Nt,st)})}}),{...R,centerProj:Re,renderedFaces:gt}})},[V,u,l,e.length,F,k,me,T]),fe=m.useMemo(()=>[...pe].sort((A,R)=>A.centerProj.z-R.centerProj.z),[pe]),le=m.useMemo(()=>{if(fe.length===0)return{minX:-100,minY:-100,maxX:100,maxY:100};let A=1/0,R=1/0,J=-1/0,H=-1/0;return fe.forEach(ie=>{const se=k*2,xe=ie.centerProj.x,_e=ie.centerProj.y;xe-se<A&&(A=xe-se),xe+se>J&&(J=xe+se),_e-se<R&&(R=_e-se),_e+se>H&&(H=_e+se)}),{minX:A,minY:R,maxX:J,maxY:H}},[fe,k]),he=12,Pe=le.maxX-le.minX+he*2,De=le.maxY-le.minY+he*2,ke=Pe/p,Ie=De/p,je=le.minX-he+(Pe-ke)/2,Te=le.minY-he+(De-Ie)/2,Ce=`${je} ${Te} ${ke} ${Ie}`;return V.length===0?o.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:h("heatmap.empty")}):o.jsxs("div",{ref:C,className:`relative select-none outline-none ${a?"cursor-grab active:cursor-grabbing w-full h-full flex items-center justify-center":"w-full overflow-hidden flex justify-center"}`,onMouseDown:A=>{if(!a)return;M(A.clientX,A.clientY);const R=H=>Z(H.clientX,H.clientY),J=()=>{Y(),window.removeEventListener("mousemove",R),window.removeEventListener("mouseup",J)};window.addEventListener("mousemove",R),window.addEventListener("mouseup",J)},onTouchStart:A=>{!a||A.touches.length===0||M(A.touches[0].clientX,A.touches[0].clientY)},onTouchMove:A=>{!a||A.touches.length===0||Z(A.touches[0].clientX,A.touches[0].clientY)},onTouchEnd:()=>{a&&Y()},children:[o.jsxs("svg",{ref:w,viewBox:Ce,width:a?"95%":"100%",height:a?"95%":"auto",role:"img","aria-label":h("heatmap.iso.aria")||"3D interactive activity heatmap",style:{display:"block",width:"100%",height:"auto",maxWidth:a?"none":`${Pe}px`,maxHeight:a?"78vh":"none"},className:"transition-transform duration-300 ease-out",children:[a&&v.map(A=>o.jsx("path",{d:A.d,fill:"none",stroke:c,strokeWidth:.25,strokeDasharray:"1.5 2.5",strokeLinecap:"round"},A.key)),fe.map(A=>{const R=P&&P.key===A.key;return o.jsxs("g",{onMouseEnter:J=>{if(W.current&&(clearTimeout(W.current),W.current=null),z(A),a&&w.current){const H=Ze((A.col-e.length/2)*k,(A.row-3.5)*k,oe(A.level),u.yaw,u.pitch);let ie=0,se=0;const xe=w.current;if(C.current&&typeof xe.createSVGPoint=="function"&&typeof xe.getScreenCTM=="function")try{const ge=xe.createSVGPoint();ge.x=H.x,ge.y=H.y;const Se=xe.getScreenCTM();if(Se){const we=ge.matrixTransform(Se),Re=C.current.getBoundingClientRect();ie=we.x-Re.left,se=we.y-Re.top}}catch{const Se=xe.getBoundingClientRect(),we=le.maxX-le.minX+he*2,Re=le.maxY-le.minY+he*2;ie=(H.x-(le.minX-he))/we*Se.width,se=(H.y-(le.minY-he))/Re*Se.height}else{const ge=xe.getBoundingClientRect(),Se=le.maxX-le.minX+he*2,we=le.maxY-le.minY+he*2;ie=(H.x-(le.minX-he))/Se*ge.width,se=(H.y-(le.minY-he))/we*ge.height}const _e=140;let Ne=0;const ae=C.current?C.current.getBoundingClientRect().width:xe.getBoundingClientRect().width;ie<_e?Ne=_e-ie:ie>ae-_e&&(Ne=ae-_e-ie),de({x:ie,y:se,shiftX:Ne})}},onMouseLeave:()=>{W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{z(null)},150)},className:"transition-all duration-200",style:{filter:R?"brightness(1.15) drop-shadow(0 4px 6px rgba(0,0,0,0.15))":"none",cursor:a?"pointer":"default"},children:[!a&&A.day&&o.jsx("title",{children:`${A.day}: ${Number(A.value).toLocaleString()} tokens`}),A.renderedFaces.map((J,H)=>o.jsx("path",{d:J.d,fill:J.fill,stroke:J.fill,strokeWidth:.25,strokeLinejoin:"round"},H))]},A.key)})]}),a&&P&&o.jsxs("div",{onMouseEnter:()=>{W.current&&(clearTimeout(W.current),W.current=null)},onMouseLeave:()=>{W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{z(null)},150)},className:"absolute z-[9999] w-0 h-0 transition-all duration-100 ease-out",style:{left:`${G.x}px`,top:`${G.y}px`},children:[o.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${G.shiftX}px))`},children:[o.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:P.day}),(()=>{const A=P.level===0?n?"#9ca3af":"#6b7280":l[P.level];return o.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:A+"22",color:A,border:`1px solid ${A}44`},children:["Level ",P.level]})})()]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-baseline gap-1",children:[o.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none",children:Number(P.value).toLocaleString()}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Tokens"})]}),P.models&&Object.keys(P.models).length>0?o.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[o.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),o.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 scrollbar-thin",children:Object.entries(P.models).map(([A,R])=>({name:A,val:Number(R)})).sort((A,R)=>R.val-A.val).map(({name:A,val:R})=>{const J=Number(P.value)||1,H=Math.round(R/J*100);return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[o.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:A,children:A}),o.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[o.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:R.toLocaleString()}),o.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[H,"%"]})]})]}),o.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${H}%`,backgroundColor:l[4],boxShadow:`0 0 4px ${l[4]}55`}})})]},A)})})]}):o.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:po(P.level,P.value)})]})]}),o.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]})]})}const Ct=12,tn=3,Qn=26,dc=["#ebedf0","#a7f3d0","#6ee7b7","#34d399","#10b981"],uc=["#30363d","#065f46","#059669","#10b981","#34d399"];function hr(e){const t=Number(e);return Number.isFinite(t)?t<1e3?t.toLocaleString():He(t,{decimals:2}):"0"}function fc(e){if(typeof e!="string")return null;const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(!t)return null;const n=new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])));return Number.isFinite(n.getTime())?n:null}function xo(e,t){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()+t))}function mc(e,t){return Math.floor((Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())-Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()))/864e5)}function hc(e,t){const n=t==="mon"?1:0,a=e.getUTCDay();return xo(e,-((a-n+7)%7))}function gc(e,t,n,a){if(!e)return[];const r=fc(t)||new Date,s=[];for(let f=11;f>=0;f-=1)s.push(new Date(Date.UTC(r.getUTCFullYear(),r.getUTCMonth()-f,1)));const i=hc(r,n),l=xo(i,-(e-1)*7),c=[],d=new Set;for(const f of s){const u=Math.floor(mc(l,f)/7);u<0||u>=e||d.has(u)||(d.add(u),c.push({label:a[f.getUTCMonth()],index:u}))}return c}function yc({heatmap:e,timeZoneLabel:t,timeZoneShortLabel:n,hideLegend:a=!1}){const{resolvedTheme:r}=no(),s=r==="dark",i=s?uc:dc,l=m.useRef(null),c=m.useRef(null),[d,f]=m.useState(null),[u,y]=m.useState({x:0,y:0,shiftX:0}),g=m.useRef(null);m.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]);const[x,p]=m.useState(!1),[b,k]=m.useState(!1),[v,w]=m.useState(!1),C=m.useRef(null),[D,S]=m.useState("emerald"),I=[h("heatmap.month.jan"),h("heatmap.month.feb"),h("heatmap.month.mar"),h("heatmap.month.apr"),h("heatmap.month.may"),h("heatmap.month.jun"),h("heatmap.month.jul"),h("heatmap.month.aug"),h("heatmap.month.sep"),h("heatmap.month.oct"),h("heatmap.month.nov"),h("heatmap.month.dec")],N=(T,oe)=>{if(!oe||!oe.day)return;g.current&&(clearTimeout(g.current),g.current=null),f(oe);const pe=T.currentTarget.getBoundingClientRect(),fe=c.current;if(!fe)return;const le=fe.getBoundingClientRect(),he=pe.left-le.left+pe.width/2,Pe=pe.top-le.top,De=140;let ke=0;he<De?ke=De-he:he>le.width-De&&(ke=le.width-De-he),y({x:he,y:Pe,shiftX:ke})},O=()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{f(null)},150)},E=()=>{g.current&&(clearTimeout(g.current),g.current=null)},F=()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{f(null)},150)},Q=()=>{k(!1),p(!0)},j=()=>{k(!0)},L=T=>{T.target===T.currentTarget&&b&&(p(!1),k(!1))};m.useEffect(()=>{if(!x||b)return;const T=oe=>{oe.key==="Escape"&&j()};return window.addEventListener("keydown",T),()=>{window.removeEventListener("keydown",T)}},[x,b]);const B=m.useMemo(()=>({emerald:{accentText:"text-emerald-500 dark:text-emerald-400",accentBg:"bg-emerald-500/10 dark:bg-emerald-400/10",accentBorder:"border-emerald-500/20 dark:border-emerald-400/15",hoverBorder:"hover:border-emerald-500/30 dark:hover:border-emerald-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(16,185,129,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(52,211,153,0.25)]",rawColor:"#10b981"},ocean:{accentText:"text-blue-500 dark:text-blue-400",accentBg:"bg-blue-500/10 dark:bg-blue-400/10",accentBorder:"border-blue-500/20 dark:border-blue-400/15",hoverBorder:"hover:border-blue-500/30 dark:hover:border-blue-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(59,130,246,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(96,165,250,0.25)]",rawColor:"#3b82f6"},neon:{accentText:"text-purple-500 dark:text-purple-400",accentBg:"bg-purple-500/10 dark:bg-purple-400/10",accentBorder:"border-purple-500/20 dark:border-purple-400/15",hoverBorder:"hover:border-purple-500/30 dark:hover:border-purple-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(168,85,247,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(192,132,252,0.25)]",rawColor:"#a855f7"},amber:{accentText:"text-amber-500 dark:text-amber-400",accentBg:"bg-amber-500/10 dark:bg-amber-400/10",accentBorder:"border-amber-500/20 dark:border-amber-400/15",hoverBorder:"hover:border-amber-500/30 dark:hover:border-amber-400/30",hoverGlow:"hover:shadow-[0_0_20px_-3px_rgba(245,158,11,0.15)] hover:dark:shadow-[0_0_20px_-3px_rgba(245,158,11,0.25)]",rawColor:"#f59e0b"}}),[]),M=B[D]||B.emerald,Z=ft[D]?s?ft[D].dark:ft[D].light:s?ft.emerald.dark:ft.emerald.light,[Y,P]=m.useState(()=>{try{return window.localStorage?.getItem("tt:heatmap-view")==="3d"?"3d":"2d"}catch{return"2d"}});m.useEffect(()=>{try{window.localStorage?.setItem("tt:heatmap-view",Y)}catch{}},[Y]),m.useEffect(()=>{const T=l.current;T&&(T.scrollLeft=T.scrollWidth)},[e?.weeks]),m.useEffect(()=>{const T=l.current;if(!T)return;const oe=()=>{g.current&&(clearTimeout(g.current),g.current=null),f(null)};return T.addEventListener("scroll",oe),()=>T.removeEventListener("scroll",oe)},[]);const z=e?.week_starts_on==="mon"?"mon":"sun",G=m.useMemo(()=>{const T=Array.isArray(e?.weeks)?e.weeks:[];if(!T.length)return{weeks:[]};const oe=[];for(const pe of T)for(const fe of Array.isArray(pe)?pe:[])fe?.day&&oe.push({day:fe.day,total_tokens:fe.total_tokens??fe.value??0,billable_total_tokens:fe.billable_total_tokens??fe.value??fe.total_tokens??0,models:fe.models??null});return fa({dailyRows:oe,weeks:Math.max(52,T.length),to:e?.to,weekStartsOn:z})},[e?.to,e?.weeks,z]),de=G?.weeks||[],W=m.useMemo(()=>{let T=0,oe=0,pe={day:"无数据",value:0},fe=0,le=0;const he=[];de.forEach(Ce=>{(Array.isArray(Ce)?Ce:[]).forEach(A=>{A&&A.day&&he.push(A)})}),he.sort((Ce,A)=>Ce.day.localeCompare(A.day)),he.forEach(Ce=>{const A=Number(Ce.value)||0;T+=A,A>0?(oe++,fe++,fe>le&&(le=fe)):fe=0,A>pe.value&&(pe={day:Ce.day,value:A})});const Pe=he.length||365,De=(oe/Pe*100).toFixed(1);let ke="heatmap.3d.modal.ai.eval.default",Ie="heatmap.3d.modal.ai.title.default";T>=15e6?(Ie="heatmap.3d.modal.ai.title.peak",ke="heatmap.3d.modal.ai.eval.peak"):T>=5e6?(Ie="heatmap.3d.modal.ai.title.heavy",ke="heatmap.3d.modal.ai.eval.heavy"):T>=1e6?(Ie="heatmap.3d.modal.ai.title.core",ke="heatmap.3d.modal.ai.eval.core"):T>=2e4&&(Ie="heatmap.3d.modal.ai.title.steady",ke="heatmap.3d.modal.ai.eval.steady");const je=e?.total_cost_usd,Te=je!=null?Number(je):T/15e5;return{totalTokens:T,activeDays:oe,activeRate:De,maxSingleDay:pe,maxStreak:le,aiEvaluationTitleKey:Ie,aiEvaluationKey:ke,totalCostUsd:Te}},[de,e?.total_cost_usd]),V=z==="mon"?["Mon","Tue","Wed","Thu","Fri","Sat","Sun"].map(T=>h(`heatmap.day.${T.toLowerCase()}`)):["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(T=>h(`heatmap.day.${T.toLowerCase()}`)),ue=m.useMemo(()=>gc(de.length,G?.to,z,I),[G?.to,de.length,z,I]);if(!de.length)return o.jsx("div",{className:"py-8 text-center text-sm text-oai-gray-500",children:h("heatmap.empty")});const me=Qn+de.length*Ct+Math.max(0,de.length-1)*tn;return o.jsxs("div",{ref:c,className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-5",children:[o.jsxs("div",{className:"flex items-baseline justify-between mb-3",children:[o.jsx("h3",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:h("heatmap.title")}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs("div",{role:"tablist","aria-label":"Heatmap view",className:"flex rounded-md border border-oai-gray-200 dark:border-oai-gray-800 p-0.5 text-[10px]",children:[o.jsx("button",{type:"button",role:"tab","aria-selected":Y==="2d",onClick:()=>P("2d"),className:Y==="2d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:h("heatmap.view.2d")}),o.jsx("button",{type:"button",role:"tab","aria-selected":Y==="3d",onClick:()=>P("3d"),className:Y==="3d"?"px-2 py-0.5 rounded bg-oai-gray-100 text-oai-black dark:bg-oai-gray-800 dark:text-oai-white font-medium":"px-2 py-0.5 rounded text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200",children:h("heatmap.view.3d")})]}),o.jsx("span",{className:"text-xs text-oai-gray-400 dark:text-oai-gray-450",children:n||h("heatmap.legend.utc")})]})]}),Y==="3d"&&o.jsxs("div",{onClick:Q,className:"cursor-pointer group relative overflow-hidden rounded-lg hover:border-oai-gray-350 dark:hover:border-oai-gray-700 border border-transparent transition-all",title:h("heatmap.3d.hover_tip"),children:[o.jsx(mr,{weeks:de,isDark:s,palette:D}),o.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-oai-gray-900/5 to-transparent pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity flex items-end justify-center pb-2",children:o.jsxs("span",{className:"text-[10px] bg-white/95 dark:bg-oai-gray-900/95 shadow border border-oai-gray-200/60 dark:border-oai-gray-800/80 px-2.5 py-1 rounded-full font-medium text-oai-gray-500 dark:text-oai-gray-400 flex items-center gap-1 transform translate-y-2 group-hover:translate-y-0 transition-transform duration-200",children:[o.jsx(pl,{size:9}),h("heatmap.3d.hover_tip")]})})]}),Y==="2d"&&o.jsx("div",{ref:l,className:"overflow-x-auto overflow-y-hidden heatmap-scroll-thin",children:o.jsxs("div",{style:{minWidth:me},children:[o.jsxs("div",{className:"grid text-[10px] uppercase text-oai-gray-400 dark:text-oai-gray-400 mb-1",style:{gridTemplateColumns:`${Qn}px repeat(${de.length}, ${Ct}px)`,columnGap:tn},children:[o.jsx("span",{}),ue.map(T=>o.jsx("span",{style:{gridColumnStart:T.index+2},className:"whitespace-nowrap",children:T.label},`${T.label}-${T.index}`))]}),o.jsxs("div",{className:"grid",style:{gridTemplateColumns:`${Qn}px repeat(${de.length}, ${Ct}px)`,columnGap:tn},children:[o.jsx("div",{className:"grid text-[10px] text-oai-gray-400 dark:text-oai-gray-400 sticky left-0 bg-white dark:bg-oai-gray-900 pr-2",style:{gridTemplateRows:`repeat(7, ${Ct}px)`,rowGap:tn},children:V.map(T=>o.jsx("span",{className:"leading-none",children:T},T))}),o.jsx("div",{className:"grid",style:{gridAutoFlow:"column",gridTemplateRows:`repeat(7, ${Ct}px)`,gap:tn},children:de.map((T,oe)=>(Array.isArray(T)?T:[]).map((pe,fe)=>{if(!pe)return null;const le=pe.day||`e-${oe}-${fe}`,he=Number(pe.level)||0,Pe=i[he]||i[0];return o.jsx("span",{onMouseEnter:De=>N(De,pe),onMouseLeave:O,className:"rounded-[2px] transition-transform hover:scale-125 hover:z-10 cursor-pointer",style:{width:Ct,height:Ct,background:Pe}},le)}))})]})]})}),!a&&o.jsxs("div",{className:"flex items-center justify-center gap-2 mt-3",children:[o.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:h("heatmap.legend.less")}),o.jsx("div",{className:"flex gap-0.5",children:i.map((T,oe)=>o.jsx("span",{className:"rounded-[1px]",style:{width:10,height:10,background:T}},oe))}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 dark:text-oai-gray-400",children:h("heatmap.legend.more")})]}),x&&o.jsx("div",{onAnimationEnd:L,onClick:T=>{T.target===T.currentTarget&&j()},className:`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 ${b?"animate-tt-fade-out":"animate-tt-fade-in"}`,children:o.jsxs("div",{className:`relative w-full max-w-6xl 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 ${b?"animate-tt-modal-exit":"animate-tt-modal"}`,children:[o.jsx("button",{type:"button",onClick:j,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 transition-all duration-300",children:o.jsx(ao,{size:16})}),o.jsxs("div",{className:"w-full md:w-[340px] 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-6 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[o.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[o.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:M.rawColor}}),o.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:M.rawColor}})]}),o.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:"3D Insight"})]}),o.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-none mt-2 select-none",children:h("heatmap.3d.modal.title")}),o.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-400 dark:text-zinc-500 mt-2 font-normal select-none",children:h("heatmap.3d.modal.desc")})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-y border-zinc-200/50 dark:border-zinc-800/50 py-5 select-none",children:[o.jsxs("div",{className:"flex flex-col gap-1 relative group cursor-help",children:[o.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:o.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[o.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:h("heatmap.3d.modal.stats.precision_total_tokens")}),o.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[W.totalTokens.toLocaleString()," Tokens"]})]})}),o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.total_tokens")}),o.jsxs("div",{className:"flex items-baseline gap-1.5",children:[o.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:hr(W.totalTokens)}),o.jsx("div",{className:"opacity-30 group-hover:opacity-60 transition-opacity",children:o.jsx("svg",{width:"24",height:"10",viewBox:"0 0 24 10",fill:"none",children:o.jsx("path",{d:"M1 9C3 7 5 7 7 4C9 1 11 0 13 2C15 4 17 0 23 0",stroke:M.rawColor,strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.estimated_cost")}),o.jsx("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:"$"+W.totalCostUsd.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.active_rate_days")}),o.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.activeRate,"% ",o.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",W.activeDays,"D)"]})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 group cursor-default",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.max_streak")}),o.jsxs("span",{className:"text-xl font-black text-amber-500 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.maxStreak," ",o.jsx("span",{className:"text-[10px] font-bold text-amber-500/80 font-mono",children:h("heatmap.3d.modal.stats.days_suffix")})]})]}),o.jsxs("div",{className:"flex flex-col gap-1 col-span-2 relative group cursor-help",children:[o.jsx("div",{className:"absolute left-0 bottom-full mb-2 pointer-events-none opacity-0 translate-y-1 group-hover:opacity-100 group-hover:translate-y-0 transition-all duration-200 z-50",children:o.jsxs("div",{className:"bg-white dark:bg-zinc-950 text-zinc-900 dark:text-zinc-50 text-[10px] font-semibold font-mono rounded-lg px-2.5 py-1.5 shadow-xl border border-zinc-200 dark:border-zinc-800/80 whitespace-nowrap flex flex-col",children:[o.jsx("span",{className:"text-[9px] text-zinc-400 dark:text-zinc-500",children:h("heatmap.3d.modal.stats.precision_peak_value")}),o.jsxs("span",{className:"mt-0.5 font-bold text-zinc-900 dark:text-zinc-50",children:[W.maxSingleDay.value>0?W.maxSingleDay.value.toLocaleString():h("heatmap.3d.modal.stats.no_data")," Tokens"]}),o.jsx("span",{className:"text-[8px] text-zinc-400 dark:text-zinc-500 mt-0.5",children:W.maxSingleDay.day!=="无数据"?W.maxSingleDay.day:h("heatmap.3d.modal.stats.no_data")})]})}),o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.stats.peak_day")}),o.jsxs("span",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight font-mono transition-transform duration-200 group-hover:-translate-y-[1px]",children:[W.maxSingleDay.value>0?hr(W.maxSingleDay.value):h("heatmap.3d.modal.stats.no_data")," ",o.jsxs("span",{className:"text-[10px] font-bold text-zinc-400 dark:text-zinc-500 font-mono",children:["(",W.maxSingleDay.day!=="无数据"?W.maxSingleDay.day:h("heatmap.3d.modal.stats.no_data"),")"]})]})]})]}),o.jsxs("div",{className:"flex flex-col gap-2.5 py-1",children:[o.jsxs("div",{className:"flex items-center gap-1.5 select-none",children:[o.jsx(Ml,{size:11,style:{color:M.rawColor}}),o.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono",style:{color:M.rawColor},children:h(W.aiEvaluationTitleKey)})]}),o.jsxs("div",{className:"pl-3.5 border-l-2 relative transition-all duration-300 group",style:{borderColor:M.rawColor},children:[o.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px] blur-[2px] opacity-15 pointer-events-none rounded-full",style:{backgroundColor:M.rawColor}}),o.jsx("p",{className:"text-[11px] leading-relaxed text-zinc-600 dark:text-zinc-400 font-normal",children:h(W.aiEvaluationKey)})]})]}),o.jsx("div",{className:"mt-auto border-t border-zinc-200/50 dark:border-zinc-800/50 pt-4 select-none",children:o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("span",{className:"text-[9px] font-bold text-zinc-400 dark:text-zinc-500 uppercase tracking-widest font-mono",children:h("heatmap.3d.modal.legend.title")}),o.jsx("span",{className:"text-[10px] font-medium text-zinc-500 dark:text-zinc-400",children:h(`heatmap.3d.modal.palette.${D}`)})]}),o.jsx("div",{className:"flex gap-1",children:Z.map((T,oe)=>o.jsx("div",{className:"flex-1 h-1 rounded-[2px]",style:{backgroundColor:T},title:`Level ${oe}`},oe))})]})})]}),o.jsxs("div",{className:"flex-1 h-full relative flex items-center justify-center overflow-hidden p-4",children:[o.jsx("div",{className:"absolute top-1/4 left-1/3 w-96 h-96 rounded-full blur-[130px] pointer-events-none -translate-x-1/2 -translate-y-1/2 transition-all duration-500",style:{backgroundColor:M.rawColor+"15"}}),o.jsx("div",{className:"absolute bottom-1/4 right-1/3 w-80 h-80 rounded-full blur-[120px] pointer-events-none translate-x-1/2 translate-y-1/2 bg-purple-500/[0.04] dark:bg-purple-500/[0.08]"}),o.jsxs("div",{className:"absolute top-4 left-1/2 -translate-x-1/2 flex items-center gap-3 p-1.5 backdrop-blur-md bg-white/70 dark:bg-oai-gray-900/75 border border-oai-gray-200/60 dark:border-oai-gray-800/80 rounded-full shadow-lg z-30 select-none",children:[o.jsx("div",{className:"flex items-center gap-1.5 px-2",children:Object.keys(B).map(T=>{const oe=D===T;return o.jsx("button",{type:"button",onClick:()=>S(T),title:h(`heatmap.3d.modal.palette.${T}`),className:`w-3.5 h-3.5 rounded-full transition-all duration-200 relative hover:scale-125 ${T==="emerald"?"bg-[#10b981]":T==="ocean"?"bg-[#3b82f6]":T==="neon"?"bg-[#a855f7]":"bg-[#f59e0b]"}`,children:oe&&o.jsx("span",{className:"absolute inset-0 rounded-full ring-2 ring-offset-1 ring-offset-white dark:ring-offset-oai-gray-900 ring-oai-gray-900 dark:ring-white scale-110"})},T)})}),o.jsx("div",{className:"w-[1px] h-4 bg-oai-gray-200 dark:bg-oai-gray-800"}),o.jsxs("div",{className:"flex items-center gap-1 pr-1",children:[o.jsx("button",{type:"button",onClick:()=>{const T=!v;w(T),C.current&&C.current.toggleAutoRotate(T)},title:v?h("heatmap.3d.modal.control.pause"):h("heatmap.3d.modal.control.play"),className:`p-1.5 rounded-full transition-all duration-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 ${v?M.accentText:"text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250"}`,children:v?o.jsx(bl,{size:12}):o.jsx(wl,{size:12})}),o.jsx("button",{type:"button",onClick:()=>{w(!1),C.current&&C.current.reset()},title:h("heatmap.3d.modal.control.reset"),className:"p-1.5 rounded-full text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-250 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-all duration-200",children:o.jsx(_l,{size:12})})]})]}),o.jsx(mr,{weeks:de,isDark:s,interactive:!0,palette:D,autoRotateInit:v,onResetViewRef:C}),o.jsxs("div",{className:"absolute bottom-4 right-4 flex items-center gap-1.5 text-[9px] font-bold text-oai-gray-400 bg-white/80 dark:bg-oai-gray-900/80 border border-oai-gray-200/50 dark:border-oai-gray-800/80 rounded-md px-2.5 py-1.5 select-none pointer-events-none backdrop-blur-md shadow-sm",children:[o.jsx(va,{size:10,className:M.accentText}),o.jsx("span",{children:h("heatmap.3d.modal.footer.tip")})]})]})]})}),d&&!x&&o.jsxs("div",{onMouseEnter:E,onMouseLeave:F,className:"absolute z-[9999] w-0 h-0 transition-all duration-100 ease-out",style:{left:`${u.x}px`,top:`${u.y}px`},children:[o.jsxs("div",{className:"absolute left-0 bottom-[10px] backdrop-blur-md bg-white/95 dark:bg-oai-gray-900/95 border border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-xl rounded-xl p-3.5 max-w-[280px] min-w-[200px] flex flex-col gap-2 animate-in fade-in zoom-in-95 duration-100",style:{transform:`translateX(calc(-50% + ${u.shiftX}px))`},children:[o.jsxs("div",{className:"flex items-center justify-between border-b border-oai-gray-100 dark:border-oai-gray-800/80 pb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold text-oai-gray-500 dark:text-oai-gray-400",children:d.day}),(()=>{const T=d.level===0?s?"#9ca3af":"#6b7280":i[d.level];return o.jsxs("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{backgroundColor:T+"22",color:T,border:`1px solid ${T}44`},children:["Level ",d.level]})})()]}),o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsxs("div",{className:"flex items-baseline gap-1",children:[o.jsx("span",{className:"text-lg font-bold text-oai-gray-900 dark:text-white leading-none",children:Number(d.total_tokens??d.value).toLocaleString()}),o.jsx("span",{className:"text-[10px] text-oai-gray-400 uppercase tracking-wider font-semibold",children:"Tokens"})]}),d.models&&Object.keys(d.models).length>0?o.jsxs("div",{className:"mt-1.5 border-t border-oai-gray-100 dark:border-oai-gray-800/60 pt-2 flex flex-col gap-1.5",children:[o.jsx("div",{className:"text-[10px] font-semibold text-oai-gray-400 dark:text-oai-gray-500 uppercase tracking-wider",children:"Model Breakdown"}),o.jsx("div",{className:"flex flex-col gap-2 max-h-[150px] overflow-y-auto pr-1.5 scrollbar-thin",children:Object.entries(d.models).map(([T,oe])=>({name:T,val:Number(oe)})).sort((T,oe)=>oe.val-T.val).map(({name:T,val:oe})=>{const pe=Number(d.total_tokens??d.value)||1,fe=Math.round(oe/pe*100);return o.jsxs("div",{className:"flex flex-col gap-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-[11px] gap-3",children:[o.jsx("span",{className:"font-medium text-oai-gray-750 dark:text-oai-gray-200 truncate max-w-[120px]",title:T,children:T}),o.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[o.jsx("span",{className:"font-mono text-oai-gray-900 dark:text-oai-gray-100 font-semibold",children:oe.toLocaleString()}),o.jsxs("span",{className:"text-[9px] text-oai-gray-450 dark:text-oai-gray-500 min-w-[28px] text-right font-medium",children:[fe,"%"]})]})]}),o.jsx("div",{className:"w-full h-1 bg-oai-gray-100 dark:bg-oai-gray-800/85 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${fe}%`,backgroundColor:i[4],boxShadow:`0 0 4px ${i[4]}55`}})})]},T)})})]}):o.jsx("p",{className:"text-[11px] text-oai-gray-600 dark:text-oai-gray-300 leading-relaxed font-normal mt-1 border-t border-dashed border-oai-gray-100 dark:border-oai-gray-800/60 pt-1.5",children:po(d.level,d.total_tokens??d.value)})]})]}),o.jsx("div",{className:"absolute bottom-[6px] left-0 -translate-x-1/2 w-2.5 h-2.5 rotate-45 bg-white dark:bg-oai-gray-900 border-r border-b border-oai-gray-200/50 dark:border-oai-gray-800/50 shadow-sm",style:{marginBottom:"1px"}})]}),o.jsx("style",{children:`
2
2
  .scrollbar-thin::-webkit-scrollbar {
3
3
  width: 4px;
4
4
  height: 4px;
@@ -1 +1 @@
1
- import{Q as p,r as c,C as e,al as f}from"./main-D0Irg9xR.js";const b={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_APP_VERSION:"0.22.0",VITE_INSFORGE_ANON_KEY:"ik_9f35735991b684f7cf57fa00bb4d0487",VITE_INSFORGE_BASE_URL:"https://srctyff5.us-east.insforge.app"};function x(){return f(),`${(b&&"https://srctyff5.us-east.insforge.app"||"https://srctyff5.us-east.insforge.app").replace(/\/$/,"")}/functions/tokentracker-device-flow-grant`}function l(a){return(a||"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9-]/g,"")}function h(){const a=p(),[m,g]=c.useState(""),[t,r]=c.useState({kind:"idle",message:""});c.useEffect(()=>{try{const n=new URLSearchParams(window.location.search).get("user_code");n&&g(l(n))}catch{}},[]);async function u(d){if(d?.preventDefault?.(),!a?.signedIn){r({kind:"error",message:"Please sign in first."});return}const n=l(m);if(!/^[A-HJKMNP-Z2-9]{4}-[A-HJKMNP-Z2-9]{4}$/.test(n)){r({kind:"error",message:"Invalid code format. Expected XXXX-XXXX."});return}r({kind:"working",message:"Approving…"});try{const i=await a.getAccessToken?.();if(!i){r({kind:"error",message:"No access token — please sign in again."});return}const s=await fetch(x(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({user_code:n})}),o=await s.json().catch(()=>({}));s.ok?r({kind:"success",message:o.status==="already_approved"?`Already approved earlier${o.client_info?" ("+o.client_info+")":""}.`:`Approved${o.client_info?" for "+o.client_info:""}. You can close this tab — your CLI will pick it up within a few seconds.`}):s.status===404?r({kind:"error",message:"Code not found. Double-check what your CLI printed."}):s.status===410?r({kind:"error",message:"Code expired. Re-run `tracker device-login` and try again."}):s.status===401?r({kind:"error",message:"Session expired. Sign out, sign in, and try again."}):r({kind:"error",message:o?.error||`Server error (HTTP ${s.status}).`})}catch(i){r({kind:"error",message:`Network error: ${i?.message||i}`})}}return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-oai-gray-950 px-6 py-12",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-8",children:[e.jsx("h1",{className:"text-2xl font-semibold text-oai-gray-900 dark:text-white mb-2",children:"Approve your CLI"}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 mb-6",children:"Type the code your CLI showed you. We'll link it to your account so token usage from that machine flows into your leaderboard profile."}),a?.signedIn?null:e.jsx("div",{className:"rounded-md border border-amber-200 bg-amber-50 dark:bg-amber-900/20 dark:border-amber-800 p-4 mb-4",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Sign in first, then return to this page."})}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-medium uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400 mb-1",children:"CLI code"}),e.jsx("input",{type:"text",value:m,onChange:d=>g(l(d.target.value)),placeholder:"XXXX-XXXX",spellCheck:!1,autoCapitalize:"characters",maxLength:9,className:"w-full font-mono text-xl tracking-widest text-center rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-900 dark:text-white px-4 py-3 focus:outline-none focus:ring-inset focus:ring-2 focus:ring-emerald-600"})]}),e.jsx("button",{type:"submit",disabled:t.kind==="working"||!a?.signedIn,className:"w-full rounded-md bg-emerald-600 hover:bg-emerald-500 disabled:bg-oai-gray-300 disabled:cursor-not-allowed text-white font-medium py-3 transition-colors",children:t.kind==="working"?"Approving…":"Approve"})]}),t.kind==="success"&&e.jsx("div",{className:"mt-4 rounded-md border border-emerald-200 bg-emerald-50 dark:bg-emerald-900/20 dark:border-emerald-800 p-4",children:e.jsx("p",{className:"text-sm text-emerald-700 dark:text-emerald-300",children:t.message})}),t.kind==="error"&&e.jsx("div",{className:"mt-4 rounded-md border border-red-200 bg-red-50 dark:bg-red-900/20 dark:border-red-800 p-4",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:t.message})})]})})}export{h as default};
1
+ import{Q as p,r as c,C as e,al as f}from"./main-Csid8osN.js";const b={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_APP_VERSION:"0.22.1",VITE_INSFORGE_ANON_KEY:"ik_9f35735991b684f7cf57fa00bb4d0487",VITE_INSFORGE_BASE_URL:"https://srctyff5.us-east.insforge.app"};function x(){return f(),`${(b&&"https://srctyff5.us-east.insforge.app"||"https://srctyff5.us-east.insforge.app").replace(/\/$/,"")}/functions/tokentracker-device-flow-grant`}function l(a){return(a||"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9-]/g,"")}function h(){const a=p(),[m,g]=c.useState(""),[t,r]=c.useState({kind:"idle",message:""});c.useEffect(()=>{try{const n=new URLSearchParams(window.location.search).get("user_code");n&&g(l(n))}catch{}},[]);async function u(d){if(d?.preventDefault?.(),!a?.signedIn){r({kind:"error",message:"Please sign in first."});return}const n=l(m);if(!/^[A-HJKMNP-Z2-9]{4}-[A-HJKMNP-Z2-9]{4}$/.test(n)){r({kind:"error",message:"Invalid code format. Expected XXXX-XXXX."});return}r({kind:"working",message:"Approving…"});try{const i=await a.getAccessToken?.();if(!i){r({kind:"error",message:"No access token — please sign in again."});return}const s=await fetch(x(),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({user_code:n})}),o=await s.json().catch(()=>({}));s.ok?r({kind:"success",message:o.status==="already_approved"?`Already approved earlier${o.client_info?" ("+o.client_info+")":""}.`:`Approved${o.client_info?" for "+o.client_info:""}. You can close this tab — your CLI will pick it up within a few seconds.`}):s.status===404?r({kind:"error",message:"Code not found. Double-check what your CLI printed."}):s.status===410?r({kind:"error",message:"Code expired. Re-run `tracker device-login` and try again."}):s.status===401?r({kind:"error",message:"Session expired. Sign out, sign in, and try again."}):r({kind:"error",message:o?.error||`Server error (HTTP ${s.status}).`})}catch(i){r({kind:"error",message:`Network error: ${i?.message||i}`})}}return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-white dark:bg-oai-gray-950 px-6 py-12",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-8",children:[e.jsx("h1",{className:"text-2xl font-semibold text-oai-gray-900 dark:text-white mb-2",children:"Approve your CLI"}),e.jsx("p",{className:"text-sm text-oai-gray-500 dark:text-oai-gray-400 mb-6",children:"Type the code your CLI showed you. We'll link it to your account so token usage from that machine flows into your leaderboard profile."}),a?.signedIn?null:e.jsx("div",{className:"rounded-md border border-amber-200 bg-amber-50 dark:bg-amber-900/20 dark:border-amber-800 p-4 mb-4",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Sign in first, then return to this page."})}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-medium uppercase tracking-wide text-oai-gray-500 dark:text-oai-gray-400 mb-1",children:"CLI code"}),e.jsx("input",{type:"text",value:m,onChange:d=>g(l(d.target.value)),placeholder:"XXXX-XXXX",spellCheck:!1,autoCapitalize:"characters",maxLength:9,className:"w-full font-mono text-xl tracking-widest text-center rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-white dark:bg-oai-gray-900 text-oai-gray-900 dark:text-white px-4 py-3 focus:outline-none focus:ring-inset focus:ring-2 focus:ring-emerald-600"})]}),e.jsx("button",{type:"submit",disabled:t.kind==="working"||!a?.signedIn,className:"w-full rounded-md bg-emerald-600 hover:bg-emerald-500 disabled:bg-oai-gray-300 disabled:cursor-not-allowed text-white font-medium py-3 transition-colors",children:t.kind==="working"?"Approving…":"Approve"})]}),t.kind==="success"&&e.jsx("div",{className:"mt-4 rounded-md border border-emerald-200 bg-emerald-50 dark:bg-emerald-900/20 dark:border-emerald-800 p-4",children:e.jsx("p",{className:"text-sm text-emerald-700 dark:text-emerald-300",children:t.message})}),t.kind==="error"&&e.jsx("div",{className:"mt-4 rounded-md border border-red-200 bg-red-50 dark:bg-red-900/20 dark:border-red-800 p-4",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:t.message})})]})})}export{h as default};
@@ -1 +1 @@
1
- import{C as o,F as d}from"./main-D0Irg9xR.js";import{u as r}from"./use-reduced-motion-HUOV_JD1.js";function x({children:i,delay:t=0,duration:n=.35,y:e=12,className:s="",once:a=!0}){return r()?o.jsx("div",{className:s,children:i}):o.jsx(d.div,{initial:{opacity:0,y:e},animate:{opacity:1,y:0},transition:{duration:n,delay:t,ease:[.16,1,.3,1]},className:s,children:i})}function f({children:i,staggerDelay:t=.1,initialDelay:n=0,className:e=""}){return r()?o.jsx("div",{className:e,children:i}):o.jsx(d.div,{initial:"hidden",animate:"visible",variants:{hidden:{},visible:{transition:{staggerChildren:t,delayChildren:n}}},className:e,children:i})}function h({children:i,className:t="",y:n=12}){return r()?o.jsx("div",{className:t,children:i}):o.jsx(d.div,{variants:{hidden:{opacity:0,y:n},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}},className:t,children:i})}export{x as F,f as S,h as a};
1
+ import{C as o,F as d}from"./main-Csid8osN.js";import{u as r}from"./use-reduced-motion-CPJKbom2.js";function x({children:i,delay:t=0,duration:n=.35,y:e=12,className:s="",once:a=!0}){return r()?o.jsx("div",{className:s,children:i}):o.jsx(d.div,{initial:{opacity:0,y:e},animate:{opacity:1,y:0},transition:{duration:n,delay:t,ease:[.16,1,.3,1]},className:s,children:i})}function f({children:i,staggerDelay:t=.1,initialDelay:n=0,className:e=""}){return r()?o.jsx("div",{className:e,children:i}):o.jsx(d.div,{initial:"hidden",animate:"visible",variants:{hidden:{},visible:{transition:{staggerChildren:t,delayChildren:n}}},className:e,children:i})}function h({children:i,className:t="",y:n=12}){return r()?o.jsx("div",{className:t,children:i}):o.jsx(d.div,{variants:{hidden:{opacity:0,y:n},visible:{opacity:1,y:0,transition:{duration:.35,ease:[.16,1,.3,1]}}},className:t,children:i})}export{x as F,f as S,h as a};
@@ -1 +1 @@
1
- import{r as s,ah as c,C as t}from"./main-D0Irg9xR.js";function h({repo:r="mm7894215/TokenTracker"}){const[a,o]=s.useState(null);return s.useEffect(()=>{if(typeof window>"u")return;const n=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,i=typeof document<"u"&&(document.documentElement?.classList.contains("screenshot-capture")||document.body?.classList.contains("screenshot-capture"));c({prefersReducedMotion:n,screenshotCapture:i})&&fetch(`https://api.github.com/repos/${r}`).then(e=>e.json()).then(e=>{e&&typeof e.stargazers_count=="number"&&o(e.stargazers_count)}).catch(()=>{})},[r]),t.jsxs("a",{href:`https://github.com/${r}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex shrink-0 items-center gap-2 px-3 py-1.5 rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-oai-gray-50 dark:bg-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-700 transition-colors no-underline",children:[t.jsx("svg",{height:"16",viewBox:"0 0 16 16",width:"16",className:"shrink-0 fill-oai-gray-700 dark:fill-oai-gray-300",children:t.jsx("path",{d:"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"})}),t.jsx("span",{className:"text-xs font-medium text-oai-gray-700 dark:text-oai-gray-300 whitespace-nowrap",children:"Star"}),a!==null&&t.jsx("span",{className:"text-xs font-semibold text-oai-gray-900 dark:text-oai-white tabular-nums whitespace-nowrap",children:a})]})}export{h as H};
1
+ import{r as s,ah as c,C as t}from"./main-Csid8osN.js";function h({repo:r="mm7894215/TokenTracker"}){const[a,o]=s.useState(null);return s.useEffect(()=>{if(typeof window>"u")return;const n=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,i=typeof document<"u"&&(document.documentElement?.classList.contains("screenshot-capture")||document.body?.classList.contains("screenshot-capture"));c({prefersReducedMotion:n,screenshotCapture:i})&&fetch(`https://api.github.com/repos/${r}`).then(e=>e.json()).then(e=>{e&&typeof e.stargazers_count=="number"&&o(e.stargazers_count)}).catch(()=>{})},[r]),t.jsxs("a",{href:`https://github.com/${r}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex shrink-0 items-center gap-2 px-3 py-1.5 rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-oai-gray-50 dark:bg-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-700 transition-colors no-underline",children:[t.jsx("svg",{height:"16",viewBox:"0 0 16 16",width:"16",className:"shrink-0 fill-oai-gray-700 dark:fill-oai-gray-300",children:t.jsx("path",{d:"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"})}),t.jsx("span",{className:"text-xs font-medium text-oai-gray-700 dark:text-oai-gray-300 whitespace-nowrap",children:"Star"}),a!==null&&t.jsx("span",{className:"text-xs font-semibold text-oai-gray-900 dark:text-oai-white tabular-nums whitespace-nowrap",children:a})]})}export{h as H};
@@ -1 +1 @@
1
- import{r as i,C as a}from"./main-D0Irg9xR.js";function o(){const[s,d]=i.useState(!1);return a.jsxs("div",{className:"h-full relative dark:bg-[#050505]",children:[!s&&a.jsxs("div",{className:"absolute inset-0 p-6 space-y-5 animate-pulse",children:[a.jsx("div",{className:"flex gap-4 justify-center",children:Array.from({length:6}).map((e,r)=>a.jsx("div",{className:"h-4 w-20 rounded bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsxs("div",{className:"space-y-2 pt-2",children:[a.jsx("div",{className:"h-7 w-72 rounded bg-oai-gray-200 dark:bg-oai-gray-800"}),a.jsx("div",{className:"h-4 w-96 rounded bg-oai-gray-200 dark:bg-oai-gray-800"})]}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-24 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-40 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-32 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))})]}),a.jsx("iframe",{src:"/proxy/ipcheck/claude/",title:"Cloud AI IP Check",className:`w-full h-full dark:invert dark:hue-rotate-180 transition-opacity duration-300 ${s?"opacity-100":"opacity-0"}`,style:{border:"none"},onLoad:()=>d(!0)})]})}export{o as default};
1
+ import{r as i,C as a}from"./main-Csid8osN.js";function o(){const[s,d]=i.useState(!1);return a.jsxs("div",{className:"h-full relative dark:bg-[#050505]",children:[!s&&a.jsxs("div",{className:"absolute inset-0 p-6 space-y-5 animate-pulse",children:[a.jsx("div",{className:"flex gap-4 justify-center",children:Array.from({length:6}).map((e,r)=>a.jsx("div",{className:"h-4 w-20 rounded bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsxs("div",{className:"space-y-2 pt-2",children:[a.jsx("div",{className:"h-7 w-72 rounded bg-oai-gray-200 dark:bg-oai-gray-800"}),a.jsx("div",{className:"h-4 w-96 rounded bg-oai-gray-200 dark:bg-oai-gray-800"})]}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-24 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-40 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))}),a.jsx("div",{className:"grid grid-cols-3 gap-4",children:Array.from({length:3}).map((e,r)=>a.jsx("div",{className:"h-32 rounded-xl bg-oai-gray-200 dark:bg-oai-gray-800"},r))})]}),a.jsx("iframe",{src:"/proxy/ipcheck/claude/",title:"Cloud AI IP Check",className:`w-full h-full dark:invert dark:hue-rotate-180 transition-opacity duration-300 ${s?"opacity-100":"opacity-0"}`,style:{border:"none"},onLoad:()=>d(!0)})]})}export{o as default};