@georgedong32/ccs 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/assets/{accounts-BGuXLcVx.js → accounts-DY2qc1Fj.js} +1 -1
- package/dist/ui/assets/{alert-dialog-jF9isdf5.js → alert-dialog-DxSEXEYT.js} +1 -1
- package/dist/ui/assets/{api-Ci1Bzv_m.js → api-BuQsvzTw.js} +1 -1
- package/dist/ui/assets/{auth-section-sr19LsMn.js → auth-section-BaOzwIQC.js} +1 -1
- package/dist/ui/assets/{backups-section-CM_YkWDa.js → backups-section-CtCPd8ZP.js} +1 -1
- package/dist/ui/assets/{channels-DS93mnFK.js → channels-Dc9yAiRV.js} +1 -1
- package/dist/ui/assets/{checkbox-sD9xsUKe.js → checkbox-PmhTRKMJ.js} +1 -1
- package/dist/ui/assets/{claude-extension-ITdAX2gE.js → claude-extension-BmrRz66m.js} +1 -1
- package/dist/ui/assets/{cliproxy-Cy2nG9Cw.js → cliproxy-CisEtPs4.js} +1 -1
- package/dist/ui/assets/{cliproxy-ai-providers-1HBAFOKl.js → cliproxy-ai-providers-CuUlJ9io.js} +1 -1
- package/dist/ui/assets/{cliproxy-control-panel-gTB6KR67.js → cliproxy-control-panel-yiOrEg3N.js} +1 -1
- package/dist/ui/assets/{codex-BxWQizC_.js → codex-EjebSo8c.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-DyatJXUE.js → confirm-dialog-BIPtmVJj.js} +1 -1
- package/dist/ui/assets/{copilot-CozS5Tdw.js → copilot-BSZD1eVg.js} +1 -1
- package/dist/ui/assets/{cursor-CDnZVKJR.js → cursor-BVhDG7IA.js} +1 -1
- package/dist/ui/assets/{droid-C2B8C435.js → droid-2Cn2gExW.js} +1 -1
- package/dist/ui/assets/{globalenv-section-BaI_bbio.js → globalenv-section-DdDcVEM8.js} +1 -1
- package/dist/ui/assets/{health-F88SuMCJ.js → health-DMpTU0-S.js} +1 -1
- package/dist/ui/assets/{index-t3kB7EcJ.js → index-B9Ty7Irs.js} +1 -1
- package/dist/ui/assets/{index-CmlrhroD.js → index-CUg_ifEj.js} +1 -1
- package/dist/ui/assets/index-CvcrgRX9.js +1 -0
- package/dist/ui/assets/{index-vCHZXitE.js → index-DJ7By7qi.js} +1 -1
- package/dist/ui/assets/{index-BiZ2Cm5S.js → index-DObHizqD.js} +1 -1
- package/dist/ui/assets/{index-CsDC6zFL.js → index-DcAGM-vb.js} +1 -1
- package/dist/ui/assets/{index-COJHdqX1.js → index-Dm0Cx9St.js} +2 -2
- package/dist/ui/assets/{logs-D7MNTXPD.js → logs-CgJ-0Ohj.js} +1 -1
- package/dist/ui/assets/{masked-input-P3yXLhDm.js → masked-input-Bvcx7hT9.js} +1 -1
- package/dist/ui/assets/{proxy-status-widget-CCghVKQX.js → proxy-status-widget-DgakK820.js} +1 -1
- package/dist/ui/assets/{raw-json-settings-editor-panel-DwppyNrK.js → raw-json-settings-editor-panel-DJc8S7Hd.js} +1 -1
- package/dist/ui/assets/{searchable-select-Db7X8GwA.js → searchable-select-ycZJ7HQQ.js} +1 -1
- package/dist/ui/assets/{separator-B-X_NPlM.js → separator-F5z10x_U.js} +1 -1
- package/dist/ui/assets/{shared-BbFiCDYw.js → shared-CHO8lnK0.js} +1 -1
- package/dist/ui/assets/{table-BHS4nbeU.js → table-DzcQUkAB.js} +1 -1
- package/dist/ui/assets/{updates-BH08kNan.js → updates-FFYZ3hbq.js} +1 -1
- package/dist/ui/assets/{use-accounts-D_J-0yRj.js → use-accounts-CfYoYSF6.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/index-9CEJIHJQ.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-DvRtHWGI.js";import{r as h,E as $e}from"./react-vendor-Bjx91N7w.js";import{u as A,a as L,C as D,b as T,S as j,c as f,P as C,B as te,d as Ie,e as K,f as pe,g as Ae,h as ge,i as Be,D as qe,j as Ue,k as Ke,l as Oe,m as Ee,n as _e,o as He,p as We,q as Qe,r as Ge,s as Ve,t as ye,v as P,w as _,x as ae,I as Ye,y as ze}from"./index-COJHdqX1.js";import{a2 as je,al as Z,am as H,an as Ne,a0 as we,a9 as Ze,G as Je,ao as re,L as Xe,ap as es,w as ss,v as ts,aq as as,R as ns,_ as de,U as rs,Z as ls,u as os,ar as is,as as cs,at as ve,C as ds,au as us}from"./icons-bxdfpJdB.js";import{a as J,u as F,b as oe}from"./tanstack-Dg84L5cM.js";import{u as xs}from"./use-accounts-D_J-0yRj.js";import{K as O,L as be,f as M,H as ms}from"./utils-CzKF5WmX.js";import{R as Ce,A as hs,C as fs,X as ps,Y as ue,T as ke,b as xe,P as gs,c as ys,d as js}from"./charts-eIPy2oG6.js";import"./notifications-B4_o8bcr.js";import"./form-utils-CuHzLhJZ.js";function Ns({data:s,isLoading:t}){const{privacyMode:a}=A(),{t:n}=L(),l=s?.totalTokens??0,o=s?.totalInputTokens??0,c=s?.totalOutputTokens??0,d=s?.totalCacheTokens??0,r=o+c;if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(i=>e.jsx(D,{children:e.jsx(T,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{className:"h-4 w-[100px]"}),e.jsx(j,{className:"h-8 w-[80px]"})]}),e.jsx(j,{className:"h-8 w-8 rounded-lg"})]})})},i))});const u=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),m=s?.totalCost?Math.round(u/s.totalCost*100):0,x=d>0&&l>r,y=d>0&&!x?"Total Tokens (I/O)":n("analyticsSummary.totalTokens"),w=x?`${$(o)} in / ${$(c)} out / ${$(d)} cache`:n("analyticsSummary.totalTokensSubtitle",{input:$(o),output:$(c)}),k=[{title:y,value:l,icon:je,format:i=>$(i),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:w},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:Z,format:i=>`$${i.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:H,format:i=>$(i),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:u.toFixed(2),percent:m})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:Ne,format:i=>`$${i.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:$(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:we,format:i=>`$${i.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:$(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:k.map((i,p)=>{const g=i.icon;return e.jsx(D,{className:"hover:shadow-md transition-shadow",children:e.jsx(T,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:i.title}),e.jsx("p",{className:f("text-xl font-bold truncate",a&&C),children:i.format(i.value)}),i.subtitle&&e.jsx("p",{className:f("text-[10px] text-muted-foreground truncate",a&&C),children:i.subtitle})]}),e.jsx("div",{className:f("p-2 rounded-lg shrink-0",i.bgColor),children:e.jsx(g,{className:f("h-4 w-4",i.color)})})]})})},p)})})}function $(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ws({model:s}){const{privacyMode:t}=A(),{t:a}=L(),n=bs(s.ioRatio,a),o=s.cacheCreationTokens+s.cacheReadTokens>0?a("analyticsCards.allTokens"):a("analyticsCards.totalTokens"),c=s.cacheReadTokens>0?s.cacheReadTokens/(s.inputTokens+s.cacheReadTokens)*100:0,d=c>0?vs(c):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(te,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(te,{variant:n.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]}),d&&e.jsxs(te,{variant:d,className:"text-[10px] h-5 px-1.5",children:[c.toFixed(0),"% ",a("analyticsCards.hitRate")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:f("text-lg font-bold",t&&C),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.totalCost")})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:f("text-lg font-bold",t&&C),children:ks(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:o})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:a("analyticsCards.tokenBreakdown")}),e.jsxs("div",{className:f("space-y-1",t&&C),children:[e.jsx(z,{label:a("analyticsCards.input"),tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:Ne}),e.jsx(z,{label:a("analyticsCards.output"),tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:we}),e.jsx(z,{label:a("analyticsCards.cacheWrite"),tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:H}),e.jsx(z,{label:a("analyticsCards.cacheRead"),tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:H})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:a("analyticsCards.inputOutputRatio")})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:n.description})]})]})}function z({label:s,tokens:t,cost:a,color:n,icon:l}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:Cs(t)})]})]})]})}function vs(s){return s>=50?"success":s>=20?"secondary":"outline"}function bs(s,t){return s>=200?{variant:"destructive",description:t("analyticsCards.extendedThinkingHint")}:s>=50?{variant:"secondary",description:t("analyticsCards.analysisTaskHint")}:s>=5?{variant:"outline",description:t("analyticsCards.balancedRatioHint")}:{variant:"default",description:t("analyticsCards.generationHeavyHint")}}function Cs(s){return s.toLocaleString()}function ks(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const me="/api";function he(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${n}`}function B(s,t){const a=t.toString();return a?`${s}?${a}`:s}function q(s,t){t?.startDate&&s.append("since",he(t.startDate)),t?.endDate&&s.append("until",he(t.endDate))}function U(s,t){t?.profile&&s.append("profile",t.profile)}const R={summary:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/summary",t))},trends:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/daily",t))},hourly:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/hourly",t))},models:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/models",t))},sessions:s=>{const t=new URLSearchParams;return q(t,s),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),U(t,s),I(B("/usage/sessions",t))},monthly:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/monthly",t))},refresh:async()=>{if(!(await fetch(`${me}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache");const t=1500,a=3e4,n=Date.now();for(;Date.now()-n<a;){await new Promise(l=>setTimeout(l,t));try{const l=await fetch(`${me}/usage/refresh-status`);if(!l.ok)continue;if(!(await l.json()).data?.refreshing)return}catch{}}},status:()=>I("/usage/status"),insights:s=>{const t=new URLSearchParams;return q(t,s),U(t,s),I(B("/usage/insights",t))},cursorImport:async s=>{const t=new FormData;t.append("file",s);const a=await fetch("/api/usage/cursor/import",{method:"POST",body:t});if(!a.ok){const l=await a.json().catch(()=>({error:"Upload failed"}));throw new Error(l.error||"Failed to import Cursor usage data")}return(await a.json()).data},cursorStatus:async()=>{const s=await fetch("/api/usage/cursor/status");if(!s.ok)throw new Error("Failed to fetch Cursor status");return(await s.json()).data},cursorDataClear:async()=>{const s=await fetch("/api/usage/cursor/clear",{method:"POST"});if(!s.ok)throw new Error("Failed to clear Cursor data");return(await s.json()).data}};async function I(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const l=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||a.statusText)}const n=await a.json();return n.data||n}function Ss(s){return F({queryKey:["usage","summary",s],queryFn:()=>R.summary(s),staleTime:60*1e3})}function Ds(s){return F({queryKey:["usage","trends",s],queryFn:()=>R.trends(s),staleTime:60*1e3})}function Ts(s){return F({queryKey:["usage","hourly",s],queryFn:()=>R.hourly(s),staleTime:60*1e3})}function Ls(s){return F({queryKey:["usage","models",s],queryFn:()=>R.models(s),staleTime:60*1e3})}function Fs(){const s=J();return h.useCallback(async()=>{await R.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function Ps(){return F({queryKey:["usage","status"],queryFn:()=>R.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function Ms(s){return F({queryKey:["usage","sessions",s],queryFn:()=>R.sessions(s),staleTime:60*1e3})}const Rs=50,le="ccs.analytics.selectedProfile",W="all";function $s(){if(typeof globalThis.localStorage>"u")return W;const s=globalThis.localStorage.getItem(le);return!s||s.startsWith("unsupported:")?W:s}function Is(s){if(!(typeof globalThis.localStorage>"u")){if(s===W){globalThis.localStorage.removeItem(le);return}globalThis.localStorage.setItem(le,s)}}function As(){const[s,t]=h.useState({from:O(new Date,30),to:new Date}),[a,n]=h.useState(!1),[l,o]=h.useState(null),[c,d]=h.useState($s),[r,u]=h.useState(null),[m,x]=h.useState("daily"),{t:y}=L(),{data:w}=xs(),{data:k}=Ie(),i=Fs(),p=h.useCallback(async()=>{n(!0);try{await i()}finally{n(!1)}},[i]),g=h.useMemo(()=>({startDate:s?.from,endDate:s?.to,profile:c===W?void 0:c}),[s?.from,s?.to,c]),v=h.useMemo(()=>{const S=new Set(w?.accounts.map(b=>b.name)??[]),Y=[{value:W,label:y("analyticsCards.allProfiles"),description:y("analyticsCards.allProfilesDesc"),supported:!0},{value:"default",label:y("analyticsCards.defaultClaude"),description:y("analyticsCards.defaultClaudeDesc"),supported:!0},...Array.from(S).sort((b,Re)=>b.localeCompare(Re)).map(b=>({value:b,label:b,description:"Profile-scoped account data.",supported:!0}))];for(const b of k?.profiles??[])S.has(b.name)||b.name==="default"||Y.push({value:`unsupported:${b.name}`,label:b.name,description:"API profile usage is not yet attributed by stable profile.",supported:!1});return Y},[w?.accounts,k?.profiles]),{data:N,isLoading:Q}=Ss(g),{data:X,isLoading:E}=Ds(g),{data:G,isLoading:ee}=Ts(g),{data:se,isLoading:ie}=Ls(g),{data:Se,isLoading:ce}=Ms({...g,limit:Rs}),{data:V}=Ps(),De=h.useCallback(()=>{const S=new Date;t({from:O(S,1),to:S}),x("hourly")},[]),Te=h.useCallback(S=>{t(S),x("daily")},[]),Le=h.useCallback(S=>{S.startsWith("unsupported:")||(d(S),Is(S))},[]),Fe=h.useMemo(()=>V?.lastFetch?be(new Date(V.lastFetch),{addSuffix:!0}):null,[V?.lastFetch]),Pe=h.useCallback((S,Y)=>{const b=Y.currentTarget.getBoundingClientRect();u({x:b.left+b.width/2,y:b.top+b.height/2}),o(S)},[]),Me=h.useCallback(()=>{o(null),u(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:m,selectedProfile:c,profileOptions:v,selectedModel:l,popoverPosition:r,summary:N,trends:X,hourlyData:G,models:se,sessions:Se,status:V,isSummaryLoading:Q,isTrendsLoading:E,isHourlyLoading:ee,isModelsLoading:ie,isSessionsLoading:ce,isLoading:Q||E||ie||ce,handleRefresh:p,handleTodayClick:De,handleDateRangeChange:Te,handleProfileChange:Le,handleModelClick:Pe,handlePopoverClose:Me,lastUpdatedText:Fe}}function Bs({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:O(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:O(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:O(new Date,90),to:new Date}}],className:n}){const[l,o]=$e.useState(!1),{t:c}=L(),d=r=>!s||!s.from||!s.to||!r.from||!r.to?!1:M(s.from,"yyyy-MM-dd")===M(r.from,"yyyy-MM-dd")&&M(s.to,"yyyy-MM-dd")===M(r.to,"yyyy-MM-dd");return e.jsxs("div",{className:f("flex flex-wrap items-center gap-2",n),children:[a.map(r=>e.jsx(K,{variant:d(r.range)?"default":"outline",size:"sm",onClick:()=>t(r.range),children:r.label},r.label)),e.jsxs(pe,{open:l,onOpenChange:o,children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(K,{id:"date",variant:"outline",className:f("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(re,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[M(s.from,"LLL dd, y")," - ",M(s.to,"LLL dd, y")]}):M(s.from,"LLL dd, y"):e.jsx("span",{children:c("dateRangeFilter.pickADate")})]})}),e.jsx(ge,{className:"w-auto p-0",align:"end",children:e.jsx(Be,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function qs(){const s=J();return oe({mutationFn:t=>R.cursorImport(t),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function Us(){return F({queryKey:["cursor-status"],queryFn:()=>R.cursorStatus(),staleTime:30*1e3})}function Ks(){const s=J();return oe({mutationFn:()=>R.cursorDataClear(),onSuccess:()=>{s.invalidateQueries({queryKey:["usage"]}),s.invalidateQueries({queryKey:["cursor-status"]})}})}function Os(){const{t:s}=L(),{privacyMode:t}=A(),a=h.useRef(null),[n,l]=h.useState(!1),[o,c]=h.useState(null),d=qs(),{data:r,isLoading:u}=Us(),m=Ks(),x=async i=>{const p=i.target.files?.[0];if(p){c(null);try{await d.mutateAsync(p)}catch(g){c(g instanceof Error?g.message:s("analyticsCursor.errorMessage"))}a.current&&(a.current.value="")}},y=async()=>{if(window.confirm(s("analyticsCursor.clearConfirm")))try{await m.mutateAsync()}catch{c(s("analyticsCursor.errorMessage"))}},w=i=>i>=1e6?`${(i/1e6).toFixed(1)}M`:i.toLocaleString(),k=i=>!i||i.length<8?i:`${i.slice(0,4)}-${i.slice(4,6)}-${i.slice(6,8)}`;return e.jsxs(qe,{open:n,onOpenChange:l,children:[e.jsx(Ue,{asChild:!0,children:e.jsxs(K,{variant:"outline",size:"sm",className:"gap-2 h-8",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:s("analytics.importData")})]})}),e.jsxs(Ke,{className:"sm:max-w-md",children:[e.jsxs(Oe,{children:[e.jsxs(Ee,{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),s("analytics.importData")]}),e.jsx(_e,{children:s("analyticsCursor.fileHint")})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(je,{className:"w-4 h-4"}),s("cursorIde")]}),e.jsx("input",{ref:a,type:"file",accept:".csv",className:"hidden",onChange:x}),e.jsx(K,{variant:"outline",size:"sm",className:"w-full",disabled:d.isPending,onClick:()=>a.current?.click(),children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Xe,{className:"w-3.5 h-3.5 mr-2 animate-spin"}),s("analyticsCursor.importing")]}):e.jsxs(e.Fragment,{children:[e.jsx(es,{className:"w-3.5 h-3.5 mr-2"}),s("analyticsCursor.importButton")]})}),d.isSuccess&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-green-600",children:[e.jsx(ss,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:s("analyticsCursor.successMessage")})]}),o&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[e.jsx(ts,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]}),u?null:r?.hasData?e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3 text-xs space-y-1.5",children:[r.dateRange&&e.jsxs("div",{className:"text-muted-foreground",children:[k(r.dateRange.from)," ~ ",k(r.dateRange.to)]}),e.jsxs("div",{className:f(t&&C),children:[w(r.totalTokens)," tokens · ",r.totalEvents," events"]}),r.models.length>0&&e.jsx("div",{className:"text-muted-foreground truncate",children:r.models.join(", ")})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("analyticsCursor.fileHint")}),r?.hasData&&e.jsxs(K,{variant:"ghost",size:"sm",className:"w-full text-xs text-muted-foreground hover:text-destructive",disabled:m.isPending,onClick:y,children:[e.jsx(as,{className:"w-3 h-3 mr-1"}),s("analyticsCursor.clearButton")]})]})})]})]})}function Es({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:l,lastUpdatedText:o,viewMode:c,selectedProfile:d,profileOptions:r,onProfileChange:u}){const{t:m}=L();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:m("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:m("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsxs(He,{value:d,onValueChange:u,children:[e.jsx(We,{className:"h-8 w-[200px] min-w-0","aria-label":m("analyticsCards.allProfiles"),children:e.jsx(Qe,{placeholder:m("analyticsCards.allProfiles"),children:r.find(x=>x.value===d)?.label})}),e.jsx(Ge,{className:"min-w-[260px]",children:r.map(x=>e.jsx(Ve,{value:x.value,disabled:!x.supported,children:e.jsxs("span",{className:"flex flex-col gap-0.5 py-0.5",children:[e.jsx("span",{className:"font-medium text-sm",children:x.label}),e.jsx("span",{className:"text-xs text-muted-foreground leading-tight",children:x.description})]})},x.value))})]}),e.jsx(K,{variant:c==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(Bs,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:O(new Date,7),to:new Date}},{label:"30D",range:{from:O(new Date,30),to:new Date}},{label:m("analytics.month"),range:{from:ms(new Date),to:new Date}},{label:m("analytics.allTime"),range:{from:void 0,to:new Date}}]}),o&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:m("analytics.updated",{value:o})}),e.jsx(K,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(ns,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})}),e.jsx(Os,{})]}),d!=="all"&&e.jsx("p",{className:"text-xs text-muted-foreground xl:text-right",children:"Selected-profile analytics include only default/account data with stable profile attribution. CLIProxy and native runtime snapshots remain in All profiles."})]})}function _s({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:l}=A(),{t:o}=L(),c=h.useMemo(()=>!s||s.length===0?[]:s.map(u=>{const m="hour"in u?u.hour:u.date;return{...u,dateFormatted:Hs(m,a),costRounded:Number(u.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(j,{className:f("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:f("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:o(a==="hourly"?"analytics.noDailyUsage":"analytics.noUsageData")})});const d=({x:r,y:u,payload:m,isRight:x})=>{const y=x?`$${m.value}`:fe(Number(m.value));return e.jsx("text",{x:r,y:u,dy:4,textAnchor:x?"start":"end",fontSize:12,fill:"currentColor",className:f("fill-muted-foreground",l&&"blur-[4px]"),children:y})};return e.jsx("div",{className:f("w-full h-full",n),children:e.jsx(Ce,{width:"100%",height:"100%",children:e.jsxs(hs,{data:c,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(fs,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(ps,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ue,{yAxisId:"left",orientation:"left",tick:r=>e.jsx(d,{...r,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ue,{yAxisId:"right",orientation:"right",tick:r=>e.jsx(d,{...r,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ke,{content:({active:r,payload:u,label:m})=>!r||!u||!u.length?null:e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:m}),u.map((x,y)=>e.jsxs("p",{className:f("text-sm",l&&C),style:{color:x.color},children:[x.name,":"," ",x.name==="Tokens"?fe(Number(x.value)||0):`$${x.value}`]},y))]})}),e.jsx(xe,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(xe,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function Hs(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const o=new Date(`${n}T${l}:00Z`);return M(o,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?M(a,"MMM yyyy"):M(a,"MMM dd")}function fe(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ws({data:s,isLoading:t,className:a}){const{privacyMode:n}=A(),{t:l}=L(),o=h.useMemo(()=>!s||s.length===0?[]:s.map(r=>({name:r.model,value:r.tokens,cost:r.cost,percentage:r.percentage,fill:ye(r.model)})),[s]);if(t)return e.jsx(j,{className:f("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:f("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:l("analyticsCards.noModelData")})});const c=({active:r,payload:u})=>{if(!r||!u)return null;const m=u;if(!m.length)return null;const x=m[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:x.name}),e.jsxs("p",{className:f("text-muted-foreground",n&&C),children:[Qs(x.value)," (",x.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:f("text-muted-foreground",n&&C),children:["$",x.cost.toFixed(4)]})]})},d=r=>r.percentage>5?`${r.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:f("w-full h-full min-h-[100px]",a),children:e.jsx(Ce,{width:"100%",height:"100%",children:e.jsxs(gs,{children:[e.jsx(ys,{data:o,cx:"50%",cy:"50%",labelLine:!1,label:d,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((r,u)=>e.jsx(js,{fill:r.fill,strokeWidth:1},`cell-${u}`))}),e.jsx(ke,{content:c})]})})})}function Qs(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Gs(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function Vs({data:s,isLoading:t,className:a}){const{privacyMode:n}=A(),{t:l}=L(),o=h.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const c=s.sessions,d=s.total,r=c.length,u=s.hasMore||s.offset>0,x=c.reduce((y,w)=>y+w.cost,0)/c.length;return{displayedSessions:u?r:d,totalSessions:d,avgCost:x,hasPartialSample:u,recentSessions:c.slice(0,3)}},[s]);return t?e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-32"})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):o?e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),l("analyticsCards.sessionStats")]})}),e.jsxs(T,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(rs,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:o.displayedSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:o.hasPartialSample?l("analyticsCards.sampledSessions"):l("analyticsCards.totalSessions")}),o.hasPartialSample&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[o.totalSessions," total"]})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ls,{className:"w-4 h-4"}),e.jsxs("span",{className:f("text-xl font-bold",n&&C),children:["$",o.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:o.hasPartialSample?l("analyticsCards.recentAvgCost"):l("analyticsCards.avgCostPerSession")})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx(os,{className:"w-3 h-3"}),l("analyticsCards.recentActivity")]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:o.recentSessions.map(c=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:c.projectPath,children:Gs(c.projectPath)}),(c.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:c.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(new Date(c.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:f("text-right shrink-0 ml-2",n&&C),children:[e.jsxs("div",{className:"font-mono",children:["$",c.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Ys(c.tokens??c.inputTokens+c.outputTokens)," ","toks"]})]})]},c.sessionId))})]})]})]}):e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),l("analyticsCards.sessionStats")]})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:l("analyticsCards.noSessionData")})})]})}function Ys(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}async function ne(s,t){try{const a=new URLSearchParams,n=d=>{const r=d.getFullYear(),u=String(d.getMonth()+1).padStart(2,"0"),m=String(d.getDate()).padStart(2,"0");return`${r}${u}${m}`};a.append("since",n(s)),a.append("until",n(t));const l=await fetch(`/api/usage/summary?${a}`,{headers:{"Content-Type":"application/json"}});if(!l.ok)return 0;const o=await l.json();return(o.data||o).totalCost||0}catch{return 0}}function zs(){const s=new Date;return new Date(s.getFullYear(),s.getMonth()+1,0).getDate()}function Zs(){return new Date().getDate()}function Js(s,t){return t<=0?"N/A":`${(s/t).toFixed(2)}x`}function Xs(s,t){return t<=0?null:s/t}function et(){const s=J(),t=F({queryKey:["cost-leverage-config"],queryFn:async()=>{const g=(await ae.config.get()).preferences?.baseline_cost_30d;return typeof g=="number"?g:void 0},staleTime:30*1e3}),a=t.data,n=h.useMemo(()=>new Date,[]),l=h.useMemo(()=>{const i=new Date(n),p=new Date(n);return p.setDate(p.getDate()-6),{start:p,end:i}},[n]),o=h.useMemo(()=>{const i=new Date(n),p=new Date(n);return p.setDate(p.getDate()-29),{start:p,end:i}},[n]),c=h.useMemo(()=>{const i=new Date(n.getFullYear(),n.getMonth(),1),p=new Date(n);return{start:i,end:p}},[n]),d=F({queryKey:["cost-leverage","7d"],queryFn:()=>ne(l.start,l.end),staleTime:60*1e3}),r=F({queryKey:["cost-leverage","30d"],queryFn:()=>ne(o.start,o.end),staleTime:60*1e3}),u=F({queryKey:["cost-leverage","month"],queryFn:()=>ne(c.start,c.end),staleTime:60*1e3}),m=oe({mutationFn:async i=>{const p=await ae.config.get(),v={...p.preferences||{}};i==null?delete v.baseline_cost_30d:v.baseline_cost_30d=i;const N=typeof p.version=="number"?p.version:12;return ae.config.update({version:N,preferences:v})},onSuccess:()=>{s.invalidateQueries({queryKey:["cost-leverage-config"]})}}),x=h.useMemo(()=>{const i=Zs(),p=zs();return[{label:"7d",cost:d.data??0,windowDays:7,scaleDays:7},{label:"30d",cost:r.data??0,windowDays:30,scaleDays:30},{label:"Month",cost:u.data??0,windowDays:i,scaleDays:p}].map(v=>{const N=a?a*v.scaleDays/30:0;return{label:v.label,estimatedCost:v.cost,scaledBaseline:N,ratio:Xs(v.cost,N),ratioDisplay:Js(v.cost,N),windowDays:v.windowDays}})},[a,d.data,r.data,u.data]),y=h.useCallback(i=>{const p=i.trim();if(p==="")return m.mutate(void 0),{valid:!0};const g=Number(p);return isNaN(g)||g<=0?{valid:!1,error:"invalid"}:(m.mutate(g),{valid:!0})},[m]),w=t.isLoading||d.isLoading&&r.isLoading&&u.isLoading,k=t.error?.message||m.error?.message||null;return{baselineCost:a,windows:x,isLoading:w,isSaving:m.isPending,error:k,saveBaseline:y,cost7d:d.data,cost30d:r.data,costMonth:u.data}}function st({className:s,isLoading:t}){const{privacyMode:a}=A(),{t:n}=L(),{baselineCost:l,windows:o,isLoading:c,isSaving:d,error:r,saveBaseline:u}=et(),[m,x]=h.useState(l!==void 0?String(l):""),[y,w]=h.useState(null),[k,i]=h.useState(!1);l!==void 0&&!k&&(x(String(l)),i(!0)),l===void 0&&k&&i(!1);const p=h.useCallback(()=>{u(m).valid?(w(null),m.trim()===""&&(x(""),i(!1))):w(n("analyticsCostLeverage.invalidInput"))},[m,u,n]),g=h.useCallback(N=>{N.key==="Enter"&&(N.preventDefault(),p())},[p]),v=l!==void 0&&l>0;return c||t?e.jsxs(D,{className:f("flex flex-col h-full",s),children:[e.jsx(P,{className:"px-3 py-2",children:e.jsx(j,{className:"h-5 w-36"})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}):e.jsxs(D,{className:f("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",s),children:[e.jsx(P,{className:"px-3 py-2 shrink-0",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4"}),n("analyticsCostLeverage.title")]})}),e.jsxs(T,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-2",children:[v?e.jsx("div",{className:"flex-1 flex flex-col gap-2 justify-center min-h-0",children:o.map(N=>e.jsx(tt,{window:N,privacyMode:a,t:n},N.label))}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted/50 flex items-center justify-center",children:e.jsx(Z,{className:"w-5 h-5 text-muted-foreground"})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center leading-relaxed max-w-[180px]",children:n("analyticsCostLeverage.noBaseline")})]}),e.jsxs("div",{className:"shrink-0 pt-2 mt-auto border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),e.jsx(Ye,{type:"text",inputMode:"decimal",value:m,onChange:N=>{x(N.target.value),w(null)},onBlur:p,onKeyDown:g,placeholder:n("analyticsCostLeverage.baselinePlaceholder"),disabled:d,className:f("h-7 text-xs",y&&"border-destructive focus-visible:ring-destructive")}),d&&e.jsx("span",{className:"text-[10px] text-muted-foreground animate-pulse",children:n("analyticsCostLeverage.saving")})]}),y&&e.jsx("p",{className:"text-[10px] text-destructive mt-1",children:y}),r&&e.jsxs("p",{className:"text-[10px] text-destructive mt-1",children:[n("analyticsCostLeverage.saveError"),": ",r]})]})]})]})}function tt({window:s,privacyMode:t,t:a}){const n=s.label==="7d"?"analyticsCostLeverage.window7d":s.label==="30d"?"analyticsCostLeverage.window30d":"analyticsCostLeverage.windowMonth",l=s.label==="7d"?re:s.label==="30d"?cs:re,o=s.ratio===null?"text-muted-foreground":s.ratio<2.5?"text-red-600 dark:text-red-400":s.ratio<10?"text-amber-600 dark:text-amber-400":"text-emerald-600 dark:text-emerald-400",c=s.ratio===null?"bg-muted/30":s.ratio<2.5?"bg-red-100/30 dark:bg-red-950/30":s.ratio<10?"bg-amber-100/30 dark:bg-amber-950/30":"bg-emerald-100/30 dark:bg-emerald-950/30";return e.jsxs("div",{className:f("flex items-center gap-2 px-2.5 py-2 rounded-lg border transition-colors",c),children:[e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(l,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:a(n)})]}),e.jsxs("span",{className:f("text-xs text-muted-foreground font-mono",t&&C),children:["$",s.estimatedCost.toFixed(2)]}),e.jsx("div",{className:"flex-1 border-t border-dashed border-muted-foreground/30"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.ratio!==null&&s.ratio>=10&&e.jsx(ve,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:f("text-lg font-bold tabular-nums min-w-[56px] text-right",o,t&&C),children:s.ratioDisplay})]})]})}function at(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function nt({models:s,isLoading:t,onModelClick:a,privacyMode:n}){const{t:l}=L();return e.jsxs(D,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4"}),l("analyticsPages.costByModel")]})}),e.jsx(T,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(j,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((o,c)=>c.cost-o.cost).map(o=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:c=>a(o,c),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ye(o.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:o.model})]}),e.jsx(rt,{model:o}),e.jsx("span",{className:f("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&C),children:at(o.tokens)}),e.jsxs("span",{className:f("font-mono font-medium w-16 text-right shrink-0",n&&C),children:["$",o.cost.toFixed(2)]}),e.jsx(ds,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},o.model)),e.jsx(lt,{})]})})]})}function rt({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function lt(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:a,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:f("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function ot({viewMode:s,trends:t,hourlyData:a,models:n,sessions:l,isTrendsLoading:o,isHourlyLoading:c,isModelsLoading:d,isSessionsLoading:r,onModelClick:u}){const{privacyMode:m}=A(),{t:x}=L();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(D,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(P,{className:"px-3 py-2 shrink-0",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4"}),x(s==="hourly"?"analyticsPages.last24Hours":"analyticsPages.usageTrends")]})}),e.jsx(T,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(_s,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?c:o,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(nt,{models:n,isLoading:d,onModelClick:u,privacyMode:m}),e.jsxs(D,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(P,{className:"px-3 py-2",children:e.jsxs(_,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(us,{className:"w-4 h-4"}),x("analyticsPages.modelUsage")]})}),e.jsx(T,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(Ws,{data:n||[],isLoading:d,className:"h-full w-full"})})]}),e.jsx(Vs,{data:l,isLoading:r,className:"lg:col-span-2"}),e.jsx(st,{className:"lg:col-span-2"})]})]})}function yt(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(D,{className:"flex flex-col min-h-[300px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-32"})}),e.jsx(T,{className:"p-4 pt-0 flex-1",children:e.jsx(j,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(D,{className:"flex flex-col min-h-[250px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(T,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(j,{className:"h-3 w-24"})]}),e.jsx(j,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(D,{className:"flex flex-col min-h-[250px]",children:[e.jsx(P,{className:"p-4 pb-2",children:e.jsx(j,{className:"h-4 w-28"})}),e.jsx(T,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(j,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"w-2 h-2 rounded-full"}),e.jsx(j,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function jt(){const s=h.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:d,selectedProfile:r,profileOptions:u,summary:m,isSummaryLoading:x,trends:y,hourlyData:w,models:k,sessions:i,isTrendsLoading:p,isHourlyLoading:g,isModelsLoading:v,isSessionsLoading:N,handleModelClick:Q,handleProfileChange:X,selectedModel:E,popoverPosition:G,handlePopoverClose:ee}=As();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(Es,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:l,isRefreshing:o,lastUpdatedText:c,viewMode:d,selectedProfile:r,profileOptions:u,onProfileChange:X}),e.jsx(Ns,{data:m,isLoading:x}),e.jsx(ot,{viewMode:d,trends:y,hourlyData:w,models:k,sessions:i,isTrendsLoading:p,isHourlyLoading:g,isModelsLoading:v,isSessionsLoading:N,onModelClick:Q}),e.jsxs(pe,{open:!!E,onOpenChange:se=>!se&&ee(),children:[e.jsx(ze,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:G?.x??0,top:G?.y??0,width:1,height:1}})}),e.jsx(ge,{className:"w-80 p-3",side:"top",align:"center",children:E&&e.jsx(ws,{model:E})})]})]})}export{jt as AnalyticsPage,yt as AnalyticsSkeleton};
|