tokentracker-cli 0.96.3 → 0.97.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.
- package/dashboard/dist/assets/{AchievementBadge-BX4iBBYM.js → AchievementBadge-BdvqY4Qb.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-DRYRuCbh.js → AchievementsPage-CrqvRxnb.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-BM_JWWhJ.js → AchievementsSection-wyLAM9N7.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-DxoxXst2.js → BadgeDetailModal-CquST3dj.js} +1 -1
- package/dashboard/dist/assets/{BotAnimated-BVpFxG8u.js → BotAnimated-EXhdUHSg.js} +1 -1
- package/dashboard/dist/assets/{Card-BJJs701t.js → Card-Il2WWgOG.js} +1 -1
- package/dashboard/dist/assets/{ClawdAnimated-46wPZ_Tc.js → ClawdAnimated-DioF5wa-.js} +2 -2
- package/dashboard/dist/assets/{CommandPalette-B_zkc7IU.js → CommandPalette-CaDx06tM.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-M2k5rIf1.js → CommunityStatsModal-BbYWzM07.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-DBvOTcAQ.js → ConfirmModal-BHWQLUCM.js} +1 -1
- package/dashboard/dist/assets/{Controls-BCkjPMSH.js → Controls--LFhExZX.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-3bHhou09.js → DashboardPage-DuqJOpHL.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-DFBUce8C.js → DevicePage-RKTirqz0.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-kvDd8h3V.js → DialogClose-DPFsTKmJ.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-DgaV8Gtk.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-DL5nvD31.js → DialogTitle-DolLpmFL.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-B-Bg6SEy.js → FadeIn-92GGNCPe.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-BExz0hh4.js → HeaderGithubStar-GfXudotT.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-Dj5zemYT.js → HoverTooltip-n7gbPEsq.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-DN7FuJ_v.js → IpCheckPage-BaQOTbXi.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-9dKgSBRy.js → LandingPage-D3JcvxW_.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardAvatar-00V95XIg.js → LeaderboardAvatar-tVaWJXZ3.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-DkKfUt0Z.js → LeaderboardPage-NqHcStnk.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProfileModal-C9sIHBgN.js → LeaderboardProfileModal-DmvcCVS7.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-BAiLMsEb.js → LeaderboardProfilePage-VSv3IlzS.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-BuenTaHa.js → LimitsPage-CtxgT20z.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-CKhY27Lr.js → LocalOnlyNotice-O9o586G8.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-BbvoBx5N.js → LoginCard-JCejigVu.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-P7zIkBhO.js → LoginModal-CJ3g7tBc.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-Bo0bR26x.js → LoginPage-DPWzPywx.js} +1 -1
- package/dashboard/dist/assets/{PetPage-C6i9bSSl.js → PetPage-MSJ3jseK.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-h0gf36vg.js → PopoverPopup-nL3YOLPO.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-Dm8fwPdj.js → ProviderIcon-C5RX_xPk.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-DvSJ8kg0.js → ResetPasswordPage-DW_NCwA_.js} +1 -1
- package/dashboard/dist/assets/{SegmentedControl-CP7oiGZE.js → SegmentedControl-CS6wQtck.js} +1 -1
- package/dashboard/dist/assets/{Select-iwP92x9C.js → Select-YqlqvbT5.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText-DzljA15_.js → SelectItemText-BahqsiIc.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-uD4D0Tid.js → ServiceStatusPage-DyhutLUy.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-Cmb1ssNP.js → SessionsPage-wbvi4EHi.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-D8ryg1Pv.js → SettingsPage-HGSwpV1O.js} +2 -2
- package/dashboard/dist/assets/SkillsPage-BbVT9oyh.js +1 -0
- package/dashboard/dist/assets/{TokenGalaxy-f2djrlUv.js → TokenGalaxy-Cej6MLu6.js} +1 -1
- package/dashboard/dist/assets/{ToolbarRootContext-CDxCPYLv.js → ToolbarRootContext-D9pPY73U.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-C419X22G.js → TrendMonitor-BtBcCjx-.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-AYq__pOO.js → WidgetsPage-BSNl2WIL.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-Bsm9k5XI.js → WrappedPage-d5oiNV4T.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-BDkeh90N.js → __vite-browser-external-CjrP5KfC.js} +12 -12
- package/dashboard/dist/assets/{agent-logos-B6Vg-4_1.js → agent-logos-CCVzO3uU.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DIQXwaOD.js → arrow-up-right-AKItXMyh.js} +1 -1
- package/dashboard/dist/assets/{check-CgD_bV39.js → check-BQw5n0V0.js} +1 -1
- package/dashboard/dist/assets/{composite-BIgEqWZD.js → composite-CWz1s64R.js} +1 -1
- package/dashboard/dist/assets/{copy-DlM1BHdp.js → copy-CF8XNmv3.js} +1 -1
- package/dashboard/dist/assets/{download-CQFG-VIY.js → download-BZvLU_hD.js} +1 -1
- package/dashboard/dist/assets/{external-link-BQyDqGxz.js → external-link-bZrcVkeE.js} +1 -1
- package/dashboard/dist/assets/{flame-BamzyXzF.js → flame-CMHolW1z.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-C4G-_xYt.js → format-tokens-Bs2YotMr.js} +1 -1
- package/dashboard/dist/assets/{icons-Ntscvl1a.js → icons-OKyij2y_.js} +1 -1
- package/dashboard/dist/assets/{index-DGxgsNoQ.js → index-C8nY1OaT.js} +1 -1
- package/dashboard/dist/assets/{index-FRIt5mlv.js → index-CN7xY7j_.js} +1 -1
- package/dashboard/dist/assets/{index-CUrcPqgp.js → index-DOwPCQx2.js} +1 -1
- package/dashboard/dist/assets/{info-CXytWcZi.js → info-CU7bMBhU.js} +1 -1
- package/dashboard/dist/assets/{link-2-Dexoo_jO.js → link-2-wwoUOujz.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-Cn0JHc8t.js → loader-circle-BK3Ltc-j.js} +1 -1
- package/dashboard/dist/assets/{maximize-2-DLh7gYuP.js → maximize-2-DIPnLqR8.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-DOh_xtyt.js → modifiers.esm-D_aVVjx5.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-CpqS9Ior.js → monitor-smartphone-4NOM9BHb.js} +1 -1
- package/dashboard/dist/assets/{plus-bfQV7nyv.js → plus-JqSTJ28Y.js} +1 -1
- package/dashboard/dist/assets/{provider-display-Bf9pW06U.js → provider-display-CEFlg9ho.js} +1 -1
- package/dashboard/dist/assets/{react-BmFZKA_b.js → react-jS0-5kwE.js} +1 -1
- package/dashboard/dist/assets/{search-l3jJ2fzC.js → search-CbBetPN7.js} +1 -1
- package/dashboard/dist/assets/{skills-api-CWmLnaxn.js → skills-api-PwUMTdmV.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-DLgyXLHM.js → sortable.esm-BDdw7tkz.js} +1 -1
- package/dashboard/dist/assets/{store-JM-a8ElZ.js → store-CFdu9yv_.js} +1 -1
- package/dashboard/dist/assets/{terminal-6aY2Sn8P.js → terminal-Dh7Sh6IG.js} +1 -1
- package/dashboard/dist/assets/{trash-D5oon5pT.js → trash-B6_OaEVL.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-ZWUMFwzc.js → use-community-stats-D55oU9bu.js} +1 -1
- package/dashboard/dist/assets/{use-latest-request-guard-BDaXr4gK.js → use-latest-request-guard-BO89yQ3n.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-yXXToNIc.js → use-limits-display-prefs-C358N7B0.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-C6RG8N6c.js → use-ordered-list-B9ZYDS1K.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-DWHVI51t.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-DpgZO_Lx.js → use-session-efficiency-pref-CwGRDyVq.js} +1 -1
- package/dashboard/dist/assets/{use-transform-D42P7jkd.js → use-transform-9S4Ruq_s.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-CV6puFwq.js → use-usage-limits-CpnM5V06.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-GWBmOrCR.js → useCurrency-BKJGW_4l.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-Beybkb0v.js → useTokenFormat-CTB5svOB.js} +1 -1
- package/dashboard/dist/assets/{zap-CEq2616W.js → zap-DGdBuT6m.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/ip-check.html +1 -1
- package/dashboard/dist/leaderboard.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/lib/codex-rollout-parser.js +48 -1
- package/src/lib/codex-service-tier.js +49 -0
- package/src/lib/local-api.js +5 -0
- package/src/lib/pricing/curated-overrides.json +2 -1
- package/src/lib/pricing/index.js +61 -3
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +83 -2
- package/src/lib/session-analytics.js +11 -0
- package/src/lib/skills-manager.js +226 -30
- package/dashboard/dist/assets/DialogDescription-BMyOicfz.js +0 -1
- package/dashboard/dist/assets/SkillsPage-eXI09q03.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-BqDKim_3.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{m as wr,r as d,j as e,L as Yo,cx as Zo,G as ut,am as Yt,cy as Oe,cz as Jo,cA as Qo,a9 as qr,cB as ga,cC as Ws,cD as Gs,cE as _r,cF as Xo,cG as ei,cH as ti,cI as vr,cJ as Wt,cK as ai,cL as ri,cM as se,c as l,d as _t,X as jr,as as Gt,a3 as Sa,l as Qe,q as qs,cN as si,Z as ni,n as Kt,aI as va,e as jt,cO as oi,F as Ys,z as Zs,aK as ii,$ as li,B as ci,R as di,k as ui,u as mi,a as Js,b4 as Qs,a4 as hi,cP as gi,cQ as xi,cR as fi,cS as pi,V as Yr,_ as yi,cT as Zr,g as bi,I as ki,ch as wi,cU as _i,cV as vi,cW as ji,cX as Ni,cY as Si,aJ as Jr,cZ as Qr,c_ as Ci,c$ as Ti,ad as Ai,d0 as Xr,aa as es,d1 as Di,d2 as Li,d3 as Mi}from"./__vite-browser-external-BDkeh90N.js";import{u as St}from"./use-latest-request-guard-BDaXr4gK.js";import{u as ts}from"./use-ordered-list-C6RG8N6c.js";import{t as as,T as Xs,g as Ei,f as xa,D as Ii,a as Ri,u as Fi}from"./TrendMonitor-C419X22G.js";import{u as $i}from"./use-usage-limits-CV6puFwq.js";import{u as Ca}from"./useCurrency-GWBmOrCR.js";import{u as Fe}from"./useTokenFormat-Beybkb0v.js";import{f as vt,A as Pi}from"./provider-display-Bf9pW06U.js";import{g as Bi,q as en,J as zi,M as Oi,m as ve}from"./react-BmFZKA_b.js";import{u as Ui,C as Hi,a as Vi,b as rs,D as Ki,S as Wi,v as Gi,s as qi,K as Yi,P as Zi}from"./sortable.esm-DLgyXLHM.js";import{D as Ji,a as Qi,b as Xi,c as el,d as tl,e as al}from"./DialogTitle-DL5nvD31.js";import{D as rl}from"./DialogClose-kvDd8h3V.js";import{C as De}from"./Card-BJJs701t.js";import{S as tn}from"./Select-iwP92x9C.js";import{P as Ct}from"./ProviderIcon-Dm8fwPdj.js";import{u as Nr}from"./use-reduced-motion-BqDKim_3.js";import{a as an,u as rn}from"./use-transform-D42P7jkd.js";import{I as sn}from"./info-CXytWcZi.js";import{A as Ta}from"./index-FRIt5mlv.js";import{L as sl}from"./loader-circle-Cn0JHc8t.js";import{P as nl,a as ol,b as il,c as ll,d as cl}from"./PopoverPopup-h0gf36vg.js";import{F as st}from"./FadeIn-B-Bg6SEy.js";import{C as dl}from"./ClawdAnimated-46wPZ_Tc.js";import{u as ul,T as ml}from"./Controls-BCkjPMSH.js";import{A as hl}from"./arrow-up-right-DIQXwaOD.js";import{u as gl,a as xl,P as fl}from"./use-session-efficiency-pref-DpgZO_Lx.js";import{L as ss}from"./LoginCard-BbvoBx5N.js";import{L as pl,A as yl}from"./agent-logos-B6Vg-4_1.js";import{M as nn}from"./monitor-smartphone-CpqS9Ior.js";import{C as bl}from"./check-CgD_bV39.js";import"./terminal-6aY2Sn8P.js";import"./maximize-2-DLh7gYuP.js";import"./use-limits-display-prefs-yXXToNIc.js";import"./composite-BIgEqWZD.js";import"./store-JM-a8ElZ.js";import"./ToolbarRootContext-CDxCPYLv.js";import"./SelectItemText-DzljA15_.js";const kl=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],wl=wr("git-branch",kl);const _l=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],vl=wr("laptop",_l);const jl=[["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"}]],Nl=wr("square-arrow-out-up-right",jl);function Sl(t,a,r={}){const s=t.get();let n=null,i=s,o;const u=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,c=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const x=ns(t.get()),g=ns(i);if(x===g){c();return}const p=n?n.getGeneratorVelocity():t.getVelocity();c(),n=new zi({keyframes:[x,g],velocity:p,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},m=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((x,g)=>{i=x,o=p=>g(Ja(p,u)),Bi.postRender(m)},c),en(a)){let x=r.skipInitialAnimation===!0;const g=a.on("change",y=>{x?(x=!1,t.jump(Ja(y,u),!1)):t.set(Ja(y,u))}),p=t.on("destroy",g);return()=>{g(),p()}}return c}function Ja(t,a){return a?t+a:t}function ns(t){return typeof t=="number"?t:parseFloat(t)}function Cl(t,a={}){const{isStatic:r}=d.useContext(Oi),s=()=>en(t)?t.get():t;if(r)return an(s);const n=rn(s());return d.useInsertionEffect(()=>Sl(n,t,a),[n,JSON.stringify(a)]),n}function Tl(t,a={}){return Cl(t,{type:"spring",...a})}function Al(){return e.jsxs(Yo,{to:"/landing",className:"flex items-center gap-2.5 no-underline hover:opacity-80 transition-opacity",children:[e.jsx("img",{src:"/app-icon.png",alt:"Token Tracker",width:28,height:28,className:"rounded-md"}),e.jsx("span",{className:"text-base font-semibold text-oai-black dark:text-oai-white leading-tight",children:"Token Tracker"})]})}function Dl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Al,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function Ll({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},u=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:u,children:t})}var Ml={};function El(t,a){return t==="."?{width:"0.34ch",justifyContent:"center",marginInline:"-0.04ch"}:t===","?{width:"0.08ch",justifyContent:"center",marginInline:"-0.30ch"}:{width:"0.72ch",justifyContent:"flex-start",paddingLeft:"0.04ch",height:a}}function Il({mv:t,digit:a,height:r}){const s=an(t,n=>{const i=(n%10+10)%10,o=(10+a-i)%10;let u=o*r;return o>5&&(u-=10*r),u});return e.jsx(ve.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Rl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Fl(t,a){const r=t/a;return Math.floor(Rl(r))}function $l(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((u,c)=>/\d/.test(u)&&(s===-1||c<s)).length,i=0,o=!1;return r.map(u=>{if(!/\d/.test(u))return u==="."&&(o=!0),u;if(!o){const c=10**Math.max(n-1,0);return n-=1,c}return i+=1,10**-i})}function Pl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const c=El(t,r),h=t!=="."&&t!==",",m=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...c,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...m?{width:c.width}:null},children:t})}const i=Fl(a,t),o=rn(0),u=Tl(o,{stiffness:220,damping:26,mass:.8});return d.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(c,h)=>e.jsx(Il,{mv:u,digit:h,height:r},h))})}function Bl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:u=0,textColor:c="inherit",fontWeight:h="inherit",containerStyle:m,counterStyle:x,digitStyle:g,gradientHeight:p=14,gradientFrom:y="rgba(255,255,255,0.95)",gradientTo:k="rgba(255,255,255,0)",topGradientStyle:f,bottomGradientStyle:v}){const w=String(a??t??""),D=d.useMemo(()=>Array.isArray(n)&&n.length?n:$l(w),[n,w]),C=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Ml?.VITEST==="true",R=Nr()||C,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,P=r+s;return R?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:c,fontSize:r,fontWeight:h,lineHeight:1,...m,...x},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...m},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:u,paddingRight:u,lineHeight:1,color:c,fontWeight:h,...x},children:D.map((N,j)=>e.jsx(Pl,{place:N,value:A,height:P,digitStyle:g,shouldReduceMotion:R},`${String(N)}-${j}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:f??{height:p,background:`linear-gradient(to bottom, ${y}, ${k})`}}),e.jsx("span",{style:v??{height:p,background:`linear-gradient(to top, ${y}, ${k})`}})]})]})}function zl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:u,now:c,accountView:h=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:g=!1,deviceId:p=null}={}){const y=!!(h&&m),k=y?"cloud":"local",f=d.useMemo(()=>Zo({weeks:s,weekStartsOn:n,now:c}),[c,s,n]),[v,w]=d.useState([]),[D,C]=d.useState(null),[R,A]=d.useState("edge"),[P,N]=d.useState(!1),[j,S]=d.useState(null),E=ut(),O=Yt(a),F=!r,L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=St([t,f.from,f.to,s,n,k,a,m,x,g,p,o,u,r,E,F,O,L]),K=d.useMemo(()=>{if(!i)return null;const W=_r({timeZone:o,offsetMinutes:u});return`tokentracker.heatmap.${i}.${k}.${s}.${n}.${W}.${p||"all"}`},[i,p,k,o,u,s,n]),q=d.useCallback(()=>{if(!K||typeof window>"u")return null;try{const W=window.localStorage.getItem(K);if(!W)return null;const ne=JSON.parse(W);return!ne||!ne.heatmap?null:ne}catch{return null}},[K]),_=d.useCallback(W=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(W))}catch{}},[K]),$=d.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=d.useRef(k);d.useEffect(()=>{H.current!==k&&(H.current=k,w([]),C(null),A("edge"),S(null),N(!0))},[k]);const te=d.useCallback(async()=>{const W=B(),ne=await Oe(a),oe=y?await Oe(m):null;if(!W()||!ne&&!E&&!L&&!y)return;if(y&&!oe){S("Your session expired. Please sign in again to view account data."),N(!1);return}const je=y?oe:ne,be=y?Jo:Qo,Le=y?Ws:Gs;N(!0),S(null);try{try{const ee=await be({baseUrl:t,accessToken:je,weeks:s,to:f.to,weekStartsOn:n,device:p,timeZone:o,tzOffsetMinutes:u}),ae=Array.isArray(ee?.weeks)?ee.weeks:[];if(!W())return;if(!ae.length&&F){const Y=q();if(Y?.heatmap){if(!W())return;C(Y.heatmap),w(Y.daily||[]),A("cache");return}}if(!ae.some(Y=>(Array.isArray(Y)?Y:[]).some(J=>J&&Number.isFinite(Number(J.level))))&&ae.length){const Y=[];for(const Z of ae)for(const ge of Array.isArray(Z)?Z:[])ge?.day&&Y.push({day:ge.day,total_tokens:ge.total_tokens??ge.value??0,billable_total_tokens:ge.billable_total_tokens??ge.value??ge.total_tokens??0});const J=qr({dailyRows:Y,weeks:s,to:ee?.to||f.to,weekStartsOn:n});if(!W())return;w(Y),C({...J,week_starts_on:n,active_days:Y.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ga({dailyRows:Y,to:ee?.to||f.to})}),A("client"),F?_({heatmap:{...J,week_starts_on:n,active_days:Y.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ga({dailyRows:Y,to:ee?.to||f.to})},daily:Y,fetchedAt:new Date().toISOString()}):$();return}if(!W())return;C(ee||null),w([]),A("edge"),ee&&F?_({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):F||$();return}catch(ee){const ae=ee,ye=ae?.status??ae?.statusCode;if(ye===401||ye===403)throw ee}if(!W())return;const X=await Le({baseUrl:t,accessToken:je,from:f.from,to:f.to,device:p,timeZone:o,tzOffsetMinutes:u}),U=Array.isArray(X?.data)?X.data:[];if(!W())return;w(U);const re=qr({dailyRows:U,weeks:s,to:f.to,weekStartsOn:n});if(!W())return;C({...re,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ga({dailyRows:U,to:f.to})}),A("client"),F?_({heatmap:{...re,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ga({dailyRows:U,to:f.to})},daily:U,fetchedAt:new Date().toISOString()}):$()}catch(X){if(!W())return;if(F){const U=q();if(U?.heatmap){if(!W())return;C(U.heatmap),w(U.daily||[]),A("cache"),S(null)}else{const re=X;S(re?.message||String(re)),w([]),C(null),A("edge")}}else{const U=X;S(U?.message||String(U)),w([]),C(null),A("edge")}}finally{W()&&N(!1)}},[a,t,E,r,F,f.from,f.to,q,O,o,u,n,s,$,_,L,y,m,x,p,B]);return d.useEffect(()=>{if(g){N(!0);return}if(!O&&!r&&!E&&!L&&!y){w([]),N(!1),S(null),C(null),A("edge");return}if(!F)$(),w([]),S(null),C(null),A("edge");else{const W=q();W?.heatmap&&(C(W.heatmap),w(W.daily||[]),A("cache"))}te()},[a,E,q,te,O,r,F,$,L,g]),{range:f,daily:v,heatmap:D,source:E?"mock":R==="client"?"edge":R,loading:P,error:j,refresh:te}}const Ol="tokentracker.dashboard.leftCardOrder.v1",Ul="tokentracker.dashboard.rightCardOrder.v1";function Hl(t,a){const r=ts(Ol,t),s=ts(Ul,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=d.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const Vl=10;function Kl({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[u,c]=d.useState([]),[h,m]=d.useState(!1),[x,g]=d.useState(null),p=ut(),y=Yt(a),k=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),f=St([t,a,r,s,n,i,o]),v=d.useCallback(async()=>{const w=f(),D=await Oe(a);if(w()){if(!D&&!p&&!k){c([]),g(null),m(!1);return}m(!0),g(null);try{const C=await Xo({baseUrl:t,accessToken:D,limit:Vl,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!w())return;c(Array.isArray(C?.entries)?C.entries:[])}catch(C){if(!w())return;const R=C?.message||String(C);g(R),c([])}finally{w()&&m(!1)}}},[a,t,r,p,n,i,s,o,k,f]);return d.useEffect(()=>{if(!y&&!p&&!k){c([]),g(null),m(!1);return}c([]),g(null),m(!0),v()},[p,v,y,k]),{entries:u,loading:h,error:x,refresh:v}}const os="tokentracker.usage-cache-index",is=24;function ls({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:u,timeZone:c,tzOffsetMinutes:h,now:m,accountView:x=!1,accountAccessToken:g=null,accountRevision:p=0,accountViewResolving:y=!1,deviceId:k=null}={}){const f=!!(x&&g),v=f?"cloud":"local",[w,D]=d.useState([]),[C,R]=d.useState(null),[A,P]=d.useState(null),[N,j]=d.useState("edge"),[S,E]=d.useState(null),[O,F]=d.useState(!1),[L,B]=d.useState(null),K=ut(),q=Yt(a),_=!r&&!K,$=k||"all",H=(()=>{if(!u)return null;const X=Wl(t)||"default",U=i?o?"daily-summary":"daily-only":"summary",re=_r({timeZone:c,offsetMinutes:h});return`tokentracker.usage.${u}.${v}.${X}.${s}.${n}.${U}.${re}.${$}`})(),te=d.useRef(v);d.useEffect(()=>{te.current!==v&&(te.current=v,D([]),R(null),P(null),j("edge"),E(null),B(null),F(!0))},[v]);const ue=d.useCallback(()=>{if(!H||typeof window>"u")return null;try{const X=window.localStorage.getItem(H);if(!X)return null;const U=JSON.parse(X),re=o?!!U?.summary:Array.isArray(U?.daily);return!U||!re?null:(as(os,H,is),U)}catch{return null}},[o,H]),W=d.useCallback(X=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(X)),as(os,H,is)}catch{}},[H]),ne=d.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),oe=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),je=St([t,s,n,i,o,v,a,g,p,k,c,h,r,K,_,y,q,oe]),be=d.useCallback(async()=>{const X=je(),U=await Oe(a),re=f?await Oe(g):null;if(!X()||!U&&!K&&!oe&&!f)return;if(f&&!re){B("Your session expired. Please sign in again to view account data."),F(!1);return}const ee=f?Ws:Gs,ae=f?ei:ti,ye=f?re:U;F(!0),B(null);try{let Y=null,J=null;if(i)if(o){const[T,z]=await Promise.allSettled([ee({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h}),ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0})]);if(T.status==="rejected")throw T.reason;Y=T.value,J=z.status==="fulfilled"?z.value:null}else Y=await ee({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h});else o&&(J=await ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0}));let Z=i&&Array.isArray(Y?.data)?Y.data:[];i&&(Z=Xa(Z,s,n,{timeZone:c,offsetMinutes:h,now:m}));let ge=o&&(J?.totals||Y?.summary?.totals)||null,$e=o&&(J?.rolling||Y?.summary?.rolling)||null;if(o&&i&&!ge&&!J)try{const T=await ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0});ge=T?.totals||null,$e=T?.rolling||$e}catch{}const me=new Date().toISOString();if(!X())return;D(Z),R(ge),P($e),j("edge"),E(me),(ge||!o&&i)&&_?W({summary:ge,rolling:$e,daily:Z,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:me}):_||ne()}catch(Y){if(!X())return;if(_){const J=ue();if(J?.summary||!o&&Array.isArray(J?.daily)){R(J.summary),P(J.rolling||null);const Z=Array.isArray(J.daily)?J.daily:[],ge=i?Xa(Z,J.from||s,J.to||n,{timeZone:c,offsetMinutes:h,now:m}):Z;D(ge),j("cache"),E(J.fetchedAt||null),B(null)}else{const Z=Y;B(Z?.message||String(Z)),D([]),R(null),P(null),j("edge"),E(null)}}else{const J=Y;B(J?.message||String(J)),D([]),R(null),P(null),j("edge"),E(null)}}finally{X()&&F(!1)}},[a,t,s,i,o,K,r,_,m,ue,q,c,n,h,ne,W,oe,f,g,p,k,je]);return d.useEffect(()=>{if(y){F(!0);return}const X=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!q&&!r&&!K&&!X&&!f){D([]),R(null),P(null),B(null),F(!1),j("edge"),E(null);return}if(!_)ne(),D([]),R(null),P(null),B(null),j("edge"),E(null);else{const U=ue();if(U?.summary||!o&&Array.isArray(U?.daily)){R(U.summary),P(U.rolling||null);const re=Array.isArray(U.daily)?U.daily:[],ee=i?Xa(re,U.from||s,U.to||n,{timeZone:c,offsetMinutes:h,now:m}):re;D(ee),j("cache"),E(U.fetchedAt||null),B(null)}else D([]),R(null),P(null),j("edge"),E(null),B(null)}F(!0),be()},[a,K,ue,be,q,r,_,ne,oe,y,o]),d.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const X=15e3;let U=Date.now();const re=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-U<X||(U=ee,be())};return window.addEventListener("focus",re),document.addEventListener("visibilitychange",re),()=>{window.removeEventListener("focus",re),document.removeEventListener("visibilitychange",re)}},[be]),{daily:w,summary:C,rolling:A,source:K?"mock":N,fetchedAt:S,loading:O,error:L,refresh:be}}function Wl(t){try{return new URL(t).host}catch{return null}}function Qa(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Wt(o)===a?o:null}function Gl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Xa(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=Qa(a),u=Qa(r);if(!o||!u||u<o)return Array.isArray(t)?t:[];const c=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=vr({timeZone:s,offsetMinutes:n,date:c}),m=Qa(h),x=m?m.getTime():c.getTime(),g=new Map;for(const y of t||[])y?.day&&g.set(y.day,y);const p=[];for(let y=o;y<=u;y=Gl(y,1)){const k=Wt(y),f=g.get(k),v=y.getTime()>x;if(f){p.push({...f,missing:!1,future:v});continue}p.push({day:k,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!v,future:v})}return p}function ql({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:u,accountView:c=!1,accountAccessToken:h=null,accountRevision:m=0,accountViewResolving:x=!1,deviceId:g=null}={}){const p=!!(c&&h),y=p?"cloud":"local",[k,f]=d.useState(null),[v,w]=d.useState("edge"),[D,C]=d.useState(!1),[R,A]=d.useState(null),P=ut(),N=Yt(a),j=!r,S=d.useMemo(()=>{if(!i)return null;const $=Yl(t)||"default",H=_r({timeZone:o,offsetMinutes:u});return`tokentracker.modelBreakdown.${i}.${y}.${$}.${s}.${n}.${H}.${g||"all"}`},[t,i,g,s,y,o,n,u]),E=d.useCallback(()=>{if(!S||typeof window>"u")return null;try{const $=window.localStorage.getItem(S);if(!$)return null;const H=JSON.parse($);return!H||!H.breakdown?null:H}catch{return null}},[S]),O=d.useCallback($=>{if(!(!S||typeof window>"u"))try{window.localStorage.setItem(S,JSON.stringify($))}catch{}},[S]),F=d.useCallback(()=>{if(!(!S||typeof window>"u"))try{window.localStorage.removeItem(S)}catch{}},[S]),L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=St([t,s,n,y,a,h,m,g,o,u,r,P,j,x,N,L]),K=d.useRef(y);d.useEffect(()=>{K.current!==y&&(K.current=y,f(null),w("edge"),A(null),C(!0))},[y]);const q=d.useCallback(async()=>{const $=B(),H=await Oe(a),te=p?await Oe(h):null;if(!$()||!H&&!P&&!L&&!p)return;if(p&&!te){A("Your session expired. Please sign in again to view account data."),C(!1);return}const ue=p?te:H,W=p?ai:ri;C(!0),A(null);try{const ne=await W({baseUrl:t,accessToken:ue,from:s,to:n,device:g,timeZone:o,tzOffsetMinutes:u});if(!$())return;f(ne||null),w("edge"),ne&&j?O({breakdown:ne,fetchedAt:new Date().toISOString()}):j||F()}catch(ne){if(!$())return;if(j){const oe=E();if(oe?.breakdown)f(oe.breakdown),w("cache"),A(null);else{f(null),w("edge");const je=ne;A(je?.message||String(je))}}else{f(null),w("edge");const oe=ne;A(oe?.message||String(oe))}}finally{$()&&C(!1)}},[a,t,s,P,r,j,E,o,n,N,u,F,O,L,p,h,m,g,B]);return d.useEffect(()=>{if(x){C(!0);return}if(!N&&!r&&!P&&!L&&!p){f(null),w("edge"),A(null),C(!1);return}if(!j)F(),f(null),w("edge"),A(null);else{const $=E();$?.breakdown?(f($.breakdown),w("cache"),A(null)):(f(null),w("edge"),A(null))}C(!0),q()},[a,P,E,q,N,r,j,F,L,x]),{breakdown:k,source:P?"mock":v,loading:D,error:R,refresh:q}}function Yl(t){try{return new URL(t).host}catch{return null}}const on=new Set(["day","hour","month"]);function Zl(t){return on.has(t)}function cs(t){if(t==null)return null;const a=String(t).trim();if(!/^[0-9]+$/.test(a))return null;const r=a.replace(/^0+/,"");return r.length===0?"0":r}function Jl(t,a){const r=cs(t),s=cs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=se(t),i=se(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function Ql(t,a){const r=typeof t=="string"?t:String(t||""),s=typeof a=="string"?a:String(a||"");return r===s?0:r<s?-1:1}function Xl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function ec(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function tc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),u=Number(r[5]),c=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(u)||!Number.isFinite(c)||n<1||n>12||i<1||i>31||o<0||o>23||u<0||u>59||c<0||c>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,u,c));return Number.isFinite(h.getTime())?h.getTime():null}function ac(t,a,r){const s=r==="hour"?tc:r==="month"?ec:Xl,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:Ql(t,a)}function ln(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=on.has(a)?(u,c)=>ac(u,c,a):Jl,o=u=>a==="total_tokens"&&u?.billable_total_tokens!=null?u.billable_total_tokens:u?.[a];return n.map((u,c)=>({row:u,index:c})).sort((u,c)=>{const h=o(u.row),m=o(c.row),x=h==null,g=m==null;if(x&&g)return u.index-c.index;if(x)return 1;if(g)return-1;const p=i(h,m);return p!==0?p*s:u.index-c.index}).map(u=>u.row)}function rc(){return[{key:"day",label:l("daily.sort.date.label"),title:l("daily.sort.date.title")},{key:"total_tokens",label:l("daily.sort.total.label"),title:l("daily.sort.total.title")},{key:"input_tokens",label:l("daily.sort.input.label"),title:l("daily.sort.input.title")},{key:"output_tokens",label:l("daily.sort.output.label"),title:l("daily.sort.output.title")},{key:"cached_input_tokens",label:l("daily.sort.cached.label"),title:l("daily.sort.cached.title")},{key:"reasoning_output_tokens",label:l("daily.sort.reasoning.label"),title:l("daily.sort.reasoning.title")},{key:"conversation_count",label:l("daily.sort.conversations.label"),title:l("daily.sort.conversations.title")}]}function ds(t){const a=Zl(t)?t:"day";return rc().map((r,s)=>s===0?{...r,key:a}:r)}function us(t,{key:a,dir:r}){return ln(t,{key:a,dir:r})}const ja=12,sc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function nc(t){if(typeof t=="bigint")return t!==0n;if(typeof t=="number")return Number.isFinite(t)&&t!==0;if(t==null)return!1;const a=String(t).trim();if(!a||!/^-?\d+$/.test(a))return!1;const r=a.startsWith("-")?a.slice(1):a;return/[1-9]/.test(r)}function oc(t){return sc.some(a=>nc(t?.[a]))}function ic(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=ln(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&oc(n));return s===-1?a:r.slice(s)}function lc(t,a,r=ja){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:ja,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function cc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const fa=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function dc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return fa.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?fa.active:s<=60*6e4?fa.warm:fa.idle}const uc=3e4;function mc({refresh:t,intervalMs:a=uc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,u=Date.now(),c=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const p=Promise.resolve().then(()=>t()).catch(y=>n(y)).then(()=>{}).finally(()=>{o===p&&(o=null)});return o=p,p},m=r.setInterval(()=>{const p=Date.now();p<c||(c=p+dc({visible:s.visibilityState==="visible",lastInteractionAt:u,now:p}),h())},a),x=()=>{s.visibilityState==="visible"&&(u=Date.now(),c=0,h())},g=()=>{u=Date.now()};return r.addEventListener("focus",x),r.addEventListener("pointerdown",g),r.addEventListener("keydown",g),s.addEventListener("visibilitychange",x),{run:h,stop(){i=!0,r.clearInterval(m),r.removeEventListener("focus",x),r.removeEventListener("pointerdown",g),r.removeEventListener("keydown",g),s.removeEventListener("visibilitychange",x)}}}function hc(t){if(!t)return null;const a=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!a)return null;const r=new Date(Date.UTC(Number(a[1]),Number(a[2])-1,Number(a[3])));return Wt(r)===t?r:null}function gc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=hc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Wt(i),to:Wt(n)}}function xc(t,{period:a}={}){const r=(Array.isArray(t)?t:[]).filter(n=>!n?.future&&n?.day);return(a==="total"?r.filter(n=>!n?.missing):r).slice(-30)}function Sr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function fc(t){const a=Sr(t?.model_id);return a||null}function cn(t,a){return t?.model?String(t.model):a}function dn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Sr(n);if(!i||i.includes("/"))continue;const o=Math.max(0,se(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function un(t,a){const r=Sr(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function Nt(t,a=0){const r=se(t?.billable_total_tokens),s=se(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const pc={deepseek:"dsh"};function yc(t){const a=typeof t=="string"?t:"";return pc[a]||a}const bc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"];function ms(t,a){for(const r of bc)t[r]=(Number(t[r])||0)+(Number(a?.[r])||0);t.total_cost_usd=String(Number(t.total_cost_usd||0)+Number(a?.total_cost_usd||0))}function hs(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,total_cost_usd:"0"}}function kc(t){const a=new Map;for(const r of t||[]){const s=yc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:hs(),models:new Map},a.set(s,n)),ms(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let u=n.models.get(o);u||(u={model:i?.model||o,model_id:o,totals:hs()},n.models.set(o,u)),ms(u.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function wc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=kc(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const u=Nt(o?.totals),c=se(o?.totals?.total_cost_usd)??0;return{source:o?.source,totalTokens:Number.isFinite(u)?u:0,totalCost:Number.isFinite(c)?c:0,inputTokens:Math.max(0,se(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,se(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,se(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0);if(!n.length)return[];const i=n.reduce((o,u)=>o+u.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,u)=>u.totalTokens-o.totalTokens).map(o=>{const u=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),c=i>0?o.totalTokens/i*100:0,h=Number.isFinite(c)?c.toFixed(2):"0.00",m=o.models.map(y=>{const k=Nt(y?.totals);if(!Number.isFinite(k)||k<=0)return null;const f=o.totalTokens>0?Math.round(k/o.totalTokens*1e3)/10:0,v=cn(y,r("shared.placeholder.short")),w=fc(y),D=se(y?.totals?.total_cost_usd),C=D??(o.totalCost>0&&o.totalTokens>0?k/o.totalTokens*o.totalCost:null);return{id:w,name:v,share:f,usage:k,cost:C}}).filter(Boolean),x=o.inputTokens+o.cacheRead+o.cacheCreate,p=o.cacheRead+o.cacheCreate>0&&x>0?Math.round(o.cacheRead/x*100):null;return{source:o.source,label:u,totalPercent:String(h),totalPercentValue:c,usd:o.totalCost,usage:o.totalTokens,cacheHitRate:p,cacheReusedTokens:o.cacheRead,cacheInputTokens:x,models:m}})}function _c(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const u=Array.isArray(o?.models)?o.models:[];for(const c of u){const h=se(c?.usage);if(h==null||h<=0)continue;const m=typeof c?.name=="string"&&c.name.trim()?c.name.trim():typeof c?.id=="string"&&c.id.trim()?c.id.trim():null;m&&s.push({model:c,name:m,usage:h})}}const n=dn(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:u,usage:c}of s){const h=un(u,n);if(!h)continue;const{key:m}=h,x=r.get(m)||{id:m,name:h.name,usage:0,cost:0,hasCost:!1,nameWeight:0};x.usage+=c;const g=se(o?.cost);g!=null&&(x.cost+=g,x.hasCost=!0),n.has(m)?x.name=n.get(m):c>=x.nameWeight&&(x.name=u,x.nameWeight=c),r.set(m,x)}const i=Array.from(r.values()).reduce((o,u)=>o+u.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,cost:o.hasCost?o.cost:null,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,u)=>u.usage!==o.usage?u.usage-o.usage:String(o.name).localeCompare(String(u.name)))}function vc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:y=>y,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const i=new Map,o=new Map,u=new Map,c=[];let h=0;for(const y of n){const k=Array.isArray(y?.models)?y.models:[];for(const f of k){const v=Nt(f?.totals);if(!Number.isFinite(v)||v<=0)continue;h+=v;const w=cn(f,s("shared.placeholder.short"));c.push({name:w,tokens:v})}}const m=dn(c.map(y=>({name:y.name,weight:y.tokens})));for(const{name:y,tokens:k}of c){const f=un(y,m);if(!f)continue;const{key:v}=f;i.set(v,(i.get(v)||0)+k),m.has(v)?o.set(v,m.get(v)):k>=(u.get(v)||0)&&(u.set(v,k),o.set(v,y))}if(!i.size)return[];const x=Array.from(i.values()).reduce((y,k)=>y+k,0),g=h>0?h:x,p=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([y,k])=>{const f=g>0?(k/g*100).toFixed(1):"0.0";return{id:y,name:o.get(y)||s("shared.placeholder.short"),tokens:k,percent:String(f)}}).sort((y,k)=>k.tokens!==y.tokens?k.tokens-y.tokens:String(y.name).localeCompare(String(k.name))).slice(0,p)}function jc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Sa(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function gs(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Gt(a);return(a===qs?t:t*r)<.01?`<${s}0.01`:Sa(t,{decimals:2,currency:a,rate:r})}function xs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Qe(a,{decimals:1})}const Nc=_t.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=Ca(),o=d.useMemo(()=>(Array.isArray(s)?s:[]).map(c=>{const h=se(c?.usd)??0,m=se(c?.usage)??0,x=Array.isArray(c?.models)?c.models:[];return{label:c?.label?String(c.label):"",usdValue:h,costLabel:gs(h,n,i),tokensLabel:xs(m),models:x.map(g=>{const p=se(g?.usage)??0,y=se(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:xs(p),costLabel:gs(y,n,i),sortCost:y}}).filter(g=>g.costLabel||g.tokensLabel).sort((g,p)=>p.sortCost-g.sortCost)}}).filter(c=>c.usdValue>0||c.models.length>0).sort((c,h)=>h.usdValue-c.usdValue),[s,n,i]),u=d.useMemo(()=>{const c=o.reduce((h,m)=>h+m.usdValue,0);return jc(c,n,i)},[o,n,i]);return e.jsx(Ji,{open:a,onOpenChange:c=>{c||r?.()},children:e.jsxs(Qi,{children:[e.jsx(Xi,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(el,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(tl,{className:"cost-modal-popup relative w-full max-w-[460px] max-h-[calc(100vh-2rem)] flex flex-col rounded-2xl bg-white dark:bg-oai-gray-950 shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)] ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden",children:[e.jsx(al,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(rl,{type:"button",className:"absolute top-3 right-3 flex h-9 w-9 items-center justify-center rounded-md text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-100 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50 transition-colors z-10","aria-label":l("dashboard.cost_breakdown.close"),children:e.jsx(jr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:u}),o.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),o.map((c,h)=>{const m=`fleet-${h}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":m,className:h>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:m,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:c.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:c.costLabel||"—"})]}),c.models.map((x,g)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsx("span",{role:"cell",className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400 truncate leading-none",title:x.name,children:x.name}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:x.costLabel||""})]},x.id||`${x.name}-${g}`))]},`${c.label}-${h}`)})]})]})})]})})]})})});function Sc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[h,m]=d.useState(null),x=ut();return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}let g=!0;return c(!0),m(null),si({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(p=>{g&&o(p||null)}).catch(p=>{g&&(m(p?.message||String(p)),o(null))}).finally(()=>{g&&c(!1)}),()=>{g=!1}},[t,a,r,s,n,x]),{data:i,loading:u,error:h}}function mn(t){if(typeof t!="string"||!t)return{owner:"",repo:""};const a=t.indexOf("/");return a<0?{owner:"",repo:t}:{owner:t.slice(0,a),repo:t.slice(a+1)}}function hn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function gn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function xn(t,a){return a&&gn(hn(t))==="github"?a:""}function fn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=d.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const fs="#10b981",er=[{key:"input_tokens",labelKey:"dashboard.projects.detail.comp_input",color:"#38bdf8"},{key:"cached_input_tokens",labelKey:"dashboard.projects.detail.comp_cached",color:"#14b8a6"},{key:"cache_creation_input_tokens",labelKey:"dashboard.projects.detail.comp_cache_write",color:"#f59e0b"},{key:"output_tokens",labelKey:"dashboard.projects.detail.comp_output",color:"#a78bfa"},{key:"reasoning_output_tokens",labelKey:"dashboard.projects.detail.comp_reasoning",color:"#fb7185"}],tr=60;function Cc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(g=>[g.day,g]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const u=t[t.length-1].day;o<u&&(o=u);const c=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(c.getTime())||!Number.isFinite(h.getTime()))return t;const m=Math.round((h.getTime()-c.getTime())/864e5)+1;m>tr&&c.setUTCDate(c.getUTCDate()+(m-tr));const x=[];for(;c.getTime()<=h.getTime()&&x.length<tr;){const g=c.toISOString().slice(0,10);x.push(n.get(g)||{day:g,total_tokens:0,billable_total_tokens:0}),c.setUTCDate(c.getUTCDate()+1)}return x}function ar(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function wt({label:t,value:a,title:r}){return e.jsxs("div",{className:"flex flex-col gap-1.5 group min-w-0",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:t}),e.jsx("span",{className:"text-xl font-black font-mono text-zinc-900 dark:text-zinc-50 tracking-tight leading-none tabular-nums truncate transition-transform duration-200 group-hover:-translate-y-[1px]",title:r,children:a})]})}function Tc({host:t}){if(!t)return null;let a;const r=gn(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(wl,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function rr({children:t}){return e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500 select-none",children:t})}function Ac({entry:t,query:a={},onClose:r}){const[s,n]=_t.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:u}=mn(i),c=typeof t?.project_ref=="string"?t.project_ref:"",h=hn(c),{data:m,loading:x,error:g}=Sc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:p,formatTokensTooltip:y}=Fe(),k=_t.useCallback(()=>n(!0),[]),f=L=>{L.target===L.currentTarget&&s&&r()};_t.useEffect(()=>{const L=B=>{B.key==="Escape"&&k()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[k]);const v=m?.totals||null,w=se(v?.billable_total_tokens)??0,D=Number(m?.days_active||0),C=se(v?.input_tokens)??0,R=se(v?.cached_input_tokens)??0,A=C+R>0?R/(C+R):null,P=se(m?.range_total_tokens)??0,N=se(v?.total_tokens)??0,j=P>0?N/P:null,S=_t.useMemo(()=>Cc(m?.daily,m?.from,m?.to,vr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[m,a.timeZone,a.tzOffsetMinutes]),E=er.reduce((L,B)=>L+(se(v?.[B.key])??0),0),O=Array.isArray(m?.sources)?m.sources:[],F=!x&&!g&&v&&N>0;return e.jsx("div",{onAnimationEnd:f,onClick:L=>{L.target===L.currentTarget&&k()},className:jt("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i,className:jt("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:k,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(jr,{size:16})}),e.jsxs("div",{className:"w-full md:w-[300px] shrink-0 border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-5 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:fs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:fs}})]}),e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:l("dashboard.projects.detail.badge")})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3 min-w-0",children:[e.jsx(fn,{githubOwner:xn(c,o),letter:(u?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:u||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(Tc,{host:h}),h&&m?.from&&m?.to?e.jsx("span",{children:"·"}):null,m?.from&&m?.to?e.jsxs("span",{className:"tabular-nums",children:[m.from," – ",m.to]}):null]})]}),F?e.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-t border-zinc-200/50 dark:border-zinc-800/50 pt-5 select-none",children:[e.jsx(wt,{label:l("dashboard.projects.detail.stat_total"),value:p(w),title:y(w)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_share"),value:j==null?"—":ar(j)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":ar(A)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_conversations"),value:va(v.conversation_count)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_active_days"),value:va(D)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_avg_day"),value:D>0?p(Math.round(w/D)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[x&&e.jsxs("div",{className:"space-y-4 p-5 md:p-6",children:[e.jsx("div",{className:"h-32 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-24 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"})]}),!x&&g&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!x&&!g&&!F&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.empty_range")}),F&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[S.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(Xs,{embedded:!0,rows:S,from:S[0]?.day,to:S[S.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),E>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:er.map(L=>{const B=se(v[L.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/E*100}%`,backgroundColor:L.color,minWidth:"2px"}},L.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:er.map(L=>{const B=se(v[L.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:L.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(L.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(B),children:p(B)})]},L.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(L=>{const B=Number(L.total_tokens||0),K=N>0?B/N:0,q=K*100,_=Number(L.conversation_count||0),$=Ei(L.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Ct,{provider:L.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:vt(L.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(L.days_active||0)}),_>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:_})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(B),children:p(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:ar(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(q,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:$}})})]},L.source)})})]})]})]})]})})}function Dc(t){return e.jsx(ni,{mode:Kt.COMPACT,children:e.jsx(Ac,{...t})})}const Lc=5;function Mc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",u=typeof t?.project_ref=="string"?t.project_ref:"",{owner:c,repo:h}=mn(o),m=xn(u,c),x=se(t?.billable_total_tokens??t?.total_tokens)??0,g=a>0?Math.min(100,Math.max(2,x/a*100)):0,p=Array.isArray(t?.sources)?t.sources:[],y=p.slice(0,Lc),k=p.length-y.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(fn,{githubOwner:m,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[c?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[c,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:h||o||"—"})]}),y.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[y.map(f=>e.jsx(Ct,{provider:f.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},f.source)),k>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:k})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(x),children:s(x)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${g}%`,minWidth:x>0?"3px":0}})})]})]})}function Ec({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:u,dailyEmptySuffix:c,detailsColumns:h,ariaSortFor:m,toggleSort:x,sortIconFor:g,pagedDetails:p,dailyBreakdownRows:y=[],dailyBreakdownColumns:k=[],dailyBreakdownAriaSortFor:f,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:w="day",detailsDateKey:D,renderDetailDate:C,renderDailyBreakdownDate:R,renderDetailCell:A,DETAILS_PAGED_PERIODS:P,period:N,detailsPageCount:j,detailsPage:S,setDetailsPage:E}){const[O,F]=d.useState("daily"),[L,B]=d.useState(null),{formatTokens:K,formatTokensTooltip:q}=Fe();return e.jsxs(De,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":O==="daily",type:"button",onClick:()=>F("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":O==="projects",type:"button",onClick:()=>F("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),O==="projects"&&e.jsx(tn,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:_=>r?.(Number(_)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),O==="projects"&&(()=>{const _=t.slice(0,a);if(_.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const $=_.reduce((H,te)=>{const ue=se(te?.billable_total_tokens??te?.total_tokens)??0;return ue>H?ue:H},0);return e.jsx("div",{className:"space-y-1",children:_.map((H,te)=>e.jsx(Mc,{entry:H,maxTokens:$,copy:n,formatTokens:K,formatTokensTooltip:q,onSelect:B},H?.project_key||H?.project_ref||`entry-${te}`))})})(),L&&e.jsx(Dc,{entry:L,query:s,onClose:()=>B(null)}),O==="daily"&&e.jsxs("div",{children:[y?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:u}),c]}):e.jsx("div",{className:"overflow-auto max-h-[384px] -mx-4 oai-scrollbar",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsx("tr",{className:"border-b border-oai-gray-200 dark:border-oai-gray-700",children:k.map(_=>e.jsx("th",{"aria-sort":f?.(_.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>x(_.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:_.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(_.key)||""})]})})},_.key))})}),e.jsx("tbody",{children:y.map(_=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${_.missing?"text-oai-gray-400 dark:text-oai-gray-400":_.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:R?R(_):C(_)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(_,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"conversation_count")})]},String(_?.[w]||_?.day||_?.hour||_?.month||"")))})]})}),O!=="daily"&&P.has(N)&&j>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>E(_=>Math.max(0,_-1)),disabled:S===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[S+1," / ",j]}),e.jsx("button",{type:"button",onClick:()=>E(_=>Math.min(j-1,_+1)),disabled:S+1>=j,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function _a(t){return typeof t!="string"?"":t.trim()}function ps(t){const a=_a(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Ic(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=_a(r.tool),n=_a(r.planType)||_a(r.plan_type);if(!s||!n)continue;const i=ps(s)||s,o=ps(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function Rc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:u}=Fe(),c=l("shared.placeholder.short"),h=l("shared.unit.percent"),m=t??l("identity_card.rank_placeholder"),x=Number.isFinite(Number(a))?Number(a):0,g=x?l("identity_card.streak_value",{days:x}):l("identity_card.rank_placeholder"),p=Ic(r),y={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev")},k=w=>{if(w==null)return c;const D=Qe(w,y);return D==="-"?c:D},f={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=i.slice(0,3);return e.jsxs(De,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.convs})]})]}),v.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:v.map((w,D)=>{const C=w?.name?String(w.name):c,R=w?.percent?String(w.percent):"",A=D===v.length-1,P=D+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:P}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:C,children:C}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[R,h]})]},w.id||C)})}),p.length>0&&e.jsx("div",{className:"mt-3 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex flex-wrap gap-1.5",children:p.map((w,D)=>e.jsxs(Ll,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${D}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:g})]})]})]})}let pa=null;function Fc(){if(pa===null)try{pa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{pa=!1}return pa}function $c(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,u=t-.1055613458*n-.0638541728*i,c=t-.0894841775*n-1.291485548*i,h=o*o*o,m=u*u*u,x=c*c*c;return[4.0767416621*h-3.3077115913*m+.2309699292*x,-1.2684380046*h+2.6097574011*m-.3413193965*x,-.0041960863*h-.7034186147*m+1.707614701*x].map(p=>{const y=Math.min(1,Math.max(0,p)),k=y<=.0031308?12.92*y:1.055*Math.pow(y,1/2.4)-.055;return Math.round(k*255)})}function pn(t,a,r,s){if(Fc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=$c(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?pn(Number(a[1]),Number(a[2]),Number(a[3])):t}const ys={claude:35,codex:250,grok:200},bs={system_prompt:{l:.55,c:.05},messages:{l:.65,c:.18},tool_calls:{l:.6,c:.14},custom_agents:{l:.55,c:.1},reasoning:{l:.7,c:.08}};function Pc(t,a){const r=ys[a]??ys.claude,s=bs[t]||bs.system_prompt;return pn(s.l,s.c,r)}const Bc=[{key:"system_prompt",from:["system_prefix"]},{key:"messages",from:["user_input","conversation_history","assistant_response"]},{key:"tool_calls",from:["tool_calls"]},{key:"custom_agents",from:["subagents"]},{key:"reasoning",from:["reasoning"]}],zc=[["by_type","dashboard.context_breakdown.exec_details.group_by_type"],["by_executable","dashboard.context_breakdown.exec_details.group_by_executable"],["by_command","dashboard.context_breakdown.exec_details.group_by_command"],["by_duration","dashboard.context_breakdown.exec_details.group_by_duration"],["by_output","dashboard.context_breakdown.exec_details.group_by_output"],["by_exit","dashboard.context_breakdown.exec_details.group_by_exit"]],Oc={duration:.18,ease:[.4,0,.2,1]},Uc={height:0,opacity:0},Hc={height:"auto",opacity:1},Vc={height:0,opacity:0};function Kc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function Wc(t,a){const r={};for(const s of["input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens","total_tokens"])r[s]=Math.round(Number(t?.[s]||0)*a);return r}function yn(t,a=null){const r=t.reduce((o,u)=>o+Number(u.totals.total_tokens||0),0),s=Kc(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const u=i===1?o.totals:Wc(o.totals,i);return{...o,totals:u,percent:n>0?Number((u.total_tokens/n*100).toFixed(2)):0}}).sort((o,u)=>u.totals.total_tokens-o.totals.total_tokens)}function Gc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=Bc.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const u=r.get(o);if(!u)continue;const c=u.totals||{};i.input_tokens+=c.input_tokens||0,i.cached_input_tokens+=c.cached_input_tokens||0,i.cache_creation_input_tokens+=c.cache_creation_input_tokens||0,i.output_tokens+=c.output_tokens||0,i.reasoning_output_tokens+=c.reasoning_output_tokens||0,i.total_tokens+=c.total_tokens||0}return{key:n.key,totals:i}});return yn(s,a)}function qc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,m)=>m?.name==="Text Response"?h:h+Number(m?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),c=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return yn(c,a)}const ks="MCP: ";function Yc(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(ks)?(a.push({...n,name:i.slice(ks.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function ws(t){return l(`dashboard.context_breakdown.category.${t}`)}function Zc(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function Jc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),u=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:Zc(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(u||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function Qc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),u=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:u,total_tokens:Number(r.total_tokens||n+i)},tools:Jc(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Xc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function ed(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{};return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),total_tokens:Number(r.total_tokens||0)}}).filter(a=>a.name).sort((a,r)=>Number(r.total_tokens||0)-Number(a.total_tokens||0))}function td(t){if(t?.key){const a=l(`dashboard.context_breakdown.message_details.${t.key}`);if(a&&!a.includes("dashboard.context_breakdown"))return a}return t?.name||""}function ad(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function _s(t){const a=Number(t||0);return!Number.isFinite(a)||a<=0?"0ms":a<1e3?`${Math.round(a)}ms`:a<6e4?`${(a/1e3).toFixed(1)}s`:`${Math.round(a/1e3)}s`}function rd(t,a){return t?a==="by_executable"?t.by_executable||[]:a==="by_command"?t.by_command||[]:a==="by_duration"?t.by_duration||[]:a==="by_output"?t.by_output||[]:a==="by_exit"?t.by_exit||[]:t.by_type||[]:[]}function vs(t){return t==="exec_command"||t==="Bash"}function bn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function sd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function nd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const od=10;function Je({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:u,tokens:c,percent:h=null,children:m,share:x=null,fillColor:g=null}){const p=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",y=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:od},"aria-hidden":!a,children:a}),k=e.jsxs(e.Fragment,{children:[y,e.jsx("span",{className:p,children:r}),s,i&&e.jsx(ve.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(ii,{size:11})})]}),f=g&&x!=null&&x>0,v=f?Math.max(0,Math.min(100,x)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:f?{backgroundImage:`linear-gradient(to right, ${g.replace(/\)\s*$/," / 0.10)")} 0%, ${g.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:u,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:k}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:k}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:c||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:h||""})]}),i&&m?e.jsx(Ta,{initial:!1,children:o&&e.jsx(ve.div,{initial:Uc,animate:Hc,exit:Vc,transition:Oc,style:{overflow:"hidden"},children:m},"content")}):null]})}function js({execDetails:t,source:a="claude"}){const{formatTokens:r}=Fe(),[s,n]=d.useState("by_type"),i=ad(rd(t,s)),o=a==="codex"||a==="grok",u=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:zc.map(([c,h])=>e.jsx("button",{type:"button",onClick:()=>n(c),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===c?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(h)},c))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${u} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((c,h)=>e.jsxs(ve.div,{role:"row",className:`grid ${u} gap-2 py-1.5`,title:c.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:c.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.failures||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:_s(c.duration_ms||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:_s(c.max_duration_ms||0)})]}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:r(c.totals.total_tokens||0)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.output_lines||0)})]},c.name))]})})]})}function Ht({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Fe(),[i,o]=d.useState({}),[u,c]=d.useState(!1),h=Qc(t?.categories||[]);function m(x){o(g=>({...g,[x]:!g[x]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(bn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(x=>{const g=x.toolCount>0,p=x.name==="Execution"&&a,y=p&&x.tools.some(f=>vs(f.name)),k=!!i[x.name];return e.jsxs(Je,{level:1,label:x.name,labelTone:"strong",hasChevron:g||p&&!y,open:k||p&&!y&&u,onToggle:()=>{g?m(x.name):p&&!y&&c(f=>!f)},tokens:n(x.totals.total_tokens||0),percent:null,children:[g&&e.jsx("ul",{className:"space-y-0.5",children:x.tools.map(f=>{const v=p&&vs(f.name);return e.jsx(Je,{level:2,label:f.name,labelTone:v?"accent":"default",hasChevron:v,open:u,onToggle:()=>c(w=>!w),tokens:n(f.total_tokens||0),percent:null,children:v&&e.jsx(js,{execDetails:a,source:r})},f.name)})}),p&&!y&&e.jsx(js,{execDetails:a,source:r})]},x.name)})})}function id({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:i}=Fe(),[o,u]=d.useState(null),[c,h]=d.useState(!1),[m,x]=d.useState(null),[g,p]=d.useState({}),y=d.useRef({});function k(_){p($=>({...$,[_]:!$[_]}))}if(d.useEffect(()=>{let _=!1;const $=`${t||""}|${a||""}|${r||"claude"}`,H=y.current[$];return u(H||null),h(!0),n?.(!0),x(null),oi({from:t,to:a,source:r,timeZone:Zs(),tzOffsetMinutes:Ys()}).then(te=>{_||(y.current[$]=te,u(te))}).catch(te=>{_||x(te?.message||String(te))}).finally(()=>{_||(h(!1),n?.(!1))}),()=>{_=!0}},[t,a,r]),c&&!o)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(_=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${_*80}ms`}},_))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(m)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(sd(r))});if(!o||o.scope!=="supported"||!o.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(bn(r))});const f=r==="claude"?Gc(o.categories||[],s):qc(o,s),v=o.tool_calls_breakdown||null,w=o.skills_breakdown||null,D=o.message_breakdown||null,C=o.configured_resources||null,R=o.exec_command_breakdown||null,A=ed(w?.skills||[]),P=Xc(D?.categories||[]),N=r==="codex"&&(o?.breakdown_status==="queue_fallback"||o?.fallback==="queue_totals"),j=r==="claude"?v?.tool_calls||null:v||null,{mcpSet:S,residualSet:E,mcpTotalTokens:O}=Yc(j),F=r==="claude"&&v?.subagents||null,L=F?.categories?.length>0||(C?.custom_agents_count||0)>0,B=r==="claude"?(E?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,K=r==="claude"?(F?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,q=[...f].sort((_,$)=>($.totals?.total_tokens||0)-(_.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:f.filter(_=>_.percent>0).filter(_=>!(r==="claude"&&(_.key==="tool_calls"||_.key==="custom_agents"))).map(_=>`${ws(_.key)} ${_.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[q.map(_=>{const $=_.key==="system_prompt",H=_.key==="messages",te=_.key==="tool_calls",ue=_.key==="custom_agents";if(_.key,r==="claude"&&(te||ue))return null;const W=H&&P.length>0||te&&(E?.categories?.length>0||N)||ue&&L&&F,ne=!!g[_.key],oe=Pc(_.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:oe},"aria-hidden":"true"}),be=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(sn,{size:11,className:"text-oai-gray-400 dark:text-oai-gray-500 cursor-help","aria-hidden":"true"}),e.jsx("span",{role:"tooltip",className:"pointer-events-none absolute left-1/2 bottom-full z-20 mb-1.5 -translate-x-1/2 w-64 rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 px-2.5 py-1.5 text-[11px] leading-snug text-oai-gray-700 dark:text-oai-gray-200 shadow-md opacity-0 group-hover:opacity-100 transition-opacity",children:l("dashboard.context_breakdown.system_prefix_tooltip")})]}):null,Le=_.percent>0?`${_.percent.toFixed(_.percent<.1&&_.percent>0?2:1)}%`:"0.0%";return e.jsxs(Je,{level:0,colorSquare:je,label:ws(_.key),labelSuffix:be,tokens:i(_.totals?.total_tokens||0),percent:Le,hasChevron:W,open:ne,onToggle:()=>k(_.key),share:_.percent,fillColor:oe,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:P.map(X=>e.jsx(Je,{level:1,label:td(X),tokens:i(X.totals.total_tokens||0),percent:null},X.key||X.name))}),te&&E&&e.jsx(Ht,{toolSet:E,execDetails:R,source:r,codexQueueFallback:N}),te&&N&&!E&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),ue&&F&&e.jsx(Ht,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})]},_.key)}),r==="claude"&&E?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:i(B),percent:null,hasChevron:!0,open:!!g.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Ht,{toolSet:E,execDetails:R,source:r,codexQueueFallback:!1})}),r==="claude"&&F?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:i(K),percent:null,hasChevron:!0,open:!!g.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Ht,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})}),S?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:i(O),percent:null,hasChevron:!0,open:!!g.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Ht,{toolSet:S,execDetails:null,source:r,codexQueueFallback:!1})}),A.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:i(A.reduce((_,$)=>_+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!g.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:A.slice(0,12).map(_=>e.jsx(Je,{level:1,label:_.name,tokens:i(_.total_tokens),percent:null},_.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(nd(r))}),N?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,C?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Qe(C.skills_count||0)," skills ·"," ",Qe(C.mcp_servers_count||0)," MCP servers ·"," ",Qe(C.custom_agents_count||0)," agents ·"," ",Qe(C.memory_files_count||0)," memory files"]}):null]})}function kn({size:t=15,className:a=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:a,"aria-hidden":"true",children:[e.jsx("path",{d:"M12 1.6 23 7.4 12 13.2 1 7.4 12 1.6Z"}),e.jsx("path",{d:"m4 10.3-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.72"}),e.jsx("path",{d:"m4 14.6-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.45"})]})}const nt="__all__",ld=`${100 .toFixed(2)}%`;function qt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function xr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Gt(a);return(a===qs?s:s*r)<.01?`<${n}0.01`:Sa(s,{decimals:2,currency:a,rate:r})}function cd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Ns(a)}:{key:a.key,label:a.label||Ns(a.key)}):[]}function dd(t){if(typeof t!="string")return null;const a=t.replace(/,/g,"").match(/-?\d+(?:\.\d+)?/);if(!a)return null;const r=Number(a[0]);return Number.isFinite(r)?r:null}const ud={ACODE:"var(--brand-primary-light)",CODEX:"#3b82f6",DSH:"var(--community-deepseek)",CLAUDE:"#d97757",OPENCODE:"#f59e0b",GEMINI:"#2196f3",KIMI:"#a78bfa","KILO-CLI":"#facc15","KILO-CODE":"#facc15",MIMO:"#ff6900",DROID:"#ef4444",ZCODE:"#14b8a6",ANYTHINGLLM:"var(--provider-anythingllm)",LMSTUDIO:"var(--provider-lmstudio)",UNSLOTH:"var(--provider-unsloth)"};function sr(t,a){const r=t?.toUpperCase?.()||"";return ud[r]||`hsl(${150+a*40}, 60%, 45%)`}function md(t){const a=String(t?.source||"").trim().toLowerCase(),r=String(t?.label||"").trim().toLowerCase();return a==="claude"||r==="claude"?"claude":a==="codex"||r==="codex"?"codex":a==="grok"||r==="grok"||r.includes("grok")?"grok":null}function hd(t){return t==="claude"?l("dashboard.context_breakdown.heading_claude"):t==="codex"?l("dashboard.context_breakdown.heading_codex"):t==="grok"?l("dashboard.context_breakdown.heading_grok"):l("dashboard.context_breakdown.heading")}function gd(t){return!!t?.models?.length}function wn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function nr(t){const a=wn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const xd={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Ns(t){const a=xd[t];return a?l(a):String(t).toUpperCase()}function fd({loading:t,onClick:a}){const r=Nr();return e.jsx(ci,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(ve.span,{"aria-hidden":"true",animate:t?{rotate:360}:{rotate:0},transition:t&&!r?{duration:1,repeat:1/0,ease:"linear"}:{duration:.3},style:{display:"inline-flex"},children:e.jsx(di,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function pd(){return e.jsx("div",{"data-testid":"usage-summary-skeleton","aria-hidden":"true",className:"mx-auto h-[58px] sm:h-[72px] w-[min(72vw,18rem)] rounded-2xl bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"})}function yd(){return e.jsxs("div",{"data-testid":"usage-provider-skeleton","aria-hidden":"true",className:"space-y-6",children:[e.jsx("div",{className:"h-1.5 w-full rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[0,1,2,3].map(t=>e.jsx("div",{className:"h-[92px] rounded-xl border border-oai-gray-100 dark:border-oai-gray-800 bg-oai-gray-50 dark:bg-oai-gray-800/60 animate-pulse motion-reduce:animate-none",style:{animationDelay:`${t*70}ms`}},t))})]})}function bd({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:u,onCostInfo:c,fleetData:h=[],onRefresh:m,loading:x,announceLoading:g=!1,summaryLoading:p=!1,providersLoading:y=!1,hasSummary:k=!0,className:f="",customFrom:v,customTo:w,onCustomRangeApply:D,customRangeOpen:C,onCustomRangeOpenChange:R,onOpenShare:A,from:P,to:N,deviceOptions:j=[],selectedDevice:S="",onDeviceChange:E}){const O=cd(a),F=Ri(ui()),L=dd(String(s??"")),B=t==="week"&&typeof P=="string"&&typeof N=="string"&&P.slice(0,7)!==N.slice(0,7),K=P&&N?`${xa(P,F)} — ${xa(N,F)}`:null,q=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[_,$]=d.useState(q);d.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const T=window.matchMedia("(max-width: 639px)"),z=he=>$(he.matches);return T.addEventListener("change",z),()=>T.removeEventListener("change",z)},[]);const H=L!=null&&!_,te=d.useRef(null);d.useEffect(()=>{const T=te.current?.querySelector('[aria-selected="true"]');T&&typeof T.scrollIntoView=="function"&&T.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,W]=d.useState(null),{resolvedTheme:ne}=li(),{currency:oe,rate:je}=Ca(),{formatTokens:be}=Fe(),Le=ne==="dark",X=Le?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Le?"rgba(10,10,10,0)":"rgba(255,255,255,0)",re=p&&!k,ee=y&&!h.some(gd);d.useEffect(()=>{W(null)},[t,P,N,S]);const ae=T=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(T.key))return;const z=Array.from(T.currentTarget.querySelectorAll('[role="tab"]')).filter(de=>!de.disabled),he=z.indexOf(T.target.closest('[role="tab"]'));if(he===-1||z.length===0)return;T.preventDefault();let V=he;T.key==="Home"?V=0:T.key==="End"?V=z.length-1:T.key==="ArrowRight"?V=(he+1)%z.length:V=(he-1+z.length)%z.length,z[V].focus(),z[V].click()},ye=H?e.jsx(Bl,{value:L,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Le?0:8,gradientFrom:X,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,Y=h.filter(T=>T.models?.length>0),J=Y.some(T=>String(T?.source||T?.label||"").trim().toLowerCase()==="devin"),Z=d.useMemo(()=>_c(h),[h]),ge=Z.reduce((T,z)=>T+(Number(z.usage)||0),0),$e=Y.reduce((T,z)=>T+(Number(z.usd)||0),0),me=ue==null?null:ue===nt||Y.some(function(z){return z.label===ue})?ue:null;return e.jsx(De,{className:f,children:e.jsxs("div",{"aria-busy":x||re||ee,children:[g?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:te,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:ae,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(T=>{const z=t===T.key,he=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${z?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(T.key==="custom"){const V=z&&v&&w?`${xa(v,F)} — ${xa(w,F)}`:T.label;return e.jsxs(nl,{open:C,onOpenChange:de=>{de?r?.("custom"):R?.(de)},children:[e.jsx(ol,{render:e.jsx("button",{role:"tab","aria-selected":z,tabIndex:z?0:-1,type:"button",className:he}),children:V}),e.jsx(il,{children:e.jsx(ll,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(cl,{className:"bg-white dark:bg-oai-gray-900 border border-oai-gray-200 dark:border-oai-gray-700 rounded-xl shadow-lg",children:e.jsx(Ii,{from:v,to:w,onApply:D,onCancel:()=>R?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":z,tabIndex:z?0:-1,type:"button",className:he,onClick:()=>r?.(T.key),children:T.label},T.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[j.length>1?e.jsx(tn,{value:S,onValueChange:E,options:j,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Nl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,m&&e.jsx(fd,{loading:x,onClick:m})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:re?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:ye}):e.jsx("span",{title:n||void 0,children:ye})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${re?"":"hidden"}`,children:e.jsx(pd,{})})]}),u&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:c?e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[u,e.jsx(sn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:u})}),K?e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-1 text-[11px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{className:"tabular-nums",children:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(yd,{})}),Y.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:Y.map(T=>l("usage.overview.distribution_item",{label:vt(T.label),percent:nr(T)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:Y.map((T,z)=>{const he=sr(T.label,z),V=vt(T.label),de=nr(T);return e.jsx(ve.div,{initial:{width:0},animate:{width:`${wn(T)}%`},transition:{duration:.5,delay:.45+z*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:he},title:`${V}: ${de}%`},T.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":me===nt,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:qt(be,ge)||String(0),cost:xr($e,oe,je)||`${Gt(oe)}0`,count:Z.length}),onClick:()=>W(me===nt?null:nt),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${me===nt?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(kn,{size:15,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",children:l("usage.overview.all_tools")})]}),e.jsx("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:ld}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:Z.length})})]}),Y.map((T,z)=>{const he=sr(T.label,z),V=me===T.label,de=vt(T.label),Ce=nr(T);return e.jsxs("button",{"aria-expanded":V,"aria-controls":`provider-details-${T.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:de,percent:Ce,tokens:qt(be,T.usage)||String(0),cost:xr(T.usd,oe,je)||`${Gt(oe)}0`,action:l(V?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>W(V?null:T.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${V?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(Ct,{provider:T.label,size:15,color:he,className:"text-oai-gray-700 dark:text-oai-gray-300 shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",title:de,children:de})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[Ce,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:T.models.length})})]},T.label)})]}),me===nt&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[J&&e.jsx(vn,{}),e.jsx(kd,{models:Z})]}),me!=null&&me!==nt&&e.jsx("div",{id:`provider-details-${me}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:me}),className:"mt-2",children:Y.filter(T=>T.label===me).map(T=>{const z=sr(T.label,0),he=md(T),V=[...T.models].sort((Ce,Ne)=>(Ne.share||0)-(Ce.share||0)),de=he?hd(he):vt(T.label);return e.jsx(wd,{provider:T,color:z,providerHeading:de,contextSource:he,from:P,to:N,sortedModels:V},T.label)})})]})]})})}function _n({models:t,color:a}){const{currency:r,rate:s}=Ca(),{formatTokens:n,formatTokensTooltip:i}=Fe();return e.jsx("div",{className:"space-y-3",children:t.map(o=>{const u=qt(n,o.usage),c=xr(o.cost,r,s),h=Math.max(0,Math.min(100,Number(o.share)||0));return e.jsxs("div",{"data-model-rank-row":!0,children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_4rem] items-baseline gap-x-3 mb-1.5",children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:o.name,children:o.name}),e.jsx("span",{title:i(o.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:u}),e.jsx("span",{className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:c}),e.jsxs("span",{className:"col-start-4 row-start-1 text-right whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[o.share,"%"]})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":h,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${h}%`,backgroundColor:a,opacity:.45}})})]},o.id||o.name)})})}function kd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(kn,{size:14,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("usage.overview.all_models")})]}),e.jsx("p",{className:"mb-4 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("usage.overview.all_models_note")}),e.jsx(_n,{models:t,color:"var(--oai-blue)"})]})}function vn(){return e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.devin_notice_title"),"."]})," ",l("usage.overview.devin_notice_body")]})}function wd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o}){const{formatTokens:u}=Fe(),[c,h]=d.useState(!1),m=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",x=String(t?.source||t?.label||"").trim().toLowerCase()==="devin";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Ct,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&c&&e.jsx(sl,{size:12,className:"text-oai-gray-400 dark:text-oai-gray-500 animate-spin shrink-0","aria-label":l("dashboard.context_breakdown.loading_aria")})]}),t.cacheHitRate!=null&&e.jsxs("p",{className:"mb-3 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:[e.jsx("span",{className:"font-medium text-oai-gray-600 dark:text-oai-gray-300",children:l("usage.overview.cache_hit_rate_label")})," ",e.jsxs("span",{className:"text-oai-black dark:text-oai-white",children:[t.cacheHitRate,"%"]})," · ",l("usage.overview.cache_hit_rate_detail",{reused:qt(u,t.cacheReusedTokens)||String(0),input:qt(u,t.cacheInputTokens)||String(0)})]}),m&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),x&&e.jsx(vn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(id,{from:n,to:i,source:s,referenceTotalTokens:t.usage,onLoadingChange:h})}):null,e.jsx(_n,{models:o,color:a})]})}function _d({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:u,isDragging:c}=Ui({id:t}),h=d.useRef(null),m=d.useRef(null);d.useLayoutEffect(()=>{if(!r)return;const g=h.current?h.current.childNodes.length===0:!0;m.current!==g&&(m.current=g,r(t,g))});const x={transform:Hi.Transform.toString(o)||void 0,transition:u,zIndex:c?20:void 0};return e.jsxs("div",{ref:i,style:x,className:jt("group/sortable relative has-[[data-sortable-body]:empty]:hidden",c&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:jt("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",c&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:h,"data-sortable-body":!0,className:jt("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",c&&"shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]"),children:a})]})}function vd({todayTokens:t=0,isSyncing:a=!1,hasError:r=!1,isDisconnected:s=!1}={}){return d.useMemo(()=>r?"error":s?"disconnected":a?"working-typing":t===0?"sleeping":t<5e4?"idle-living":t<2e5?"idle-look":t<5e5?"working-ultrathink":t<2e6?"working-typing":"working-ultrathink",[t,a,r,s])}const Ss="macAppBannerDismissed",jd="leaderboardBannerDismissed",Nd="https://github.com/xiufengsun/TokenTracker/releases/latest",Cs="tokentracker_native_app",ya=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Cs,"1"),!0):localStorage.getItem(Cs)==="1"}catch{return!1}})();function Sd({todayTokens:t=0,isSyncing:a=!1,enterDelay:r=0}){const{openLoginModal:s}=mi(),{signedIn:n}=Js(),i=vd({todayTokens:t,isSyncing:a}),o=ya?jd:Ss,[u,c]=d.useState(()=>{try{return localStorage.getItem(o)==="1"?!0:!ya&&new URLSearchParams(window.location.search).get("from")==="menubar"?(localStorage.setItem(Ss,"1"),!0):!1}catch{return!1}}),h=d.useCallback(()=>{c(!0);try{localStorage.setItem(o,"1")}catch{}},[o]);if(u)return null;let m,x,g,p,y,k;ya&&n?(m="View the Leaderboard",x="Compare your usage globally",g="Leaderboard",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M2 8.5V10h8V8.5M6 1.5v6m0 0L3.5 5M6 7.5l2.5-2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(180 6 6)"})}),y=()=>{window.location.pathname="/leaderboard"}):ya?(m="Join the Leaderboard",x="Log in to compare your usage with others",g="Log In",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6.5 1.5h3a1 1 0 011 1v7a1 1 0 01-1 1h-3M5 8.5L7.5 6 5 3.5M7.5 6H1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),y=s):(m="Try the Menu Bar App",x="Always-on stats with Clawd companion",g="Download",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6 2v6m0 0L3.5 5.5M6 8l2.5-2.5M2 10h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),k=Nd);const f=k?ve.a:ve.button,v=k?{href:k,target:"_blank",rel:"noopener noreferrer"}:{onClick:y};return e.jsx(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:r,ease:[.16,1,.3,1]},className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(dl,{state:i,size:56})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-900 dark:text-oai-white",children:m}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-0.5",children:x})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(f,{...v,whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[g,p]}),e.jsx("button",{onClick:h,className:"p-1 text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-300 transition-colors","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})})]})]})})}const Ts="widgetOnboardingDismissed",As="tokentracker_native_app",Cd=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(As,"1"),!0):localStorage.getItem(As)==="1"}catch{return!1}})();function Td({enterDelay:t=0}){const[a,r]=d.useState(()=>{try{return localStorage.getItem(Ts)==="1"}catch{return!1}}),s=d.useCallback(()=>{r(!0);try{localStorage.setItem(Ts,"1")}catch{}},[]);return!Cd||Qs()?null:e.jsx(Ta,{initial:!1,children:!a&&e.jsxs(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-8,transition:{duration:.2,ease:[.4,0,.2,1]}},transition:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:s,"aria-label":l("dashboard.widgets.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"rounded-lg overflow-hidden ring-1 ring-black/5 dark:ring-white/10 shadow-sm",children:e.jsx("img",{src:"/widgets-overview.png",alt:l("dashboard.widgets.title"),width:734,height:552,className:"w-full h-auto block",loading:"lazy",decoding:"async"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.widgets.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.widgets.hint")})]})]},"widget-onboarding-card")})}const Cr="islandOnboardingDismissed";function Ad(){try{return localStorage.getItem(Cr)==="1"}catch{return!1}}function Ds(){try{localStorage.setItem(Cr,"1")}catch{}}function Dd(){try{localStorage.removeItem(Cr)}catch{}}function Ld({className:t}){return e.jsxs("svg",{viewBox:"0 6 15 9",fill:"currentColor","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"2",y:"6",width:"11",height:"7"}),e.jsx("rect",{x:"0",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"13",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"3",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"5",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"9",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"11",y:"13",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"4",y:"8",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"10",y:"8",width:"1",height:"2"})]})}function Md({reduceMotion:t}){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-950 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 -top-12 h-36 w-56 rounded-full bg-indigo-600/25 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-2 h-32 w-48 rounded-full bg-sky-500/15 blur-3xl"}),e.jsx("div",{className:"absolute bottom-[-3rem] left-1/3 h-32 w-64 rounded-full bg-fuchsia-500/10 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[16px] items-center justify-between bg-black/45 px-2.5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-white/60"}),e.jsx("span",{className:"h-[3px] w-5 rounded-full bg-white/30"}),e.jsx("span",{className:"h-[3px] w-3.5 rounded-full bg-white/20"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-3 rounded-full bg-white/20"}),e.jsx("span",{className:"h-[3px] w-4 rounded-full bg-white/35"})]})]}),e.jsxs(ve.div,{className:"absolute left-1/2 top-0 flex h-[22px] -translate-x-1/2 items-center rounded-b-[10px] bg-black pl-2 pr-2.5 shadow-lg shadow-black/60 ring-1 ring-white/[0.06]",animate:t?void 0:{opacity:[1,.94,1]},transition:t?void 0:{duration:3.2,repeat:1/0,ease:"easeInOut"},children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(Ld,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),"8.2M"]}),e.jsx("span",{className:"mx-2 h-2.5 w-7 rounded-[2px] bg-black"}),e.jsx("span",{className:"text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:"$12.40"})]})]})}function Ed({enterDelay:t=0}){const{available:a,settings:r,setSetting:s}=ul(),[n,i]=d.useState(Ad),[o,u]=d.useState(!1),c=Nr(),h=d.useCallback(()=>{i(!0),Ds()},[]),m=d.useCallback(()=>{if(!a){try{window.location.href="tokentracker://open"}catch{}return}s("dynamicIslandEnabled",!0),o&&s("hideMenuBarIcon",!0),Ds(),i(!0),hi({title:l("dashboard.island.enabled_toast"),data:{onUndo:()=>{s("hideMenuBarIcon",!1),s("dynamicIslandEnabled",!1),Dd(),i(!1)}}})},[a,o,s]),x=a&&!!r?.dynamicIslandSupported&&!r?.dynamicIslandEnabled,g=!a&&!Qs(),p=!n&&(x||g);return e.jsx(Ta,{initial:!1,children:p&&e.jsxs(ve.div,{initial:c?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:c?{opacity:0}:{opacity:0,y:-8},transition:c?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:h,"aria-label":l("dashboard.island.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx(Md,{reduceMotion:c}),e.jsx("div",{className:"mt-4 flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.island.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:l("qpd.card.badge")})]}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.island.hint")})]})}),a?e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg bg-oai-gray-50 px-3 py-2.5 dark:bg-oai-gray-800/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-medium text-oai-gray-800 dark:text-oai-gray-200",children:l("settings.labs.island_hide_menubar.label")}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("settings.labs.island_hide_menubar.hint")})]}),e.jsx(ml,{checked:o,onChange:()=>u(y=>!y),ariaLabel:l("settings.labs.island_hide_menubar.aria")})]}):null,e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(ve.button,{type:"button",onClick:m,whileHover:c?void 0:{scale:1.03},whileTap:c?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:a?l("dashboard.island.enable"):l("local_only.open_app")}),e.jsxs("a",{href:"/settings?section=labs",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.island.settings_link"),e.jsx(hl,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"island-onboarding-card")})}function Id({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[h,m]=d.useState(null),x=St([t,a,r,s,n]),g=d.useCallback(async()=>{if(!t)return;const p=x();c(!0),m(null);try{const y=await Oe(s);if(!p())return;const k=await gi({from:a,to:r,device:n,accessToken:y});if(!p())return;o(k||null)}catch(y){if(!p())return;m(y?.message||String(y)),o(null)}finally{p()&&c(!1)}},[t,a,r,s,n,x]);return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}o(null),m(null),c(!0),g()},[t,g]),{data:i,loading:u,error:h,refresh:g}}function jn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Nn(t){return t==null?"—":`${Math.round(t*100)}%`}function Rd(t,a){if(a==null||a===0||t==null||t===0)return"—";const r=t/a;return r<1?`$${r.toFixed(4)}`:`$${r.toFixed(2)}`}function Fd({row:t}){return e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60 hover:bg-oai-gray-50/40 dark:hover:bg-oai-gray-800/10 transition-colors",children:[e.jsx("td",{className:"py-2.5 pr-2 font-mono text-[11px] text-oai-gray-700 dark:text-oai-gray-300 truncate max-w-[80px] xs:max-w-[110px] sm:max-w-[140px]",title:t.key,children:t.key}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:jn(t.cost_usd)}),e.jsxs("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:[t.accepted,"/",t.outcomes]}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:Nn(t.acceptance_rate)}),e.jsx("td",{className:"py-2.5 pl-2 pr-2 text-right tabular-nums font-semibold text-oai-black dark:text-oai-white",children:Rd(t.cost_usd,t.accepted)})]})}function $d({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Fe(),{enabled:i}=gl(),{data:o,loading:u}=Id({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const c=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(g=>g.outcomes>0&&g.key!=="unknown");if(!c.length)return null;const h=c.slice(0,6),m=o.totals||{},x=`${l("qpd.card.subtitle")}${u?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(De,{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("qpd.card.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:x}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(g=>e.jsx(Fd,{row:g},g.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:m.accepted??0,outcomes:m.outcomes??0,cost:jn(m.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(m.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(m.effective_tokens),rate:Nn(m.acceptance_rate)})})]}),m.outcomes<15&&e.jsxs("p",{className:"mt-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500 italic border-t border-oai-gray-100 dark:border-oai-gray-800/40 pt-2",children:["* ",l("qpd.card.sparse_notice","Tip: Spark outcomes dataset might skew Quality/$ ratios. For precise metrics, select a narrower time window.")]})]})}const Pd=new Set(["unknown","synthetic","openai"]);function or(t){return t==null?"—":`${Math.round(t*100)}%`}function Bd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function zd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Pd.has(r)&&Number(t?.edit_turns||0)>0}function Ls(){return e.jsx("div",{className:"mb-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:l("sessions.card.title")}),e.jsx("span",{className:"rounded bg-oai-gray-100 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-oai-gray-500 dark:bg-oai-gray-800/80 dark:text-oai-gray-400",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("sessions.card.subtitle")})]})})}function Od({from:t,to:a}){const[r,s]=d.useState({loading:!0,sessions:null,context:null}),n=d.useId(),{enabled:i}=xl(),{formatTokens:o}=Fe(),u=f=>o(f,{mode:Kt.COMPACT});d.useEffect(()=>{if(!i){s({loading:!1,sessions:null,context:null});return}let f=!1;return s(v=>({...v,loading:!0})),Promise.all([xi({from:t,to:a}),fi()]).then(([v,w])=>{f||s({loading:!1,sessions:v,context:w})}).catch(()=>{f||s({loading:!1,sessions:null,context:null})}),()=>{f=!0}},[i,t,a]);const c=d.useMemo(()=>(r.sessions?.by_model||[]).filter(zd).slice(0,5),[r.sessions]),h=d.useMemo(()=>(r.sessions?.subagents||[]).slice(0,3),[r.sessions]);if(!i||!r.loading&&!r.sessions?.available&&!r.context?.estimated_fixed_tokens)return null;const m=r.sessions?.summary||{},x=m.edit_session_rate??m.productive_rate,g=m.first_pass_rate??m.one_shot_rate,p=m.edit_sessions??m.productive_sessions??0,y=m.sessions??r.sessions?.session_count??0,k=m.edit_turns??0;return r.loading&&!r.sessions&&!r.context?e.jsxs(De,{children:[e.jsx(Ls,{}),e.jsx("div",{role:"status",className:"flex h-24 items-center justify-center rounded-lg bg-oai-gray-50 text-xs text-oai-gray-400 dark:bg-oai-gray-800/50 dark:text-oai-gray-500",children:l("sessions.card.loading")})]}):e.jsxs(De,{children:[e.jsx(Ls,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(ir,{label:l("sessions.card.edit_sessions"),value:or(x),detail:l("sessions.card.edit_session_value",{edits:Ze(p),sessions:Ze(y)})}),e.jsx(ir,{label:l("sessions.card.first_pass"),value:or(g),detail:l("sessions.card.edit_session_value",{edits:Ze(m.first_pass_sessions??m.one_shot_sessions??0),sessions:Ze(p)})}),e.jsx(ir,{label:l("sessions.card.cost_edit"),value:Bd(m.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(k)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Ze(y),edits:Ze(k)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":n,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:n,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!c.length&&e.jsx("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:c.map(f=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:f.model,children:f.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Ze(f.edit_sessions??f.productive_sessions??0),sessions:Ze(f.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:or(f.first_pass_rate??f.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:u(f.tokens_per_edit)})]},f.model))})]})}),r.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:u(r.context.estimated_fixed_tokens)})]}):null,!!h.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),h.map(f=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:f.name,calls:Math.round(f.calls)})},f.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function ir({label:t,value:a,detail:r}){return e.jsxs("div",{className:"rounded-lg bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 truncate",children:t}),e.jsx("div",{className:"mt-0.5 text-sm font-semibold tabular-nums text-oai-black dark:text-white",children:a}),e.jsx("div",{className:"mt-0.5 text-[9px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 truncate",children:r})]})}function le({className:t}){return e.jsx("div",{className:jt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Ud(){return e.jsx("div",{className:"flex gap-1 overflow-hidden",children:Array.from({length:20},(t,a)=>e.jsx("div",{className:"flex flex-col gap-1",children:Array.from({length:7},(r,s)=>e.jsx(le,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function Hd(){return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsxs("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:[e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(le,{className:"h-4 w-32"}),e.jsx(le,{className:"h-6 w-24"})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-24"}),Array.from({length:4},(t,a)=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(le,{className:"h-3 w-20"}),e.jsx(le,{className:"h-3 w-12"})]},a))]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-20"}),e.jsx(Ud,{})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-28"}),e.jsx(le,{className:"h-32 w-full"})]})})]}),e.jsxs("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex flex-1 min-w-0 gap-1",children:Array.from({length:5},(t,a)=>e.jsx(le,{className:"h-7 w-14 rounded-md shrink-0"},a))}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(le,{className:"h-8 w-20 rounded-md"}),e.jsx(le,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(le,{className:"h-3 w-28"}),e.jsx(le,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(le,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(le,{className:"h-1.5 w-full rounded-full"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-3",children:Array.from({length:5},(t,a)=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(le,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(le,{className:"h-3 w-12"})]}),e.jsx(le,{className:"h-5 w-10"}),e.jsx(le,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(le,{className:"h-7 w-16 rounded"}),e.jsx(le,{className:"h-7 w-20 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-200 dark:border-oai-gray-700 pb-2",children:[e.jsx(le,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(le,{className:"h-3 flex-1"},a))]}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:8},(t,a)=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-100 dark:border-oai-gray-800 py-2.5 last:border-b-0",children:[e.jsx(le,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(le,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const Vd=yl.slice(0,10),Ms=.06,Kd=.11,Wd=.05,Gd=new Set(["macAppBanner","widgetOnboarding"]);function Es({title:t,subtitle:a,desc:r,loginCard:s,copy:n}){return e.jsxs("div",{className:"min-h-[85vh] w-full flex items-center justify-center text-oai-black dark:text-white relative overflow-hidden px-4 md:px-8 py-8 md:py-16 transition-colors duration-200 bg-[linear-gradient(to_right,#80808007_1px,transparent_1px),linear-gradient(to_bottom,#80808007_1px,transparent_1px)] bg-[size:40px_40px]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_50%_0%,rgba(59,130,246,0.03),transparent_50%)] dark:bg-[radial-gradient(circle_at_50%_0%,rgba(99,102,241,0.05),transparent_50%)] pointer-events-none"}),e.jsxs("div",{className:"w-full max-w-5xl grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-16 items-start relative z-10",children:[e.jsxs("div",{className:"lg:col-span-7 flex flex-col justify-center space-y-8 text-left pr-0 lg:pr-6",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:32,height:32,className:"rounded-md shadow-md border border-oai-gray-200/50 dark:border-oai-gray-800 shadow-black/10 dark:shadow-black/30"}),e.jsx("span",{className:"text-xl font-bold tracking-tight bg-gradient-to-r from-oai-black to-oai-gray-600 dark:from-white dark:to-oai-gray-400 bg-clip-text text-transparent font-oai",children:n("shared.app_name")})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl md:text-4xl lg:text-4.5xl font-black tracking-tight leading-[1.15] text-oai-black dark:text-white",children:t}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm md:text-base max-w-xl leading-relaxed",children:r})]}),e.jsx("div",{className:"w-full max-w-[280px] sm:max-w-md opacity-85 hover:opacity-100 transition-opacity duration-200",children:e.jsx("div",{className:"flex justify-start",children:e.jsx(pl,{logos:Vd,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(ve.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{duration:.3},className:"w-full max-w-[400px] rounded-2xl border border-oai-gray-200/80 dark:border-oai-gray-800 bg-white/70 dark:bg-oai-gray-950/40 backdrop-blur-md shadow-2xl p-1 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -inset-px bg-gradient-to-b from-white/10 dark:from-white/5 to-transparent pointer-events-none rounded-2xl"}),s]})})]})]})}function qd(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:u,activeDays:c,identitySubscriptions:h,identityScrambleDurationMs:m,projectUsageEntries:x,projectUsageLimit:g,setProjectUsageLimit:p,projectDetailQuery:y,topModels:k,signedIn:f,publicMode:v,isLocalMode:w,shouldShowInstall:D,installPrompt:C,handleCopyInstall:R,installCopied:A,installInitCmdDisplay:P,trendRowsForDisplay:N,trendFromForDisplay:j,trendToForDisplay:S,trendZoomConfig:E,usageFrom:O,usageTo:F,period:L,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:q,setSelectedPeriod:_,customFrom:$,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,summaryLabel:ne,summaryValue:oe,summaryFullValue:je,hasSummary:be,summaryLoading:Le,providersLoading:X,onToggleSummaryFormat:U,summaryTotalTokensRaw:re,summaryCostValue:ee,summaryConversationsValue:ae,rollingUsage:ye,costInfoEnabled:Y,openCostModal:J,costModalOpen:Z,closeCostModal:ge,allowBreakdownToggle:$e,refreshAll:me,usageLoadingState:T,announceUsageLoading:z,initialDashboardLoading:he,fleetData:V,hasDetailsActual:de,dailyEmptyPrefix:Ce,installSyncCmd:Ne,dailyEmptySuffix:At,detailsColumns:fe,ariaSortFor:pe,toggleSort:Pe,sortIconFor:Be,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:ht,renderDailyBreakdownDate:Q,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:ke,detailsPageCount:we,detailsPage:Te,setDetailsPage:gt,deviceOptions:Lt,selectedDevice:Jt,onDeviceChange:Qt,deviceUsageBlock:Mt,leftCardOrder:Ma,onLeftReorder:Ke,rightCardOrder:Xt,onRightReorder:rt}=t,Et=null,Ea=null,[ea,ta]=d.useState(()=>new Set),It=d.useCallback((ce,ie)=>{Gd.has(ce)&&ta(Se=>{if(Se.has(ce)===ie)return Se;const et=new Set(Se);return ie?et.add(ce):et.delete(ce),et})},[]),Ia={macAppBanner:w,statsPanel:!0,islandOnboarding:w,widgetOnboarding:w,installCopy:D,activityHeatmap:!!K,deviceUsage:!!Mt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},Rt=(Ma||[]).filter(ce=>Ia[ce]&&!ea.has(ce)),Ft={usageOverview:!0,dataDetails:!s},Ra=(Xt||[]).filter(ce=>Ft[ce]&&!ea.has(ce));function qe(ce,ie){switch(ce){case"macAppBanner":return e.jsx(Sd,{todayTokens:re,isSyncing:T,enterDelay:ie});case"statsPanel":return e.jsx(st,{delay:ie,children:e.jsx(Rc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:L,startDate:u??a("identity_card.rank_placeholder"),streakDays:c,subscriptions:h,periodConversations:ae,rolling:ye,topModels:k})});case"islandOnboarding":return e.jsx(Ed,{enterDelay:ie});case"widgetOnboarding":return e.jsx(Td,{enterDelay:ie});case"installCopy":return e.jsx(st,{delay:ie,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:C}),e.jsxs(ve.button,{onClick:R,whileHover:{scale:1.01},whileTap:{scale:.99},className:"w-full flex items-center justify-between px-3 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-700 rounded-lg transition-colors",children:[e.jsx("code",{className:"text-xs font-mono text-oai-gray-700 dark:text-oai-gray-300",children:P}),e.jsx(ve.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:A?"Copied ✓":"Copy"},A?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(st,{delay:ie,children:K});case"deviceUsage":return e.jsx(st,{delay:ie,children:Mt});case"trendMonitor":return e.jsx(st,{delay:ie,children:e.jsx(Xs,{rows:N,from:j,to:S,period:L,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:E})});case"qualityPerDollar":return e.jsx($d,{from:O,to:F,deviceId:Jt});case"sessionInsights":return e.jsx(Od,{from:O,to:F});default:return null}}function aa(ce,ie){switch(ce){case"usageOverview":return e.jsx(st,{delay:ie,children:e.jsx(bd,{period:L,periods:q,onPeriodChange:_,summaryLabel:ne,summaryValue:oe,summaryFullValue:je,hasSummary:be,summaryLoading:Le,providersLoading:X,onToggleSummaryFormat:be?U:null,summaryCostValue:ee,onCostInfo:Y?J:null,fleetData:V,onRefresh:s?null:me,loading:T,announceLoading:z,onOpenShare:s?null:r,customFrom:$,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,from:O,to:F,deviceOptions:Lt,selectedDevice:Jt,onDeviceChange:Qt})});case"dataDetails":return e.jsx(st,{delay:ie,children:e.jsx(Ec,{projectEntries:x,projectLimit:g,onProjectLimitChange:p,projectDetailQuery:y,copy:a,hasDetailsActual:de,dailyEmptyPrefix:Ce,installSyncCmd:Ne,dailyEmptySuffix:At,detailsColumns:fe,ariaSortFor:pe,toggleSort:Pe,sortIconFor:Be,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:ht,renderDailyBreakdownDate:Q,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:ke,period:L,detailsPageCount:we,detailsPage:Te,setDetailsPage:gt})});default:return null}}const We=Vi(rs(Zi,{activationConstraint:{distance:6}}),rs(Yi,{coordinateGetter:qi})),xe=d.useCallback(ce=>{const{active:ie,over:Se}=ce;!Se||ie.id===Se.id||Ke?.(String(ie.id),String(Se.id))},[Ke]),Fa=d.useCallback(ce=>{const{active:ie,over:Se}=ce;!Se||ie.id===Se.id||rt?.(String(ie.id),String(Se.id))},[rt]);function $t(ce,ie,Se,et){return s?e.jsx(e.Fragment,{children:ce.map((Ae,xt)=>e.jsx(_t.Fragment,{children:ie(Ae,Se+Ms*xt)},Ae))}):e.jsx(Ki,{sensors:We,onDragEnd:et,children:e.jsx(Wi,{items:ce,strategy:Gi,children:ce.map((Ae,xt)=>e.jsx(_d,{id:Ae,onEmptyChange:It,children:ie(Ae,Se+Ms*xt)},Ae))})})}const ra=$t(Rt,qe,Kd,xe),$a=$t(Ra,aa,Wd,Fa);return e.jsxs(e.Fragment,{children:[e.jsxs(Dl,{bare:!s,hideHeader:s,header:Et,footer:s?null:Ea,className:s?"screenshot-mode":"",children:[i&&e.jsx(Es,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(ss,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Es,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(ss,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&he&&e.jsx(Hd,{}),!i&&!n&&!he&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:ra}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:$a})]})})]}),e.jsx(Nc,{isOpen:Z,onClose:ge,fleetData:V})]})}function Yd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0}={}){const u=!!(n&&i),[c,h]=d.useState([]),[m,x]=d.useState([]),[g,p]=d.useState(!1),[y,k]=d.useState(null),f=St([u,t,a,r,s,i,o]),v=d.useCallback(async()=>{const w=f();if(!u){h([]),x([]),p(!1),k(null);return}p(!0),k(null);try{const D=await Oe(i);if(!w())return;const C=await pi({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:D});if(!w())return;h(Array.isArray(C?.devices)?C.devices:[]),x(Array.isArray(C?.account_sources)?C.account_sources:[])}catch(D){if(!w())return;k(D?.message||String(D)),h([]),x([])}finally{w()&&p(!1)}},[u,i,t,a,r,s,o,f]);return d.useEffect(()=>{h([]),x([]),k(null),u&&p(!0),v()},[u,v]),{devices:c,accountSources:m,loading:g,error:y,refresh:v}}const Zd=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Is(t){const a=String(t||"").toLowerCase();return/iphone|ipad|ios/.test(a)?"iOS":/android/.test(a)?"Android":/mac|darwin/.test(a)?"Mac":/win/.test(a)?"Windows":/linux/.test(a)?"Linux":"Web"}function fr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(Zd);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Is(t.platform)} · ${s}`:Is(t.platform)}const Rs=" · ",Fs="%";function $s({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(vl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Yr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Yr,{className:a,"aria-hidden":!0}):e.jsx(nn,{className:a,"aria-hidden":!0})}function Ps(t,a){return a===t?.id||t?.isCurrent===!0}function Jd({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:u}=Fe(),[c,h]=d.useState(""),[m,x]=d.useState(""),[g,p]=d.useState(!1),[y,k]=d.useState(""),f=typeof i=="function",v=typeof n=="function",w=!!s,D=t.reduce((j,S)=>j+(Number(S.total_tokens)||0),0)+a.reduce((j,S)=>j+(Number(S.total_tokens)||0),0),C=d.useMemo(()=>t.filter(j=>(Number(j.total_tokens)||0)>0).sort((j,S)=>(Number(S.total_tokens)||0)-(Number(j.total_tokens)||0)),[t]);function R(j){k(""),h(j.id);const S=typeof j.device_name=="string"?j.device_name:"";x(fr(j)===S?S:"")}function A(){h(""),x(""),k("")}async function P(j){const S=m.trim();if(!(!S||g)){p(!0),k("");try{await i(j.id,S),h(""),x("")}catch{k(j.id)}finally{p(!1)}}}const N=a.filter(j=>(Number(j.total_tokens)||0)>0);return C.length===0&&N.length===0?e.jsxs(De,{bodyClassName:"!px-3 !py-3.5",children:[e.jsx("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide px-2",children:l("dashboard.device_card.title")})}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-center",children:[e.jsx(nn,{className:"h-7 w-7 text-oai-gray-300 dark:text-oai-gray-600 mb-2 stroke-[1.5]"}),e.jsx("p",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 font-medium",children:l("dashboard.device_card.empty")})]})]}):e.jsxs(De,{bodyClassName:"!px-3 !py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:l("dashboard.device_card.title")}),v&&w&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[C.map(j=>{const S=Number(j.total_tokens)||0,E=D>0?(S/D*100).toFixed(1):"0.0",O=s===j.id,F=fr(j)||l("dashboard.device_card.unnamed"),L=c===j.id,B=O?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=w&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[L?e.jsxs("div",{className:"w-full rounded-md px-2 py-1.5 bg-oai-gray-50/50 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx($s,{platform:j.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:m,disabled:g,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:q=>x(q.target.value),onKeyDown:q=>{q.key==="Enter"?P(j):q.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:g||!m.trim(),onClick:()=>P(j),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(bl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:g,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(jr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${E}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${F}${Ps(j,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":j.id),className:`w-full text-left rounded-md px-2 py-1.5 transition-all duration-200 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-oai-brand/50 ${K} ${O?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx($s,{platform:j.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:F,children:F}),Ps(j,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")})]}),e.jsxs("span",{title:u(S),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${f?"group-hover:opacity-0":""}`,children:[o(S),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Rs,E,Fs]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${E}%`}})})]}),f&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>R(j),className:"absolute right-2 top-1.5 flex h-4 items-center text-oai-gray-400 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-oai-brand focus:outline-none transition-opacity duration-150",children:e.jsx(fl,{className:"h-3 w-3"})})]}),y===j.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},j.id)}),N.map(j=>{const S=Number(j.total_tokens)||0,E=D>0?(S/D*100).toFixed(1):"0.0",O=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(Ct,{provider:j.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:vt(j.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:u(S),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(S),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Rs,E,Fs]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${E}%`}})})]},`account-${j.source}`)})]})]})}function Sn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ct=new Map,dt=new Map;function Cn(){typeof window>"u"||window.__tokentrackerNativeSaveListener||(window.__tokentrackerNativeSaveListener=!0,window.addEventListener("native:saveImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!ct.has(r))return;const s=ct.get(r);ct.delete(r),s({ok:!!a.ok,path:typeof a.path=="string"?a.path:void 0,error:typeof a.error=="string"?a.error:void 0})}),window.addEventListener("native:copyImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!dt.has(r))return;const s=dt.get(r);dt.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function Qd(t){if(!Sn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const a=window?.webkit?.messageHandlers?.nativeBridge;if(!a)return{ok:!1,error:"native bridge unavailable"};Cn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{dt.has(r)&&(dt.delete(r),s({ok:!1,error:"timeout"}))},8e3);dt.set(r,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){dt.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Bs(t,a){if(!Sn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const r=window?.webkit?.messageHandlers?.nativeBridge;if(!r)return{ok:!1,error:"native bridge unavailable"};Cn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{ct.has(s)&&(ct.delete(s),n({ok:!1,error:"timeout"}))},8e3);ct.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){ct.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Tn=1200,An=1630,Dn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},Xd="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter+Tight:wght@400;500;600;700&family=IBM+Plex+Serif:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap";let lr=!1;function eu(){if(typeof document>"u"||lr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){lr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=Xd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),lr=!0}async function tu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function au(t,a={}){if(typeof window>"u"||!t)return null;eu(),await tu(),await new Promise(c=>requestAnimationFrame(()=>c(null)));const{toBlob:r,toPng:s}=await yi(async()=>{const{toBlob:c,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:c,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Tn,o=t.offsetHeight||An,u={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:c=>!(c instanceof HTMLElement)||c.dataset?.screenshotExclude!=="true"};try{const c=await r(t,u);if(c)return c}catch{}try{const c=await s(t,u);return c?await(await fetch(c)).blob():null}catch{return null}}async function cr(t){return new Promise(a=>{const r=new FileReader;r.onload=()=>{const s=typeof r.result=="string"?r.result:null;a(s)},r.onerror=()=>a(null),r.readAsDataURL(t)})}function zs(t,a){if(typeof window>"u"||!t)return!1;try{const r=URL.createObjectURL(t),s=document.createElement("a");return s.href=r,s.download=a,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),!0}catch{return!1}}function pr(t){const a=se(t);return Number.isFinite(a)?a:0}function ru(t){return t?pr(t.billable_total_tokens??t.total_tokens):0}function su(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(u=>{const c=!!u?.future,h=Number.isFinite(u?.level)?Math.max(0,Math.min(4,Math.round(u.level))):0;u?.day&&!c&&(r+=1,h>0&&(s+=1));const m=u?.billable_total_tokens??u?.total_tokens??u?.value??0,x=Number.isFinite(m)?Math.max(0,m):0;return{day:typeof u?.day=="string"?u.day:"",level:h,value:x,future:c}})),totalDays:r,activeDays:s}}function nu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:u,periodFrom:c,periodTo:h,heatmap:m,capturedAt:x,currency:g,exchangeRate:p}=t,y=ru(n),k=pr(n?.total_cost_usd),f=Array.isArray(i)?i.slice(0,3).map(w=>({id:w?.id??null,name:typeof w?.name=="string"&&w.name?w.name:"—",tokens:pr(w?.tokens),percent:typeof w?.percent=="string"&&w.percent?w.percent:"0.0"})):[],v=su(m);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:y,totalCost:k,period:u,periodFrom:c,periodTo:h,topModels:f,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:x||new Date().toISOString(),currency:typeof g=="string"&&g.length>0?g.toUpperCase():"USD",exchangeRate:Number.isFinite(p)&&p>0?p:1}}const ou=["share.month_short.jan","share.month_short.feb","share.month_short.mar","share.month_short.apr","share.month_short.may","share.month_short.jun","share.month_short.jul","share.month_short.aug","share.month_short.sep","share.month_short.oct","share.month_short.nov","share.month_short.dec"];function iu(t){const a=ou[t];return a?l(a):"—"}function Ln(t,a){return l("share.date.month_year",{month:iu(t),year:a})}function lu(t){if(!t)return"—";const a=t.split("-");if(a.length!==3)return t;const[r,s]=a,n=Number(s)-1;return n<0||n>11?t:Ln(n,r)}function cu(t){if(t.period==="total")return l("share.issue.all_time");if(t.period==="day"&&t.periodTo)return t.periodTo.replace(/-/g,".");if(t.period==="custom"&&t.periodFrom&&t.periodTo)return`${t.periodFrom.replace(/-/g,".")} — ${t.periodTo.replace(/-/g,".")}`;if(t.periodTo){const a=new Date(`${t.periodTo}T00:00:00Z`);if(!Number.isNaN(a.getTime()))return Ln(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function yr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Mn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Gt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function du(t){const a=t.topModels[0];if(a){const r=parseFloat(a.percent);return Number.isFinite(r)&&r>=60?l("share.hook.top_loyal",{percent:Math.round(r),name:a.name}):t.activeDays>=60?l("share.hook.days_record",{days:t.activeDays}):Number.isFinite(r)&&r>=30?l("share.hook.top_led",{name:a.name,percent:Math.round(r)}):t.topModels.length>1?l("share.hook.multi_models",{count:t.topModels.length,days:t.activeDays}):l("share.hook.days_with_model",{days:t.activeDays,name:a.name})}return t.activeDays>0?l("share.hook.days_record",{days:t.activeDays}):l("share.hook.new_chapter")}function uu(t,a){const r=(t||"").length;if(r<=a.baseChars)return a.baseSize;const s=a.baseSize-(r-a.baseChars)*a.shrinkPerChar;return Math.max(a.minSize,s)}function mu(t){if(!t||t.future)return null;const a=typeof t.level=="number"?t.level:0;return a<0?0:a>4?4:Math.round(a)}function hu({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],u=i||o[0],c=t.length,h=(c-1)*s,m=Math.max(4,(r-h)/c),x=7*m+6*s;return e.jsx("svg",{width:r,height:x,viewBox:`0 0 ${r} ${x}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((g,p)=>(Array.isArray(g)?g:[]).map((k,f)=>{if(f>=7)return null;const v=mu(k),w=p*(m+s),D=f*(m+s),C=v===null?u:o[v];return e.jsx("rect",{x:w,y:D,width:m,height:m,rx:n,ry:n,fill:C},`${p}-${f}`)}))})}const gu=Tt("oklch(0.97 0.01 85)"),Re=Tt("oklch(0.18 0.02 85)"),tt=Tt("oklch(0.38 0.015 85)"),Os=Tt("oklch(0.55 0.012 85)"),ot=Tt("oklch(0.55 0.22 25)"),it='"Instrument Serif", "Times New Roman", Georgia, serif',xu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',fu=["oklch(0.93 0.013 80)","oklch(0.87 0.04 55)","oklch(0.78 0.09 45)","oklch(0.67 0.16 35)","oklch(0.55 0.22 25)"].map(Tt);function En({data:t}){const a=cu(t),r=yr(t.totalTokens),s=Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=lu(t.startDate),i=uu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=du(t),u=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:gu,color:Re,fontFamily:xu,padding:"80px 88px 68px 88px",boxSizing:"border-box",display:"flex",flexDirection:"column",position:"relative"},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,paddingBottom:14,borderBottom:`1px solid ${Os}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:ot}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:tt,textAlign:"right"},children:[l("share.card.broadsheet.issue")," № ",a]})]}),e.jsxs("div",{style:{marginTop:24,display:"flex",justifyContent:"space-between",alignItems:"flex-end",gap:24},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.2em",textTransform:"uppercase",color:tt,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:it,fontSize:52,fontStyle:"italic",lineHeight:1,color:Re,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:tt,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Re},children:n})]})]}),e.jsxs("div",{style:{marginTop:40,display:"flex",flexDirection:"column"},children:[e.jsx("div",{style:{fontSize:13,letterSpacing:"0.3em",textTransform:"uppercase",color:ot,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:it,fontSize:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:it,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:ot,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:tt},children:[e.jsxs("span",{children:[l("share.card.broadsheet.estimated_spend")," · ",s]}),e.jsx("span",{children:l("share.card.broadsheet.billable_days",{days:t.activeDays})})]})]}),u?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(hu,{weeks:t.heatmapWeeks,palette:fu,width:1024,gap:3,radius:2})]}):null,e.jsxs("section",{style:{marginTop:30,flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",borderBottom:`1px solid ${Re}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:it,fontStyle:"italic",fontSize:26,color:tt,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((c,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Os}`},children:[e.jsx("div",{style:{fontFamily:it,fontSize:34,fontStyle:"italic",color:ot,lineHeight:1},children:String(h+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:it,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("div",{style:{fontFamily:it,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:yr(c.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:tt,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[c.percent,"%"]})]},c.id||c.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsxs("div",{style:{display:"flex",gap:28},children:[e.jsxs("span",{children:[l("share.card.broadsheet.global_rank")," ",e.jsxs("span",{style:{color:ot},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:ot},children:l("share.card.broadsheet.days_count",{days:t.activeDays})})]})]}),e.jsxs("div",{children:[l("share.card.broadsheet.track_yours")," ",e.jsx("span",{style:{color:ot},children:"→ tokentracker.cc"})]})]})]})}const pu=Dn["annual-report"].width,yu="#0a0820",at="#ffffffee",lt="rgba(255,255,255,0.45)",dr="#a78bfa",bu={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(40px)",WebkitBackdropFilter:"blur(40px)",border:"1px solid rgba(255,255,255,0.05)",boxShadow:["0 39px 56px -36px rgba(255,255,255,0.10) inset","0 7px 11px -4px rgba(255,255,255,0.06) inset","0 -82px 68px -64px rgba(101,67,149,0.08) inset","0 98px 100px -48px rgba(208,171,255,0.06) inset","0 4px 18px 0 rgba(156,146,215,0.06) inset","0 1px 40px 0 rgba(228,222,255,0.04) inset"].join(", ")},ba={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},br='"Space Grotesk", "Inter Tight", sans-serif',ur='"Inter Tight", sans-serif',ku="rgba(255,255,255,0.06)",In=[ku,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Rn=48,Fn=28,Na=4,$n=20,wu=pu-Rn*2-Fn*2,_u=(wu-$n*2)/3,kr=Math.min(Math.floor((_u-Na*6)/7),40),vu=kr*7+Na*6;function ju(t){if(!Array.isArray(t))return t;const a=[];for(const u of t)if(Array.isArray(u))for(const c of u)c?.day&&!c.future&&c.value>0&&a.push(c.value);if(!a.length)return t;a.sort((u,c)=>u-c);const r=u=>{const c=a.length,h=(c-1)*u,m=Math.floor(h);return Math.round((a[m]??0)+((a[Math.min(c-1,m+1)]??0)-(a[m]??0))*(h-m))},s=r(.5),n=r(.75),i=r(.9),o=u=>!u||u<=0?0:u<=s?1:u<=n?2:u<=i?3:4;return t.map(u=>Array.isArray(u)?u.map(c=>c?.day&&!c.future&&typeof c.value=="number"?{...c,level:o(c.value)}:c):u)}function Nu(t){if(!Array.isArray(t))return[];const a={},r=ju(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Su(t){if(!t.length)return[];const a=[...t].sort((o,u)=>o.day.localeCompare(u.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const Cu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Tu(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Us(t){const[a,r]=d.useState(null);return d.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Au({data:t}){const a=Su(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:lt,fontFamily:br,marginBottom:4},children:Cu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Na},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Na},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:kr,height:kr,borderRadius:4,background:o<0?"transparent":In[o]}},i)})},s))})]})}function Du({data:t}){const a=Nu(t.heatmapWeeks),r=Tu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Us(n),o=Us("/neon_bg.png"),u=(t.handle||"?")[0].toUpperCase(),c=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:yu,fontFamily:br,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Rn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:c*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:lt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:at},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:at},children:u})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:at},children:t.handle})]})]}),e.jsxs("div",{style:{...bu,borderRadius:22,padding:Fn,marginBottom:c},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:lt},children:[e.jsx("span",{children:l("share.card.annual.less")}),In.map((h,m)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},m)),e.jsx("span",{children:l("share.card.annual.more")})]}),e.jsx("div",{style:{fontSize:16,fontWeight:700,letterSpacing:"0.14em",color:"rgba(255,255,255,0.22)",textTransform:"uppercase"},children:l("share.card.annual.heatmap_title")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(3,${vu}px)`,gap:`8px ${$n}px`,justifyContent:"center"},children:a.map(h=>e.jsx(Au,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:c,marginBottom:c},children:[e.jsxs("div",{style:{...ba,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:yr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...ba,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:c},children:[e.jsxs("div",{style:{...ba,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:dr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:ur,fontSize:28,fontWeight:700,color:at},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...ba,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:dr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:br,fontSize:28,fontWeight:700,color:at},children:s?s.name:"—"})]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:44,height:44,style:{width:44,height:44,borderRadius:8,display:"block"}}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:at},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:dr},children:"tokentracker.cc"})]})]})]})}const Pn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Lu={broadsheet:En,"annual-report":Du};function Bn(t){return Dn[t]||{width:Tn,height:An}}function Mu(t){const a=Pn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Hs=d.forwardRef(function({data:a,variant:r},s){const n=Lu[r]||En,{width:i,height:o}=Bn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function ka(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const Eu=440;function Iu(){const[t,a]=d.useState(null),r=d.useRef(null),s=d.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return d.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function mr({onClick:t,disabled:a,children:r,emphasis:s,ariaLabel:n}){return e.jsx("button",{type:"button",onClick:t,disabled:a,"aria-label":n,className:["group relative flex items-center justify-between gap-3 w-full px-4 py-3 text-left","rounded-lg border transition-colors",s?"border-oai-black dark:border-oai-white bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black hover:opacity-90":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600",a?"opacity-60 cursor-not-allowed":"cursor-pointer"].join(" "),children:r})}function Ru({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=d.useState(null),[o,u]=d.useState(""),[c,h]=d.useState("annual-report"),m=d.useRef(null),{toast:x,push:g}=Iu(),p=Js(),y=d.useMemo(()=>{const N=p?.user;if(!N||typeof N!="object")return null;const j=N.user_metadata||{},S=N.profile||{},E=j.avatar_url||j.picture||S.avatar_url||N.avatar_url;return typeof E=="string"&&E.trim()?E.trim():null},[p?.user]);d.useEffect(()=>{t&&(i(null),u(r?.handle||""))},[t,r?.handle]);const k=r&&{...r,handle:o||r.handle,avatarUrl:y},{width:f,height:v}=Bn(c),w=Eu/f;d.useEffect(()=>{if(!t)return;const N=j=>{j.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const D=d.useCallback(async()=>{const N=m.current;if(!N)return null;try{return await au(N)}catch(j){return console.warn("[share] capture failed",j),null}},[]),C=d.useCallback(async()=>{if(n)return;i("copy");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}let j=!1;if(ka()){const S=await cr(N);S&&(j=(await Qd(S)).ok)}else j=await Zr(N);g(j?l("share.toast.copied"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,g]),R=d.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=d.useCallback(async()=>{if(n)return;i("download");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}if(ka()){const S=await cr(N);if(S&&(await Bs(S,R())).ok){g(l("share.toast.downloaded"),"success"),i(null);return}}const j=zs(N,R());g(j?l("share.toast.downloaded"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,R,g]),P=d.useCallback(async()=>{if(n)return;i("x");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}if(ka()){const O=await cr(N);O&&(await Bs(O,R()),g(l("share.toast.downloaded"),"success"))}else await Zr(N)?g(l("share.toast.copied"),"success"):zs(N,R());const j=new URL("https://twitter.com/intent/tweet");s&&j.searchParams.set("text",s);const S=p?.user?.id,E=typeof S=="string"&&S?`/u/${S}`:"/";if(j.searchParams.set("url",`https://www.tokentracker.cc${E}?ref=share`),ka())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:j.toString()})}catch{window.open(j.toString(),"_blank","noopener,noreferrer")}else window.open(j.toString(),"_blank","noopener,noreferrer");i(null)},[n,D,g,s,R,p]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:f,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Hs,{ref:m,data:k,variant:c})}),e.jsxs(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},transition:{duration:.18,ease:[.2,.8,.2,1]},className:"relative w-full max-w-[1040px] max-h-[92vh] overflow-hidden rounded-2xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-black shadow-oai-lg",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row max-h-[92vh]",children:[e.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-7 bg-oai-gray-50 dark:bg-oai-gray-950 flex items-center justify-center overflow-auto",children:e.jsxs("div",{style:{width:f*w,height:v*w,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:f,height:v,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Hs,{data:k,variant:c})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:o,onChange:N=>u(N.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:Pn.map(N=>e.jsx("button",{type:"button",onClick:()=>h(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",c===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Mu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(mr,{onClick:P,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(mr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(mr,{onClick:C,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(Ta,{children:x?e.jsx(ve.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},className:"pointer-events-none absolute left-1/2 bottom-4 -translate-x-1/2",children:e.jsx("div",{className:["px-4 py-2 rounded-full text-xs font-medium shadow-oai-md",x.kind==="error"?"bg-red-600 text-white":x.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:x.text})},x.id):null})]})]}):null}function Fu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:u,periodFrom:c,periodTo:h,heatmap:m,accessToken:x,userId:g,currency:p,exchangeRate:y}=t,[k,f]=d.useState(null),v=y;return d.useEffect(()=>{if(!a||!g&&!ut())return;let w=!1;return(async()=>{try{const C=await bi({accessToken:x,userId:g,period:u==="day"||u==="custom"?"week":u,metric:"all",limit:100,offset:0});if(w)return;const A=(Array.isArray(C?.entries)?C.entries:Array.isArray(C)?C:[]).find(N=>N?.is_me===!0),P=typeof A?.rank=="number"?A.rank:null;f(P)}catch{w||f(null)}})(),()=>{w=!0}},[a,x,g,u]),d.useMemo(()=>nu({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:k,period:u,periodFrom:c,periodTo:h,heatmap:m,currency:p,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,i,o,k,u,c,h,m,p,v])}function Vs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const $u=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function Pu({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const Bu=["day","week","month","total","custom"],hr=new Set(["day","hour","month"]),Vt=new Set(["day","total","custom"]),zu=["islandOnboarding","macAppBanner","statsPanel","widgetOnboarding","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Ou=["usageOverview","dataDetails"];function gr(t,a){if(typeof a=="number"&&a>0)return!0;if(typeof t=="bigint")return t>0n;if(typeof t=="number")return Number.isFinite(t)&&t>0;if(typeof t=="string"){const r=t.trim();if(!r)return!1;if(/^[0-9]+$/.test(r))try{return BigInt(r)>0n}catch{return!1}const s=Number(r);return Number.isFinite(s)&&s>0}return!1}function wa(t){return t?Nt(t,null):null}function Ks(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function Uu(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function Hu(){if(typeof window>"u")return!1;const t=new URLSearchParams(window.location.search),a=String(t.get("force_install")||"").toLowerCase();return a!=="1"&&a!=="true"?!1:!Uu(window.location.hostname)}function Am({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:u="/sign-in",signUpUrl:c="/sign-up",onMainContentVisible:h}){const{resolvedLocale:m}=ki(),{currency:x,rate:g}=Ca(),{mode:p,setMode:y,formatTokens:k,formatTokensTooltip:f}=Fe(),[v,w]=d.useState(!1),[D,C]=d.useState(null),[R,A]=d.useState(null),[P,N]=d.useState(!1),[j,S]=d.useState(null),[E,O]=d.useState(0),[F,L]=d.useState(0),[B,K]=d.useState(null),q=d.useMemo(()=>typeof window>"u"?!1:wi(window.location.search),[]),_=d.useMemo(()=>Hu(),[]),[$,H]=d.useState(!1),te=2200,[ue,W]=d.useState(!0),[ne,oe]=d.useState(!1),[je,be]=d.useState(!1),[Le,X]=d.useState(!1),[U,re]=d.useState(!1),ee=d.useRef(!1),ae=ut(),ye=r&&!s,Y=d.useMemo(()=>ye&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,ye]),J=ye?Y:null,Z=i?_i(o):J,ge=r||ae||i,$e=ye&&Yt(J),me=r&&s&&!i,{accountView:T,revision:z,resolving:he}=vi(),V=T&&!i,de=V?J:null,Ce=he&&!i;d.useEffect(()=>{if(!r||ae){C(null),A(null),N(!1),S(null);return}if(i)return;if(!$e){C(null),A(null),N(!1),S(null);return}let b=!0;const I=()=>{C(null),A(null),N(!1),S(null)};return N(!0),S(null),(async()=>{let M=null;try{M=await Oe(J)}catch{M=null}if(b){if(!M){I();return}try{const G={link_code:null,expires_at:null};if(!b)return;C(typeof G?.link_code=="string"?G.link_code:null),A(typeof G?.expires_at=="string"?G.expires_at:null)}catch(G){if(!b)return;C(null),A(null),S(G?.message||"Failed to load link code")}finally{if(!b)return;N(!1)}}})(),()=>{b=!1}},[t,ae,r,i,$e,J,F]);const Ne=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");d.useEffect(()=>{if(!Ne&&(!r||ae||i)){K(null);return}if(!Ne&&!$e){K(null);return}let b=!0;return(async()=>{let I=null;try{I=await Oe(J)}catch{I=null}if(b){if(!I&&!Ne){K(null);return}try{const M=await ji({baseUrl:t,accessToken:I});if(!b)return;K(M&&typeof M=="object"?M:null)}catch{if(!b)return;K(null)}}})(),()=>{b=!1}},[$e,t,J,ae,i,r]);const At=d.useMemo(()=>{if(!R)return!1;const b=Date.parse(R);if(!Number.isFinite(b))return!1;const I=E||Date.now();return b<=I},[R,E]);d.useEffect(()=>{!r||ae||i||!R||!At||P||(C(null),A(null),S(null),L(b=>b+1))},[At,R,P,ae,r]),d.useEffect(()=>{if(!R||i)return;const b=Date.parse(R);if(!Number.isFinite(b))return;const I=Date.now();if(O(I),b<=I)return;const M=window.setTimeout(()=>O(Date.now()),b-I),G=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",G),window.addEventListener("focus",G),()=>{window.clearTimeout(M),typeof document<"u"&&document.removeEventListener("visibilitychange",G),window.removeEventListener("focus",G)}},[R]);const fe=d.useMemo(()=>Zs(),[]),pe=d.useMemo(()=>Ys(),[]),Pe=d.useMemo(()=>Ni(),[]),Be=i?null:a?.userId||a?.email||"default",[Dt,mt]=d.useState("month"),[Ve,Aa]=d.useState(null),[Xe,Da]=d.useState(null),[La,ht]=d.useState(!1),Q=q?"total":Dt,Zt=d.useMemo(()=>Q==="custom"&&Ve&&Xe?{from:Ve,to:Xe}:Si(Q,{timeZone:fe,offsetMinutes:pe,now:Pe}),[Pe,Q,fe,pe,Ve,Xe]),ke=Zt.from,we=Zt.to,[Te,gt]=d.useState(null),[Lt,Jt]=d.useState(()=>Jr());d.useEffect(()=>{const b=()=>Jt(Jr());return window.addEventListener(Qr,b),window.addEventListener("storage",b),()=>{window.removeEventListener(Qr,b),window.removeEventListener("storage",b)}},[]);const{devices:Qt,accountSources:Mt,refresh:Ma}=Yd({from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe,accountView:V,accountAccessToken:de,accountRevision:z}),Ke=d.useMemo(()=>Qt.filter(b=>(Number(b.total_tokens)||0)>0).map(b=>({...b,isCurrent:b.id===Lt})),[Qt,Lt]),Xt=d.useMemo(()=>Mt.filter(b=>(Number(b.total_tokens)||0)>0),[Mt]),rt=V&&Ke.length>=2,Et=V&&Ke.length+Xt.length>=2;d.useEffect(()=>{if(!rt&&!Et){Te!==null&>(null);return}Te&&!Ke.some(b=>b.id===Te)&>(null)},[rt,Et,Ke,Te]);const Ea=d.useMemo(()=>rt?[{value:"",label:l("dashboard.device_filter.all")},...Ke.map(b=>{const I=fr(b)||l("dashboard.device_card.unnamed"),M=b.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:b.id,label:`${I}${M}`}})]:[],[rt,Ke,m]),ea=Et?e.jsx(Jd,{devices:Ke,accountSources:Xt,currentDeviceId:Lt,selectedDeviceId:Te||"",onSelectDevice:b=>gt(b||null),onRenameDevice:async(b,I)=>{const M=await Oe(de);await Mi({deviceId:b,name:I,accessToken:M}),await Ma()}}):null,ta=d.useMemo(()=>Ci({timeZone:fe,offsetMinutes:pe}),[fe,pe]),It=d.useMemo(()=>Ti({timeZone:fe,offsetMinutes:pe}),[fe,pe]),Ia=d.useMemo(()=>`Local time (${It})`,[It]),Rt=fe,Ft=pe,Ra=ta,qe=d.useMemo(()=>vr({timeZone:fe,offsetMinutes:pe,date:Pe||new Date}),[Pe,fe,pe]),aa=d.useMemo(()=>gc({period:Q,selectedFrom:ke,selectedTo:we,todayKey:qe}),[ke,Q,we,qe]),{daily:We,summary:xe,rolling:Fa,source:$t,loading:ra,error:$a,refresh:ce}=ls({baseUrl:t,accessToken:Z,guestAllowed:me,from:ke,to:we,includeDaily:Q!=="total",cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{daily:ie,loading:Se,refresh:et}=ls({baseUrl:t,accessToken:Z,guestAllowed:me,from:aa.from,to:aa.to,includeDaily:!0,includeSummary:!1,cacheKey:Be?`${Be}.daily-breakdown`:"daily-breakdown",timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{breakdown:Ae,loading:xt,refresh:Tr}=ql({baseUrl:t,accessToken:Z,guestAllowed:me,from:ke,to:we,cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),[zn,On]=d.useState(3),{entries:Un,loading:Hn,refresh:Ar}=Kl({baseUrl:t,accessToken:Z,from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe}),Dr=Q==="week"||Q==="month",sa=Q==="week"||Q==="month",Lr=d.useMemo(()=>We.filter(b=>b?.future?!1:!b?.day||!qe?!0:String(b.day)<=String(qe)),[We,qe]),{rows:Ye,from:Vn,to:Kn,loading:Wn,refresh:Mr}=Fi({baseUrl:t,accessToken:Z,guestAllowed:me,period:Q,from:ke,to:we,months:24,cacheKey:Be,timeZone:Rt,tzOffsetMinutes:Ft,now:Pe,sharedRows:Dr?We:null,sharedRange:Dr?{from:ke,to:we}:null,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),Gn=d.useMemo(()=>({baseUrl:t,accessToken:Z,guestAllowed:me,cacheKey:Be,timeZone:Rt,tzOffsetMinutes:Ft,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce}),[t,Z,me,Be,Rt,Ft,Pe,V,de,z,Ce]),{daily:ft,heatmap:Ge,loading:Er,refresh:Ir}=zl({baseUrl:t,accessToken:Z,guestAllowed:me,weeks:52,cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{data:na,refresh:Rr}=$i();d.useEffect(()=>{na&&typeof na=="object"&&Ai(na)},[na]);const Ue=d.useMemo(()=>Q==="day"?"hour":Q==="total"?"month":"day",[Q]),qn=d.useMemo(()=>ds(Ue),[Ue]),oa="day",Yn=d.useMemo(()=>ds(oa),[]),[He,Fr]=d.useState(()=>({key:"day",dir:"desc"}));d.useEffect(()=>{Fr(b=>!hr.has(b.key)||b.key===Ue?b:{key:Ue,dir:b.dir})},[Ue]);const pt=d.useMemo(()=>hr.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),ia=d.useMemo(()=>{if(Q==="day")return Array.isArray(Ye)?Ye.filter(M=>M?.hour&&!M?.future):[];if(Q==="total"){const M=Array.isArray(Ye)?Ye.filter(G=>G?.month&&!G?.future):[];return ic(M)}const b=Lr;return!b.some(M=>!M?.missing&&!M?.future)&&We.length>0?We.filter(M=>!M?.future).slice(-30).filter(M=>M?.day):b},[Q,Ye,Lr,We]),Pt=d.useMemo(()=>us(ia,pt),[ia,pt]),$r=d.useMemo(()=>ia.some(b=>!b?.missing&&!b?.future),[ia]),Pa=d.useMemo(()=>{if(!Vt.has(Q))return 1;const b=Math.ceil(Pt.length/ja);return b>0?b:1},[Q,Pt.length]),[Ba,la]=d.useState(0);d.useEffect(()=>{if(!Vt.has(Q)){la(0);return}la(b=>Math.min(b,Pa-1))},[Pa,Q]),d.useEffect(()=>{Vt.has(Q)&&la(0)},[Q,He.dir,He.key]);const Zn=d.useMemo(()=>Vt.has(Q)?lc(Pt,Ba,ja):Pt,[Ba,Q,Pt]),Pr=d.useMemo(()=>xc(ie,{period:Q}),[ie,Q]),yt=d.useMemo(()=>hr.has(He.key)?{...He,key:oa}:He,[He]),Jn=d.useMemo(()=>us(Pr,yt),[Pr,yt]),Qn=d.useMemo(()=>sa?We:Q==="day"?Array.isArray(Ye)?Ye.filter(b=>b?.hour):[]:Ye,[We,Q,Ye,sa]),Xn=sa?ke:Vn,eo=sa?we:Kn;function to(b,I){if(b?.future)return"—";if(b?.missing)return l("shared.status.unsynced");if(I.endsWith("_tokens")){const M=I==="total_tokens"?wa(b):b?.[I];return e.jsx("span",{title:f(M),children:k(M)})}return va(b?.[I])}function ao(b){const I=b?.[Ue];if(I==null)return"";const M=String(I);if(Ue==="hour"){const[G,Ee]=M.split("T");if(G&&Ee)return`${G} ${Ee.slice(0,5)}`}return M}function ro(b){const I=b?.[oa];return I==null?"":String(I)}function so(b){Fr(I=>I.key===b?{key:b,dir:I.dir==="asc"?"desc":"asc"}:{key:b,dir:"desc"})}function no(b){return pt.key!==b?"none":pt.dir==="asc"?"ascending":"descending"}function oo(b){return pt.key!==b?"":pt.dir==="asc"?"▲":"▼"}function io(b){return yt.key!==b?"none":yt.dir==="asc"?"ascending":"descending"}function lo(b){return yt.key!==b?"":yt.dir==="asc"?"▲":"▼"}const za=d.useMemo(()=>{if(!r&&!ae&&!i&&!Ne)return 0;const b=Number(Ge?.active_days);if(Number.isFinite(b))return b;let I=0;const M=new Set,G=(_e,ze,Ie)=>{typeof _e!="string"||!_e||M.has(_e)||gr(ze,Ie)&&(M.add(_e),I+=1)};if(Array.isArray(ft))for(const _e of ft)G(_e?.day,wa(_e));const Ee=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const _e of Ee)for(const ze of Array.isArray(_e)?_e:[]){const Ie=Ks(ze);G(ze?.day,Ie,ze?.level)}return I},[r,ae,Ge?.active_days,Ge?.weeks,ft]),[Br,zr]=d.useState("month"),co=d.useCallback(b=>{b==="custom"?(zr(I=>I==="custom"?"month":I),mt(I=>Ve&&Xe?"custom":I),ht(!0)):(mt(b),zr(b),ht(!1))},[Ve,Xe]),uo=d.useCallback((b,I)=>{Aa(b),Da(I),mt("custom"),ht(!1)},[]),mo=d.useCallback(b=>{ht(b),!b&&Dt==="custom"&&!Ve&&mt(Br)},[Dt,Ve,Br]),ho=d.useRef(null),ca=d.useMemo(()=>[t||"",Be||"",V?"cloud":"local",z??"",Q||"",ke||"",we||"",qe||"",Te||"all",fe||"",pe??""].join(""),[z,V,t,Be,ke,Q,Te,fe,qe,we,pe]),Bt=d.useCallback(async()=>Vs(ho,ca,async()=>{V&&Di(),V||Li(),await Promise.all([ce(),Ir(),Mr(),Tr(),Ar(),et()])}),[V,et,Ir,Tr,Ar,Mr,ce,ca]),go=d.useRef(null),Or=d.useCallback(async()=>Vs(go,ca,async()=>{await Pu({refreshUsageStats:Bt,refreshUsageLimits:Rr})}),[ca,Rr,Bt]),Oa=d.useRef(Bt);d.useEffect(()=>{Oa.current=Bt},[Bt]);const Ua=d.useRef(null);d.useEffect(()=>{if(!Ne||ae||V)return;Ua.current||(Ua.current=Xr({auto:!0,background:!0,allLocalSources:!0}));let b=!0;return Ua.current.then(()=>{if(b)return Oa.current()}).catch(I=>{b&&console.warn("[DashboardPage] Reload sync failed:",I)}),()=>{b=!1}},[Ne,ae,V]),d.useEffect(()=>{if(!Ne||ae||V)return;const b=mc({refresh:()=>Oa.current(),onError:I=>console.warn("[DashboardPage] Automatic usage refresh failed:",I)});return()=>b.stop()},[Ne,ae,V]);const xo=d.useCallback(async()=>{X(!0);try{Ne&&await Xr($u),await Or()}catch(b){console.error("[DashboardPage] Refresh failed:",b)}finally{X(!1)}},[Ne,Or]),da=Le||ra||Se||Er||Wn||xt||Hn,Ha=!U&&(Ce||V&&da&&!$r),fo=d.useMemo(()=>l("shared.data_source",{source:String($t||"edge").toUpperCase()}),[$t,m]),ua=d.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),po="",Ur=d.useMemo(()=>!ua||ua.includes("@")?l("dashboard.identity.fallback"):ua,[ua]),Hr=d.useMemo(()=>Ur.replace(/[^a-zA-Z0-9._-]/g,"_"),[Ur]),Vr=d.useMemo(()=>i?l("dashboard.identity.fallback"):Hr,[Hr,po,i]),Kr=d.useMemo(()=>{let b=null;const I=G=>{typeof G!="string"||!G||(!b||G<b)&&(b=G)};if(Array.isArray(ft))for(const G of ft)G?.day&&gr(wa(G))&&I(G.day);const M=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const G of M)for(const Ee of Array.isArray(G)?G:[]){if(!Ee?.day)continue;const _e=Ks(Ee),ze=Ee?.level;gr(_e,ze)&&I(Ee.day)}return b},[Ge?.weeks,ft]),yo=d.useMemo(()=>i?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(M=>{const G=typeof M?.tool=="string"?M.tool.trim():"",_e=(typeof M?.plan_type=="string"?M.plan_type:typeof M?.planType=="string"?M.planType:"").trim();return!G||!_e?null:{tool:G,planType:_e,provider:typeof M?.provider=="string"?M.provider.trim():"",product:typeof M?.product=="string"?M.product.trim():"",rateLimitTier:typeof M?.rate_limit_tier=="string"?M.rate_limit_tier.trim():typeof M?.rateLimitTier=="string"?M.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,B]),bo=e.jsx(Pi,{heatmap:Ge,timeZoneLabel:ta,timeZoneShortLabel:It,hideLegend:q,defaultToLatestMonth:q}),ko=d.useMemo(()=>`${ke}..${we}`,[ke,Q,we]),wo=l("usage.summary.total"),Me=xe!=null,bt=Me?wa(xe):0,_o=k(bt),vo=d.useCallback(()=>{y(p===Kt.COMPACT?Kt.FULL:Kt.COMPACT)},[y,p]),jo=l("dashboard.core_index.collapse_label"),No=l("dashboard.core_index.expand_label"),So=l("dashboard.core_index.collapse_aria"),Co=l("dashboard.core_index.expand_aria"),To=!q,kt=l("shared.placeholder.short"),Va=d.useMemo(()=>{const b=Array.isArray(Ae?.sources)?Ae.sources:[];let I=null,M=0;for(const ze of b){const Ie=Nt(ze?.totals);!Number.isFinite(Ie)||Ie<=0||Ie>M&&(M=Ie,I=ze)}let G=kt,Ee=kt,_e="0.0";if(I&&M>0){G=I?.source?String(I.source).toUpperCase():kt;const ze=Array.isArray(I?.models)?I.models:[];let Ie=0;for(const Za of ze){const ha=Nt(Za?.totals);!Number.isFinite(ha)||ha<=0||ha>Ie&&(Ie=ha,Ee=Za?.model?String(Za.model):kt)}Ie>0&&(_e=(Ie/M*100).toFixed(1))}return{agentName:G,modelName:Ee,modelPercent:_e}},[Ae,kt]),Ka=va(bt),Ao=l("dashboard.screenshot.twitter_text",{total_tokens:Ka==="-"?kt:Ka,agent_name:Va.agentName,model_name:Va.modelName,model_percent:Va.modelPercent}),Do=d.useMemo(()=>q?[]:Bu,[q]),Lo=d.useMemo(()=>[{label:l("usage.metric.total"),value:Me?k(bt):"—",title:Me?f(bt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?k(xe?.input_tokens):"—",title:Me?f(xe?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?k(xe?.output_tokens):"—",title:Me?f(xe?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?k(xe?.cached_input_tokens):"—",title:Me?f(xe?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?k(xe?.reasoning_output_tokens):"—",title:Me?f(xe?.reasoning_output_tokens):void 0}],[xe?.cached_input_tokens,xe?.input_tokens,xe?.output_tokens,xe?.reasoning_output_tokens,bt,Me,k,f]),Wa=d.useMemo(()=>Sa(xe?.total_cost_usd,{currency:x,rate:g}),[xe?.total_cost_usd,x,g]),Mo=d.useMemo(()=>xe?.conversation_count??null,[xe?.conversation_count]),Wr=d.useMemo(()=>wc(Ae,{copyFn:l}),[Ae]),Gr=d.useMemo(()=>vc(Ae,{limit:3,copyFn:l}),[Ae]),Eo=Fu({enabled:$,handle:Vr,startDate:Kr,activeDays:za,summary:xe,topModels:Gr,period:Q,periodFrom:ke,periodTo:we,heatmap:Ge,accessToken:typeof Z=="string"?Z:null,userId:a?.userId||null,currency:x,exchangeRate:g}),Io=d.useCallback(()=>H(!0),[]),Ro=d.useCallback(()=>H(!1),[]),Fo=d.useCallback(()=>w(!0),[]),$o=d.useCallback(()=>w(!1),[]),Po=Wa&&Wa!=="-"&&Wr.length>0,zt=l("dashboard.install.cmd.init"),Ga=At?null:D,qa=Ga?l("dashboard.install.cmd.init_link_code",{link_code:Ga}):zt,Bo=zt,zo=l("dashboard.install.cmd.sync"),Oo=Ga?l("dashboard.install.copy"):l("dashboard.install.copy_base"),Uo=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const Ho=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),Vo=cc({publicMode:i,screenshotMode:q,forceInstall:_,accessEnabled:ge,heatmapLoading:Er,activeDays:za,hasActiveDeviceToken:Ho}),Ko=l("dashboard.install.prompt"),Wo=d.useCallback(async()=>{!qa||!await es(qa)||(oe(!0),window.setTimeout(()=>oe(!1),2e3))},[qa]);d.useCallback(async()=>{!zt||!await es(zt)||(be(!0),window.setTimeout(()=>be(!1),2e3))},[zt]);const Ya=d.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[m]),[Go,qo]=d.useMemo(()=>{const b=Ya.split("{{cmd}}");return b.length===1?[Ya,""]:[b[0],b.slice(1).join("{{cmd}}")]},[Ya]),Ot=s&&!i,Ut=!r&&!ae&&!s&&!Ne&&!i;d.useEffect(()=>{Ot||Ut||Ha||re(!0)},[Ha,Ut,Ot]);const ma=Hl(zu,Ou);return d.useEffect(()=>{ee.current||Ot||Ut||da||(ee.current=!0,h?.())},[h,Ut,Ot,da]),e.jsxs(e.Fragment,{children:[e.jsx(qd,{copy:l,onOpenShare:Io,screenshotMode:q,showExpiredGate:Ot,showAuthGate:Ut,identityDisplayName:Vr,identityStartDate:Kr,activeDays:za,identitySubscriptions:yo,identityScrambleDurationMs:te,projectUsageEntries:Un,projectUsageLimit:zn,setProjectUsageLimit:On,projectDetailQuery:{from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe},topModels:Gr,signedIn:r,publicMode:i,isLocalMode:Ne,shouldShowInstall:Vo,installPrompt:Ko,handleCopyInstall:Wo,installCopied:ne,installCopiedLabel:Uo,installCopyLabel:Oo,installInitCmdDisplay:Bo,linkCodeLoading:P,linkCodeError:j,trendRowsForDisplay:Qn,trendFromForDisplay:Xn,trendToForDisplay:eo,trendZoomConfig:Gn,usageFrom:ke,usageTo:we,period:Q,trendTimeZoneLabel:Ra,activityHeatmapBlock:bo,periodsForDisplay:Do,setSelectedPeriod:co,customFrom:Ve,customTo:Xe,onCustomRangeApply:uo,customRangeOpen:La,onCustomRangeOpenChange:mo,metricsRows:Lo,summaryLabel:wo,summaryValue:_o,hasSummary:Me,summaryLoading:ra,providersLoading:xt,summaryFullValue:Ka,onToggleSummaryFormat:vo,summaryTotalTokensRaw:se(bt)||0,summaryCostValue:Wa,summaryConversationsValue:Mo,rollingUsage:Fa,costInfoEnabled:Po,openCostModal:Fo,allowBreakdownToggle:To,coreIndexCollapsed:ue,setCoreIndexCollapsed:W,coreIndexCollapseLabel:jo,coreIndexExpandLabel:No,coreIndexCollapseAria:So,coreIndexExpandAria:Co,refreshAll:xo,usageLoadingState:da,announceUsageLoading:Le,initialDashboardLoading:Ha,usageError:$a,rangeLabel:ko,timeZoneRangeLabel:Ia,usageSourceLabel:fo,fleetData:Wr,hasDetailsActual:$r,dailyEmptyPrefix:Go,installSyncCmd:zo,dailyEmptySuffix:qo,detailsColumns:qn,ariaSortFor:no,toggleSort:so,sortIconFor:oo,pagedDetails:Zn,dailyBreakdownRows:Jn,dailyBreakdownColumns:Yn,dailyBreakdownAriaSortFor:io,dailyBreakdownSortIconFor:lo,dailyBreakdownDateKey:oa,detailsDateKey:Ue,renderDetailDate:ao,renderDailyBreakdownDate:ro,renderDetailCell:to,DETAILS_PAGED_PERIODS:Vt,detailsPageCount:Pa,detailsPage:Ba,setDetailsPage:la,costModalOpen:v,closeCostModal:$o,deviceOptions:Ea,selectedDevice:Te||"",onDeviceChange:b=>gt(b||null),deviceUsageBlock:ea,leftCardOrder:ma.left.order,onLeftReorder:ma.left.reorder,rightCardOrder:ma.right.order,onRightReorder:ma.right.reorder}),e.jsx(Ru,{open:$,onClose:Ro,data:Eo,twitterText:Ao})]})}export{Am as DashboardPage};
|
|
1
|
+
import{m as wr,r as d,j as e,L as Yo,cx as Zo,G as ut,am as Yt,cy as Oe,cz as Jo,cA as Qo,a9 as qr,cB as ga,cC as Ws,cD as Gs,cE as _r,cF as Xo,cG as ei,cH as ti,cI as vr,cJ as Wt,cK as ai,cL as ri,cM as se,c as l,d as _t,X as jr,as as Gt,a3 as Sa,l as Qe,q as qs,cN as si,Z as ni,n as Kt,aI as va,e as jt,cO as oi,F as Ys,z as Zs,aK as ii,$ as li,B as ci,R as di,k as ui,u as mi,a as Js,b4 as Qs,a4 as hi,cP as gi,cQ as xi,cR as fi,cS as pi,V as Yr,_ as yi,cT as Zr,g as bi,I as ki,ch as wi,cU as _i,cV as vi,cW as ji,cX as Ni,cY as Si,aJ as Jr,cZ as Qr,c_ as Ci,c$ as Ti,ad as Ai,d0 as Xr,aa as es,d1 as Di,d2 as Li,d3 as Mi}from"./__vite-browser-external-CjrP5KfC.js";import{u as St}from"./use-latest-request-guard-BO89yQ3n.js";import{u as ts}from"./use-ordered-list-B9ZYDS1K.js";import{t as as,T as Xs,g as Ei,f as xa,D as Ii,a as Ri,u as Fi}from"./TrendMonitor-BtBcCjx-.js";import{u as $i}from"./use-usage-limits-CpnM5V06.js";import{u as Ca}from"./useCurrency-BKJGW_4l.js";import{u as Fe}from"./useTokenFormat-CTB5svOB.js";import{f as vt,A as Pi}from"./provider-display-CEFlg9ho.js";import{g as Bi,q as en,J as zi,M as Oi,m as ve}from"./react-jS0-5kwE.js";import{u as Ui,C as Hi,a as Vi,b as rs,D as Ki,S as Wi,v as Gi,s as qi,K as Yi,P as Zi}from"./sortable.esm-BDdw7tkz.js";import{D as Ji,a as Qi,b as Xi,c as el,d as tl,e as al}from"./DialogTitle-DolLpmFL.js";import{D as rl}from"./DialogClose-DPFsTKmJ.js";import{C as De}from"./Card-Il2WWgOG.js";import{S as tn}from"./Select-YqlqvbT5.js";import{P as Ct}from"./ProviderIcon-C5RX_xPk.js";import{u as Nr}from"./use-reduced-motion-DWHVI51t.js";import{a as an,u as rn}from"./use-transform-9S4Ruq_s.js";import{I as sn}from"./info-CU7bMBhU.js";import{A as Ta}from"./index-CN7xY7j_.js";import{L as sl}from"./loader-circle-BK3Ltc-j.js";import{P as nl,a as ol,b as il,c as ll,d as cl}from"./PopoverPopup-nL3YOLPO.js";import{F as st}from"./FadeIn-92GGNCPe.js";import{C as dl}from"./ClawdAnimated-DioF5wa-.js";import{u as ul,T as ml}from"./Controls--LFhExZX.js";import{A as hl}from"./arrow-up-right-AKItXMyh.js";import{u as gl,a as xl,P as fl}from"./use-session-efficiency-pref-CwGRDyVq.js";import{L as ss}from"./LoginCard-JCejigVu.js";import{L as pl,A as yl}from"./agent-logos-CCVzO3uU.js";import{M as nn}from"./monitor-smartphone-4NOM9BHb.js";import{C as bl}from"./check-BQw5n0V0.js";import"./terminal-Dh7Sh6IG.js";import"./maximize-2-DIPnLqR8.js";import"./use-limits-display-prefs-C358N7B0.js";import"./composite-CWz1s64R.js";import"./store-CFdu9yv_.js";import"./ToolbarRootContext-D9pPY73U.js";import"./SelectItemText-BahqsiIc.js";const kl=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],wl=wr("git-branch",kl);const _l=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],vl=wr("laptop",_l);const jl=[["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"}]],Nl=wr("square-arrow-out-up-right",jl);function Sl(t,a,r={}){const s=t.get();let n=null,i=s,o;const u=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,c=()=>{n&&(n.stop(),n=null),t.animation=void 0},h=()=>{const x=ns(t.get()),g=ns(i);if(x===g){c();return}const p=n?n.getGeneratorVelocity():t.getVelocity();c(),n=new zi({keyframes:[x,g],velocity:p,type:"spring",restDelta:.001,restSpeed:.01,...r,onUpdate:o})},m=()=>{h(),t.animation=n??void 0,t.events.animationStart?.notify(),n?.then(()=>{t.animation=void 0,t.events.animationComplete?.notify()})};if(t.attach((x,g)=>{i=x,o=p=>g(Ja(p,u)),Bi.postRender(m)},c),en(a)){let x=r.skipInitialAnimation===!0;const g=a.on("change",y=>{x?(x=!1,t.jump(Ja(y,u),!1)):t.set(Ja(y,u))}),p=t.on("destroy",g);return()=>{g(),p()}}return c}function Ja(t,a){return a?t+a:t}function ns(t){return typeof t=="number"?t:parseFloat(t)}function Cl(t,a={}){const{isStatic:r}=d.useContext(Oi),s=()=>en(t)?t.get():t;if(r)return an(s);const n=rn(s());return d.useInsertionEffect(()=>Sl(n,t,a),[n,JSON.stringify(a)]),n}function Tl(t,a={}){return Cl(t,{type:"spring",...a})}function Al(){return e.jsxs(Yo,{to:"/landing",className:"flex items-center gap-2.5 no-underline hover:opacity-80 transition-opacity",children:[e.jsx("img",{src:"/app-icon.png",alt:"Token Tracker",width:28,height:28,className:"rounded-md"}),e.jsx("span",{className:"text-base font-semibold text-oai-black dark:text-oai-white leading-tight",children:"Token Tracker"})]})}function Dl({children:t,header:a,footer:r,className:s="",hideHeader:n=!1,hideFooter:i=!1,bare:o=!1}){return o?e.jsxs("div",{className:`flex flex-col flex-1 min-h-0 ${s}`,children:[e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]}):e.jsxs("div",{className:`min-h-screen bg-oai-white dark:bg-oai-gray-950 text-oai-black dark:text-oai-white font-sans flex flex-col transition-colors duration-200 ${s}`,children:[!n&&e.jsxs("header",{className:"border-b border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 flex items-center justify-between transition-colors duration-200",children:[e.jsx(Al,{}),e.jsx("div",{className:"flex-1 flex justify-center",children:a})]}),e.jsx("main",{className:"flex-1 px-6 py-6",children:t}),!i&&r&&e.jsx("footer",{className:"border-t border-oai-gray-200 dark:border-oai-gray-800 px-6 py-4 mt-auto transition-colors duration-200",children:r})]})}function Ll({children:t,variant:a="info",size:r="md",className:s=""}){const n="inline-flex items-center font-medium",i={success:"bg-oai-brand-100 dark:bg-oai-brand-900/30 text-oai-brand-700 dark:text-oai-brand-400 rounded-full",warning:"bg-oai-amber-50 dark:bg-oai-amber-900/30 text-oai-amber-dark dark:text-oai-amber-400 rounded-full",error:"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-full",info:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-600 dark:text-oai-gray-300 rounded-full",secondary:"bg-oai-gray-100 dark:bg-oai-gray-800 text-oai-gray-500 dark:text-oai-gray-300 rounded-md"},o={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-sm"},u=`${n} ${i[a]} ${o[r]} ${s}`.trim();return e.jsx("span",{className:u,children:t})}var Ml={};function El(t,a){return t==="."?{width:"0.34ch",justifyContent:"center",marginInline:"-0.04ch"}:t===","?{width:"0.08ch",justifyContent:"center",marginInline:"-0.30ch"}:{width:"0.72ch",justifyContent:"flex-start",paddingLeft:"0.04ch",height:a}}function Il({mv:t,digit:a,height:r}){const s=an(t,n=>{const i=(n%10+10)%10,o=(10+a-i)%10;let u=o*r;return o>5&&(u-=10*r),u});return e.jsx(ve.span,{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",y:s},children:a})}function Rl(t){const a=Math.round(t),r=1e-9*Math.max(1,Math.abs(t));return Math.abs(t-a)<r?a:t}function Fl(t,a){const r=t/a;return Math.floor(Rl(r))}function $l(t){const a=String(t??""),r=Array.from(a),s=r.indexOf(".");let n=r.filter((u,c)=>/\d/.test(u)&&(s===-1||c<s)).length,i=0,o=!1;return r.map(u=>{if(!/\d/.test(u))return u==="."&&(o=!0),u;if(!o){const c=10**Math.max(n-1,0);return n-=1,c}return i+=1,10**-i})}function Pl({place:t,value:a,height:r,digitStyle:s,shouldReduceMotion:n}){if(typeof t!="number"){const c=El(t,r),h=t!=="."&&t!==",",m=t===".";return e.jsx("span",{"data-counter-token":"static",className:"relative inline-flex items-center justify-center",style:{height:r,...c,...s,...h?{width:"auto",paddingInline:"0.06ch",justifyContent:"center"}:null,...m?{width:c.width}:null},children:t})}const i=Fl(a,t),o=rn(0),u=Tl(o,{stiffness:220,damping:26,mass:.8});return d.useEffect(()=>{o.set(i)},[o,i]),n?e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex items-center justify-center overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Math.abs(i)%10}):e.jsx("span",{"data-counter-token":"digit",className:"relative inline-flex overflow-hidden",style:{height:r,position:"relative",width:"0.9ch",fontVariantNumeric:"tabular-nums",...s},children:Array.from({length:10},(c,h)=>e.jsx(Il,{mv:u,digit:h,height:r},h))})}function Bl({value:t,displayValue:a,fontSize:r=72,padding:s=0,places:n,gap:i=6,borderRadius:o=4,horizontalPadding:u=0,textColor:c="inherit",fontWeight:h="inherit",containerStyle:m,counterStyle:x,digitStyle:g,gradientHeight:p=14,gradientFrom:y="rgba(255,255,255,0.95)",gradientTo:k="rgba(255,255,255,0)",topGradientStyle:f,bottomGradientStyle:v}){const w=String(a??t??""),D=d.useMemo(()=>Array.isArray(n)&&n.length?n:$l(w),[n,w]),C=typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent||"")||typeof process<"u"&&Ml?.VITEST==="true",R=Nr()||C,A=Number.isFinite(Number(t))?Math.abs(Number(t)):0,P=r+s;return R?e.jsx("span",{"data-counter-root":"true",style:{display:"inline-flex",alignItems:"center",color:c,fontSize:r,fontWeight:h,lineHeight:1,...m,...x},children:w}):e.jsxs("span",{"data-counter-root":"true",style:{position:"relative",display:"inline-block",...m},children:[e.jsx("span",{style:{fontSize:r,display:"flex",gap:i,overflow:"hidden",borderRadius:o,paddingLeft:u,paddingRight:u,lineHeight:1,color:c,fontWeight:h,...x},children:D.map((N,j)=>e.jsx(Pl,{place:N,value:A,height:P,digitStyle:g,shouldReduceMotion:R},`${String(N)}-${j}`))}),e.jsxs("span",{style:{pointerEvents:"none",position:"absolute",inset:0,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[e.jsx("span",{style:f??{height:p,background:`linear-gradient(to bottom, ${y}, ${k})`}}),e.jsx("span",{style:v??{height:p,background:`linear-gradient(to top, ${y}, ${k})`}})]})]})}function zl({baseUrl:t,accessToken:a,guestAllowed:r=!1,weeks:s=52,weekStartsOn:n="sun",cacheKey:i,timeZone:o,tzOffsetMinutes:u,now:c,accountView:h=!1,accountAccessToken:m=null,accountRevision:x=0,accountViewResolving:g=!1,deviceId:p=null}={}){const y=!!(h&&m),k=y?"cloud":"local",f=d.useMemo(()=>Zo({weeks:s,weekStartsOn:n,now:c}),[c,s,n]),[v,w]=d.useState([]),[D,C]=d.useState(null),[R,A]=d.useState("edge"),[P,N]=d.useState(!1),[j,S]=d.useState(null),E=ut(),O=Yt(a),F=!r,L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=St([t,f.from,f.to,s,n,k,a,m,x,g,p,o,u,r,E,F,O,L]),K=d.useMemo(()=>{if(!i)return null;const W=_r({timeZone:o,offsetMinutes:u});return`tokentracker.heatmap.${i}.${k}.${s}.${n}.${W}.${p||"all"}`},[i,p,k,o,u,s,n]),q=d.useCallback(()=>{if(!K||typeof window>"u")return null;try{const W=window.localStorage.getItem(K);if(!W)return null;const ne=JSON.parse(W);return!ne||!ne.heatmap?null:ne}catch{return null}},[K]),_=d.useCallback(W=>{if(!(!K||typeof window>"u"))try{window.localStorage.setItem(K,JSON.stringify(W))}catch{}},[K]),$=d.useCallback(()=>{if(!(!K||typeof window>"u"))try{window.localStorage.removeItem(K)}catch{}},[K]),H=d.useRef(k);d.useEffect(()=>{H.current!==k&&(H.current=k,w([]),C(null),A("edge"),S(null),N(!0))},[k]);const te=d.useCallback(async()=>{const W=B(),ne=await Oe(a),oe=y?await Oe(m):null;if(!W()||!ne&&!E&&!L&&!y)return;if(y&&!oe){S("Your session expired. Please sign in again to view account data."),N(!1);return}const je=y?oe:ne,be=y?Jo:Qo,Le=y?Ws:Gs;N(!0),S(null);try{try{const ee=await be({baseUrl:t,accessToken:je,weeks:s,to:f.to,weekStartsOn:n,device:p,timeZone:o,tzOffsetMinutes:u}),ae=Array.isArray(ee?.weeks)?ee.weeks:[];if(!W())return;if(!ae.length&&F){const Y=q();if(Y?.heatmap){if(!W())return;C(Y.heatmap),w(Y.daily||[]),A("cache");return}}if(!ae.some(Y=>(Array.isArray(Y)?Y:[]).some(J=>J&&Number.isFinite(Number(J.level))))&&ae.length){const Y=[];for(const Z of ae)for(const ge of Array.isArray(Z)?Z:[])ge?.day&&Y.push({day:ge.day,total_tokens:ge.total_tokens??ge.value??0,billable_total_tokens:ge.billable_total_tokens??ge.value??ge.total_tokens??0});const J=qr({dailyRows:Y,weeks:s,to:ee?.to||f.to,weekStartsOn:n});if(!W())return;w(Y),C({...J,week_starts_on:n,active_days:Y.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ga({dailyRows:Y,to:ee?.to||f.to})}),A("client"),F?_({heatmap:{...J,week_starts_on:n,active_days:Y.filter(Z=>Number(Z?.billable_total_tokens??Z?.total_tokens)>0).length,streak_days:ga({dailyRows:Y,to:ee?.to||f.to})},daily:Y,fetchedAt:new Date().toISOString()}):$();return}if(!W())return;C(ee||null),w([]),A("edge"),ee&&F?_({heatmap:ee,daily:[],fetchedAt:new Date().toISOString()}):F||$();return}catch(ee){const ae=ee,ye=ae?.status??ae?.statusCode;if(ye===401||ye===403)throw ee}if(!W())return;const X=await Le({baseUrl:t,accessToken:je,from:f.from,to:f.to,device:p,timeZone:o,tzOffsetMinutes:u}),U=Array.isArray(X?.data)?X.data:[];if(!W())return;w(U);const re=qr({dailyRows:U,weeks:s,to:f.to,weekStartsOn:n});if(!W())return;C({...re,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ga({dailyRows:U,to:f.to})}),A("client"),F?_({heatmap:{...re,week_starts_on:n,active_days:U.filter(ee=>Number(ee?.billable_total_tokens??ee?.total_tokens)>0).length,streak_days:ga({dailyRows:U,to:f.to})},daily:U,fetchedAt:new Date().toISOString()}):$()}catch(X){if(!W())return;if(F){const U=q();if(U?.heatmap){if(!W())return;C(U.heatmap),w(U.daily||[]),A("cache"),S(null)}else{const re=X;S(re?.message||String(re)),w([]),C(null),A("edge")}}else{const U=X;S(U?.message||String(U)),w([]),C(null),A("edge")}}finally{W()&&N(!1)}},[a,t,E,r,F,f.from,f.to,q,O,o,u,n,s,$,_,L,y,m,x,p,B]);return d.useEffect(()=>{if(g){N(!0);return}if(!O&&!r&&!E&&!L&&!y){w([]),N(!1),S(null),C(null),A("edge");return}if(!F)$(),w([]),S(null),C(null),A("edge");else{const W=q();W?.heatmap&&(C(W.heatmap),w(W.daily||[]),A("cache"))}te()},[a,E,q,te,O,r,F,$,L,g]),{range:f,daily:v,heatmap:D,source:E?"mock":R==="client"?"edge":R,loading:P,error:j,refresh:te}}const Ol="tokentracker.dashboard.leftCardOrder.v1",Ul="tokentracker.dashboard.rightCardOrder.v1";function Hl(t,a){const r=ts(Ol,t),s=ts(Ul,a),n=r.order.join("|")!==t.join("|")||s.order.join("|")!==a.join("|"),i=d.useCallback(()=>{r.reset(),s.reset()},[r,s]);return{left:r,right:s,isCustomized:n,resetAll:i}}const Vl=10;function Kl({baseUrl:t,accessToken:a,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o}={}){const[u,c]=d.useState([]),[h,m]=d.useState(!1),[x,g]=d.useState(null),p=ut(),y=Yt(a),k=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),f=St([t,a,r,s,n,i,o]),v=d.useCallback(async()=>{const w=f(),D=await Oe(a);if(w()){if(!D&&!p&&!k){c([]),g(null),m(!1);return}m(!0),g(null);try{const C=await Xo({baseUrl:t,accessToken:D,limit:Vl,from:r,to:s,source:n,timeZone:i,tzOffsetMinutes:o});if(!w())return;c(Array.isArray(C?.entries)?C.entries:[])}catch(C){if(!w())return;const R=C?.message||String(C);g(R),c([])}finally{w()&&m(!1)}}},[a,t,r,p,n,i,s,o,k,f]);return d.useEffect(()=>{if(!y&&!p&&!k){c([]),g(null),m(!1);return}c([]),g(null),m(!0),v()},[p,v,y,k]),{entries:u,loading:h,error:x,refresh:v}}const os="tokentracker.usage-cache-index",is=24;function ls({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,includeDaily:i=!0,includeSummary:o=!0,cacheKey:u,timeZone:c,tzOffsetMinutes:h,now:m,accountView:x=!1,accountAccessToken:g=null,accountRevision:p=0,accountViewResolving:y=!1,deviceId:k=null}={}){const f=!!(x&&g),v=f?"cloud":"local",[w,D]=d.useState([]),[C,R]=d.useState(null),[A,P]=d.useState(null),[N,j]=d.useState("edge"),[S,E]=d.useState(null),[O,F]=d.useState(!1),[L,B]=d.useState(null),K=ut(),q=Yt(a),_=!r&&!K,$=k||"all",H=(()=>{if(!u)return null;const X=Wl(t)||"default",U=i?o?"daily-summary":"daily-only":"summary",re=_r({timeZone:c,offsetMinutes:h});return`tokentracker.usage.${u}.${v}.${X}.${s}.${n}.${U}.${re}.${$}`})(),te=d.useRef(v);d.useEffect(()=>{te.current!==v&&(te.current=v,D([]),R(null),P(null),j("edge"),E(null),B(null),F(!0))},[v]);const ue=d.useCallback(()=>{if(!H||typeof window>"u")return null;try{const X=window.localStorage.getItem(H);if(!X)return null;const U=JSON.parse(X),re=o?!!U?.summary:Array.isArray(U?.daily);return!U||!re?null:(as(os,H,is),U)}catch{return null}},[o,H]),W=d.useCallback(X=>{if(!(!H||typeof window>"u"))try{window.localStorage.setItem(H,JSON.stringify(X)),as(os,H,is)}catch{}},[H]),ne=d.useCallback(()=>{if(!(!H||typeof window>"u"))try{window.localStorage.removeItem(H)}catch{}},[H]),oe=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),je=St([t,s,n,i,o,v,a,g,p,k,c,h,r,K,_,y,q,oe]),be=d.useCallback(async()=>{const X=je(),U=await Oe(a),re=f?await Oe(g):null;if(!X()||!U&&!K&&!oe&&!f)return;if(f&&!re){B("Your session expired. Please sign in again to view account data."),F(!1);return}const ee=f?Ws:Gs,ae=f?ei:ti,ye=f?re:U;F(!0),B(null);try{let Y=null,J=null;if(i)if(o){const[T,z]=await Promise.allSettled([ee({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h}),ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0})]);if(T.status==="rejected")throw T.reason;Y=T.value,J=z.status==="fulfilled"?z.value:null}else Y=await ee({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h});else o&&(J=await ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0}));let Z=i&&Array.isArray(Y?.data)?Y.data:[];i&&(Z=Xa(Z,s,n,{timeZone:c,offsetMinutes:h,now:m}));let ge=o&&(J?.totals||Y?.summary?.totals)||null,$e=o&&(J?.rolling||Y?.summary?.rolling)||null;if(o&&i&&!ge&&!J)try{const T=await ae({baseUrl:t,accessToken:ye,from:s,to:n,device:k,timeZone:c,tzOffsetMinutes:h,rolling:!0});ge=T?.totals||null,$e=T?.rolling||$e}catch{}const me=new Date().toISOString();if(!X())return;D(Z),R(ge),P($e),j("edge"),E(me),(ge||!o&&i)&&_?W({summary:ge,rolling:$e,daily:Z,from:s,to:n,includeDaily:i,includeSummary:o,fetchedAt:me}):_||ne()}catch(Y){if(!X())return;if(_){const J=ue();if(J?.summary||!o&&Array.isArray(J?.daily)){R(J.summary),P(J.rolling||null);const Z=Array.isArray(J.daily)?J.daily:[],ge=i?Xa(Z,J.from||s,J.to||n,{timeZone:c,offsetMinutes:h,now:m}):Z;D(ge),j("cache"),E(J.fetchedAt||null),B(null)}else{const Z=Y;B(Z?.message||String(Z)),D([]),R(null),P(null),j("edge"),E(null)}}else{const J=Y;B(J?.message||String(J)),D([]),R(null),P(null),j("edge"),E(null)}}finally{X()&&F(!1)}},[a,t,s,i,o,K,r,_,m,ue,q,c,n,h,ne,W,oe,f,g,p,k,je]);return d.useEffect(()=>{if(y){F(!0);return}const X=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");if(!q&&!r&&!K&&!X&&!f){D([]),R(null),P(null),B(null),F(!1),j("edge"),E(null);return}if(!_)ne(),D([]),R(null),P(null),B(null),j("edge"),E(null);else{const U=ue();if(U?.summary||!o&&Array.isArray(U?.daily)){R(U.summary),P(U.rolling||null);const re=Array.isArray(U.daily)?U.daily:[],ee=i?Xa(re,U.from||s,U.to||n,{timeZone:c,offsetMinutes:h,now:m}):re;D(ee),j("cache"),E(U.fetchedAt||null),B(null)}else D([]),R(null),P(null),j("edge"),E(null),B(null)}F(!0),be()},[a,K,ue,be,q,r,_,ne,oe,y,o]),d.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const X=15e3;let U=Date.now();const re=()=>{if(document.visibilityState!=="visible")return;const ee=Date.now();ee-U<X||(U=ee,be())};return window.addEventListener("focus",re),document.addEventListener("visibilitychange",re),()=>{window.removeEventListener("focus",re),document.removeEventListener("visibilitychange",re)}},[be]),{daily:w,summary:C,rolling:A,source:K?"mock":N,fetchedAt:S,loading:O,error:L,refresh:be}}function Wl(t){try{return new URL(t).host}catch{return null}}function Qa(t){if(!t)return null;const a=String(t).trim(),r=a.split("-");if(r.length!==3)return null;const s=Number(r[0]),n=Number(r[1])-1,i=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n,i));return Number.isFinite(o.getTime())&&Wt(o)===a?o:null}function Gl(t,a){return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()+a))}function Xa(t,a,r,{timeZone:s,offsetMinutes:n,now:i}={}){const o=Qa(a),u=Qa(r);if(!o||!u||u<o)return Array.isArray(t)?t:[];const c=i instanceof Date&&Number.isFinite(i.getTime())?i:new Date,h=vr({timeZone:s,offsetMinutes:n,date:c}),m=Qa(h),x=m?m.getTime():c.getTime(),g=new Map;for(const y of t||[])y?.day&&g.set(y.day,y);const p=[];for(let y=o;y<=u;y=Gl(y,1)){const k=Wt(y),f=g.get(k),v=y.getTime()>x;if(f){p.push({...f,missing:!1,future:v});continue}p.push({day:k,total_tokens:null,billable_total_tokens:null,input_tokens:null,cached_input_tokens:null,output_tokens:null,reasoning_output_tokens:null,missing:!v,future:v})}return p}function ql({baseUrl:t,accessToken:a,guestAllowed:r=!1,from:s,to:n,cacheKey:i,timeZone:o,tzOffsetMinutes:u,accountView:c=!1,accountAccessToken:h=null,accountRevision:m=0,accountViewResolving:x=!1,deviceId:g=null}={}){const p=!!(c&&h),y=p?"cloud":"local",[k,f]=d.useState(null),[v,w]=d.useState("edge"),[D,C]=d.useState(!1),[R,A]=d.useState(null),P=ut(),N=Yt(a),j=!r,S=d.useMemo(()=>{if(!i)return null;const $=Yl(t)||"default",H=_r({timeZone:o,offsetMinutes:u});return`tokentracker.modelBreakdown.${i}.${y}.${$}.${s}.${n}.${H}.${g||"all"}`},[t,i,g,s,y,o,n,u]),E=d.useCallback(()=>{if(!S||typeof window>"u")return null;try{const $=window.localStorage.getItem(S);if(!$)return null;const H=JSON.parse($);return!H||!H.breakdown?null:H}catch{return null}},[S]),O=d.useCallback($=>{if(!(!S||typeof window>"u"))try{window.localStorage.setItem(S,JSON.stringify($))}catch{}},[S]),F=d.useCallback(()=>{if(!(!S||typeof window>"u"))try{window.localStorage.removeItem(S)}catch{}},[S]),L=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),B=St([t,s,n,y,a,h,m,g,o,u,r,P,j,x,N,L]),K=d.useRef(y);d.useEffect(()=>{K.current!==y&&(K.current=y,f(null),w("edge"),A(null),C(!0))},[y]);const q=d.useCallback(async()=>{const $=B(),H=await Oe(a),te=p?await Oe(h):null;if(!$()||!H&&!P&&!L&&!p)return;if(p&&!te){A("Your session expired. Please sign in again to view account data."),C(!1);return}const ue=p?te:H,W=p?ai:ri;C(!0),A(null);try{const ne=await W({baseUrl:t,accessToken:ue,from:s,to:n,device:g,timeZone:o,tzOffsetMinutes:u});if(!$())return;f(ne||null),w("edge"),ne&&j?O({breakdown:ne,fetchedAt:new Date().toISOString()}):j||F()}catch(ne){if(!$())return;if(j){const oe=E();if(oe?.breakdown)f(oe.breakdown),w("cache"),A(null);else{f(null),w("edge");const je=ne;A(je?.message||String(je))}}else{f(null),w("edge");const oe=ne;A(oe?.message||String(oe))}}finally{$()&&C(!1)}},[a,t,s,P,r,j,E,o,n,N,u,F,O,L,p,h,m,g,B]);return d.useEffect(()=>{if(x){C(!0);return}if(!N&&!r&&!P&&!L&&!p){f(null),w("edge"),A(null),C(!1);return}if(!j)F(),f(null),w("edge"),A(null);else{const $=E();$?.breakdown?(f($.breakdown),w("cache"),A(null)):(f(null),w("edge"),A(null))}C(!0),q()},[a,P,E,q,N,r,j,F,L,x]),{breakdown:k,source:P?"mock":v,loading:D,error:R,refresh:q}}function Yl(t){try{return new URL(t).host}catch{return null}}const on=new Set(["day","hour","month"]);function Zl(t){return on.has(t)}function cs(t){if(t==null)return null;const a=String(t).trim();if(!/^[0-9]+$/.test(a))return null;const r=a.replace(/^0+/,"");return r.length===0?"0":r}function Jl(t,a){const r=cs(t),s=cs(a);if(r&&s)return r.length!==s.length?r.length<s.length?-1:1:r===s?0:r<s?-1:1;const n=se(t),i=se(a);return n==null&&i==null?0:n==null?1:i==null?-1:n===i?0:n<i?-1:1}function Ql(t,a){const r=typeof t=="string"?t:String(t||""),s=typeof a=="string"?a:String(a||"");return r===s?0:r<s?-1:1}function Xl(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i))return null;const o=new Date(Date.UTC(s,n-1,i));return!Number.isFinite(o.getTime())||o.getUTCFullYear()!==s||o.getUTCMonth()+1!==n||o.getUTCDate()!==i?null:o.getTime()}function ec(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]);if(!Number.isFinite(s)||!Number.isFinite(n)||n<1||n>12)return null;const i=new Date(Date.UTC(s,n-1,1));return Number.isFinite(i.getTime())?i.getTime():null}function tc(t){if(!t)return null;const r=String(t).trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?Z?$/);if(!r)return null;const s=Number(r[1]),n=Number(r[2]),i=Number(r[3]),o=Number(r[4]),u=Number(r[5]),c=Number(r[6]||0);if(!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(o)||!Number.isFinite(u)||!Number.isFinite(c)||n<1||n>12||i<1||i>31||o<0||o>23||u<0||u>59||c<0||c>59)return null;const h=new Date(Date.UTC(s,n-1,i,o,u,c));return Number.isFinite(h.getTime())?h.getTime():null}function ac(t,a,r){const s=r==="hour"?tc:r==="month"?ec:Xl,n=s(t),i=s(a);return n!=null&&i!=null?n===i?0:n<i?-1:1:Ql(t,a)}function ln(t,{key:a,dir:r}){const s=r==="asc"?1:-1,n=Array.isArray(t)?t:[],i=on.has(a)?(u,c)=>ac(u,c,a):Jl,o=u=>a==="total_tokens"&&u?.billable_total_tokens!=null?u.billable_total_tokens:u?.[a];return n.map((u,c)=>({row:u,index:c})).sort((u,c)=>{const h=o(u.row),m=o(c.row),x=h==null,g=m==null;if(x&&g)return u.index-c.index;if(x)return 1;if(g)return-1;const p=i(h,m);return p!==0?p*s:u.index-c.index}).map(u=>u.row)}function rc(){return[{key:"day",label:l("daily.sort.date.label"),title:l("daily.sort.date.title")},{key:"total_tokens",label:l("daily.sort.total.label"),title:l("daily.sort.total.title")},{key:"input_tokens",label:l("daily.sort.input.label"),title:l("daily.sort.input.title")},{key:"output_tokens",label:l("daily.sort.output.label"),title:l("daily.sort.output.title")},{key:"cached_input_tokens",label:l("daily.sort.cached.label"),title:l("daily.sort.cached.title")},{key:"reasoning_output_tokens",label:l("daily.sort.reasoning.label"),title:l("daily.sort.reasoning.title")},{key:"conversation_count",label:l("daily.sort.conversations.label"),title:l("daily.sort.conversations.title")}]}function ds(t){const a=Zl(t)?t:"day";return rc().map((r,s)=>s===0?{...r,key:a}:r)}function us(t,{key:a,dir:r}){return ln(t,{key:a,dir:r})}const ja=12,sc=["total_tokens","billable_total_tokens","input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens"];function nc(t){if(typeof t=="bigint")return t!==0n;if(typeof t=="number")return Number.isFinite(t)&&t!==0;if(t==null)return!1;const a=String(t).trim();if(!a||!/^-?\d+$/.test(a))return!1;const r=a.startsWith("-")?a.slice(1):a;return/[1-9]/.test(r)}function oc(t){return sc.some(a=>nc(t?.[a]))}function ic(t){const a=Array.isArray(t)?t:[];if(!a.length)return[];const r=ln(a,{key:"month",dir:"asc"}),s=r.findIndex(n=>n?.month&&oc(n));return s===-1?a:r.slice(s)}function lc(t,a,r=ja){const s=Array.isArray(t)?t:[],n=Number.isFinite(r)&&r>0?r:ja,o=(Number.isFinite(a)&&a>=0?Math.floor(a):0)*n;return s.slice(o,o+n)}function cc({publicMode:t,screenshotMode:a,forceInstall:r,accessEnabled:s,heatmapLoading:n,activeDays:i,hasActiveDeviceToken:o}={}){return t||a?!1:r?!0:s&&!n&&i===0&&!o}const fa=Object.freeze({active:3e4,warm:2*6e4,idle:10*6e4,longIdle:30*6e4});function dc({visible:t=!0,lastInteractionAt:a=0,now:r=Date.now()}={}){if(!t)return fa.longIdle;const s=Math.max(0,r-(Number(a)||0));return s<=10*6e4?fa.active:s<=60*6e4?fa.warm:fa.idle}const uc=3e4;function mc({refresh:t,intervalMs:a=uc,windowRef:r=window,documentRef:s=document,onError:n=()=>{}}){let i=!1,o=null,u=Date.now(),c=0;const h=()=>{if(i||s.visibilityState!=="visible"||o)return o;const p=Promise.resolve().then(()=>t()).catch(y=>n(y)).then(()=>{}).finally(()=>{o===p&&(o=null)});return o=p,p},m=r.setInterval(()=>{const p=Date.now();p<c||(c=p+dc({visible:s.visibilityState==="visible",lastInteractionAt:u,now:p}),h())},a),x=()=>{s.visibilityState==="visible"&&(u=Date.now(),c=0,h())},g=()=>{u=Date.now()};return r.addEventListener("focus",x),r.addEventListener("pointerdown",g),r.addEventListener("keydown",g),s.addEventListener("visibilitychange",x),{run:h,stop(){i=!0,r.clearInterval(m),r.removeEventListener("focus",x),r.removeEventListener("pointerdown",g),r.removeEventListener("keydown",g),s.removeEventListener("visibilitychange",x)}}}function hc(t){if(!t)return null;const a=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!a)return null;const r=new Date(Date.UTC(Number(a[1]),Number(a[2])-1,Number(a[3])));return Wt(r)===t?r:null}function gc({period:t,selectedFrom:a,selectedTo:r,todayKey:s}={}){if(t==="total"&&a&&r)return{from:a,to:r};const n=hc(s)||new Date,i=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()-29));return{from:Wt(i),to:Wt(n)}}function xc(t,{period:a}={}){const r=(Array.isArray(t)?t:[]).filter(n=>!n?.future&&n?.day);return(a==="total"?r.filter(n=>!n?.missing):r).slice(-30)}function Sr(t){if(typeof t!="string")return null;const a=t.trim();return a?a.toLowerCase():null}function fc(t){const a=Sr(t?.model_id);return a||null}function cn(t,a){return t?.model?String(t.model):a}function dn(t){const a=new Map,r=new Map;for(const s of t){const n=typeof s?.name=="string"?s.name.trim():"",i=Sr(n);if(!i||i.includes("/"))continue;const o=Math.max(0,se(s?.weight)??0);(!a.has(i)||o>=(r.get(i)||0))&&(a.set(i,n),r.set(i,o))}return a}function un(t,a){const r=Sr(t);if(!r)return null;const s=r.lastIndexOf("/");if(s>0){const n=r.slice(s+1);if(a.has(n))return{key:n,name:a.get(n)}}return{key:r,name:t}}function Nt(t,a=0){const r=se(t?.billable_total_tokens),s=se(t?.total_tokens);return r!=null&&r>0?r:s!=null&&s>0?s:r??s??a}const pc={deepseek:"dsh"};function yc(t){const a=typeof t=="string"?t:"";return pc[a]||a}const bc=["total_tokens","billable_total_tokens","input_tokens","output_tokens","cached_input_tokens","cache_creation_input_tokens","reasoning_output_tokens"];function ms(t,a){for(const r of bc)t[r]=(Number(t[r])||0)+(Number(a?.[r])||0);t.total_cost_usd=String(Number(t.total_cost_usd||0)+Number(a?.total_cost_usd||0))}function hs(){return{total_tokens:0,billable_total_tokens:0,input_tokens:0,output_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,reasoning_output_tokens:0,total_cost_usd:"0"}}function kc(t){const a=new Map;for(const r of t||[]){const s=yc(r?.source);if(!s)continue;let n=a.get(s);n||(n={source:s,source_scope:r?.source_scope,totals:hs(),models:new Map},a.set(s,n)),ms(n.totals,r?.totals);for(const i of Array.isArray(r?.models)?r.models:[]){const o=i?.model_id||i?.model||"";if(!o)continue;let u=n.models.get(o);u||(u={model:i?.model||o,model_id:o,totals:hs()},n.models.set(o,u)),ms(u.totals,i?.totals)}}return Array.from(a.values()).map(r=>({...r,models:Array.from(r.models.values())}))}function wc(t,{copyFn:a}={}){const r=typeof a=="function"?a:o=>o,n=kc(Array.isArray(t?.sources)?t.sources:[]).map(o=>{const u=Nt(o?.totals),c=se(o?.totals?.total_cost_usd)??0;return{source:o?.source,totalTokens:Number.isFinite(u)?u:0,totalCost:Number.isFinite(c)?c:0,inputTokens:Math.max(0,se(o?.totals?.input_tokens)??0),cacheRead:Math.max(0,se(o?.totals?.cached_input_tokens)??0),cacheCreate:Math.max(0,se(o?.totals?.cache_creation_input_tokens)??0),models:Array.isArray(o?.models)?o.models:[]}}).filter(o=>o.totalTokens>0);if(!n.length)return[];const i=n.reduce((o,u)=>o+u.totalTokens,0);return typeof t?.pricing?.pricing_mode=="string"&&t.pricing.pricing_mode.toUpperCase(),n.slice().sort((o,u)=>u.totalTokens-o.totalTokens).map(o=>{const u=o.source?String(o.source).toUpperCase():r("shared.placeholder.short"),c=i>0?o.totalTokens/i*100:0,h=Number.isFinite(c)?c.toFixed(2):"0.00",m=o.models.map(y=>{const k=Nt(y?.totals);if(!Number.isFinite(k)||k<=0)return null;const f=o.totalTokens>0?Math.round(k/o.totalTokens*1e3)/10:0,v=cn(y,r("shared.placeholder.short")),w=fc(y),D=se(y?.totals?.total_cost_usd),C=D??(o.totalCost>0&&o.totalTokens>0?k/o.totalTokens*o.totalCost:null);return{id:w,name:v,share:f,usage:k,cost:C}}).filter(Boolean),x=o.inputTokens+o.cacheRead+o.cacheCreate,p=o.cacheRead+o.cacheCreate>0&&x>0?Math.round(o.cacheRead/x*100):null;return{source:o.source,label:u,totalPercent:String(h),totalPercentValue:c,usd:o.totalCost,usage:o.totalTokens,cacheHitRate:p,cacheReusedTokens:o.cacheRead,cacheInputTokens:x,models:m}})}function _c(t){const a=Array.isArray(t)?t:[],r=new Map,s=[];for(const o of a){const u=Array.isArray(o?.models)?o.models:[];for(const c of u){const h=se(c?.usage);if(h==null||h<=0)continue;const m=typeof c?.name=="string"&&c.name.trim()?c.name.trim():typeof c?.id=="string"&&c.id.trim()?c.id.trim():null;m&&s.push({model:c,name:m,usage:h})}}const n=dn(s.map(o=>({name:o.name,weight:o.usage})));for(const{model:o,name:u,usage:c}of s){const h=un(u,n);if(!h)continue;const{key:m}=h,x=r.get(m)||{id:m,name:h.name,usage:0,cost:0,hasCost:!1,nameWeight:0};x.usage+=c;const g=se(o?.cost);g!=null&&(x.cost+=g,x.hasCost=!0),n.has(m)?x.name=n.get(m):c>=x.nameWeight&&(x.name=u,x.nameWeight=c),r.set(m,x)}const i=Array.from(r.values()).reduce((o,u)=>o+u.usage,0);return Array.from(r.values()).map(o=>({id:o.id,name:o.name,usage:o.usage,cost:o.hasCost?o.cost:null,share:i>0?Math.round(o.usage/i*1e3)/10:0})).sort((o,u)=>u.usage!==o.usage?u.usage-o.usage:String(o.name).localeCompare(String(u.name)))}function vc(t,{limit:a=3,copyFn:r}={}){const s=typeof r=="function"?r:y=>y,n=Array.isArray(t?.sources)?t.sources:[];if(!n.length)return[];const i=new Map,o=new Map,u=new Map,c=[];let h=0;for(const y of n){const k=Array.isArray(y?.models)?y.models:[];for(const f of k){const v=Nt(f?.totals);if(!Number.isFinite(v)||v<=0)continue;h+=v;const w=cn(f,s("shared.placeholder.short"));c.push({name:w,tokens:v})}}const m=dn(c.map(y=>({name:y.name,weight:y.tokens})));for(const{name:y,tokens:k}of c){const f=un(y,m);if(!f)continue;const{key:v}=f;i.set(v,(i.get(v)||0)+k),m.has(v)?o.set(v,m.get(v)):k>=(u.get(v)||0)&&(u.set(v,k),o.set(v,y))}if(!i.size)return[];const x=Array.from(i.values()).reduce((y,k)=>y+k,0),g=h>0?h:x,p=Number.isFinite(a)?Math.max(0,Math.floor(a)):3;return Array.from(i.entries()).map(([y,k])=>{const f=g>0?(k/g*100).toFixed(1):"0.0";return{id:y,name:o.get(y)||s("shared.placeholder.short"),tokens:k,percent:String(f)}}).sort((y,k)=>k.tokens!==y.tokens?k.tokens-y.tokens:String(y.name).localeCompare(String(k.name))).slice(0,p)}function jc(t,a,r){if(!Number.isFinite(t))return l("shared.placeholder.short");const s=Sa(t,{decimals:2,currency:a,rate:r});return s==="-"?l("shared.placeholder.short"):s}function gs(t,a,r){if(!Number.isFinite(t)||t<=0)return null;const s=Gt(a);return(a===qs?t:t*r)<.01?`<${s}0.01`:Sa(t,{decimals:2,currency:a,rate:r})}function xs(t){const a=Number(t);return!Number.isFinite(a)||a<=0?null:Qe(a,{decimals:1})}const Nc=_t.memo(function({isOpen:a,onClose:r,fleetData:s=[]}){const{currency:n,rate:i}=Ca(),o=d.useMemo(()=>(Array.isArray(s)?s:[]).map(c=>{const h=se(c?.usd)??0,m=se(c?.usage)??0,x=Array.isArray(c?.models)?c.models:[];return{label:c?.label?String(c.label):"",usdValue:h,costLabel:gs(h,n,i),tokensLabel:xs(m),models:x.map(g=>{const p=se(g?.usage)??0,y=se(g?.cost)??0;return{id:g?.id?String(g.id):"",name:g?.name?String(g.name):"",tokensLabel:xs(p),costLabel:gs(y,n,i),sortCost:y}}).filter(g=>g.costLabel||g.tokensLabel).sort((g,p)=>p.sortCost-g.sortCost)}}).filter(c=>c.usdValue>0||c.models.length>0).sort((c,h)=>h.usdValue-c.usdValue),[s,n,i]),u=d.useMemo(()=>{const c=o.reduce((h,m)=>h+m.usdValue,0);return jc(c,n,i)},[o,n,i]);return e.jsx(Ji,{open:a,onOpenChange:c=>{c||r?.()},children:e.jsxs(Qi,{children:[e.jsx(Xi,{className:"cost-modal-backdrop","data-cost-analysis-backdrop":"true"}),e.jsx(el,{className:"fixed inset-0 z-[101] flex items-center justify-center p-4",children:e.jsxs(tl,{className:"cost-modal-popup relative w-full max-w-[460px] max-h-[calc(100vh-2rem)] flex flex-col rounded-2xl bg-white dark:bg-oai-gray-950 shadow-[0_20px_60px_-20px_rgba(0,0,0,0.25)] dark:shadow-[0_20px_60px_-10px_rgba(0,0,0,0.65)] ring-1 ring-oai-gray-200 dark:ring-oai-gray-800 overflow-hidden",children:[e.jsx(al,{render:e.jsx("h2",{className:"sr-only"}),children:l("dashboard.cost_breakdown.title")}),e.jsx(rl,{type:"button",className:"absolute top-3 right-3 flex h-9 w-9 items-center justify-center rounded-md text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-800 dark:hover:text-oai-gray-100 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50 transition-colors z-10","aria-label":l("dashboard.cost_breakdown.close"),children:e.jsx(jr,{size:16,strokeWidth:2,"aria-hidden":!0})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto oai-scrollbar",children:e.jsxs("div",{className:"px-3 py-6",children:[e.jsx("p",{className:"text-label uppercase tracking-[0.12em] text-oai-gray-500 dark:text-oai-gray-400 mb-2",children:l("dashboard.cost_breakdown.total_label")}),e.jsx("p",{className:"font-bold text-oai-brand tabular-nums tracking-tight leading-none mb-6",style:{fontSize:"clamp(24px, 6.5vw, 32px)"},children:u}),o.length===0?e.jsx("p",{className:"text-body-sm text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.cost_breakdown.empty")}):e.jsxs("div",{role:"table","aria-label":l("dashboard.cost_breakdown.title"),children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2 mb-2 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.model_column")}),e.jsx("span",{role:"columnheader",children:l("dashboard.cost_breakdown.cost_column")})]}),o.map((c,h)=>{const m=`fleet-${h}`;return e.jsxs("div",{role:"rowgroup","aria-labelledby":m,className:h>0?"mt-5":"mt-2",children:[e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-2",children:[e.jsx("span",{id:m,role:"rowheader",className:"flex-1 min-w-0 text-body-sm font-semibold text-oai-black dark:text-oai-white truncate leading-none",children:c.label}),e.jsx("span",{role:"cell",className:"shrink-0 text-body-sm font-semibold text-oai-black dark:text-oai-white tabular-nums leading-none",children:c.costLabel||"—"})]}),c.models.map((x,g)=>e.jsxs("div",{role:"row",className:"flex items-center justify-between gap-4 py-[5px]",children:[e.jsx("span",{role:"cell",className:"flex-1 min-w-0 text-caption text-oai-gray-500 dark:text-oai-gray-400 truncate leading-none",title:x.name,children:x.name}),e.jsx("span",{role:"cell",className:"shrink-0 text-caption text-oai-gray-700 dark:text-oai-gray-300 tabular-nums leading-none",children:x.costLabel||""})]},x.id||`${x.name}-${g}`))]},`${c.label}-${h}`)})]})]})})]})})]})})});function Sc({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[h,m]=d.useState(null),x=ut();return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}let g=!0;return c(!0),m(null),si({projectKey:t,from:a,to:r,timeZone:s,tzOffsetMinutes:n}).then(p=>{g&&o(p||null)}).catch(p=>{g&&(m(p?.message||String(p)),o(null))}).finally(()=>{g&&c(!1)}),()=>{g=!1}},[t,a,r,s,n,x]),{data:i,loading:u,error:h}}function mn(t){if(typeof t!="string"||!t)return{owner:"",repo:""};const a=t.indexOf("/");return a<0?{owner:"",repo:t}:{owner:t.slice(0,a),repo:t.slice(a+1)}}function hn(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function gn(t){return t?t==="github.com"||t.endsWith(".github.com")?"github":t.includes("gitlab")||t.startsWith("git.")?"gitlab":"generic":""}function xn(t,a){return a&&gn(hn(t))==="github"?a:""}function fn({githubOwner:t,letter:a,size:r="w-8 h-8"}){const[s,n]=d.useState(!1);return t&&!s?e.jsx("img",{src:`https://github.com/${t}.png?size=80`,alt:"",loading:"lazy",onError:()=>n(!0),className:`${r} rounded-md object-cover bg-oai-gray-100 dark:bg-oai-gray-800 flex-shrink-0`}):e.jsx("div",{className:`${r} rounded-md oai-bg-elevated flex items-center justify-center oai-text-caption font-medium text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0`,children:a})}const fs="#10b981",er=[{key:"input_tokens",labelKey:"dashboard.projects.detail.comp_input",color:"#38bdf8"},{key:"cached_input_tokens",labelKey:"dashboard.projects.detail.comp_cached",color:"#14b8a6"},{key:"cache_creation_input_tokens",labelKey:"dashboard.projects.detail.comp_cache_write",color:"#f59e0b"},{key:"output_tokens",labelKey:"dashboard.projects.detail.comp_output",color:"#a78bfa"},{key:"reasoning_output_tokens",labelKey:"dashboard.projects.detail.comp_reasoning",color:"#fb7185"}],tr=60;function Cc(t,a,r,s){if(!Array.isArray(t)||t.length===0)return[];const n=new Map(t.map(g=>[g.day,g]));let i=a||t[0].day,o=r||t[t.length-1].day;i>o&&([i,o]=[o,i]),s&&o>s&&(o=s);const u=t[t.length-1].day;o<u&&(o=u);const c=new Date(`${i}T00:00:00Z`),h=new Date(`${o}T00:00:00Z`);if(!Number.isFinite(c.getTime())||!Number.isFinite(h.getTime()))return t;const m=Math.round((h.getTime()-c.getTime())/864e5)+1;m>tr&&c.setUTCDate(c.getUTCDate()+(m-tr));const x=[];for(;c.getTime()<=h.getTime()&&x.length<tr;){const g=c.toISOString().slice(0,10);x.push(n.get(g)||{day:g,total_tokens:0,billable_total_tokens:0}),c.setUTCDate(c.getUTCDate()+1)}return x}function ar(t){if(!Number.isFinite(t))return"—";const a=t*100;return`${a>=10?Math.round(a):a.toFixed(1)}%`}function wt({label:t,value:a,title:r}){return e.jsxs("div",{className:"flex flex-col gap-1.5 group min-w-0",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:t}),e.jsx("span",{className:"text-xl font-black font-mono text-zinc-900 dark:text-zinc-50 tracking-tight leading-none tabular-nums truncate transition-transform duration-200 group-hover:-translate-y-[1px]",title:r,children:a})]})}function Tc({host:t}){if(!t)return null;let a;const r=gn(t);return r==="github"||r==="gitlab"?a=e.jsx(Ct,{provider:r,size:12,className:"fill-current"}):a=e.jsx(wl,{size:12}),e.jsx("span",{title:t,"aria-label":t,className:"inline-flex flex-shrink-0 items-center",children:a})}function rr({children:t}){return e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500 select-none",children:t})}function Ac({entry:t,query:a={},onClose:r}){const[s,n]=_t.useState(!1),i=typeof t?.project_key=="string"?t.project_key:"",{owner:o,repo:u}=mn(i),c=typeof t?.project_ref=="string"?t.project_ref:"",h=hn(c),{data:m,loading:x,error:g}=Sc({projectKey:i,from:a.from,to:a.to,timeZone:a.timeZone,tzOffsetMinutes:a.tzOffsetMinutes}),{formatTokens:p,formatTokensTooltip:y}=Fe(),k=_t.useCallback(()=>n(!0),[]),f=L=>{L.target===L.currentTarget&&s&&r()};_t.useEffect(()=>{const L=B=>{B.key==="Escape"&&k()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[k]);const v=m?.totals||null,w=se(v?.billable_total_tokens)??0,D=Number(m?.days_active||0),C=se(v?.input_tokens)??0,R=se(v?.cached_input_tokens)??0,A=C+R>0?R/(C+R):null,P=se(m?.range_total_tokens)??0,N=se(v?.total_tokens)??0,j=P>0?N/P:null,S=_t.useMemo(()=>Cc(m?.daily,m?.from,m?.to,vr({timeZone:a.timeZone,offsetMinutes:a.tzOffsetMinutes})),[m,a.timeZone,a.tzOffsetMinutes]),E=er.reduce((L,B)=>L+(se(v?.[B.key])??0),0),O=Array.isArray(m?.sources)?m.sources:[],F=!x&&!g&&v&&N>0;return e.jsx("div",{onAnimationEnd:f,onClick:L=>{L.target===L.currentTarget&&k()},className:jt("fixed inset-0 z-50 flex items-center justify-center p-3 md:p-6 backdrop-blur-md bg-black/15 dark:bg-black/40",s?"animate-tt-fade-out":"animate-tt-fade-in"),children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":i,className:jt("relative w-full max-w-4xl max-h-[88vh] backdrop-blur-2xl bg-white/90 dark:bg-oai-gray-900/90 border border-oai-gray-200/50 dark:border-white/10 shadow-2xl rounded-2xl flex flex-col md:flex-row overflow-hidden",s?"animate-tt-modal-exit":"animate-tt-modal"),children:[e.jsx("button",{type:"button",onClick:k,"aria-label":l("dashboard.projects.detail.close_aria"),className:"absolute top-4 right-4 z-50 p-2 rounded-full border border-oai-gray-200/60 dark:border-oai-gray-800/60 bg-white/50 dark:bg-oai-gray-900/50 text-oai-gray-500 dark:text-oai-gray-400 hover:text-oai-gray-900 dark:hover:text-white hover:rotate-90 hover:scale-105 active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-all duration-300",children:e.jsx(jr,{size:16})}),e.jsxs("div",{className:"w-full md:w-[300px] shrink-0 border-b md:border-b-0 md:border-r border-zinc-200/50 dark:border-zinc-800/40 p-5 md:p-6 flex flex-col gap-5 overflow-y-auto backdrop-blur-md bg-zinc-50/50 dark:bg-zinc-950/50",children:[e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:fs}}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5",style:{backgroundColor:fs}})]}),e.jsx("span",{className:"text-[9px] font-extrabold uppercase tracking-widest font-mono text-zinc-400 dark:text-zinc-500",children:l("dashboard.projects.detail.badge")})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3 min-w-0",children:[e.jsx(fn,{githubOwner:xn(c,o),letter:(u?.[0]||i?.[0]||"?").toUpperCase(),size:"w-10 h-10"}),e.jsxs("div",{className:"min-w-0",children:[o?e.jsxs("p",{className:"text-[10px] font-mono text-zinc-400 dark:text-zinc-500 truncate leading-tight",children:[o,"/"]}):null,e.jsx("h4",{className:"text-xl font-black text-zinc-900 dark:text-zinc-50 tracking-tight leading-tight truncate",children:u||i||"—"})]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[10px] font-mono text-zinc-400 dark:text-zinc-500 leading-relaxed",children:[e.jsx(Tc,{host:h}),h&&m?.from&&m?.to?e.jsx("span",{children:"·"}):null,m?.from&&m?.to?e.jsxs("span",{className:"tabular-nums",children:[m.from," – ",m.to]}):null]})]}),F?e.jsxs("div",{className:"grid grid-cols-2 gap-x-5 gap-y-5 border-t border-zinc-200/50 dark:border-zinc-800/50 pt-5 select-none",children:[e.jsx(wt,{label:l("dashboard.projects.detail.stat_total"),value:p(w),title:y(w)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_share"),value:j==null?"—":ar(j)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_cache_hit"),value:A==null?"—":ar(A)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_conversations"),value:va(v.conversation_count)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_active_days"),value:va(D)}),e.jsx(wt,{label:l("dashboard.projects.detail.stat_avg_day"),value:D>0?p(Math.round(w/D)):"—"})]}):null]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-y-auto",children:[x&&e.jsxs("div",{className:"space-y-4 p-5 md:p-6",children:[e.jsx("div",{className:"h-32 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"}),e.jsx("div",{className:"h-24 rounded-lg bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse"})]}),!x&&g&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.error")}),!x&&!g&&!F&&e.jsx("p",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 p-5 md:p-6",children:l("dashboard.projects.detail.empty_range")}),F&&e.jsxs("div",{className:"divide-y divide-zinc-200/50 dark:divide-zinc-800/40",children:[S.length>1&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_trend")}),e.jsx("div",{className:"mt-3",children:e.jsx(Xs,{embedded:!0,rows:S,from:S[0]?.day,to:S[S.length-1]?.day,period:"month",showTimeZoneLabel:!1,chartHeightClass:"h-36"})})]}),E>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_composition")}),e.jsx("div",{className:"mt-3 flex h-1.5 w-full overflow-hidden rounded-full",children:er.map(L=>{const B=se(v[L.key])??0;return B<=0?null:e.jsx("div",{style:{width:`${B/E*100}%`,backgroundColor:L.color,minWidth:"2px"}},L.key)})}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-x-4 gap-y-1.5",children:er.map(L=>{const B=se(v[L.key])??0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full",style:{backgroundColor:L.color}}),e.jsx("span",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:l(L.labelKey)}),e.jsx("span",{className:"text-[11px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(B),children:p(B)})]},L.key)})})]}),O.length>0&&e.jsxs("section",{className:"px-5 py-5 md:px-6 first:md:pt-6",children:[e.jsx(rr,{children:l("dashboard.projects.detail.section_sources")}),e.jsx("div",{className:"mt-3 space-y-3.5",children:O.map(L=>{const B=Number(L.total_tokens||0),K=N>0?B/N:0,q=K*100,_=Number(L.conversation_count||0),$=Ei(L.source||"unknown");return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx(Ct,{provider:L.source,size:13,className:"flex-shrink-0"}),e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wide text-zinc-900 dark:text-zinc-50 truncate",children:vt(L.source)}),e.jsxs("span",{className:"hidden text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums whitespace-nowrap sm:inline",children:[l("dashboard.projects.detail.source_days",{n:Number(L.days_active||0)}),_>0?e.jsxs(e.Fragment,{children:[" · ",l("dashboard.projects.detail.source_conv",{n:_})]}):null]}),e.jsx("span",{className:"ml-auto text-[12px] font-bold font-mono text-zinc-900 dark:text-zinc-50 tabular-nums",title:y(B),children:p(B)}),e.jsx("span",{className:"w-9 text-right text-[10px] font-mono text-zinc-400 dark:text-zinc-500 tabular-nums",children:ar(K)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full overflow-hidden rounded-full bg-zinc-100 dark:bg-zinc-800/60",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,Math.max(q,B>0?1:0))}%`,minWidth:B>0?"3px":0,backgroundColor:$}})})]},L.source)})})]})]})]})]})})}function Dc(t){return e.jsx(ni,{mode:Kt.COMPACT,children:e.jsx(Ac,{...t})})}const Lc=5;function Mc({entry:t,maxTokens:a,copy:r,formatTokens:s,formatTokensTooltip:n,onSelect:i}){const o=typeof t?.project_key=="string"?t.project_key:"",u=typeof t?.project_ref=="string"?t.project_ref:"",{owner:c,repo:h}=mn(o),m=xn(u,c),x=se(t?.billable_total_tokens??t?.total_tokens)??0,g=a>0?Math.min(100,Math.max(2,x/a*100)):0,p=Array.isArray(t?.sources)?t.sources:[],y=p.slice(0,Lc),k=p.length-y.length;return e.jsxs("button",{type:"button",onClick:()=>i?.(t),className:"flex w-full items-center gap-3 p-2 rounded-lg text-left hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50 active:bg-oai-gray-100 dark:active:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/60 transition-colors",children:[e.jsx(fn,{githubOwner:m,letter:(h?.[0]||o?.[0]||"?").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline min-w-0",children:[c?e.jsxs("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500 truncate flex-shrink-[2]",children:[c,"/"]}):null,e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:h||o||"—"})]}),y.length>0&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1",children:[y.map(f=>e.jsx(Ct,{provider:f.source,size:12,className:"text-oai-gray-400 dark:text-oai-gray-500"},f.source)),k>0&&e.jsx("span",{className:"oai-text-caption text-oai-gray-400 dark:text-oai-gray-500",children:r("dashboard.projects.sources_more",{n:k})})]})]}),e.jsxs("div",{className:"flex w-24 flex-shrink-0 flex-col items-end gap-1",children:[e.jsx("span",{className:"oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",title:n(x),children:s(x)}),e.jsx("div",{className:"h-1 w-full overflow-hidden rounded-full bg-oai-gray-100 dark:bg-oai-gray-800",children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${g}%`,minWidth:x>0?"3px":0}})})]})]})}function Ec({projectEntries:t=[],projectLimit:a=3,onProjectLimitChange:r,projectDetailQuery:s={},copy:n,hasDetailsActual:i,dailyEmptyPrefix:o,installSyncCmd:u,dailyEmptySuffix:c,detailsColumns:h,ariaSortFor:m,toggleSort:x,sortIconFor:g,pagedDetails:p,dailyBreakdownRows:y=[],dailyBreakdownColumns:k=[],dailyBreakdownAriaSortFor:f,dailyBreakdownSortIconFor:v,dailyBreakdownDateKey:w="day",detailsDateKey:D,renderDetailDate:C,renderDailyBreakdownDate:R,renderDetailCell:A,DETAILS_PAGED_PERIODS:P,period:N,detailsPageCount:j,detailsPage:S,setDetailsPage:E}){const[O,F]=d.useState("daily"),[L,B]=d.useState(null),{formatTokens:K,formatTokensTooltip:q}=Fe();return e.jsxs(De,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${O==="projects"?"mb-4":"mb-0"}`,children:[e.jsxs("div",{role:"tablist","aria-label":"Data view",className:"flex gap-1",children:[e.jsx("button",{role:"tab","aria-selected":O==="daily",type:"button",onClick:()=>F("daily"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="daily"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.daily.title")}),e.jsx("button",{role:"tab","aria-selected":O==="projects",type:"button",onClick:()=>F("projects"),className:`text-xs font-medium px-3 py-1.5 rounded transition-colors ${O==="projects"?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/50"}`,children:n("dashboard.projects.title")})]}),O==="projects"&&e.jsx(tn,{ariaLabel:n("dashboard.projects.limit_aria"),value:a,onValueChange:_=>r?.(Number(_)),options:[{value:3,label:n("dashboard.projects.limit_top_3")},{value:6,label:n("dashboard.projects.limit_top_6")},{value:10,label:n("dashboard.projects.limit_top_10")}],align:"end",className:"px-2 py-1 text-xs text-oai-gray-600 dark:text-oai-gray-300"})]}),O==="projects"&&(()=>{const _=t.slice(0,a);if(_.length===0)return e.jsx("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300",children:n("dashboard.projects.empty")});const $=_.reduce((H,te)=>{const ue=se(te?.billable_total_tokens??te?.total_tokens)??0;return ue>H?ue:H},0);return e.jsx("div",{className:"space-y-1",children:_.map((H,te)=>e.jsx(Mc,{entry:H,maxTokens:$,copy:n,formatTokens:K,formatTokensTooltip:q,onSelect:B},H?.project_key||H?.project_ref||`entry-${te}`))})})(),L&&e.jsx(Dc,{entry:L,query:s,onClose:()=>B(null)}),O==="daily"&&e.jsxs("div",{children:[y?.length===0?e.jsxs("div",{className:"oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 mb-4",children:[o,e.jsx("code",{className:"mx-1 rounded border border-oai-gray-300 dark:border-oai-gray-700 oai-bg-elevated px-1.5 py-0.5 font-mono oai-text-caption",children:u}),c]}):e.jsx("div",{className:"overflow-auto max-h-[384px] -mx-4 oai-scrollbar",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsx("tr",{className:"border-b border-oai-gray-200 dark:border-oai-gray-700",children:k.map(_=>e.jsx("th",{"aria-sort":f?.(_.key)||"none",className:"text-left p-0 bg-white dark:bg-oai-gray-900",children:e.jsx("button",{type:"button",onClick:()=>x(_.key),className:"flex w-full items-center justify-start px-2.5 sm:px-4 py-2 text-left oai-text-caption font-semibold text-oai-gray-600 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white transition-colors",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:_.label}),e.jsx("span",{className:"text-oai-gray-400 dark:text-oai-gray-400",children:v?.(_.key)||""})]})})},_.key))})}),e.jsx("tbody",{children:y.map(_=>e.jsxs("tr",{className:`border-b border-oai-gray-100 dark:border-oai-gray-800 last:border-b-0 hover:bg-oai-gray-50/50 dark:hover:bg-oai-gray-800/50 transition-colors ${_.missing?"text-oai-gray-400 dark:text-oai-gray-400":_.future?"text-oai-gray-300 dark:text-oai-gray-600":"text-oai-black dark:text-oai-white"}`,children:[e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-500 dark:text-oai-gray-300 whitespace-nowrap",children:R?R(_):C(_)}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm font-medium text-oai-black dark:text-oai-white tabular-nums",children:A(_,"total_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"cached_input_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"reasoning_output_tokens")}),e.jsx("td",{className:"px-2.5 sm:px-4 py-2 oai-text-body-sm text-oai-gray-600 dark:text-oai-gray-300 tabular-nums",children:A(_,"conversation_count")})]},String(_?.[w]||_?.day||_?.hour||_?.month||"")))})]})}),O!=="daily"&&P.has(N)&&j>1?e.jsxs("div",{className:"mt-3 flex items-center justify-between oai-text-caption",children:[e.jsx("button",{type:"button",onClick:()=>E(_=>Math.max(0,_-1)),disabled:S===0,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.prev")}),e.jsxs("span",{className:"oai-text-muted",children:[S+1," / ",j]}),e.jsx("button",{type:"button",onClick:()=>E(_=>Math.min(j-1,_+1)),disabled:S+1>=j,className:"px-3 py-1.5 text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 rounded-md disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:n("details.pagination.next")})]}):null]})]})}function _a(t){return typeof t!="string"?"":t.trim()}function ps(t){const a=_a(t);return a?a.split(/[_\-\s]+/).filter(Boolean).map(r=>r.slice(0,1).toUpperCase()+r.slice(1).toLowerCase()).join(" "):""}function Ic(t){if(!Array.isArray(t))return[];const a=new Map;for(const r of t){if(!r||typeof r!="object")continue;const s=_a(r.tool),n=_a(r.planType)||_a(r.plan_type);if(!s||!n)continue;const i=ps(s)||s,o=ps(n)||n;a.set(`${s.toLowerCase()}::${n.toLowerCase()}`,{tool:i,plan:o})}return Array.from(a.values())}function Rc({startDate:t,streakDays:a,subscriptions:r=[],periodConversations:s,rolling:n,topModels:i=[],className:o=""}){const{formatTokensTooltip:u}=Fe(),c=l("shared.placeholder.short"),h=l("shared.unit.percent"),m=t??l("identity_card.rank_placeholder"),x=Number.isFinite(Number(a))?Number(a):0,g=x?l("identity_card.streak_value",{days:x}):l("identity_card.rank_placeholder"),p=Ic(r),y={thousandSuffix:l("shared.unit.thousand_abbrev"),millionSuffix:l("shared.unit.million_abbrev"),billionSuffix:l("shared.unit.billion_abbrev")},k=w=>{if(w==null)return c;const D=Qe(w,y);return D==="-"?c:D},f={last7d:l("stats.period.last_7d"),last30d:l("stats.period.last_30d"),avg:l("stats.period.avg"),convs:l("stats.period.convs")},v=i.slice(0,3);return e.jsxs(De,{className:`h-full ${o}`,children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-2 xl:grid-cols-4 gap-2",children:[e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_7d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_7d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.last7d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.totals?.billable_total_tokens),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_30d?.totals?.billable_total_tokens)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.last30d})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{title:u(n?.last_30d?.avg_per_active_day),className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(n?.last_30d?.avg_per_active_day)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.avg})]}),e.jsxs("div",{className:"min-w-0 flex flex-col items-center justify-center px-2 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 rounded-lg",children:[e.jsx("span",{className:"w-full min-w-0 truncate text-center text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums",children:k(s)}),e.jsx("span",{className:"w-full min-w-0 truncate text-center text-[10px] text-oai-gray-400 dark:text-oai-gray-400 mt-0.5 whitespace-nowrap",children:f.convs})]})]}),v.length>0&&e.jsx("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800",children:v.map((w,D)=>{const C=w?.name?String(w.name):c,R=w?.percent?String(w.percent):"",A=D===v.length-1,P=D+1;return e.jsxs("div",{className:`flex items-center py-2 ${A?"":"border-b border-oai-gray-50 dark:border-oai-gray-800"}`,children:[e.jsx("span",{className:"w-5 h-5 flex items-center justify-center rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 text-[10px] font-semibold text-oai-gray-500 dark:text-oai-gray-300 flex-shrink-0",children:P}),e.jsx("span",{className:"flex-1 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate px-2.5",title:C,children:C}),e.jsxs("span",{className:"text-sm font-semibold text-oai-black dark:text-oai-white tabular-nums flex-shrink-0",children:[R,h]})]},w.id||C)})}),p.length>0&&e.jsx("div",{className:"mt-3 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex flex-wrap gap-1.5",children:p.map((w,D)=>e.jsxs(Ll,{variant:"secondary",size:"sm",children:[w.tool," ",w.plan]},`${w.tool}:${w.plan}:${D}`))}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-oai-gray-100 dark:border-oai-gray-800 flex items-center justify-between text-xs text-oai-gray-400 dark:text-oai-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:l("identity_card.rank_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:m})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:l("identity_card.streak_label")}),e.jsx("span",{className:"text-oai-gray-500 dark:text-oai-gray-300 tabular-nums",children:g})]})]})]})}let pa=null;function Fc(){if(pa===null)try{pa=typeof CSS<"u"&&typeof CSS.supports=="function"&&CSS.supports("color","oklch(0 0 0)")}catch{pa=!1}return pa}function $c(t,a,r){const s=r*Math.PI/180,n=a*Math.cos(s),i=a*Math.sin(s),o=t+.3963377774*n+.2158037573*i,u=t-.1055613458*n-.0638541728*i,c=t-.0894841775*n-1.291485548*i,h=o*o*o,m=u*u*u,x=c*c*c;return[4.0767416621*h-3.3077115913*m+.2309699292*x,-1.2684380046*h+2.6097574011*m-.3413193965*x,-.0041960863*h-.7034186147*m+1.707614701*x].map(p=>{const y=Math.min(1,Math.max(0,p)),k=y<=.0031308?12.92*y:1.055*Math.pow(y,1/2.4)-.055;return Math.round(k*255)})}function pn(t,a,r,s){if(Fc())return s==null?`oklch(${t} ${a} ${r})`:`oklch(${t} ${a} ${r} / ${s})`;const[n,i,o]=$c(t,a,r);return s==null?`rgb(${n} ${i} ${o})`:`rgb(${n} ${i} ${o} / ${s})`}function Tt(t){const a=/^oklch\(\s*([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s*\)$/.exec(t);return a?pn(Number(a[1]),Number(a[2]),Number(a[3])):t}const ys={claude:35,codex:250,grok:200},bs={system_prompt:{l:.55,c:.05},messages:{l:.65,c:.18},tool_calls:{l:.6,c:.14},custom_agents:{l:.55,c:.1},reasoning:{l:.7,c:.08}};function Pc(t,a){const r=ys[a]??ys.claude,s=bs[t]||bs.system_prompt;return pn(s.l,s.c,r)}const Bc=[{key:"system_prompt",from:["system_prefix"]},{key:"messages",from:["user_input","conversation_history","assistant_response"]},{key:"tool_calls",from:["tool_calls"]},{key:"custom_agents",from:["subagents"]},{key:"reasoning",from:["reasoning"]}],zc=[["by_type","dashboard.context_breakdown.exec_details.group_by_type"],["by_executable","dashboard.context_breakdown.exec_details.group_by_executable"],["by_command","dashboard.context_breakdown.exec_details.group_by_command"],["by_duration","dashboard.context_breakdown.exec_details.group_by_duration"],["by_output","dashboard.context_breakdown.exec_details.group_by_output"],["by_exit","dashboard.context_breakdown.exec_details.group_by_exit"]],Oc={duration:.18,ease:[.4,0,.2,1]},Uc={height:0,opacity:0},Hc={height:"auto",opacity:1},Vc={height:0,opacity:0};function Kc(t){const a=Number(t||0);return Number.isFinite(a)&&a>0?a:0}function Wc(t,a){const r={};for(const s of["input_tokens","cached_input_tokens","cache_creation_input_tokens","output_tokens","reasoning_output_tokens","total_tokens"])r[s]=Math.round(Number(t?.[s]||0)*a);return r}function yn(t,a=null){const r=t.reduce((o,u)=>o+Number(u.totals.total_tokens||0),0),s=Kc(a),n=s||r,i=s&&r>0?s/r:1;return t.map(o=>{const u=i===1?o.totals:Wc(o.totals,i);return{...o,totals:u,percent:n>0?Number((u.total_tokens/n*100).toFixed(2)):0}}).sort((o,u)=>u.totals.total_tokens-o.totals.total_tokens)}function Gc(t,a=null){const r=new Map;for(const n of t||[])r.set(n.key,n);const s=Bc.map(n=>{const i={input_tokens:0,cached_input_tokens:0,cache_creation_input_tokens:0,output_tokens:0,reasoning_output_tokens:0,total_tokens:0};for(const o of n.from){const u=r.get(o);if(!u)continue;const c=u.totals||{};i.input_tokens+=c.input_tokens||0,i.cached_input_tokens+=c.cached_input_tokens||0,i.cache_creation_input_tokens+=c.cache_creation_input_tokens||0,i.output_tokens+=c.output_tokens||0,i.reasoning_output_tokens+=c.reasoning_output_tokens||0,i.total_tokens+=c.total_tokens||0}return{key:n.key,totals:i}});return yn(s,a)}function qc(t,a=null){const r=t?.totals||{},s=Number(r.reasoning_output_tokens||0),n=(t?.tool_calls_breakdown?.categories||[]).reduce((h,m)=>m?.name==="Text Response"?h:h+Number(m?.totals?.total_tokens||0),0),i=Number(r.total_tokens||0),o=Math.min(Math.max(0,n),Math.max(0,i-s)),c=[{key:"messages",totals:{total_tokens:Math.max(0,i-s-o)}},{key:"tool_calls",totals:{total_tokens:o}},{key:"reasoning",totals:{total_tokens:s}}];return yn(c,a)}const ks="MCP: ";function Yc(t){if(!t?.categories?.length)return{mcpSet:null,residualSet:t,mcpTotalTokens:0};const a=[],r=[];let s=0;for(const n of t.categories){const i=String(n?.name||"");i.startsWith(ks)?(a.push({...n,name:i.slice(ks.length)}),s+=Number(n?.totals?.total_tokens||0)):r.push(n)}return a.length===0?{mcpSet:null,residualSet:t,mcpTotalTokens:0}:(a.sort((n,i)=>(i.totals?.total_tokens||0)-(n.totals?.total_tokens||0)),{mcpSet:{...t,categories:a},residualSet:{...t,categories:r},mcpTotalTokens:s})}function ws(t){return l(`dashboard.context_breakdown.category.${t}`)}function Zc(t){return typeof t!="string"?"":t.startsWith("mcp__")?t.split("__").slice(2).join("__")||t:t.includes("/")&&t.split("/").pop()||t}function Jc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||null,s=Number(r?r.input_tokens||0:a?.input_tokens||0),n=Number(r?r.output_tokens||0:a?.output_tokens||0),i=Number(r?r.cached_input_tokens||0:a?.cache_read||0),o=Number(r?r.cache_creation_input_tokens||0:a?.cache_creation||0),u=Number(r?r.total_tokens||s+n:a?.total_tokens||n);return{name:Zc(a?.name?String(a.name):""),calls:Number(a?.calls||0),input_tokens:s,output_tokens:n,cache_read:i,cache_creation:o,total_tokens:Number(u||0)}}).filter(a=>a.name).sort((a,r)=>(r.total_tokens||0)-(a.total_tokens||0))}function Qc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Array.isArray(a?.tools)?a.tools:[],n=Number(r.input_tokens||0),i=Number(r.output_tokens||0),o=Number(r.cached_input_tokens||0),u=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),totals:{input_tokens:n,output_tokens:i,cached_input_tokens:o,cache_creation_input_tokens:u,total_tokens:Number(r.total_tokens||n+i)},tools:Jc(s),toolCount:s.length}}).filter(a=>a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function Xc(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{key:a?.key?String(a.key):"",name:a?.name?String(a.name):"",totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n+i+o)}}}).filter(a=>a.key||a.name).sort((a,r)=>(r.totals.total_tokens||0)-(a.totals.total_tokens||0))}function ed(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{};return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),total_tokens:Number(r.total_tokens||0)}}).filter(a=>a.name).sort((a,r)=>Number(r.total_tokens||0)-Number(a.total_tokens||0))}function td(t){if(t?.key){const a=l(`dashboard.context_breakdown.message_details.${t.key}`);if(a&&!a.includes("dashboard.context_breakdown"))return a}return t?.name||""}function ad(t){return(Array.isArray(t)?t:[]).map(a=>{const r=a?.totals||{},s=Number(r.input_tokens||0),n=Number(r.output_tokens||0),i=Number(r.cached_input_tokens||0),o=Number(r.cache_creation_input_tokens||0);return{name:a?.name?String(a.name):"",calls:Number(a?.calls||0),failures:Number(a?.failures||0),duration_ms:Number(a?.duration_ms||0),max_duration_ms:Number(a?.max_duration_ms||0),output_chars:Number(a?.output_chars||0),output_lines:Number(a?.output_lines||0),totals:{input_tokens:s,output_tokens:n,cached_input_tokens:i,cache_creation_input_tokens:o,total_tokens:Number(r.total_tokens||s+n)}}}).filter(a=>a.name).sort((a,r)=>Number(r.totals.total_tokens||0)-Number(a.totals.total_tokens||0))}function _s(t){const a=Number(t||0);return!Number.isFinite(a)||a<=0?"0ms":a<1e3?`${Math.round(a)}ms`:a<6e4?`${(a/1e3).toFixed(1)}s`:`${Math.round(a/1e3)}s`}function rd(t,a){return t?a==="by_executable"?t.by_executable||[]:a==="by_command"?t.by_command||[]:a==="by_duration"?t.by_duration||[]:a==="by_output"?t.by_output||[]:a==="by_exit"?t.by_exit||[]:t.by_type||[]:[]}function vs(t){return t==="exec_command"||t==="Bash"}function bn(t){return t==="codex"?"dashboard.context_breakdown.empty_codex":t==="grok"?"dashboard.context_breakdown.empty_grok":"dashboard.context_breakdown.empty"}function sd(t){return t==="codex"?"dashboard.context_breakdown.error_codex":t==="grok"?"dashboard.context_breakdown.error_grok":"dashboard.context_breakdown.error"}function nd(t){return t==="codex"?"dashboard.context_breakdown.footnote_codex":t==="grok"?"dashboard.context_breakdown.footnote_grok":"dashboard.context_breakdown.footnote"}const od=10;function Je({level:t=0,colorSquare:a=null,label:r,labelSuffix:s=null,labelTone:n="default",hasChevron:i=!1,open:o=!1,onToggle:u,tokens:c,percent:h=null,children:m,share:x=null,fillColor:g=null}){const p=n==="accent"?"text-oai-brand truncate":n==="muted"?"text-oai-gray-500 dark:text-oai-gray-400 truncate":n==="strong"?"font-medium text-oai-black dark:text-oai-white truncate":"text-oai-gray-700 dark:text-oai-gray-300 truncate",y=e.jsx("span",{className:"shrink-0 flex items-center justify-start",style:{width:od},"aria-hidden":!a,children:a}),k=e.jsxs(e.Fragment,{children:[y,e.jsx("span",{className:p,children:r}),s,i&&e.jsx(ve.span,{animate:{rotate:o?90:0},transition:{duration:.15},className:"shrink-0 text-oai-gray-400 dark:text-oai-gray-500 flex items-center","aria-hidden":"true",children:e.jsx(ii,{size:11})})]}),f=g&&x!=null&&x>0,v=f?Math.max(0,Math.min(100,x)):0;return e.jsxs("li",{className:"min-w-0 group/row",children:[e.jsxs("div",{className:"relative grid grid-cols-[minmax(0,1fr)_minmax(9rem,max-content)_4rem] items-center gap-x-3 text-xs py-1 px-1 rounded-sm transition-colors duration-150",style:f?{backgroundImage:`linear-gradient(to right, ${g.replace(/\)\s*$/," / 0.10)")} 0%, ${g.replace(/\)\s*$/," / 0.10)")} ${v}%, transparent ${v}%)`}:void 0,children:[i?e.jsx("button",{type:"button",onClick:u,"aria-expanded":o,className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0 text-left cursor-pointer focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-oai-brand/40 rounded-sm",children:k}):e.jsx("div",{className:"relative col-start-1 row-start-1 flex items-center gap-1.5 min-w-0",children:k}),e.jsx("span",{className:"relative col-start-2 row-start-1 text-right whitespace-nowrap tabular-nums text-oai-gray-500 dark:text-oai-gray-400",children:c||""}),e.jsx("span",{className:"relative col-start-3 row-start-1 text-right whitespace-nowrap tabular-nums text-[10px] text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:h||""})]}),i&&m?e.jsx(Ta,{initial:!1,children:o&&e.jsx(ve.div,{initial:Uc,animate:Hc,exit:Vc,transition:Oc,style:{overflow:"hidden"},children:m},"content")}):null]})}function js({execDetails:t,source:a="claude"}){const{formatTokens:r}=Fe(),[s,n]=d.useState("by_type"),i=ad(rd(t,s)),o=a==="codex"||a==="grok",u=o?"grid-cols-[minmax(0,1fr)_48px_48px_72px_72px_60px_60px]":"grid-cols-[minmax(0,1fr)_56px_60px]";return e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-md bg-oai-gray-100 dark:bg-oai-gray-900 p-1 w-fit max-w-full",children:zc.map(([c,h])=>e.jsx("button",{type:"button",onClick:()=>n(c),className:"h-7 px-2 rounded-md text-[10px] font-medium transition-colors "+(s===c?"bg-oai-white dark:bg-oai-gray-800 text-oai-black dark:text-oai-white shadow-sm":"text-oai-gray-600 dark:text-oai-gray-300 hover:bg-oai-white/70 dark:hover:bg-oai-gray-800/70"),children:l(h)},c))}),i.length===0?e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:"—"}):e.jsx("div",{className:"mt-2 overflow-x-auto",children:e.jsxs("div",{role:"table","aria-label":l("dashboard.context_breakdown.exec_details.title"),className:o?"min-w-[420px]":"min-w-[260px]",children:[e.jsxs("div",{role:"row",className:`grid ${u} gap-2 py-1.5 mb-1 border-b border-oai-gray-200 dark:border-oai-gray-800 text-label uppercase text-oai-gray-500 dark:text-oai-gray-400`,children:[e.jsx("span",{role:"columnheader",children:l("dashboard.context_breakdown.exec_details.kind_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.calls_column")}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.failures_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.duration_column")}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.max_duration_column")})]}),e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.tool_details.total_column")}),o&&e.jsx("span",{role:"columnheader",className:"text-right",children:l("dashboard.context_breakdown.exec_details.output_column")})]}),i.map((c,h)=>e.jsxs(ve.div,{role:"row",className:`grid ${u} gap-2 py-1.5`,title:c.name,initial:{opacity:0},animate:{opacity:1},transition:{duration:.18,delay:h*.02},children:[e.jsx("span",{role:"cell",className:"min-w-0 text-body-sm font-medium text-oai-black dark:text-oai-white truncate",children:c.name}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.calls||0)}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.failures||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:_s(c.duration_ms||0)}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:_s(c.max_duration_ms||0)})]}),e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:r(c.totals.total_tokens||0)}),o&&e.jsx("span",{role:"cell",className:"text-right text-body-sm tabular-nums text-oai-gray-700 dark:text-oai-gray-300",children:Qe(c.output_lines||0)})]},c.name))]})})]})}function Ht({toolSet:t,execDetails:a,source:r,codexQueueFallback:s}){const{formatTokens:n}=Fe(),[i,o]=d.useState({}),[u,c]=d.useState(!1),h=Qc(t?.categories||[]);function m(x){o(g=>({...g,[x]:!g[x]}))}return h.length===0?e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:r==="codex"&&s?l("dashboard.context_breakdown.tool_details.unavailable_codex"):l(bn(r))}):e.jsx("ul",{className:"mt-0.5 mb-0.5 space-y-0.5",children:h.map(x=>{const g=x.toolCount>0,p=x.name==="Execution"&&a,y=p&&x.tools.some(f=>vs(f.name)),k=!!i[x.name];return e.jsxs(Je,{level:1,label:x.name,labelTone:"strong",hasChevron:g||p&&!y,open:k||p&&!y&&u,onToggle:()=>{g?m(x.name):p&&!y&&c(f=>!f)},tokens:n(x.totals.total_tokens||0),percent:null,children:[g&&e.jsx("ul",{className:"space-y-0.5",children:x.tools.map(f=>{const v=p&&vs(f.name);return e.jsx(Je,{level:2,label:f.name,labelTone:v?"accent":"default",hasChevron:v,open:u,onToggle:()=>c(w=>!w),tokens:n(f.total_tokens||0),percent:null,children:v&&e.jsx(js,{execDetails:a,source:r})},f.name)})}),p&&!y&&e.jsx(js,{execDetails:a,source:r})]},x.name)})})}function id({from:t,to:a,source:r="claude",referenceTotalTokens:s=null,onLoadingChange:n=null}){const{formatTokens:i}=Fe(),[o,u]=d.useState(null),[c,h]=d.useState(!1),[m,x]=d.useState(null),[g,p]=d.useState({}),y=d.useRef({});function k(_){p($=>({...$,[_]:!$[_]}))}if(d.useEffect(()=>{let _=!1;const $=`${t||""}|${a||""}|${r||"claude"}`,H=y.current[$];return u(H||null),h(!0),n?.(!0),x(null),oi({from:t,to:a,source:r,timeZone:Zs(),tzOffsetMinutes:Ys()}).then(te=>{_||(y.current[$]=te,u(te))}).catch(te=>{_||x(te?.message||String(te))}).finally(()=>{_||(h(!1),n?.(!1))}),()=>{_=!0}},[t,a,r]),c&&!o)return e.jsxs("div",{children:[e.jsx("div",{className:"h-1 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden animate-pulse"}),e.jsx("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2",children:[0,1,2,3,4].map(_=>e.jsx("div",{className:"h-3 rounded bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse",style:{animationDelay:`${_*80}ms`}},_))}),e.jsx("p",{className:"mt-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.loading_hint")})]});if(m)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(sd(r))});if(!o||o.scope!=="supported"||!o.totals?.total_tokens)return e.jsx("p",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l(bn(r))});const f=r==="claude"?Gc(o.categories||[],s):qc(o,s),v=o.tool_calls_breakdown||null,w=o.skills_breakdown||null,D=o.message_breakdown||null,C=o.configured_resources||null,R=o.exec_command_breakdown||null,A=ed(w?.skills||[]),P=Xc(D?.categories||[]),N=r==="codex"&&(o?.breakdown_status==="queue_fallback"||o?.fallback==="queue_totals"),j=r==="claude"?v?.tool_calls||null:v||null,{mcpSet:S,residualSet:E,mcpTotalTokens:O}=Yc(j),F=r==="claude"&&v?.subagents||null,L=F?.categories?.length>0||(C?.custom_agents_count||0)>0,B=r==="claude"?(E?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,K=r==="claude"?(F?.categories||[]).reduce((_,$)=>_+Number($?.totals?.total_tokens||0),0):0,q=[...f].sort((_,$)=>($.totals?.total_tokens||0)-(_.totals?.total_tokens||0));return e.jsxs("div",{role:"region","aria-label":l("dashboard.context_breakdown.bar_aria",{summary:f.filter(_=>_.percent>0).filter(_=>!(r==="claude"&&(_.key==="tool_calls"||_.key==="custom_agents"))).map(_=>`${ws(_.key)} ${_.percent}%`).join(",")}),children:[e.jsxs("ul",{className:"space-y-0.5",children:[q.map(_=>{const $=_.key==="system_prompt",H=_.key==="messages",te=_.key==="tool_calls",ue=_.key==="custom_agents";if(_.key,r==="claude"&&(te||ue))return null;const W=H&&P.length>0||te&&(E?.categories?.length>0||N)||ue&&L&&F,ne=!!g[_.key],oe=Pc(_.key,r),je=e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0",style:{backgroundColor:oe},"aria-hidden":"true"}),be=$?e.jsxs("span",{className:"relative inline-flex shrink-0 group",children:[e.jsx(sn,{size:11,className:"text-oai-gray-400 dark:text-oai-gray-500 cursor-help","aria-hidden":"true"}),e.jsx("span",{role:"tooltip",className:"pointer-events-none absolute left-1/2 bottom-full z-20 mb-1.5 -translate-x-1/2 w-64 rounded-md border border-oai-gray-200 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 px-2.5 py-1.5 text-[11px] leading-snug text-oai-gray-700 dark:text-oai-gray-200 shadow-md opacity-0 group-hover:opacity-100 transition-opacity",children:l("dashboard.context_breakdown.system_prefix_tooltip")})]}):null,Le=_.percent>0?`${_.percent.toFixed(_.percent<.1&&_.percent>0?2:1)}%`:"0.0%";return e.jsxs(Je,{level:0,colorSquare:je,label:ws(_.key),labelSuffix:be,tokens:i(_.totals?.total_tokens||0),percent:Le,hasChevron:W,open:ne,onToggle:()=>k(_.key),share:_.percent,fillColor:oe,children:[H&&e.jsx("ul",{className:"space-y-0.5",children:P.map(X=>e.jsx(Je,{level:1,label:td(X),tokens:i(X.totals.total_tokens||0),percent:null},X.key||X.name))}),te&&E&&e.jsx(Ht,{toolSet:E,execDetails:R,source:r,codexQueueFallback:N}),te&&N&&!E&&e.jsx("p",{className:"text-[11px] text-oai-gray-400 dark:text-oai-gray-500 py-0.5",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}),ue&&F&&e.jsx(Ht,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})]},_.key)}),r==="claude"&&E?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.tool_calls"),tokens:i(B),percent:null,hasChevron:!0,open:!!g.tool_calls_aux,onToggle:()=>k("tool_calls_aux"),children:e.jsx(Ht,{toolSet:E,execDetails:R,source:r,codexQueueFallback:!1})}),r==="claude"&&F?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.custom_agents"),tokens:i(K),percent:null,hasChevron:!0,open:!!g.custom_agents_aux,onToggle:()=>k("custom_agents_aux"),children:e.jsx(Ht,{toolSet:F,execDetails:null,source:r,codexQueueFallback:!1})}),S?.categories?.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.mcp_servers"),tokens:i(O),percent:null,hasChevron:!0,open:!!g.mcp_servers,onToggle:()=>k("mcp_servers"),children:e.jsx(Ht,{toolSet:S,execDetails:null,source:r,codexQueueFallback:!1})}),A.length>0&&e.jsx(Je,{level:0,colorSquare:e.jsx("span",{className:"h-2 w-2 rounded-sm shrink-0 bg-oai-gray-300 dark:bg-oai-gray-600","aria-hidden":"true"}),label:l("dashboard.context_breakdown.category.skills"),tokens:i(A.reduce((_,$)=>_+($.total_tokens||0),0)),percent:null,hasChevron:!0,open:!!g.skills,onToggle:()=>k("skills"),children:e.jsx("ul",{className:"space-y-0.5",children:A.slice(0,12).map(_=>e.jsx(Je,{level:1,label:_.name,tokens:i(_.total_tokens),percent:null},_.name))})})]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l(nd(r))}),N?e.jsx("p",{className:"mt-2 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("dashboard.context_breakdown.tool_details.unavailable_codex")}):null,C?e.jsxs("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[Qe(C.skills_count||0)," skills ·"," ",Qe(C.mcp_servers_count||0)," MCP servers ·"," ",Qe(C.custom_agents_count||0)," agents ·"," ",Qe(C.memory_files_count||0)," memory files"]}):null]})}function kn({size:t=15,className:a=""}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",className:a,"aria-hidden":"true",children:[e.jsx("path",{d:"M12 1.6 23 7.4 12 13.2 1 7.4 12 1.6Z"}),e.jsx("path",{d:"m4 10.3-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.72"}),e.jsx("path",{d:"m4 14.6-3 1.5 11 5.5 11-5.5-3-1.5-8 4-8-4Z",opacity:"0.45"})]})}const nt="__all__",ld=`${100 .toFixed(2)}%`;function qt(t,a){const r=Number(a);return Number.isFinite(r)&&r>0?t(r):null}function xr(t,a,r){const s=Number(t);if(!Number.isFinite(s)||s<=0)return null;const n=Gt(a);return(a===qs?s:s*r)<.01?`<${n}0.01`:Sa(s,{decimals:2,currency:a,rate:r})}function cd(t){return Array.isArray(t)?t.map(a=>typeof a=="string"?{key:a,label:Ns(a)}:{key:a.key,label:a.label||Ns(a.key)}):[]}function dd(t){if(typeof t!="string")return null;const a=t.replace(/,/g,"").match(/-?\d+(?:\.\d+)?/);if(!a)return null;const r=Number(a[0]);return Number.isFinite(r)?r:null}const ud={ACODE:"var(--brand-primary-light)",CODEX:"#3b82f6",DSH:"var(--community-deepseek)",CLAUDE:"#d97757",OPENCODE:"#f59e0b",GEMINI:"#2196f3",KIMI:"#a78bfa","KILO-CLI":"#facc15","KILO-CODE":"#facc15",MIMO:"#ff6900",DROID:"#ef4444",ZCODE:"#14b8a6",ANYTHINGLLM:"var(--provider-anythingllm)",LMSTUDIO:"var(--provider-lmstudio)",UNSLOTH:"var(--provider-unsloth)"};function sr(t,a){const r=t?.toUpperCase?.()||"";return ud[r]||`hsl(${150+a*40}, 60%, 45%)`}function md(t){const a=String(t?.source||"").trim().toLowerCase(),r=String(t?.label||"").trim().toLowerCase();return a==="claude"||r==="claude"?"claude":a==="codex"||r==="codex"?"codex":a==="grok"||r==="grok"||r.includes("grok")?"grok":null}function hd(t){return t==="claude"?l("dashboard.context_breakdown.heading_claude"):t==="codex"?l("dashboard.context_breakdown.heading_codex"):t==="grok"?l("dashboard.context_breakdown.heading_grok"):l("dashboard.context_breakdown.heading")}function gd(t){return!!t?.models?.length}function wn(t){const a=Number(t?.totalPercentValue??t?.totalPercent);return Number.isFinite(a)?Math.max(0,a):0}function nr(t){const a=wn(t);return a>0&&!(a>=.01)?l("usage.overview.percent_below_threshold"):a.toFixed(2)}const xd={day:"usage.period.day",week:"usage.period.week",month:"usage.period.month",total:"usage.period.total",custom:"usage.period.custom"};function Ns(t){const a=xd[t];return a?l(a):String(t).toUpperCase()}function fd({loading:t,onClick:a}){const r=Nr();return e.jsx(ci,{variant:"secondary",size:"sm",disabled:t,onClick:a,"aria-label":l("usage.button.refresh"),className:"w-8 p-0",children:e.jsx(ve.span,{"aria-hidden":"true",animate:t?{rotate:360}:{rotate:0},transition:t&&!r?{duration:1,repeat:1/0,ease:"linear"}:{duration:.3},style:{display:"inline-flex"},children:e.jsx(di,{className:"h-3.5 w-3.5",strokeWidth:2})})})}function pd(){return e.jsx("div",{"data-testid":"usage-summary-skeleton","aria-hidden":"true",className:"mx-auto h-[58px] sm:h-[72px] w-[min(72vw,18rem)] rounded-2xl bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"})}function yd(){return e.jsxs("div",{"data-testid":"usage-provider-skeleton","aria-hidden":"true",className:"space-y-6",children:[e.jsx("div",{className:"h-1.5 w-full rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 animate-pulse motion-reduce:animate-none"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[0,1,2,3].map(t=>e.jsx("div",{className:"h-[92px] rounded-xl border border-oai-gray-100 dark:border-oai-gray-800 bg-oai-gray-50 dark:bg-oai-gray-800/60 animate-pulse motion-reduce:animate-none",style:{animationDelay:`${t*70}ms`}},t))})]})}function bd({period:t,periods:a,onPeriodChange:r,summaryValue:s,summaryFullValue:n,onToggleSummaryFormat:i,summaryLabel:o,summaryCostValue:u,onCostInfo:c,fleetData:h=[],onRefresh:m,loading:x,announceLoading:g=!1,summaryLoading:p=!1,providersLoading:y=!1,hasSummary:k=!0,className:f="",customFrom:v,customTo:w,onCustomRangeApply:D,customRangeOpen:C,onCustomRangeOpenChange:R,onOpenShare:A,from:P,to:N,deviceOptions:j=[],selectedDevice:S="",onDeviceChange:E}){const O=cd(a),F=Ri(ui()),L=dd(String(s??"")),B=t==="week"&&typeof P=="string"&&typeof N=="string"&&P.slice(0,7)!==N.slice(0,7),K=P&&N?`${xa(P,F)} — ${xa(N,F)}`:null,q=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 639px)").matches,[_,$]=d.useState(q);d.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const T=window.matchMedia("(max-width: 639px)"),z=he=>$(he.matches);return T.addEventListener("change",z),()=>T.removeEventListener("change",z)},[]);const H=L!=null&&!_,te=d.useRef(null);d.useEffect(()=>{const T=te.current?.querySelector('[aria-selected="true"]');T&&typeof T.scrollIntoView=="function"&&T.scrollIntoView({block:"nearest",inline:"center"})},[t]);const[ue,W]=d.useState(null),{resolvedTheme:ne}=li(),{currency:oe,rate:je}=Ca(),{formatTokens:be}=Fe(),Le=ne==="dark",X=Le?"rgba(10,10,10,0.98)":"rgba(255,255,255,0.96)",U=Le?"rgba(10,10,10,0)":"rgba(255,255,255,0)",re=p&&!k,ee=y&&!h.some(gd);d.useEffect(()=>{W(null)},[t,P,N,S]);const ae=T=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(T.key))return;const z=Array.from(T.currentTarget.querySelectorAll('[role="tab"]')).filter(de=>!de.disabled),he=z.indexOf(T.target.closest('[role="tab"]'));if(he===-1||z.length===0)return;T.preventDefault();let V=he;T.key==="Home"?V=0:T.key==="End"?V=z.length-1:T.key==="ArrowRight"?V=(he+1)%z.length:V=(he-1+z.length)%z.length,z[V].focus(),z[V].click()},ye=H?e.jsx(Bl,{value:L,displayValue:s,fontSize:72,padding:6,gap:1,textColor:"var(--oai-black, #111827)",fontWeight:700,gradientHeight:Le?0:8,gradientFrom:X,gradientTo:U,counterStyle:{paddingLeft:0,paddingRight:0,gap:0},digitStyle:{width:"0.88ch"}}):s,Y=h.filter(T=>T.models?.length>0),J=Y.some(T=>String(T?.source||T?.label||"").trim().toLowerCase()==="devin"),Z=d.useMemo(()=>_c(h),[h]),ge=Z.reduce((T,z)=>T+(Number(z.usage)||0),0),$e=Y.reduce((T,z)=>T+(Number(z.usd)||0),0),me=ue==null?null:ue===nt||Y.some(function(z){return z.label===ue})?ue:null;return e.jsx(De,{className:f,children:e.jsxs("div",{"aria-busy":x||re||ee,children:[g?e.jsx("span",{className:"sr-only",role:"status",children:l("qpd.card.updating")}):null,e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{ref:te,role:"tablist","aria-label":l("usage.overview.tablist_aria"),onKeyDown:ae,className:"flex flex-1 min-w-0 gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:O.map(T=>{const z=t===T.key,he=`shrink-0 whitespace-nowrap text-xs font-medium px-3 py-1.5 rounded-md transition-colors ${z?"text-oai-black dark:text-oai-white bg-oai-gray-100 dark:bg-oai-gray-800":"text-oai-gray-500 dark:text-oai-gray-300 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800"}`;if(T.key==="custom"){const V=z&&v&&w?`${xa(v,F)} — ${xa(w,F)}`:T.label;return e.jsxs(nl,{open:C,onOpenChange:de=>{de?r?.("custom"):R?.(de)},children:[e.jsx(ol,{render:e.jsx("button",{role:"tab","aria-selected":z,tabIndex:z?0:-1,type:"button",className:he}),children:V}),e.jsx(il,{children:e.jsx(ll,{sideOffset:8,side:"bottom",align:"start",className:"!z-[9999]",children:e.jsx(cl,{className:"bg-white dark:bg-oai-gray-900 border border-oai-gray-200 dark:border-oai-gray-700 rounded-xl shadow-lg",children:e.jsx(Ii,{from:v,to:w,onApply:D,onCancel:()=>R?.(!1)})})})})]},"custom")}return e.jsx("button",{role:"tab","aria-selected":z,tabIndex:z?0:-1,type:"button",className:he,onClick:()=>r?.(T.key),children:T.label},T.key)})}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[j.length>1?e.jsx(tn,{value:S,onValueChange:E,options:j,ariaLabel:l("dashboard.device_filter.aria"),matchTriggerWidth:!0,className:"h-8 px-3 text-xs font-medium rounded-md border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand hover:[&_svg]:text-oai-brand transition-colors duration-200"}):null,A?e.jsxs("button",{type:"button",onClick:A,"aria-label":l("share.button.aria"),className:"inline-flex items-center justify-center gap-1.5 h-8 px-3 text-xs font-medium rounded-md border border-oai-gray-300 dark:border-oai-gray-700 bg-oai-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-brand hover:text-oai-brand transition-colors duration-200",children:[e.jsx(Nl,{className:"h-3.5 w-3.5",strokeWidth:2}),l("share.button.label")]}):null,m&&e.jsx(fd,{loading:x,onClick:m})]})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wider mb-3",children:o}),e.jsxs("div",{className:"relative text-5xl sm:text-6xl md:text-7xl font-bold text-oai-black dark:text-oai-white tracking-tight tabular-nums",children:[e.jsx("div",{className:re?"invisible":void 0,children:i?e.jsx("button",{type:"button",onClick:i,title:n||void 0,"aria-label":l("usage.summary.toggle_aria"),className:"cursor-pointer rounded-lg leading-none transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-oai-brand",children:ye}):e.jsx("span",{title:n||void 0,children:ye})}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center ${re?"":"hidden"}`,children:e.jsx(pd,{})})]}),u&&e.jsx("div",{className:"flex items-center justify-center gap-2 mt-4",children:c?e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1.5 text-xl font-bold text-oai-brand hover:text-oai-brand-dark dark:hover:text-oai-brand-light transition-colors cursor-pointer","aria-label":l("usage.overview.cost_breakdown_aria"),children:[u,e.jsx(sn,{size:16,strokeWidth:2,className:"opacity-80"})]}):e.jsx("span",{className:"text-xl font-bold text-oai-brand",children:u})}),K?e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-1 text-[11px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{className:"tabular-nums",children:K}),B?e.jsx("span",{children:l("usage.overview.week_cross_month_hint")}):null]}):null]}),e.jsx("div",{className:ee?void 0:"hidden",children:e.jsx(yd,{})}),Y.length>0&&e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{role:"img","aria-label":l("usage.overview.distribution_aria",{items:Y.map(T=>l("usage.overview.distribution_item",{label:vt(T.label),percent:nr(T)})).join(",")}),className:"h-1.5 w-full bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden flex",children:Y.map((T,z)=>{const he=sr(T.label,z),V=vt(T.label),de=nr(T);return e.jsx(ve.div,{initial:{width:0},animate:{width:`${wn(T)}%`},transition:{duration:.5,delay:.45+z*.04,ease:[.16,1,.3,1]},className:"h-full",style:{backgroundColor:he},title:`${V}: ${de}%`},T.label)})}),e.jsxs("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(140px,1fr))] gap-3",children:[e.jsxs("button",{type:"button","aria-expanded":me===nt,"aria-controls":"provider-details-all","aria-label":l("usage.overview.all_tools_card_aria",{tokens:qt(be,ge)||String(0),cost:xr($e,oe,je)||`${Gt(oe)}0`,count:Z.length}),onClick:()=>W(me===nt?null:nt),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${me===nt?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(kn,{size:15,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",children:l("usage.overview.all_tools")})]}),e.jsx("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:ld}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:Z.length})})]}),Y.map((T,z)=>{const he=sr(T.label,z),V=me===T.label,de=vt(T.label),Ce=nr(T);return e.jsxs("button",{"aria-expanded":V,"aria-controls":`provider-details-${T.label}`,"aria-label":l("usage.overview.provider_card_aria",{provider:de,percent:Ce,tokens:qt(be,T.usage)||String(0),cost:xr(T.usd,oe,je)||`${Gt(oe)}0`,action:l(V?"usage.overview.collapse":"usage.overview.expand")}),onClick:()=>W(V?null:T.label),className:`min-w-0 text-left p-3 rounded-lg border transition-colors duration-200 ${V?"border-oai-gray-300 dark:border-oai-gray-600 bg-oai-gray-50 dark:bg-oai-gray-800":"border-oai-gray-200 dark:border-oai-gray-700 hover:border-oai-gray-300 dark:hover:border-oai-gray-600"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1 min-w-0",children:[e.jsx(Ct,{provider:T.label,size:15,color:he,className:"text-oai-gray-700 dark:text-oai-gray-300 shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white truncate",title:de,children:de})]}),e.jsxs("div",{className:"text-lg font-semibold text-oai-black dark:text-oai-white tabular-nums",children:[Ce,"%"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-oai-gray-400 dark:text-oai-gray-400 tabular-nums",children:l("usage.overview.model_count",{count:T.models.length})})]},T.label)})]}),me===nt&&e.jsxs("div",{id:"provider-details-all",role:"region","aria-label":l("usage.overview.all_models"),className:"mt-2",children:[J&&e.jsx(vn,{}),e.jsx(kd,{models:Z})]}),me!=null&&me!==nt&&e.jsx("div",{id:`provider-details-${me}`,role:"region","aria-label":l("usage.overview.model_details_aria",{provider:me}),className:"mt-2",children:Y.filter(T=>T.label===me).map(T=>{const z=sr(T.label,0),he=md(T),V=[...T.models].sort((Ce,Ne)=>(Ne.share||0)-(Ce.share||0)),de=he?hd(he):vt(T.label);return e.jsx(wd,{provider:T,color:z,providerHeading:de,contextSource:he,from:P,to:N,sortedModels:V},T.label)})})]})]})})}function _n({models:t,color:a}){const{currency:r,rate:s}=Ca(),{formatTokens:n,formatTokensTooltip:i}=Fe();return e.jsx("div",{className:"space-y-3",children:t.map(o=>{const u=qt(n,o.usage),c=xr(o.cost,r,s),h=Math.max(0,Math.min(100,Number(o.share)||0));return e.jsxs("div",{"data-model-rank-row":!0,children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(8rem,max-content)_minmax(5.5rem,max-content)_4rem] items-baseline gap-x-3 mb-1.5",children:[e.jsx("span",{className:"col-start-1 row-start-1 min-w-0 text-sm text-oai-gray-700 dark:text-oai-gray-300 truncate",title:o.name,children:o.name}),e.jsx("span",{title:i(o.usage),className:"col-start-2 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:u}),e.jsx("span",{className:"col-start-3 row-start-1 text-right whitespace-nowrap text-sm text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:c}),e.jsxs("span",{className:"col-start-4 row-start-1 text-right whitespace-nowrap text-sm text-oai-black dark:text-oai-white tabular-nums",children:[o.share,"%"]})]}),e.jsx("div",{className:"h-[3px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",role:"progressbar","aria-valuenow":h,"aria-valuemin":0,"aria-valuemax":100,children:e.jsx("div",{className:"h-full transition-[width] duration-500 ease-out",style:{width:`${h}%`,backgroundColor:a,opacity:.45}})})]},o.id||o.name)})})}function kd({models:t}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[e.jsx(kn,{size:14,className:"shrink-0 text-oai-brand dark:text-oai-white"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("usage.overview.all_models")})]}),e.jsx("p",{className:"mb-4 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("usage.overview.all_models_note")}),e.jsx(_n,{models:t,color:"var(--oai-blue)"})]})}function vn(){return e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.devin_notice_title"),"."]})," ",l("usage.overview.devin_notice_body")]})}function wd({provider:t,color:a,providerHeading:r,contextSource:s,from:n,to:i,sortedModels:o}){const{formatTokens:u}=Fe(),[c,h]=d.useState(!1),m=String(t?.source||t?.label||"").trim().toLowerCase()==="antigravity",x=String(t?.source||t?.label||"").trim().toLowerCase()==="devin";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-3",children:[e.jsx(Ct,{provider:t.label,size:14,color:a,className:"shrink-0"}),e.jsx("span",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:r}),s&&c&&e.jsx(sl,{size:12,className:"text-oai-gray-400 dark:text-oai-gray-500 animate-spin shrink-0","aria-label":l("dashboard.context_breakdown.loading_aria")})]}),t.cacheHitRate!=null&&e.jsxs("p",{className:"mb-3 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400 tabular-nums",children:[e.jsx("span",{className:"font-medium text-oai-gray-600 dark:text-oai-gray-300",children:l("usage.overview.cache_hit_rate_label")})," ",e.jsxs("span",{className:"text-oai-black dark:text-oai-white",children:[t.cacheHitRate,"%"]})," · ",l("usage.overview.cache_hit_rate_detail",{reused:qt(u,t.cacheReusedTokens)||String(0),input:qt(u,t.cacheInputTokens)||String(0)})]}),m&&e.jsxs("p",{className:"mb-3 text-[10px] leading-snug text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsxs("span",{className:"font-medium text-oai-gray-500 dark:text-oai-gray-400",children:[l("usage.overview.antigravity_notice_title"),"."]})," ",l("usage.overview.antigravity_notice_body")]}),x&&e.jsx(vn,{}),s?e.jsx("div",{className:"mb-4 pb-4 border-b border-oai-gray-200 dark:border-oai-gray-700",children:e.jsx(id,{from:n,to:i,source:s,referenceTotalTokens:t.usage,onLoadingChange:h})}):null,e.jsx(_n,{models:o,color:a})]})}function _d({id:t,children:a,onEmptyChange:r}){const{attributes:s,listeners:n,setNodeRef:i,transform:o,transition:u,isDragging:c}=Ui({id:t}),h=d.useRef(null),m=d.useRef(null);d.useLayoutEffect(()=>{if(!r)return;const g=h.current?h.current.childNodes.length===0:!0;m.current!==g&&(m.current=g,r(t,g))});const x={transform:Hi.Transform.toString(o)||void 0,transition:u,zIndex:c?20:void 0};return e.jsxs("div",{ref:i,style:x,className:jt("group/sortable relative has-[[data-sortable-body]:empty]:hidden",c&&"opacity-90"),children:[e.jsx("button",{type:"button","aria-label":l("dashboard.overview.layout.drag_handle"),className:jt("peer absolute left-1/2 top-1 z-10 flex h-5 w-6 -translate-x-1/2 items-center justify-center rounded-md","cursor-grab active:cursor-grabbing touch-none select-none","text-oai-gray-400 dark:text-oai-gray-600 opacity-0 transition-colors duration-150","hover:text-oai-gray-600 dark:hover:text-oai-gray-300 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800","group-hover/sortable:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/50",c&&"opacity-100 bg-oai-gray-100 dark:bg-oai-gray-800"),...s,...n,children:e.jsxs("svg",{viewBox:"0 0 14 8",width:"14",height:"8",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"2",cy:"2",r:"1"}),e.jsx("circle",{cx:"2",cy:"6",r:"1"}),e.jsx("circle",{cx:"7",cy:"2",r:"1"}),e.jsx("circle",{cx:"7",cy:"6",r:"1"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"}),e.jsx("circle",{cx:"12",cy:"6",r:"1"})]})}),e.jsx("div",{ref:h,"data-sortable-body":!0,className:jt("rounded-xl transition-shadow duration-200 ease-out","peer-hover:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-hover:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]","peer-focus-visible:shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:peer-focus-visible:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]",c&&"shadow-[0_12px_28px_-14px_rgba(15,23,42,0.22)] dark:shadow-[0_12px_28px_-12px_rgba(0,0,0,0.6)]"),children:a})]})}function vd({todayTokens:t=0,isSyncing:a=!1,hasError:r=!1,isDisconnected:s=!1}={}){return d.useMemo(()=>r?"error":s?"disconnected":a?"working-typing":t===0?"sleeping":t<5e4?"idle-living":t<2e5?"idle-look":t<5e5?"working-ultrathink":t<2e6?"working-typing":"working-ultrathink",[t,a,r,s])}const Ss="macAppBannerDismissed",jd="leaderboardBannerDismissed",Nd="https://github.com/xiufengsun/TokenTracker/releases/latest",Cs="tokentracker_native_app",ya=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(Cs,"1"),!0):localStorage.getItem(Cs)==="1"}catch{return!1}})();function Sd({todayTokens:t=0,isSyncing:a=!1,enterDelay:r=0}){const{openLoginModal:s}=mi(),{signedIn:n}=Js(),i=vd({todayTokens:t,isSyncing:a}),o=ya?jd:Ss,[u,c]=d.useState(()=>{try{return localStorage.getItem(o)==="1"?!0:!ya&&new URLSearchParams(window.location.search).get("from")==="menubar"?(localStorage.setItem(Ss,"1"),!0):!1}catch{return!1}}),h=d.useCallback(()=>{c(!0);try{localStorage.setItem(o,"1")}catch{}},[o]);if(u)return null;let m,x,g,p,y,k;ya&&n?(m="View the Leaderboard",x="Compare your usage globally",g="Leaderboard",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M2 8.5V10h8V8.5M6 1.5v6m0 0L3.5 5M6 7.5l2.5-2.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(180 6 6)"})}),y=()=>{window.location.pathname="/leaderboard"}):ya?(m="Join the Leaderboard",x="Log in to compare your usage with others",g="Log In",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6.5 1.5h3a1 1 0 011 1v7a1 1 0 01-1 1h-3M5 8.5L7.5 6 5 3.5M7.5 6H1.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),y=s):(m="Try the Menu Bar App",x="Always-on stats with Clawd companion",g="Download",p=e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:"opacity-70",children:e.jsx("path",{d:"M6 2v6m0 0L3.5 5.5M6 8l2.5-2.5M2 10h8",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round"})}),k=Nd);const f=k?ve.a:ve.button,v=k?{href:k,target:"_blank",rel:"noopener noreferrer"}:{onClick:y};return e.jsx(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,delay:r,ease:[.16,1,.3,1]},className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx(dl,{state:i,size:56})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-900 dark:text-oai-white",children:m}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-0.5",children:x})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs(f,{...v,whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:[g,p]}),e.jsx("button",{onClick:h,className:"p-1 text-oai-gray-400 hover:text-oai-gray-600 dark:hover:text-oai-gray-300 transition-colors","aria-label":"Dismiss",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round"})})})]})]})})}const Ts="widgetOnboardingDismissed",As="tokentracker_native_app",Cd=(()=>{try{return new URLSearchParams(window.location.search).get("app")==="1"?(localStorage.setItem(As,"1"),!0):localStorage.getItem(As)==="1"}catch{return!1}})();function Td({enterDelay:t=0}){const[a,r]=d.useState(()=>{try{return localStorage.getItem(Ts)==="1"}catch{return!1}}),s=d.useCallback(()=>{r(!0);try{localStorage.setItem(Ts,"1")}catch{}},[]);return!Cd||Qs()?null:e.jsx(Ta,{initial:!1,children:!a&&e.jsxs(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-8,transition:{duration:.2,ease:[.4,0,.2,1]}},transition:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:s,"aria-label":l("dashboard.widgets.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx("div",{className:"rounded-lg overflow-hidden ring-1 ring-black/5 dark:ring-white/10 shadow-sm",children:e.jsx("img",{src:"/widgets-overview.png",alt:l("dashboard.widgets.title"),width:734,height:552,className:"w-full h-auto block",loading:"lazy",decoding:"async"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.widgets.title")}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.widgets.hint")})]})]},"widget-onboarding-card")})}const Cr="islandOnboardingDismissed";function Ad(){try{return localStorage.getItem(Cr)==="1"}catch{return!1}}function Ds(){try{localStorage.setItem(Cr,"1")}catch{}}function Dd(){try{localStorage.removeItem(Cr)}catch{}}function Ld({className:t}){return e.jsxs("svg",{viewBox:"0 6 15 9",fill:"currentColor","aria-hidden":"true",className:t,children:[e.jsx("rect",{x:"2",y:"6",width:"11",height:"7"}),e.jsx("rect",{x:"0",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"13",y:"9",width:"2",height:"2"}),e.jsx("rect",{x:"3",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"5",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"9",y:"13",width:"1",height:"2"}),e.jsx("rect",{x:"11",y:"13",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"4",y:"8",width:"1",height:"2"}),e.jsx("rect",{className:"fill-black",x:"10",y:"8",width:"1",height:"2"})]})}function Md({reduceMotion:t}){return e.jsxs("div",{"aria-hidden":"true",className:"relative h-24 overflow-hidden rounded-lg bg-slate-950 ring-1 ring-black/10 dark:ring-white/10",children:[e.jsx("div",{className:"absolute -left-10 -top-12 h-36 w-56 rounded-full bg-indigo-600/25 blur-3xl"}),e.jsx("div",{className:"absolute -right-8 top-2 h-32 w-48 rounded-full bg-sky-500/15 blur-3xl"}),e.jsx("div",{className:"absolute bottom-[-3rem] left-1/3 h-32 w-64 rounded-full bg-fuchsia-500/10 blur-3xl"}),e.jsxs("div",{className:"absolute inset-x-0 top-0 flex h-[16px] items-center justify-between bg-black/45 px-2.5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-[3px] rounded-full bg-white/60"}),e.jsx("span",{className:"h-[3px] w-5 rounded-full bg-white/30"}),e.jsx("span",{className:"h-[3px] w-3.5 rounded-full bg-white/20"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-[3px] w-3 rounded-full bg-white/20"}),e.jsx("span",{className:"h-[3px] w-4 rounded-full bg-white/35"})]})]}),e.jsxs(ve.div,{className:"absolute left-1/2 top-0 flex h-[22px] -translate-x-1/2 items-center rounded-b-[10px] bg-black pl-2 pr-2.5 shadow-lg shadow-black/60 ring-1 ring-white/[0.06]",animate:t?void 0:{opacity:[1,.94,1]},transition:t?void 0:{duration:3.2,repeat:1/0,ease:"easeInOut"},children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:[e.jsx(Ld,{className:"h-[9px] w-[15px] translate-y-[0.5px] text-white/90"}),"8.2M"]}),e.jsx("span",{className:"mx-2 h-2.5 w-7 rounded-[2px] bg-black"}),e.jsx("span",{className:"text-[9px] font-semibold tracking-tight text-white/90 tabular-nums",children:"$12.40"})]})]})}function Ed({enterDelay:t=0}){const{available:a,settings:r,setSetting:s}=ul(),[n,i]=d.useState(Ad),[o,u]=d.useState(!1),c=Nr(),h=d.useCallback(()=>{i(!0),Ds()},[]),m=d.useCallback(()=>{if(!a){try{window.location.href="tokentracker://open"}catch{}return}s("dynamicIslandEnabled",!0),o&&s("hideMenuBarIcon",!0),Ds(),i(!0),hi({title:l("dashboard.island.enabled_toast"),data:{onUndo:()=>{s("hideMenuBarIcon",!1),s("dynamicIslandEnabled",!1),Dd(),i(!1)}}})},[a,o,s]),x=a&&!!r?.dynamicIslandSupported&&!r?.dynamicIslandEnabled,g=!a&&!Qs(),p=!n&&(x||g);return e.jsx(Ta,{initial:!1,children:p&&e.jsxs(ve.div,{initial:c?!1:{opacity:0,y:12},animate:{opacity:1,y:0},exit:c?{opacity:0}:{opacity:0,y:-8},transition:c?{duration:0}:{duration:.35,delay:t,ease:[.16,1,.3,1]},className:"relative rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-4",children:[e.jsx("button",{type:"button",onClick:h,"aria-label":l("dashboard.island.dismiss_aria"),className:"absolute top-2.5 right-2.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-md text-oai-gray-400 hover:text-oai-gray-700 dark:hover:text-oai-gray-200 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-gray-300 dark:focus-visible:ring-oai-gray-600 transition-colors",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M4 4l6 6m0-6L4 10",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})}),e.jsx(Md,{reduceMotion:c}),e.jsx("div",{className:"mt-4 flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-sm font-medium tracking-tight text-oai-gray-900 dark:text-oai-white",children:l("dashboard.island.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[8px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase scale-90 origin-left",children:l("qpd.card.badge")})]}),e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-400 mt-1 leading-snug",children:l("dashboard.island.hint")})]})}),a?e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-lg bg-oai-gray-50 px-3 py-2.5 dark:bg-oai-gray-800/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-medium text-oai-gray-800 dark:text-oai-gray-200",children:l("settings.labs.island_hide_menubar.label")}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-oai-gray-500 dark:text-oai-gray-400",children:l("settings.labs.island_hide_menubar.hint")})]}),e.jsx(ml,{checked:o,onChange:()=>u(y=>!y),ariaLabel:l("settings.labs.island_hide_menubar.aria")})]}):null,e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx(ve.button,{type:"button",onClick:m,whileHover:c?void 0:{scale:1.03},whileTap:c?void 0:{scale:.97},className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-white bg-oai-gray-900 dark:bg-oai-white dark:text-oai-gray-900 rounded-md hover:opacity-90 transition-opacity",children:a?l("dashboard.island.enable"):l("local_only.open_app")}),e.jsxs("a",{href:"/settings?section=labs",className:"inline-flex items-center gap-0.5 text-xs font-medium text-oai-gray-500 hover:text-oai-gray-700 dark:text-oai-gray-400 dark:hover:text-oai-gray-200 transition-colors",children:[l("dashboard.island.settings_link"),e.jsx(hl,{size:12,strokeWidth:2,"aria-hidden":!0})]})]})]},"island-onboarding-card")})}function Id({enabled:t=!1,from:a,to:r,accessToken:s,deviceId:n=null}={}){const[i,o]=d.useState(null),[u,c]=d.useState(!1),[h,m]=d.useState(null),x=St([t,a,r,s,n]),g=d.useCallback(async()=>{if(!t)return;const p=x();c(!0),m(null);try{const y=await Oe(s);if(!p())return;const k=await gi({from:a,to:r,device:n,accessToken:y});if(!p())return;o(k||null)}catch(y){if(!p())return;m(y?.message||String(y)),o(null)}finally{p()&&c(!1)}},[t,a,r,s,n,x]);return d.useEffect(()=>{if(!t){o(null),m(null),c(!1);return}o(null),m(null),c(!0),g()},[t,g]),{data:i,loading:u,error:h,refresh:g}}function jn(t){return t==null?"—":t===0?"$0":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Nn(t){return t==null?"—":`${Math.round(t*100)}%`}function Rd(t,a){if(a==null||a===0||t==null||t===0)return"—";const r=t/a;return r<1?`$${r.toFixed(4)}`:`$${r.toFixed(2)}`}function Fd({row:t}){return e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60 hover:bg-oai-gray-50/40 dark:hover:bg-oai-gray-800/10 transition-colors",children:[e.jsx("td",{className:"py-2.5 pr-2 font-mono text-[11px] text-oai-gray-700 dark:text-oai-gray-300 truncate max-w-[80px] xs:max-w-[110px] sm:max-w-[140px]",title:t.key,children:t.key}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:jn(t.cost_usd)}),e.jsxs("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:[t.accepted,"/",t.outcomes]}),e.jsx("td",{className:"py-2.5 px-1.5 text-right tabular-nums text-oai-gray-600 dark:text-oai-gray-400",children:Nn(t.acceptance_rate)}),e.jsx("td",{className:"py-2.5 pl-2 pr-2 text-right tabular-nums font-semibold text-oai-black dark:text-oai-white",children:Rd(t.cost_usd,t.accepted)})]})}function $d({from:t,to:a,deviceId:r=null}){const{formatTokens:s,formatTokensTooltip:n}=Fe(),{enabled:i}=gl(),{data:o,loading:u}=Id({enabled:i,from:t,to:a,deviceId:r});if(!i)return null;const c=(o&&o.available&&Array.isArray(o.by_model)?o.by_model:[]).filter(g=>g.outcomes>0&&g.key!=="unknown");if(!c.length)return null;const h=c.slice(0,6),m=o.totals||{},x=`${l("qpd.card.subtitle")}${u?` ${l("qpd.card.updating")}`:""}`;return e.jsxs(De,{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-oai-white",children:l("qpd.card.title")}),e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-semibold tracking-wider text-oai-gray-500 bg-oai-gray-100 dark:text-oai-gray-400 dark:bg-oai-gray-800/80 rounded uppercase",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mb-3 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:x}),e.jsx("div",{className:"w-full overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full text-xs min-w-[340px] sm:min-w-0",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("th",{className:"pb-1.5 pr-2 text-left font-medium",children:l("qpd.card.col_model")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_cost")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_accepted")}),e.jsx("th",{className:"pb-1.5 px-1.5 text-right font-medium",children:l("qpd.card.col_rate")}),e.jsx("th",{className:"pb-1.5 pl-2 pr-2 text-right font-medium",title:l("qpd.card.qpd_tooltip"),children:l("qpd.card.col_qpd")})]})}),e.jsx("tbody",{children:h.map(g=>e.jsx(Fd,{row:g},g.key))})]})}),e.jsxs("div",{className:"mt-3 flex items-center justify-between border-t border-oai-gray-200 dark:border-oai-gray-800 pt-2.5 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("qpd.card.totals",{accepted:m.accepted??0,outcomes:m.outcomes??0,cost:jn(m.cost_usd)})}),e.jsx("span",{title:`${l("qpd.card.et_tooltip")} · ${n(m.effective_tokens)}`,children:l("qpd.card.et",{tokens:s(m.effective_tokens),rate:Nn(m.acceptance_rate)})})]}),m.outcomes<15&&e.jsxs("p",{className:"mt-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500 italic border-t border-oai-gray-100 dark:border-oai-gray-800/40 pt-2",children:["* ",l("qpd.card.sparse_notice","Tip: Spark outcomes dataset might skew Quality/$ ratios. For precise metrics, select a narrower time window.")]})]})}const Pd=new Set(["unknown","synthetic","openai"]);function or(t){return t==null?"—":`${Math.round(t*100)}%`}function Bd(t){return t==null?"—":t<1?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`}function Ze(t){const a=Number(t);return Number.isFinite(a)?new Intl.NumberFormat().format(Math.round(a)):"0"}function zd(t){const r=String(t?.model||"").trim().toLowerCase().replace(/^<|>$/g,"");return!!r&&!Pd.has(r)&&Number(t?.edit_turns||0)>0}function Ls(){return e.jsx("div",{className:"mb-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-oai-black dark:text-white",children:l("sessions.card.title")}),e.jsx("span",{className:"rounded bg-oai-gray-100 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wider text-oai-gray-500 dark:bg-oai-gray-800/80 dark:text-oai-gray-400",children:l("qpd.card.badge")})]}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("sessions.card.subtitle")})]})})}function Od({from:t,to:a}){const[r,s]=d.useState({loading:!0,sessions:null,context:null}),n=d.useId(),{enabled:i}=xl(),{formatTokens:o}=Fe(),u=f=>o(f,{mode:Kt.COMPACT});d.useEffect(()=>{if(!i){s({loading:!1,sessions:null,context:null});return}let f=!1;return s(v=>({...v,loading:!0})),Promise.all([xi({from:t,to:a}),fi()]).then(([v,w])=>{f||s({loading:!1,sessions:v,context:w})}).catch(()=>{f||s({loading:!1,sessions:null,context:null})}),()=>{f=!0}},[i,t,a]);const c=d.useMemo(()=>(r.sessions?.by_model||[]).filter(zd).slice(0,5),[r.sessions]),h=d.useMemo(()=>(r.sessions?.subagents||[]).slice(0,3),[r.sessions]);if(!i||!r.loading&&!r.sessions?.available&&!r.context?.estimated_fixed_tokens)return null;const m=r.sessions?.summary||{},x=m.edit_session_rate??m.productive_rate,g=m.first_pass_rate??m.one_shot_rate,p=m.edit_sessions??m.productive_sessions??0,y=m.sessions??r.sessions?.session_count??0,k=m.edit_turns??0;return r.loading&&!r.sessions&&!r.context?e.jsxs(De,{children:[e.jsx(Ls,{}),e.jsx("div",{role:"status",className:"flex h-24 items-center justify-center rounded-lg bg-oai-gray-50 text-xs text-oai-gray-400 dark:bg-oai-gray-800/50 dark:text-oai-gray-500",children:l("sessions.card.loading")})]}):e.jsxs(De,{children:[e.jsx(Ls,{}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsx(ir,{label:l("sessions.card.edit_sessions"),value:or(x),detail:l("sessions.card.edit_session_value",{edits:Ze(p),sessions:Ze(y)})}),e.jsx(ir,{label:l("sessions.card.first_pass"),value:or(g),detail:l("sessions.card.edit_session_value",{edits:Ze(m.first_pass_sessions??m.one_shot_sessions??0),sessions:Ze(p)})}),e.jsx(ir,{label:l("sessions.card.cost_edit"),value:Bd(m.cost_per_edit),detail:l("sessions.card.edit_turn_count",{count:Ze(k)})})]}),e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:[e.jsx("span",{children:l("sessions.card.sample",{sessions:Ze(y),edits:Ze(k)})}),e.jsxs("span",{className:"group relative inline-flex shrink-0",children:[e.jsx("button",{type:"button","aria-describedby":n,className:"cursor-help rounded-sm underline decoration-dotted underline-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-oai-brand/40",children:l("sessions.card.methodology_label")}),e.jsx("span",{id:n,role:"tooltip",className:"pointer-events-none absolute right-0 top-full z-20 mt-2 w-64 rounded-xl border border-oai-gray-200/60 bg-white/95 px-3 py-2 text-left text-[10.5px] font-normal leading-relaxed text-oai-gray-700 opacity-0 shadow-xl backdrop-blur-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 dark:border-oai-gray-700/70 dark:bg-oai-gray-900/95 dark:text-oai-gray-200",children:l("sessions.card.methodology")})]})]}),!!c.length&&e.jsx("div",{className:"overflow-x-auto oai-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[440px] text-xs",children:[e.jsx("thead",{className:"text-[10px] uppercase tracking-wide text-oai-gray-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"pb-1.5 text-left font-medium",children:l("sessions.card.model")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.edit_sessions")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.first_pass")}),e.jsx("th",{className:"pb-1.5 text-right font-medium",children:l("sessions.card.tokens_edit")})]})}),e.jsx("tbody",{children:c.map(f=>e.jsxs("tr",{className:"border-t border-oai-gray-100 dark:border-oai-gray-800/60",children:[e.jsx("td",{className:"py-2 pr-2 font-mono text-[11px] truncate max-w-[150px]",title:f.model,children:f.model}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:l("sessions.card.edit_session_value",{edits:Ze(f.edit_sessions??f.productive_sessions??0),sessions:Ze(f.sessions)})}),e.jsx("td",{className:"py-2 pl-2 text-right tabular-nums",children:or(f.first_pass_rate??f.one_shot_rate)}),e.jsx("td",{className:"py-2 text-right tabular-nums",children:u(f.tokens_per_edit)})]},f.model))})]})}),r.context?e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-oai-gray-200 dark:border-oai-gray-800 flex items-center justify-between gap-3 text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.context")}),e.jsx("span",{className:"tabular-nums",title:l("sessions.card.context_tooltip"),children:u(r.context.estimated_fixed_tokens)})]}):null,!!h.length&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5 text-[10px] text-oai-gray-500 dark:text-oai-gray-400",children:[e.jsx("span",{children:l("sessions.card.subagents")}),h.map(f=>e.jsx("span",{className:"rounded-full bg-oai-gray-100 dark:bg-oai-gray-800 px-1.5 py-0.5",children:l("sessions.card.subagent_item",{name:f.name,calls:Math.round(f.calls)})},f.name))]}),e.jsx("p",{className:"mt-2 text-[10px] text-oai-gray-400 dark:text-oai-gray-500",children:l("sessions.card.privacy")})]})}function ir({label:t,value:a,detail:r}){return e.jsxs("div",{className:"rounded-lg bg-oai-gray-50 dark:bg-oai-gray-800/50 px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] text-oai-gray-500 dark:text-oai-gray-400 truncate",children:t}),e.jsx("div",{className:"mt-0.5 text-sm font-semibold tabular-nums text-oai-black dark:text-white",children:a}),e.jsx("div",{className:"mt-0.5 text-[9px] tabular-nums text-oai-gray-400 dark:text-oai-gray-500 truncate",children:r})]})}function le({className:t}){return e.jsx("div",{className:jt("rounded bg-oai-gray-200/70 dark:bg-oai-gray-800/70 animate-pulse",t)})}function Ud(){return e.jsx("div",{className:"flex gap-1 overflow-hidden",children:Array.from({length:20},(t,a)=>e.jsx("div",{className:"flex flex-col gap-1",children:Array.from({length:7},(r,s)=>e.jsx(le,{className:"h-2.5 w-2.5 rounded-[2px]"},s))},a))})}function Hd(){return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsxs("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:[e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(le,{className:"h-4 w-32"}),e.jsx(le,{className:"h-6 w-24"})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-24"}),Array.from({length:4},(t,a)=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(le,{className:"h-3 w-20"}),e.jsx(le,{className:"h-3 w-12"})]},a))]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-20"}),e.jsx(Ud,{})]})}),e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(le,{className:"h-3.5 w-28"}),e.jsx(le,{className:"h-32 w-full"})]})})]}),e.jsxs("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:[e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex flex-1 min-w-0 gap-1",children:Array.from({length:5},(t,a)=>e.jsx(le,{className:"h-7 w-14 rounded-md shrink-0"},a))}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(le,{className:"h-8 w-20 rounded-md"}),e.jsx(le,{className:"h-8 w-8 rounded-md"})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4 mb-8",children:[e.jsx(le,{className:"h-3 w-28"}),e.jsx(le,{className:"h-14 w-3/5 max-w-xs"}),e.jsx(le,{className:"h-6 w-24"})]}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(le,{className:"h-1.5 w-full rounded-full"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-5 gap-3",children:Array.from({length:5},(t,a)=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg border border-oai-gray-200 dark:border-oai-gray-700 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(le,{className:"h-[15px] w-[15px] rounded-sm shrink-0"}),e.jsx(le,{className:"h-3 w-12"})]}),e.jsx(le,{className:"h-5 w-10"}),e.jsx(le,{className:"h-2.5 w-14"})]},a))})]})]}),e.jsxs(De,{children:[e.jsxs("div",{className:"flex items-center gap-1 mb-4",children:[e.jsx(le,{className:"h-7 w-16 rounded"}),e.jsx(le,{className:"h-7 w-20 rounded"})]}),e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-200 dark:border-oai-gray-700 pb-2",children:[e.jsx(le,{className:"h-3 w-20 shrink-0"}),Array.from({length:5},(t,a)=>e.jsx(le,{className:"h-3 flex-1"},a))]}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:8},(t,a)=>e.jsxs("div",{className:"flex items-center gap-3 border-b border-oai-gray-100 dark:border-oai-gray-800 py-2.5 last:border-b-0",children:[e.jsx(le,{className:"h-3.5 w-20 shrink-0"}),Array.from({length:5},(r,s)=>e.jsx(le,{className:"h-3.5 flex-1"},s))]},a))})]})]})]})}const Vd=yl.slice(0,10),Ms=.06,Kd=.11,Wd=.05,Gd=new Set(["macAppBanner","widgetOnboarding"]);function Es({title:t,subtitle:a,desc:r,loginCard:s,copy:n}){return e.jsxs("div",{className:"min-h-[85vh] w-full flex items-center justify-center text-oai-black dark:text-white relative overflow-hidden px-4 md:px-8 py-8 md:py-16 transition-colors duration-200 bg-[linear-gradient(to_right,#80808007_1px,transparent_1px),linear-gradient(to_bottom,#80808007_1px,transparent_1px)] bg-[size:40px_40px]",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_50%_0%,rgba(59,130,246,0.03),transparent_50%)] dark:bg-[radial-gradient(circle_at_50%_0%,rgba(99,102,241,0.05),transparent_50%)] pointer-events-none"}),e.jsxs("div",{className:"w-full max-w-5xl grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-16 items-start relative z-10",children:[e.jsxs("div",{className:"lg:col-span-7 flex flex-col justify-center space-y-8 text-left pr-0 lg:pr-6",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:32,height:32,className:"rounded-md shadow-md border border-oai-gray-200/50 dark:border-oai-gray-800 shadow-black/10 dark:shadow-black/30"}),e.jsx("span",{className:"text-xl font-bold tracking-tight bg-gradient-to-r from-oai-black to-oai-gray-600 dark:from-white dark:to-oai-gray-400 bg-clip-text text-transparent font-oai",children:n("shared.app_name")})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl md:text-4xl lg:text-4.5xl font-black tracking-tight leading-[1.15] text-oai-black dark:text-white",children:t}),e.jsx("p",{className:"text-oai-gray-500 dark:text-oai-gray-400 text-sm md:text-base max-w-xl leading-relaxed",children:r})]}),e.jsx("div",{className:"w-full max-w-[280px] sm:max-w-md opacity-85 hover:opacity-100 transition-opacity duration-200",children:e.jsx("div",{className:"flex justify-start",children:e.jsx(pl,{logos:Vd,columnCount:6})})})]})]}),e.jsx("div",{className:"lg:col-span-5 flex justify-center",children:e.jsxs(ve.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{duration:.3},className:"w-full max-w-[400px] rounded-2xl border border-oai-gray-200/80 dark:border-oai-gray-800 bg-white/70 dark:bg-oai-gray-950/40 backdrop-blur-md shadow-2xl p-1 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -inset-px bg-gradient-to-b from-white/10 dark:from-white/5 to-transparent pointer-events-none rounded-2xl"}),s]})})]})]})}function qd(t){const{copy:a,onOpenShare:r,screenshotMode:s,showExpiredGate:n,showAuthGate:i,identityDisplayName:o,identityStartDate:u,activeDays:c,identitySubscriptions:h,identityScrambleDurationMs:m,projectUsageEntries:x,projectUsageLimit:g,setProjectUsageLimit:p,projectDetailQuery:y,topModels:k,signedIn:f,publicMode:v,isLocalMode:w,shouldShowInstall:D,installPrompt:C,handleCopyInstall:R,installCopied:A,installInitCmdDisplay:P,trendRowsForDisplay:N,trendFromForDisplay:j,trendToForDisplay:S,trendZoomConfig:E,usageFrom:O,usageTo:F,period:L,trendTimeZoneLabel:B,activityHeatmapBlock:K,periodsForDisplay:q,setSelectedPeriod:_,customFrom:$,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,summaryLabel:ne,summaryValue:oe,summaryFullValue:je,hasSummary:be,summaryLoading:Le,providersLoading:X,onToggleSummaryFormat:U,summaryTotalTokensRaw:re,summaryCostValue:ee,summaryConversationsValue:ae,rollingUsage:ye,costInfoEnabled:Y,openCostModal:J,costModalOpen:Z,closeCostModal:ge,allowBreakdownToggle:$e,refreshAll:me,usageLoadingState:T,announceUsageLoading:z,initialDashboardLoading:he,fleetData:V,hasDetailsActual:de,dailyEmptyPrefix:Ce,installSyncCmd:Ne,dailyEmptySuffix:At,detailsColumns:fe,ariaSortFor:pe,toggleSort:Pe,sortIconFor:Be,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:ht,renderDailyBreakdownDate:Q,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:ke,detailsPageCount:we,detailsPage:Te,setDetailsPage:gt,deviceOptions:Lt,selectedDevice:Jt,onDeviceChange:Qt,deviceUsageBlock:Mt,leftCardOrder:Ma,onLeftReorder:Ke,rightCardOrder:Xt,onRightReorder:rt}=t,Et=null,Ea=null,[ea,ta]=d.useState(()=>new Set),It=d.useCallback((ce,ie)=>{Gd.has(ce)&&ta(Se=>{if(Se.has(ce)===ie)return Se;const et=new Set(Se);return ie?et.add(ce):et.delete(ce),et})},[]),Ia={macAppBanner:w,statsPanel:!0,islandOnboarding:w,widgetOnboarding:w,installCopy:D,activityHeatmap:!!K,deviceUsage:!!Mt,trendMonitor:!s,qualityPerDollar:!s,sessionInsights:w&&!s},Rt=(Ma||[]).filter(ce=>Ia[ce]&&!ea.has(ce)),Ft={usageOverview:!0,dataDetails:!s},Ra=(Xt||[]).filter(ce=>Ft[ce]&&!ea.has(ce));function qe(ce,ie){switch(ce){case"macAppBanner":return e.jsx(Sd,{todayTokens:re,isSyncing:T,enterDelay:ie});case"statsPanel":return e.jsx(st,{delay:ie,children:e.jsx(Rc,{title:a("dashboard.identity.title"),subtitle:a("dashboard.identity.subtitle"),period:L,startDate:u??a("identity_card.rank_placeholder"),streakDays:c,subscriptions:h,periodConversations:ae,rolling:ye,topModels:k})});case"islandOnboarding":return e.jsx(Ed,{enterDelay:ie});case"widgetOnboarding":return e.jsx(Td,{enterDelay:ie});case"installCopy":return e.jsx(st,{delay:ie,children:e.jsxs("div",{className:"rounded-xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 p-3",children:[e.jsx("div",{className:"text-xs text-oai-gray-500 dark:text-oai-gray-300 mb-1.5",children:C}),e.jsxs(ve.button,{onClick:R,whileHover:{scale:1.01},whileTap:{scale:.99},className:"w-full flex items-center justify-between px-3 py-2 bg-oai-gray-50 dark:bg-oai-gray-800 hover:bg-oai-gray-100 dark:hover:bg-oai-gray-700 rounded-lg transition-colors",children:[e.jsx("code",{className:"text-xs font-mono text-oai-gray-700 dark:text-oai-gray-300",children:P}),e.jsx(ve.span,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"text-xs text-oai-brand",children:A?"Copied ✓":"Copy"},A?"copied":"copy")]})]})});case"activityHeatmap":return e.jsx(st,{delay:ie,children:K});case"deviceUsage":return e.jsx(st,{delay:ie,children:Mt});case"trendMonitor":return e.jsx(st,{delay:ie,children:e.jsx(Xs,{rows:N,from:j,to:S,period:L,timeZoneLabel:B,showTimeZoneLabel:!1,zoomConfig:E})});case"qualityPerDollar":return e.jsx($d,{from:O,to:F,deviceId:Jt});case"sessionInsights":return e.jsx(Od,{from:O,to:F});default:return null}}function aa(ce,ie){switch(ce){case"usageOverview":return e.jsx(st,{delay:ie,children:e.jsx(bd,{period:L,periods:q,onPeriodChange:_,summaryLabel:ne,summaryValue:oe,summaryFullValue:je,hasSummary:be,summaryLoading:Le,providersLoading:X,onToggleSummaryFormat:be?U:null,summaryCostValue:ee,onCostInfo:Y?J:null,fleetData:V,onRefresh:s?null:me,loading:T,announceLoading:z,onOpenShare:s?null:r,customFrom:$,customTo:H,onCustomRangeApply:te,customRangeOpen:ue,onCustomRangeOpenChange:W,from:O,to:F,deviceOptions:Lt,selectedDevice:Jt,onDeviceChange:Qt})});case"dataDetails":return e.jsx(st,{delay:ie,children:e.jsx(Ec,{projectEntries:x,projectLimit:g,onProjectLimitChange:p,projectDetailQuery:y,copy:a,hasDetailsActual:de,dailyEmptyPrefix:Ce,installSyncCmd:Ne,dailyEmptySuffix:At,detailsColumns:fe,ariaSortFor:pe,toggleSort:Pe,sortIconFor:Be,pagedDetails:Dt,dailyBreakdownRows:mt,dailyBreakdownColumns:Ve,dailyBreakdownAriaSortFor:Aa,dailyBreakdownSortIconFor:Xe,dailyBreakdownDateKey:Da,detailsDateKey:La,renderDetailDate:ht,renderDailyBreakdownDate:Q,renderDetailCell:Zt,DETAILS_PAGED_PERIODS:ke,period:L,detailsPageCount:we,detailsPage:Te,setDetailsPage:gt})});default:return null}}const We=Vi(rs(Zi,{activationConstraint:{distance:6}}),rs(Yi,{coordinateGetter:qi})),xe=d.useCallback(ce=>{const{active:ie,over:Se}=ce;!Se||ie.id===Se.id||Ke?.(String(ie.id),String(Se.id))},[Ke]),Fa=d.useCallback(ce=>{const{active:ie,over:Se}=ce;!Se||ie.id===Se.id||rt?.(String(ie.id),String(Se.id))},[rt]);function $t(ce,ie,Se,et){return s?e.jsx(e.Fragment,{children:ce.map((Ae,xt)=>e.jsx(_t.Fragment,{children:ie(Ae,Se+Ms*xt)},Ae))}):e.jsx(Ki,{sensors:We,onDragEnd:et,children:e.jsx(Wi,{items:ce,strategy:Gi,children:ce.map((Ae,xt)=>e.jsx(_d,{id:Ae,onEmptyChange:It,children:ie(Ae,Se+Ms*xt)},Ae))})})}const ra=$t(Rt,qe,Kd,xe),$a=$t(Ra,aa,Wd,Fa);return e.jsxs(e.Fragment,{children:[e.jsxs(Dl,{bare:!s,hideHeader:s,header:Et,footer:s?null:Ea,className:s?"screenshot-mode":"",children:[i&&e.jsx(Es,{title:a("dashboard.auth_gate.hero_title"),desc:a("dashboard.auth_gate.desc"),copy:a,loginCard:e.jsx(ss,{title:a("dashboard.auth_gate.title"),subtitle:a("dashboard.auth_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),n&&e.jsx(Es,{title:a("dashboard.expired_gate.hero_title"),desc:a("dashboard.expired_gate.desc"),copy:a,loginCard:e.jsx(ss,{title:a("dashboard.expired_gate.title"),subtitle:a("dashboard.expired_gate.subtitle"),hideLogo:!0,className:"bg-transparent rounded-xl"})}),!i&&!n&&he&&e.jsx(Hd,{}),!i&&!n&&!he&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4",children:[e.jsx("div",{className:"lg:col-span-4 flex flex-col gap-4 min-w-0 order-2 lg:order-1",children:ra}),e.jsx("div",{className:"lg:col-span-8 flex flex-col gap-4 min-w-0 order-1 lg:order-2",children:$a})]})})]}),e.jsx(Nc,{isOpen:Z,onClose:ge,fleetData:V})]})}function Yd({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accountView:n=!1,accountAccessToken:i=null,accountRevision:o=0}={}){const u=!!(n&&i),[c,h]=d.useState([]),[m,x]=d.useState([]),[g,p]=d.useState(!1),[y,k]=d.useState(null),f=St([u,t,a,r,s,i,o]),v=d.useCallback(async()=>{const w=f();if(!u){h([]),x([]),p(!1),k(null);return}p(!0),k(null);try{const D=await Oe(i);if(!w())return;const C=await pi({from:t,to:a,timeZone:r,tzOffsetMinutes:s,accessToken:D});if(!w())return;h(Array.isArray(C?.devices)?C.devices:[]),x(Array.isArray(C?.account_sources)?C.account_sources:[])}catch(D){if(!w())return;k(D?.message||String(D)),h([]),x([])}finally{w()&&p(!1)}},[u,i,t,a,r,s,o,f]);return d.useEffect(()=>{h([]),x([]),k(null),u&&p(!0),v()},[u,v]),{devices:c,accountSources:m,loading:g,error:y,refresh:v}}const Zd=/^Token Tracker \(dashboard\)(?: #([0-9a-fA-F]+))?$/;function Is(t){const a=String(t||"").toLowerCase();return/iphone|ipad|ios/.test(a)?"iOS":/android/.test(a)?"Android":/mac|darwin/.test(a)?"Mac":/win/.test(a)?"Windows":/linux/.test(a)?"Linux":"Web"}function fr(t){if(!t)return null;const a=typeof t.device_name=="string"?t.device_name.trim():"",r=a.match(Zd);if(!r)return a||null;const s=(r[1]||String(t.id||"")).slice(0,8).toLowerCase();return s?`${Is(t.platform)} · ${s}`:Is(t.platform)}const Rs=" · ",Fs="%";function $s({platform:t,className:a}){const r=String(t||"").toLowerCase();return r.includes("darwin")||r.includes("mac")?e.jsx(vl,{className:a,"aria-hidden":!0}):r.includes("win")?e.jsx(Yr,{className:a,"aria-hidden":!0}):r.includes("linux")?e.jsx(Yr,{className:a,"aria-hidden":!0}):e.jsx(nn,{className:a,"aria-hidden":!0})}function Ps(t,a){return a===t?.id||t?.isCurrent===!0}function Jd({devices:t=[],accountSources:a=[],currentDeviceId:r="",selectedDeviceId:s="",onSelectDevice:n,onRenameDevice:i}){const{formatTokens:o,formatTokensTooltip:u}=Fe(),[c,h]=d.useState(""),[m,x]=d.useState(""),[g,p]=d.useState(!1),[y,k]=d.useState(""),f=typeof i=="function",v=typeof n=="function",w=!!s,D=t.reduce((j,S)=>j+(Number(S.total_tokens)||0),0)+a.reduce((j,S)=>j+(Number(S.total_tokens)||0),0),C=d.useMemo(()=>t.filter(j=>(Number(j.total_tokens)||0)>0).sort((j,S)=>(Number(S.total_tokens)||0)-(Number(j.total_tokens)||0)),[t]);function R(j){k(""),h(j.id);const S=typeof j.device_name=="string"?j.device_name:"";x(fr(j)===S?S:"")}function A(){h(""),x(""),k("")}async function P(j){const S=m.trim();if(!(!S||g)){p(!0),k("");try{await i(j.id,S),h(""),x("")}catch{k(j.id)}finally{p(!1)}}}const N=a.filter(j=>(Number(j.total_tokens)||0)>0);return C.length===0&&N.length===0?e.jsxs(De,{bodyClassName:"!px-3 !py-3.5",children:[e.jsx("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide px-2",children:l("dashboard.device_card.title")})}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-center",children:[e.jsx(nn,{className:"h-7 w-7 text-oai-gray-300 dark:text-oai-gray-600 mb-2 stroke-[1.5]"}),e.jsx("p",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400 font-medium",children:l("dashboard.device_card.empty")})]})]}):e.jsxs(De,{bodyClassName:"!px-3 !py-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 px-2",children:[e.jsx("div",{className:"text-sm font-medium text-oai-gray-500 dark:text-oai-gray-300 uppercase tracking-wide",children:l("dashboard.device_card.title")}),v&&w&&e.jsx("button",{type:"button",onClick:()=>n(""),className:"text-xs text-oai-gray-400 hover:text-oai-brand focus:outline-none transition-colors",children:l("dashboard.device_card.clear")})]}),e.jsxs("div",{className:"space-y-[2px]",children:[C.map(j=>{const S=Number(j.total_tokens)||0,E=D>0?(S/D*100).toFixed(1):"0.0",O=s===j.id,F=fr(j)||l("dashboard.device_card.unnamed"),L=c===j.id,B=O?"bg-oai-brand":w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50",K=w&&!O?"opacity-40 hover:opacity-80":"opacity-100";return e.jsxs("div",{className:"group relative",children:[L?e.jsxs("div",{className:"w-full rounded-md px-2 py-1.5 bg-oai-gray-50/50 dark:bg-oai-gray-900/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx($s,{platform:j.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("input",{autoFocus:!0,value:m,disabled:g,maxLength:60,placeholder:l("dashboard.device_card.rename_placeholder"),onChange:q=>x(q.target.value),onKeyDown:q=>{q.key==="Enter"?P(j):q.key==="Escape"&&A()},className:"flex-1 min-w-0 bg-transparent text-xs font-medium text-oai-black dark:text-oai-white border-b border-oai-gray-300 dark:border-oai-gray-700 focus:outline-none focus:border-oai-brand py-0"})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5",children:[e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_save"),disabled:g||!m.trim(),onClick:()=>P(j),className:"text-oai-gray-400 hover:text-oai-brand dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(bl,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_cancel"),disabled:g,onClick:A,className:"text-oai-gray-400 hover:text-oai-black dark:hover:text-white disabled:opacity-30 transition-colors p-0.5",children:e.jsx(jr,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden opacity-40 select-none",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${E}%`}})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-pressed":O,"aria-label":`${l("dashboard.device_filter.aria")}: ${F}${Ps(j,r)?` (${l("dashboard.device_card.current")})`:""}`,onClick:()=>n?.(O?"":j.id),className:`w-full text-left rounded-md px-2 py-1.5 transition-all duration-200 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-oai-brand/50 ${K} ${O?"bg-oai-gray-100/70 dark:bg-oai-gray-800/80 text-oai-black dark:text-oai-white":"bg-transparent hover:bg-oai-gray-50 dark:hover:bg-oai-gray-800/40 text-oai-black dark:text-oai-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx($s,{platform:j.platform,className:"h-3.5 w-3.5 shrink-0 text-oai-gray-500 dark:text-oai-gray-400"}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",title:F,children:F}),Ps(j,r)&&e.jsx("span",{className:"shrink-0 rounded-full bg-oai-brand/10 px-1.5 py-0.5 text-[10px] font-medium text-oai-brand",children:l("dashboard.device_card.current")})]}),e.jsxs("span",{title:u(S),className:`shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white transition-opacity duration-150 ${f?"group-hover:opacity-0":""}`,children:[o(S),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Rs,E,Fs]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${B}`,style:{width:`${E}%`}})})]}),f&&e.jsx("button",{type:"button","aria-label":l("dashboard.device_card.rename_aria"),onClick:()=>R(j),className:"absolute right-2 top-1.5 flex h-4 items-center text-oai-gray-400 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-oai-brand focus:outline-none transition-opacity duration-150",children:e.jsx(fl,{className:"h-3 w-3"})})]}),y===j.id&&e.jsx("div",{className:"px-2 mt-1 text-xs text-red-500 font-medium",children:l("dashboard.device_card.rename_error")})]},j.id)}),N.map(j=>{const S=Number(j.total_tokens)||0,E=D>0?(S/D*100).toFixed(1):"0.0",O=w?"opacity-40":"opacity-100";return e.jsxs("div",{className:`rounded-md px-2 py-1.5 transition-all duration-200 ${O}`,title:l("dashboard.device_card.account_scope_tip"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("span",{className:"h-3.5 w-3.5 shrink-0 flex items-center justify-center",children:e.jsx(Ct,{provider:j.source,size:14})}),e.jsx("span",{className:"block truncate text-[13px] font-medium text-oai-black dark:text-oai-white",children:vt(j.source)}),e.jsx("span",{className:"shrink-0 text-[10px] uppercase tracking-wide text-oai-gray-400 dark:text-oai-gray-500",children:l("dashboard.device_card.account_scope")})]}),e.jsxs("span",{title:u(S),className:"shrink-0 text-[13px] font-semibold tabular-nums text-oai-black dark:text-oai-white",children:[o(S),e.jsxs("span",{className:"text-oai-gray-400 dark:text-oai-gray-500 font-normal",children:[Rs,E,Fs]})]})]}),e.jsx("div",{className:"mt-1.5 h-[2px] bg-oai-gray-100 dark:bg-oai-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-700 ease-out ${w?"bg-oai-gray-300 dark:bg-oai-gray-600":"bg-oai-brand/50"}`,style:{width:`${E}%`}})})]},`account-${j.source}`)})]})]})}function Sn(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const ct=new Map,dt=new Map;function Cn(){typeof window>"u"||window.__tokentrackerNativeSaveListener||(window.__tokentrackerNativeSaveListener=!0,window.addEventListener("native:saveImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!ct.has(r))return;const s=ct.get(r);ct.delete(r),s({ok:!!a.ok,path:typeof a.path=="string"?a.path:void 0,error:typeof a.error=="string"?a.error:void 0})}),window.addEventListener("native:copyImageResult",t=>{const a=t?.detail||{},r=typeof a.requestId=="string"?a.requestId:null;if(!r||!dt.has(r))return;const s=dt.get(r);dt.delete(r),s({ok:!!a.ok,error:typeof a.error=="string"?a.error:void 0})}))}async function Qd(t){if(!Sn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const a=window?.webkit?.messageHandlers?.nativeBridge;if(!a)return{ok:!1,error:"native bridge unavailable"};Cn();const r=`copy_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(s=>{const n=window.setTimeout(()=>{dt.has(r)&&(dt.delete(r),s({ok:!1,error:"timeout"}))},8e3);dt.set(r,i=>{window.clearTimeout(n),s(i)});try{a.postMessage({type:"action",name:"copyImageToClipboard",requestId:r,dataUrl:t})}catch(i){dt.delete(r),window.clearTimeout(n),s({ok:!1,error:i?.message||String(i)})}})}async function Bs(t,a){if(!Sn()||typeof window>"u")return{ok:!1,error:"native bridge unavailable"};const r=window?.webkit?.messageHandlers?.nativeBridge;if(!r)return{ok:!1,error:"native bridge unavailable"};Cn();const s=`save_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return new Promise(n=>{const i=window.setTimeout(()=>{ct.has(s)&&(ct.delete(s),n({ok:!1,error:"timeout"}))},8e3);ct.set(s,o=>{window.clearTimeout(i),n(o)});try{r.postMessage({type:"action",name:"saveImageToDownloads",requestId:s,filename:a,dataUrl:t})}catch(o){ct.delete(s),window.clearTimeout(i),n({ok:!1,error:o?.message||String(o)})}})}const Tn=1200,An=1630,Dn={broadsheet:{width:1200,height:1630},"annual-report":{width:1080,height:1865}},Xd="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter+Tight:wght@400;500;600;700&family=IBM+Plex+Serif:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap";let lr=!1;function eu(){if(typeof document>"u"||lr)return;if(document.querySelector('link[data-share-card-fonts="true"]')){lr=!0;return}const a=document.createElement("link");a.rel="stylesheet",a.href=Xd,a.dataset.shareCardFonts="true",a.crossOrigin="anonymous",document.head.appendChild(a),lr=!0}async function tu(){if(typeof document>"u")return;const t=document.fonts;if(!(!t||typeof t.ready?.then!="function"))try{await t.ready}catch{}}async function au(t,a={}){if(typeof window>"u"||!t)return null;eu(),await tu(),await new Promise(c=>requestAnimationFrame(()=>c(null)));const{toBlob:r,toPng:s}=await yi(async()=>{const{toBlob:c,toPng:h}=await import("./index-BFIcLxb4.js");return{toBlob:c,toPng:h}},[]),n=a.pixelRatio??2,i=t.offsetWidth||Tn,o=t.offsetHeight||An,u={pixelRatio:n,cacheBust:!0,width:i,height:o,style:{width:`${i}px`,height:`${o}px`},skipFonts:!1,filter:c=>!(c instanceof HTMLElement)||c.dataset?.screenshotExclude!=="true"};try{const c=await r(t,u);if(c)return c}catch{}try{const c=await s(t,u);return c?await(await fetch(c)).blob():null}catch{return null}}async function cr(t){return new Promise(a=>{const r=new FileReader;r.onload=()=>{const s=typeof r.result=="string"?r.result:null;a(s)},r.onerror=()=>a(null),r.readAsDataURL(t)})}function zs(t,a){if(typeof window>"u"||!t)return!1;try{const r=URL.createObjectURL(t),s=document.createElement("a");return s.href=r,s.download=a,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),!0}catch{return!1}}function pr(t){const a=se(t);return Number.isFinite(a)?a:0}function ru(t){return t?pr(t.billable_total_tokens??t.total_tokens):0}function su(t){const a=Array.isArray(t?.weeks)?t.weeks:[];if(!a.length)return{weeks:[],totalDays:0,activeDays:0};let r=0,s=0;return{weeks:a.map(i=>(Array.isArray(i)?i:[]).slice(0,7).map(u=>{const c=!!u?.future,h=Number.isFinite(u?.level)?Math.max(0,Math.min(4,Math.round(u.level))):0;u?.day&&!c&&(r+=1,h>0&&(s+=1));const m=u?.billable_total_tokens??u?.total_tokens??u?.value??0,x=Number.isFinite(m)?Math.max(0,m):0;return{day:typeof u?.day=="string"?u.day:"",level:h,value:x,future:c}})),totalDays:r,activeDays:s}}function nu(t){const{handle:a,startDate:r,activeDays:s,summary:n,topModels:i,rank:o,period:u,periodFrom:c,periodTo:h,heatmap:m,capturedAt:x,currency:g,exchangeRate:p}=t,y=ru(n),k=pr(n?.total_cost_usd),f=Array.isArray(i)?i.slice(0,3).map(w=>({id:w?.id??null,name:typeof w?.name=="string"&&w.name?w.name:"—",tokens:pr(w?.tokens),percent:typeof w?.percent=="string"&&w.percent?w.percent:"0.0"})):[],v=su(m);return{handle:a||"—",startDate:r||null,activeDays:Number.isFinite(s)&&s>0?Math.floor(s):0,totalTokens:y,totalCost:k,period:u,periodFrom:c,periodTo:h,topModels:f,rank:typeof o=="number"&&Number.isFinite(o)&&o>0?Math.floor(o):null,heatmapWeeks:v.weeks,heatmapTotalDays:v.totalDays,heatmapActiveDays:v.activeDays,capturedAt:x||new Date().toISOString(),currency:typeof g=="string"&&g.length>0?g.toUpperCase():"USD",exchangeRate:Number.isFinite(p)&&p>0?p:1}}const ou=["share.month_short.jan","share.month_short.feb","share.month_short.mar","share.month_short.apr","share.month_short.may","share.month_short.jun","share.month_short.jul","share.month_short.aug","share.month_short.sep","share.month_short.oct","share.month_short.nov","share.month_short.dec"];function iu(t){const a=ou[t];return a?l(a):"—"}function Ln(t,a){return l("share.date.month_year",{month:iu(t),year:a})}function lu(t){if(!t)return"—";const a=t.split("-");if(a.length!==3)return t;const[r,s]=a,n=Number(s)-1;return n<0||n>11?t:Ln(n,r)}function cu(t){if(t.period==="total")return l("share.issue.all_time");if(t.period==="day"&&t.periodTo)return t.periodTo.replace(/-/g,".");if(t.period==="custom"&&t.periodFrom&&t.periodTo)return`${t.periodFrom.replace(/-/g,".")} — ${t.periodTo.replace(/-/g,".")}`;if(t.periodTo){const a=new Date(`${t.periodTo}T00:00:00Z`);if(!Number.isNaN(a.getTime()))return Ln(a.getUTCMonth(),a.getUTCFullYear())}return l(`usage.period.${t.period}`)}function yr(t){return Number.isFinite(t)?Math.round(t).toLocaleString("en-US"):"—"}function Mn(t,a={}){const{currency:r="USD",rate:s=1}=a,n=Gt(r);if(!Number.isFinite(t)||t<=0)return`${n}0.00`;const i=r!=="USD"&&Number.isFinite(s)&&s>0?t*s:t;return i>=1e3?`${n}${Math.round(i).toLocaleString("en-US")}`:`${n}${i.toFixed(2)}`}function du(t){const a=t.topModels[0];if(a){const r=parseFloat(a.percent);return Number.isFinite(r)&&r>=60?l("share.hook.top_loyal",{percent:Math.round(r),name:a.name}):t.activeDays>=60?l("share.hook.days_record",{days:t.activeDays}):Number.isFinite(r)&&r>=30?l("share.hook.top_led",{name:a.name,percent:Math.round(r)}):t.topModels.length>1?l("share.hook.multi_models",{count:t.topModels.length,days:t.activeDays}):l("share.hook.days_with_model",{days:t.activeDays,name:a.name})}return t.activeDays>0?l("share.hook.days_record",{days:t.activeDays}):l("share.hook.new_chapter")}function uu(t,a){const r=(t||"").length;if(r<=a.baseChars)return a.baseSize;const s=a.baseSize-(r-a.baseChars)*a.shrinkPerChar;return Math.max(a.minSize,s)}function mu(t){if(!t||t.future)return null;const a=typeof t.level=="number"?t.level:0;return a<0?0:a>4?4:Math.round(a)}function hu({weeks:t,palette:a,width:r,gap:s=3,radius:n=2,emptyColor:i}){if(!Array.isArray(t)||t.length===0||!r||r<=0)return null;const o=a||["#eee","#ccc","#999","#666","#333"],u=i||o[0],c=t.length,h=(c-1)*s,m=Math.max(4,(r-h)/c),x=7*m+6*s;return e.jsx("svg",{width:r,height:x,viewBox:`0 0 ${r} ${x}`,xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,style:{display:"block"},children:t.map((g,p)=>(Array.isArray(g)?g:[]).map((k,f)=>{if(f>=7)return null;const v=mu(k),w=p*(m+s),D=f*(m+s),C=v===null?u:o[v];return e.jsx("rect",{x:w,y:D,width:m,height:m,rx:n,ry:n,fill:C},`${p}-${f}`)}))})}const gu=Tt("oklch(0.97 0.01 85)"),Re=Tt("oklch(0.18 0.02 85)"),tt=Tt("oklch(0.38 0.015 85)"),Os=Tt("oklch(0.55 0.012 85)"),ot=Tt("oklch(0.55 0.22 25)"),it='"Instrument Serif", "Times New Roman", Georgia, serif',xu='"Inter Tight", "Helvetica Neue", Arial, sans-serif',fu=["oklch(0.93 0.013 80)","oklch(0.87 0.04 55)","oklch(0.78 0.09 45)","oklch(0.67 0.16 35)","oklch(0.55 0.22 25)"].map(Tt);function En({data:t}){const a=cu(t),r=yr(t.totalTokens),s=Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate}),n=lu(t.startDate),i=uu(r,{baseSize:188,baseChars:9,shrinkPerChar:14,minSize:104}),o=du(t),u=Array.isArray(t.heatmapWeeks)&&t.heatmapWeeks.length>0;return e.jsxs("div",{style:{width:"100%",height:"100%",background:gu,color:Re,fontFamily:xu,padding:"80px 88px 68px 88px",boxSizing:"border-box",display:"flex",flexDirection:"column",position:"relative"},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,paddingBottom:14,borderBottom:`1px solid ${Os}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,fontSize:14,fontWeight:500,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsx("div",{style:{width:10,height:10,borderRadius:"50%",background:ot}}),"The Token Tracker"]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:tt,textAlign:"right"},children:[l("share.card.broadsheet.issue")," № ",a]})]}),e.jsxs("div",{style:{marginTop:24,display:"flex",justifyContent:"space-between",alignItems:"flex-end",gap:24},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.2em",textTransform:"uppercase",color:tt,marginBottom:6},children:l("share.card.broadsheet.by")}),e.jsx("div",{style:{fontFamily:it,fontSize:52,fontStyle:"italic",lineHeight:1,color:Re,letterSpacing:"-0.01em"},children:t.handle})]}),e.jsxs("div",{style:{fontSize:12,letterSpacing:"0.18em",textTransform:"uppercase",color:tt,textAlign:"right",lineHeight:1.6},children:[l("share.card.broadsheet.tracked_since"),e.jsx("br",{}),e.jsx("span",{style:{color:Re},children:n})]})]}),e.jsxs("div",{style:{marginTop:40,display:"flex",flexDirection:"column"},children:[e.jsx("div",{style:{fontSize:13,letterSpacing:"0.3em",textTransform:"uppercase",color:ot,marginBottom:10},children:l("share.card.broadsheet.total_tokens")}),e.jsx("div",{style:{fontFamily:it,fontSize:i,fontWeight:400,lineHeight:.86,letterSpacing:"-0.032em",color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap",overflow:"hidden"},children:r}),e.jsxs("div",{style:{marginTop:14,fontFamily:it,fontStyle:"italic",fontSize:34,lineHeight:1.15,color:Re,letterSpacing:"-0.005em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:["“",o,"”"]}),e.jsx("div",{style:{marginTop:14,height:1,background:ot,width:"100%"}}),e.jsxs("div",{style:{marginTop:10,display:"flex",justifyContent:"space-between",fontSize:13,letterSpacing:"0.16em",textTransform:"uppercase",color:tt},children:[e.jsxs("span",{children:[l("share.card.broadsheet.estimated_spend")," · ",s]}),e.jsx("span",{children:l("share.card.broadsheet.billable_days",{days:t.activeDays})})]})]}),u?e.jsxs("section",{style:{marginTop:40},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.heatmap_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.heatmap_days_on_record",{active:t.heatmapActiveDays,total:t.heatmapTotalDays})})]}),e.jsx(hu,{weeks:t.heatmapWeeks,palette:fu,width:1024,gap:3,radius:2})]}):null,e.jsxs("section",{style:{marginTop:30,flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",borderBottom:`1px solid ${Re}`,paddingBottom:10,marginBottom:6},children:[e.jsx("div",{style:{fontSize:12,letterSpacing:"0.3em",textTransform:"uppercase",color:Re,fontWeight:600},children:l("share.card.broadsheet.roster_title")}),e.jsx("div",{style:{fontSize:11,letterSpacing:"0.18em",textTransform:"uppercase",color:tt},children:l("share.card.broadsheet.roster_subtitle")})]}),t.topModels.length===0?e.jsx("div",{style:{fontFamily:it,fontStyle:"italic",fontSize:26,color:tt,paddingTop:14},children:l("share.card.broadsheet.empty")}):t.topModels.map((c,h)=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"52px 1fr auto 68px",alignItems:"baseline",gap:16,padding:"13px 0",borderBottom:`1px solid ${Os}`},children:[e.jsx("div",{style:{fontFamily:it,fontSize:34,fontStyle:"italic",color:ot,lineHeight:1},children:String(h+1).padStart(2,"0")}),e.jsx("div",{style:{fontFamily:it,fontSize:32,color:Re,lineHeight:1.1,letterSpacing:"-0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c.name}),e.jsx("div",{style:{fontFamily:it,fontSize:28,color:Re,fontFeatureSettings:'"lnum" 1, "tnum" 1',whiteSpace:"nowrap"},children:yr(c.tokens)}),e.jsxs("div",{style:{fontSize:13,letterSpacing:"0.1em",color:tt,textAlign:"right",fontFeatureSettings:'"tnum" 1'},children:[c.percent,"%"]})]},c.id||c.name))]}),e.jsxs("footer",{style:{marginTop:18,paddingTop:12,borderTop:`1px solid ${Re}`,display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12,letterSpacing:"0.22em",textTransform:"uppercase",color:Re},children:[e.jsxs("div",{style:{display:"flex",gap:28},children:[e.jsxs("span",{children:[l("share.card.broadsheet.global_rank")," ",e.jsxs("span",{style:{color:ot},children:["№ ",t.rank!=null?t.rank:"—"]})]}),e.jsxs("span",{children:[l("share.card.broadsheet.active_days")," ",e.jsx("span",{style:{color:ot},children:l("share.card.broadsheet.days_count",{days:t.activeDays})})]})]}),e.jsxs("div",{children:[l("share.card.broadsheet.track_yours")," ",e.jsx("span",{style:{color:ot},children:"→ tokentracker.cc"})]})]})]})}const pu=Dn["annual-report"].width,yu="#0a0820",at="#ffffffee",lt="rgba(255,255,255,0.45)",dr="#a78bfa",bu={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(40px)",WebkitBackdropFilter:"blur(40px)",border:"1px solid rgba(255,255,255,0.05)",boxShadow:["0 39px 56px -36px rgba(255,255,255,0.10) inset","0 7px 11px -4px rgba(255,255,255,0.06) inset","0 -82px 68px -64px rgba(101,67,149,0.08) inset","0 98px 100px -48px rgba(208,171,255,0.06) inset","0 4px 18px 0 rgba(156,146,215,0.06) inset","0 1px 40px 0 rgba(228,222,255,0.04) inset"].join(", ")},ba={background:"rgba(20,15,50,0.38)",backdropFilter:"blur(32px)",WebkitBackdropFilter:"blur(32px)",border:"1px solid rgba(255,255,255,0.06)",boxShadow:"0 1px 8px 0 rgba(228,222,255,0.06) inset"},br='"Space Grotesk", "Inter Tight", sans-serif',ur='"Inter Tight", sans-serif',ku="rgba(255,255,255,0.06)",In=[ku,"#4a3d8f","#6b5cbe","#9060e0","#d946ef"],Rn=48,Fn=28,Na=4,$n=20,wu=pu-Rn*2-Fn*2,_u=(wu-$n*2)/3,kr=Math.min(Math.floor((_u-Na*6)/7),40),vu=kr*7+Na*6;function ju(t){if(!Array.isArray(t))return t;const a=[];for(const u of t)if(Array.isArray(u))for(const c of u)c?.day&&!c.future&&c.value>0&&a.push(c.value);if(!a.length)return t;a.sort((u,c)=>u-c);const r=u=>{const c=a.length,h=(c-1)*u,m=Math.floor(h);return Math.round((a[m]??0)+((a[Math.min(c-1,m+1)]??0)-(a[m]??0))*(h-m))},s=r(.5),n=r(.75),i=r(.9),o=u=>!u||u<=0?0:u<=s?1:u<=n?2:u<=i?3:4;return t.map(u=>Array.isArray(u)?u.map(c=>c?.day&&!c.future&&typeof c.value=="number"?{...c,level:o(c.value)}:c):u)}function Nu(t){if(!Array.isArray(t))return[];const a={},r=ju(t);for(const s of r)if(Array.isArray(s))for(const n of s){if(!n?.day||n.future)continue;const i=n.day.split("-");if(i.length<2)continue;const o=`${i[0]}-${i[1]}`;(a[o]??=[]).push(n)}return Object.entries(a).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:parseInt(s.split("-")[1],10),cells:n}))}function Su(t){if(!t.length)return[];const a=[...t].sort((o,u)=>o.day.localeCompare(u.day));let r=new Date(`${a[0].day}T00:00:00Z`).getUTCDay();const s=Array(r).fill(null).concat(a),n=[];for(let o=0;o<s.length;o+=7)n.push(s.slice(o,o+7));const i=n[n.length-1];for(;i&&i.length<7;)i.push(null);return n.slice(0,6)}const Cu=["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Tu(t){if(!Array.isArray(t))return 0;const a=[];for(const n of t)if(Array.isArray(n))for(const i of n)i?.day&&!i.future&&a.push(i);a.sort((n,i)=>n.day.localeCompare(i.day));let r=0,s=0;for(const n of a)(n.level||0)>0?(s++,s>r&&(r=s)):s=0;return r}function Us(t){const[a,r]=d.useState(null);return d.useEffect(()=>{if(!t){r(null);return}let s=!1;const n=new Image;return n.crossOrigin="anonymous",n.onload=()=>{if(!s)try{const i=document.createElement("canvas");i.width=n.naturalWidth,i.height=n.naturalHeight,i.getContext("2d").drawImage(n,0,0),r(i.toDataURL("image/png"))}catch{r(null)}},n.onerror=()=>{s||r(null)},n.src=t,()=>{s=!0}},[t]),a}function Au({data:t}){const a=Su(t.cells);return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600,color:lt,fontFamily:br,marginBottom:4},children:Cu[t.month]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:Na},children:a.map((r,s)=>e.jsx("div",{style:{display:"flex",gap:Na},children:r.map((n,i)=>{const o=n?Math.min(4,Math.max(0,n.level||0)):-1;return e.jsx("div",{style:{width:kr,height:kr,borderRadius:4,background:o<0?"transparent":In[o]}},i)})},s))})]})}function Du({data:t}){const a=Nu(t.heatmapWeeks),r=Tu(t.heatmapWeeks),s=t.topModels[0],n=t.avatarUrl||null,i=Us(n),o=Us("/neon_bg.png"),u=(t.handle||"?")[0].toUpperCase(),c=16;return e.jsxs("div",{style:{width:"100%",height:"100%",background:yu,fontFamily:br,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:[e.jsx("img",{src:o||"/neon_bg.png",alt:"",style:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none"}}),e.jsxs("div",{style:{position:"relative",zIndex:1,display:"flex",flexDirection:"column",height:"100%",padding:Rn,boxSizing:"border-box"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:c*3},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:64,height:64,style:{width:64,height:64,borderRadius:16,display:"block"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:20,fontWeight:500,color:lt,lineHeight:1.2},children:"Token Tracker"}),e.jsx("div",{style:{fontSize:36,fontWeight:700,lineHeight:1.15,color:at},children:l("share.card.annual.report_title")})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:"50%",background:"linear-gradient(135deg,#4c1d95,#7c3aed)",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid rgba(255,255,255,0.15)",overflow:"hidden",flexShrink:0},children:i?e.jsx("img",{src:i,alt:"",width:48,height:48,style:{width:48,height:48,objectFit:"cover",display:"block"},crossOrigin:"anonymous",referrerPolicy:"no-referrer"}):e.jsx("span",{style:{fontSize:20,fontWeight:700,color:at},children:u})}),e.jsx("div",{style:{fontSize:32,fontWeight:700,color:at},children:t.handle})]})]}),e.jsxs("div",{style:{...bu,borderRadius:22,padding:Fn,marginBottom:c},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:14,color:lt},children:[e.jsx("span",{children:l("share.card.annual.less")}),In.map((h,m)=>e.jsx("div",{style:{width:16,height:16,borderRadius:3,background:h}},m)),e.jsx("span",{children:l("share.card.annual.more")})]}),e.jsx("div",{style:{fontSize:16,fontWeight:700,letterSpacing:"0.14em",color:"rgba(255,255,255,0.22)",textTransform:"uppercase"},children:l("share.card.annual.heatmap_title")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:`repeat(3,${vu}px)`,gap:`8px ${$n}px`,justifyContent:"center"},children:a.map(h=>e.jsx(Au,{data:h},h.month))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:c,marginBottom:c},children:[e.jsxs("div",{style:{...ba,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:yr(t.totalTokens)}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.total_tokens")})]}),e.jsxs("div",{style:{...ba,borderRadius:22,padding:"28px 16px",textAlign:"center"},children:[e.jsx("div",{style:{fontFamily:ur,fontSize:52,fontWeight:700,color:at,letterSpacing:"-0.02em",lineHeight:1},children:Mn(t.totalCost,{currency:t.currency,rate:t.exchangeRate})}),e.jsx("div",{style:{fontSize:22,color:lt,marginTop:12},children:l("share.card.annual.estimated_cost")})]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:c},children:[e.jsxs("div",{style:{...ba,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:dr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48 2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48 2.83-2.83"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.longest_streak")})]}),e.jsx("span",{style:{fontFamily:ur,fontSize:28,fontWeight:700,color:at},children:l("share.card.annual.days_count",{days:r})})]}),e.jsxs("div",{style:{...ba,borderRadius:22,padding:"18px 24px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:dr,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("circle",{cx:"12",cy:"12",r:"4"})]}),e.jsx("span",{style:{fontSize:20,color:lt},children:l("share.card.annual.top_model")})]}),e.jsx("span",{style:{fontFamily:br,fontSize:28,fontWeight:700,color:at},children:s?s.name:"—"})]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"auto"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("img",{src:"/app-icon.png",alt:"",width:44,height:44,style:{width:44,height:44,borderRadius:8,display:"block"}}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:at},children:"Token Tracker"})]}),e.jsx("span",{style:{fontSize:22,fontWeight:600,color:dr},children:"tokentracker.cc"})]})]})]})}const Pn=[{id:"annual-report",labelKey:"share.variant.neon"},{id:"broadsheet",labelKey:"share.variant.broadsheet"}],Lu={broadsheet:En,"annual-report":Du};function Bn(t){return Dn[t]||{width:Tn,height:An}}function Mu(t){const a=Pn.find(r=>r.id===t);return a?.labelKey?l(a.labelKey):t}const Hs=d.forwardRef(function({data:a,variant:r},s){const n=Lu[r]||En,{width:i,height:o}=Bn(r);return e.jsx("div",{ref:s,"data-share-card":"true",style:{width:i,height:o,position:"relative",overflow:"hidden",boxSizing:"border-box"},children:e.jsx(n,{data:a})})});function ka(){return typeof window>"u"?!1:!!window?.webkit?.messageHandlers?.nativeBridge}const Eu=440;function Iu(){const[t,a]=d.useState(null),r=d.useRef(null),s=d.useCallback((n,i="info")=>{r.current&&window.clearTimeout(r.current),a({id:Date.now(),kind:i,text:n}),r.current=window.setTimeout(()=>a(null),2800)},[]);return d.useEffect(()=>()=>{r.current&&window.clearTimeout(r.current)},[]),{toast:t,push:s}}function mr({onClick:t,disabled:a,children:r,emphasis:s,ariaLabel:n}){return e.jsx("button",{type:"button",onClick:t,disabled:a,"aria-label":n,className:["group relative flex items-center justify-between gap-3 w-full px-4 py-3 text-left","rounded-lg border transition-colors",s?"border-oai-black dark:border-oai-white bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black hover:opacity-90":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white hover:border-oai-gray-400 dark:hover:border-oai-gray-600",a?"opacity-60 cursor-not-allowed":"cursor-pointer"].join(" "),children:r})}function Ru({open:t,onClose:a,data:r,twitterText:s}){const[n,i]=d.useState(null),[o,u]=d.useState(""),[c,h]=d.useState("annual-report"),m=d.useRef(null),{toast:x,push:g}=Iu(),p=Js(),y=d.useMemo(()=>{const N=p?.user;if(!N||typeof N!="object")return null;const j=N.user_metadata||{},S=N.profile||{},E=j.avatar_url||j.picture||S.avatar_url||N.avatar_url;return typeof E=="string"&&E.trim()?E.trim():null},[p?.user]);d.useEffect(()=>{t&&(i(null),u(r?.handle||""))},[t,r?.handle]);const k=r&&{...r,handle:o||r.handle,avatarUrl:y},{width:f,height:v}=Bn(c),w=Eu/f;d.useEffect(()=>{if(!t)return;const N=j=>{j.key==="Escape"&&a?.()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,a]);const D=d.useCallback(async()=>{const N=m.current;if(!N)return null;try{return await au(N)}catch(j){return console.warn("[share] capture failed",j),null}},[]),C=d.useCallback(async()=>{if(n)return;i("copy");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}let j=!1;if(ka()){const S=await cr(N);S&&(j=(await Qd(S)).ok)}else j=await Zr(N);g(j?l("share.toast.copied"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,g]),R=d.useCallback(()=>`tokentracker-share-${Date.now()}.png`,[]),A=d.useCallback(async()=>{if(n)return;i("download");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}if(ka()){const S=await cr(N);if(S&&(await Bs(S,R())).ok){g(l("share.toast.downloaded"),"success"),i(null);return}}const j=zs(N,R());g(j?l("share.toast.downloaded"):l("share.toast.failed"),j?"success":"error"),i(null)},[n,D,R,g]),P=d.useCallback(async()=>{if(n)return;i("x");const N=await D();if(!N){g(l("share.toast.failed"),"error"),i(null);return}if(ka()){const O=await cr(N);O&&(await Bs(O,R()),g(l("share.toast.downloaded"),"success"))}else await Zr(N)?g(l("share.toast.copied"),"success"):zs(N,R());const j=new URL("https://twitter.com/intent/tweet");s&&j.searchParams.set("text",s);const S=p?.user?.id,E=typeof S=="string"&&S?`/u/${S}`:"/";if(j.searchParams.set("url",`https://www.tokentracker.cc${E}?ref=share`),ka())try{window.webkit?.messageHandlers?.nativeBridge?.postMessage({type:"action",name:"openURL",value:j.toString()})}catch{window.open(j.toString(),"_blank","noopener,noreferrer")}else window.open(j.toString(),"_blank","noopener,noreferrer");i(null)},[n,D,g,s,R,p]);return t?e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":l("share.modal.title"),"data-screenshot-exclude":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 sm:p-6",style:{background:"rgba(10,10,10,0.72)"},onClick:N=>{N.target===N.currentTarget&&a?.()},children:[e.jsx("div",{"aria-hidden":!0,style:{position:"fixed",left:0,top:0,width:f,height:v,pointerEvents:"none",opacity:0,zIndex:-1,clip:"rect(0,0,0,0)",overflow:"hidden"},children:e.jsx(Hs,{ref:m,data:k,variant:c})}),e.jsxs(ve.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:12},transition:{duration:.18,ease:[.2,.8,.2,1]},className:"relative w-full max-w-[1040px] max-h-[92vh] overflow-hidden rounded-2xl border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-black shadow-oai-lg",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row max-h-[92vh]",children:[e.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-7 bg-oai-gray-50 dark:bg-oai-gray-950 flex items-center justify-center overflow-auto",children:e.jsxs("div",{style:{width:f*w,height:v*w,flexShrink:0,position:"relative"},className:"rounded-xl overflow-hidden shadow-oai-md ring-1 ring-black/5",children:[n?e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-white/70 dark:bg-black/50",children:e.jsxs("svg",{className:"animate-spin h-6 w-6 text-oai-gray-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):null,e.jsx("div",{style:{width:f,height:v,transform:`scale(${w})`,transformOrigin:"top left"},children:e.jsx(Hs,{data:k,variant:c})})]})}),e.jsxs("div",{className:"w-full lg:w-[340px] flex-shrink-0 border-t lg:border-t-0 lg:border-l border-oai-gray-200 dark:border-oai-gray-800 p-5 sm:p-6 flex flex-col gap-5 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-oai-black dark:text-oai-white",children:l("share.modal.title")}),e.jsx("p",{className:"mt-1 text-xs text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.subtitle")})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":l("share.modal.close"),className:"p-1.5 -mt-1 -mr-1 rounded-md text-oai-gray-500 hover:text-oai-black dark:hover:text-oai-white hover:bg-oai-gray-100 dark:hover:bg-oai-gray-800 transition-colors",children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"share-handle",className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.name_label")}),e.jsx("input",{id:"share-handle",type:"text",value:o,onChange:N=>u(N.target.value),placeholder:l("share.modal.name_placeholder"),className:"w-full px-3 py-2 text-sm rounded-lg border border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white placeholder:text-oai-gray-400 dark:placeholder:text-oai-gray-600 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-oai-brand transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] tracking-[0.18em] uppercase text-oai-gray-500 dark:text-oai-gray-400 mb-1.5 block",children:l("share.modal.style_label")}),e.jsx("div",{className:"flex gap-2",children:Pn.map(N=>e.jsx("button",{type:"button",onClick:()=>h(N.id),className:["flex-1 px-3 py-2 text-sm rounded-lg border transition-colors",c===N.id?"border-oai-black dark:border-oai-white bg-white dark:bg-oai-gray-900 text-oai-black dark:text-oai-white font-medium":"border-oai-gray-200 dark:border-oai-gray-800 bg-white dark:bg-oai-gray-900 text-oai-gray-500 dark:text-oai-gray-400 hover:border-oai-gray-400 dark:hover:border-oai-gray-600"].join(" "),children:Mu(N.id)},N.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs(mr,{onClick:P,disabled:!!n,emphasis:!0,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:e.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.x")})]}),e.jsx("span",{className:"text-[11px] opacity-70",children:n==="x"?l("share.toast.working"):l("share.modal.hint.x")})]}),e.jsxs(mr,{onClick:A,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.download")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:"PNG"})]}),e.jsxs(mr,{onClick:C,disabled:!!n,children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),e.jsx("span",{className:"font-medium text-sm",children:l("share.modal.action.copy")})]}),e.jsx("span",{className:"text-[11px] text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.hint.copy")})]})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-oai-gray-200 dark:border-oai-gray-800",children:e.jsx("p",{className:"text-[11px] leading-relaxed text-oai-gray-500 dark:text-oai-gray-400",children:l("share.modal.footer")})})]})]}),e.jsx(Ta,{children:x?e.jsx(ve.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},className:"pointer-events-none absolute left-1/2 bottom-4 -translate-x-1/2",children:e.jsx("div",{className:["px-4 py-2 rounded-full text-xs font-medium shadow-oai-md",x.kind==="error"?"bg-red-600 text-white":x.kind==="success"?"bg-oai-black dark:bg-oai-white text-oai-white dark:text-oai-black":"bg-oai-gray-800 text-white"].join(" "),children:x.text})},x.id):null})]})]}):null}function Fu(t){const{enabled:a,handle:r,startDate:s,activeDays:n,summary:i,topModels:o,period:u,periodFrom:c,periodTo:h,heatmap:m,accessToken:x,userId:g,currency:p,exchangeRate:y}=t,[k,f]=d.useState(null),v=y;return d.useEffect(()=>{if(!a||!g&&!ut())return;let w=!1;return(async()=>{try{const C=await bi({accessToken:x,userId:g,period:u==="day"||u==="custom"?"week":u,metric:"all",limit:100,offset:0});if(w)return;const A=(Array.isArray(C?.entries)?C.entries:Array.isArray(C)?C:[]).find(N=>N?.is_me===!0),P=typeof A?.rank=="number"?A.rank:null;f(P)}catch{w||f(null)}})(),()=>{w=!0}},[a,x,g,u]),d.useMemo(()=>nu({handle:r,startDate:s,activeDays:n,summary:i,topModels:o,rank:k,period:u,periodFrom:c,periodTo:h,heatmap:m,currency:p,exchangeRate:typeof v=="number"?v:void 0}),[r,s,n,i,o,k,u,c,h,m,p,v])}function Vs(t,a,r){const s=t?.current;if(s&&Object.is(s.key,a))return s.promise;const n=Promise.resolve().then(r),i={key:a,promise:n};t.current=i;const o=()=>{t.current===i&&(t.current=null)};return n.then(o,o),n}const $u=Object.freeze({auto:!0,background:!0,allLocalSources:!0});async function Pu({refreshUsageStats:t,refreshUsageLimits:a}){const r=t();a(),await r}const Bu=["day","week","month","total","custom"],hr=new Set(["day","hour","month"]),Vt=new Set(["day","total","custom"]),zu=["islandOnboarding","macAppBanner","statsPanel","widgetOnboarding","installCopy","activityHeatmap","deviceUsage","trendMonitor","qualityPerDollar","sessionInsights"],Ou=["usageOverview","dataDetails"];function gr(t,a){if(typeof a=="number"&&a>0)return!0;if(typeof t=="bigint")return t>0n;if(typeof t=="number")return Number.isFinite(t)&&t>0;if(typeof t=="string"){const r=t.trim();if(!r)return!1;if(/^[0-9]+$/.test(r))try{return BigInt(r)>0n}catch{return!1}const s=Number(r);return Number.isFinite(s)&&s>0}return!1}function wa(t){return t?Nt(t,null):null}function Ks(t){return t?t?.billable_total_tokens??t?.value??t?.total_tokens:null}function Uu(t){return t?t==="www.tokentracker.cc"||t==="tokentracker.cc":!1}function Hu(){if(typeof window>"u")return!1;const t=new URLSearchParams(window.location.search),a=String(t.get("force_install")||"").toLowerCase();return a!=="1"&&a!=="true"?!1:!Uu(window.location.hostname)}function Am({baseUrl:t,auth:a,signedIn:r,sessionSoftExpired:s,signOut:n,publicMode:i=!1,publicToken:o=null,signInUrl:u="/sign-in",signUpUrl:c="/sign-up",onMainContentVisible:h}){const{resolvedLocale:m}=ki(),{currency:x,rate:g}=Ca(),{mode:p,setMode:y,formatTokens:k,formatTokensTooltip:f}=Fe(),[v,w]=d.useState(!1),[D,C]=d.useState(null),[R,A]=d.useState(null),[P,N]=d.useState(!1),[j,S]=d.useState(null),[E,O]=d.useState(0),[F,L]=d.useState(0),[B,K]=d.useState(null),q=d.useMemo(()=>typeof window>"u"?!1:wi(window.location.search),[]),_=d.useMemo(()=>Hu(),[]),[$,H]=d.useState(!1),te=2200,[ue,W]=d.useState(!0),[ne,oe]=d.useState(!1),[je,be]=d.useState(!1),[Le,X]=d.useState(!1),[U,re]=d.useState(!1),ee=d.useRef(!1),ae=ut(),ye=r&&!s,Y=d.useMemo(()=>ye&&(typeof a=="function"||typeof a=="string"||a&&typeof a=="object")?a:null,[a,ye]),J=ye?Y:null,Z=i?_i(o):J,ge=r||ae||i,$e=ye&&Yt(J),me=r&&s&&!i,{accountView:T,revision:z,resolving:he}=vi(),V=T&&!i,de=V?J:null,Ce=he&&!i;d.useEffect(()=>{if(!r||ae){C(null),A(null),N(!1),S(null);return}if(i)return;if(!$e){C(null),A(null),N(!1),S(null);return}let b=!0;const I=()=>{C(null),A(null),N(!1),S(null)};return N(!0),S(null),(async()=>{let M=null;try{M=await Oe(J)}catch{M=null}if(b){if(!M){I();return}try{const G={link_code:null,expires_at:null};if(!b)return;C(typeof G?.link_code=="string"?G.link_code:null),A(typeof G?.expires_at=="string"?G.expires_at:null)}catch(G){if(!b)return;C(null),A(null),S(G?.message||"Failed to load link code")}finally{if(!b)return;N(!1)}}})(),()=>{b=!1}},[t,ae,r,i,$e,J,F]);const Ne=typeof window<"u"&&(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1");d.useEffect(()=>{if(!Ne&&(!r||ae||i)){K(null);return}if(!Ne&&!$e){K(null);return}let b=!0;return(async()=>{let I=null;try{I=await Oe(J)}catch{I=null}if(b){if(!I&&!Ne){K(null);return}try{const M=await ji({baseUrl:t,accessToken:I});if(!b)return;K(M&&typeof M=="object"?M:null)}catch{if(!b)return;K(null)}}})(),()=>{b=!1}},[$e,t,J,ae,i,r]);const At=d.useMemo(()=>{if(!R)return!1;const b=Date.parse(R);if(!Number.isFinite(b))return!1;const I=E||Date.now();return b<=I},[R,E]);d.useEffect(()=>{!r||ae||i||!R||!At||P||(C(null),A(null),S(null),L(b=>b+1))},[At,R,P,ae,r]),d.useEffect(()=>{if(!R||i)return;const b=Date.parse(R);if(!Number.isFinite(b))return;const I=Date.now();if(O(I),b<=I)return;const M=window.setTimeout(()=>O(Date.now()),b-I),G=()=>{typeof document>"u"||document.visibilityState==="visible"&&O(Date.now())};return typeof document<"u"&&document.addEventListener("visibilitychange",G),window.addEventListener("focus",G),()=>{window.clearTimeout(M),typeof document<"u"&&document.removeEventListener("visibilitychange",G),window.removeEventListener("focus",G)}},[R]);const fe=d.useMemo(()=>Zs(),[]),pe=d.useMemo(()=>Ys(),[]),Pe=d.useMemo(()=>Ni(),[]),Be=i?null:a?.userId||a?.email||"default",[Dt,mt]=d.useState("month"),[Ve,Aa]=d.useState(null),[Xe,Da]=d.useState(null),[La,ht]=d.useState(!1),Q=q?"total":Dt,Zt=d.useMemo(()=>Q==="custom"&&Ve&&Xe?{from:Ve,to:Xe}:Si(Q,{timeZone:fe,offsetMinutes:pe,now:Pe}),[Pe,Q,fe,pe,Ve,Xe]),ke=Zt.from,we=Zt.to,[Te,gt]=d.useState(null),[Lt,Jt]=d.useState(()=>Jr());d.useEffect(()=>{const b=()=>Jt(Jr());return window.addEventListener(Qr,b),window.addEventListener("storage",b),()=>{window.removeEventListener(Qr,b),window.removeEventListener("storage",b)}},[]);const{devices:Qt,accountSources:Mt,refresh:Ma}=Yd({from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe,accountView:V,accountAccessToken:de,accountRevision:z}),Ke=d.useMemo(()=>Qt.filter(b=>(Number(b.total_tokens)||0)>0).map(b=>({...b,isCurrent:b.id===Lt})),[Qt,Lt]),Xt=d.useMemo(()=>Mt.filter(b=>(Number(b.total_tokens)||0)>0),[Mt]),rt=V&&Ke.length>=2,Et=V&&Ke.length+Xt.length>=2;d.useEffect(()=>{if(!rt&&!Et){Te!==null&>(null);return}Te&&!Ke.some(b=>b.id===Te)&>(null)},[rt,Et,Ke,Te]);const Ea=d.useMemo(()=>rt?[{value:"",label:l("dashboard.device_filter.all")},...Ke.map(b=>{const I=fr(b)||l("dashboard.device_card.unnamed"),M=b.isCurrent?` (${l("dashboard.device_card.current")})`:"";return{value:b.id,label:`${I}${M}`}})]:[],[rt,Ke,m]),ea=Et?e.jsx(Jd,{devices:Ke,accountSources:Xt,currentDeviceId:Lt,selectedDeviceId:Te||"",onSelectDevice:b=>gt(b||null),onRenameDevice:async(b,I)=>{const M=await Oe(de);await Mi({deviceId:b,name:I,accessToken:M}),await Ma()}}):null,ta=d.useMemo(()=>Ci({timeZone:fe,offsetMinutes:pe}),[fe,pe]),It=d.useMemo(()=>Ti({timeZone:fe,offsetMinutes:pe}),[fe,pe]),Ia=d.useMemo(()=>`Local time (${It})`,[It]),Rt=fe,Ft=pe,Ra=ta,qe=d.useMemo(()=>vr({timeZone:fe,offsetMinutes:pe,date:Pe||new Date}),[Pe,fe,pe]),aa=d.useMemo(()=>gc({period:Q,selectedFrom:ke,selectedTo:we,todayKey:qe}),[ke,Q,we,qe]),{daily:We,summary:xe,rolling:Fa,source:$t,loading:ra,error:$a,refresh:ce}=ls({baseUrl:t,accessToken:Z,guestAllowed:me,from:ke,to:we,includeDaily:Q!=="total",cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{daily:ie,loading:Se,refresh:et}=ls({baseUrl:t,accessToken:Z,guestAllowed:me,from:aa.from,to:aa.to,includeDaily:!0,includeSummary:!1,cacheKey:Be?`${Be}.daily-breakdown`:"daily-breakdown",timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{breakdown:Ae,loading:xt,refresh:Tr}=ql({baseUrl:t,accessToken:Z,guestAllowed:me,from:ke,to:we,cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),[zn,On]=d.useState(3),{entries:Un,loading:Hn,refresh:Ar}=Kl({baseUrl:t,accessToken:Z,from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe}),Dr=Q==="week"||Q==="month",sa=Q==="week"||Q==="month",Lr=d.useMemo(()=>We.filter(b=>b?.future?!1:!b?.day||!qe?!0:String(b.day)<=String(qe)),[We,qe]),{rows:Ye,from:Vn,to:Kn,loading:Wn,refresh:Mr}=Fi({baseUrl:t,accessToken:Z,guestAllowed:me,period:Q,from:ke,to:we,months:24,cacheKey:Be,timeZone:Rt,tzOffsetMinutes:Ft,now:Pe,sharedRows:Dr?We:null,sharedRange:Dr?{from:ke,to:we}:null,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),Gn=d.useMemo(()=>({baseUrl:t,accessToken:Z,guestAllowed:me,cacheKey:Be,timeZone:Rt,tzOffsetMinutes:Ft,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce}),[t,Z,me,Be,Rt,Ft,Pe,V,de,z,Ce]),{daily:ft,heatmap:Ge,loading:Er,refresh:Ir}=zl({baseUrl:t,accessToken:Z,guestAllowed:me,weeks:52,cacheKey:Be,timeZone:fe,tzOffsetMinutes:pe,now:Pe,accountView:V,accountAccessToken:de,accountRevision:z,accountViewResolving:Ce,deviceId:Te}),{data:na,refresh:Rr}=$i();d.useEffect(()=>{na&&typeof na=="object"&&Ai(na)},[na]);const Ue=d.useMemo(()=>Q==="day"?"hour":Q==="total"?"month":"day",[Q]),qn=d.useMemo(()=>ds(Ue),[Ue]),oa="day",Yn=d.useMemo(()=>ds(oa),[]),[He,Fr]=d.useState(()=>({key:"day",dir:"desc"}));d.useEffect(()=>{Fr(b=>!hr.has(b.key)||b.key===Ue?b:{key:Ue,dir:b.dir})},[Ue]);const pt=d.useMemo(()=>hr.has(He.key)&&He.key!==Ue?{...He,key:Ue}:He,[Ue,He]),ia=d.useMemo(()=>{if(Q==="day")return Array.isArray(Ye)?Ye.filter(M=>M?.hour&&!M?.future):[];if(Q==="total"){const M=Array.isArray(Ye)?Ye.filter(G=>G?.month&&!G?.future):[];return ic(M)}const b=Lr;return!b.some(M=>!M?.missing&&!M?.future)&&We.length>0?We.filter(M=>!M?.future).slice(-30).filter(M=>M?.day):b},[Q,Ye,Lr,We]),Pt=d.useMemo(()=>us(ia,pt),[ia,pt]),$r=d.useMemo(()=>ia.some(b=>!b?.missing&&!b?.future),[ia]),Pa=d.useMemo(()=>{if(!Vt.has(Q))return 1;const b=Math.ceil(Pt.length/ja);return b>0?b:1},[Q,Pt.length]),[Ba,la]=d.useState(0);d.useEffect(()=>{if(!Vt.has(Q)){la(0);return}la(b=>Math.min(b,Pa-1))},[Pa,Q]),d.useEffect(()=>{Vt.has(Q)&&la(0)},[Q,He.dir,He.key]);const Zn=d.useMemo(()=>Vt.has(Q)?lc(Pt,Ba,ja):Pt,[Ba,Q,Pt]),Pr=d.useMemo(()=>xc(ie,{period:Q}),[ie,Q]),yt=d.useMemo(()=>hr.has(He.key)?{...He,key:oa}:He,[He]),Jn=d.useMemo(()=>us(Pr,yt),[Pr,yt]),Qn=d.useMemo(()=>sa?We:Q==="day"?Array.isArray(Ye)?Ye.filter(b=>b?.hour):[]:Ye,[We,Q,Ye,sa]),Xn=sa?ke:Vn,eo=sa?we:Kn;function to(b,I){if(b?.future)return"—";if(b?.missing)return l("shared.status.unsynced");if(I.endsWith("_tokens")){const M=I==="total_tokens"?wa(b):b?.[I];return e.jsx("span",{title:f(M),children:k(M)})}return va(b?.[I])}function ao(b){const I=b?.[Ue];if(I==null)return"";const M=String(I);if(Ue==="hour"){const[G,Ee]=M.split("T");if(G&&Ee)return`${G} ${Ee.slice(0,5)}`}return M}function ro(b){const I=b?.[oa];return I==null?"":String(I)}function so(b){Fr(I=>I.key===b?{key:b,dir:I.dir==="asc"?"desc":"asc"}:{key:b,dir:"desc"})}function no(b){return pt.key!==b?"none":pt.dir==="asc"?"ascending":"descending"}function oo(b){return pt.key!==b?"":pt.dir==="asc"?"▲":"▼"}function io(b){return yt.key!==b?"none":yt.dir==="asc"?"ascending":"descending"}function lo(b){return yt.key!==b?"":yt.dir==="asc"?"▲":"▼"}const za=d.useMemo(()=>{if(!r&&!ae&&!i&&!Ne)return 0;const b=Number(Ge?.active_days);if(Number.isFinite(b))return b;let I=0;const M=new Set,G=(_e,ze,Ie)=>{typeof _e!="string"||!_e||M.has(_e)||gr(ze,Ie)&&(M.add(_e),I+=1)};if(Array.isArray(ft))for(const _e of ft)G(_e?.day,wa(_e));const Ee=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const _e of Ee)for(const ze of Array.isArray(_e)?_e:[]){const Ie=Ks(ze);G(ze?.day,Ie,ze?.level)}return I},[r,ae,Ge?.active_days,Ge?.weeks,ft]),[Br,zr]=d.useState("month"),co=d.useCallback(b=>{b==="custom"?(zr(I=>I==="custom"?"month":I),mt(I=>Ve&&Xe?"custom":I),ht(!0)):(mt(b),zr(b),ht(!1))},[Ve,Xe]),uo=d.useCallback((b,I)=>{Aa(b),Da(I),mt("custom"),ht(!1)},[]),mo=d.useCallback(b=>{ht(b),!b&&Dt==="custom"&&!Ve&&mt(Br)},[Dt,Ve,Br]),ho=d.useRef(null),ca=d.useMemo(()=>[t||"",Be||"",V?"cloud":"local",z??"",Q||"",ke||"",we||"",qe||"",Te||"all",fe||"",pe??""].join(""),[z,V,t,Be,ke,Q,Te,fe,qe,we,pe]),Bt=d.useCallback(async()=>Vs(ho,ca,async()=>{V&&Di(),V||Li(),await Promise.all([ce(),Ir(),Mr(),Tr(),Ar(),et()])}),[V,et,Ir,Tr,Ar,Mr,ce,ca]),go=d.useRef(null),Or=d.useCallback(async()=>Vs(go,ca,async()=>{await Pu({refreshUsageStats:Bt,refreshUsageLimits:Rr})}),[ca,Rr,Bt]),Oa=d.useRef(Bt);d.useEffect(()=>{Oa.current=Bt},[Bt]);const Ua=d.useRef(null);d.useEffect(()=>{if(!Ne||ae||V)return;Ua.current||(Ua.current=Xr({auto:!0,background:!0,allLocalSources:!0}));let b=!0;return Ua.current.then(()=>{if(b)return Oa.current()}).catch(I=>{b&&console.warn("[DashboardPage] Reload sync failed:",I)}),()=>{b=!1}},[Ne,ae,V]),d.useEffect(()=>{if(!Ne||ae||V)return;const b=mc({refresh:()=>Oa.current(),onError:I=>console.warn("[DashboardPage] Automatic usage refresh failed:",I)});return()=>b.stop()},[Ne,ae,V]);const xo=d.useCallback(async()=>{X(!0);try{Ne&&await Xr($u),await Or()}catch(b){console.error("[DashboardPage] Refresh failed:",b)}finally{X(!1)}},[Ne,Or]),da=Le||ra||Se||Er||Wn||xt||Hn,Ha=!U&&(Ce||V&&da&&!$r),fo=d.useMemo(()=>l("shared.data_source",{source:String($t||"edge").toUpperCase()}),[$t,m]),ua=d.useMemo(()=>typeof a?.name!="string"?"":a.name.trim(),[a?.name]),po="",Ur=d.useMemo(()=>!ua||ua.includes("@")?l("dashboard.identity.fallback"):ua,[ua]),Hr=d.useMemo(()=>Ur.replace(/[^a-zA-Z0-9._-]/g,"_"),[Ur]),Vr=d.useMemo(()=>i?l("dashboard.identity.fallback"):Hr,[Hr,po,i]),Kr=d.useMemo(()=>{let b=null;const I=G=>{typeof G!="string"||!G||(!b||G<b)&&(b=G)};if(Array.isArray(ft))for(const G of ft)G?.day&&gr(wa(G))&&I(G.day);const M=Array.isArray(Ge?.weeks)?Ge.weeks:[];for(const G of M)for(const Ee of Array.isArray(G)?G:[]){if(!Ee?.day)continue;const _e=Ks(Ee),ze=Ee?.level;gr(_e,ze)&&I(Ee.day)}return b},[Ge?.weeks,ft]),yo=d.useMemo(()=>i?[]:(Array.isArray(B?.subscriptions?.items)?B.subscriptions.items:[]).map(M=>{const G=typeof M?.tool=="string"?M.tool.trim():"",_e=(typeof M?.plan_type=="string"?M.plan_type:typeof M?.planType=="string"?M.planType:"").trim();return!G||!_e?null:{tool:G,planType:_e,provider:typeof M?.provider=="string"?M.provider.trim():"",product:typeof M?.product=="string"?M.product.trim():"",rateLimitTier:typeof M?.rate_limit_tier=="string"?M.rate_limit_tier.trim():typeof M?.rateLimitTier=="string"?M.rateLimitTier.trim():""}}).filter(Boolean).slice(0,6),[i,B]),bo=e.jsx(Pi,{heatmap:Ge,timeZoneLabel:ta,timeZoneShortLabel:It,hideLegend:q,defaultToLatestMonth:q}),ko=d.useMemo(()=>`${ke}..${we}`,[ke,Q,we]),wo=l("usage.summary.total"),Me=xe!=null,bt=Me?wa(xe):0,_o=k(bt),vo=d.useCallback(()=>{y(p===Kt.COMPACT?Kt.FULL:Kt.COMPACT)},[y,p]),jo=l("dashboard.core_index.collapse_label"),No=l("dashboard.core_index.expand_label"),So=l("dashboard.core_index.collapse_aria"),Co=l("dashboard.core_index.expand_aria"),To=!q,kt=l("shared.placeholder.short"),Va=d.useMemo(()=>{const b=Array.isArray(Ae?.sources)?Ae.sources:[];let I=null,M=0;for(const ze of b){const Ie=Nt(ze?.totals);!Number.isFinite(Ie)||Ie<=0||Ie>M&&(M=Ie,I=ze)}let G=kt,Ee=kt,_e="0.0";if(I&&M>0){G=I?.source?String(I.source).toUpperCase():kt;const ze=Array.isArray(I?.models)?I.models:[];let Ie=0;for(const Za of ze){const ha=Nt(Za?.totals);!Number.isFinite(ha)||ha<=0||ha>Ie&&(Ie=ha,Ee=Za?.model?String(Za.model):kt)}Ie>0&&(_e=(Ie/M*100).toFixed(1))}return{agentName:G,modelName:Ee,modelPercent:_e}},[Ae,kt]),Ka=va(bt),Ao=l("dashboard.screenshot.twitter_text",{total_tokens:Ka==="-"?kt:Ka,agent_name:Va.agentName,model_name:Va.modelName,model_percent:Va.modelPercent}),Do=d.useMemo(()=>q?[]:Bu,[q]),Lo=d.useMemo(()=>[{label:l("usage.metric.total"),value:Me?k(bt):"—",title:Me?f(bt):void 0,valueClassName:"text-white"},{label:l("usage.metric.input"),value:Me?k(xe?.input_tokens):"—",title:Me?f(xe?.input_tokens):void 0},{label:l("usage.metric.output"),value:Me?k(xe?.output_tokens):"—",title:Me?f(xe?.output_tokens):void 0},{label:l("usage.metric.cached_input"),value:Me?k(xe?.cached_input_tokens):"—",title:Me?f(xe?.cached_input_tokens):void 0},{label:l("usage.metric.reasoning_output"),value:Me?k(xe?.reasoning_output_tokens):"—",title:Me?f(xe?.reasoning_output_tokens):void 0}],[xe?.cached_input_tokens,xe?.input_tokens,xe?.output_tokens,xe?.reasoning_output_tokens,bt,Me,k,f]),Wa=d.useMemo(()=>Sa(xe?.total_cost_usd,{currency:x,rate:g}),[xe?.total_cost_usd,x,g]),Mo=d.useMemo(()=>xe?.conversation_count??null,[xe?.conversation_count]),Wr=d.useMemo(()=>wc(Ae,{copyFn:l}),[Ae]),Gr=d.useMemo(()=>vc(Ae,{limit:3,copyFn:l}),[Ae]),Eo=Fu({enabled:$,handle:Vr,startDate:Kr,activeDays:za,summary:xe,topModels:Gr,period:Q,periodFrom:ke,periodTo:we,heatmap:Ge,accessToken:typeof Z=="string"?Z:null,userId:a?.userId||null,currency:x,exchangeRate:g}),Io=d.useCallback(()=>H(!0),[]),Ro=d.useCallback(()=>H(!1),[]),Fo=d.useCallback(()=>w(!0),[]),$o=d.useCallback(()=>w(!1),[]),Po=Wa&&Wa!=="-"&&Wr.length>0,zt=l("dashboard.install.cmd.init"),Ga=At?null:D,qa=Ga?l("dashboard.install.cmd.init_link_code",{link_code:Ga}):zt,Bo=zt,zo=l("dashboard.install.cmd.sync"),Oo=Ga?l("dashboard.install.copy"):l("dashboard.install.copy_base"),Uo=l("dashboard.install.copied");l("dashboard.session_expired.copy_label"),l("dashboard.session_expired.copied");const Ho=!!(B?.install?.has_active_device_token??B?.install?.hasActiveDeviceToken),Vo=cc({publicMode:i,screenshotMode:q,forceInstall:_,accessEnabled:ge,heatmapLoading:Er,activeDays:za,hasActiveDeviceToken:Ho}),Ko=l("dashboard.install.prompt"),Wo=d.useCallback(async()=>{!qa||!await es(qa)||(oe(!0),window.setTimeout(()=>oe(!1),2e3))},[qa]);d.useCallback(async()=>{!zt||!await es(zt)||(be(!0),window.setTimeout(()=>be(!1),2e3))},[zt]);const Ya=d.useMemo(()=>l("dashboard.daily.empty",{cmd:"{{cmd}}"}),[m]),[Go,qo]=d.useMemo(()=>{const b=Ya.split("{{cmd}}");return b.length===1?[Ya,""]:[b[0],b.slice(1).join("{{cmd}}")]},[Ya]),Ot=s&&!i,Ut=!r&&!ae&&!s&&!Ne&&!i;d.useEffect(()=>{Ot||Ut||Ha||re(!0)},[Ha,Ut,Ot]);const ma=Hl(zu,Ou);return d.useEffect(()=>{ee.current||Ot||Ut||da||(ee.current=!0,h?.())},[h,Ut,Ot,da]),e.jsxs(e.Fragment,{children:[e.jsx(qd,{copy:l,onOpenShare:Io,screenshotMode:q,showExpiredGate:Ot,showAuthGate:Ut,identityDisplayName:Vr,identityStartDate:Kr,activeDays:za,identitySubscriptions:yo,identityScrambleDurationMs:te,projectUsageEntries:Un,projectUsageLimit:zn,setProjectUsageLimit:On,projectDetailQuery:{from:ke,to:we,timeZone:fe,tzOffsetMinutes:pe},topModels:Gr,signedIn:r,publicMode:i,isLocalMode:Ne,shouldShowInstall:Vo,installPrompt:Ko,handleCopyInstall:Wo,installCopied:ne,installCopiedLabel:Uo,installCopyLabel:Oo,installInitCmdDisplay:Bo,linkCodeLoading:P,linkCodeError:j,trendRowsForDisplay:Qn,trendFromForDisplay:Xn,trendToForDisplay:eo,trendZoomConfig:Gn,usageFrom:ke,usageTo:we,period:Q,trendTimeZoneLabel:Ra,activityHeatmapBlock:bo,periodsForDisplay:Do,setSelectedPeriod:co,customFrom:Ve,customTo:Xe,onCustomRangeApply:uo,customRangeOpen:La,onCustomRangeOpenChange:mo,metricsRows:Lo,summaryLabel:wo,summaryValue:_o,hasSummary:Me,summaryLoading:ra,providersLoading:xt,summaryFullValue:Ka,onToggleSummaryFormat:vo,summaryTotalTokensRaw:se(bt)||0,summaryCostValue:Wa,summaryConversationsValue:Mo,rollingUsage:Fa,costInfoEnabled:Po,openCostModal:Fo,allowBreakdownToggle:To,coreIndexCollapsed:ue,setCoreIndexCollapsed:W,coreIndexCollapseLabel:jo,coreIndexExpandLabel:No,coreIndexCollapseAria:So,coreIndexExpandAria:Co,refreshAll:xo,usageLoadingState:da,announceUsageLoading:Le,initialDashboardLoading:Ha,usageError:$a,rangeLabel:ko,timeZoneRangeLabel:Ia,usageSourceLabel:fo,fleetData:Wr,hasDetailsActual:$r,dailyEmptyPrefix:Go,installSyncCmd:zo,dailyEmptySuffix:qo,detailsColumns:qn,ariaSortFor:no,toggleSort:so,sortIconFor:oo,pagedDetails:Zn,dailyBreakdownRows:Jn,dailyBreakdownColumns:Yn,dailyBreakdownAriaSortFor:io,dailyBreakdownSortIconFor:lo,dailyBreakdownDateKey:oa,detailsDateKey:Ue,renderDetailDate:ao,renderDailyBreakdownDate:ro,renderDetailCell:to,DETAILS_PAGED_PERIODS:Vt,detailsPageCount:Pa,detailsPage:Ba,setDetailsPage:la,costModalOpen:v,closeCostModal:$o,deviceOptions:Ea,selectedDevice:Te||"",onDeviceChange:b=>gt(b||null),deviceUsageBlock:ea,leftCardOrder:ma.left.order,onLeftReorder:ma.left.reorder,rightCardOrder:ma.right.order,onRightReorder:ma.right.reorder}),e.jsx(Ru,{open:$,onClose:Ro,data:Eo,twitterText:Ao})]})}export{Am as DashboardPage};
|