@oh-my-pi/omp-stats 18.1.13 → 18.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -254,4 +254,4 @@ React keys must be passed directly to JSX without using spread:
254
254
  * Released under the MIT License
255
255
  */class qM{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(a,n,s,i){let l=n.listeners[i],u=n.duration;l.forEach((d)=>d({chart:a,initial:n.initial,numSteps:u,currentStep:Math.min(s-n.start,u)}))}_refresh(){if(this._request)return;this._running=!0,this._request=Xx.call(window,()=>{if(this._update(),this._request=null,this._running)this._refresh()})}_update(a=Date.now()){let n=0;if(this._charts.forEach((s,i)=>{if(!s.running||!s.items.length)return;let l=s.items,u=l.length-1,d=!1,p;for(;u>=0;--u)if(p=l[u],p._active){if(p._total>s.duration)s.duration=p._total;p.tick(a),d=!0}else l[u]=l[l.length-1],l.pop();if(d)i.draw(),this._notify(i,s,a,"progress");if(!l.length)s.running=!1,this._notify(i,s,a,"complete"),s.initial=!1;n+=l.length}),this._lastDate=a,n===0)this._running=!1}_getAnims(a){let n=this._charts,s=n.get(a);if(!s)s={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},n.set(a,s);return s}listen(a,n,s){this._getAnims(a).listeners[n].push(s)}add(a,n){if(!n||!n.length)return;this._getAnims(a).items.push(...n)}has(a){return this._getAnims(a).items.length>0}start(a){let n=this._charts.get(a);if(!n)return;n.running=!0,n.start=Date.now(),n.duration=n.items.reduce((s,i)=>Math.max(s,i._duration),0),this._refresh()}running(a){if(!this._running)return!1;let n=this._charts.get(a);if(!n||!n.running||!n.items.length)return!1;return!0}stop(a){let n=this._charts.get(a);if(!n||!n.items.length)return;let s=n.items,i=s.length-1;for(;i>=0;--i)s[i].cancel();n.items=[],this._notify(a,n,Date.now(),"complete")}remove(a){return this._charts.delete(a)}}var js=new qM,Xk="transparent",bO={boolean(a,n,s){return s>0.5?n:a},color(a,n,s){let i=Wx(a||Xk),l=i.valid&&Wx(n||Xk);return l&&l.valid?l.mix(i,s).hexString():n},number(a,n,s){return a+(n-a)*s}};class VM{constructor(a,n,s,i){let l=n[s];i=Hd([a.to,i,l,a.from]);let u=Hd([a.from,l,i]);this._active=!0,this._fn=a.fn||bO[a.type||typeof u],this._easing=_u[a.easing]||_u.linear,this._start=Math.floor(Date.now()+(a.delay||0)),this._duration=this._total=Math.floor(a.duration),this._loop=!!a.loop,this._target=n,this._prop=s,this._from=u,this._to=i,this._promises=void 0}active(){return this._active}update(a,n,s){if(this._active){this._notify(!1);let i=this._target[this._prop],l=s-this._start,u=this._duration-l;this._start=s,this._duration=Math.floor(Math.max(u,a.duration)),this._total+=l,this._loop=!!a.loop,this._to=Hd([a.to,n,i,a.from]),this._from=Hd([a.from,i,n])}}cancel(){if(this._active)this.tick(Date.now()),this._active=!1,this._notify(!1)}tick(a){let n=a-this._start,s=this._duration,i=this._prop,l=this._from,u=this._loop,d=this._to,p;if(this._active=l!==d&&(u||n<s),!this._active){this._target[i]=d,this._notify(!0);return}if(n<0){this._target[i]=l;return}p=n/s%2,p=u&&p>1?2-p:p,p=this._easing(Math.min(1,Math.max(0,p))),this._target[i]=this._fn(l,d,p)}wait(){let a=this._promises||(this._promises=[]);return new Promise((n,s)=>{a.push({res:n,rej:s})})}_notify(a){let n=a?"res":"rej",s=this._promises||[];for(let i=0;i<s.length;i++)s[i][n]()}}class Av{constructor(a,n){this._chart=a,this._properties=new Map,this.configure(n)}configure(a){if(!it(a))return;let n=Object.keys(Jt.animation),s=this._properties;Object.getOwnPropertyNames(a).forEach((i)=>{let l=a[i];if(!it(l))return;let u={};for(let d of n)u[d]=l[d];(zt(l.properties)&&l.properties||[i]).forEach((d)=>{if(d===i||!s.has(d))s.set(d,u)})})}_animateOptions(a,n){let s=n.options,i=vO(a,s);if(!i)return[];let l=this._createAnimations(i,s);if(s.$shared)xO(a.options.$animations,s).then(()=>{a.options=s},()=>{});return l}_createAnimations(a,n){let s=this._properties,i=[],l=a.$animations||(a.$animations={}),u=Object.keys(n),d=Date.now(),p;for(p=u.length-1;p>=0;--p){let h=u[p];if(h.charAt(0)==="$")continue;if(h==="options"){i.push(...this._animateOptions(a,n));continue}let g=n[h],b=l[h],y=s.get(h);if(b)if(y&&b.active()){b.update(y,g,d);continue}else b.cancel();if(!y||!y.duration){a[h]=g;continue}l[h]=b=new VM(y,a,h,g),i.push(b)}return i}update(a,n){if(this._properties.size===0){Object.assign(a,n);return}let s=this._createAnimations(a,n);if(s.length)return js.add(this._chart,s),!0}}function xO(a,n){let s=[],i=Object.keys(n);for(let l=0;l<i.length;l++){let u=a[i[l]];if(u&&u.active())s.push(u.wait())}return Promise.all(s)}function vO(a,n){if(!n)return;let s=a.options;if(!s){a.options=n;return}if(s.$shared)a.options=s=Object.assign({},s,{$shared:!1,$animations:{}});return s}function Yk(a,n){let s=a&&a.options||{},i=s.reverse,l=s.min===void 0?n:0,u=s.max===void 0?n:0;return{start:i?u:l,end:i?l:u}}function SO(a,n,s){if(s===!1)return!1;let i=Yk(a,s),l=Yk(n,s);return{top:l.end,right:i.end,bottom:l.start,left:i.start}}function LO(a){let n,s,i,l;if(it(a))n=a.top,s=a.right,i=a.bottom,l=a.left;else n=s=i=l=a;return{top:n,right:s,bottom:i,left:l,disabled:a===!1}}function jM(a,n){let s=[],i=a._getSortedDatasetMetas(n),l,u;for(l=0,u=i.length;l<u;++l)s.push(i[l].index);return s}function $k(a,n,s,i={}){let l=a.keys,u=i.mode==="single",d,p,h,g;if(n===null)return;let b=!1;for(d=0,p=l.length;d<p;++d){if(h=+l[d],h===s){if(b=!0,i.all)continue;break}if(g=a.values[h],Kt(g)&&(u||n===0||Ln(n)===Ln(g)))n+=g}if(!b&&!i.all)return 0;return n}function CO(a,n){let{iScale:s,vScale:i}=n,l=s.axis==="x"?"x":"y",u=i.axis==="x"?"x":"y",d=Object.keys(a),p=Array(d.length),h,g,b;for(h=0,g=d.length;h<g;++h)b=d[h],p[h]={[l]:b,[u]:a[b]};return p}function cv(a,n){let s=a&&a.options.stacked;return s||s===void 0&&n.stack!==void 0}function TO(a,n,s){return`${a.id}.${n.id}.${s.stack||s.type}`}function wO(a){let{min:n,max:s,minDefined:i,maxDefined:l}=a.getUserBounds();return{min:i?n:Number.NEGATIVE_INFINITY,max:l?s:Number.POSITIVE_INFINITY}}function kO(a,n,s){let i=a[n]||(a[n]={});return i[s]||(i[s]={})}function Wk(a,n,s,i){for(let l of n.getMatchingVisibleMetas(i).reverse()){let u=a[l.index];if(s&&u>0||!s&&u<0)return l.index}return null}function Zk(a,n){let{chart:s,_cachedMeta:i}=a,l=s._stacks||(s._stacks={}),{iScale:u,vScale:d,index:p}=i,h=u.axis,g=d.axis,b=TO(u,d,i),y=n.length,v;for(let T=0;T<y;++T){let M=n[T],{[h]:I,[g]:w}=M,A=M._stacks||(M._stacks={});v=A[g]=kO(l,b,I),v[p]=w,v._top=Wk(v,d,!0,i.type),v._bottom=Wk(v,d,!1,i.type);let B=v._visualValues||(v._visualValues={});B[p]=w}}function dv(a,n){let s=a.scales;return Object.keys(s).filter((i)=>s[i].axis===n).shift()}function MO(a,n){return Vs(a,{active:!1,dataset:void 0,datasetIndex:n,index:n,mode:"default",type:"dataset"})}function IO(a,n,s){return Vs(a,{active:!1,dataIndex:n,parsed:void 0,raw:void 0,element:s,index:n,mode:"default",type:"data"})}function Ud(a,n){let s=a.controller.index,i=a.vScale&&a.vScale.axis;if(!i)return;n=n||a._parsed;for(let l of n){let u=l._stacks;if(!u||u[i]===void 0||u[i][s]===void 0)return;if(delete u[i][s],u[i]._visualValues!==void 0&&u[i]._visualValues[s]!==void 0)delete u[i]._visualValues[s]}}var fv=(a)=>a==="reset"||a==="none",Qk=(a,n)=>n?a:Object.assign({},a),AO=(a,n,s)=>a&&!n.hidden&&n._stacked&&{keys:jM(s,!0),values:null};class vm{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(a,n){this.chart=a,this._ctx=a.ctx,this.index=n,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){let a=this._cachedMeta;if(this.configure(),this.linkScales(),a._stacked=cv(a.vScale,a),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler"))console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(a){if(this.index!==a)Ud(this._cachedMeta);this.index=a}linkScales(){let a=this.chart,n=this._cachedMeta,s=this.getDataset(),i=(b,y,v,T)=>b==="x"?y:b==="r"?T:v,l=n.xAxisID=Ke(s.xAxisID,dv(a,"x")),u=n.yAxisID=Ke(s.yAxisID,dv(a,"y")),d=n.rAxisID=Ke(s.rAxisID,dv(a,"r")),p=n.indexAxis,h=n.iAxisID=i(p,l,u,d),g=n.vAxisID=i(p,u,l,d);n.xScale=this.getScaleForId(l),n.yScale=this.getScaleForId(u),n.rScale=this.getScaleForId(d),n.iScale=this.getScaleForId(h),n.vScale=this.getScaleForId(g)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(a){return this.chart.scales[a]}_getOtherScale(a){let n=this._cachedMeta;return a===n.iScale?n.vScale:n.iScale}reset(){this._update("reset")}_destroy(){let a=this._cachedMeta;if(this._data)jx(this._data,this);if(a._stacked)Ud(a)}_dataCheck(){let a=this.getDataset(),n=a.data||(a.data=[]),s=this._data;if(it(n)){let i=this._cachedMeta;this._data=CO(n,i)}else if(s!==n){if(s){jx(s,this);let i=this._cachedMeta;Ud(i),i._parsed=[]}if(n&&Object.isExtensible(n))Tk(n,this);this._syncList=[],this._data=n}}addElements(){let a=this._cachedMeta;if(this._dataCheck(),this.datasetElementType)a.dataset=new this.datasetElementType}buildOrUpdateElements(a){let n=this._cachedMeta,s=this.getDataset(),i=!1;this._dataCheck();let l=n._stacked;if(n._stacked=cv(n.vScale,n),n.stack!==s.stack)i=!0,Ud(n),n.stack=s.stack;if(this._resyncElements(a),i||l!==n._stacked)Zk(this,n._parsed),n._stacked=cv(n.vScale,n)}configure(){let a=this.chart.config,n=a.datasetScopeKeys(this._type),s=a.getOptionScopes(this.getDataset(),n,!0);this.options=a.createResolver(s,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(a,n){let{_cachedMeta:s,_data:i}=this,{iScale:l,_stacked:u}=s,d=l.axis,p=a===0&&n===i.length?!0:s._sorted,h=a>0&&s._parsed[a-1],g,b,y;if(this._parsing===!1)s._parsed=i,s._sorted=!0,y=i;else{if(zt(i[a]))y=this.parseArrayData(s,i,a,n);else if(it(i[a]))y=this.parseObjectData(s,i,a,n);else y=this.parsePrimitiveData(s,i,a,n);let v=()=>b[d]===null||h&&b[d]<h[d];for(g=0;g<n;++g)if(s._parsed[g+a]=b=y[g],p){if(v())p=!1;h=b}s._sorted=p}if(u)Zk(this,y)}parsePrimitiveData(a,n,s,i){let{iScale:l,vScale:u}=a,d=l.axis,p=u.axis,h=l.getLabels(),g=l===u,b=Array(i),y,v,T;for(y=0,v=i;y<v;++y)T=y+s,b[y]={[d]:g||l.parse(h[T],T),[p]:u.parse(n[T],T)};return b}parseArrayData(a,n,s,i){let{xScale:l,yScale:u}=a,d=Array(i),p,h,g,b;for(p=0,h=i;p<h;++p)g=p+s,b=n[g],d[p]={x:l.parse(b[0],g),y:u.parse(b[1],g)};return d}parseObjectData(a,n,s,i){let{xScale:l,yScale:u}=a,{xAxisKey:d="x",yAxisKey:p="y"}=this._parsing,h=Array(i),g,b,y,v;for(g=0,b=i;g<b;++g)y=g+s,v=n[y],h[g]={x:l.parse(rl(v,d),y),y:u.parse(rl(v,p),y)};return h}getParsed(a){return this._cachedMeta._parsed[a]}getDataElement(a){return this._cachedMeta.data[a]}applyStack(a,n,s){let i=this.chart,l=this._cachedMeta,u=n[a.axis],d={keys:jM(i,!0),values:n._stacks[a.axis]._visualValues};return $k(d,u,l.index,{mode:s})}updateRangeFromParsed(a,n,s,i){let l=s[n.axis],u=l===null?NaN:l,d=i&&s._stacks[n.axis];if(i&&d)i.values=d,u=$k(i,l,this._cachedMeta.index);a.min=Math.min(a.min,u),a.max=Math.max(a.max,u)}getMinMax(a,n){let s=this._cachedMeta,i=s._parsed,l=s._sorted&&a===s.iScale,u=i.length,d=this._getOtherScale(a),p=AO(n,s,this.chart),h={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:g,max:b}=wO(d),y,v;function T(){v=i[y];let M=v[d.axis];return!Kt(v[a.axis])||g>M||b<M}for(y=0;y<u;++y){if(T())continue;if(this.updateRangeFromParsed(h,a,v,p),l)break}if(l)for(y=u-1;y>=0;--y){if(T())continue;this.updateRangeFromParsed(h,a,v,p);break}return h}getAllParsedValues(a){let n=this._cachedMeta._parsed,s=[],i,l,u;for(i=0,l=n.length;i<l;++i)if(u=n[i][a.axis],Kt(u))s.push(u);return s}getMaxOverflow(){return!1}getLabelAndValue(a){let n=this._cachedMeta,{iScale:s,vScale:i}=n,l=this.getParsed(a);return{label:s?""+s.getLabelForValue(l[s.axis]):"",value:i?""+i.getLabelForValue(l[i.axis]):""}}_update(a){let n=this._cachedMeta;this.update(a||"default"),n._clip=LO(Ke(this.options.clip,SO(n.xScale,n.yScale,this.getMaxOverflow())))}update(a){}draw(){let a=this._ctx,n=this.chart,s=this._cachedMeta,i=s.data||[],l=n.chartArea,u=[],d=this._drawStart||0,p=this._drawCount||i.length-d,h=this.options.drawActiveElementsOnTop,g;if(s.dataset)s.dataset.draw(a,l,d,p);for(g=d;g<d+p;++g){let b=i[g];if(b.hidden)continue;if(b.active&&h)u.push(b);else b.draw(a,l)}for(g=0;g<u.length;++g)u[g].draw(a,l)}getStyle(a,n){let s=n?"active":"default";return a===void 0&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(s):this.resolveDataElementOptions(a||0,s)}getContext(a,n,s){let i=this.getDataset(),l;if(a>=0&&a<this._cachedMeta.data.length){let u=this._cachedMeta.data[a];l=u.$context||(u.$context=IO(this.getContext(),a,u)),l.parsed=this.getParsed(a),l.raw=i.data[a],l.index=l.dataIndex=a}else l=this.$context||(this.$context=MO(this.chart.getContext(),this.index)),l.dataset=i,l.index=l.datasetIndex=this.index;return l.active=!!n,l.mode=s,l}resolveDatasetElementOptions(a){return this._resolveElementOptions(this.datasetElementType.id,a)}resolveDataElementOptions(a,n){return this._resolveElementOptions(this.dataElementType.id,n,a)}_resolveElementOptions(a,n="default",s){let i=n==="active",l=this._cachedDataOpts,u=a+"-"+n,d=l[u],p=this.enableOptionSharing&&Pu(s);if(d)return Qk(d,p);let h=this.chart.config,g=h.datasetElementScopeKeys(this._type,a),b=i?[`${a}Hover`,"hover",a,""]:[a,""],y=h.getOptionScopes(this.getDataset(),g),v=Object.keys(Jt.elements[a]),T=()=>this.getContext(s,i,n),M=h.resolveNamedOptions(y,v,T,b);if(M.$shared)M.$shared=p,l[u]=Object.freeze(Qk(M,p));return M}_resolveAnimations(a,n,s){let i=this.chart,l=this._cachedDataOpts,u=`animation-${n}`,d=l[u];if(d)return d;let p;if(i.options.animation!==!1){let g=this.chart.config,b=g.datasetAnimationScopeKeys(this._type,n),y=g.getOptionScopes(this.getDataset(),b);p=g.createResolver(y,this.getContext(a,s,n))}let h=new Av(i,p&&p.animations);if(p&&p._cacheable)l[u]=Object.freeze(h);return h}getSharedOptions(a){if(!a.$shared)return;return this._sharedOptions||(this._sharedOptions=Object.assign({},a))}includeOptions(a,n){return!n||fv(a)||this.chart._animationsDisabled}_getSharedOptions(a,n){let s=this.resolveDataElementOptions(a,n),i=this._sharedOptions,l=this.getSharedOptions(s),u=this.includeOptions(n,l)||l!==i;return this.updateSharedOptions(l,n,s),{sharedOptions:l,includeOptions:u}}updateElement(a,n,s,i){if(fv(i))Object.assign(a,s);else this._resolveAnimations(n,i).update(a,s)}updateSharedOptions(a,n,s){if(a&&!fv(n))this._resolveAnimations(void 0,n).update(a,s)}_setStyle(a,n,s,i){a.active=i;let l=this.getStyle(n,i);this._resolveAnimations(n,s,i).update(a,{options:!i&&this.getSharedOptions(l)||l})}removeHoverStyle(a,n,s){this._setStyle(a,s,"active",!1)}setHoverStyle(a,n,s){this._setStyle(a,s,"active",!0)}_removeDatasetHoverStyle(){let a=this._cachedMeta.dataset;if(a)this._setStyle(a,void 0,"active",!1)}_setDatasetHoverStyle(){let a=this._cachedMeta.dataset;if(a)this._setStyle(a,void 0,"active",!0)}_resyncElements(a){let n=this._data,s=this._cachedMeta.data;for(let[d,p,h]of this._syncList)this[d](p,h);this._syncList=[];let i=s.length,l=n.length,u=Math.min(l,i);if(u)this.parse(0,u);if(l>i)this._insertElements(i,l-i,a);else if(l<i)this._removeElements(l,i-l)}_insertElements(a,n,s=!0){let i=this._cachedMeta,l=i.data,u=a+n,d,p=(h)=>{h.length+=n;for(d=h.length-1;d>=u;d--)h[d]=h[d-n]};p(l);for(d=a;d<u;++d)l[d]=new this.dataElementType;if(this._parsing)p(i._parsed);if(this.parse(a,n),s)this.updateElements(l,a,n,"reset")}updateElements(a,n,s,i){}_removeElements(a,n){let s=this._cachedMeta;if(this._parsing){let i=s._parsed.splice(a,n);if(s._stacked)Ud(s,i)}s.data.splice(a,n)}_sync(a){if(this._parsing)this._syncList.push(a);else{let[n,s,i]=a;this[n](s,i)}this.chart._dataChanges.push([this.index,...a])}_onDataPush(){let a=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-a,a])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(a,n){if(n)this._sync(["_removeElements",a,n]);let s=arguments.length-2;if(s)this._sync(["_insertElements",a,s])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}function RO(a,n){if(!a._cache.$bar){let s=a.getMatchingVisibleMetas(n),i=[];for(let l=0,u=s.length;l<u;l++)i=i.concat(s[l].controller.getAllParsedValues(a));a._cache.$bar=Gx(i.sort((l,u)=>l-u))}return a._cache.$bar}function _O(a){let n=a.iScale,s=RO(n,a.type),i=n._length,l,u,d,p,h=()=>{if(d===32767||d===-32768)return;if(Pu(p))i=Math.min(i,Math.abs(d-p)||i);p=d};for(l=0,u=s.length;l<u;++l)d=n.getPixelForValue(s[l]),h();p=void 0;for(l=0,u=n.ticks.length;l<u;++l)d=n.getPixelForTick(l),h();return i}function DO(a,n,s,i){let l=s.barThickness,u,d;if(ht(l))u=n.min*s.categoryPercentage,d=s.barPercentage;else u=l*i,d=1;return{chunk:u/i,ratio:d,start:n.pixels[a]-u/2}}function EO(a,n,s,i){let l=n.pixels,u=l[a],d=a>0?l[a-1]:null,p=a<l.length-1?l[a+1]:null,h=s.categoryPercentage;if(d===null)d=u-(p===null?n.end-n.start:p-u);if(p===null)p=u+u-d;let g=u-(u-Math.min(d,p))/2*h;return{chunk:Math.abs(p-d)/2*h/i,ratio:s.barPercentage,start:g}}function OO(a,n,s,i){let l=s.parse(a[0],i),u=s.parse(a[1],i),d=Math.min(l,u),p=Math.max(l,u),h=d,g=p;if(Math.abs(d)>Math.abs(p))h=p,g=d;n[s.axis]=g,n._custom={barStart:h,barEnd:g,start:l,end:u,min:d,max:p}}function GM(a,n,s,i){if(zt(a))OO(a,n,s,i);else n[s.axis]=s.parse(a,i);return n}function Kk(a,n,s,i){let{iScale:l,vScale:u}=a,d=l.getLabels(),p=l===u,h=[],g,b,y,v;for(g=s,b=s+i;g<b;++g)v=n[g],y={},y[l.axis]=p||l.parse(d[g],g),h.push(GM(v,y,u,g));return h}function pv(a){return a&&a.barStart!==void 0&&a.barEnd!==void 0}function PO(a,n,s){if(a!==0)return Ln(a);return(n.isHorizontal()?1:-1)*(n.min>=s?1:-1)}function BO(a){let n,s,i,l,u;if(a.horizontal)n=a.base>a.x,s="left",i="right";else n=a.base<a.y,s="bottom",i="top";if(n)l="end",u="start";else l="start",u="end";return{start:s,end:i,reverse:n,top:l,bottom:u}}function NO(a,n,s,i){let l=n.borderSkipped,u={};if(!l){a.borderSkipped=u;return}if(l===!0){a.borderSkipped={top:!0,right:!0,bottom:!0,left:!0};return}let{start:d,end:p,reverse:h,top:g,bottom:b}=BO(a);if(l==="middle"&&s)if(a.enableBorderRadius=!0,(s._top||0)===i)l=g;else if((s._bottom||0)===i)l=b;else u[Jk(b,d,p,h)]=!0,l=g;u[Jk(l,d,p,h)]=!0,a.borderSkipped=u}function Jk(a,n,s,i){if(i)a=zO(a,n,s),a=eM(a,s,n);else a=eM(a,n,s);return a}function zO(a,n,s){return a===n?s:a===s?n:a}function eM(a,n,s){return a==="start"?n:a==="end"?s:a}function HO(a,{inflateAmount:n},s){a.inflateAmount=n==="auto"?s===1?0.33:0:n}class Rv extends vm{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:0.8,barPercentage:0.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(a,n,s,i){return Kk(a,n,s,i)}parseArrayData(a,n,s,i){return Kk(a,n,s,i)}parseObjectData(a,n,s,i){let{iScale:l,vScale:u}=a,{xAxisKey:d="x",yAxisKey:p="y"}=this._parsing,h=l.axis==="x"?d:p,g=u.axis==="x"?d:p,b=[],y,v,T,M;for(y=s,v=s+i;y<v;++y)M=n[y],T={},T[l.axis]=l.parse(rl(M,h),y),b.push(GM(rl(M,g),T,u,y));return b}updateRangeFromParsed(a,n,s,i){super.updateRangeFromParsed(a,n,s,i);let l=s._custom;if(l&&n===this._cachedMeta.vScale)a.min=Math.min(a.min,l.min),a.max=Math.max(a.max,l.max)}getMaxOverflow(){return 0}getLabelAndValue(a){let n=this._cachedMeta,{iScale:s,vScale:i}=n,l=this.getParsed(a),u=l._custom,d=pv(u)?"["+u.start+", "+u.end+"]":""+i.getLabelForValue(l[i.axis]);return{label:""+s.getLabelForValue(l[s.axis]),value:d}}initialize(){this.enableOptionSharing=!0,super.initialize();let a=this._cachedMeta;a.stack=this.getDataset().stack}update(a){let n=this._cachedMeta;this.updateElements(n.data,0,n.data.length,a)}updateElements(a,n,s,i){let l=i==="reset",{index:u,_cachedMeta:{vScale:d}}=this,p=d.getBasePixel(),h=d.isHorizontal(),g=this._getRuler(),{sharedOptions:b,includeOptions:y}=this._getSharedOptions(n,i);for(let v=n;v<n+s;v++){let T=this.getParsed(v),M=l||ht(T[d.axis])?{base:p,head:p}:this._calculateBarValuePixels(v),I=this._calculateBarIndexPixels(v,g),w=(T._stacks||{})[d.axis],A={horizontal:h,base:M.base,enableBorderRadius:!w||pv(T._custom)||u===w._top||u===w._bottom,x:h?M.head:I.center,y:h?I.center:M.head,height:h?I.size:Math.abs(M.size),width:h?Math.abs(M.size):I.size};if(y)A.options=b||this.resolveDataElementOptions(v,a[v].active?"active":i);let B=A.options||a[v].options;NO(A,B,w,u),HO(A,B,g.ratio),this.updateElement(a[v],v,A,i)}}_getStacks(a,n){let{iScale:s}=this._cachedMeta,i=s.getMatchingVisibleMetas(this._type).filter((g)=>g.controller.options.grouped),l=s.options.stacked,u=[],d=this._cachedMeta.controller.getParsed(n),p=d&&d[s.axis],h=(g)=>{let b=g._parsed.find((v)=>v[s.axis]===p),y=b&&b[g.vScale.axis];if(ht(y)||isNaN(y))return!0};for(let g of i){if(n!==void 0&&h(g))continue;if(l===!1||u.indexOf(g.stack)===-1||l===void 0&&g.stack===void 0)u.push(g.stack);if(g.index===a)break}if(!u.length)u.push(void 0);return u}_getStackCount(a){return this._getStacks(void 0,a).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){let a=this.chart.scales,n=this.chart.options.indexAxis;return Object.keys(a).filter((s)=>a[s].axis===n).shift()}_getAxis(){let a={},n=this.getFirstScaleIdForIndexAxis();for(let s of this.chart.data.datasets)a[Ke(this.chart.options.indexAxis==="x"?s.xAxisID:s.yAxisID,n)]=!0;return Object.keys(a)}_getStackIndex(a,n,s){let i=this._getStacks(a,s),l=n!==void 0?i.indexOf(n):-1;return l===-1?i.length-1:l}_getRuler(){let a=this.options,n=this._cachedMeta,s=n.iScale,i=[],l,u;for(l=0,u=n.data.length;l<u;++l)i.push(s.getPixelForValue(this.getParsed(l)[s.axis],l));let d=a.barThickness;return{min:d||_O(n),pixels:i,start:s._startPixel,end:s._endPixel,stackCount:this._getStackCount(),scale:s,grouped:a.grouped,ratio:d?1:a.categoryPercentage*a.barPercentage}}_calculateBarValuePixels(a){let{_cachedMeta:{vScale:n,_stacked:s,index:i},options:{base:l,minBarLength:u}}=this,d=l||0,p=this.getParsed(a),h=p._custom,g=pv(h),b=p[n.axis],y=0,v=s?this.applyStack(n,p,s):b,T,M;if(v!==b)y=v-b,v=b;if(g){if(b=h.barStart,v=h.barEnd-h.barStart,b!==0&&Ln(b)!==Ln(h.barEnd))y=0;y+=b}let I=!ht(l)&&!g?l:y,w=n.getPixelForValue(I);if(this.chart.getDataVisibility(a))T=n.getPixelForValue(y+v);else T=w;if(M=T-w,Math.abs(M)<u){if(M=PO(M,n,d)*u,b===d)w-=M/2;let A=n.getPixelForDecimal(0),B=n.getPixelForDecimal(1),z=Math.min(A,B),H=Math.max(A,B);if(w=Math.max(Math.min(w,H),z),T=w+M,s&&!g)p._stacks[n.axis]._visualValues[i]=n.getValueForPixel(T)-n.getValueForPixel(w)}if(w===n.getPixelForValue(d)){let A=Ln(M)*n.getLineWidthForValue(d)/2;w+=A,M-=A}return{size:M,base:w,head:T,center:T+M/2}}_calculateBarIndexPixels(a,n){let s=n.scale,i=this.options,l=i.skipNull,u=Ke(i.maxBarThickness,1/0),d,p,h=this._getAxisCount();if(n.grouped){let g=l?this._getStackCount(a):n.stackCount,b=i.barThickness==="flex"?EO(a,n,i,g*h):DO(a,n,i,g*h),y=this.chart.options.indexAxis==="x"?this.getDataset().xAxisID:this.getDataset().yAxisID,v=this._getAxis().indexOf(Ke(y,this.getFirstScaleIdForIndexAxis())),T=this._getStackIndex(this.index,this._cachedMeta.stack,l?a:void 0)+v;d=b.start+b.chunk*T+b.chunk/2,p=Math.min(u,b.chunk*b.ratio)}else d=s.getPixelForValue(this.getParsed(a)[s.axis],a),p=Math.min(u,n.min*n.ratio);return{base:d-p/2,head:d+p/2,center:d,size:p}}draw(){let a=this._cachedMeta,{vScale:n,data:s}=a,i=s.length,l=0;for(;l<i;++l)if(this.getParsed(l)[n.axis]!==null&&!s[l].hidden)s[l].draw(this._ctx)}}class _v extends vm{static id="line";static defaults={datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1};static overrides={scales:{_index_:{type:"category"},_value_:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(a){let n=this._cachedMeta,{dataset:s,data:i=[],_dataset:l}=n,u=this.chart._animationsDisabled,{start:d,count:p}=Mk(n,i,u);if(this._drawStart=d,this._drawCount=p,Ik(n))d=0,p=i.length;s._chart=this.chart,s._datasetIndex=this.index,s._decimated=!!l._decimated,s.points=i;let h=this.resolveDatasetElementOptions(a);if(!this.options.showLine)h.borderWidth=0;h.segment=this.options.segment,this.updateElement(s,void 0,{animated:!u,options:h},a),this.updateElements(i,d,p,a)}updateElements(a,n,s,i){let l=i==="reset",{iScale:u,vScale:d,_stacked:p,_dataset:h}=this._cachedMeta,{sharedOptions:g,includeOptions:b}=this._getSharedOptions(n,i),y=u.axis,v=d.axis,{spanGaps:T,segment:M}=this.options,I=Nu(T)?T:Number.POSITIVE_INFINITY,w=this.chart._animationsDisabled||l||i==="none",A=n+s,B=a.length,z=n>0&&this.getParsed(n-1);for(let H=0;H<B;++H){let V=a[H],G=w?V:{};if(H<n||H>=A){G.skip=!0;continue}let X=this.getParsed(H),Y=ht(X[v]),J=G[y]=u.getPixelForValue(X[y],H),j=G[v]=l||Y?d.getBasePixel():d.getPixelForValue(p?this.applyStack(d,X,p):X[v],H);if(G.skip=isNaN(J)||isNaN(j)||Y,G.stop=H>0&&Math.abs(X[y]-z[y])>I,M)G.parsed=X,G.raw=h.data[H];if(b)G.options=g||this.resolveDataElementOptions(H,V.active?"active":i);if(!w)this.updateElement(V,H,G,i);z=X}}getMaxOverflow(){let a=this._cachedMeta,n=a.dataset,s=n.options&&n.options.borderWidth||0,i=a.data||[];if(!i.length)return s;let l=i[0].size(this.resolveDataElementOptions(0)),u=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(s,l,u)/2}draw(){let a=this._cachedMeta;a.dataset.updateControlPoints(this.chart.chartArea,a.iScale.axis),super.draw()}}function ll(){throw Error("This method is not implemented: Check that a complete date adapter is provided.")}class Dv{static override(a){Object.assign(Dv.prototype,a)}options;constructor(a){this.options=a||{}}init(){}formats(){return ll()}parse(){return ll()}format(){return ll()}add(){return ll()}diff(){return ll()}startOf(){return ll()}endOf(){return ll()}}var UO={_date:Dv};function FO(a,n,s,i){let{controller:l,data:u,_sorted:d}=a,p=l._cachedMeta.iScale,h=a.dataset?a.dataset.options?a.dataset.options.spanGaps:null:null;if(p&&n===p.axis&&n!=="r"&&d&&u.length){let g=p._reversePixels?Sk:Zr;if(!i){let b=g(u,n,s);if(h){let{vScale:y}=l._cachedMeta,{_parsed:v}=a,T=v.slice(0,b.lo+1).reverse().findIndex((I)=>!ht(I[y.axis]));b.lo-=Math.max(0,T);let M=v.slice(b.hi).findIndex((I)=>!ht(I[y.axis]));b.hi+=Math.max(0,M)}return b}else if(l._sharedOptions){let b=u[0],y=typeof b.getRange==="function"&&b.getRange(n);if(y){let v=g(u,n,s-y),T=g(u,n,s+y);return{lo:v.lo,hi:T.hi}}}}return{lo:0,hi:u.length-1}}function Qd(a,n,s,i,l){let u=a.getSortedVisibleDatasetMetas(),d=s[n];for(let p=0,h=u.length;p<h;++p){let{index:g,data:b}=u[p],{lo:y,hi:v}=FO(u[p],n,d,l);for(let T=y;T<=v;++T){let M=b[T];if(!M.skip)i(M,g,T)}}}function qO(a){let n=a.indexOf("x")!==-1,s=a.indexOf("y")!==-1;return function(i,l){let u=n?Math.abs(i.x-l.x):0,d=s?Math.abs(i.y-l.y):0;return Math.sqrt(Math.pow(u,2)+Math.pow(d,2))}}function hv(a,n,s,i,l){let u=[];if(!l&&!a.isPointInArea(n))return u;return Qd(a,s,n,function(p,h,g){if(!l&&!as(p,a.chartArea,0))return;if(p.inRange(n.x,n.y,i))u.push({element:p,datasetIndex:h,index:g})},!0),u}function VO(a,n,s,i){let l=[];function u(d,p,h){let{startAngle:g,endAngle:b}=d.getProps(["startAngle","endAngle"],i),{angle:y}=xk(d,{x:n.x,y:n.y});if(Vx(y,g,b))l.push({element:d,datasetIndex:p,index:h})}return Qd(a,s,n,u),l}function jO(a,n,s,i,l,u){let d=[],p=qO(s),h=Number.POSITIVE_INFINITY;function g(b,y,v){let T=b.inRange(n.x,n.y,l);if(i&&!T)return;let M=b.getCenterPoint(l);if(!(!!u||a.isPointInArea(M))&&!T)return;let w=p(n,M);if(w<h)d=[{element:b,datasetIndex:y,index:v}],h=w;else if(w===h)d.push({element:b,datasetIndex:y,index:v})}return Qd(a,s,n,g),d}function mv(a,n,s,i,l,u){if(!u&&!a.isPointInArea(n))return[];return s==="r"&&!i?VO(a,n,s,l):jO(a,n,s,i,l,u)}function tM(a,n,s,i,l){let u=[],d=s==="x"?"inXRange":"inYRange",p=!1;if(Qd(a,s,n,(h,g,b)=>{if(h[d]&&h[d](n[s],l))u.push({element:h,datasetIndex:g,index:b}),p=p||h.inRange(n.x,n.y,l)}),i&&!p)return[];return u}var GO={evaluateInteractionItems:Qd,modes:{index(a,n,s,i){let l=ai(n,a),u=s.axis||"x",d=s.includeInvisible||!1,p=s.intersect?hv(a,l,u,i,d):mv(a,l,u,!1,i,d),h=[];if(!p.length)return[];return a.getSortedVisibleDatasetMetas().forEach((g)=>{let b=p[0].index,y=g.data[b];if(y&&!y.skip)h.push({element:y,datasetIndex:g.index,index:b})}),h},dataset(a,n,s,i){let l=ai(n,a),u=s.axis||"xy",d=s.includeInvisible||!1,p=s.intersect?hv(a,l,u,i,d):mv(a,l,u,!1,i,d);if(p.length>0){let h=p[0].datasetIndex,g=a.getDatasetMeta(h).data;p=[];for(let b=0;b<g.length;++b)p.push({element:g[b],datasetIndex:h,index:b})}return p},point(a,n,s,i){let l=ai(n,a),u=s.axis||"xy",d=s.includeInvisible||!1;return hv(a,l,u,i,d)},nearest(a,n,s,i){let l=ai(n,a),u=s.axis||"xy",d=s.includeInvisible||!1;return mv(a,l,u,s.intersect,i,d)},x(a,n,s,i){let l=ai(n,a);return tM(a,l,"x",s.intersect,i)},y(a,n,s,i){let l=ai(n,a);return tM(a,l,"y",s.intersect,i)}}},XM=["left","top","right","bottom"];function Fd(a,n){return a.filter((s)=>s.pos===n)}function aM(a,n){return a.filter((s)=>XM.indexOf(s.pos)===-1&&s.box.axis===n)}function qd(a,n){return a.sort((s,i)=>{let l=n?i:s,u=n?s:i;return l.weight===u.weight?l.index-u.index:l.weight-u.weight})}function XO(a){let n=[],s,i,l,u,d,p;for(s=0,i=(a||[]).length;s<i;++s)l=a[s],{position:u,options:{stack:d,stackWeight:p=1}}=l,n.push({index:s,box:l,pos:u,horizontal:l.isHorizontal(),weight:l.weight,stack:d&&u+d,stackWeight:p});return n}function YO(a){let n={};for(let s of a){let{stack:i,pos:l,stackWeight:u}=s;if(!i||!XM.includes(l))continue;let d=n[i]||(n[i]={count:0,placed:0,weight:0,size:0});d.count++,d.weight+=u}return n}function $O(a,n){let s=YO(a),{vBoxMaxWidth:i,hBoxMaxHeight:l}=n,u,d,p;for(u=0,d=a.length;u<d;++u){p=a[u];let{fullSize:h}=p.box,g=s[p.stack],b=g&&p.stackWeight/g.weight;if(p.horizontal)p.width=b?b*i:h&&n.availableWidth,p.height=l;else p.width=i,p.height=b?b*l:h&&n.availableHeight}return s}function WO(a){let n=XO(a),s=qd(n.filter((g)=>g.box.fullSize),!0),i=qd(Fd(n,"left"),!0),l=qd(Fd(n,"right")),u=qd(Fd(n,"top"),!0),d=qd(Fd(n,"bottom")),p=aM(n,"x"),h=aM(n,"y");return{fullSize:s,leftAndTop:i.concat(u),rightAndBottom:l.concat(h).concat(d).concat(p),chartArea:Fd(n,"chartArea"),vertical:i.concat(l).concat(h),horizontal:u.concat(d).concat(p)}}function oM(a,n,s,i){return Math.max(a[s],n[s])+Math.max(a[i],n[i])}function YM(a,n){a.top=Math.max(a.top,n.top),a.left=Math.max(a.left,n.left),a.bottom=Math.max(a.bottom,n.bottom),a.right=Math.max(a.right,n.right)}function ZO(a,n,s,i){let{pos:l,box:u}=s,d=a.maxPadding;if(!it(l)){if(s.size)a[l]-=s.size;let y=i[s.stack]||{size:0,count:1};y.size=Math.max(y.size,s.horizontal?u.height:u.width),s.size=y.size/y.count,a[l]+=s.size}if(u.getPadding)YM(d,u.getPadding());let p=Math.max(0,n.outerWidth-oM(d,a,"left","right")),h=Math.max(0,n.outerHeight-oM(d,a,"top","bottom")),g=p!==a.w,b=h!==a.h;return a.w=p,a.h=h,s.horizontal?{same:g,other:b}:{same:b,other:g}}function QO(a){let n=a.maxPadding;function s(i){let l=Math.max(n[i]-a[i],0);return a[i]+=l,l}a.y+=s("top"),a.x+=s("left"),s("right"),s("bottom")}function KO(a,n){let s=n.maxPadding;function i(l){let u={left:0,top:0,right:0,bottom:0};return l.forEach((d)=>{u[d]=Math.max(n[d],s[d])}),u}return a?i(["left","right"]):i(["top","bottom"])}function Gd(a,n,s,i){let l=[],u,d,p,h,g,b;for(u=0,d=a.length,g=0;u<d;++u){p=a[u],h=p.box,h.update(p.width||n.w,p.height||n.h,KO(p.horizontal,n));let{same:y,other:v}=ZO(n,s,p,i);if(g|=y&&l.length,b=b||v,!h.fullSize)l.push(p)}return g&&Gd(l,n,s,i)||b}function fm(a,n,s,i,l){a.top=s,a.left=n,a.right=n+i,a.bottom=s+l,a.width=i,a.height=l}function nM(a,n,s,i){let l=s.padding,{x:u,y:d}=n;for(let p of a){let h=p.box,g=i[p.stack]||{count:1,placed:0,weight:1},b=p.stackWeight/g.weight||1;if(p.horizontal){let y=n.w*b,v=g.size||h.height;if(Pu(g.start))d=g.start;if(h.fullSize)fm(h,l.left,d,s.outerWidth-l.right-l.left,v);else fm(h,n.left+g.placed,d,y,v);g.start=d,g.placed+=y,d=h.bottom}else{let y=n.h*b,v=g.size||h.width;if(Pu(g.start))u=g.start;if(h.fullSize)fm(h,u,l.top,v,s.outerHeight-l.bottom-l.top);else fm(h,u,n.top+g.placed,v,y);g.start=u,g.placed+=y,u=h.right}}n.x=u,n.y=d}var nn={addBox(a,n){if(!a.boxes)a.boxes=[];n.fullSize=n.fullSize||!1,n.position=n.position||"top",n.weight=n.weight||0,n._layers=n._layers||function(){return[{z:0,draw(s){n.draw(s)}}]},a.boxes.push(n)},removeBox(a,n){let s=a.boxes?a.boxes.indexOf(n):-1;if(s!==-1)a.boxes.splice(s,1)},configure(a,n,s){n.fullSize=s.fullSize,n.position=s.position,n.weight=s.weight},update(a,n,s,i){if(!a)return;let l=Na(a.options.layout.padding),u=Math.max(n-l.width,0),d=Math.max(s-l.height,0),p=WO(a.boxes),{vertical:h,horizontal:g}=p;Lt(a.boxes,(I)=>{if(typeof I.beforeLayout==="function")I.beforeLayout()});let b=h.reduce((I,w)=>w.box.options&&w.box.options.display===!1?I:I+1,0)||1,y=Object.freeze({outerWidth:n,outerHeight:s,padding:l,availableWidth:u,availableHeight:d,vBoxMaxWidth:u/2/b,hBoxMaxHeight:d/2}),v=Object.assign({},l);YM(v,Na(i));let T=Object.assign({maxPadding:v,w:u,h:d,x:l.left,y:l.top},l),M=$O(h.concat(g),y);if(Gd(p.fullSize,T,y,M),Gd(h,T,y,M),Gd(g,T,y,M))Gd(h,T,y,M);QO(T),nM(p.leftAndTop,T,y,M),T.x+=T.w,T.y+=T.h,nM(p.rightAndBottom,T,y,M),a.chartArea={left:T.left,top:T.top,right:T.left+T.w,bottom:T.top+T.h,height:T.h,width:T.w},Lt(p.chartArea,(I)=>{let w=I.box;Object.assign(w,a.chartArea),w.update(T.w,T.h,{left:0,top:0,right:0,bottom:0})})}};class Ev{acquireContext(a,n){}releaseContext(a){return!1}addEventListener(a,n,s){}removeEventListener(a,n,s){}getDevicePixelRatio(){return 1}getMaximumSize(a,n,s,i){return n=Math.max(0,n||a.width),s=s||a.height,{width:n,height:Math.max(0,i?Math.floor(n/i):s)}}isAttached(a){return!0}updateConfig(a){}}class $M extends Ev{acquireContext(a){return a&&a.getContext&&a.getContext("2d")||null}updateConfig(a){a.options.animation=!1}}var ym="$chartjs",JO={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},sM=(a)=>a===null||a==="";function eP(a,n){let s=a.style,i=a.getAttribute("height"),l=a.getAttribute("width");if(a[ym]={initial:{height:i,width:l,style:{display:s.display,height:s.height,width:s.width}}},s.display=s.display||"block",s.boxSizing=s.boxSizing||"border-box",sM(l)){let u=nv(a,"width");if(u!==void 0)a.width=u}if(sM(i))if(a.style.height==="")a.height=a.width/(n||2);else{let u=nv(a,"height");if(u!==void 0)a.height=u}return a}var WM=Fk?{passive:!0}:!1;function tP(a,n,s){if(a)a.addEventListener(n,s,WM)}function aP(a,n,s){if(a&&a.canvas)a.canvas.removeEventListener(n,s,WM)}function oP(a,n){let s=JO[a.type]||a.type,{x:i,y:l}=ai(a,n);return{type:s,chart:n,native:a,x:i!==void 0?i:null,y:l!==void 0?l:null}}function xm(a,n){for(let s of a)if(s===n||s.contains(n))return!0}function nP(a,n,s){let i=a.canvas,l=new MutationObserver((u)=>{let d=!1;for(let p of u)d=d||xm(p.addedNodes,i),d=d&&!xm(p.removedNodes,i);if(d)s()});return l.observe(document,{childList:!0,subtree:!0}),l}function sP(a,n,s){let i=a.canvas,l=new MutationObserver((u)=>{let d=!1;for(let p of u)d=d||xm(p.removedNodes,i),d=d&&!xm(p.addedNodes,i);if(d)s()});return l.observe(document,{childList:!0,subtree:!0}),l}var $d=new Map,rM=0;function ZM(){let a=window.devicePixelRatio;if(a===rM)return;rM=a,$d.forEach((n,s)=>{if(s.currentDevicePixelRatio!==a)n()})}function rP(a,n){if(!$d.size)window.addEventListener("resize",ZM);$d.set(a,n)}function iP(a){if($d.delete(a),!$d.size)window.removeEventListener("resize",ZM)}function lP(a,n,s){let i=a.canvas,l=i&&cm(i);if(!l)return;let u=Yx((p,h)=>{let g=l.clientWidth;if(s(p,h),g<l.clientWidth)s()},window),d=new ResizeObserver((p)=>{let h=p[0],g=h.contentRect.width,b=h.contentRect.height;if(g===0&&b===0)return;u(g,b)});return d.observe(l),rP(a,u),d}function gv(a,n,s){if(s)s.disconnect();if(n==="resize")iP(a)}function uP(a,n,s){let i=a.canvas,l=Yx((u)=>{if(a.ctx!==null)s(oP(u,a))},a);return tP(i,n,l),l}class QM extends Ev{acquireContext(a,n){let s=a&&a.getContext&&a.getContext("2d");if(s&&s.canvas===a)return eP(a,n),s;return null}releaseContext(a){let n=a.canvas;if(!n[ym])return!1;let s=n[ym].initial;["height","width"].forEach((l)=>{let u=s[l];if(ht(u))n.removeAttribute(l);else n.setAttribute(l,u)});let i=s.style||{};return Object.keys(i).forEach((l)=>{n.style[l]=i[l]}),n.width=n.width,delete n[ym],!0}addEventListener(a,n,s){this.removeEventListener(a,n);let i=a.$proxies||(a.$proxies={}),u={attach:nP,detach:sP,resize:lP}[n]||uP;i[n]=u(a,n,s)}removeEventListener(a,n){let s=a.$proxies||(a.$proxies={}),i=s[n];if(!i)return;({attach:gv,detach:gv,resize:gv}[n]||aP)(a,n,i),s[n]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(a,n,s,i){return Uk(a,n,s,i)}isAttached(a){let n=a&&cm(a);return!!(n&&n.isConnected)}}function cP(a){if(!um()||typeof OffscreenCanvas<"u"&&a instanceof OffscreenCanvas)return $M;return QM}class Xs{static defaults={};static defaultRoutes=void 0;x;y;active=!1;options;$animations;tooltipPosition(a){let{x:n,y:s}=this.getProps(["x","y"],a);return{x:n,y:s}}hasValue(){return Nu(this.x)&&Nu(this.y)}getProps(a,n){let s=this.$animations;if(!n||!s)return this;let i={};return a.forEach((l)=>{i[l]=s[l]&&s[l].active()?s[l]._to:this[l]}),i}}function dP(a,n){let s=a.options.ticks,i=fP(a),l=Math.min(s.maxTicksLimit||i,i),u=s.major.enabled?hP(n):[],d=u.length,p=u[0],h=u[d-1],g=[];if(d>l)return mP(n,g,u,d/l),g;let b=pP(u,n,l);if(d>0){let y,v,T=d>1?Math.round((h-p)/(d-1)):null;pm(n,g,b,ht(T)?0:p-T,p);for(y=0,v=d-1;y<v;y++)pm(n,g,b,u[y],u[y+1]);return pm(n,g,b,h,ht(T)?n.length:h+T),g}return pm(n,g,b),g}function fP(a){let n=a.options.offset,s=a._tickSize(),i=a._length/s+(n?0:1),l=a._maxLength/s;return Math.floor(Math.min(i,l))}function pP(a,n,s){let i=gP(a),l=n.length/s;if(!i)return Math.max(l,1);let u=yk(i);for(let d=0,p=u.length-1;d<p;d++){let h=u[d];if(h>l)return h}return Math.max(l,1)}function hP(a){let n=[],s,i;for(s=0,i=a.length;s<i;s++)if(a[s].major)n.push(s);return n}function mP(a,n,s,i){let l=0,u=s[0],d;i=Math.ceil(i);for(d=0;d<a.length;d++)if(d===u)n.push(a[d]),l++,u=s[l*i]}function pm(a,n,s,i,l){let u=Ke(i,0),d=Math.min(Ke(l,a.length),a.length),p=0,h,g,b;if(s=Math.ceil(s),l)h=l-i,s=h/Math.floor(h/s);b=u;while(b<0)p++,b=Math.round(u+p*s);for(g=Math.max(u,0);g<d;g++)if(g===b)n.push(a[g]),p++,b=Math.round(u+p*s)}function gP(a){let n=a.length,s,i;if(n<2)return!1;for(i=a[0],s=1;s<n;++s)if(a[s]-a[s-1]!==i)return!1;return i}var yP=(a)=>a==="left"?"right":a==="right"?"left":a,iM=(a,n,s)=>n==="top"||n==="left"?a[n]+s:a[n]-s,lM=(a,n)=>Math.min(n||a,a);function uM(a,n){let s=[],i=a.length/n,l=a.length,u=0;for(;u<l;u+=i)s.push(a[Math.floor(u)]);return s}function bP(a,n,s){let i=a.ticks.length,l=Math.min(n,i-1),{_startPixel:u,_endPixel:d}=a,p=0.000001,h=a.getPixelForTick(l),g;if(s){if(i===1)g=Math.max(h-u,d-h);else if(n===0)g=(a.getPixelForTick(1)-h)/2;else g=(h-a.getPixelForTick(l-1))/2;if(h+=l<n?g:-g,h<u-0.000001||h>d+0.000001)return}return h}function xP(a,n){Lt(a,(s)=>{let i=s.gc,l=i.length/2,u;if(l>n){for(u=0;u<l;++u)delete s.data[i[u]];i.splice(0,l)}})}function Vd(a){return a.drawTicks?a.tickLength:0}function cM(a,n){if(!a.display)return 0;let s=pa(a.font,n),i=Na(a.padding);return(zt(a.text)?a.text.length:1)*s.lineHeight+i.height}function vP(a,n){return Vs(a,{scale:n,type:"scale"})}function SP(a,n,s){return Vs(a,{tick:s,index:n,type:"tick"})}function LP(a,n,s){let i=nm(a);if(s&&n!=="right"||!s&&n==="right")i=yP(i);return i}function CP(a,n,s,i){let{top:l,left:u,bottom:d,right:p,chart:h}=a,{chartArea:g,scales:b}=h,y=0,v,T,M,I=d-l,w=p-u;if(a.isHorizontal()){if(T=Ba(i,u,p),it(s)){let A=Object.keys(s)[0],B=s[A];M=b[A].getPixelForValue(B)+I-n}else if(s==="center")M=(g.bottom+g.top)/2+I-n;else M=iM(a,s,n);v=p-u}else{if(it(s)){let A=Object.keys(s)[0],B=s[A];T=b[A].getPixelForValue(B)-w+n}else if(s==="center")T=(g.left+g.right)/2-w+n;else T=iM(a,s,n);M=Ba(i,d,l),y=s==="left"?-po:po}return{titleX:T,titleY:M,maxWidth:v,rotation:y}}class cl extends Xs{constructor(a){super();this.id=a.id,this.type=a.type,this.options=void 0,this.ctx=a.ctx,this.chart=a.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(a){this.options=a.setContext(this.getContext()),this.axis=a.axis,this._userMin=this.parse(a.min),this._userMax=this.parse(a.max),this._suggestedMin=this.parse(a.suggestedMin),this._suggestedMax=this.parse(a.suggestedMax)}parse(a,n){return a}getUserBounds(){let{_userMin:a,_userMax:n,_suggestedMin:s,_suggestedMax:i}=this;return a=go(a,Number.POSITIVE_INFINITY),n=go(n,Number.NEGATIVE_INFINITY),s=go(s,Number.POSITIVE_INFINITY),i=go(i,Number.NEGATIVE_INFINITY),{min:go(a,s),max:go(n,i),minDefined:Kt(a),maxDefined:Kt(n)}}getMinMax(a){let{min:n,max:s,minDefined:i,maxDefined:l}=this.getUserBounds(),u;if(i&&l)return{min:n,max:s};let d=this.getMatchingVisibleMetas();for(let p=0,h=d.length;p<h;++p){if(u=d[p].controller.getMinMax(this,a),!i)n=Math.min(n,u.min);if(!l)s=Math.max(s,u.max)}return n=l&&n>s?s:n,s=i&&n>s?n:s,{min:go(n,go(s,n)),max:go(s,go(n,s))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){let a=this.chart.data;return this.options.labels||(this.isHorizontal()?a.xLabels:a.yLabels)||a.labels||[]}getLabelItems(a=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(a))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){Ot(this.options.beforeUpdate,[this])}update(a,n,s){let{beginAtZero:i,grace:l,ticks:u}=this.options,d=u.sampleSize;if(this.beforeUpdate(),this.maxWidth=a,this.maxHeight=n,this._margins=s=Object.assign({left:0,right:0,top:0,bottom:0},s),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+s.left+s.right:this.height+s.top+s.bottom,!this._dataLimitsCached)this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=Ok(this,l,i),this._dataLimitsCached=!0;this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();let p=d<this.ticks.length;if(this._convertTicksToLabels(p?uM(this.ticks,d):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),u.display&&(u.autoSkip||u.source==="auto"))this.ticks=dP(this,this.ticks),this._labelSizes=null,this.afterAutoSkip();if(p)this._convertTicksToLabels(this.ticks);this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let a=this.options.reverse,n,s;if(this.isHorizontal())n=this.left,s=this.right;else n=this.top,s=this.bottom,a=!a;this._startPixel=n,this._endPixel=s,this._reversePixels=a,this._length=s-n,this._alignToPixels=this.options.alignToPixels}afterUpdate(){Ot(this.options.afterUpdate,[this])}beforeSetDimensions(){Ot(this.options.beforeSetDimensions,[this])}setDimensions(){if(this.isHorizontal())this.width=this.maxWidth,this.left=0,this.right=this.width;else this.height=this.maxHeight,this.top=0,this.bottom=this.height;this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){Ot(this.options.afterSetDimensions,[this])}_callHooks(a){this.chart.notifyPlugins(a,this.getContext()),Ot(this.options[a],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){Ot(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(a){let n=this.options.ticks,s,i,l;for(s=0,i=a.length;s<i;s++)l=a[s],l.label=Ot(n.callback,[l.value,s,a],this)}afterTickToLabelConversion(){Ot(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){Ot(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){let a=this.options,n=a.ticks,s=lM(this.ticks.length,a.ticks.maxTicksLimit),i=n.minRotation||0,l=n.maxRotation,u=i,d,p,h;if(!this._isVisible()||!n.display||i>=l||s<=1||!this.isHorizontal()){this.labelRotation=i;return}let g=this._getLabelSizes(),b=g.widest.width,y=g.highest.height,v=mo(this.chart.width-b,0,this.maxWidth);if(d=a.offset?this.maxWidth/s:v/(s-1),b+6>d)d=v/(s-(a.offset?0.5:1)),p=this.maxHeight-Vd(a.grid)-n.padding-cM(a.title,this.chart.options.font),h=Math.sqrt(b*b+y*y),u=am(Math.min(Math.asin(mo((g.highest.height+6)/d,-1,1)),Math.asin(mo(p/h,-1,1))-Math.asin(mo(y/h,-1,1)))),u=Math.max(i,Math.min(l,u));this.labelRotation=u}afterCalculateLabelRotation(){Ot(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){Ot(this.options.beforeFit,[this])}fit(){let a={width:0,height:0},{chart:n,options:{ticks:s,title:i,grid:l}}=this,u=this._isVisible(),d=this.isHorizontal();if(u){let p=cM(i,n.options.font);if(d)a.width=this.maxWidth,a.height=Vd(l)+p;else a.height=this.maxHeight,a.width=Vd(l)+p;if(s.display&&this.ticks.length){let{first:h,last:g,widest:b,highest:y}=this._getLabelSizes(),v=s.padding*2,T=Fs(this.labelRotation),M=Math.cos(T),I=Math.sin(T);if(d){let w=s.mirror?0:I*b.width+M*y.height;a.height=Math.min(this.maxHeight,a.height+w+v)}else{let w=s.mirror?0:M*b.width+I*y.height;a.width=Math.min(this.maxWidth,a.width+w+v)}this._calculatePadding(h,g,I,M)}}if(this._handleMargins(),d)this.width=this._length=n.width-this._margins.left-this._margins.right,this.height=a.height;else this.width=a.width,this.height=this._length=n.height-this._margins.top-this._margins.bottom}_calculatePadding(a,n,s,i){let{ticks:{align:l,padding:u},position:d}=this.options,p=this.labelRotation!==0,h=d!=="top"&&this.axis==="x";if(this.isHorizontal()){let g=this.getPixelForTick(0)-this.left,b=this.right-this.getPixelForTick(this.ticks.length-1),y=0,v=0;if(p)if(h)y=i*a.width,v=s*n.height;else y=s*a.height,v=i*n.width;else if(l==="start")v=n.width;else if(l==="end")y=a.width;else if(l!=="inner")y=a.width/2,v=n.width/2;this.paddingLeft=Math.max((y-g+u)*this.width/(this.width-g),0),this.paddingRight=Math.max((v-b+u)*this.width/(this.width-b),0)}else{let g=n.height/2,b=a.height/2;if(l==="start")g=0,b=a.height;else if(l==="end")g=n.height,b=0;this.paddingTop=g+u,this.paddingBottom=b+u}}_handleMargins(){if(this._margins)this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom)}afterFit(){Ot(this.options.afterFit,[this])}isHorizontal(){let{axis:a,position:n}=this.options;return n==="top"||n==="bottom"||a==="x"}isFullSize(){return this.options.fullSize}_convertTicksToLabels(a){this.beforeTickToLabelConversion(),this.generateTickLabels(a);let n,s;for(n=0,s=a.length;n<s;n++)if(ht(a[n].label))a.splice(n,1),s--,n--;this.afterTickToLabelConversion()}_getLabelSizes(){let a=this._labelSizes;if(!a){let n=this.options.ticks.sampleSize,s=this.ticks;if(n<s.length)s=uM(s,n);this._labelSizes=a=this._computeLabelSizes(s,s.length,this.options.ticks.maxTicksLimit)}return a}_computeLabelSizes(a,n,s){let{ctx:i,_longestTextCache:l}=this,u=[],d=[],p=Math.floor(n/lM(n,s)),h=0,g=0,b,y,v,T,M,I,w,A,B,z,H;for(b=0;b<n;b+=p){if(T=a[b].label,M=this._resolveTickFontOptions(b),i.font=I=M.string,w=l[I]=l[I]||{data:{},gc:[]},A=M.lineHeight,B=z=0,!ht(T)&&!zt(T))B=Od(i,w.data,w.gc,B,T),z=A;else if(zt(T)){for(y=0,v=T.length;y<v;++y)if(H=T[y],!ht(H)&&!zt(H))B=Od(i,w.data,w.gc,B,H),z+=A}u.push(B),d.push(z),h=Math.max(B,h),g=Math.max(z,g)}xP(l,n);let V=u.indexOf(h),G=d.indexOf(g),X=(Y)=>({width:u[Y]||0,height:d[Y]||0});return{first:X(0),last:X(n-1),widest:X(V),highest:X(G),widths:u,heights:d}}getLabelForValue(a){return a}getPixelForValue(a,n){return NaN}getValueForPixel(a){}getPixelForTick(a){let n=this.ticks;if(a<0||a>n.length-1)return null;return this.getPixelForValue(n[a].value)}getPixelForDecimal(a){if(this._reversePixels)a=1-a;let n=this._startPixel+a*this._length;return vk(this._alignToPixels?Jr(this.chart,n,0):n)}getDecimalForPixel(a){let n=(a-this._startPixel)/this._length;return this._reversePixels?1-n:n}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){let{min:a,max:n}=this;return a<0&&n<0?n:a>0&&n>0?a:0}getContext(a){let n=this.ticks||[];if(a>=0&&a<n.length){let s=n[a];return s.$context||(s.$context=SP(this.getContext(),a,s))}return this.$context||(this.$context=vP(this.chart.getContext(),this))}_tickSize(){let a=this.options.ticks,n=Fs(this.labelRotation),s=Math.abs(Math.cos(n)),i=Math.abs(Math.sin(n)),l=this._getLabelSizes(),u=a.autoSkipPadding||0,d=l?l.widest.width+u:0,p=l?l.highest.height+u:0;return this.isHorizontal()?p*s>d*i?d/s:p/i:p*i<d*s?p/s:d/i}_isVisible(){let a=this.options.display;if(a!=="auto")return!!a;return this.getMatchingVisibleMetas().length>0}_computeGridLineItems(a){let n=this.axis,s=this.chart,i=this.options,{grid:l,position:u,border:d}=i,p=l.offset,h=this.isHorizontal(),b=this.ticks.length+(p?1:0),y=Vd(l),v=[],T=d.setContext(this.getContext()),M=T.display?T.width:0,I=M/2,w=function(K){return Jr(s,K,M)},A,B,z,H,V,G,X,Y,J,j,se,ge;if(u==="top")A=w(this.bottom),G=this.bottom-y,Y=A-I,j=w(a.top)+I,ge=a.bottom;else if(u==="bottom")A=w(this.top),j=a.top,ge=w(a.bottom)-I,G=A+I,Y=this.top+y;else if(u==="left")A=w(this.right),V=this.right-y,X=A-I,J=w(a.left)+I,se=a.right;else if(u==="right")A=w(this.left),J=a.left,se=w(a.right)-I,V=A+I,X=this.left+y;else if(n==="x"){if(u==="center")A=w((a.top+a.bottom)/2+0.5);else if(it(u)){let K=Object.keys(u)[0],pe=u[K];A=w(this.chart.scales[K].getPixelForValue(pe))}j=a.top,ge=a.bottom,G=A+I,Y=G+y}else if(n==="y"){if(u==="center")A=w((a.left+a.right)/2);else if(it(u)){let K=Object.keys(u)[0],pe=u[K];A=w(this.chart.scales[K].getPixelForValue(pe))}V=A-I,X=V-y,J=a.left,se=a.right}let ye=Ke(i.ticks.maxTicksLimit,b),Se=Math.max(1,Math.ceil(b/ye));for(B=0;B<b;B+=Se){let K=this.getContext(B),pe=l.setContext(K),be=d.setContext(K),{lineWidth:Ue,color:He}=pe,k=be.dash||[],W=be.dashOffset,{tickWidth:ee,tickColor:ne}=pe,te=pe.tickBorderDash||[],le=pe.tickBorderDashOffset;if(z=bP(this,B,p),z===void 0)continue;if(H=Jr(s,z,Ue),h)V=X=J=se=H;else G=Y=j=ge=H;v.push({tx1:V,ty1:G,tx2:X,ty2:Y,x1:J,y1:j,x2:se,y2:ge,width:Ue,color:He,borderDash:k,borderDashOffset:W,tickWidth:ee,tickColor:ne,tickBorderDash:te,tickBorderDashOffset:le})}return this._ticksLength=b,this._borderValue=A,v}_computeLabelItems(a){let n=this.axis,s=this.options,{position:i,ticks:l}=s,u=this.isHorizontal(),d=this.ticks,{align:p,crossAlign:h,padding:g,mirror:b}=l,y=Vd(s.grid),v=y+g,T=b?-g:v,M=-Fs(this.labelRotation),I=[],w,A,B,z,H,V,G,X,Y,J,j,se,ge="middle";if(i==="top")V=this.bottom-T,G=this._getXAxisLabelAlignment();else if(i==="bottom")V=this.top+T,G=this._getXAxisLabelAlignment();else if(i==="left"){let Se=this._getYAxisLabelAlignment(y);G=Se.textAlign,H=Se.x}else if(i==="right"){let Se=this._getYAxisLabelAlignment(y);G=Se.textAlign,H=Se.x}else if(n==="x"){if(i==="center")V=(a.top+a.bottom)/2+v;else if(it(i)){let Se=Object.keys(i)[0],K=i[Se];V=this.chart.scales[Se].getPixelForValue(K)+v}G=this._getXAxisLabelAlignment()}else if(n==="y"){if(i==="center")H=(a.left+a.right)/2-v;else if(it(i)){let Se=Object.keys(i)[0],K=i[Se];H=this.chart.scales[Se].getPixelForValue(K)}G=this._getYAxisLabelAlignment(y).textAlign}if(n==="y"){if(p==="start")ge="top";else if(p==="end")ge="bottom"}let ye=this._getLabelSizes();for(w=0,A=d.length;w<A;++w){B=d[w],z=B.label;let Se=l.setContext(this.getContext(w));X=this.getPixelForTick(w)+l.labelOffset,Y=this._resolveTickFontOptions(w),J=Y.lineHeight,j=zt(z)?z.length:1;let K=j/2,{color:pe,textStrokeColor:be,textStrokeWidth:Ue}=Se,He=G;if(u){if(H=X,G==="inner")if(w===A-1)He=!this.options.reverse?"right":"left";else if(w===0)He=!this.options.reverse?"left":"right";else He="center";if(i==="top")if(h==="near"||M!==0)se=-j*J+J/2;else if(h==="center")se=-ye.highest.height/2-K*J+J;else se=-ye.highest.height+J/2;else if(h==="near"||M!==0)se=J/2;else if(h==="center")se=ye.highest.height/2-K*J;else se=ye.highest.height-j*J;if(b)se*=-1;if(M!==0&&!Se.showLabelBackdrop)H+=J/2*Math.sin(M)}else V=X,se=(1-j)*J/2;let k;if(Se.showLabelBackdrop){let W=Na(Se.backdropPadding),ee=ye.heights[w],ne=ye.widths[w],te=se-W.top,le=0-W.left;switch(ge){case"middle":te-=ee/2;break;case"bottom":te-=ee;break}switch(G){case"center":le-=ne/2;break;case"right":le-=ne;break;case"inner":if(w===A-1)le-=ne;else if(w>0)le-=ne/2;break}k={left:le,top:te,width:ne+W.width,height:ee+W.height,color:Se.backdropColor}}I.push({label:z,font:Y,textOffset:se,options:{rotation:M,color:pe,strokeColor:be,strokeWidth:Ue,textAlign:He,textBaseline:ge,translation:[H,V],backdrop:k}})}return I}_getXAxisLabelAlignment(){let{position:a,ticks:n}=this.options;if(-Fs(this.labelRotation))return a==="top"?"left":"right";let i="center";if(n.align==="start")i="left";else if(n.align==="end")i="right";else if(n.align==="inner")i="inner";return i}_getYAxisLabelAlignment(a){let{position:n,ticks:{crossAlign:s,mirror:i,padding:l}}=this.options,u=this._getLabelSizes(),d=a+l,p=u.widest.width,h,g;if(n==="left")if(i)if(g=this.right+l,s==="near")h="left";else if(s==="center")h="center",g+=p/2;else h="right",g+=p;else if(g=this.right-d,s==="near")h="right";else if(s==="center")h="center",g-=p/2;else h="left",g=this.left;else if(n==="right")if(i)if(g=this.left+l,s==="near")h="right";else if(s==="center")h="center",g-=p/2;else h="left",g-=p;else if(g=this.left+d,s==="near")h="left";else if(s==="center")h="center",g+=p/2;else h="right",g=this.right;else h="right";return{textAlign:h,x:g}}_computeLabelArea(){if(this.options.ticks.mirror)return;let a=this.chart,n=this.options.position;if(n==="left"||n==="right")return{top:0,left:this.left,bottom:a.height,right:this.right};if(n==="top"||n==="bottom")return{top:this.top,left:0,bottom:this.bottom,right:a.width}}drawBackground(){let{ctx:a,options:{backgroundColor:n},left:s,top:i,width:l,height:u}=this;if(n)a.save(),a.fillStyle=n,a.fillRect(s,i,l,u),a.restore()}getLineWidthForValue(a){let n=this.options.grid;if(!this._isVisible()||!n.display)return 0;let i=this.ticks.findIndex((l)=>l.value===a);if(i>=0)return n.setContext(this.getContext(i)).lineWidth;return 0}drawGrid(a){let n=this.options.grid,s=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(a)),l,u,d=(p,h,g)=>{if(!g.width||!g.color)return;s.save(),s.lineWidth=g.width,s.strokeStyle=g.color,s.setLineDash(g.borderDash||[]),s.lineDashOffset=g.borderDashOffset,s.beginPath(),s.moveTo(p.x,p.y),s.lineTo(h.x,h.y),s.stroke(),s.restore()};if(n.display)for(l=0,u=i.length;l<u;++l){let p=i[l];if(n.drawOnChartArea)d({x:p.x1,y:p.y1},{x:p.x2,y:p.y2},p);if(n.drawTicks)d({x:p.tx1,y:p.ty1},{x:p.tx2,y:p.ty2},{color:p.tickColor,width:p.tickWidth,borderDash:p.tickBorderDash,borderDashOffset:p.tickBorderDashOffset})}}drawBorder(){let{chart:a,ctx:n,options:{border:s,grid:i}}=this,l=s.setContext(this.getContext()),u=s.display?l.width:0;if(!u)return;let d=i.setContext(this.getContext(0)).lineWidth,p=this._borderValue,h,g,b,y;if(this.isHorizontal())h=Jr(a,this.left,u)-u/2,g=Jr(a,this.right,d)+d/2,b=y=p;else b=Jr(a,this.top,u)-u/2,y=Jr(a,this.bottom,d)+d/2,h=g=p;n.save(),n.lineWidth=l.width,n.strokeStyle=l.color,n.beginPath(),n.moveTo(h,b),n.lineTo(g,y),n.stroke(),n.restore()}drawLabels(a){if(!this.options.ticks.display)return;let s=this.ctx,i=this._computeLabelArea();if(i)Nd(s,i);let l=this.getLabelItems(a);for(let u of l){let{options:d,font:p,label:h,textOffset:g}=u;ei(s,h,0,g,p,d)}if(i)zd(s)}drawTitle(){let{ctx:a,options:{position:n,title:s,reverse:i}}=this;if(!s.display)return;let l=pa(s.font),u=Na(s.padding),d=s.align,p=l.lineHeight/2;if(n==="bottom"||n==="center"||it(n)){if(p+=u.bottom,zt(s.text))p+=l.lineHeight*(s.text.length-1)}else p+=u.top;let{titleX:h,titleY:g,maxWidth:b,rotation:y}=CP(this,p,n,d);ei(a,s.text,0,0,l,{color:s.color,maxWidth:b,rotation:y,textAlign:LP(d,n,i),textBaseline:"middle",translation:[h,g]})}draw(a){if(!this._isVisible())return;this.drawBackground(),this.drawGrid(a),this.drawBorder(),this.drawTitle(),this.drawLabels(a)}_layers(){let a=this.options,n=a.ticks&&a.ticks.z||0,s=Ke(a.grid&&a.grid.z,-1),i=Ke(a.border&&a.border.z,0);if(!this._isVisible()||this.draw!==cl.prototype.draw)return[{z:n,draw:(l)=>{this.draw(l)}}];return[{z:s,draw:(l)=>{this.drawBackground(),this.drawGrid(l),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:n,draw:(l)=>{this.drawLabels(l)}}]}getMatchingVisibleMetas(a){let n=this.chart.getSortedVisibleDatasetMetas(),s=this.axis+"AxisID",i=[],l,u;for(l=0,u=n.length;l<u;++l){let d=n[l];if(d[s]===this.id&&(!a||d.type===a))i.push(d)}return i}_resolveTickFontOptions(a){let n=this.options.ticks.setContext(this.getContext(a));return pa(n.font)}_maxDigits(){let a=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/a}}class Xd{constructor(a,n,s){this.type=a,this.scope=n,this.override=s,this.items=Object.create(null)}isForType(a){return Object.prototype.isPrototypeOf.call(this.type.prototype,a.prototype)}register(a){let n=Object.getPrototypeOf(a),s;if(kP(n))s=this.register(n);let i=this.items,l=a.id,u=this.scope+"."+l;if(!l)throw Error("class does not have id: "+a);if(l in i)return u;if(i[l]=a,TP(a,u,s),this.override)Jt.override(a.id,a.overrides);return u}get(a){return this.items[a]}unregister(a){let n=this.items,s=a.id,i=this.scope;if(s in n)delete n[s];if(i&&s in Jt[i]){if(delete Jt[i][s],this.override)delete Kr[s]}}}function TP(a,n,s){let i=Du(Object.create(null),[s?Jt.get(s):{},Jt.get(n),a.defaults]);if(Jt.set(n,i),a.defaultRoutes)wP(n,a.defaultRoutes);if(a.descriptors)Jt.describe(n,a.descriptors)}function wP(a,n){Object.keys(n).forEach((s)=>{let i=s.split("."),l=i.pop(),u=[a].concat(i).join("."),d=n[s].split("."),p=d.pop(),h=d.join(".");Jt.route(u,l,h,p)})}function kP(a){return"id"in a&&"defaults"in a}class KM{constructor(){this.controllers=new Xd(vm,"datasets",!0),this.elements=new Xd(Xs,"elements"),this.plugins=new Xd(Object,"plugins"),this.scales=new Xd(cl,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...a){this._each("register",a)}remove(...a){this._each("unregister",a)}addControllers(...a){this._each("register",a,this.controllers)}addElements(...a){this._each("register",a,this.elements)}addPlugins(...a){this._each("register",a,this.plugins)}addScales(...a){this._each("register",a,this.scales)}getController(a){return this._get(a,this.controllers,"controller")}getElement(a){return this._get(a,this.elements,"element")}getPlugin(a){return this._get(a,this.plugins,"plugin")}getScale(a){return this._get(a,this.scales,"scale")}removeControllers(...a){this._each("unregister",a,this.controllers)}removeElements(...a){this._each("unregister",a,this.elements)}removePlugins(...a){this._each("unregister",a,this.plugins)}removeScales(...a){this._each("unregister",a,this.scales)}_each(a,n,s){[...n].forEach((i)=>{let l=s||this._getRegistryForType(i);if(s||l.isForType(i)||l===this.plugins&&i.id)this._exec(a,l,i);else Lt(i,(u)=>{let d=s||this._getRegistryForType(u);this._exec(a,d,u)})})}_exec(a,n,s){let i=tm(a);Ot(s["before"+i],[],s),n[a](s),Ot(s["after"+i],[],s)}_getRegistryForType(a){for(let n=0;n<this._typedRegistries.length;n++){let s=this._typedRegistries[n];if(s.isForType(a))return s}return this.plugins}_get(a,n,s){let i=n.get(a);if(i===void 0)throw Error('"'+a+'" is not a registered '+s+".");return i}}var ss=new KM;class JM{constructor(){this._init=void 0}notify(a,n,s,i){if(n==="beforeInit")this._init=this._createDescriptors(a,!0),this._notify(this._init,a,"install");if(this._init===void 0)return;let l=i?this._descriptors(a).filter(i):this._descriptors(a),u=this._notify(l,a,n,s);if(n==="afterDestroy")this._notify(l,a,"stop"),this._notify(this._init,a,"uninstall"),this._init=void 0;return u}_notify(a,n,s,i){i=i||{};for(let l of a){let u=l.plugin,d=u[s],p=[n,i,l.options];if(Ot(d,p,u)===!1&&i.cancelable)return!1}return!0}invalidate(){if(!ht(this._cache))this._oldCache=this._cache,this._cache=void 0}_descriptors(a){if(this._cache)return this._cache;let n=this._cache=this._createDescriptors(a);return this._notifyStateChanges(a),n}_createDescriptors(a,n){let s=a&&a.config,i=Ke(s.options&&s.options.plugins,{}),l=MP(s);return i===!1&&!n?[]:AP(a,l,i,n)}_notifyStateChanges(a){let n=this._oldCache||[],s=this._cache,i=(l,u)=>l.filter((d)=>!u.some((p)=>d.plugin.id===p.plugin.id));this._notify(i(n,s),a,"stop"),this._notify(i(s,n),a,"start")}}function MP(a){let n={},s=[],i=Object.keys(ss.plugins.items);for(let u=0;u<i.length;u++)s.push(ss.getPlugin(i[u]));let l=a.plugins||[];for(let u=0;u<l.length;u++){let d=l[u];if(s.indexOf(d)===-1)s.push(d),n[d.id]=!0}return{plugins:s,localIds:n}}function IP(a,n){if(!n&&a===!1)return null;if(a===!0)return{};return a}function AP(a,{plugins:n,localIds:s},i,l){let u=[],d=a.getContext();for(let p of n){let h=p.id,g=IP(i[h],l);if(g===null)continue;u.push({plugin:p,options:RP(a.config,{plugin:p,local:s[h]},g,d)})}return u}function RP(a,{plugin:n,local:s},i,l){let u=a.pluginScopeKeys(n),d=a.getOptionScopes(i,u);if(s&&n.defaults)d.push(n.defaults);return a.createResolver(d,l,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Sv(a,n){let s=Jt.datasets[a]||{};return((n.datasets||{})[a]||{}).indexAxis||n.indexAxis||s.indexAxis||"x"}function _P(a,n){let s=a;if(a==="_index_")s=n;else if(a==="_value_")s=n==="x"?"y":"x";return s}function DP(a,n){return a===n?"_index_":"_value_"}function dM(a){if(a==="x"||a==="y"||a==="r")return a}function EP(a){if(a==="top"||a==="bottom")return"x";if(a==="left"||a==="right")return"y"}function Lv(a,...n){if(dM(a))return a;for(let s of n){let i=s.axis||EP(s.position)||a.length>1&&dM(a[0].toLowerCase());if(i)return i}throw Error(`Cannot determine type of '${a}' axis. Please provide 'axis' or 'position' option.`)}function fM(a,n,s){if(s[n+"AxisID"]===a)return{axis:n}}function OP(a,n){if(n.data&&n.data.datasets){let s=n.data.datasets.filter((i)=>i.xAxisID===a||i.yAxisID===a);if(s.length)return fM(a,"x",s[0])||fM(a,"y",s[0])}return{}}function PP(a,n){let s=Kr[a.type]||{scales:{}},i=n.scales||{},l=Sv(a.type,n),u=Object.create(null);return Object.keys(i).forEach((d)=>{let p=i[d];if(!it(p))return console.error(`Invalid scale configuration for scale: ${d}`);if(p._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${d}`);let h=Lv(d,p,OP(d,a),Jt.scales[p.type]),g=DP(h,l),b=s.scales||{};u[d]=Ou(Object.create(null),[{axis:h},p,b[h],b[g]])}),a.data.datasets.forEach((d)=>{let p=d.type||a.type,h=d.indexAxis||Sv(p,n),b=(Kr[p]||{}).scales||{};Object.keys(b).forEach((y)=>{let v=_P(y,h),T=d[v+"AxisID"]||v;u[T]=u[T]||Object.create(null),Ou(u[T],[{axis:v},i[T],b[y]])})}),Object.keys(u).forEach((d)=>{let p=u[d];Ou(p,[Jt.scales[p.type],Jt.scale])}),u}function eI(a){let n=a.options||(a.options={});n.plugins=Ke(n.plugins,{}),n.scales=PP(a,n)}function tI(a){return a=a||{},a.datasets=a.datasets||[],a.labels=a.labels||[],a}function BP(a){return a=a||{},a.data=tI(a.data),eI(a),a}var pM=new Map,aI=new Set;function hm(a,n){let s=pM.get(a);if(!s)s=n(),pM.set(a,s),aI.add(s);return s}var jd=(a,n,s)=>{let i=rl(n,s);if(i!==void 0)a.add(i)};class oI{constructor(a){this._config=BP(a),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(a){this._config.type=a}get data(){return this._config.data}set data(a){this._config.data=tI(a)}get options(){return this._config.options}set options(a){this._config.options=a}get plugins(){return this._config.plugins}update(){let a=this._config;this.clearCache(),eI(a)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(a){return hm(a,()=>[[`datasets.${a}`,""]])}datasetAnimationScopeKeys(a,n){return hm(`${a}.transition.${n}`,()=>[[`datasets.${a}.transitions.${n}`,`transitions.${n}`],[`datasets.${a}`,""]])}datasetElementScopeKeys(a,n){return hm(`${a}-${n}`,()=>[[`datasets.${a}.elements.${n}`,`datasets.${a}`,`elements.${n}`,""]])}pluginScopeKeys(a){let n=a.id,s=this.type;return hm(`${s}-plugin-${n}`,()=>[[`plugins.${n}`,...a.additionalOptionScopes||[]]])}_cachedScopes(a,n){let s=this._scopeCache,i=s.get(a);if(!i||n)i=new Map,s.set(a,i);return i}getOptionScopes(a,n,s){let{options:i,type:l}=this,u=this._cachedScopes(a,s),d=u.get(n);if(d)return d;let p=new Set;n.forEach((g)=>{if(a)p.add(a),g.forEach((b)=>jd(p,a,b));g.forEach((b)=>jd(p,i,b)),g.forEach((b)=>jd(p,Kr[l]||{},b)),g.forEach((b)=>jd(p,Jt,b)),g.forEach((b)=>jd(p,rm,b))});let h=Array.from(p);if(h.length===0)h.push(Object.create(null));if(aI.has(n))u.set(n,h);return h}chartOptionScopes(){let{options:a,type:n}=this;return[a,Kr[n]||{},Jt.datasets[n]||{},{type:n},Jt,rm]}resolveNamedOptions(a,n,s,i=[""]){let l={$shared:!0},{resolver:u,subPrefixes:d}=hM(this._resolverCache,a,i),p=u;if(zP(u,n)){l.$shared=!1,s=Hs(s)?s():s;let h=this.createResolver(a,s,d);p=sl(u,s,h)}for(let h of n)l[h]=p[h];return l}createResolver(a,n,s=[""],i){let{resolver:l}=hM(this._resolverCache,a,s);return it(n)?sl(l,n,void 0,i):l}}function hM(a,n,s){let i=a.get(n);if(!i)i=new Map,a.set(n,i);let l=s.join(),u=i.get(l);if(!u)u={resolver:lm(n,s),subPrefixes:s.filter((p)=>!p.toLowerCase().includes("hover"))},i.set(l,u);return u}var NP=(a)=>it(a)&&Object.getOwnPropertyNames(a).some((n)=>Hs(a[n]));function zP(a,n){let{isScriptable:s,isIndexable:i}=ev(a);for(let l of n){let u=s(l),d=i(l),p=(d||u)&&a[l];if(u&&(Hs(p)||NP(p))||d&&zt(p))return!0}return!1}var HP="4.5.1",UP=["top","bottom","left","right","chartArea"];function mM(a,n){return a==="top"||a==="bottom"||UP.indexOf(a)===-1&&n==="x"}function gM(a,n){return function(s,i){return s[a]===i[a]?s[n]-i[n]:s[a]-i[a]}}function yM(a){let n=a.chart,s=n.options.animation;n.notifyPlugins("afterRender"),Ot(s&&s.onComplete,[a],n)}function FP(a){let n=a.chart,s=n.options.animation;Ot(s&&s.onProgress,[a],n)}function nI(a){if(um()&&typeof a==="string")a=document.getElementById(a);else if(a&&a.length)a=a[0];if(a&&a.canvas)a=a.canvas;return a}var bm={},bM=(a)=>{let n=nI(a);return Object.values(bm).filter((s)=>s.canvas===n).pop()};function qP(a,n,s){let i=Object.keys(a);for(let l of i){let u=+l;if(u>=n){let d=a[l];if(delete a[l],s>0||u>n)a[u+s]=d}}}function VP(a,n,s,i){if(!s||a.type==="mouseout")return null;if(i)return n;return a}class dl{static defaults=Jt;static instances=bm;static overrides=Kr;static registry=ss;static version=HP;static getChart=bM;static register(...a){ss.add(...a),xM()}static unregister(...a){ss.remove(...a),xM()}constructor(a,n){let s=this.config=new oI(n),i=nI(a),l=bM(i);if(l)throw Error("Canvas is already in use. Chart with ID '"+l.id+"' must be destroyed before the canvas with ID '"+l.canvas.id+"' can be reused.");let u=s.createResolver(s.chartOptionScopes(),this.getContext());this.platform=new(s.platform||cP(i)),this.platform.updateConfig(s);let d=this.platform.acquireContext(i,u.aspectRatio),p=d&&d.canvas,h=p&&p.height,g=p&&p.width;if(this.id=pk(),this.ctx=d,this.canvas=p,this.width=g,this.height=h,this._options=u,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new JM,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=wk((b)=>this.update(b),u.resizeDelay||0),this._dataChanges=[],bm[this.id]=this,!d||!p){console.error("Failed to create chart: can't acquire context from the given item");return}if(js.listen(this,"complete",yM),js.listen(this,"progress",FP),this._initialize(),this.attached)this.update()}get aspectRatio(){let{options:{aspectRatio:a,maintainAspectRatio:n},width:s,height:i,_aspectRatio:l}=this;if(!ht(a))return a;if(n&&l)return l;return i?s/i:null}get data(){return this.config.data}set data(a){this.config.data=a}get options(){return this._options}set options(a){this.config.options=a}get registry(){return ss}_initialize(){if(this.notifyPlugins("beforeInit"),this.options.responsive)this.resize();else ov(this,this.options.devicePixelRatio);return this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return Zx(this.canvas,this.ctx),this}stop(){return js.stop(this),this}resize(a,n){if(!js.running(this))this._resize(a,n);else this._resizeBeforeDraw={width:a,height:n}}_resize(a,n){let s=this.options,i=this.canvas,l=s.maintainAspectRatio&&this.aspectRatio,u=this.platform.getMaximumSize(i,a,n,l),d=s.devicePixelRatio||this.platform.getDevicePixelRatio(),p=this.width?"resize":"attach";if(this.width=u.width,this.height=u.height,this._aspectRatio=this.aspectRatio,!ov(this,d,!0))return;if(this.notifyPlugins("resize",{size:u}),Ot(s.onResize,[this,u],this),this.attached){if(this._doResize(p))this.render()}}ensureScalesHaveIDs(){let n=this.options.scales||{};Lt(n,(s,i)=>{s.id=i})}buildOrUpdateScales(){let a=this.options,n=a.scales,s=this.scales,i=Object.keys(s).reduce((u,d)=>(u[d]=!1,u),{}),l=[];if(n)l=l.concat(Object.keys(n).map((u)=>{let d=n[u],p=Lv(u,d),h=p==="r",g=p==="x";return{options:d,dposition:h?"chartArea":g?"bottom":"left",dtype:h?"radialLinear":g?"category":"linear"}}));Lt(l,(u)=>{let d=u.options,p=d.id,h=Lv(p,d),g=Ke(d.type,u.dtype);if(d.position===void 0||mM(d.position,h)!==mM(u.dposition))d.position=u.dposition;i[p]=!0;let b=null;if(p in s&&s[p].type===g)b=s[p];else b=new(ss.getScale(g))({id:p,type:g,ctx:this.ctx,chart:this}),s[b.id]=b;b.init(d,a)}),Lt(i,(u,d)=>{if(!u)delete s[d]}),Lt(s,(u)=>{nn.configure(this,u,u.options),nn.addBox(this,u)})}_updateMetasets(){let a=this._metasets,n=this.data.datasets.length,s=a.length;if(a.sort((i,l)=>i.index-l.index),s>n){for(let i=n;i<s;++i)this._destroyDatasetMeta(i);a.splice(n,s-n)}this._sortedMetasets=a.slice(0).sort(gM("order","index"))}_removeUnreferencedMetasets(){let{_metasets:a,data:{datasets:n}}=this;if(a.length>n.length)delete this._stacks;a.forEach((s,i)=>{if(n.filter((l)=>l===s._dataset).length===0)this._destroyDatasetMeta(i)})}buildOrUpdateControllers(){let a=[],n=this.data.datasets,s,i;this._removeUnreferencedMetasets();for(s=0,i=n.length;s<i;s++){let l=n[s],u=this.getDatasetMeta(s),d=l.type||this.config.type;if(u.type&&u.type!==d)this._destroyDatasetMeta(s),u=this.getDatasetMeta(s);if(u.type=d,u.indexAxis=l.indexAxis||Sv(d,this.options),u.order=l.order||0,u.index=s,u.label=""+l.label,u.visible=this.isDatasetVisible(s),u.controller)u.controller.updateIndex(s),u.controller.linkScales();else{let p=ss.getController(d),{datasetElementType:h,dataElementType:g}=Jt.datasets[d];Object.assign(p,{dataElementType:ss.getElement(g),datasetElementType:h&&ss.getElement(h)}),u.controller=new p(this,s),a.push(u.controller)}}return this._updateMetasets(),a}_resetElements(){Lt(this.data.datasets,(a,n)=>{this.getDatasetMeta(n).controller.reset()},this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(a){let n=this.config;n.update();let s=this._options=n.createResolver(n.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!s.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),this.notifyPlugins("beforeUpdate",{mode:a,cancelable:!0})===!1)return;let l=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let u=0;for(let h=0,g=this.data.datasets.length;h<g;h++){let{controller:b}=this.getDatasetMeta(h),y=!i&&l.indexOf(b)===-1;b.buildOrUpdateElements(y),u=Math.max(+b.getMaxOverflow(),u)}if(u=this._minPadding=s.layout.autoPadding?u:0,this._updateLayout(u),!i)Lt(l,(h)=>{h.reset()});this._updateDatasets(a),this.notifyPlugins("afterUpdate",{mode:a}),this._layers.sort(gM("z","_idx"));let{_active:d,_lastEvent:p}=this;if(p)this._eventHandler(p,!0);else if(d.length)this._updateHoverStyles(d,d,!0);this.render()}_updateScales(){Lt(this.scales,(a)=>{nn.removeBox(this,a)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){let a=this.options,n=new Set(Object.keys(this._listeners)),s=new Set(a.events);if(!Hx(n,s)||!!this._responsiveListeners!==a.responsive)this.unbindEvents(),this.bindEvents()}_updateHiddenIndices(){let{_hiddenIndices:a}=this,n=this._getUniformDataChanges()||[];for(let{method:s,start:i,count:l}of n){let u=s==="_removeElements"?-l:l;qP(a,i,u)}}_getUniformDataChanges(){let a=this._dataChanges;if(!a||!a.length)return;this._dataChanges=[];let n=this.data.datasets.length,s=(l)=>new Set(a.filter((u)=>u[0]===l).map((u,d)=>d+","+u.splice(1).join(","))),i=s(0);for(let l=1;l<n;l++)if(!Hx(i,s(l)))return;return Array.from(i).map((l)=>l.split(",")).map((l)=>({method:l[1],start:+l[2],count:+l[3]}))}_updateLayout(a){if(this.notifyPlugins("beforeLayout",{cancelable:!0})===!1)return;nn.update(this,this.width,this.height,a);let n=this.chartArea,s=n.width<=0||n.height<=0;this._layers=[],Lt(this.boxes,(i)=>{if(s&&i.position==="chartArea")return;if(i.configure)i.configure();this._layers.push(...i._layers())},this),this._layers.forEach((i,l)=>{i._idx=l}),this.notifyPlugins("afterLayout")}_updateDatasets(a){if(this.notifyPlugins("beforeDatasetsUpdate",{mode:a,cancelable:!0})===!1)return;for(let n=0,s=this.data.datasets.length;n<s;++n)this.getDatasetMeta(n).controller.configure();for(let n=0,s=this.data.datasets.length;n<s;++n)this._updateDataset(n,Hs(a)?a({datasetIndex:n}):a);this.notifyPlugins("afterDatasetsUpdate",{mode:a})}_updateDataset(a,n){let s=this.getDatasetMeta(a),i={meta:s,index:a,mode:n,cancelable:!0};if(this.notifyPlugins("beforeDatasetUpdate",i)===!1)return;s.controller._update(n),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i)}render(){if(this.notifyPlugins("beforeRender",{cancelable:!0})===!1)return;if(js.has(this)){if(this.attached&&!js.running(this))js.start(this)}else this.draw(),yM({chart:this})}draw(){let a;if(this._resizeBeforeDraw){let{width:s,height:i}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(s,i)}if(this.clear(),this.width<=0||this.height<=0)return;if(this.notifyPlugins("beforeDraw",{cancelable:!0})===!1)return;let n=this._layers;for(a=0;a<n.length&&n[a].z<=0;++a)n[a].draw(this.chartArea);this._drawDatasets();for(;a<n.length;++a)n[a].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(a){let n=this._sortedMetasets,s=[],i,l;for(i=0,l=n.length;i<l;++i){let u=n[i];if(!a||u.visible)s.push(u)}return s}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0})===!1)return;let a=this.getSortedVisibleDatasetMetas();for(let n=a.length-1;n>=0;--n)this._drawDataset(a[n]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(a){let n=this.ctx,s={meta:a,index:a.index,cancelable:!0},i=uv(this,a);if(this.notifyPlugins("beforeDatasetDraw",s)===!1)return;if(i)Nd(n,i);if(a.controller.draw(),i)zd(n);s.cancelable=!1,this.notifyPlugins("afterDatasetDraw",s)}isPointInArea(a){return as(a,this.chartArea,this._minPadding)}getElementsAtEventForMode(a,n,s,i){let l=GO.modes[n];if(typeof l==="function")return l(this,a,s,i);return[]}getDatasetMeta(a){let n=this.data.datasets[a],s=this._metasets,i=s.filter((l)=>l&&l._dataset===n).pop();if(!i)i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:n&&n.order||0,index:a,_dataset:n,_parsed:[],_sorted:!1},s.push(i);return i}getContext(){return this.$context||(this.$context=Vs(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(a){let n=this.data.datasets[a];if(!n)return!1;let s=this.getDatasetMeta(a);return typeof s.hidden==="boolean"?!s.hidden:!n.hidden}setDatasetVisibility(a,n){let s=this.getDatasetMeta(a);s.hidden=!n}toggleDataVisibility(a){this._hiddenIndices[a]=!this._hiddenIndices[a]}getDataVisibility(a){return!this._hiddenIndices[a]}_updateVisibility(a,n,s){let i=s?"show":"hide",l=this.getDatasetMeta(a),u=l.controller._resolveAnimations(void 0,i);if(Pu(n))l.data[n].hidden=!s,this.update();else this.setDatasetVisibility(a,s),u.update(l,{visible:s}),this.update((d)=>d.datasetIndex===a?i:void 0)}hide(a,n){this._updateVisibility(a,n,!1)}show(a,n){this._updateVisibility(a,n,!0)}_destroyDatasetMeta(a){let n=this._metasets[a];if(n&&n.controller)n.controller._destroy();delete this._metasets[a]}_stop(){let a,n;this.stop(),js.remove(this);for(a=0,n=this.data.datasets.length;a<n;++a)this._destroyDatasetMeta(a)}destroy(){this.notifyPlugins("beforeDestroy");let{canvas:a,ctx:n}=this;if(this._stop(),this.config.clearCache(),a)this.unbindEvents(),Zx(a,n),this.platform.releaseContext(n),this.canvas=null,this.ctx=null;delete bm[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...a){return this.canvas.toDataURL(...a)}bindEvents(){if(this.bindUserEvents(),this.options.responsive)this.bindResponsiveEvents();else this.attached=!0}bindUserEvents(){let a=this._listeners,n=this.platform,s=(l,u)=>{n.addEventListener(this,l,u),a[l]=u},i=(l,u,d)=>{l.offsetX=u,l.offsetY=d,this._eventHandler(l)};Lt(this.options.events,(l)=>s(l,i))}bindResponsiveEvents(){if(!this._responsiveListeners)this._responsiveListeners={};let a=this._responsiveListeners,n=this.platform,s=(p,h)=>{n.addEventListener(this,p,h),a[p]=h},i=(p,h)=>{if(a[p])n.removeEventListener(this,p,h),delete a[p]},l=(p,h)=>{if(this.canvas)this.resize(p,h)},u,d=()=>{i("attach",d),this.attached=!0,this.resize(),s("resize",l),s("detach",u)};if(u=()=>{this.attached=!1,i("resize",l),this._stop(),this._resize(0,0),s("attach",d)},n.isAttached(this.canvas))d();else u()}unbindEvents(){Lt(this._listeners,(a,n)=>{this.platform.removeEventListener(this,n,a)}),this._listeners={},Lt(this._responsiveListeners,(a,n)=>{this.platform.removeEventListener(this,n,a)}),this._responsiveListeners=void 0}updateHoverStyle(a,n,s){let i=s?"set":"remove",l,u,d,p;if(n==="dataset")l=this.getDatasetMeta(a[0].datasetIndex),l.controller["_"+i+"DatasetHoverStyle"]();for(d=0,p=a.length;d<p;++d){u=a[d];let h=u&&this.getDatasetMeta(u.datasetIndex).controller;if(h)h[i+"HoverStyle"](u.element,u.datasetIndex,u.index)}}getActiveElements(){return this._active||[]}setActiveElements(a){let n=this._active||[],s=a.map(({datasetIndex:l,index:u})=>{let d=this.getDatasetMeta(l);if(!d)throw Error("No dataset found at index "+l);return{datasetIndex:l,element:d.data[u],index:u}});if(!Pd(s,n))this._active=s,this._lastEvent=null,this._updateHoverStyles(s,n)}notifyPlugins(a,n,s){return this._plugins.notify(this,a,n,s)}isPluginEnabled(a){return this._plugins._cache.filter((n)=>n.plugin.id===a).length===1}_updateHoverStyles(a,n,s){let i=this.options.hover,l=(p,h)=>p.filter((g)=>!h.some((b)=>g.datasetIndex===b.datasetIndex&&g.index===b.index)),u=l(n,a),d=s?a:l(a,n);if(u.length)this.updateHoverStyle(u,i.mode,!1);if(d.length&&i.mode)this.updateHoverStyle(d,i.mode,!0)}_eventHandler(a,n){let s={event:a,replay:n,cancelable:!0,inChartArea:this.isPointInArea(a)},i=(u)=>(u.options.events||this.options.events).includes(a.native.type);if(this.notifyPlugins("beforeEvent",s,i)===!1)return;let l=this._handleEvent(a,n,s.inChartArea);if(s.cancelable=!1,this.notifyPlugins("afterEvent",s,i),l||s.changed)this.render();return this}_handleEvent(a,n,s){let{_active:i=[],options:l}=this,u=n,d=this._getActiveElements(a,i,s,u),p=gk(a),h=VP(a,this._lastEvent,s,p);if(s){if(this._lastEvent=null,Ot(l.onHover,[a,d,this],this),p)Ot(l.onClick,[a,d,this],this)}let g=!Pd(d,i);if(g||n)this._active=d,this._updateHoverStyles(d,i,n);return this._lastEvent=h,g}_getActiveElements(a,n,s,i){if(a.type==="mouseout")return[];if(!s)return n;let l=this.options.hover;return this.getElementsAtEventForMode(a,l.mode,l,i)}}function xM(){return Lt(dl.instances,(a)=>a._plugins.invalidate())}function sI(a,n,s=n){a.lineCap=Ke(s.borderCapStyle,n.borderCapStyle),a.setLineDash(Ke(s.borderDash,n.borderDash)),a.lineDashOffset=Ke(s.borderDashOffset,n.borderDashOffset),a.lineJoin=Ke(s.borderJoinStyle,n.borderJoinStyle),a.lineWidth=Ke(s.borderWidth,n.borderWidth),a.strokeStyle=Ke(s.borderColor,n.borderColor)}function jP(a,n,s){a.lineTo(s.x,s.y)}function GP(a){if(a.stepped)return Dk;if(a.tension||a.cubicInterpolationMode==="monotone")return Ek;return jP}function rI(a,n,s={}){let i=a.length,{start:l=0,end:u=i-1}=s,{start:d,end:p}=n,h=Math.max(l,d),g=Math.min(u,p),b=l<d&&u<d||l>p&&u>p;return{count:i,start:h,loop:n.loop,ilen:g<h&&!b?i+g-h:g-h}}function XP(a,n,s,i){let{points:l,options:u}=n,{count:d,start:p,loop:h,ilen:g}=rI(l,s,i),b=GP(u),{move:y=!0,reverse:v}=i||{},T,M,I;for(T=0;T<=g;++T){if(M=l[(p+(v?g-T:T))%d],M.skip)continue;else if(y)a.moveTo(M.x,M.y),y=!1;else b(a,I,M,v,u.stepped);I=M}if(h)M=l[(p+(v?g:0))%d],b(a,I,M,v,u.stepped);return!!h}function YP(a,n,s,i){let l=n.points,{count:u,start:d,ilen:p}=rI(l,s,i),{move:h=!0,reverse:g}=i||{},b=0,y=0,v,T,M,I,w,A,B=(H)=>(d+(g?p-H:H))%u,z=()=>{if(I!==w)a.lineTo(b,w),a.lineTo(b,I),a.lineTo(b,A)};if(h)T=l[B(0)],a.moveTo(T.x,T.y);for(v=0;v<=p;++v){if(T=l[B(v)],T.skip)continue;let H=T.x,V=T.y,G=H|0;if(G===M){if(V<I)I=V;else if(V>w)w=V;b=(y*b+H)/++y}else z(),a.lineTo(H,V),M=G,y=0,I=w=V;A=V}z()}function Cv(a){let n=a.options,s=n.borderDash&&n.borderDash.length;return!a._decimated&&!a._loop&&!n.tension&&n.cubicInterpolationMode!=="monotone"&&!n.stepped&&!s?YP:XP}function $P(a){if(a.stepped)return qk;if(a.tension||a.cubicInterpolationMode==="monotone")return Vk;return Wr}function WP(a,n,s,i){let l=n._path;if(!l){if(l=n._path=new Path2D,n.path(l,s,i))l.closePath()}sI(a,n.options),a.stroke(l)}function ZP(a,n,s,i){let{segments:l,options:u}=n,d=Cv(n);for(let p of l){if(sI(a,u,p.style),a.beginPath(),d(a,n,p,{start:s,end:s+i-1}))a.closePath();a.stroke()}}var QP=typeof Path2D==="function";function KP(a,n,s,i){if(QP&&!n.options.segment)WP(a,n,s,i);else ZP(a,n,s,i)}class Hu extends Xs{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:(a)=>a!=="borderDash"&&a!=="fill"};constructor(a){super();if(this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,a)Object.assign(this,a)}updateControlPoints(a,n){let s=this.options;if((s.tension||s.cubicInterpolationMode==="monotone")&&!s.stepped&&!this._pointsUpdated){let i=s.spanGaps?this._loop:this._fullLoop;Hk(this._points,s,a,i,n),this._pointsUpdated=!0}}set points(a){this._points=a,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=Gk(this,this.options.segment))}first(){let a=this.segments,n=this.points;return a.length&&n[a[0].start]}last(){let a=this.segments,n=this.points,s=a.length;return s&&n[a[s-1].end]}interpolate(a,n){let s=this.options,i=a[n],l=this.points,u=lv(this,{property:n,start:i,end:i});if(!u.length)return;let d=[],p=$P(s),h,g;for(h=0,g=u.length;h<g;++h){let{start:b,end:y}=u[h],v=l[b],T=l[y];if(v===T){d.push(v);continue}let M=Math.abs((i-v[n])/(T[n]-v[n])),I=p(v,T,M,s.stepped);I[n]=a[n],d.push(I)}return d.length===1?d[0]:d}pathSegment(a,n,s){return Cv(this)(a,this,n,s)}path(a,n,s){let i=this.segments,l=Cv(this),u=this._loop;n=n||0,s=s||this.points.length-n;for(let d of i)u&=l(a,this,d,{start:n,end:n+s-1});return!!u}draw(a,n,s,i){let l=this.options||{};if((this.points||[]).length&&l.borderWidth)a.save(),KP(a,this,s,i),a.restore();if(this.animated)this._pointsUpdated=!1,this._path=void 0}}function vM(a,n,s,i){let l=a.options,{[s]:u}=a.getProps([s],i);return Math.abs(n-u)<l.radius+l.hitRadius}class Ov extends Xs{static id="point";parsed;skip;stop;static defaults={borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(a){super();if(this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,a)Object.assign(this,a)}inRange(a,n,s){let i=this.options,{x:l,y:u}=this.getProps(["x","y"],s);return Math.pow(a-l,2)+Math.pow(n-u,2)<Math.pow(i.hitRadius+i.radius,2)}inXRange(a,n){return vM(this,a,"x",n)}inYRange(a,n){return vM(this,a,"y",n)}getCenterPoint(a){let{x:n,y:s}=this.getProps(["x","y"],a);return{x:n,y:s}}size(a){a=a||this.options||{};let n=a.radius||0;n=Math.max(n,n&&a.hoverRadius||0);let s=n&&a.borderWidth||0;return(n+s)*2}draw(a,n){let s=this.options;if(this.skip||s.radius<0.1||!as(this,n,this.size(s)/2))return;a.strokeStyle=s.borderColor,a.lineWidth=s.borderWidth,a.fillStyle=s.backgroundColor,im(a,s,this.x,this.y)}getRange(){let a=this.options||{};return a.radius+a.hitRadius}}function iI(a,n){let{x:s,y:i,base:l,width:u,height:d}=a.getProps(["x","y","base","width","height"],n),p,h,g,b,y;if(a.horizontal)y=d/2,p=Math.min(s,l),h=Math.max(s,l),g=i-y,b=i+y;else y=u/2,p=s-y,h=s+y,g=Math.min(i,l),b=Math.max(i,l);return{left:p,top:g,right:h,bottom:b}}function oi(a,n,s,i){return a?0:mo(n,s,i)}function JP(a,n,s){let i=a.options.borderWidth,l=a.borderSkipped,u=Jx(i);return{t:oi(l.top,u.top,0,s),r:oi(l.right,u.right,0,n),b:oi(l.bottom,u.bottom,0,s),l:oi(l.left,u.left,0,n)}}function eB(a,n,s){let{enableBorderRadius:i}=a.getProps(["enableBorderRadius"]),l=a.options.borderRadius,u=ti(l),d=Math.min(n,s),p=a.borderSkipped,h=i||it(l);return{topLeft:oi(!h||p.top||p.left,u.topLeft,0,d),topRight:oi(!h||p.top||p.right,u.topRight,0,d),bottomLeft:oi(!h||p.bottom||p.left,u.bottomLeft,0,d),bottomRight:oi(!h||p.bottom||p.right,u.bottomRight,0,d)}}function tB(a){let n=iI(a),s=n.right-n.left,i=n.bottom-n.top,l=JP(a,s/2,i/2),u=eB(a,s/2,i/2);return{outer:{x:n.left,y:n.top,w:s,h:i,radius:u},inner:{x:n.left+l.l,y:n.top+l.t,w:s-l.l-l.r,h:i-l.t-l.b,radius:{topLeft:Math.max(0,u.topLeft-Math.max(l.t,l.l)),topRight:Math.max(0,u.topRight-Math.max(l.t,l.r)),bottomLeft:Math.max(0,u.bottomLeft-Math.max(l.b,l.l)),bottomRight:Math.max(0,u.bottomRight-Math.max(l.b,l.r))}}}}function yv(a,n,s,i){let l=n===null,u=s===null,p=a&&!(l&&u)&&iI(a,i);return p&&(l||qs(n,p.left,p.right))&&(u||qs(s,p.top,p.bottom))}function aB(a){return a.topLeft||a.topRight||a.bottomLeft||a.bottomRight}function oB(a,n){a.rect(n.x,n.y,n.w,n.h)}function bv(a,n,s={}){let i=a.x!==s.x?-n:0,l=a.y!==s.y?-n:0,u=(a.x+a.w!==s.x+s.w?n:0)-i,d=(a.y+a.h!==s.y+s.h?n:0)-l;return{x:a.x+i,y:a.y+l,w:a.w+u,h:a.h+d,radius:a.radius}}class Pv extends Xs{static id="bar";static defaults={borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(a){super();if(this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,a)Object.assign(this,a)}draw(a){let{inflateAmount:n,options:{borderColor:s,backgroundColor:i}}=this,{inner:l,outer:u}=tB(this),d=aB(u.radius)?zu:oB;if(a.save(),u.w!==l.w||u.h!==l.h)a.beginPath(),d(a,bv(u,n,l)),a.clip(),d(a,bv(l,-n,u)),a.fillStyle=s,a.fill("evenodd");a.beginPath(),d(a,bv(l,n)),a.fillStyle=i,a.fill(),a.restore()}inRange(a,n,s){return yv(this,a,n,s)}inXRange(a,n){return yv(this,a,null,n)}inYRange(a,n){return yv(this,null,a,n)}getCenterPoint(a){let{x:n,y:s,base:i,horizontal:l}=this.getProps(["x","y","base","horizontal"],a);return{x:l?(n+i)/2:n,y:l?s:(s+i)/2}}getRange(a){return a==="x"?this.width/2:this.height/2}}function nB(a,n,s){let{segments:i,points:l}=a,u=n.points,d=[];for(let p of i){let{start:h,end:g}=p;g=Sm(h,g,l);let b=Tv(s,l[h],l[g],p.loop);if(!n.segments){d.push({source:p,target:b,start:l[h],end:l[g]});continue}let y=lv(n,b);for(let v of y){let T=Tv(s,u[v.start],u[v.end],v.loop),M=iv(p,l,T);for(let I of M)d.push({source:I,target:v,start:{[s]:SM(b,T,"start",Math.max)},end:{[s]:SM(b,T,"end",Math.min)}})}}return d}function Tv(a,n,s,i){if(i)return;let l=n[a],u=s[a];if(a==="angle")l=fo(l),u=fo(u);return{property:a,start:l,end:u}}function sB(a,n){let{x:s=null,y:i=null}=a||{},l=n.points,u=[];return n.segments.forEach(({start:d,end:p})=>{p=Sm(d,p,l);let h=l[d],g=l[p];if(i!==null)u.push({x:h.x,y:i}),u.push({x:g.x,y:i});else if(s!==null)u.push({x:s,y:h.y}),u.push({x:s,y:g.y})}),u}function Sm(a,n,s){for(;n>a;n--){let i=s[n];if(!isNaN(i.x)&&!isNaN(i.y))break}return n}function SM(a,n,s,i){if(a&&n)return i(a[s],n[s]);return a?a[s]:n?n[s]:0}function lI(a,n){let s=[],i=!1;if(zt(a))i=!0,s=a;else s=sB(a,n);return s.length?new Hu({points:s,options:{tension:0},_loop:i,_fullLoop:i}):null}function LM(a){return a&&a.fill!==!1}function rB(a,n,s){let l=a[n].fill,u=[n],d;if(!s)return l;while(l!==!1&&u.indexOf(l)===-1){if(!Kt(l))return l;if(d=a[l],!d)return!1;if(d.visible)return l;u.push(l),l=d.fill}return!1}function iB(a,n,s){let i=dB(a);if(it(i))return isNaN(i.value)?!1:i;let l=parseFloat(i);if(Kt(l)&&Math.floor(l)===l)return lB(i[0],n,l,s);return["origin","start","end","stack","shape"].indexOf(i)>=0&&i}function lB(a,n,s,i){if(a==="-"||a==="+")s=n+s;if(s===n||s<0||s>=i)return!1;return s}function uB(a,n){let s=null;if(a==="start")s=n.bottom;else if(a==="end")s=n.top;else if(it(a))s=n.getPixelForValue(a.value);else if(n.getBasePixel)s=n.getBasePixel();return s}function cB(a,n,s){let i;if(a==="start")i=s;else if(a==="end")i=n.options.reverse?n.min:n.max;else if(it(a))i=a.value;else i=n.getBaseValue();return i}function dB(a){let n=a.options,s=n.fill,i=Ke(s&&s.target,s);if(i===void 0)i=!!n.backgroundColor;if(i===!1||i===null)return!1;if(i===!0)return"origin";return i}function fB(a){let{scale:n,index:s,line:i}=a,l=[],{segments:u,points:d}=i,p=pB(n,s);p.push(lI({x:null,y:n.bottom},i));for(let h=0;h<u.length;h++){let g=u[h];for(let b=g.start;b<=g.end;b++)hB(l,d[b],p)}return new Hu({points:l,options:{}})}function pB(a,n){let s=[],i=a.getMatchingVisibleMetas("line");for(let l=0;l<i.length;l++){let u=i[l];if(u.index===n)break;if(!u.hidden)s.unshift(u.dataset)}return s}function hB(a,n,s){let i=[];for(let l=0;l<s.length;l++){let u=s[l],{first:d,last:p,point:h}=mB(u,n,"x");if(!h||d&&p)continue;if(d)i.unshift(h);else if(a.push(h),!p)break}a.push(...i)}function mB(a,n,s){let i=a.interpolate(n,s);if(!i)return{};let l=i[s],{segments:u,points:d}=a,p=!1,h=!1;for(let g=0;g<u.length;g++){let b=u[g],y=d[b.start][s],v=d[b.end][s];if(qs(l,y,v)){p=l===y,h=l===v;break}}return{first:p,last:h,point:i}}class Bv{constructor(a){this.x=a.x,this.y=a.y,this.radius=a.radius}pathSegment(a,n,s){let{x:i,y:l,radius:u}=this;return n=n||{start:0,end:ho},a.arc(i,l,u,n.end,n.start,!0),!s.bounds}interpolate(a){let{x:n,y:s,radius:i}=this,l=a.angle;return{x:n+Math.cos(l)*i,y:s+Math.sin(l)*i,angle:l}}}function gB(a){let{chart:n,fill:s,line:i}=a;if(Kt(s))return yB(n,s);if(s==="stack")return fB(a);if(s==="shape")return!0;let l=bB(a);if(l instanceof Bv)return l;return lI(l,i)}function yB(a,n){let s=a.getDatasetMeta(n);return s&&a.isDatasetVisible(n)?s.dataset:null}function bB(a){if((a.scale||{}).getPointPositionForValue)return vB(a);return xB(a)}function xB(a){let{scale:n={},fill:s}=a,i=uB(s,n);if(Kt(i)){let l=n.isHorizontal();return{x:l?i:null,y:l?null:i}}return null}function vB(a){let{scale:n,fill:s}=a,i=n.options,l=n.getLabels().length,u=i.reverse?n.max:n.min,d=cB(s,n,u),p=[];if(i.grid.circular){let h=n.getPointPositionForValue(0,u);return new Bv({x:h.x,y:h.y,radius:n.getDistanceFromCenterForValue(d)})}for(let h=0;h<l;++h)p.push(n.getPointPositionForValue(h,d));return p}function xv(a,n,s){let i=gB(n),{chart:l,index:u,line:d,scale:p,axis:h}=n,g=d.options,{fill:b,backgroundColor:y}=g,{above:v=y,below:T=y}=b||{},M=l.getDatasetMeta(u),I=uv(l,M);if(i&&d.points.length)Nd(a,s),SB(a,{line:d,target:i,above:v,below:T,area:s,scale:p,axis:h,clip:I}),zd(a)}function SB(a,n){let{line:s,target:i,above:l,below:u,area:d,scale:p,clip:h}=n,g=s._loop?"angle":n.axis;a.save();let b=u;if(u!==l){if(g==="x")CM(a,i,d.top),vv(a,{line:s,target:i,color:l,scale:p,property:g,clip:h}),a.restore(),a.save(),CM(a,i,d.bottom);else if(g==="y")TM(a,i,d.left),vv(a,{line:s,target:i,color:u,scale:p,property:g,clip:h}),a.restore(),a.save(),TM(a,i,d.right),b=l}vv(a,{line:s,target:i,color:b,scale:p,property:g,clip:h}),a.restore()}function CM(a,n,s){let{segments:i,points:l}=n,u=!0,d=!1;a.beginPath();for(let p of i){let{start:h,end:g}=p,b=l[h],y=l[Sm(h,g,l)];if(u)a.moveTo(b.x,b.y),u=!1;else a.lineTo(b.x,s),a.lineTo(b.x,b.y);if(d=!!n.pathSegment(a,p,{move:d}),d)a.closePath();else a.lineTo(y.x,s)}a.lineTo(n.first().x,s),a.closePath(),a.clip()}function TM(a,n,s){let{segments:i,points:l}=n,u=!0,d=!1;a.beginPath();for(let p of i){let{start:h,end:g}=p,b=l[h],y=l[Sm(h,g,l)];if(u)a.moveTo(b.x,b.y),u=!1;else a.lineTo(s,b.y),a.lineTo(b.x,b.y);if(d=!!n.pathSegment(a,p,{move:d}),d)a.closePath();else a.lineTo(s,y.y)}a.lineTo(s,n.first().y),a.closePath(),a.clip()}function vv(a,n){let{line:s,target:i,property:l,color:u,scale:d,clip:p}=n,h=nB(s,i,l);for(let{source:g,target:b,start:y,end:v}of h){let{style:{backgroundColor:T=u}={}}=g,M=i!==!0;a.save(),a.fillStyle=T,LB(a,d,p,M&&Tv(l,y,v)),a.beginPath();let I=!!s.pathSegment(a,g),w;if(M){if(I)a.closePath();else wM(a,i,v,l);let A=!!i.pathSegment(a,b,{move:I,reverse:!0});if(w=I&&A,!w)wM(a,i,y,l)}a.closePath(),a.fill(w?"evenodd":"nonzero"),a.restore()}}function LB(a,n,s,i){let l=n.chart.chartArea,{property:u,start:d,end:p}=i||{};if(u==="x"||u==="y"){let h,g,b,y;if(u==="x")h=d,g=l.top,b=p,y=l.bottom;else h=l.left,g=d,b=l.right,y=p;if(a.beginPath(),s)h=Math.max(h,s.left),b=Math.min(b,s.right),g=Math.max(g,s.top),y=Math.min(y,s.bottom);a.rect(h,g,b-h,y-g),a.clip()}}function wM(a,n,s,i){let l=n.interpolate(s,i);if(l)a.lineTo(l.x,l.y)}var uI={id:"filler",afterDatasetsUpdate(a,n,s){let i=(a.data.datasets||[]).length,l=[],u,d,p,h;for(d=0;d<i;++d){if(u=a.getDatasetMeta(d),p=u.dataset,h=null,p&&p.options&&p instanceof Hu)h={visible:a.isDatasetVisible(d),index:d,fill:iB(p,d,i),chart:a,axis:u.controller.options.indexAxis,scale:u.vScale,line:p};u.$filler=h,l.push(h)}for(d=0;d<i;++d){if(h=l[d],!h||h.fill===!1)continue;h.fill=rB(l,d,s.propagate)}},beforeDraw(a,n,s){let i=s.drawTime==="beforeDraw",l=a.getSortedVisibleDatasetMetas(),u=a.chartArea;for(let d=l.length-1;d>=0;--d){let p=l[d].$filler;if(!p)continue;if(p.line.updateControlPoints(u,p.axis),i&&p.fill)xv(a.ctx,p,u)}},beforeDatasetsDraw(a,n,s){if(s.drawTime!=="beforeDatasetsDraw")return;let i=a.getSortedVisibleDatasetMetas();for(let l=i.length-1;l>=0;--l){let u=i[l].$filler;if(LM(u))xv(a.ctx,u,a.chartArea)}},beforeDatasetDraw(a,n,s){let i=n.meta.$filler;if(!LM(i)||s.drawTime!=="beforeDatasetDraw")return;xv(a.ctx,i,a.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}},kM=(a,n)=>{let{boxHeight:s=n,boxWidth:i=n}=a;if(a.usePointStyle)s=Math.min(s,n),i=a.pointStyleWidth||Math.min(i,n);return{boxWidth:i,boxHeight:s,itemHeight:Math.max(n,s)}},CB=(a,n)=>a!==null&&n!==null&&a.datasetIndex===n.datasetIndex&&a.index===n.index;class wv extends Xs{constructor(a){super();this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=a.chart,this.options=a.options,this.ctx=a.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(a,n,s){this.maxWidth=a,this.maxHeight=n,this._margins=s,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){if(this.isHorizontal())this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width;else this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height}buildLabels(){let a=this.options.labels||{},n=Ot(a.generateLabels,[this.chart],this)||[];if(a.filter)n=n.filter((s)=>a.filter(s,this.chart.data));if(a.sort)n=n.sort((s,i)=>a.sort(s,i,this.chart.data));if(this.options.reverse)n.reverse();this.legendItems=n}fit(){let{options:a,ctx:n}=this;if(!a.display){this.width=this.height=0;return}let s=a.labels,i=pa(s.font),l=i.size,u=this._computeTitleHeight(),{boxWidth:d,itemHeight:p}=kM(s,l),h,g;if(n.font=i.string,this.isHorizontal())h=this.maxWidth,g=this._fitRows(u,l,d,p)+10;else g=this.maxHeight,h=this._fitCols(u,i,d,p)+10;this.width=Math.min(h,a.maxWidth||this.maxWidth),this.height=Math.min(g,a.maxHeight||this.maxHeight)}_fitRows(a,n,s,i){let{ctx:l,maxWidth:u,options:{labels:{padding:d}}}=this,p=this.legendHitBoxes=[],h=this.lineWidths=[0],g=i+d,b=a;l.textAlign="left",l.textBaseline="middle";let y=-1,v=-g;return this.legendItems.forEach((T,M)=>{let I=s+n/2+l.measureText(T.text).width;if(M===0||h[h.length-1]+I+2*d>u)b+=g,h[h.length-(M>0?0:1)]=0,v+=g,y++;p[M]={left:0,top:v,row:y,width:I,height:i},h[h.length-1]+=I+d}),b}_fitCols(a,n,s,i){let{ctx:l,maxHeight:u,options:{labels:{padding:d}}}=this,p=this.legendHitBoxes=[],h=this.columnSizes=[],g=u-a,b=d,y=0,v=0,T=0,M=0;return this.legendItems.forEach((I,w)=>{let{itemWidth:A,itemHeight:B}=TB(s,n,l,I,i);if(w>0&&v+B+2*d>g)b+=y+d,h.push({width:y,height:v}),T+=y+d,M++,y=v=0;p[w]={left:T,top:v,col:M,width:A,height:B},y=Math.max(y,A),v+=B+d}),b+=y,h.push({width:y,height:v}),b}adjustHitBoxes(){if(!this.options.display)return;let a=this._computeTitleHeight(),{legendHitBoxes:n,options:{align:s,labels:{padding:i},rtl:l}}=this,u=il(l,this.left,this.width);if(this.isHorizontal()){let d=0,p=Ba(s,this.left+i,this.right-this.lineWidths[d]);for(let h of n){if(d!==h.row)d=h.row,p=Ba(s,this.left+i,this.right-this.lineWidths[d]);h.top+=this.top+a+i,h.left=u.leftForLtr(u.x(p),h.width),p+=h.width+i}}else{let d=0,p=Ba(s,this.top+a+i,this.bottom-this.columnSizes[d].height);for(let h of n){if(h.col!==d)d=h.col,p=Ba(s,this.top+a+i,this.bottom-this.columnSizes[d].height);h.top=p,h.left+=this.left+i,h.left=u.leftForLtr(u.x(h.left),h.width),p+=h.height+i}}}isHorizontal(){return this.options.position==="top"||this.options.position==="bottom"}draw(){if(this.options.display){let a=this.ctx;Nd(a,this),this._draw(),zd(a)}}_draw(){let{options:a,columnSizes:n,lineWidths:s,ctx:i}=this,{align:l,labels:u}=a,d=Jt.color,p=il(a.rtl,this.left,this.width),h=pa(u.font),{padding:g}=u,b=h.size,y=b/2,v;this.drawTitle(),i.textAlign=p.textAlign("left"),i.textBaseline="middle",i.lineWidth=0.5,i.font=h.string;let{boxWidth:T,boxHeight:M,itemHeight:I}=kM(u,b),w=function(V,G,X){if(isNaN(T)||T<=0||isNaN(M)||M<0)return;i.save();let Y=Ke(X.lineWidth,1);if(i.fillStyle=Ke(X.fillStyle,d),i.lineCap=Ke(X.lineCap,"butt"),i.lineDashOffset=Ke(X.lineDashOffset,0),i.lineJoin=Ke(X.lineJoin,"miter"),i.lineWidth=Y,i.strokeStyle=Ke(X.strokeStyle,d),i.setLineDash(Ke(X.lineDash,[])),u.usePointStyle){let J={radius:M*Math.SQRT2/2,pointStyle:X.pointStyle,rotation:X.rotation,borderWidth:Y},j=p.xPlus(V,T/2),se=G+y;Qx(i,J,j,se,u.pointStyleWidth&&T)}else{let J=G+Math.max((b-M)/2,0),j=p.leftForLtr(V,T),se=ti(X.borderRadius);if(i.beginPath(),Object.values(se).some((ge)=>ge!==0))zu(i,{x:j,y:J,w:T,h:M,radius:se});else i.rect(j,J,T,M);if(i.fill(),Y!==0)i.stroke()}i.restore()},A=function(V,G,X){ei(i,X.text,V,G+I/2,h,{strikethrough:X.hidden,textAlign:p.textAlign(X.textAlign)})},B=this.isHorizontal(),z=this._computeTitleHeight();if(B)v={x:Ba(l,this.left+g,this.right-s[0]),y:this.top+g+z,line:0};else v={x:this.left+g,y:Ba(l,this.top+z+g,this.bottom-n[0].height),line:0};sv(this.ctx,a.textDirection);let H=I+g;this.legendItems.forEach((V,G)=>{i.strokeStyle=V.fontColor,i.fillStyle=V.fontColor;let X=i.measureText(V.text).width,Y=p.textAlign(V.textAlign||(V.textAlign=u.textAlign)),J=T+y+X,j=v.x,se=v.y;if(p.setWidth(this.width),B){if(G>0&&j+J+g>this.right)se=v.y+=H,v.line++,j=v.x=Ba(l,this.left+g,this.right-s[v.line])}else if(G>0&&se+H>this.bottom)j=v.x=j+n[v.line].width+g,v.line++,se=v.y=Ba(l,this.top+z+g,this.bottom-n[v.line].height);let ge=p.x(j);if(w(ge,se,V),j=kk(Y,j+T+y,B?j+J:this.right,a.rtl),A(p.x(j),se,V),B)v.x+=J+g;else if(typeof V.text!=="string"){let ye=h.lineHeight;v.y+=cI(V,ye)+g}else v.y+=H}),rv(this.ctx,a.textDirection)}drawTitle(){let a=this.options,n=a.title,s=pa(n.font),i=Na(n.padding);if(!n.display)return;let l=il(a.rtl,this.left,this.width),u=this.ctx,d=n.position,p=s.size/2,h=i.top+p,g,b=this.left,y=this.width;if(this.isHorizontal())y=Math.max(...this.lineWidths),g=this.top+h,b=Ba(a.align,b,this.right-y);else{let T=this.columnSizes.reduce((M,I)=>Math.max(M,I.height),0);g=h+Ba(a.align,this.top,this.bottom-T-a.labels.padding-this._computeTitleHeight())}let v=Ba(d,b,b+y);u.textAlign=l.textAlign(nm(d)),u.textBaseline="middle",u.strokeStyle=n.color,u.fillStyle=n.color,u.font=s.string,ei(u,n.text,v,g,s)}_computeTitleHeight(){let a=this.options.title,n=pa(a.font),s=Na(a.padding);return a.display?n.lineHeight+s.height:0}_getLegendItemAt(a,n){let s,i,l;if(qs(a,this.left,this.right)&&qs(n,this.top,this.bottom)){l=this.legendHitBoxes;for(s=0;s<l.length;++s)if(i=l[s],qs(a,i.left,i.left+i.width)&&qs(n,i.top,i.top+i.height))return this.legendItems[s]}return null}handleEvent(a){let n=this.options;if(!MB(a.type,n))return;let s=this._getLegendItemAt(a.x,a.y);if(a.type==="mousemove"||a.type==="mouseout"){let i=this._hoveredItem,l=CB(i,s);if(i&&!l)Ot(n.onLeave,[a,i,this],this);if(this._hoveredItem=s,s&&!l)Ot(n.onHover,[a,s,this],this)}else if(s)Ot(n.onClick,[a,s,this],this)}}function TB(a,n,s,i,l){let u=wB(i,a,n,s),d=kB(l,i,n.lineHeight);return{itemWidth:u,itemHeight:d}}function wB(a,n,s,i){let l=a.text;if(l&&typeof l!=="string")l=l.reduce((u,d)=>u.length>d.length?u:d);return n+s.size/2+i.measureText(l).width}function kB(a,n,s){let i=a;if(typeof n.text!=="string")i=cI(n,s);return i}function cI(a,n){let s=a.text?a.text.length:0;return n*s}function MB(a,n){if((a==="mousemove"||a==="mouseout")&&(n.onHover||n.onLeave))return!0;if(n.onClick&&(a==="click"||a==="mouseup"))return!0;return!1}var dI={id:"legend",_element:wv,start(a,n,s){let i=a.legend=new wv({ctx:a.ctx,options:s,chart:a});nn.configure(a,i,s),nn.addBox(a,i)},stop(a){nn.removeBox(a,a.legend),delete a.legend},beforeUpdate(a,n,s){let i=a.legend;nn.configure(a,i,s),i.options=s},afterUpdate(a){let n=a.legend;n.buildLabels(),n.adjustHitBoxes()},afterEvent(a,n){if(!n.replay)a.legend.handleEvent(n.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1000,onClick(a,n,s){let i=n.datasetIndex,l=s.chart;if(l.isDatasetVisible(i))l.hide(i),n.hidden=!0;else l.show(i),n.hidden=!1},onHover:null,onLeave:null,labels:{color:(a)=>a.chart.options.color,boxWidth:40,padding:10,generateLabels(a){let n=a.data.datasets,{labels:{usePointStyle:s,pointStyle:i,textAlign:l,color:u,useBorderRadius:d,borderRadius:p}}=a.legend.options;return a._getSortedDatasetMetas().map((h)=>{let g=h.controller.getStyle(s?0:void 0),b=Na(g.borderWidth);return{text:n[h.index].label,fillStyle:g.backgroundColor,fontColor:u,hidden:!h.visible,lineCap:g.borderCapStyle,lineDash:g.borderDash,lineDashOffset:g.borderDashOffset,lineJoin:g.borderJoinStyle,lineWidth:(b.width+b.height)/4,strokeStyle:g.borderColor,pointStyle:i||g.pointStyle,rotation:g.rotation,textAlign:l||g.textAlign,borderRadius:d&&(p||g.borderRadius),datasetIndex:h.index}},this)}},title:{color:(a)=>a.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:(a)=>!a.startsWith("on"),labels:{_scriptable:(a)=>!["generateLabels","filter","sort"].includes(a)}}};class Nv extends Xs{constructor(a){super();this.chart=a.chart,this.options=a.options,this.ctx=a.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(a,n){let s=this.options;if(this.left=0,this.top=0,!s.display){this.width=this.height=this.right=this.bottom=0;return}this.width=this.right=a,this.height=this.bottom=n;let i=zt(s.text)?s.text.length:1;this._padding=Na(s.padding);let l=i*pa(s.font).lineHeight+this._padding.height;if(this.isHorizontal())this.height=l;else this.width=l}isHorizontal(){let a=this.options.position;return a==="top"||a==="bottom"}_drawArgs(a){let{top:n,left:s,bottom:i,right:l,options:u}=this,d=u.align,p=0,h,g,b;if(this.isHorizontal())g=Ba(d,s,l),b=n+a,h=l-s;else{if(u.position==="left")g=s+a,b=Ba(d,i,n),p=na*-0.5;else g=l-a,b=Ba(d,n,i),p=na*0.5;h=i-n}return{titleX:g,titleY:b,maxWidth:h,rotation:p}}draw(){let a=this.ctx,n=this.options;if(!n.display)return;let s=pa(n.font),l=s.lineHeight/2+this._padding.top,{titleX:u,titleY:d,maxWidth:p,rotation:h}=this._drawArgs(l);ei(a,n.text,0,0,s,{color:n.color,maxWidth:p,rotation:h,textAlign:nm(n.align),textBaseline:"middle",translation:[u,d]})}}function IB(a,n){let s=new Nv({ctx:a.ctx,options:n,chart:a});nn.configure(a,s,n),nn.addBox(a,s),a.titleBlock=s}var fI={id:"title",_element:Nv,start(a,n,s){IB(a,s)},stop(a){let n=a.titleBlock;nn.removeBox(a,n),delete a.titleBlock},beforeUpdate(a,n,s){let i=a.titleBlock;nn.configure(a,i,s),i.options=s},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2000},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};var Yd={average(a){if(!a.length)return!1;let n,s,i=new Set,l=0,u=0;for(n=0,s=a.length;n<s;++n){let p=a[n].element;if(p&&p.hasValue()){let h=p.tooltipPosition();i.add(h.x),l+=h.y,++u}}if(u===0||i.size===0)return!1;return{x:[...i].reduce((p,h)=>p+h)/i.size,y:l/u}},nearest(a,n){if(!a.length)return!1;let{x:s,y:i}=n,l=Number.POSITIVE_INFINITY,u,d,p;for(u=0,d=a.length;u<d;++u){let h=a[u].element;if(h&&h.hasValue()){let g=h.getCenterPoint(),b=Jh(n,g);if(b<l)l=b,p=h}}if(p){let h=p.tooltipPosition();s=h.x,i=h.y}return{x:s,y:i}}};function ns(a,n){if(n)if(zt(n))Array.prototype.push.apply(a,n);else a.push(n);return a}function Gs(a){if((typeof a==="string"||a instanceof String)&&a.indexOf(`
256
256
  `)>-1)return a.split(`
257
- `);return a}function AB(a,n){let{element:s,datasetIndex:i,index:l}=n,u=a.getDatasetMeta(i).controller,{label:d,value:p}=u.getLabelAndValue(l);return{chart:a,label:d,parsed:u.getParsed(l),raw:a.data.datasets[i].data[l],formattedValue:p,dataset:u.getDataset(),dataIndex:l,datasetIndex:i,element:s}}function MM(a,n){let s=a.chart.ctx,{body:i,footer:l,title:u}=a,{boxWidth:d,boxHeight:p}=n,h=pa(n.bodyFont),g=pa(n.titleFont),b=pa(n.footerFont),y=u.length,v=l.length,T=i.length,M=Na(n.padding),I=M.height,w=0,A=i.reduce((H,V)=>H+V.before.length+V.lines.length+V.after.length,0);if(A+=a.beforeBody.length+a.afterBody.length,y)I+=y*g.lineHeight+(y-1)*n.titleSpacing+n.titleMarginBottom;if(A){let H=n.displayColors?Math.max(p,h.lineHeight):h.lineHeight;I+=T*H+(A-T)*h.lineHeight+(A-1)*n.bodySpacing}if(v)I+=n.footerMarginTop+v*b.lineHeight+(v-1)*n.footerSpacing;let B=0,z=function(H){w=Math.max(w,s.measureText(H).width+B)};return s.save(),s.font=g.string,Lt(a.title,z),s.font=h.string,Lt(a.beforeBody.concat(a.afterBody),z),B=n.displayColors?d+2+n.boxPadding:0,Lt(i,(H)=>{Lt(H.before,z),Lt(H.lines,z),Lt(H.after,z)}),B=0,s.font=b.string,Lt(a.footer,z),s.restore(),w+=M.width,{width:w,height:I}}function RB(a,n){let{y:s,height:i}=n;if(s<i/2)return"top";else if(s>a.height-i/2)return"bottom";return"center"}function _B(a,n,s,i){let{x:l,width:u}=i,d=s.caretSize+s.caretPadding;if(a==="left"&&l+u+d>n.width)return!0;if(a==="right"&&l-u-d<0)return!0}function DB(a,n,s,i){let{x:l,width:u}=s,{width:d,chartArea:{left:p,right:h}}=a,g="center";if(i==="center")g=l<=(p+h)/2?"left":"right";else if(l<=u/2)g="left";else if(l>=d-u/2)g="right";if(_B(g,a,n,s))g="center";return g}function IM(a,n,s){let i=s.yAlign||n.yAlign||RB(a,s);return{xAlign:s.xAlign||n.xAlign||DB(a,n,s,i),yAlign:i}}function EB(a,n){let{x:s,width:i}=a;if(n==="right")s-=i;else if(n==="center")s-=i/2;return s}function OB(a,n,s){let{y:i,height:l}=a;if(n==="top")i+=s;else if(n==="bottom")i-=l+s;else i-=l/2;return i}function AM(a,n,s,i){let{caretSize:l,caretPadding:u,cornerRadius:d}=a,{xAlign:p,yAlign:h}=s,g=l+u,{topLeft:b,topRight:y,bottomLeft:v,bottomRight:T}=ti(d),M=EB(n,p),I=OB(n,h,g);if(h==="center"){if(p==="left")M+=g;else if(p==="right")M-=g}else if(p==="left")M-=Math.max(b,v)+l;else if(p==="right")M+=Math.max(y,T)+l;return{x:mo(M,0,i.width-n.width),y:mo(I,0,i.height-n.height)}}function mm(a,n,s){let i=Na(s.padding);return n==="center"?a.x+a.width/2:n==="right"?a.x+a.width-i.right:a.x+i.left}function RM(a){return ns([],Gs(a))}function PB(a,n,s){return Vs(a,{tooltip:n,tooltipItems:s,type:"tooltip"})}function _M(a,n){let s=n&&n.dataset&&n.dataset.tooltip&&n.dataset.tooltip.callbacks;return s?a.override(s):a}var pI={beforeTitle:os,title(a){if(a.length>0){let n=a[0],s=n.chart.data.labels,i=s?s.length:0;if(this&&this.options&&this.options.mode==="dataset")return n.dataset.label||"";else if(n.label)return n.label;else if(i>0&&n.dataIndex<i)return s[n.dataIndex]}return""},afterTitle:os,beforeBody:os,beforeLabel:os,label(a){if(this&&this.options&&this.options.mode==="dataset")return a.label+": "+a.formattedValue||a.formattedValue;let n=a.dataset.label||"";if(n)n+=": ";let s=a.formattedValue;if(!ht(s))n+=s;return n},labelColor(a){let s=a.chart.getDatasetMeta(a.datasetIndex).controller.getStyle(a.dataIndex);return{borderColor:s.borderColor,backgroundColor:s.backgroundColor,borderWidth:s.borderWidth,borderDash:s.borderDash,borderDashOffset:s.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(a){let s=a.chart.getDatasetMeta(a.datasetIndex).controller.getStyle(a.dataIndex);return{pointStyle:s.pointStyle,rotation:s.rotation}},afterLabel:os,afterBody:os,beforeFooter:os,footer:os,afterFooter:os};function yo(a,n,s,i){let l=a[n].call(s,i);if(typeof l>"u")return pI[n].call(s,i);return l}class kv extends Xs{static positioners=Yd;constructor(a){super();this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=a.chart,this.options=a.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(a){this.options=a,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){let a=this._cachedAnimations;if(a)return a;let n=this.chart,s=this.options.setContext(this.getContext()),i=s.enabled&&n.options.animation&&s.animations,l=new Av(this.chart,i);if(i._cacheable)this._cachedAnimations=Object.freeze(l);return l}getContext(){return this.$context||(this.$context=PB(this.chart.getContext(),this,this._tooltipItems))}getTitle(a,n){let{callbacks:s}=n,i=yo(s,"beforeTitle",this,a),l=yo(s,"title",this,a),u=yo(s,"afterTitle",this,a),d=[];return d=ns(d,Gs(i)),d=ns(d,Gs(l)),d=ns(d,Gs(u)),d}getBeforeBody(a,n){return RM(yo(n.callbacks,"beforeBody",this,a))}getBody(a,n){let{callbacks:s}=n,i=[];return Lt(a,(l)=>{let u={before:[],lines:[],after:[]},d=_M(s,l);ns(u.before,Gs(yo(d,"beforeLabel",this,l))),ns(u.lines,yo(d,"label",this,l)),ns(u.after,Gs(yo(d,"afterLabel",this,l))),i.push(u)}),i}getAfterBody(a,n){return RM(yo(n.callbacks,"afterBody",this,a))}getFooter(a,n){let{callbacks:s}=n,i=yo(s,"beforeFooter",this,a),l=yo(s,"footer",this,a),u=yo(s,"afterFooter",this,a),d=[];return d=ns(d,Gs(i)),d=ns(d,Gs(l)),d=ns(d,Gs(u)),d}_createItems(a){let n=this._active,s=this.chart.data,i=[],l=[],u=[],d=[],p,h;for(p=0,h=n.length;p<h;++p)d.push(AB(this.chart,n[p]));if(a.filter)d=d.filter((g,b,y)=>a.filter(g,b,y,s));if(a.itemSort)d=d.sort((g,b)=>a.itemSort(g,b,s));return Lt(d,(g)=>{let b=_M(a.callbacks,g);i.push(yo(b,"labelColor",this,g)),l.push(yo(b,"labelPointStyle",this,g)),u.push(yo(b,"labelTextColor",this,g))}),this.labelColors=i,this.labelPointStyles=l,this.labelTextColors=u,this.dataPoints=d,d}update(a,n){let s=this.options.setContext(this.getContext()),i=this._active,l,u=[];if(!i.length){if(this.opacity!==0)l={opacity:0}}else{let d=Yd[s.position].call(this,i,this._eventPosition);u=this._createItems(s),this.title=this.getTitle(u,s),this.beforeBody=this.getBeforeBody(u,s),this.body=this.getBody(u,s),this.afterBody=this.getAfterBody(u,s),this.footer=this.getFooter(u,s);let p=this._size=MM(this,s),h=Object.assign({},d,p),g=IM(this.chart,s,h),b=AM(s,h,g,this.chart);this.xAlign=g.xAlign,this.yAlign=g.yAlign,l={opacity:1,x:b.x,y:b.y,width:p.width,height:p.height,caretX:d.x,caretY:d.y}}if(this._tooltipItems=u,this.$context=void 0,l)this._resolveAnimations().update(this,l);if(a&&s.external)s.external.call(this,{chart:this.chart,tooltip:this,replay:n})}drawCaret(a,n,s,i){let l=this.getCaretPosition(a,s,i);n.lineTo(l.x1,l.y1),n.lineTo(l.x2,l.y2),n.lineTo(l.x3,l.y3)}getCaretPosition(a,n,s){let{xAlign:i,yAlign:l}=this,{caretSize:u,cornerRadius:d}=s,{topLeft:p,topRight:h,bottomLeft:g,bottomRight:b}=ti(d),{x:y,y:v}=a,{width:T,height:M}=n,I,w,A,B,z,H;if(l==="center"){if(z=v+M/2,i==="left")I=y,w=I-u,B=z+u,H=z-u;else I=y+T,w=I+u,B=z-u,H=z+u;A=I}else{if(i==="left")w=y+Math.max(p,g)+u;else if(i==="right")w=y+T-Math.max(h,b)-u;else w=this.caretX;if(l==="top")B=v,z=B-u,I=w-u,A=w+u;else B=v+M,z=B+u,I=w+u,A=w-u;H=B}return{x1:I,x2:w,x3:A,y1:B,y2:z,y3:H}}drawTitle(a,n,s){let i=this.title,l=i.length,u,d,p;if(l){let h=il(s.rtl,this.x,this.width);a.x=mm(this,s.titleAlign,s),n.textAlign=h.textAlign(s.titleAlign),n.textBaseline="middle",u=pa(s.titleFont),d=s.titleSpacing,n.fillStyle=s.titleColor,n.font=u.string;for(p=0;p<l;++p)if(n.fillText(i[p],h.x(a.x),a.y+u.lineHeight/2),a.y+=u.lineHeight+d,p+1===l)a.y+=s.titleMarginBottom-d}}_drawColorBox(a,n,s,i,l){let u=this.labelColors[s],d=this.labelPointStyles[s],{boxHeight:p,boxWidth:h}=l,g=pa(l.bodyFont),b=mm(this,"left",l),y=i.x(b),v=p<g.lineHeight?(g.lineHeight-p)/2:0,T=n.y+v;if(l.usePointStyle){let M={radius:Math.min(h,p)/2,pointStyle:d.pointStyle,rotation:d.rotation,borderWidth:1},I=i.leftForLtr(y,h)+h/2,w=T+p/2;a.strokeStyle=l.multiKeyBackground,a.fillStyle=l.multiKeyBackground,im(a,M,I,w),a.strokeStyle=u.borderColor,a.fillStyle=u.backgroundColor,im(a,M,I,w)}else{a.lineWidth=it(u.borderWidth)?Math.max(...Object.values(u.borderWidth)):u.borderWidth||1,a.strokeStyle=u.borderColor,a.setLineDash(u.borderDash||[]),a.lineDashOffset=u.borderDashOffset||0;let M=i.leftForLtr(y,h),I=i.leftForLtr(i.xPlus(y,1),h-2),w=ti(u.borderRadius);if(Object.values(w).some((A)=>A!==0))a.beginPath(),a.fillStyle=l.multiKeyBackground,zu(a,{x:M,y:T,w:h,h:p,radius:w}),a.fill(),a.stroke(),a.fillStyle=u.backgroundColor,a.beginPath(),zu(a,{x:I,y:T+1,w:h-2,h:p-2,radius:w}),a.fill();else a.fillStyle=l.multiKeyBackground,a.fillRect(M,T,h,p),a.strokeRect(M,T,h,p),a.fillStyle=u.backgroundColor,a.fillRect(I,T+1,h-2,p-2)}a.fillStyle=this.labelTextColors[s]}drawBody(a,n,s){let{body:i}=this,{bodySpacing:l,bodyAlign:u,displayColors:d,boxHeight:p,boxWidth:h,boxPadding:g}=s,b=pa(s.bodyFont),y=b.lineHeight,v=0,T=il(s.rtl,this.x,this.width),M=function(X){n.fillText(X,T.x(a.x+v),a.y+y/2),a.y+=y+l},I=T.textAlign(u),w,A,B,z,H,V,G;n.textAlign=u,n.textBaseline="middle",n.font=b.string,a.x=mm(this,I,s),n.fillStyle=s.bodyColor,Lt(this.beforeBody,M),v=d&&I!=="right"?u==="center"?h/2+g:h+2+g:0;for(z=0,V=i.length;z<V;++z){if(w=i[z],A=this.labelTextColors[z],n.fillStyle=A,Lt(w.before,M),B=w.lines,d&&B.length)this._drawColorBox(n,a,z,T,s),y=Math.max(b.lineHeight,p);for(H=0,G=B.length;H<G;++H)M(B[H]),y=b.lineHeight;Lt(w.after,M)}v=0,y=b.lineHeight,Lt(this.afterBody,M),a.y-=l}drawFooter(a,n,s){let i=this.footer,l=i.length,u,d;if(l){let p=il(s.rtl,this.x,this.width);a.x=mm(this,s.footerAlign,s),a.y+=s.footerMarginTop,n.textAlign=p.textAlign(s.footerAlign),n.textBaseline="middle",u=pa(s.footerFont),n.fillStyle=s.footerColor,n.font=u.string;for(d=0;d<l;++d)n.fillText(i[d],p.x(a.x),a.y+u.lineHeight/2),a.y+=u.lineHeight+s.footerSpacing}}drawBackground(a,n,s,i){let{xAlign:l,yAlign:u}=this,{x:d,y:p}=a,{width:h,height:g}=s,{topLeft:b,topRight:y,bottomLeft:v,bottomRight:T}=ti(i.cornerRadius);if(n.fillStyle=i.backgroundColor,n.strokeStyle=i.borderColor,n.lineWidth=i.borderWidth,n.beginPath(),n.moveTo(d+b,p),u==="top")this.drawCaret(a,n,s,i);if(n.lineTo(d+h-y,p),n.quadraticCurveTo(d+h,p,d+h,p+y),u==="center"&&l==="right")this.drawCaret(a,n,s,i);if(n.lineTo(d+h,p+g-T),n.quadraticCurveTo(d+h,p+g,d+h-T,p+g),u==="bottom")this.drawCaret(a,n,s,i);if(n.lineTo(d+v,p+g),n.quadraticCurveTo(d,p+g,d,p+g-v),u==="center"&&l==="left")this.drawCaret(a,n,s,i);if(n.lineTo(d,p+b),n.quadraticCurveTo(d,p,d+b,p),n.closePath(),n.fill(),i.borderWidth>0)n.stroke()}_updateAnimationTarget(a){let n=this.chart,s=this.$animations,i=s&&s.x,l=s&&s.y;if(i||l){let u=Yd[a.position].call(this,this._active,this._eventPosition);if(!u)return;let d=this._size=MM(this,a),p=Object.assign({},u,this._size),h=IM(n,a,p),g=AM(a,p,h,n);if(i._to!==g.x||l._to!==g.y)this.xAlign=h.xAlign,this.yAlign=h.yAlign,this.width=d.width,this.height=d.height,this.caretX=u.x,this.caretY=u.y,this._resolveAnimations().update(this,g)}}_willRender(){return!!this.opacity}draw(a){let n=this.options.setContext(this.getContext()),s=this.opacity;if(!s)return;this._updateAnimationTarget(n);let i={width:this.width,height:this.height},l={x:this.x,y:this.y};s=Math.abs(s)<0.001?0:s;let u=Na(n.padding),d=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;if(n.enabled&&d)a.save(),a.globalAlpha=s,this.drawBackground(l,a,i,n),sv(a,n.textDirection),l.y+=u.top,this.drawTitle(l,a,n),this.drawBody(l,a,n),this.drawFooter(l,a,n),rv(a,n.textDirection),a.restore()}getActiveElements(){return this._active||[]}setActiveElements(a,n){let s=this._active,i=a.map(({datasetIndex:d,index:p})=>{let h=this.chart.getDatasetMeta(d);if(!h)throw Error("Cannot find a dataset at index "+d);return{datasetIndex:d,element:h.data[p],index:p}}),l=!Pd(s,i),u=this._positionChanged(i,n);if(l||u)this._active=i,this._eventPosition=n,this._ignoreReplayEvents=!0,this.update(!0)}handleEvent(a,n,s=!0){if(n&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;let i=this.options,l=this._active||[],u=this._getActiveElements(a,l,n,s),d=this._positionChanged(u,a),p=n||!Pd(u,l)||d;if(p){if(this._active=u,i.enabled||i.external)this._eventPosition={x:a.x,y:a.y},this.update(!0,n)}return p}_getActiveElements(a,n,s,i){let l=this.options;if(a.type==="mouseout")return[];if(!i)return n.filter((d)=>this.chart.data.datasets[d.datasetIndex]&&this.chart.getDatasetMeta(d.datasetIndex).controller.getParsed(d.index)!==void 0);let u=this.chart.getElementsAtEventForMode(a,l.mode,l,s);if(l.reverse)u.reverse();return u}_positionChanged(a,n){let{caretX:s,caretY:i,options:l}=this,u=Yd[l.position].call(this,a,n);return u!==!1&&(s!==u.x||i!==u.y)}}var hI={id:"tooltip",_element:kv,positioners:Yd,afterInit(a,n,s){if(s)a.tooltip=new kv({chart:a,options:s})},beforeUpdate(a,n,s){if(a.tooltip)a.tooltip.initialize(s)},reset(a,n,s){if(a.tooltip)a.tooltip.initialize(s)},afterDraw(a){let n=a.tooltip;if(n&&n._willRender()){let s={tooltip:n};if(a.notifyPlugins("beforeTooltipDraw",{...s,cancelable:!0})===!1)return;n.draw(a.ctx),a.notifyPlugins("afterTooltipDraw",s)}},afterEvent(a,n){if(a.tooltip){let s=n.replay;if(a.tooltip.handleEvent(n.event,s,n.inChartArea))n.changed=!0}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(a,n)=>n.bodyFont.size,boxWidth:(a,n)=>n.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:pI},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:(a)=>a!=="filter"&&a!=="itemSort"&&a!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};var BB=(a,n,s,i)=>{if(typeof n==="string")s=a.push(n)-1,i.unshift({index:s,label:n});else if(isNaN(n))s=null;return s};function NB(a,n,s,i){let l=a.indexOf(n);if(l===-1)return BB(a,n,s,i);let u=a.lastIndexOf(n);return l!==u?s:l}var zB=(a,n)=>a===null?null:mo(Math.round(a),0,n);function DM(a){let n=this.getLabels();if(a>=0&&a<n.length)return n[a];return a}class zv extends cl{static id="category";static defaults={ticks:{callback:DM}};constructor(a){super(a);this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(a){let n=this._addedLabels;if(n.length){let s=this.getLabels();for(let{index:i,label:l}of n)if(s[i]===l)s.splice(i,1);this._addedLabels=[]}super.init(a)}parse(a,n){if(ht(a))return null;let s=this.getLabels();return n=isFinite(n)&&s[n]===a?n:NB(s,a,Ke(n,a),this._addedLabels),zB(n,s.length-1)}determineDataLimits(){let{minDefined:a,maxDefined:n}=this.getUserBounds(),{min:s,max:i}=this.getMinMax(!0);if(this.options.bounds==="ticks"){if(!a)s=0;if(!n)i=this.getLabels().length-1}this.min=s,this.max=i}buildTicks(){let a=this.min,n=this.max,s=this.options.offset,i=[],l=this.getLabels();l=a===0&&n===l.length-1?l:l.slice(a,n+1),this._valueRange=Math.max(l.length-(s?0:1),1),this._startValue=this.min-(s?0.5:0);for(let u=a;u<=n;u++)i.push({value:u});return i}getLabelForValue(a){return DM.call(this,a)}configure(){if(super.configure(),!this.isHorizontal())this._reversePixels=!this._reversePixels}getPixelForValue(a){if(typeof a!=="number")a=this.parse(a);return a===null?NaN:this.getPixelForDecimal((a-this._startValue)/this._valueRange)}getPixelForTick(a){let n=this.ticks;if(a<0||a>n.length-1)return null;return this.getPixelForValue(n[a].value)}getValueForPixel(a){return Math.round(this._startValue+this.getDecimalForPixel(a)*this._valueRange)}getBasePixel(){return this.bottom}}function HB(a,n){let s=[],i=0.00000000000001,{bounds:l,step:u,min:d,max:p,precision:h,count:g,maxTicks:b,maxDigits:y,includeBounds:v}=a,T=u||1,M=b-1,{min:I,max:w}=n,A=!ht(d),B=!ht(p),z=!ht(g),H=(w-I)/(y+1),V=Ux((w-I)/M/T)*T,G,X,Y,J;if(V<0.00000000000001&&!A&&!B)return[{value:I},{value:w}];if(J=Math.ceil(w/V)-Math.floor(I/V),J>M)V=Ux(J*V/M/T)*T;if(!ht(h))G=Math.pow(10,h),V=Math.ceil(V*G)/G;if(l==="ticks")X=Math.floor(I/V)*V,Y=Math.ceil(w/V)*V;else X=I,Y=w;if(A&&B&&u&&bk((p-d)/u,V/1000))J=Math.round(Math.min((p-d)/V,b)),V=(p-d)/J,X=d,Y=p;else if(z)X=A?d:X,Y=B?p:Y,J=g-1,V=(Y-X)/J;else if(J=(Y-X)/V,Bu(J,Math.round(J),V/1000))J=Math.round(J);else J=Math.ceil(J);let j=Math.max(qx(V),qx(X));G=Math.pow(10,ht(h)?j:h),X=Math.round(X*G)/G,Y=Math.round(Y*G)/G;let se=0;if(A){if(v&&X!==d){if(s.push({value:d}),X<d)se++;if(Bu(Math.round((X+se*V)*G)/G,d,EM(d,H,a)))se++}else if(X<d)se++}for(;se<J;++se){let ge=Math.round((X+se*V)*G)/G;if(B&&ge>p)break;s.push({value:ge})}if(B&&v&&Y!==p)if(s.length&&Bu(s[s.length-1].value,p,EM(p,H,a)))s[s.length-1].value=p;else s.push({value:p});else if(!B||Y===p)s.push({value:Y});return s}function EM(a,n,{horizontal:s,minRotation:i}){let l=Fs(i),u=(s?Math.sin(l):Math.cos(l))||0.001,d=0.75*n*(""+a).length;return Math.min(n/u,d)}class Wd extends cl{constructor(a){super(a);this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(a,n){if(ht(a))return null;if((typeof a==="number"||a instanceof Number)&&!isFinite(+a))return null;return+a}handleTickRangeOptions(){let{beginAtZero:a}=this.options,{minDefined:n,maxDefined:s}=this.getUserBounds(),{min:i,max:l}=this,u=(p)=>i=n?i:p,d=(p)=>l=s?l:p;if(a){let p=Ln(i),h=Ln(l);if(p<0&&h<0)d(0);else if(p>0&&h>0)u(0)}if(i===l){let p=l===0?1:Math.abs(l*0.05);if(d(l+p),!a)u(i-p)}this.min=i,this.max=l}getTickLimit(){let a=this.options.ticks,{maxTicksLimit:n,stepSize:s}=a,i;if(s){if(i=Math.ceil(this.max/s)-Math.floor(this.min/s)+1,i>1000)console.warn(`scales.${this.id}.ticks.stepSize: ${s} would result generating up to ${i} ticks. Limiting to 1000.`),i=1000}else i=this.computeTickLimit(),n=n||11;if(n)i=Math.min(n,i);return i}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){let a=this.options,n=a.ticks,s=this.getTickLimit();s=Math.max(2,s);let i={maxTicks:s,bounds:a.bounds,min:a.min,max:a.max,precision:n.precision,step:n.stepSize,count:n.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:n.minRotation||0,includeBounds:n.includeBounds!==!1},l=this._range||this,u=HB(i,l);if(a.bounds==="ticks")Fx(u,this,"value");if(a.reverse)u.reverse(),this.start=this.max,this.end=this.min;else this.start=this.min,this.end=this.max;return u}configure(){let a=this.ticks,n=this.min,s=this.max;if(super.configure(),this.options.offset&&a.length){let i=(s-n)/Math.max(a.length-1,1)/2;n-=i,s+=i}this._startValue=n,this._endValue=s,this._valueRange=s-n}getLabelForValue(a){return sm(a,this.chart.options.locale,this.options.ticks.format)}}class Hv extends Wd{static id="linear";static defaults={ticks:{callback:Bd.formatters.numeric}};determineDataLimits(){let{min:a,max:n}=this.getMinMax(!0);this.min=Kt(a)?a:0,this.max=Kt(n)?n:1,this.handleTickRangeOptions()}computeTickLimit(){let a=this.isHorizontal(),n=a?this.width:this.height,s=Fs(this.options.ticks.minRotation),i=(a?Math.sin(s):Math.cos(s))||0.001,l=this._resolveTickFontOptions(0);return Math.ceil(n/Math.min(40,l.lineHeight/i))}getPixelForValue(a){return a===null?NaN:this.getPixelForDecimal((a-this._startValue)/this._valueRange)}getValueForPixel(a){return this._startValue+this.getDecimalForPixel(a)*this._valueRange}}var Zd=(a)=>Math.floor(Us(a)),ul=(a,n)=>Math.pow(10,Zd(a)+n);function OM(a){return a/Math.pow(10,Zd(a))===1}function PM(a,n,s){let i=Math.pow(10,s),l=Math.floor(a/i);return Math.ceil(n/i)-l}function UB(a,n){let s=n-a,i=Zd(s);while(PM(a,n,i)>10)i++;while(PM(a,n,i)<10)i--;return Math.min(i,Zd(a))}function FB(a,{min:n,max:s}){n=go(a.min,n);let i=[],l=Zd(n),u=UB(n,s),d=u<0?Math.pow(10,Math.abs(u)):1,p=Math.pow(10,u),h=l>u?Math.pow(10,l):0,g=Math.round((n-h)*d)/d,b=Math.floor((n-h)/p/10)*p*10,y=Math.floor((g-b)/Math.pow(10,u)),v=go(a.min,Math.round((h+b+y*Math.pow(10,u))*d)/d);while(v<s){if(i.push({value:v,major:OM(v),significand:y}),y>=10)y=y<15?15:20;else y++;if(y>=20)u++,y=2,d=u>=0?1:d;v=Math.round((h+b+y*Math.pow(10,u))*d)/d}let T=go(a.max,v);return i.push({value:T,major:OM(T),significand:y}),i}class qB extends cl{static id="logarithmic";static defaults={ticks:{callback:Bd.formatters.logarithmic,major:{enabled:!0}}};constructor(a){super(a);this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(a,n){let s=Wd.prototype.parse.apply(this,[a,n]);if(s===0){this._zero=!0;return}return Kt(s)&&s>0?s:null}determineDataLimits(){let{min:a,max:n}=this.getMinMax(!0);if(this.min=Kt(a)?Math.max(0,a):null,this.max=Kt(n)?Math.max(0,n):null,this.options.beginAtZero)this._zero=!0;if(this._zero&&this.min!==this._suggestedMin&&!Kt(this._userMin))this.min=a===ul(this.min,0)?ul(this.min,-1):ul(this.min,0);this.handleTickRangeOptions()}handleTickRangeOptions(){let{minDefined:a,maxDefined:n}=this.getUserBounds(),s=this.min,i=this.max,l=(d)=>s=a?s:d,u=(d)=>i=n?i:d;if(s===i)if(s<=0)l(1),u(10);else l(ul(s,-1)),u(ul(i,1));if(s<=0)l(ul(i,-1));if(i<=0)u(ul(s,1));this.min=s,this.max=i}buildTicks(){let a=this.options,n={min:this._userMin,max:this._userMax},s=FB(n,this);if(a.bounds==="ticks")Fx(s,this,"value");if(a.reverse)s.reverse(),this.start=this.max,this.end=this.min;else this.start=this.min,this.end=this.max;return s}getLabelForValue(a){return a===void 0?"0":sm(a,this.chart.options.locale,this.options.ticks.format)}configure(){let a=this.min;super.configure(),this._startValue=Us(a),this._valueRange=Us(this.max)-Us(a)}getPixelForValue(a){if(a===void 0||a===0)a=this.min;if(a===null||isNaN(a))return NaN;return this.getPixelForDecimal(a===this.min?0:(Us(a)-this._startValue)/this._valueRange)}getValueForPixel(a){let n=this.getDecimalForPixel(a);return Math.pow(10,this._startValue+n*this._valueRange)}}function Mv(a){let n=a.ticks;if(n.display&&a.display){let s=Na(n.backdropPadding);return Ke(n.font&&n.font.size,Jt.font.size)+s.height}return 0}function VB(a,n,s){return s=zt(s)?s:[s],{w:_k(a,n.string,s),h:s.length*n.lineHeight}}function BM(a,n,s,i,l){if(a===i||a===l)return{start:n-s/2,end:n+s/2};else if(a<i||a>l)return{start:n-s,end:n};return{start:n,end:n+s}}function jB(a){let n={l:a.left+a._padding.left,r:a.right-a._padding.right,t:a.top+a._padding.top,b:a.bottom-a._padding.bottom},s=Object.assign({},n),i=[],l=[],u=a._pointLabels.length,d=a.options.pointLabels,p=d.centerPointLabels?na/u:0;for(let h=0;h<u;h++){let g=d.setContext(a.getPointLabelContext(h));l[h]=g.padding;let b=a.getPointPosition(h,a.drawingArea+l[h],p),y=pa(g.font),v=VB(a.ctx,y,a._pointLabels[h]);i[h]=v;let T=fo(a.getIndexAngle(h)+p),M=Math.round(am(T)),I=BM(M,b.x,v.w,0,180),w=BM(M,b.y,v.h,90,270);GB(s,n,T,I,w)}a.setCenterPoint(n.l-s.l,s.r-n.r,n.t-s.t,s.b-n.b),a._pointLabelItems=$B(a,i,l)}function GB(a,n,s,i,l){let u=Math.abs(Math.sin(s)),d=Math.abs(Math.cos(s)),p=0,h=0;if(i.start<n.l)p=(n.l-i.start)/u,a.l=Math.min(a.l,n.l-p);else if(i.end>n.r)p=(i.end-n.r)/u,a.r=Math.max(a.r,n.r+p);if(l.start<n.t)h=(n.t-l.start)/d,a.t=Math.min(a.t,n.t-h);else if(l.end>n.b)h=(l.end-n.b)/d,a.b=Math.max(a.b,n.b+h)}function XB(a,n,s){let i=a.drawingArea,{extra:l,additionalAngle:u,padding:d,size:p}=s,h=a.getPointPosition(n,i+l+d,u),g=Math.round(am(fo(h.angle+po))),b=QB(h.y,p.h,g),y=WB(g),v=ZB(h.x,p.w,y);return{visible:!0,x:h.x,y:b,textAlign:y,left:v,top:b,right:v+p.w,bottom:b+p.h}}function YB(a,n){if(!n)return!0;let{left:s,top:i,right:l,bottom:u}=a;return!(as({x:s,y:i},n)||as({x:s,y:u},n)||as({x:l,y:i},n)||as({x:l,y:u},n))}function $B(a,n,s){let i=[],l=a._pointLabels.length,u=a.options,{centerPointLabels:d,display:p}=u.pointLabels,h={extra:Mv(u)/2,additionalAngle:d?na/l:0},g;for(let b=0;b<l;b++){h.padding=s[b],h.size=n[b];let y=XB(a,b,h);if(i.push(y),p==="auto"){if(y.visible=YB(y,g),y.visible)g=y}}return i}function WB(a){if(a===0||a===180)return"center";else if(a<180)return"left";return"right"}function ZB(a,n,s){if(s==="right")a-=n;else if(s==="center")a-=n/2;return a}function QB(a,n,s){if(s===90||s===270)a-=n/2;else if(s>270||s<90)a-=n;return a}function KB(a,n,s){let{left:i,top:l,right:u,bottom:d}=s,{backdropColor:p}=n;if(!ht(p)){let h=ti(n.borderRadius),g=Na(n.backdropPadding);a.fillStyle=p;let b=i-g.left,y=l-g.top,v=u-i+g.width,T=d-l+g.height;if(Object.values(h).some((M)=>M!==0))a.beginPath(),zu(a,{x:b,y,w:v,h:T,radius:h}),a.fill();else a.fillRect(b,y,v,T)}}function JB(a,n){let{ctx:s,options:{pointLabels:i}}=a;for(let l=n-1;l>=0;l--){let u=a._pointLabelItems[l];if(!u.visible)continue;let d=i.setContext(a.getPointLabelContext(l));KB(s,d,u);let p=pa(d.font),{x:h,y:g,textAlign:b}=u;ei(s,a._pointLabels[l],h,g+p.lineHeight/2,p,{color:d.color,textAlign:b,textBaseline:"middle"})}}function mI(a,n,s,i){let{ctx:l}=a;if(s)l.arc(a.xCenter,a.yCenter,n,0,ho);else{let u=a.getPointPosition(0,n);l.moveTo(u.x,u.y);for(let d=1;d<i;d++)u=a.getPointPosition(d,n),l.lineTo(u.x,u.y)}}function eN(a,n,s,i,l){let u=a.ctx,d=n.circular,{color:p,lineWidth:h}=n;if(!d&&!i||!p||!h||s<0)return;u.save(),u.strokeStyle=p,u.lineWidth=h,u.setLineDash(l.dash||[]),u.lineDashOffset=l.dashOffset,u.beginPath(),mI(a,s,d,i),u.closePath(),u.stroke(),u.restore()}function tN(a,n,s){return Vs(a,{label:s,index:n,type:"pointLabel"})}class aN extends Wd{static id="radialLinear";static defaults={display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:Bd.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback(a){return a},padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(a){super(a);this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){let a=this._padding=Na(Mv(this.options)/2),n=this.width=this.maxWidth-a.width,s=this.height=this.maxHeight-a.height;this.xCenter=Math.floor(this.left+n/2+a.left),this.yCenter=Math.floor(this.top+s/2+a.top),this.drawingArea=Math.floor(Math.min(n,s)/2)}determineDataLimits(){let{min:a,max:n}=this.getMinMax(!1);this.min=Kt(a)&&!isNaN(a)?a:0,this.max=Kt(n)&&!isNaN(n)?n:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/Mv(this.options))}generateTickLabels(a){Wd.prototype.generateTickLabels.call(this,a),this._pointLabels=this.getLabels().map((n,s)=>{let i=Ot(this.options.pointLabels.callback,[n,s],this);return i||i===0?i:""}).filter((n,s)=>this.chart.getDataVisibility(s))}fit(){let a=this.options;if(a.display&&a.pointLabels.display)jB(this);else this.setCenterPoint(0,0,0,0)}setCenterPoint(a,n,s,i){this.xCenter+=Math.floor((a-n)/2),this.yCenter+=Math.floor((s-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(a,n,s,i))}getIndexAngle(a){let n=ho/(this._pointLabels.length||1),s=this.options.startAngle||0;return fo(a*n+Fs(s))}getDistanceFromCenterForValue(a){if(ht(a))return NaN;let n=this.drawingArea/(this.max-this.min);if(this.options.reverse)return(this.max-a)*n;return(a-this.min)*n}getValueForDistanceFromCenter(a){if(ht(a))return NaN;let n=a/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-n:this.min+n}getPointLabelContext(a){let n=this._pointLabels||[];if(a>=0&&a<n.length){let s=n[a];return tN(this.getContext(),a,s)}}getPointPosition(a,n,s=0){let i=this.getIndexAngle(a)-po+s;return{x:Math.cos(i)*n+this.xCenter,y:Math.sin(i)*n+this.yCenter,angle:i}}getPointPositionForValue(a,n){return this.getPointPosition(a,this.getDistanceFromCenterForValue(n))}getBasePosition(a){return this.getPointPositionForValue(a||0,this.getBaseValue())}getPointLabelPosition(a){let{left:n,top:s,right:i,bottom:l}=this._pointLabelItems[a];return{left:n,top:s,right:i,bottom:l}}drawBackground(){let{backgroundColor:a,grid:{circular:n}}=this.options;if(a){let s=this.ctx;s.save(),s.beginPath(),mI(this,this.getDistanceFromCenterForValue(this._endValue),n,this._pointLabels.length),s.closePath(),s.fillStyle=a,s.fill(),s.restore()}}drawGrid(){let a=this.ctx,n=this.options,{angleLines:s,grid:i,border:l}=n,u=this._pointLabels.length,d,p,h;if(n.pointLabels.display)JB(this,u);if(i.display)this.ticks.forEach((g,b)=>{if(b!==0||b===0&&this.min<0){p=this.getDistanceFromCenterForValue(g.value);let y=this.getContext(b),v=i.setContext(y),T=l.setContext(y);eN(this,v,p,u,T)}});if(s.display){a.save();for(d=u-1;d>=0;d--){let g=s.setContext(this.getPointLabelContext(d)),{color:b,lineWidth:y}=g;if(!y||!b)continue;a.lineWidth=y,a.strokeStyle=b,a.setLineDash(g.borderDash),a.lineDashOffset=g.borderDashOffset,p=this.getDistanceFromCenterForValue(n.reverse?this.min:this.max),h=this.getPointPosition(d,p),a.beginPath(),a.moveTo(this.xCenter,this.yCenter),a.lineTo(h.x,h.y),a.stroke()}a.restore()}}drawBorder(){}drawLabels(){let a=this.ctx,n=this.options,s=n.ticks;if(!s.display)return;let i=this.getIndexAngle(0),l,u;a.save(),a.translate(this.xCenter,this.yCenter),a.rotate(i),a.textAlign="center",a.textBaseline="middle",this.ticks.forEach((d,p)=>{if(p===0&&this.min>=0&&!n.reverse)return;let h=s.setContext(this.getContext(p)),g=pa(h.font);if(l=this.getDistanceFromCenterForValue(this.ticks[p].value),h.showLabelBackdrop){a.font=g.string,u=a.measureText(d.label).width,a.fillStyle=h.backdropColor;let b=Na(h.backdropPadding);a.fillRect(-u/2-b.left,-l-g.size/2-b.top,u+b.width,g.size+b.height)}ei(a,d.label,0,-l,g,{color:h.color,strokeColor:h.textStrokeColor,strokeWidth:h.textStrokeWidth})}),a.restore()}drawTitle(){}}var Lm={millisecond:{common:!0,size:1,steps:1000},second:{common:!0,size:1000,steps:60},minute:{common:!0,size:60000,steps:60},hour:{common:!0,size:3600000,steps:24},day:{common:!0,size:86400000,steps:30},week:{common:!1,size:604800000,steps:4},month:{common:!0,size:2628000000,steps:12},quarter:{common:!1,size:7884000000,steps:4},year:{common:!0,size:31540000000}},bo=Object.keys(Lm);function NM(a,n){return a-n}function zM(a,n){if(ht(n))return null;let s=a._adapter,{parser:i,round:l,isoWeekday:u}=a._parseOpts,d=n;if(typeof i==="function")d=i(d);if(!Kt(d))d=typeof i==="string"?s.parse(d,i):s.parse(d);if(d===null)return null;if(l)d=l==="week"&&(Nu(u)||u===!0)?s.startOf(d,"isoWeek",u):s.startOf(d,l);return+d}function HM(a,n,s,i){let l=bo.length;for(let u=bo.indexOf(a);u<l-1;++u){let d=Lm[bo[u]],p=d.steps?d.steps:Number.MAX_SAFE_INTEGER;if(d.common&&Math.ceil((s-n)/(p*d.size))<=i)return bo[u]}return bo[l-1]}function oN(a,n,s,i,l){for(let u=bo.length-1;u>=bo.indexOf(s);u--){let d=bo[u];if(Lm[d].common&&a._adapter.diff(l,i,d)>=n-1)return d}return bo[s?bo.indexOf(s):0]}function nN(a){for(let n=bo.indexOf(a)+1,s=bo.length;n<s;++n)if(Lm[bo[n]].common)return bo[n]}function UM(a,n,s){if(!s)a[n]=!0;else if(s.length){let{lo:i,hi:l}=om(s,n),u=s[i]>=n?s[i]:s[l];a[u]=!0}}function sN(a,n,s,i){let l=a._adapter,u=+l.startOf(n[0].value,i),d=n[n.length-1].value,p,h;for(p=u;p<=d;p=+l.add(p,1,i))if(h=s[p],h>=0)n[h].major=!0;return n}function FM(a,n,s){let i=[],l={},u=n.length,d,p;for(d=0;d<u;++d)p=n[d],l[p]=d,i.push({value:p,major:!1});return u===0||!s?i:sN(a,i,l,s)}class Iv extends cl{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(a){super(a);this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(a,n={}){let s=a.time||(a.time={}),i=this._adapter=new UO._date(a.adapters.date);i.init(n),Ou(s.displayFormats,i.formats()),this._parseOpts={parser:s.parser,round:s.round,isoWeekday:s.isoWeekday},super.init(a),this._normalized=n.normalized}parse(a,n){if(a===void 0)return null;return zM(this,a)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){let a=this.options,n=this._adapter,s=a.time.unit||"day",{min:i,max:l,minDefined:u,maxDefined:d}=this.getUserBounds();function p(h){if(!u&&!isNaN(h.min))i=Math.min(i,h.min);if(!d&&!isNaN(h.max))l=Math.max(l,h.max)}if(!u||!d){if(p(this._getLabelBounds()),a.bounds!=="ticks"||a.ticks.source!=="labels")p(this.getMinMax(!1))}i=Kt(i)&&!isNaN(i)?i:+n.startOf(Date.now(),s),l=Kt(l)&&!isNaN(l)?l:+n.endOf(Date.now(),s)+1,this.min=Math.min(i,l-1),this.max=Math.max(i+1,l)}_getLabelBounds(){let a=this.getLabelTimestamps(),{POSITIVE_INFINITY:n,NEGATIVE_INFINITY:s}=Number;if(a.length)n=a[0],s=a[a.length-1];return{min:n,max:s}}buildTicks(){let a=this.options,{time:n,ticks:s}=a,i=s.source==="labels"?this.getLabelTimestamps():this._generate();if(a.bounds==="ticks"&&i.length)this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1];let l=this.min,u=this.max,d=Lk(i,l,u);if(this._unit=n.unit||(s.autoSkip?HM(n.minUnit,this.min,this.max,this._getLabelCapacity(l)):oN(this,d.length,n.minUnit,this.min,this.max)),this._majorUnit=!s.major.enabled||this._unit==="year"?void 0:nN(this._unit),this.initOffsets(i),a.reverse)d.reverse();return FM(this,d,this._majorUnit)}afterAutoSkip(){if(this.options.offsetAfterAutoskip)this.initOffsets(this.ticks.map((a)=>+a.value))}initOffsets(a=[]){let n=0,s=0,i,l;if(this.options.offset&&a.length){if(i=this.getDecimalForValue(a[0]),a.length===1)n=1-i;else n=(this.getDecimalForValue(a[1])-i)/2;if(l=this.getDecimalForValue(a[a.length-1]),a.length===1)s=l;else s=(l-this.getDecimalForValue(a[a.length-2]))/2}let u=a.length<3?0.5:0.25;n=mo(n,0,u),s=mo(s,0,u),this._offsets={start:n,end:s,factor:1/(n+1+s)}}_generate(){let a=this._adapter,n=this.min,s=this.max,i=this.options,l=i.time,u=l.unit||HM(l.minUnit,n,s,this._getLabelCapacity(n)),d=Ke(i.ticks.stepSize,1),p=u==="week"?l.isoWeekday:!1,h=Nu(p)||p===!0,g={},b=n,y,v;if(h)b=+a.startOf(b,"isoWeek",p);if(b=+a.startOf(b,h?"day":u),a.diff(s,n,u)>1e5*d)throw Error(n+" and "+s+" are too far apart with stepSize of "+d+" "+u);let T=i.ticks.source==="data"&&this.getDataTimestamps();for(y=b,v=0;y<s;y=+a.add(y,d,u),v++)UM(g,y,T);if(y===s||i.bounds==="ticks"||v===1)UM(g,y,T);return Object.keys(g).sort(NM).map((M)=>+M)}getLabelForValue(a){let n=this._adapter,s=this.options.time;if(s.tooltipFormat)return n.format(a,s.tooltipFormat);return n.format(a,s.displayFormats.datetime)}format(a,n){let i=this.options.time.displayFormats,l=this._unit,u=n||i[l];return this._adapter.format(a,u)}_tickFormatFunction(a,n,s,i){let l=this.options,u=l.ticks.callback;if(u)return Ot(u,[a,n,s],this);let d=l.time.displayFormats,p=this._unit,h=this._majorUnit,g=p&&d[p],b=h&&d[h],y=s[n],v=h&&b&&y&&y.major;return this._adapter.format(a,i||(v?b:g))}generateTickLabels(a){let n,s,i;for(n=0,s=a.length;n<s;++n)i=a[n],i.label=this._tickFormatFunction(i.value,n,a)}getDecimalForValue(a){return a===null?NaN:(a-this.min)/(this.max-this.min)}getPixelForValue(a){let n=this._offsets,s=this.getDecimalForValue(a);return this.getPixelForDecimal((n.start+s)*n.factor)}getValueForPixel(a){let n=this._offsets,s=this.getDecimalForPixel(a)/n.factor-n.end;return this.min+s*(this.max-this.min)}_getLabelSize(a){let n=this.options.ticks,s=this.ctx.measureText(a).width,i=Fs(this.isHorizontal()?n.maxRotation:n.minRotation),l=Math.cos(i),u=Math.sin(i),d=this._resolveTickFontOptions(0).size;return{w:s*l+d*u,h:s*u+d*l}}_getLabelCapacity(a){let n=this.options.time,s=n.displayFormats,i=s[n.unit]||s.millisecond,l=this._tickFormatFunction(a,0,FM(this,[a],this._majorUnit),i),u=this._getLabelSize(l),d=Math.floor(this.isHorizontal()?this.width/u.w:this.height/u.h)-1;return d>0?d:1}getDataTimestamps(){let a=this._cache.data||[],n,s;if(a.length)return a;let i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(n=0,s=i.length;n<s;++n)a=a.concat(i[n].controller.getAllParsedValues(this));return this._cache.data=this.normalize(a)}getLabelTimestamps(){let a=this._cache.labels||[],n,s;if(a.length)return a;let i=this.getLabels();for(n=0,s=i.length;n<s;++n)a.push(zM(this,i[n]));return this._cache.labels=this._normalized?a:this.normalize(a)}normalize(a){return Gx(a.sort(NM))}}function gm(a,n,s){let i=0,l=a.length-1,u,d,p,h;if(s){if(n>=a[i].pos&&n<=a[l].pos)({lo:i,hi:l}=Zr(a,"pos",n));({pos:u,time:p}=a[i]),{pos:d,time:h}=a[l]}else{if(n>=a[i].time&&n<=a[l].time)({lo:i,hi:l}=Zr(a,"time",n));({time:u,pos:p}=a[i]),{time:d,pos:h}=a[l]}let g=d-u;return g?p+(h-p)*(n-u)/g:p}class rN extends Iv{static id="timeseries";static defaults=Iv.defaults;constructor(a){super(a);this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){let a=this._getTimestampsForTable(),n=this._table=this.buildLookupTable(a);this._minPos=gm(n,this.min),this._tableRange=gm(n,this.max)-this._minPos,super.initOffsets(a)}buildLookupTable(a){let{min:n,max:s}=this,i=[],l=[],u,d,p,h,g;for(u=0,d=a.length;u<d;++u)if(h=a[u],h>=n&&h<=s)i.push(h);if(i.length<2)return[{time:n,pos:0},{time:s,pos:1}];for(u=0,d=i.length;u<d;++u)if(g=i[u+1],p=i[u-1],h=i[u],Math.round((g+p)/2)!==h)l.push({time:h,pos:u/(d-1)});return l}_generate(){let a=this.min,n=this.max,s=super.getDataTimestamps();if(!s.includes(a)||!s.length)s.splice(0,0,a);if(!s.includes(n)||s.length===1)s.push(n);return s.sort((i,l)=>i-l)}_getTimestampsForTable(){let a=this._cache.all||[];if(a.length)return a;let n=this.getDataTimestamps(),s=this.getLabelTimestamps();if(n.length&&s.length)a=this.normalize(n.concat(s));else a=n.length?n:s;return a=this._cache.all=a,a}getDecimalForValue(a){return(gm(this._table,a)-this._minPos)/this._tableRange}getValueForPixel(a){let n=this._offsets,s=this.getDecimalForPixel(a)/n.factor-n.end;return gm(this._table,s*this._tableRange+this._minPos,!0)}}dl.register(zv,Hv,Pv,Hu,Ov,fI,hI,dI,uI);var dR=Q(vI(),1);var er=Q(dt(),1);var Im=Q(dt(),1);var km=(...a)=>a.filter((n,s,i)=>Boolean(n)&&n.trim()!==""&&i.indexOf(n)===s).join(" ").trim();var SI=(a)=>a.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var LI=(a)=>a.replace(/^([A-Z])|[\s-_]+(\w)/g,(n,s,i)=>i?i.toUpperCase():s.toLowerCase());var qv=(a)=>{let n=LI(a);return n.charAt(0).toUpperCase()+n.slice(1)};var Kd=Q(dt(),1);var Mm={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var CI=(a)=>{for(let n in a)if(n.startsWith("aria-")||n==="role"||n==="title")return!0;return!1};var qu=Q(dt(),1),fN=qu.createContext({});var TI=()=>qu.useContext(fN);var wI=Kd.forwardRef(({color:a,size:n,strokeWidth:s,absoluteStrokeWidth:i,className:l="",children:u,iconNode:d,...p},h)=>{let{size:g=24,strokeWidth:b=2,absoluteStrokeWidth:y=!1,color:v="currentColor",className:T=""}=TI()??{},M=i??y?Number(s??b)*24/Number(n??g):s??b;return Kd.createElement("svg",{ref:h,...Mm,width:n??g??Mm.width,height:n??g??Mm.height,stroke:a??v,strokeWidth:M,className:km("lucide",T,l),...!u&&!CI(p)&&{"aria-hidden":"true"},...p},[...d.map(([I,w])=>Kd.createElement(I,w)),...Array.isArray(u)?u:[u]])});var we=(a,n)=>{let s=Im.forwardRef(({className:i,...l},u)=>Im.createElement(wI,{ref:u,iconNode:n,className:km(`lucide-${SI(qv(a))}`,`lucide-${a}`,i),...l}));return s.displayName=qv(a),s};var pN=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],ni=we("circle-alert",pN);var hN=[["path",{d:"M15 10V9",key:"4dkmfx"}],["path",{d:"M16.472 15a6 6 0 01-8.943 0",key:"7qomzy"}],["path",{d:"M9 10V9",key:"1lazqi"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],si=we("face-slightly-smiling",hN);var mN=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],Jd=we("activity",mN);var gN=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],ef=we("arrow-left",gN);var yN=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],pl=we("check",yN);var bN=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Ys=we("chevron-down",bN);var xN=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],hl=we("chevron-right",xN);var vN=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],tf=we("chevron-up",vN);var SN=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],af=we("clock",SN);var LN=[["path",{d:"M13.744 17.736a6 6 0 1 1-7.48-7.48",key:"bq4yh3"}],["path",{d:"M15 6h1v4",key:"11y1tn"}],["path",{d:"m6.134 14.768.866-.5 2 3.464",key:"17snzx"}],["circle",{cx:"16",cy:"8",r:"6",key:"14bfc9"}]],ml=we("coins",LN);var CN=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],gl=we("copy",CN);var TN=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],of=we("cpu",TN);var wN=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],nf=we("folder",wN);var kN=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],sf=we("gauge",kN);var MN=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],rf=we("hash",MN);var IN=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],lf=we("inbox",IN);var AN=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],uf=we("layout-dashboard",AN);var RN=[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]],cf=we("list-tree",RN);var _N=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],df=we("menu",_N);var DN=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],ff=we("monitor",DN);var EN=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],pf=we("moon",EN);var ON=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],hf=we("plug",ON);var PN=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],yl=we("refresh-cw",PN);var BN=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],mf=we("star",BN);var NN=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],gf=we("sun",NN);var zN=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],yf=we("trending-up",zN);var HN=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],bf=we("wrench",HN);var UN=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],$s=we("x",UN);var FN=[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]],xf=we("zap",FN);var QI=Q(dt(),1);var Am=[{id:"overview",label:"Overview",icon:uf},{id:"requests",label:"Requests",icon:Jd},{id:"traces",label:"Traces",icon:cf},{id:"errors",label:"Errors",icon:ni},{id:"models",label:"Models",icon:of},{id:"providers",label:"Providers",icon:hf},{id:"tools",label:"Tools",icon:bf},{id:"costs",label:"Costs",icon:ml},{id:"behavior",label:"Behavior",shortLabel:"Behavior",icon:si},{id:"projects",label:"Projects",icon:nf},{id:"gain",label:"Gain",icon:yf}];var sn=Q(de(),1);function Vv({activeSection:a,onSectionChange:n,className:s=""}){return sn.jsxDEV("aside",{className:`stats-nav-rail ${s}`,children:[sn.jsxDEV("div",{className:"stats-nav-rail-header",children:sn.jsxDEV("div",{className:"stats-logo-container",children:[sn.jsxDEV("span",{className:"stats-logo-text",children:"OH MY PI"},void 0,!1,void 0,this),sn.jsxDEV("span",{className:"stats-logo-subtext",children:"Observability"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),sn.jsxDEV("nav",{className:"stats-nav-rail-menu",children:Am.map((i)=>{let l=i.id===a,u=i.icon;return sn.jsxDEV("button",{type:"button",onClick:()=>n(i.id),className:"stats-nav-rail-item","data-active":l?"true":"false","aria-current":l?"page":void 0,children:[sn.jsxDEV(u,{size:16,className:"stats-nav-rail-item-icon"},void 0,!1,void 0,this),sn.jsxDEV("span",{className:"stats-nav-rail-item-label",children:i.label},void 0,!1,void 0,this)]},i.id,!0,void 0,this)})},void 0,!1,void 0,this),sn.jsxDEV("div",{className:"stats-nav-rail-footer",children:sn.jsxDEV("span",{className:"stats-version-tag",children:"OMP Stats v1.0.0"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var jv=Q(de(),1),VN=[{value:"1h",label:"1h"},{value:"24h",label:"24h"},{value:"7d",label:"7d"},{value:"30d",label:"30d"},{value:"90d",label:"90d"},{value:"all",label:"All"}];function kI({value:a,onChange:n,className:s=""}){return jv.jsxDEV("div",{className:`stats-range-control ${s}`,role:"radiogroup","aria-label":"Select time range",children:VN.map((i)=>{let l=i.value===a;return jv.jsxDEV("button",{type:"button",role:"radio","aria-checked":l,"data-active":l?"true":"false",className:"stats-range-control-btn",onClick:()=>n(i.value),children:i.label},i.value,!1,void 0,this)})},void 0,!1,void 0,this)}var Gv=Q(dt(),1);class MI extends Error{status;endpoint;constructor(a,n,s){super(s);this.name="ApiError",this.status=a,this.endpoint=n}}async function ao(a,n){let s=await fetch(a,n);if(!s.ok)throw new MI(s.status,a,`HTTP error ${s.status} on ${a}`);return s.json()}async function II(a="24h",n){return ao(`/api/stats/overview?range=${encodeURIComponent(a)}`,{signal:n})}async function AI(a="24h",n){return ao(`/api/stats/model-dashboard?range=${encodeURIComponent(a)}`,{signal:n})}async function RI(a="24h",n){return ao(`/api/stats/costs?range=${encodeURIComponent(a)}`,{signal:n})}async function Rm(a=50,n){return ao(`/api/stats/recent?limit=${a}`,{signal:n})}async function _I(a="24h",n=50,s){return ao(`/api/stats/errors?range=${encodeURIComponent(a)}&limit=${n}`,{signal:s})}async function DI(a,n){return ao(`/api/request/${a}`,{signal:n})}async function EI(a){return ao("/api/sync",{signal:a})}async function OI(a="24h",n){return ao(`/api/stats/behavior?range=${encodeURIComponent(a)}`,{signal:n})}async function PI(a="24h",n){return ao(`/api/stats/folders?range=${encodeURIComponent(a)}`,{signal:n})}async function BI(a="24h",n,s){let i=new URLSearchParams({range:a});if(n)i.set("project",n);return ao(`/api/stats/gain?${i}`,{signal:s})}async function NI(a="24h",n){return ao(`/api/stats/tools?range=${encodeURIComponent(a)}`,{signal:n})}async function zI(a="24h",n){return ao(`/api/stats/providers?range=${encodeURIComponent(a)}`,{signal:n})}async function HI(a=100,n,s){let i=new URLSearchParams({limit:String(a)});if(n)i.set("q",n);return ao(`/api/sessions?${i}`,{signal:s})}async function UI(a,n){return ao(`/api/session/trace?file=${encodeURIComponent(a)}`,{signal:n})}async function FI(a,n,s){return ao(`/api/session/entry?file=${encodeURIComponent(a)}&id=${encodeURIComponent(n)}`,{signal:s})}var vf=Q(de(),1);function qI({onSyncStart:a,onSyncComplete:n,className:s=""}){let[i,l]=Gv.useState(!1),[u,d]=Gv.useState(null),p=async()=>{if(i)return;if(l(!0),d(null),a)a();try{let h=await EI(),g={processed:typeof h?.processed==="number"?h.processed:0,files:typeof h?.files==="number"?h.files:0,totalMessages:typeof h?.totalMessages==="number"?h.totalMessages:0};if(d({type:"success",message:`Synced: ${g.processed} new request${g.processed===1?"":"s"} found.`}),n)n({success:!0,data:g})}catch(h){let g=h instanceof Error?h.message:String(h);if(d({type:"error",message:`Sync failed: ${g}`}),n)n({success:!1,error:g})}finally{l(!1)}};return vf.jsxDEV("div",{className:`stats-sync-container ${s}`,children:[u&&vf.jsxDEV("span",{className:"stats-sync-status-msg","data-type":u.type,children:u.message},void 0,!1,void 0,this),vf.jsxDEV("button",{type:"button",onClick:p,disabled:i,className:"stats-button stats-button-primary stats-sync-btn","aria-busy":i,children:[vf.jsxDEV(yl,{size:14,className:`stats-sync-icon ${i?"stats-spin":""}`},void 0,!1,void 0,this),i?"Syncing...":"Sync DB"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var _m=Q(dt(),1),VI="omp-stats-theme",jI="(prefers-color-scheme: dark)";function jN(){if(typeof localStorage>"u")return"system";let a=localStorage.getItem(VI);return a==="light"||a==="dark"||a==="system"?a:"system"}function GI(){if(typeof window>"u")return"dark";return window.matchMedia(jI).matches?"dark":"light"}var xl=jN(),Sf=xl==="system"?GI():xl,Xv=new Set;function XI(){for(let a of Xv)a()}function Yv(){if(Sf=xl==="system"?GI():xl,typeof document<"u")document.documentElement.dataset.theme=Sf,document.documentElement.style.colorScheme=Sf}if(typeof window<"u")Yv(),window.matchMedia(jI).addEventListener("change",()=>{if(xl==="system")Yv(),XI()});function GN(a){if(xl=a,typeof localStorage<"u")localStorage.setItem(VI,a);Yv(),XI()}function $v(a){return Xv.add(a),()=>Xv.delete(a)}function $t(){return _m.useSyncExternalStore($v,()=>Sf,()=>"dark")}function YI(){let a=_m.useSyncExternalStore($v,()=>xl,()=>"system"),n=_m.useSyncExternalStore($v,()=>Sf,()=>"dark");return{preference:a,resolved:n,setPreference:GN}}var Wv=Q(de(),1),XN={system:"light",light:"dark",dark:"system"},YN={system:ff,light:gf,dark:pf},$I={system:"System theme",light:"Light theme",dark:"Dark theme"};function WI(){let{preference:a,setPreference:n}=YI(),s=YN[a];return Wv.jsxDEV("button",{type:"button",className:"stats-theme-toggle",onClick:()=>n(XN[a]),"aria-label":`${$I[a]} (click to switch)`,title:`${$I[a]} — click to switch`,children:Wv.jsxDEV(s,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var rn=Q(de(),1);function ZI({activeSection:a,range:n,onRangeChange:s,updatedAt:i,onSyncStart:l,onSyncComplete:u,onMenuToggle:d,className:p=""}){let g=Am.find((y)=>y.id===a)?.label||"Observability",b=(y)=>{if(!y)return"Not updated";return`Updated ${new Date(y).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}`};return rn.jsxDEV("header",{className:`stats-top-bar ${p}`,children:[rn.jsxDEV("div",{className:"stats-top-bar-left",children:[d&&rn.jsxDEV("button",{type:"button",onClick:d,className:"stats-mobile-menu-btn","aria-label":"Open navigation menu",children:rn.jsxDEV(df,{size:20},void 0,!1,void 0,this)},void 0,!1,void 0,this),rn.jsxDEV("h1",{className:"stats-page-title",children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),rn.jsxDEV("div",{className:"stats-top-bar-right",children:[rn.jsxDEV("div",{className:"stats-top-bar-meta",children:rn.jsxDEV("span",{className:"stats-last-updated",title:i?new Date(i).toLocaleString():void 0,children:b(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this),rn.jsxDEV(kI,{value:n,onChange:s},void 0,!1,void 0,this),rn.jsxDEV(WI,{},void 0,!1,void 0,this),rn.jsxDEV(qI,{onSyncStart:l,onSyncComplete:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ga=Q(de(),1);function KI({activeSection:a,onSectionChange:n,range:s,onRangeChange:i,updatedAt:l,onSyncStart:u,onSyncComplete:d,children:p}){let[h,g]=QI.useState(!1),b=(y)=>{n(y),g(!1)};return Ga.jsxDEV("div",{className:"stats-app-container",children:[Ga.jsxDEV(Vv,{activeSection:a,onSectionChange:b,className:"stats-desktop-nav"},void 0,!1,void 0,this),h&&Ga.jsxDEV("div",{className:"stats-mobile-drawer-overlay",onClick:()=>g(!1),role:"presentation",children:Ga.jsxDEV("div",{className:"stats-mobile-drawer",onClick:(y)=>y.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Navigation menu",children:[Ga.jsxDEV("div",{className:"stats-mobile-drawer-header",children:[Ga.jsxDEV("div",{className:"stats-logo-container",children:[Ga.jsxDEV("span",{className:"stats-logo-text",children:"OH MY PI"},void 0,!1,void 0,this),Ga.jsxDEV("span",{className:"stats-logo-subtext",children:"Observability"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ga.jsxDEV("button",{type:"button",onClick:()=>g(!1),className:"stats-drawer-close-btn","aria-label":"Close navigation menu",children:Ga.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ga.jsxDEV(Vv,{activeSection:a,onSectionChange:b,className:"stats-mobile-nav"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ga.jsxDEV("div",{className:"stats-main-pane",children:[Ga.jsxDEV(ZI,{activeSection:a,range:s,onRangeChange:i,updatedAt:l,onSyncStart:u,onSyncComplete:d,onMenuToggle:()=>g(!0)},void 0,!1,void 0,this),Ga.jsxDEV("main",{className:"stats-content-area",children:Ga.jsxDEV("div",{className:"stats-content-inner",children:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var rs=Q(dt(),1),$N=["overview","requests","traces","errors","models","providers","tools","costs","behavior","projects","gain"],JI=["1h","24h","7d","30d","90d","all"];function Zv(a){let n=a.replace(/^#\/?/,""),[s,i]=n.split("?"),l=$N.includes(s)?s:"overview",u="24h",d=null;if(i){let p=new URLSearchParams(i),h=p.get("range");if(JI.includes(h))u=h;d=p.get("s")}return{section:l,range:u,session:d}}function Qv(a,n,s){let i=s?`&s=${encodeURIComponent(s)}`:"";return`/${a}?range=${n}${i}`}function eA(){let[a,n]=rs.useState(()=>Zv(window.location.hash));rs.useEffect(()=>{let d=()=>{n(Zv(window.location.hash))};return window.addEventListener("hashchange",d),()=>{window.removeEventListener("hashchange",d)}},[]);let s=rs.useCallback((d,p,h)=>{window.location.hash=Qv(d,p,h)},[]),i=rs.useCallback((d)=>{s(d,a.range,d==="traces"?a.session:null)},[a.range,a.session,s]),l=rs.useCallback((d)=>{let p=JI.includes(d)?d:"24h";s(a.section,p,a.session)},[a.section,a.session,s]),u=rs.useCallback((d)=>{s(a.section,a.range,d)},[a.section,a.range,s]);return rs.useEffect(()=>{let d=window.location.hash,p=Zv(d),h=`#${Qv(p.section,p.range,p.session)}`;if(d!==h)window.location.hash=Qv(p.section,p.range,p.session)},[]),{section:a.section,setSection:i,range:a.range,setRange:l,session:a.session,setSession:u}}var tA=["January","February","March","April","May","June","July","August","September","October","November","December"],aA=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],WN=["MMMM","yyyy","EEEE","MMM","EEE","yy","MM","dd","HH","hh","mm","ss","M","d","H","h","m","s","a"];function ri(a,n=2){return String(a).padStart(n,"0")}function ZN(a,n){let s=a.getMonth(),i=a.getDay(),l=a.getHours(),u=l%12||12;switch(n){case"yyyy":return ri(a.getFullYear(),4);case"yy":return ri(a.getFullYear()%100);case"MMMM":return tA[s];case"MMM":return tA[s].slice(0,3);case"MM":return ri(s+1);case"M":return String(s+1);case"dd":return ri(a.getDate());case"d":return String(a.getDate());case"EEEE":return aA[i];case"EEE":return aA[i].slice(0,3);case"HH":return ri(l);case"H":return String(l);case"hh":return ri(u);case"h":return String(u);case"mm":return ri(a.getMinutes());case"m":return String(a.getMinutes());case"ss":return ri(a.getSeconds());case"s":return String(a.getSeconds());case"a":return l<12?"AM":"PM"}}function nA(a){let n=a instanceof Date?new Date(a.getTime()):new Date(a);if(Number.isNaN(n.getTime()))throw RangeError("Invalid time value");return n}function Cn(a,n){let s=nA(a),i="";for(let l=0;l<n.length;){if(n[l]==="'"){if(n[l+1]==="'"){i+="'",l+=2;continue}l++;while(l<n.length){if(n[l]!=="'"){i+=n[l++];continue}if(n[l+1]==="'"){i+="'",l+=2;continue}l++;break}continue}let u=n.slice(l),d=WN.find((h)=>u.startsWith(h));if(d){i+=ZN(s,d),l+=d.length;continue}let p=n[l++];if(/[A-Za-z]/.test(p))throw RangeError(`Format string contains an unescaped latin alphabet character \`${p}\``);i+=p}return i}function ii(a,n){return`${a} ${a===1?n:`${n}s`}`}function QN(a,n){let s=(n.getFullYear()-a.getFullYear())*12+n.getMonth()-a.getMonth();if(s===0)return 0;let i=new Date(a);i.setDate(1),i.setFullYear(a.getFullYear(),a.getMonth()+s,1);let l=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();if(i.setDate(Math.min(a.getDate(),l)),i.getTime()>n.getTime())s--;return s}function oA(a,n){let s=(n.getTime()-a.getTime())/1000,i=(n.getTimezoneOffset()-a.getTimezoneOffset())*60,l=Math.round((s-i)/60);if(l<2)return l===0?"less than a minute":"1 minute";if(l<45)return ii(l,"minute");if(l<90)return"about 1 hour";if(l<1440)return`about ${ii(Math.round(l/60),"hour")}`;if(l<2520)return"1 day";if(l<43200)return ii(Math.round(l/1440),"day");if(l<86400)return`about ${ii(Math.round(l/43200),"month")}`;let u=QN(a,n);if(u<12)return ii(Math.round(l/43200),"month");let d=Math.trunc(u/12),p=u%12;if(p<3)return`about ${ii(d,"year")}`;if(p<9)return`over ${ii(d,"year")}`;return`almost ${ii(d+1,"year")}`}function sA(a,n={}){let s=nA(a),i=new Date(Date.now()),l=s.getTime()>i.getTime(),u=l?oA(i,s):oA(s,i);if(!n.addSuffix)return u;return l?`in ${u}`:`${u} ago`}var ba=Q(dt(),1);var Kv=Q(rA(),1),Ho=Q(dt(),1);var lA="label";function iA(a,n){if(typeof a==="function")a(n);else if(a)a.current=n}function JN(a,n){let s=a.options;if(s&&n)Object.assign(s,n)}function uA(a,n){a.labels=n}function cA(a,n,s=lA){let i=[];a.datasets=n.map((l)=>{let u=a.datasets.find((d)=>d[s]===l[s]);if(!u||!l.data||i.includes(u))return{...l};return i.push(u),Object.assign(u,l),u})}function ez(a,n=lA){let s={labels:[],datasets:[]};return uA(s,a.labels),cA(s,a.datasets,n),s}function tz(a,n){let{height:s=150,width:i=300,redraw:l=!1,datasetIdKey:u,type:d,data:p,options:h,plugins:g=[],fallbackContent:b,updateMode:y,...v}=a,T=Ho.useRef(null),M=Ho.useRef(null),I=()=>{if(!T.current)return;M.current=new dl(T.current,{type:d,data:ez(p,u),options:h&&{...h},plugins:g}),iA(n,M.current)},w=()=>{if(iA(n,null),M.current)M.current.destroy(),M.current=null};return Ho.useEffect(()=>{if(!l&&M.current&&h)JN(M.current,h)},[l,h]),Ho.useEffect(()=>{if(!l&&M.current)uA(M.current.config.data,p.labels)},[l,p.labels]),Ho.useEffect(()=>{if(!l&&M.current&&p.datasets)cA(M.current.config.data,p.datasets,u)},[l,p.datasets]),Ho.useEffect(()=>{if(!M.current)return;if(l)w(),setTimeout(I);else M.current.update(y)},[l,h,p.labels,p.datasets,y]),Ho.useEffect(()=>{if(!M.current)return;w(),setTimeout(I)},[d]),Ho.useEffect(()=>(I(),()=>w()),[]),Kv.jsx("canvas",{ref:T,role:"img",height:s,width:i,...v,children:b})}var az=Ho.forwardRef(tz);function dA(a,n){return dl.register(n),Ho.forwardRef((s,i)=>Kv.jsx(az,{...s,ref:i,type:a}))}var Xa=dA("line",_v),li=dA("bar",Rv);var bt=["#ed4abf","#9b4dff","#5ad8e6","#62d394","#c77dff","#ff8fd1","#f5c14b","#ff6b7d"];function fA(a){let n=[...a].sort((s,i)=>i.totalRequests-s.totalRequests||`${s.model}::${s.provider}`.localeCompare(`${i.model}::${i.provider}`));return new Map(n.map((s,i)=>[`${s.model}::${s.provider}`,bt[i%bt.length]]))}var sa={dark:{legendLabel:"#a89fb3",tooltipBackground:"#241a2e",tooltipTitle:"#eae5ef",tooltipBody:"#a89fb3",tooltipBorder:"rgba(255, 255, 255, 0.12)",grid:"rgba(255, 255, 255, 0.06)",tick:"#867a93"},light:{legendLabel:"#5a5462",tooltipBackground:"#ffffff",tooltipTitle:"#241a2e",tooltipBody:"#5a5462",tooltipBorder:"rgba(20, 12, 28, 0.15)",grid:"rgba(20, 12, 28, 0.08)",tick:"#6a6275"}};function is(a){let{chartTheme:n,showLegend:s,defaultLabel:i,formatValue:l,footer:u}=a;return{legend:{display:s,position:"top",align:"start",labels:{color:n.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:n.tooltipBackground,titleColor:n.tooltipTitle,bodyColor:n.tooltipBody,borderColor:n.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(d)=>{let p=d.dataset.label??i,h=d.parsed.y??0;return`${p}: ${l(h)}`},...u?{footer:u}:{}}}}}function ls(a){let{chartTheme:n,formatY:s}=a,i={grid:{color:n.grid,drawBorder:!1},ticks:{color:n.tick,font:{size:11}}},l={...i,ticks:{...i.ticks,callback:(u)=>s(Number(u))},min:0};return{sharedScaleBase:i,yScale:l}}function Vu(a){return{borderColor:a,backgroundColor:`${a}20`,fill:!0,tension:0,pointRadius:3,pointHoverRadius:4,borderWidth:2}}function Sl(a){return{backgroundColor:a,borderColor:a,borderWidth:0,borderRadius:4,maxBarThickness:56}}function ui(a,n){return a.datasets.map((s,i)=>({label:s.label,data:s.data,...n(i)}))}function Dm(a,n,s){if(a.length===0)return{labels:[],datasets:[]};let{initBucket:i,accumulate:l,bucketToValue:u}=s,d=new Map;for(let h of a){let g=d.get(h.timestamp)??i();l(g,h),d.set(h.timestamp,g)}let p=[...d.entries()].sort((h,g)=>h[0]-g[0]);return{labels:p.map(([h])=>Cn(new Date(h),"MMM d")),datasets:[{label:n,data:p.map(([,h])=>u(h))}]}}function ju(a,n){if(a.length===0)return{labels:[],datasets:[]};let{topN:s=5,rankWeight:i,initBucket:l,accumulate:u,bucketToValue:d}=n,p=new Map;for(let A of a){let B=`${A.model}::${A.provider}`,z=p.get(B);if(z)z.weight+=i(A);else p.set(B,{model:A.model,provider:A.provider,weight:i(A)})}let g=[...p.entries()].sort((A,B)=>B[1].weight-A[1].weight).slice(0,s),b=new Set(g.map(([A])=>A)),y=new Map;for(let[,{model:A}]of g)y.set(A,(y.get(A)??0)+1);let v=new Map;for(let[A,{model:B,provider:z}]of g)v.set(A,(y.get(B)??0)>1?`${B} (${z})`:B);let T=[...new Set(a.map((A)=>A.timestamp))].sort((A,B)=>A-B),M=g.map(([A])=>v.get(A)??A);if(a.some((A)=>!b.has(`${A.model}::${A.provider}`)))M.push("Other");let w=new Map;for(let A of T)w.set(A,{});for(let A of a){let B=`${A.model}::${A.provider}`,z=b.has(B)?v.get(B)??A.model:"Other",H=w.get(A.timestamp);if(!H)continue;let V=H[z]??l();u(V,A),H[z]=V}return{labels:T.map((A)=>Cn(new Date(A),"MMM d")),datasets:M.map((A)=>({label:A,data:T.map((B)=>{let z=w.get(B)?.[A];return z?d(z):0})}))}}var Wt=Q(de(),1);function Ws(a){return{borderColor:a,backgroundColor:"transparent",tension:0.4,pointRadius:0,borderWidth:2}}function Em({timestamps:a,values:n,color:s}){let i={labels:a.map((u)=>Cn(new Date(u),"MMM d")),datasets:[{data:n,...Ws(s)}]};return Wt.jsxDEV(Xa,{data:i,options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{x:{display:!1},y:{display:!1,min:0}}}},void 0,!1,void 0,this)}function Om(a){return{legend:{display:!0,position:"top",labels:{color:a.legendLabel,usePointStyle:!0,padding:16,font:{size:12}}},tooltip:{backgroundColor:a.tooltipBackground,titleColor:a.tooltipTitle,bodyColor:a.tooltipBody,borderColor:a.tooltipBorder,borderWidth:1,cornerRadius:8}}}function pA(a){return{x:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}},min:0}}}function hA(a){return{x:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y:{type:"linear",display:!0,position:"left",grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y1:{type:"linear",display:!0,position:"right",grid:{drawOnChartArea:!1},ticks:{color:a.tick,font:{size:11}}}}}function Pm({title:a,subtitle:n,children:s}){return Wt.jsxDEV("div",{className:"stats-panel overflow-hidden",children:[Wt.jsxDEV("div",{className:"px-5 py-4 border-b border-[var(--border-subtle)]",children:[Wt.jsxDEV("h3",{className:"text-sm font-semibold text-[var(--text-primary)]",children:a},void 0,!1,void 0,this),n?Wt.jsxDEV("p",{className:"text-xs text-[var(--text-muted)] mt-1",children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),Wt.jsxDEV("div",{className:"overflow-x-auto",children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function oz(a){if(a==="right")return"text-right";if(a==="center")return"text-center";return""}function Bm({columns:a,gridTemplate:n}){return Wt.jsxDEV("div",{className:"grid gap-3 px-5 py-3 text-[var(--text-muted)] text-xs uppercase tracking-wider font-semibold",style:{gridTemplateColumns:n},children:[a.map((s)=>Wt.jsxDEV("div",{className:oz(s.align),children:s.label},s.label,!1,void 0,this)),Wt.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nm({children:a}){return Wt.jsxDEV("div",{className:"max-h-[calc(100vh-300px)] overflow-y-auto",children:a},void 0,!1,void 0,this)}function zm({model:a,provider:n}){return Wt.jsxDEV("div",{children:[Wt.jsxDEV("div",{className:"font-medium text-[var(--text-primary)]",children:a},void 0,!1,void 0,this),Wt.jsxDEV("div",{className:"text-xs text-[var(--text-muted)]",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Hm({gridTemplate:a,cells:n,trendCell:s,isExpanded:i,onToggle:l,expandedContent:u}){return Wt.jsxDEV("div",{className:"border-t border-[var(--border-subtle)]",children:[Wt.jsxDEV("button",{type:"button",onClick:l,className:"w-full bg-transparent border-none text-left px-5 py-3 cursor-pointer hover:bg-[var(--bg-hover)] transition-colors",children:Wt.jsxDEV("div",{className:"grid gap-3 items-center",style:{gridTemplateColumns:a},children:[n,Wt.jsxDEV("div",{className:"h-10",children:s},void 0,!1,void 0,this),Wt.jsxDEV("div",{className:"flex justify-center text-[var(--text-muted)]",children:i?Wt.jsxDEV(tf,{size:16},void 0,!1,void 0,this):Wt.jsxDEV(Ys,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i?Wt.jsxDEV("div",{className:"px-5 py-4 bg-[var(--bg-elevated)] border-t border-[var(--border-subtle)]",children:u},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}function Um(){return Wt.jsxDEV("div",{className:"text-[var(--text-muted)] text-center text-sm",children:"-"},void 0,!1,void 0,this)}function Fm({message:a="No data available"}){return Wt.jsxDEV("div",{className:"h-full flex items-center justify-center text-[var(--text-muted)] text-sm",children:a},void 0,!1,void 0,this)}function Ce(a){return a.toLocaleString()}function lt(a){return a.toLocaleString(void 0,{notation:"compact"})}function us(a,n){if(a===0)return"$0";let s=n!==void 0?n:a>0&&a<0.01?4:2;return`$${a.toLocaleString(void 0,{minimumFractionDigits:s,maximumFractionDigits:s})}`}function ka(a,n,s){return a===0&&n>0?"N/A":us(a,s)}function ln(a,n){let s=a.provider==="xai-oauth"&&a.usage.totalTokens>0&&a.usage.cost.total===0?1:0;return ka(a.usage.cost.total,s,n)}function Ht(a,n=1){return`${(a*100).toFixed(n)}%`}function rt(a,n){if(a===null)return"-";let s=a/1000,i=n!==void 0?n:s<1?2:1;return`${s.toFixed(i)}s`}function qm(a){if(a===null)return"-";return a.toFixed(1)}function za(a){return sA(new Date(a),{addSuffix:!0})}function Jv(a){if(a>=1e9)return`${(a/1e9).toFixed(1)} GB`;if(a>=1e6)return`${(a/1e6).toFixed(1)} MB`;if(a>=1000)return`${(a/1000).toFixed(1)} KB`;return`${a} B`}var Ha=Q(dt(),1),ci=new Map,nz=64;function Vt(a,n,s){let i=JSON.stringify(a),[l,u]=Ha.useState(()=>ci.get(i)?.data??null),[d,p]=Ha.useState(null),[h,g]=Ha.useState(()=>!ci.has(i)),[b,y]=Ha.useState(!1),[v,T]=Ha.useState(()=>ci.get(i)?.updatedAt??null),M=Ha.useRef(n);M.current=n;let I=Ha.useRef(i);I.current=i;let w=s?.enabled??!0,A=s?.pollMs,B=Ha.useRef(null),z=Ha.useRef(!1);z.current=l!==null;let H=Ha.useCallback(async(G)=>{if(B.current)B.current.abort();let X=new AbortController;if(B.current=X,G)y(!0);else g(!0),u(null);p(null);try{let Y=await M.current(X.signal);if(X.signal.aborted)return;if(ci.set(I.current,{data:Y,updatedAt:Date.now()}),ci.size>nz){let J=ci.keys().next().value;if(J!==void 0)ci.delete(J)}u(Y),T(Date.now()),p(null)}catch(Y){if(X.signal.aborted)return;p(Y instanceof Error?Y:Error(String(Y)))}finally{if(!X.signal.aborted){if(g(!1),y(!1),B.current===X)B.current=null}}},[]);Ha.useEffect(()=>{if(!w){g(!1),y(!1);return}let G=ci.get(i);if(G)u(G.data),T(G.updatedAt),g(!1),H(!0);else H(z.current);return()=>{if(B.current)B.current.abort(),B.current=null}},[i,w,H]),Ha.useEffect(()=>{if(!w||!A)return;let G=setInterval(()=>{if(document.hidden)return;H(!0)},A);return()=>{clearInterval(G)}},[w,A,H]);let V=Ha.useCallback(async()=>{await H(!0)},[H]);return{data:l,error:d,loading:h,refreshing:b,refetch:V,updatedAt:v}}var mA=3600000,Vm=24*mA,sz=300000,gA={"1h":{windowLabel:"the last hour",trendLabel:"1h Trend",bucketMs:sz,bucketCount:12,tickFormat:"HH:mm"},"24h":{windowLabel:"the last 24 hours",trendLabel:"24h Trend",bucketMs:mA,bucketCount:24,tickFormat:"HH:mm"},"7d":{windowLabel:"the last 7 days",trendLabel:"7d Trend",bucketMs:Vm,bucketCount:7,tickFormat:"MMM d"},"30d":{windowLabel:"the last 30 days",trendLabel:"30d Trend",bucketMs:Vm,bucketCount:30,tickFormat:"MMM d"},"90d":{windowLabel:"the last 90 days",trendLabel:"90d Trend",bucketMs:Vm,bucketCount:90,tickFormat:"MMM d"},all:{windowLabel:"all time",trendLabel:"Trend",bucketMs:Vm,bucketCount:0,tickFormat:"MMM d"}};function Ll(a){return gA[a]}function Lf(a,n){return Cn(new Date(a),gA[n].tickFormat)}var rz=["main","subagent","advisor"];function jm(a){return a.totalInputTokens+a.totalOutputTokens+a.totalCacheReadTokens+a.totalCacheWriteTokens}function yA(a){let n=new Map;for(let d of a)n.set(d.agentType,d);let s=rz.map((d)=>n.get(d)).filter((d)=>d!==void 0),i=s.reduce((d,p)=>d+jm(p),0),l=s.reduce((d,p)=>d+p.totalCost,0),u=s.map((d)=>{let p=jm(d);return{agentType:d.agentType,tokens:p,requests:d.totalRequests,cost:d.totalCost,share:i>0?p/i:0}});return{totalTokens:i,totalCost:l,segments:u}}function bA(a){let n=a.reduce((h,g)=>h+g.cost,0),s=a.reduce((h,g)=>h+g.unpricedRequests,0),i=new Set(a.map((h)=>h.timestamp)).size,l=i>0?n/i:0,u=new Map;for(let h of a)u.set(h.model,(u.get(h.model)??0)+h.cost);let d="",p=0;for(let[h,g]of u)if(g>p)d=h,p=g;return{totalCost:n,unpricedRequests:s,avgDailyCost:l,topModelName:d,topModelCost:p}}function xA(a,n){if(a.length===0)return new Map;let s=Ll(n),{bucketMs:i,bucketCount:l}=s,u=l>0?(()=>{let h=a.reduce((y,v)=>Math.max(y,v.timestamp),0),b=(h>0?h:Math.floor(Date.now()/i)*i)-(l-1)*i;return Array.from({length:l},(y,v)=>b+v*i)})():Array.from(new Set(a.map((h)=>h.timestamp))).sort((h,g)=>h-g),d=new Map(u.map((h,g)=>[h,g])),p=new Map;for(let h of a){let g=`${h.model}::${h.provider}`,b=p.get(g);if(!b)b={label:`${h.model} (${h.provider})`,data:u.map((v)=>({timestamp:v,avgTtftSeconds:null,avgTokensPerSecond:null,requests:0}))},p.set(g,b);let y=d.get(h.timestamp);if(y===void 0)continue;b.data[y]={timestamp:h.timestamp,avgTtftSeconds:h.avgTtft!==null?h.avgTtft/1000:null,avgTokensPerSecond:h.avgTokensPerSecond,requests:h.requests}}return p}function vA(a,n){let s=a.totalNegation+a.totalRepetition+a.totalBlame,i=new Map;for(let u of n){let d=`${u.model}::${u.provider}`,p=i.get(d),h=u.yelling+u.profanity+u.anguish+u.negation+u.repetition+u.blame;if(p)p.score+=h;else i.set(d,{model:u.model,provider:u.provider,score:h})}let l=null;for(let u of i.values())if(!l||u.score>l.score)l=u;return{totalMessages:a.totalMessages,totalYelling:a.totalYelling,totalProfanity:a.totalProfanity,totalAnguish:a.totalAnguish,totalFrustration:s,highestFrictionModel:l}}function SA(a){let n=[...a].sort((l,u)=>{if(u.totalCost!==l.totalCost)return u.totalCost-l.totalCost;return u.totalRequests-l.totalRequests}),s=n.reduce((l,u)=>Math.max(l,u.totalCost),0),i=n.reduce((l,u)=>Math.max(l,u.totalRequests),0);return n.map((l)=>({...l,costPercentage:s>0?l.totalCost/s*100:0,requestsPercentage:i>0?l.totalRequests/i*100:0}))}function LA(a){let n=a.reduce((s,i)=>Math.max(s,i.calls),0);return a.map((s)=>({...s,errorRate:s.calls>0?s.errors/s.calls:0,callsPercentage:n>0?s.calls/n*100:0}))}var Gm=Q(de(),1);function Gu({message:a="No data available",icon:n=lf,className:s=""}){return Gm.jsxDEV("div",{className:`stats-empty-state ${s}`,children:[Gm.jsxDEV(n,{size:24,className:"stats-empty-state-icon","aria-hidden":"true"},void 0,!1,void 0,this),Gm.jsxDEV("p",{className:"stats-empty-state-message",children:a},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Xu=Q(de(),1);function CA({error:a,onRetry:n,className:s=""}){return Xu.jsxDEV("div",{className:`stats-error-state ${s}`,children:Xu.jsxDEV("div",{className:"stats-error-state-content",children:[Xu.jsxDEV("h4",{className:"stats-error-state-title",children:"Failed to load data"},void 0,!1,void 0,this),a&&Xu.jsxDEV("p",{className:"stats-error-state-message",children:a.message},void 0,!1,void 0,this),n&&Xu.jsxDEV("button",{type:"button",onClick:n,className:"stats-button stats-button-secondary stats-error-state-btn",children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var TA=Q(de(),1);function Ua({variant:a="text",width:n,height:s,className:i=""}){let l={width:n!==void 0?typeof n==="number"?`${n}px`:n:void 0,height:s!==void 0?typeof s==="number"?`${s}px`:s:void 0};return TA.jsxDEV("div",{className:`stats-skeleton ${i}`,"data-variant":a,style:l},void 0,!1,void 0,this)}var Uo=Q(de(),1);function Rt({loading:a,error:n,data:s,empty:i=!1,emptyText:l="No data available",fallback:u,onRetry:d,children:p}){if(n&&s===null)return Uo.jsxDEV(CA,{error:n,onRetry:d},void 0,!1,void 0,this);if(a&&s===null){if(u)return Uo.jsxDEV(Uo.Fragment,{children:u},void 0,!1,void 0,this);return Uo.jsxDEV("div",{className:"stats-boundary-skeleton",children:[Uo.jsxDEV(Ua,{variant:"text",width:"60%",height:24,className:"mb-4"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"rect",width:"100%",height:160,className:"mb-4"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"text",width:"80%",height:20,className:"mb-2"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"text",width:"40%",height:20},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}if(!a&&(i||s===null))return Uo.jsxDEV(Gu,{message:l},void 0,!1,void 0,this);return Uo.jsxDEV(Uo.Fragment,{children:p},void 0,!1,void 0,this)}var xo=Q(de(),1);function Ma({columns:a,data:n,keyExtractor:s,onRowClick:i,renderMobileCard:l,emptyText:u="No data available"}){let d=(p,h)=>{if(i&&(p.key==="Enter"||p.key===" "))p.preventDefault(),i(h)};if(n.length===0)return xo.jsxDEV("div",{className:"stats-table-empty",children:u},void 0,!1,void 0,this);return xo.jsxDEV("div",{className:"stats-table-wrapper",children:[l&&xo.jsxDEV("div",{className:"stats-table-mobile-only",children:xo.jsxDEV("div",{className:"stats-table-mobile-list",children:n.map((p)=>{let h=String(s(p));return xo.jsxDEV("div",{className:"stats-table-mobile-card-wrapper",children:l(p,i?()=>i(p):void 0)},h,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),xo.jsxDEV("div",{className:l?"stats-table-desktop-only":"stats-table-container",children:xo.jsxDEV("table",{className:"stats-table",children:[xo.jsxDEV("thead",{children:xo.jsxDEV("tr",{children:a.map((p)=>{let h=["stats-table-th",p.numeric?"stats-text-right":"stats-text-left",p.className||""].filter(Boolean).join(" ");return xo.jsxDEV("th",{className:h,children:p.header},p.key,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),xo.jsxDEV("tbody",{children:n.map((p)=>{let h=String(s(p)),g=typeof i==="function",b=["stats-table-tr",g?"stats-table-tr-clickable":""].filter(Boolean).join(" ");return xo.jsxDEV("tr",{className:b,onClick:g?()=>i(p):void 0,onKeyDown:g?(y)=>d(y,p):void 0,tabIndex:g?0:void 0,role:g?"button":void 0,children:a.map((y)=>{let v=["stats-table-td",y.numeric?"stats-text-right":"stats-text-left",y.className||""].filter(Boolean).join(" ");return xo.jsxDEV("td",{className:v,children:y.render?y.render(p):p[y.key]},y.key,!1,void 0,this)})},h,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Cl=Q(dt(),1),un=Q(de(),1);function Cf({data:a,title:n,initialCollapsed:s=!1}){let[i,l]=Cl.useState(s),[u,d]=Cl.useState(!1),p=Cl.useRef(0),h=JSON.stringify(a,null,2);return Cl.useEffect(()=>()=>window.clearTimeout(p.current),[]),un.jsxDEV("div",{className:"stats-json-block",children:[un.jsxDEV("div",{className:"stats-json-block-header",onClick:()=>l(!i),onKeyDown:(y)=>{if(y.key==="Enter"||y.key===" ")y.preventDefault(),l(!i)},tabIndex:0,role:"button","aria-expanded":!i,children:[un.jsxDEV("span",{className:"stats-json-block-title",children:n||"JSON"},void 0,!1,void 0,this),un.jsxDEV("div",{className:"stats-json-actions",children:[un.jsxDEV("button",{type:"button",className:"stats-json-copy-btn",onClick:async(y)=>{y.stopPropagation();try{await navigator.clipboard.writeText(h),d(!0),window.clearTimeout(p.current),p.current=window.setTimeout(()=>d(!1),1500)}catch{}},"aria-label":u?"Copied to clipboard":"Copy JSON to clipboard",children:[u?un.jsxDEV(pl,{size:13},void 0,!1,void 0,this):un.jsxDEV(gl,{size:13},void 0,!1,void 0,this),u?"Copied":"Copy"]},void 0,!0,void 0,this),un.jsxDEV("span",{className:"stats-json-block-toggle-indicator","data-collapsed":i,children:i?"▶ Show":"▼ Hide"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&un.jsxDEV("div",{className:"stats-json-block-content-wrapper",children:un.jsxDEV("pre",{className:"stats-json-block-content",children:un.jsxDEV("code",{children:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var qe=Q(de(),1);function wA({stats:a}){let n=jm(a);return qe.jsxDEV("div",{className:"stats-metric-cluster",children:[qe.jsxDEV("div",{className:"stats-metric-primary-grid",children:[qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:ka(a.totalCost,a.unpricedRequests,a.totalCost>0&&a.totalCost<0.01?4:2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Requests"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.totalRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",title:"Prompt-input cost saved versus billing the same tokens uncached; cache writes can make this negative",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Savings"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.cacheSavings)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",title:"Prompt input served from cache: cache reads / (uncached input + cache reads)",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Rate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.cacheRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Error Rate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.errorRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-secondary-grid",children:[qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Conversation input not served from cache",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Uncached Input"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalInputTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Conversation input read from the prompt cache",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Read"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalCacheReadTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Output Tokens"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalOutputTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Uncached input + cache reads + cache writes + output",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Conversation Total"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(n)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Premium Requests"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.totalPremiumRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Tokens/s"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:qm(a.avgTokensPerSecond)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Avg Latency"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:rt(a.avgDuration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Avg TTFT"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:rt(a.avgTtft)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var di=Q(de(),1);function ut({title:a,subtitle:n,actions:s,children:i,className:l="",...u}){return di.jsxDEV("div",{className:`stats-panel ${l}`,...u,children:[(a||n||s)&&di.jsxDEV("div",{className:"stats-panel-header",children:[di.jsxDEV("div",{className:"stats-panel-header-titles",children:[a&&di.jsxDEV("h3",{className:"stats-panel-title",children:a},void 0,!1,void 0,this),n&&di.jsxDEV("p",{className:"stats-panel-subtitle",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&di.jsxDEV("div",{className:"stats-panel-actions",children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),di.jsxDEV("div",{className:"stats-panel-body",children:i},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cs=Q(dt(),1);var kA=Q(de(),1);function ya({variant:a,children:n,className:s=""}){return kA.jsxDEV("span",{className:`stats-status-pill ${s}`,"data-variant":a,children:n},void 0,!1,void 0,this)}var ke=Q(de(),1);function MA({id:a,onClose:n}){let[s,i]=cs.useState(null),[l,u]=cs.useState(!1),[d,p]=cs.useState(null),h=cs.useRef(null),g=cs.useRef(null);if(cs.useEffect(()=>{if(a===null){i(null);return}h.current=document.activeElement,u(!0),p(null),i(null);let y=new AbortController;return DI(a,y.signal).then((v)=>{if(y.signal.aborted)return;i(v),setTimeout(()=>g.current?.focus(),50)}).catch((v)=>{if(y.signal.aborted)return;p(v instanceof Error?v:Error(String(v)))}).finally(()=>{if(!y.signal.aborted)u(!1)}),()=>y.abort()},[a]),cs.useEffect(()=>{if(a===null)return;let y=(v)=>{if(v.key==="Escape")n()};return window.addEventListener("keydown",y),()=>{if(window.removeEventListener("keydown",y),h.current)h.current.focus()}},[a,n]),a===null)return null;return ke.jsxDEV("div",{className:"stats-drawer-overlay",onClick:(y)=>{if(y.target===y.currentTarget)n()},role:"presentation",children:ke.jsxDEV("div",{className:"stats-drawer",role:"dialog","aria-modal":"true","aria-label":"Request details",children:[ke.jsxDEV("div",{className:"stats-drawer-header",children:[ke.jsxDEV("div",{className:"stats-drawer-header-left",children:[ke.jsxDEV("h2",{className:"stats-drawer-title",children:"Request Details"},void 0,!1,void 0,this),s&&ke.jsxDEV("span",{className:"stats-drawer-id",children:["ID: ",a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("button",{ref:g,type:"button",onClick:n,className:"stats-drawer-close-btn","aria-label":"Close request details",children:ke.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-body",children:[l&&ke.jsxDEV("div",{className:"stats-drawer-loading",children:[ke.jsxDEV(Ua,{variant:"text",width:"60%",height:24,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:80,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:120,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:200},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&ke.jsxDEV("div",{className:"stats-drawer-error",children:[ke.jsxDEV("p",{className:"stats-drawer-error-title",children:"Failed to load request details"},void 0,!1,void 0,this),ke.jsxDEV("p",{className:"stats-drawer-error-message",children:d.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&ke.jsxDEV("div",{className:"stats-drawer-content",children:[ke.jsxDEV("div",{className:"stats-drawer-status-card",children:[ke.jsxDEV("div",{className:"stats-drawer-status-row",children:[ke.jsxDEV("div",{children:[ke.jsxDEV("div",{className:"stats-drawer-model",children:s.model},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-provider",children:s.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV(ya,{variant:s.errorMessage?"danger":"success",children:s.errorMessage?"Error":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s.errorMessage&&ke.jsxDEV("div",{className:"stats-drawer-error-block",children:[ke.jsxDEV("div",{className:"stats-drawer-error-label",children:"Error Message"},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-error-text",children:s.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metrics-grid",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(ml,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"API-equivalent estimate"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:ln(s,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(mf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Premium"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(s.usage.premiumRequests??0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(rf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Total Tokens"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(s.usage.totalTokens)},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-sub",children:[Ce(s.usage.input)," in · ",Ce(s.usage.output)," out"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(af,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Duration"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(s.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(xf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"TTFT"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(s.ttft)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s.duration&&s.usage.output>0&&ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(sf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Throughput"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:(s.usage.output*1000/s.duration).toFixed(1)},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-sub",children:"tokens/second"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-json-blocks",children:[ke.jsxDEV(Cf,{data:s.output,title:"Output Payload",initialCollapsed:!1},void 0,!1,void 0,this),ke.jsxDEV(Cf,{data:s,title:"Raw Request Metadata",initialCollapsed:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var e0=Q(de(),1);function Zs({options:a,value:n,onChange:s,className:i=""}){return e0.jsxDEV("div",{className:`stats-segmented-control ${i}`,role:"radiogroup",children:a.map((l)=>{let u=l.value===n;return e0.jsxDEV("button",{type:"button",role:"radio","aria-checked":u,"data-active":u?"true":"false",className:"stats-segmented-control-btn",title:l.title,onClick:()=>s(l.value),children:l.label},String(l.value),!1,void 0,this)})},void 0,!1,void 0,this)}var Me=Q(de(),1);function EA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["behavior",n,s],(d)=>OI(n,d),{pollMs:30000,enabled:a});return Me.jsxDEV("div",{className:"stats-route-container space-y-6",children:Me.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&Me.jsxDEV(Me.Fragment,{children:[Me.jsxDEV(iz,{overall:i.overall,behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this),Me.jsxDEV(lz,{behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this),Me.jsxDEV(uz,{models:i.byModel,behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Xm(a,n){if(n<=0)return;return`${(a/n).toFixed(2)} / msg`}function iz({overall:a,behaviorSeries:n}){let s=ba.useMemo(()=>vA(a,n),[a,n]),i=a.totalMessages,l=[{label:"User Messages",value:Ce(a.totalMessages),sub:i>0?"in range":void 0},{label:"Yelling (CAPS)",value:Ce(a.totalYelling),sub:Xm(a.totalYelling,i)},{label:"Profanity Hits",value:Ce(a.totalProfanity),sub:Xm(a.totalProfanity,i)},{label:"Anguish Signals",value:Ce(a.totalAnguish),sub:Xm(a.totalAnguish,i)},{label:"Friction Signals",value:Ce(s.totalFrustration),sub:Xm(s.totalFrustration,i)},{label:"Highest Friction Model",value:s.highestFrictionModel?.model??"—",sub:s.highestFrictionModel?`${Ce(s.highestFrictionModel.score)} hits`:void 0}];return Me.jsxDEV("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-4",children:l.map((u)=>Me.jsxDEV(ut,{className:"stats-behavior-summary-card py-3 px-4",children:[Me.jsxDEV("p",{className:"text-xs stats-text-muted mb-1 font-medium truncate",children:u.label},void 0,!1,void 0,this),Me.jsxDEV("p",{className:"text-lg font-bold stats-text-primary truncate",title:u.value,children:u.value},void 0,!1,void 0,this),u.sub&&Me.jsxDEV("p",{className:"text-xs stats-text-muted mt-0.5",children:u.sub},void 0,!1,void 0,this)]},u.label,!0,void 0,this))},void 0,!1,void 0,this)}var t0=[{value:"yelling",label:"CAPS",title:"Yelling (CAPS)"},{value:"profanity",label:"Profanity",title:"Profanity"},{value:"anguish",label:"Anguish",title:"Anguish (!!!, nooo, ugh, dude, ':(')"},{value:"negation",label:"Negation",title:"Negation (no/nope/wrong, makes no sense)"},{value:"repetition",label:"Repetition",title:"Repetition (i meant, still doesnt)"},{value:"blame",label:"Blame",title:"Blame (you didnt, why did you, stop X-ing)"},{value:"frustration",label:"Frustration",title:"Frustration (neg + rep + blame)"},{value:"total",label:"All",title:"All signals combined"}];function IA(a){if(!Number.isFinite(a))return"-";if(a===0)return"0%";if(Math.abs(a)<1)return`${a.toFixed(1)}%`;return`${a.toFixed(0)}%`}function AA(a,n){if(n==="frustration")return a.negation+a.repetition+a.blame;if(n==="total")return a.yelling+a.profanity+a.anguish+a.negation+a.repetition+a.blame;return a[n]}function RA(a,n){if(n<=0)return 0;return a/n*100}function lz({behaviorSeries:a}){let[n,s]=ba.useState(!1),[i,l]=ba.useState("total"),u=$t(),d=sa[u],p=ba.useMemo(()=>{if(n)return ju(a,{rankWeight:(B)=>B.messages,initBucket:()=>({hits:0,messages:0}),accumulate:(B,z)=>{B.hits+=AA(z,i),B.messages+=z.messages},bucketToValue:(B)=>RA(B.hits,B.messages)});let A=t0.find((B)=>B.value===i)?.title??"Hits";return Dm(a,A,{initBucket:()=>({hits:0,messages:0}),accumulate:(B,z)=>{B.hits+=AA(z,i),B.messages+=z.messages},bucketToValue:(B)=>RA(B.hits,B.messages)})},[a,n,i]),h=ba.useMemo(()=>is({chartTheme:d,showLegend:n,defaultLabel:"Hits",formatValue:IA}),[d,n]),{sharedScaleBase:g,yScale:b}=ba.useMemo(()=>ls({chartTheme:d,formatY:IA}),[d]),y=ba.useMemo(()=>t0.find((A)=>A.value===i)?.title??"",[i]),v=ba.useMemo(()=>{if(!n)return null;return{labels:p.labels,datasets:ui(p,(A)=>Vu(bt[A%bt.length]))}},[p,n]),T=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:h,scales:{x:g,y:b}}),[h,g,b]),M=ba.useMemo(()=>{if(n)return null;return{labels:p.labels,datasets:ui(p,(A)=>Sl(bt[A%bt.length]))}},[p,n]),I=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:h,scales:{x:{...g,stacked:!0},y:{...b,stacked:!0}},layout:{padding:{top:8}}}),[h,g,b]),w=[{value:!1,label:"All Models"},{value:!0,label:"By Model"}];return Me.jsxDEV(ut,{title:"User Friction Signals",subtitle:`${y} as % of user messages per day`,actions:Me.jsxDEV("div",{className:"flex items-center gap-3 flex-wrap",children:[Me.jsxDEV(Zs,{options:t0.map((A)=>({value:A.value,label:A.label,title:A.title})),value:i,onChange:l},void 0,!1,void 0,this),Me.jsxDEV(Zs,{options:w,value:n,onChange:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),children:Me.jsxDEV("div",{className:"h-[300px]",children:p.labels.length===0?Me.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No friction signal data available"},void 0,!1,void 0,this):n&&v?Me.jsxDEV(Xa,{data:v,options:T},void 0,!1,void 0,this):M?Me.jsxDEV(li,{data:M,options:I},void 0,!1,void 0,this):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var _A="2fr 0.9fr 0.8fr 0.8fr 0.8fr 0.9fr 0.8fr 140px 40px";function DA(a){if(a.totalMessages===0)return 0;return(a.totalYelling+a.totalProfanity+a.totalAnguish+a.totalNegation+a.totalRepetition+a.totalBlame)/a.totalMessages}function Yu(a,n){if(n===0)return"-";let s=a/n*100;if(s===0)return"0%";if(s<1)return`${s.toFixed(1)}%`;return`${s.toFixed(0)}%`}function uz({models:a,behaviorSeries:n}){let[s,i]=ba.useState(null),l=$t(),u=sa[l],d=ba.useMemo(()=>dz(n),[n]),p=ba.useMemo(()=>[...a].sort((h,g)=>{if(g.totalMessages!==h.totalMessages)return g.totalMessages-h.totalMessages;return DA(g)-DA(h)}),[a]);return Me.jsxDEV(Pm,{title:"Behavior Signals by Model",subtitle:"Rates are per user message",children:[Me.jsxDEV(Bm,{gridTemplate:_A,columns:[{label:"Model"},{label:"Messages",align:"right"},{label:"CAPS %",align:"right"},{label:"Profanity %",align:"right"},{label:"Anguish %",align:"right"},{label:"Frustration %",align:"right"},{label:"Hits %",align:"right"},{label:"Trend",align:"center"}]},void 0,!1,void 0,this),Me.jsxDEV(Nm,{children:[p.map((h,g)=>{let b=`${h.model}::${h.provider}`,y=d.get(b)?.data??[],v=bt[g%bt.length],T=s===b,M=h.totalNegation+h.totalRepetition+h.totalBlame,I=h.totalYelling+h.totalProfanity+h.totalAnguish+M;return Me.jsxDEV(Hm,{gridTemplate:_A,isExpanded:T,onToggle:()=>i(T?null:b),cells:[Me.jsxDEV(zm,{model:h.model,provider:h.provider},"name",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Ce(h.totalMessages)},"messages",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalYelling,h.totalMessages)},"caps",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalProfanity,h.totalMessages)},"profanity",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalAnguish,h.totalMessages)},"anguish",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(M,h.totalMessages)},"frustration",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(I,h.totalMessages)},"hits",!1,void 0,this)],trendCell:y.length===0?Me.jsxDEV(Um,{},void 0,!1,void 0,this):Me.jsxDEV(Em,{timestamps:y.map((w)=>w.timestamp),values:y.map((w)=>w.total),color:v},void 0,!1,void 0,this),expandedContent:Me.jsxDEV("div",{className:"grid gap-4",style:{gridTemplateColumns:"220px 1fr"},children:[Me.jsxDEV("div",{className:"space-y-4 text-sm",children:[Me.jsxDEV(Tl,{label:"Yelling (CAPS)",total:h.totalYelling,messages:h.totalMessages,valueClass:"text-[#ed4abf]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Profanity",total:h.totalProfanity,messages:h.totalMessages,valueClass:"text-[#ff6b7d]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Anguish (!!!, nooo, dude, ..)",total:h.totalAnguish,messages:h.totalMessages,valueClass:"text-[#9b4dff]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Negation (no/nope/wrong)",total:h.totalNegation,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Repetition (i meant, still doesnt)",total:h.totalRepetition,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Blame (you didnt, stop X-ing)",total:h.totalBlame,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Avg chars / msg",total:h.totalChars,messages:h.totalMessages,valueClass:"stats-text-secondary",mode:"average"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Me.jsxDEV("div",{className:"h-[200px]",children:y.length===0?Me.jsxDEV(Fm,{},void 0,!1,void 0,this):Me.jsxDEV(cz,{data:y,chartTheme:u},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},b,!1,void 0,this)}),p.length===0?Me.jsxDEV("div",{className:"border-t border-[var(--border-subtle)] px-5 py-8 text-center text-[var(--text-muted)] text-sm",children:"No user behavior recorded for this range yet."},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Tl({label:a,total:n,messages:s,valueClass:i,mode:l="rate"}){let u=l==="rate"?"% of msgs":"Per msg",d=ba.useMemo(()=>{if(s===0)return"-";return l==="rate"?Yu(n,s):(n/s).toFixed(0)},[n,s,l]);return Me.jsxDEV("div",{children:[Me.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-1",children:a},void 0,!1,void 0,this),Me.jsxDEV("div",{className:"space-y-0.5 text-[var(--text-secondary)]",children:[Me.jsxDEV("div",{className:"flex items-center justify-between",children:[Me.jsxDEV("span",{className:"stats-text-muted text-xs",children:"Total"},void 0,!1,void 0,this),Me.jsxDEV("span",{className:`font-mono text-xs ${i}`,children:Ce(n)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Me.jsxDEV("div",{className:"flex items-center justify-between",children:[Me.jsxDEV("span",{className:"stats-text-muted text-xs",children:u},void 0,!1,void 0,this),Me.jsxDEV("span",{className:"font-mono text-xs stats-text-primary",children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ym={yelling:"#ed4abf",profanity:"#ff6b7d",anguish:"#9b4dff",frustration:"#5ad8e6"};function cz({data:a,chartTheme:n}){let s=ba.useMemo(()=>({labels:a.map((l)=>Cn(new Date(l.timestamp),"MMM d")),datasets:[{label:"CAPS",data:a.map((l)=>l.yelling),...Ws(Ym.yelling)},{label:"Profanity",data:a.map((l)=>l.profanity),...Ws(Ym.profanity)},{label:"Anguish",data:a.map((l)=>l.anguish),...Ws(Ym.anguish)},{label:"Frustration",data:a.map((l)=>l.frustration),...Ws(Ym.frustration)}]}),[a]),i=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:Om(n),scales:pA(n)}),[n]);return Me.jsxDEV(Xa,{data:s,options:i},void 0,!1,void 0,this)}function dz(a){if(a.length===0)return new Map;let n=[...new Set(a.map((l)=>l.timestamp))].sort((l,u)=>l-u),s=new Map;for(let l of a){let u=`${l.model}::${l.provider}`,d=s.get(u);if(!d)d=new Map,s.set(u,d);let p=d.get(l.timestamp)??{timestamp:l.timestamp,yelling:0,profanity:0,anguish:0,frustration:0,total:0};p.yelling+=l.yelling,p.profanity+=l.profanity,p.anguish+=l.anguish,p.frustration+=l.negation+l.repetition+l.blame,p.total=p.yelling+p.profanity+p.anguish+p.frustration,d.set(l.timestamp,p)}let i=new Map;for(let[l,u]of s){let d=n.map((p)=>u.get(p)??{timestamp:p,yelling:0,profanity:0,anguish:0,frustration:0,total:0});i.set(l,{data:d})}return i}var Fo=Q(dt(),1);var xa=Q(de(),1);function OA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["costs",n,s],(d)=>RI(n,d),{pollMs:30000,enabled:a});return xa.jsxDEV("div",{className:"stats-route-container space-y-6",children:xa.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&xa.jsxDEV(xa.Fragment,{children:[xa.jsxDEV(fz,{costSeries:i.costSeries},void 0,!1,void 0,this),xa.jsxDEV(mz,{costSeries:i.costSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function fz({costSeries:a}){let n=Fo.useMemo(()=>bA(a),[a]),s=[{label:"API-equivalent estimate",value:ka(n.totalCost,n.unpricedRequests),sub:n.unpricedRequests>0?`Excludes ${n.unpricedRequests.toLocaleString()} unpriced subscription request${n.unpricedRequests===1?"":"s"}`:void 0},{label:"Average estimate / Day",value:ka(n.avgDailyCost,n.unpricedRequests)},{label:"Top Model",value:n.topModelName||"—",sub:n.topModelName?`API-equivalent estimate: ${us(n.topModelCost)}`:void 0}];return xa.jsxDEV("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:s.map((i)=>xa.jsxDEV(ut,{className:"stats-cost-overview-card py-4 px-5",children:[xa.jsxDEV("p",{className:"text-xs stats-text-muted mb-1 font-medium uppercase tracking-wider",children:i.label},void 0,!1,void 0,this),xa.jsxDEV("p",{className:"text-2xl font-bold stats-text-primary truncate",title:i.value,children:i.value},void 0,!1,void 0,this),i.sub&&xa.jsxDEV("p",{className:"text-xs stats-text-muted mt-1 font-medium",children:i.sub},void 0,!1,void 0,this)]},i.label,!0,void 0,this))},void 0,!1,void 0,this)}var pz={dark:"rgba(248, 250, 252, 0.7)",light:"rgba(15, 23, 42, 0.6)"};function hz(a){return{id:"costBarLabels",afterDatasetsDraw(n){let{ctx:s}=n;if(!n.data.datasets[0])return;let l=n.getDatasetMeta(0);s.save(),s.font="11px system-ui, sans-serif",s.fillStyle=a,s.textAlign="center",s.textBaseline="bottom";for(let u of l.data){let d=u.$context.parsed.y;if(!d)continue;let p=`$${Math.round(d)}`,{x:h,y:g}=u.getProps(["x","y"],!0);s.fillText(p,h,g-3)}s.restore()}}}function mz({costSeries:a}){let[n,s]=Fo.useState(!1),i=$t(),l=sa[i],u=Fo.useMemo(()=>a.reduce((w,A)=>w+A.unpricedRequests,0),[a]),d=Fo.useMemo(()=>{if(n)return ju(a,{rankWeight:(w)=>w.cost,initBucket:()=>({total:0}),accumulate:(w,A)=>{w.total+=A.cost},bucketToValue:(w)=>w.total});return Dm(a,"API-equivalent estimate",{initBucket:()=>({total:0}),accumulate:(w,A)=>{w.total+=A.cost},bucketToValue:(w)=>w.total})},[a,n]),p=Fo.useMemo(()=>is({chartTheme:l,showLegend:n,defaultLabel:"API-equivalent estimate",formatValue:(w)=>`$${w.toFixed(2)}`,footer:(w)=>{if(!n||w.length<2)return;return`Total: $${w.reduce((B,z)=>B+(z.parsed.y??0),0).toFixed(2)}`}}),[l,n]),{sharedScaleBase:h,yScale:g}=Fo.useMemo(()=>ls({chartTheme:l,formatY:(w)=>`$${Math.round(w)}`}),[l]),b=Fo.useMemo(()=>hz(pz[i]),[i]),y=Fo.useMemo(()=>{if(!n)return null;return{labels:d.labels,datasets:ui(d,(w)=>Vu(bt[w%bt.length]))}},[d,n]),v=Fo.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:p,scales:{x:h,y:g}}),[p,h,g]),T=Fo.useMemo(()=>{if(n)return null;return{labels:d.labels,datasets:ui(d,(w)=>Sl(bt[w%bt.length]))}},[d,n]),M=Fo.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{...p,costBarLabels:{}},scales:{x:{...h,stacked:!0},y:{...g,stacked:!0}},layout:{padding:{top:24}}}),[p,h,g]),I=[{value:!1,label:"All Models"},{value:!0,label:"By Model"}];return xa.jsxDEV(ut,{title:"Daily API-equivalent estimate",subtitle:u>0?`Public API rate-card value over time; excludes ${u.toLocaleString()} unpriced subscription request${u===1?"":"s"}`:"Public API rate-card value over time",actions:xa.jsxDEV(Zs,{options:I,value:n,onChange:s},void 0,!1,void 0,this),children:xa.jsxDEV("div",{className:"h-[300px]",children:d.labels.length===0?xa.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No API-equivalent estimate data available"},void 0,!1,void 0,this):n&&y?xa.jsxDEV(Xa,{data:y,options:v},void 0,!1,void 0,this):T?xa.jsxDEV(li,{data:T,options:M,plugins:[b]},void 0,!1,void 0,this):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var PA=Q(dt(),1);var Ut=Q(de(),1);function BA({active:a,range:n,refreshTrigger:s,onRequestClick:i}){let{data:l,error:u,loading:d}=Vt(["recent-errors-dense",n,s],(g)=>_I(n,50,g),{pollMs:30000,enabled:a}),p=PA.useMemo(()=>[{key:"model",header:"Model",render:(g)=>Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:g.model},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:g.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(g)=>za(g.timestamp)},{key:"errorMessage",header:"Error Message",render:(g)=>Ut.jsxDEV("div",{className:"stats-text-xs stats-text-danger stats-truncate stats-max-w-md stats-font-mono",title:g.errorMessage||"",children:g.errorMessage||"Unknown error"},void 0,!1,void 0,this)},{key:"tokens",header:"Tokens",numeric:!0,render:(g)=>Ce(g.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(g)=>ln(g,4)}],[]);return Ut.jsxDEV("div",{className:"stats-route-container",children:Ut.jsxDEV(ut,{title:"Recent Errors",subtitle:"Up to 50 most recent failed requests in the stats database",children:Ut.jsxDEV(Rt,{loading:d,error:u,data:l,emptyText:"No recent failures in the local stats database",children:Ut.jsxDEV(Ma,{columns:p,data:l||[],keyExtractor:(g)=>g.id||`${g.sessionFile}-${g.entryId}`,onRowClick:(g)=>g.id&&i(g.id),renderMobileCard:(g,b)=>Ut.jsxDEV("div",{className:"stats-mobile-card stats-border-danger",onClick:b,children:[Ut.jsxDEV("div",{className:"stats-mobile-card-header",children:[Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:g.model},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:g.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV(ya,{variant:"danger",children:"Failed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-grid",children:[Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:za(g.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(g,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(g.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),g.errorMessage&&Ut.jsxDEV("div",{className:"stats-mobile-card-error mt-2 stats-font-mono",children:g.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),emptyText:"No recent failures in the local stats database"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var $m=Q(dt(),1);var De=Q(de(),1);function NA({active:a,range:n,refreshTrigger:s}){let[i,l]=$m.useState(null),{data:u,error:d,loading:p}=Vt(["gain",n,s,i],(h)=>BI(n,i,h),{pollMs:30000,enabled:a});return De.jsxDEV("div",{className:"stats-route-container space-y-6",children:De.jsxDEV(Rt,{loading:p,error:d,data:u,children:u&&De.jsxDEV(De.Fragment,{children:[De.jsxDEV(gz,{projects:u.projects,selected:i,onChange:l},void 0,!1,void 0,this),De.jsxDEV(yz,{overall:u.overall},void 0,!1,void 0,this),De.jsxDEV(xz,{bySource:u.bySource},void 0,!1,void 0,this),De.jsxDEV(Sz,{timeSeries:u.timeSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function gz({projects:a,selected:n,onChange:s}){if(a.length===0)return null;return De.jsxDEV("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[De.jsxDEV("span",{className:"stats-text-secondary",style:{fontSize:"0.875rem",whiteSpace:"nowrap"},children:"Project"},void 0,!1,void 0,this),De.jsxDEV("select",{className:"stats-select",value:n??"",onChange:(i)=>s(i.target.value||null),style:{maxWidth:"480px",flex:1},children:[De.jsxDEV("option",{value:"",children:"All projects"},void 0,!1,void 0,this),a.map((i)=>De.jsxDEV("option",{value:i,children:i},i,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function yz({overall:a}){return De.jsxDEV(ut,{title:"Overall Gain",subtitle:"Aggregate snapcompact savings",children:De.jsxDEV("div",{className:"stats-metric-primary-grid",children:[De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Tokens"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:lt(a.savedTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Bytes"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:Jv(a.savedBytes)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Reduction"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:a.reductionPercent!==null?Ht(a.reductionPercent):"—"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Total Hits"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.hits)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function bz({title:a,totals:n}){return De.jsxDEV("div",{className:"stats-metric-card secondary",style:{flex:1},children:[De.jsxDEV("div",{className:"stats-metric-label",style:{fontWeight:600,marginBottom:8},children:a},void 0,!1,void 0,this),De.jsxDEV("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Tokens"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:lt(n.savedTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Bytes"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:Jv(n.savedBytes)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Hits"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:Ce(n.hits)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Reduction"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:n.reductionPercent!==null?Ht(n.reductionPercent):"—"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xz({bySource:a}){return De.jsxDEV(ut,{title:"By Source",subtitle:"Savings breakdown per subsystem",children:De.jsxDEV("div",{style:{display:"flex",gap:16,flexWrap:"wrap"},children:De.jsxDEV(bz,{title:"Snapcompact",totals:a.snapcompact},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var vz={snapcompact:"rgb(34, 197, 94)"};function Sz({timeSeries:a}){let n=$t(),s=sa[n],{data:i,options:l}=$m.useMemo(()=>{let u=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",timeZone:"UTC"}),p={labels:a.map((y)=>u.format(new Date(`${y.date}T00:00:00.000Z`))),datasets:[{label:"Snapcompact",data:a.map((y)=>y.snapcompact),...Vu(vz.snapcompact)}]},{sharedScaleBase:h,yScale:g}=ls({chartTheme:s,formatY:(y)=>lt(y)}),b={responsive:!0,maintainAspectRatio:!1,plugins:is({chartTheme:s,showLegend:!0,defaultLabel:"Tokens Saved",formatValue:lt}),scales:{x:{...h,stacked:!0},y:{...g,stacked:!0}}};return{data:p,options:b}},[a,s]);return De.jsxDEV(ut,{title:"Savings Over Time",subtitle:"Daily token savings",children:De.jsxDEV("div",{style:{height:240},children:a.length===0?De.jsxDEV("div",{className:"stats-table-empty",children:"No time series data yet"},void 0,!1,void 0,this):De.jsxDEV(Xa,{data:i,options:l},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Tn=Q(dt(),1);var Ee=Q(de(),1);function HA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["models",n,s],(p)=>AI(n,p),{pollMs:30000,enabled:a}),d=Tn.useMemo(()=>fA(i?.byModel??[]),[i?.byModel]);return Ee.jsxDEV("div",{className:"stats-route-container space-y-6",children:Ee.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&Ee.jsxDEV(Ee.Fragment,{children:[Ee.jsxDEV(Lz,{modelSeries:i.modelSeries,timeRange:n,colorLookup:d},void 0,!1,void 0,this),Ee.jsxDEV(Tz,{models:i.byModel,performanceSeries:i.modelPerformanceSeries,timeRange:n,colorLookup:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Lz({modelSeries:a,timeRange:n,colorLookup:s}){let i=$t(),l=sa[i],u=Ll(n),d=Tn.useMemo(()=>Cz(a),[a]),p=Tn.useMemo(()=>({labels:d.data.map((g)=>Lf(g.timestamp,n)),datasets:d.series.map((g,b)=>{let y=bt[b%bt.length],v=g.key?s.get(g.key)??y:y,T=g.key??g.label;return{label:g.label,data:d.data.map((M)=>M[T]??0),borderColor:v,backgroundColor:`${v}20`,fill:!0,tension:0.4,pointRadius:0,pointHoverRadius:4,borderWidth:2}})}),[d,s,n]),h=Tn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{position:"top",align:"start",labels:{color:l.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:l.tooltipBackground,titleColor:l.tooltipTitle,bodyColor:l.tooltipBody,borderColor:l.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(g)=>{let b=g.dataset.label??"",y=g.parsed.y;return`${b}: ${(y??0).toFixed(1)}%`}}}},scales:{x:{grid:{color:l.grid,drawBorder:!1},ticks:{color:l.tick,font:{size:11}}},y:{grid:{color:l.grid,drawBorder:!1},ticks:{color:l.tick,font:{size:11},callback:(g)=>`${g}%`},min:0,max:100}}}),[l]);return Ee.jsxDEV(ut,{title:"Model Preference",subtitle:`Share of requests over ${u.windowLabel}`,children:Ee.jsxDEV("div",{className:"h-[280px]",children:d.data.length===0?Ee.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No data available"},void 0,!1,void 0,this):Ee.jsxDEV(Xa,{data:p,options:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Cz(a,n=5){if(a.length===0)return{data:[],series:[]};let s=new Map;for(let y of a){let v=`${y.model}::${y.provider}`,T=s.get(v);if(T)T.total+=y.requests;else s.set(v,{model:y.model,provider:y.provider,total:y.requests})}let l=[...s.entries()].map(([y,v])=>({key:y,...v})).sort((y,v)=>v.total-y.total).slice(0,n),u=new Set(l.map((y)=>y.key)),d=new Map;for(let y of l)d.set(y.model,(d.get(y.model)??0)+1);let p=new Map;for(let y of l){let v=(d.get(y.model)??0)>1;p.set(y.key,v?`${y.model} (${y.provider})`:y.model)}let h=new Map;for(let y of a){let v=`${y.model}::${y.provider}`,T=h.get(y.timestamp)??{timestamp:y.timestamp,total:0};T.total+=y.requests;let M=u.has(v)?v:"Other";T[M]=(T[M]??0)+y.requests,h.set(y.timestamp,T)}let g=l.map((y)=>({key:y.key,label:p.get(y.key)??y.model}));if([...h.values()].some((y)=>(y.Other??0)>0))g.push({label:"Other"});return{data:[...h.values()].sort((y,v)=>(y.timestamp??0)-(v.timestamp??0)).map((y)=>{let v=y.total??0;for(let T of g){let M=T.key??T.label;y[M]=v>0?(y[M]??0)/v*100:0}return y}),series:g}}var zA="2fr 0.9fr 0.9fr 1fr 0.8fr 0.8fr 140px 40px";function Tz({models:a,performanceSeries:n,timeRange:s,colorLookup:i}){let[l,u]=Tn.useState(null),d=Ll(s),p=Tn.useMemo(()=>xA(n,s),[n,s]),h=$t(),g=sa[h],b=Tn.useMemo(()=>[...a].sort((y,v)=>v.totalInputTokens+v.totalOutputTokens-(y.totalInputTokens+y.totalOutputTokens)),[a]);return Ee.jsxDEV(Pm,{title:"Model Statistics",children:[Ee.jsxDEV(Bm,{gridTemplate:zA,columns:[{label:"Model"},{label:"Requests",align:"right"},{label:"API-equivalent estimate",align:"right"},{label:"Tokens",align:"right"},{label:"Tokens/s",align:"right"},{label:"TTFT",align:"right"},{label:d.trendLabel,align:"center"}]},void 0,!1,void 0,this),Ee.jsxDEV(Nm,{children:b.map((y,v)=>{let T=`${y.model}::${y.provider}`,I=p.get(T)?.data??[],w=i.get(T)??bt[v%bt.length],A=l===T,B=y.errorRate*100;return Ee.jsxDEV(Hm,{gridTemplate:zA,isExpanded:A,onToggle:()=>u(A?null:T),cells:[Ee.jsxDEV(zm,{model:y.model,provider:y.provider},"name",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.totalRequests.toLocaleString()},"requests",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:ka(y.totalCost,y.unpricedRequests)},"cost",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:(y.totalInputTokens+y.totalOutputTokens).toLocaleString()},"tokens",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.avgTokensPerSecond?.toFixed(1)??"-"},"tps",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.avgTtft?`${(y.avgTtft/1000).toFixed(2)}s`:"-"},"ttft",!1,void 0,this)],trendCell:I.length===0?Ee.jsxDEV(Um,{},void 0,!1,void 0,this):Ee.jsxDEV(Em,{timestamps:I.map((z)=>z.timestamp),values:I.map((z)=>z.avgTokensPerSecond??0),color:w},void 0,!1,void 0,this),expandedContent:Ee.jsxDEV("div",{className:"grid gap-4",style:{gridTemplateColumns:"200px 1fr"},children:[Ee.jsxDEV("div",{className:"space-y-4 text-sm",children:[Ee.jsxDEV("div",{children:[Ee.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-2",children:"Efficiency"},void 0,!1,void 0,this),Ee.jsxDEV("div",{className:"space-y-1 text-[var(--text-secondary)]",children:[Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Error rate"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:B>5?"text-[var(--accent-red)]":"text-[var(--accent-green)]",children:[B.toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Cache rate"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:[(y.cacheRate*100).toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Cache savings"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:y.cacheSavings<0?"text-[var(--accent-red)]":"text-[var(--accent-green)]",children:[(y.cacheSavings*100).toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{children:[Ee.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-2",children:"Latency"},void 0,!1,void 0,this),Ee.jsxDEV("div",{className:"space-y-1 text-[var(--text-secondary)]",children:[Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Avg duration"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:y.avgDuration?`${(y.avgDuration/1000).toFixed(2)}s`:"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Avg TTFT"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:y.avgTtft?`${(y.avgTtft/1000).toFixed(2)}s`:"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"h-[200px]",children:I.length===0?Ee.jsxDEV(Fm,{},void 0,!1,void 0,this):Ee.jsxDEV(wz,{data:I,color:w,chartTheme:g,timeRange:s},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},T,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wz({data:a,color:n,chartTheme:s,timeRange:i}){let l=Tn.useMemo(()=>({labels:a.map((d)=>Lf(d.timestamp,i)),datasets:[{label:"TTFT",data:a.map((d)=>d.avgTtftSeconds??null),...Ws("#5ad8e6"),yAxisID:"y"},{label:"Tokens/s",data:a.map((d)=>d.avgTokensPerSecond??null),...Ws(n),yAxisID:"y1"}]}),[a,n,i]),u=Tn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:Om(s),scales:hA(s)}),[s]);return Ee.jsxDEV(Xa,{data:l,options:u},void 0,!1,void 0,this)}var Tf=Q(dt(),1);var UA=Q(dt(),1);var vo=Q(de(),1),Wm={main:{label:"Main agent",color:"#ed4abf"},subagent:{label:"Subagents",color:"#9b4dff"},advisor:{label:"Advisor",color:"#5ad8e6"}};function FA({stats:a}){let n=UA.useMemo(()=>yA(a),[a]);if(n.totalTokens===0)return vo.jsxDEV("div",{className:"py-8 text-center stats-text-muted text-sm",children:"No token usage in this range"},void 0,!1,void 0,this);return vo.jsxDEV("div",{className:"space-y-4",children:[vo.jsxDEV("div",{className:"flex h-3 w-full overflow-hidden rounded-full",style:{background:"var(--surface-2)"},children:n.segments.map((s)=>s.share>0&&vo.jsxDEV("div",{className:"h-full",style:{width:`${s.share*100}%`,background:Wm[s.agentType].color},title:`${Wm[s.agentType].label}: ${Ht(s.share)}`},s.agentType,!1,void 0,this))},void 0,!1,void 0,this),vo.jsxDEV("div",{className:"space-y-2",children:n.segments.map((s)=>vo.jsxDEV("div",{className:"flex items-center justify-between gap-3 text-sm",children:[vo.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[vo.jsxDEV("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:Wm[s.agentType].color}},void 0,!1,void 0,this),vo.jsxDEV("span",{className:"stats-text-primary truncate",children:Wm[s.agentType].label},void 0,!1,void 0,this),vo.jsxDEV("span",{className:"stats-text-muted stats-text-xs whitespace-nowrap",children:[Ce(s.requests)," req"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),vo.jsxDEV("div",{className:"flex items-center gap-3 whitespace-nowrap",children:[vo.jsxDEV("span",{className:"stats-text-secondary",children:[lt(s.tokens)," tok"]},void 0,!0,void 0,this),vo.jsxDEV("span",{className:"stats-font-semibold stats-text-primary tabular-nums",children:Ht(s.share)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},s.agentType,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ve=Q(de(),1);function qA({active:a,range:n,refreshTrigger:s,onRequestClick:i}){let{data:l,error:u,loading:d}=Vt(["overview",n,s],(A)=>II(n,A),{pollMs:30000,enabled:a}),{data:p,error:h,loading:g}=Vt(["recent-requests",s],(A)=>Rm(50,A),{pollMs:30000,enabled:a}),b=$t(),y=sa[b],v=Tf.useMemo(()=>{if(!l?.timeSeries)return{labels:[],datasets:[]};let A=l.timeSeries.map((z)=>Cn(new Date(z.timestamp),n==="1h"||n==="24h"?"HH:mm":"MMM d")),B=l.timeSeries.length<=2?3:0;return{labels:A,datasets:[{label:"Requests",data:l.timeSeries.map((z)=>z.requests),borderColor:"#5ad8e6",backgroundColor:"rgba(90, 216, 230, 0.12)",tension:0.2,borderWidth:2,pointRadius:B,pointHoverRadius:4,fill:!0},{label:"Errors",data:l.timeSeries.map((z)=>z.errors),borderColor:"#ff6b7d",backgroundColor:"rgba(255, 107, 125, 0.12)",tension:0.2,borderWidth:2,pointRadius:B,pointHoverRadius:4,fill:!0}]}},[l?.timeSeries,n]),T=Tf.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{display:!0,position:"top",align:"end",labels:{color:y.legendLabel,boxWidth:8,usePointStyle:!0,font:{size:11}}},tooltip:{backgroundColor:y.tooltipBackground,titleColor:y.tooltipTitle,bodyColor:y.tooltipBody,borderColor:y.tooltipBorder,borderWidth:1,cornerRadius:8,padding:10}},scales:{x:{grid:{color:y.grid,drawBorder:!1},ticks:{color:y.tick,font:{size:10}}},y:{grid:{color:y.grid,drawBorder:!1},ticks:{color:y.tick,font:{size:10}},min:0}}}),[y]),M=Tf.useMemo(()=>[{key:"model",header:"Model",render:(A)=>ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:A.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(A)=>za(A.timestamp)},{key:"tokens",header:"Tokens",numeric:!0,render:(A)=>Ce(A.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(A)=>ln(A,4)},{key:"duration",header:"Duration",numeric:!0,render:(A)=>rt(A.duration)},{key:"status",header:"Status",className:"stats-text-center",render:(A)=>ve.jsxDEV(ya,{variant:A.errorMessage?"danger":"success",children:A.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)}],[]),I=(A,B)=>ve.jsxDEV("div",{className:"stats-mobile-card",onClick:B,children:[ve.jsxDEV("div",{className:"stats-mobile-card-header",children:[ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:A.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV(ya,{variant:A.errorMessage?"danger":"success",children:A.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-grid",children:[ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:za(A.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(A,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(A.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(A.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A.errorMessage&&ve.jsxDEV("div",{className:"stats-mobile-card-error truncate mt-2",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w=Tf.useMemo(()=>{if(!p)return[];return p.slice(0,10)},[p]);return ve.jsxDEV("div",{className:"stats-route-container space-y-6",children:[ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:l&&ve.jsxDEV(wA,{stats:l.overall},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV(ut,{title:"Conversation Tokens by Agent",subtitle:"Uncached input + cache reads + cache writes + output, grouped by agent type",children:ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:l&&ve.jsxDEV(FA,{stats:l.byAgentType},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[ve.jsxDEV("div",{className:"lg:col-span-2",children:ve.jsxDEV(ut,{title:"System Throughput",subtitle:"Request volume and errors over time",children:ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:ve.jsxDEV("div",{className:"h-[280px]",children:l?.timeSeries&&l.timeSeries.length>0?ve.jsxDEV(Xa,{data:v,options:T},void 0,!1,void 0,this):ve.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No time-series data available"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV("div",{children:ve.jsxDEV(ut,{title:"Operational Feed",subtitle:"Real-time request log",children:ve.jsxDEV(Rt,{loading:g,error:h,data:p,fallback:ve.jsxDEV("div",{className:"space-y-4",children:Array.from({length:5}).map((A,B)=>ve.jsxDEV("div",{className:"flex items-center gap-3",children:[ve.jsxDEV(Ua,{variant:"circle",width:10,height:10},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"flex-1",children:[ve.jsxDEV(Ua,{variant:"text",width:"60%",height:16},void 0,!1,void 0,this),ve.jsxDEV(Ua,{variant:"text",width:"40%",height:12},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},B,!0,void 0,this))},void 0,!1,void 0,this),children:ve.jsxDEV("div",{className:"stats-feed-ledger overflow-y-auto max-h-[280px] pr-2",children:[w.map((A)=>{let B=!!A.errorMessage;return ve.jsxDEV("div",{className:"stats-feed-item flex items-start gap-3 p-2 rounded hover:bg-stats-surface-2 cursor-pointer transition-colors",onClick:()=>A.id&&i(A.id),children:[ve.jsxDEV("div",{className:`w-2 h-2 mt-1.5 rounded-full flex-shrink-0 ${B?"bg-stats-danger":"bg-stats-success"}`},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"flex-1 min-w-0",children:[ve.jsxDEV("div",{className:"flex justify-between items-baseline gap-2",children:[ve.jsxDEV("div",{className:"stats-font-medium stats-text-primary text-sm truncate",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted whitespace-nowrap",children:za(A.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{className:"flex justify-between items-center text-xs stats-text-muted mt-0.5",children:[ve.jsxDEV("div",{children:A.provider},void 0,!1,void 0,this),ve.jsxDEV("div",{children:[A.duration?rt(A.duration):""," ",A.usage.totalTokens>0?`· ${ln(A,4)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B&&ve.jsxDEV("div",{className:"text-xs text-stats-danger truncate mt-1",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},A.id||`${A.sessionFile}-${A.entryId}`,!0,void 0,this)}),w.length===0&&ve.jsxDEV("div",{className:"py-8 text-center stats-text-muted text-sm",children:"No recent requests found"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV(ut,{title:"Recent Requests Preview",subtitle:"Latest transactions processed by the proxy",actions:ve.jsxDEV("a",{href:`#/requests?range=${n}`,className:"stats-button stats-button-secondary text-xs",children:"View All Requests"},void 0,!1,void 0,this),children:ve.jsxDEV(Rt,{loading:g,error:h,data:p,children:ve.jsxDEV(Ma,{columns:M,data:w,keyExtractor:(A)=>A.id||`${A.sessionFile}-${A.entryId}`,onRowClick:(A)=>A.id&&i(A.id),renderMobileCard:I,emptyText:"No recent requests found"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var a0=Q(dt(),1);var ot=Q(de(),1);function VA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["projects",n,s],(g)=>PI(n,g),{pollMs:30000,enabled:a}),d=a0.useMemo(()=>{if(!i)return[];return SA(i)},[i]),p=a0.useMemo(()=>[{key:"folder",header:"Project/Folder",render:(g)=>ot.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate max-w-[440px]",title:g.folder||"(root)",children:g.folder||"(root)"},void 0,!1,void 0,this)},{key:"totalRequests",header:"Requests",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"stats-text-right",children:[ot.jsxDEV("div",{className:"font-mono",children:Ce(g.totalRequests)},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:ot.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"link",style:{width:`${g.requestsPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"totalCost",header:"API-equivalent estimate",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"stats-text-right",children:[ot.jsxDEV("div",{className:"font-mono",children:ka(g.totalCost,g.unpricedRequests)},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:ot.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"success",style:{width:`${g.costPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"totalTokens",header:"Tokens",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"font-mono",children:Ce(g.totalInputTokens+g.totalOutputTokens)},void 0,!1,void 0,this)},{key:"cacheRate",header:"Cache Rate",numeric:!0,render:(g)=>ot.jsxDEV("span",{className:"font-mono",children:Ht(g.cacheRate)},void 0,!1,void 0,this)},{key:"cacheSavings",header:"Cache Savings",numeric:!0,render:(g)=>ot.jsxDEV("span",{className:`${g.cacheSavings<0?"stats-text-danger":"stats-text-success"} font-medium`,children:Ht(g.cacheSavings)},void 0,!1,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(g)=>ot.jsxDEV(ya,{variant:g.errorRate>0.1?"danger":g.errorRate>0?"warning":"success",children:Ht(g.errorRate)},void 0,!1,void 0,this)},{key:"avgDuration",header:"Avg Duration",numeric:!0,render:(g)=>rt(g.avgDuration)}],[]);return ot.jsxDEV("div",{className:"stats-route-container",children:ot.jsxDEV(ut,{title:"Projects & Folders",subtitle:"Aggregate proxy metrics grouped by folder path",children:ot.jsxDEV(Rt,{loading:u,error:l,data:i,emptyText:"No project folders recorded for this range.",children:ot.jsxDEV(Ma,{columns:p,data:d,keyExtractor:(g)=>g.folder,renderMobileCard:(g)=>ot.jsxDEV("div",{className:"stats-mobile-card",children:[ot.jsxDEV("div",{className:"stats-mobile-card-header mb-2",children:[ot.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:g.folder||"(root)"},void 0,!1,void 0,this),ot.jsxDEV(ya,{variant:g.errorRate>0.1?"danger":g.errorRate>0?"warning":"success",children:[Ht(g.errorRate)," Err"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-grid",children:[ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Requests"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:Ce(g.totalRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:ka(g.totalCost,g.unpricedRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cache Rate"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:Ht(g.cacheRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cache Savings"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:Ht(g.cacheSavings)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(g.avgDuration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),emptyText:"No project folders recorded for this range."},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Ia=Q(dt(),1);var $e=Q(de(),1);function jA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["providers",n,s],(d)=>zI(n,d),{pollMs:30000,enabled:a});return $e.jsxDEV("div",{className:"stats-route-container space-y-6",children:$e.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&$e.jsxDEV($e.Fragment,{children:[$e.jsxDEV(kz,{providers:i.providers},void 0,!1,void 0,this),$e.jsxDEV(Mz,{stats:i},void 0,!1,void 0,this),$e.jsxDEV(Iz,{hourly:i.hourly,providers:i.providers},void 0,!1,void 0,this),$e.jsxDEV(Az,{insights:i.windowInsights},void 0,!1,void 0,this),$e.jsxDEV(Rz,{usageSeries:i.usageSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function kz({providers:a}){let n=Ia.useMemo(()=>a.reduce((l,u)=>l+u.totalTokens,0),[a]),s=Ia.useMemo(()=>a.reduce((l,u)=>l+u.unpricedRequests,0),[a]),i=[{key:"provider",header:"Provider",render:(l)=>$e.jsxDEV("span",{className:"font-medium",children:l.provider},void 0,!1,void 0,this)},{key:"requests",header:"Requests",numeric:!0,render:(l)=>Ce(l.totalRequests)},{key:"errors",header:"Error Rate",numeric:!0,render:(l)=>Ht(l.totalRequests>0?l.failedRequests/l.totalRequests:0)},{key:"models",header:"Models",numeric:!0,render:(l)=>Ce(l.models)},{key:"tokens",header:"Tokens",numeric:!0,render:(l)=>$e.jsxDEV("span",{title:`Input ${lt(l.totalInputTokens)} · Output ${lt(l.totalOutputTokens)} · Cache read ${lt(l.totalCacheReadTokens)} · Cache write ${lt(l.totalCacheWriteTokens)}`,children:lt(l.totalTokens)},void 0,!1,void 0,this)},{key:"share",header:"Share",numeric:!0,render:(l)=>Ht(n>0?l.totalTokens/n:0)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(l)=>ka(l.totalCost,l.unpricedRequests)},{key:"tps",header:"Tok/s",numeric:!0,render:(l)=>qm(l.avgTokensPerSecond)}];return $e.jsxDEV(ut,{title:"Provider Totals",subtitle:s>0?`Token, request, and API-equivalent estimates; excludes ${s.toLocaleString()} unpriced subscription request${s===1?"":"s"}`:"Token, request, and API-equivalent estimates over the active range",children:$e.jsxDEV(Ma,{columns:i,data:a,keyExtractor:(l)=>l.provider,emptyText:"No requests recorded in this range"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Mz({stats:a}){let[n,s]=Ia.useState("tokens"),i=$t(),l=sa[i],u=Ia.useMemo(()=>a.providers.reduce((b,y)=>b+y.unpricedRequests,0),[a.providers]),d=Ia.useMemo(()=>{let b=a.series.map((y)=>({...y,model:y.provider}));return ju(b,{topN:6,rankWeight:(y)=>n==="tokens"?y.totalTokens:y.cost,initBucket:()=>({total:0}),accumulate:(y,v)=>{y.total+=n==="tokens"?v.totalTokens:v.cost},bucketToValue:(y)=>y.total})},[a.series,n]),p=n==="tokens"?lt:(b)=>us(b),h=Ia.useMemo(()=>{let{sharedScaleBase:b,yScale:y}=ls({chartTheme:l,formatY:p});return{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:is({chartTheme:l,showLegend:!0,defaultLabel:n==="tokens"?"Tokens":"API-equivalent estimate",formatValue:p,footer:(v)=>{if(v.length<2)return;let T=v.reduce((M,I)=>M+(I.parsed.y??0),0);return`Total: ${p(T)}`}}),scales:{x:{...b,stacked:!0},y:{...y,stacked:!0}}}},[l,n,p]),g=Ia.useMemo(()=>({labels:d.labels,datasets:ui(d,(b)=>Sl(bt[b%bt.length]))}),[d]);return $e.jsxDEV(ut,{title:"Burn by Provider",subtitle:n==="cost"&&u>0?`API-equivalent estimates over time; excludes ${u.toLocaleString()} unpriced subscription request${u===1?"":"s"}`:"Stacked token or API-equivalent estimate burn over time",actions:$e.jsxDEV(Zs,{options:[{value:"tokens",label:"Tokens"},{value:"cost",label:"API-equivalent estimate"}],value:n,onChange:s},void 0,!1,void 0,this),children:$e.jsxDEV("div",{className:"h-[300px]",children:d.labels.length===0?$e.jsxDEV(Gu,{message:"No provider activity in this range"},void 0,!1,void 0,this):$e.jsxDEV(li,{data:g,options:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var o0="__all__";function Iz({hourly:a,providers:n}){let[s,i]=Ia.useState(o0),l=$t(),u=sa[l],{tokensByHour:d,peakHour:p}=Ia.useMemo(()=>{let y=Array(24).fill(0);for(let T of a){if(s!==o0&&T.provider!==s)continue;y[T.hour]+=T.totalTokens}let v=0;for(let T=1;T<24;T++)if(y[T]>y[v])v=T;return{tokensByHour:y,peakHour:v}},[a,s]),h=d.some((y)=>y>0),g=Ia.useMemo(()=>({labels:Array.from({length:24},(y,v)=>`${String(v).padStart(2,"0")}:00`),datasets:[{label:"Tokens",data:d,...Sl(bt[2]),backgroundColor:d.map((y,v)=>v===p?bt[0]:bt[2])}]}),[d,p]),b=Ia.useMemo(()=>{let{sharedScaleBase:y,yScale:v}=ls({chartTheme:u,formatY:lt});return{responsive:!0,maintainAspectRatio:!1,plugins:is({chartTheme:u,showLegend:!1,defaultLabel:"Tokens",formatValue:lt}),scales:{x:y,y:v}}},[u]);return $e.jsxDEV(ut,{title:"Peak Burn Hours",subtitle:h?`Token burn by local hour of day — peak at ${String(p).padStart(2,"0")}:00`:"Token burn by local hour of day",actions:$e.jsxDEV("select",{className:"stats-select",value:s,onChange:(y)=>i(y.target.value),"aria-label":"Provider",children:[$e.jsxDEV("option",{value:o0,children:"All providers"},void 0,!1,void 0,this),n.map((y)=>$e.jsxDEV("option",{value:y.provider,children:y.provider},y.provider,!1,void 0,this))]},void 0,!0,void 0,this),children:$e.jsxDEV("div",{className:"h-[260px]",children:h?$e.jsxDEV(li,{data:g,options:b},void 0,!1,void 0,this):$e.jsxDEV(Gu,{message:"No activity in this range"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Az({insights:a}){return $e.jsxDEV(ut,{title:"Subscription Windows",subtitle:"What each usage window buys you, and how many accounts peak demand needs",children:$e.jsxDEV(Ma,{columns:[{key:"provider",header:"Provider",render:(s)=>$e.jsxDEV("span",{className:"font-medium",children:s.provider},void 0,!1,void 0,this)},{key:"window",header:"Window",render:(s)=>s.windowLabel},{key:"accounts",header:"Accounts",numeric:!0,render:(s)=>Ce(s.accounts)},{key:"consumed",header:"Windows Burned",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Subscription-window equivalents consumed in range (sum of used-fraction increases across accounts)",children:s.fractionConsumed.toFixed(2)},void 0,!1,void 0,this)},{key:"capacity",header:"Est. Tokens / Window",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Provider tokens burned in range ÷ windows burned — what one full window is worth",children:s.estTokensPerWindow!==null?lt(s.estTokensPerWindow):"—"},void 0,!1,void 0,this)},{key:"peak",header:"Peak Utilization",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Peak of summed used fraction across accounts at any sampled instant",children:Ht(s.peakConcurrentFraction)},void 0,!1,void 0,this)},{key:"ideal",header:"Ideal Accounts",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Accounts needed to keep peak demand under 90% of fleet capacity",className:s.idealAccounts>s.accounts?"stats-text-warning font-semibold":void 0,children:[Ce(s.idealAccounts),s.idealAccounts>s.accounts?` (have ${s.accounts})`:""]},void 0,!0,void 0,this)},{key:"exhausted",header:"Exhaustions",numeric:!0,render:(s)=>$e.jsxDEV("span",{className:s.exhaustedEvents>0?"stats-text-warning":void 0,children:Ce(s.exhaustedEvents)},void 0,!1,void 0,this)}],data:a,keyExtractor:(s)=>`${s.provider}::${s.windowKey}`,emptyText:"No usage snapshots recorded yet — they accumulate whenever usage is fetched (TUI footer, /usage, omp usage)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var n0={ok:"#62d394",warning:"#f5c14b",exhausted:"#ff6b7d"};function Rz({usageSeries:a}){let n=Ia.useMemo(()=>[...new Set(a.map((b)=>b.provider))],[a]),[s,i]=Ia.useState(null),l=s!==null&&n.includes(s)?s:n[0]??null,u=$t(),d=sa[u],p=Ia.useMemo(()=>a.filter((b)=>b.provider===l).map((b)=>{let y=[...b.points].reverse().find((v)=>v.usedFraction!==null);return y?{label:`${b.windowLabel} · ${b.accountLabel}`,fraction:y.usedFraction??0,exhausted:y.exhausted,recordedAt:y.timestamp}:null}).filter((b)=>b!==null).sort((b,y)=>y.fraction-b.fraction),[a,l]),h=Ia.useMemo(()=>({labels:p.map((b)=>b.label),datasets:[{label:"Used",data:p.map((b)=>b.fraction*100),backgroundColor:p.map((b)=>b.exhausted?n0.exhausted:b.fraction>=0.8?n0.warning:n0.ok),borderWidth:0,borderRadius:4,barThickness:18}]}),[p]),g=Ia.useMemo(()=>{let{sharedScaleBase:b,yScale:y}=ls({chartTheme:d,formatY:(M)=>`${Math.round(M)}%`}),v=Math.max(100,...p.map((M)=>M.fraction*100)),T=is({chartTheme:d,showLegend:!1,defaultLabel:"Used",formatValue:(M)=>`${M.toFixed(1)}%`});return{indexAxis:"y",responsive:!0,maintainAspectRatio:!1,plugins:{...T,tooltip:{...T.tooltip,callbacks:{label:(M)=>{let I=p[M.dataIndex],w=`${(M.parsed.x??0).toFixed(1)}% used`;return I?`${w} · recorded ${za(I.recordedAt)}`:w}}}},scales:{x:{...y,max:v},y:{...b,grid:{display:!1}}}}},[d,p]);return $e.jsxDEV(ut,{title:"Window Utilization",subtitle:"Latest recorded limit utilization per account and window — red bars are exhausted, amber above 80%",actions:n.length>1?$e.jsxDEV("select",{className:"stats-select",value:l??"",onChange:(b)=>i(b.target.value),"aria-label":"Provider",children:n.map((b)=>$e.jsxDEV("option",{value:b,children:b},b,!1,void 0,this))},void 0,!1,void 0,this):void 0,children:$e.jsxDEV("div",{style:{height:Math.max(160,p.length*34+60)},children:p.length===0?$e.jsxDEV(Gu,{message:"No usage snapshots recorded yet — they accumulate whenever usage is fetched"},void 0,!1,void 0,this):$e.jsxDEV(li,{data:h,options:g},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var GA=Q(dt(),1);var Tt=Q(de(),1);function XA({active:a,refreshTrigger:n,onRequestClick:s}){let{data:i,error:l,loading:u}=Vt(["recent-requests-dense",n],(h)=>Rm(50,h),{pollMs:30000,enabled:a}),d=GA.useMemo(()=>[{key:"model",header:"Model",render:(h)=>Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:h.model},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:h.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(h)=>za(h.timestamp)},{key:"tokens",header:"Tokens",numeric:!0,render:(h)=>Ce(h.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(h)=>ln(h,4)},{key:"duration",header:"Duration",numeric:!0,render:(h)=>rt(h.duration)},{key:"status",header:"Status",className:"stats-text-center",render:(h)=>Tt.jsxDEV(ya,{variant:h.errorMessage?"danger":"success",children:h.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)}],[]);return Tt.jsxDEV("div",{className:"stats-route-container",children:Tt.jsxDEV(ut,{title:"All Recent Requests",subtitle:"Up to 50 most recent requests processed by OMP",children:Tt.jsxDEV(Rt,{loading:u,error:l,data:i,children:Tt.jsxDEV(Ma,{columns:d,data:i||[],keyExtractor:(h)=>h.id||`${h.sessionFile}-${h.entryId}`,onRowClick:(h)=>h.id&&s(h.id),renderMobileCard:(h,g)=>Tt.jsxDEV("div",{className:"stats-mobile-card",onClick:g,children:[Tt.jsxDEV("div",{className:"stats-mobile-card-header",children:[Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:h.model},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:h.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(ya,{variant:h.errorMessage?"danger":"success",children:h.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-grid",children:[Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:za(h.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(h,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(h.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(h.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h.errorMessage&&Tt.jsxDEV("div",{className:"stats-mobile-card-error truncate mt-2",children:h.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),emptyText:"No recent requests found"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var cn=Q(dt(),1);var re=Q(de(),1);function YA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["tools",n,s],(d)=>NI(n,d),{pollMs:30000,enabled:a});return re.jsxDEV("div",{className:"stats-route-container space-y-6",children:re.jsxDEV(Rt,{loading:u,error:l,data:i,emptyText:"No tool calls recorded for this range.",children:i&&re.jsxDEV(re.Fragment,{children:[re.jsxDEV(_z,{byTool:i.byTool},void 0,!1,void 0,this),re.jsxDEV(Oz,{series:i.series,timeRange:n},void 0,!1,void 0,this),re.jsxDEV(Pz,{byTool:i.byTool},void 0,!1,void 0,this),re.jsxDEV(Bz,{byToolModel:i.byToolModel},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function _z({byTool:a}){let n=cn.useMemo(()=>{let s=0,i=0,l=0,u=0,d=0,p=0,h=0,g=0;for(let b of a)s+=b.calls,i+=b.errors,l+=b.totalTokensShare,u+=b.outputTokensShare,d+=b.costShare,p+=b.unpricedRequestsShare,h+=b.resultChars,g+=b.argsChars;return{calls:s,errors:i,tokens:l,output:u,cost:d,unpricedRequests:p,resultChars:h,argsChars:g,tools:a.length}},[a]);return re.jsxDEV(ut,{title:"Tool Usage",subtitle:"Tokens and API-equivalent estimates are split from invoking turns across each turn's tool calls",children:re.jsxDEV("div",{className:"stats-metric-cluster",children:[re.jsxDEV("div",{className:"stats-metric-primary-grid",children:[re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Tool Calls"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ce(n.calls)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Tools Used"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ce(n.tools)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Error Rate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ht(n.calls>0?n.errors/n.calls:0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed API-equivalent estimate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:ka(n.cost,n.unpricedRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-secondary-grid",children:[re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed Tokens"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:lt(Math.round(n.tokens))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed Output"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:lt(Math.round(n.output))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Result Text"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:[lt(n.resultChars)," chars"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Call Arguments"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:[lt(n.argsChars)," chars"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var Dz=6;function Ez(a){let n=new Map;for(let g of a)n.set(g.tool,(n.get(g.tool)??0)+g.calls);let s=[...n.entries()].sort((g,b)=>b[1]-g[1]),i=s.slice(0,Dz).map(([g])=>g),l=new Set(i),d=s.length>i.length?[...i,"Other"]:i,p=[...new Set(a.map((g)=>g.timestamp))].sort((g,b)=>g-b),h=new Map;for(let g of p)h.set(g,{});for(let g of a){let b=l.has(g.tool)?g.tool:"Other",y=h.get(g.timestamp);if(y)y[b]=(y[b]??0)+g.calls}return{buckets:p,tools:d,data:h}}function Oz({series:a,timeRange:n}){let s=$t(),i=sa[s],l=Ll(n),u=cn.useMemo(()=>Ez(a),[a]),d=cn.useMemo(()=>({labels:u.buckets.map((h)=>Lf(h,n)),datasets:u.tools.map((h,g)=>({label:h,data:u.buckets.map((b)=>u.data.get(b)?.[h]??0),borderColor:bt[g%bt.length],backgroundColor:`${bt[g%bt.length]}30`,fill:!0,tension:0.4,pointRadius:0,pointHoverRadius:4,borderWidth:2}))}),[u,n]),p=cn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{position:"top",align:"start",labels:{color:i.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:i.tooltipBackground,titleColor:i.tooltipTitle,bodyColor:i.tooltipBody,borderColor:i.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(h)=>`${h.dataset.label??""}: ${Ce(h.parsed.y??0)} calls`}}},scales:{x:{stacked:!0,grid:{color:i.grid,drawBorder:!1},ticks:{color:i.tick,font:{size:11}}},y:{stacked:!0,grid:{color:i.grid,drawBorder:!1},ticks:{color:i.tick,font:{size:11},precision:0},min:0}}}),[i]);return re.jsxDEV(ut,{title:"Calls Over Time",subtitle:`Tool calls over ${l.windowLabel}, stacked by tool`,children:re.jsxDEV("div",{className:"h-[280px]",children:u.buckets.length===0?re.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No data available"},void 0,!1,void 0,this):re.jsxDEV(Xa,{data:d,options:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function s0(a){return a>0.1?"danger":a>0?"warning":"success"}function Pz({byTool:a}){let n=cn.useMemo(()=>LA(a),[a]),s=cn.useMemo(()=>[{key:"tool",header:"Tool",render:(l)=>re.jsxDEV("div",{className:"stats-font-medium stats-text-primary font-mono truncate max-w-[280px]",title:l.tool,children:l.tool},void 0,!1,void 0,this)},{key:"calls",header:"Calls",numeric:!0,render:(l)=>re.jsxDEV("div",{className:"stats-text-right",children:[re.jsxDEV("div",{className:"font-mono",children:Ce(l.calls)},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:re.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"link",style:{width:`${l.callsPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(l)=>re.jsxDEV(ya,{variant:s0(l.errorRate),children:Ht(l.errorRate)},void 0,!1,void 0,this)},{key:"tokens",header:"Attr. Tokens",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",title:"Invoking turns' total tokens, split across each turn's calls",children:lt(Math.round(l.totalTokensShare))},void 0,!1,void 0,this)},{key:"cost",header:"Attr. API-equivalent estimate",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",children:ka(l.costShare,l.unpricedRequestsShare)},void 0,!1,void 0,this)},{key:"resultChars",header:"Result Text",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",title:"Characters of tool-result text fed back into context",children:lt(l.resultChars)},void 0,!1,void 0,this)},{key:"lastUsed",header:"Last Used",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"stats-text-secondary",children:za(l.lastUsed)},void 0,!1,void 0,this)}],[]);return re.jsxDEV(ut,{title:"By Tool",subtitle:"Usage per tool, most called first",children:re.jsxDEV(Ma,{columns:s,data:n,keyExtractor:(l)=>l.tool,renderMobileCard:(l)=>re.jsxDEV("div",{className:"stats-mobile-card",children:[re.jsxDEV("div",{className:"stats-mobile-card-header mb-2",children:[re.jsxDEV("div",{className:"stats-font-semibold stats-text-primary font-mono",children:l.tool},void 0,!1,void 0,this),re.jsxDEV(ya,{variant:s0(l.errorRate),children:[Ht(l.errorRate)," Err"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-grid",children:[re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Calls"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:Ce(l.calls)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Attr. Tokens"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:lt(Math.round(l.totalTokensShare))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Attr. API-equivalent estimate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:ka(l.costShare,l.unpricedRequestsShare)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Result Text"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:lt(l.resultChars)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),emptyText:"No tool calls recorded for this range."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Bz({byToolModel:a}){let[n,s]=cn.useState(null),i=cn.useMemo(()=>[...new Set(a.map((d)=>d.tool))].sort(),[a]),l=cn.useMemo(()=>(n?a.filter((p)=>p.tool===n):a).map((p)=>({...p,errorRate:p.calls>0?p.errors/p.calls:0})),[a,n]),u=cn.useMemo(()=>[{key:"tool",header:"Tool",render:(d)=>re.jsxDEV("span",{className:"stats-font-medium stats-text-primary font-mono",children:d.tool},void 0,!1,void 0,this)},{key:"model",header:"Model",render:(d)=>re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-text-primary",children:d.model||"(unknown)"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-text-secondary text-xs",children:d.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"calls",header:"Calls",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:Ce(d.calls)},void 0,!1,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(d)=>re.jsxDEV(ya,{variant:s0(d.errorRate),children:Ht(d.errorRate)},void 0,!1,void 0,this)},{key:"tokens",header:"Attr. Tokens",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:lt(Math.round(d.totalTokensShare))},void 0,!1,void 0,this)},{key:"cost",header:"Attr. API-equivalent estimate",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:ka(d.costShare,d.unpricedRequestsShare)},void 0,!1,void 0,this)}],[]);return re.jsxDEV(ut,{title:"By Model",subtitle:"Which models call which tools",children:[re.jsxDEV("div",{className:"mb-4",style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[re.jsxDEV("span",{className:"stats-text-secondary",style:{fontSize:"0.875rem",whiteSpace:"nowrap"},children:"Tool"},void 0,!1,void 0,this),re.jsxDEV("select",{className:"stats-select",value:n??"",onChange:(d)=>s(d.target.value||null),style:{maxWidth:"320px",flex:1},children:[re.jsxDEV("option",{value:"",children:"All tools"},void 0,!1,void 0,this),i.map((d)=>re.jsxDEV("option",{value:d,children:d},d,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV(Ma,{columns:u,data:l,keyExtractor:(d)=>`${d.tool}::${d.model}::${d.provider}`,emptyText:"No tool calls recorded for this range."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var If=Q(dt(),1);var wt=Q(dt(),1);var Zm=Q(dt(),1);var Qs=Q(de(),1);function $A({toolStats:a}){let[n,s]=Zm.useState(!1),i=Zm.useMemo(()=>[{key:"tool",header:"Tool",render:(l)=>l.tool},{key:"calls",header:"Calls",numeric:!0,render:(l)=>Ce(l.calls)},{key:"errors",header:"Errors",numeric:!0,render:(l)=>Ce(l.errors)},{key:"total",header:"Total",numeric:!0,render:(l)=>rt(l.totalMs)},{key:"avg",header:"Avg",numeric:!0,render:(l)=>rt(l.calls>0?l.totalMs/l.calls:0)},{key:"max",header:"Max",numeric:!0,render:(l)=>rt(l.maxMs)}],[]);if(a.length===0)return null;return Qs.jsxDEV("div",{className:"stats-panel",children:[Qs.jsxDEV("button",{type:"button",onClick:()=>s((l)=>!l),"aria-expanded":n,style:{display:"flex",alignItems:"center",gap:6,width:"100%",background:"none",border:"none",padding:"10px 14px",cursor:"pointer",textAlign:"left"},children:[n?Qs.jsxDEV(Ys,{size:14,className:"stats-text-muted","aria-hidden":"true"},void 0,!1,void 0,this):Qs.jsxDEV(hl,{size:14,className:"stats-text-muted","aria-hidden":"true"},void 0,!1,void 0,this),Qs.jsxDEV("span",{className:"stats-panel-title",children:"Tool Aggregates"},void 0,!1,void 0,this),Qs.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:11},children:[a.length," tools"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),n&&Qs.jsxDEV("div",{className:"stats-panel-body",children:Qs.jsxDEV(Ma,{columns:i,data:a,keyExtractor:(l)=>l.tool,emptyText:"No tool calls"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var wn=Q(dt(),1);var $u={dark:{category:{turn:"#34d399",model:"#a78bfa",tool:"#fbbf24",subagent:"#38bdf8",background:"#94a3b8"},error:"#f87171",marker:"#facc15",turnBand:"rgba(255, 255, 255, 0.035)",surface:"transparent",grid:"rgba(255, 255, 255, 0.06)",tick:"#867a93",spanText:"#16121c",selection:"#5ad8e6",tooltipBackground:"#241a2e",tooltipTitle:"#eae5ef",tooltipBody:"#a89fb3",tooltipBorder:"rgba(255, 255, 255, 0.12)"},light:{category:{turn:"#059669",model:"#7c3aed",tool:"#d97706",subagent:"#0284c7",background:"#64748b"},error:"#ef4444",marker:"#ca8a04",turnBand:"rgba(0, 0, 0, 0.04)",surface:"transparent",grid:"rgba(20, 12, 28, 0.08)",tick:"#6a6275",spanText:"#ffffff",selection:"#0e7490",tooltipBackground:"#ffffff",tooltipTitle:"#241a2e",tooltipBody:"#5a5462",tooltipBorder:"rgba(20, 12, 28, 0.15)"}};var QA=Q(de(),1),fi=44,r0=["turn","model","tool","subagent"],WA=6,Wu=10;function ZA({tracks:a,scale:n,viewport:s,onViewportChange:i}){let l=$t(),u=$u[l],d=wn.useRef(null),[p,h]=wn.useState(800),g=wn.useRef(null);wn.useEffect(()=>{let B=d.current;if(!B)return;let z=new ResizeObserver((H)=>{h(Math.max(100,Math.floor(H[0].contentRect.width)))});return z.observe(B),()=>z.disconnect()},[]);let[b,y]=n.domain,v=Math.max(y-b,0.000000001),T=wn.useCallback((B)=>(B-b)/v*p,[b,v,p]),M=wn.useCallback((B)=>b+B/Math.max(p,1)*v,[b,v,p]);wn.useEffect(()=>{let B=d.current;if(!B)return;let z=B.getContext("2d");if(!z)return;let H=devicePixelRatio;z.setTransform(H,0,0,H,0,0),z.clearRect(0,0,p,fi);let V=fi/r0.length;for(let Y=0;Y<r0.length;Y++){let J=r0[Y],j=new Float32Array(p);for(let se of a)for(let ge of se.spans){if(ge.kind!==J)continue;let ye=Math.max(0,Math.floor(T(n.toU(ge.start)))),Se=Math.min(p-1,Math.ceil(T(n.toU(ge.end))));for(let K=ye;K<=Se;K++)j[K]=Math.min(1,j[K]+0.34)}z.fillStyle=u.category[J];for(let se=0;se<p;se++){if(j[se]<=0)continue;z.globalAlpha=0.25+j[se]*0.75,z.fillRect(se,Y*V+1,1,V-2)}z.globalAlpha=1}let G=T(s.u0),X=T(s.u1);z.fillStyle=l==="dark"?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",z.fillRect(G,0,X-G,fi),z.strokeStyle=u.selection,z.strokeRect(G+0.5,0.5,X-G-1,fi-1),z.fillStyle=u.selection,z.fillRect(G,0,2,fi),z.fillRect(X-2,0,2,fi)},[a,n,s,u,l,p,T]);let I=(B)=>{let z=B.currentTarget.getBoundingClientRect(),H=B.clientX-z.left,V=T(s.u0),G=T(s.u1),X;if(Math.abs(H-V)<=WA)X="left";else if(Math.abs(H-G)<=WA)X="right";else if(H>V&&H<G)X="move";else{X="create";let Y=M(H);i(wf({u0:Y,u1:Y+Wu},b,y))}g.current={mode:X,startX:H,startViewport:s},B.currentTarget.setPointerCapture(B.pointerId)},w=(B)=>{let z=g.current;if(!z)return;let H=B.currentTarget.getBoundingClientRect(),V=B.clientX-H.left,G=M(V)-M(z.startX),{u0:X,u1:Y}=z.startViewport;if(z.mode==="move")i(wf({u0:X+G,u1:Y+G},b,y));else if(z.mode==="left")i(wf({u0:Math.min(X+G,Y-Wu),u1:Y},b,y));else if(z.mode==="right")i(wf({u0:X,u1:Math.max(Y+G,X+Wu)},b,y));else{let J=M(z.startX),j=M(V);i(wf({u0:Math.min(J,j),u1:Math.max(J,j,Math.min(J,j)+Wu)},b,y))}},A=()=>{g.current=null};return QA.jsxDEV("canvas",{ref:d,width:Math.floor(p*devicePixelRatio),height:Math.floor(fi*devicePixelRatio),style:{width:"100%",height:fi,display:"block",cursor:"crosshair",borderRadius:4,border:"1px solid var(--border)",touchAction:"none"},role:"slider","aria-label":"Timeline overview brush","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round((s.u0-b)/v*100),tabIndex:-1,onPointerDown:I,onPointerMove:w,onPointerUp:A},void 0,!1,void 0,this)}function wf(a,n,s){let i=Math.max(Wu,a.u1-a.u0);i=Math.min(i,s-n||Wu);let l=a.u0;if(l<n)l=n;if(l+i>s)l=s-i;return{u0:l,u1:l+i}}var kn=Q(dt(),1);var Te=Q(de(),1);function Nz(a){let n=[];if(typeof a==="string"){if(a.trim())n.push({kind:"text",text:a});return n}if(!Array.isArray(a))return n;for(let s of a){if(!s||typeof s!=="object"||!("type"in s))continue;if((s.type==="text"||s.type==="thinking")&&"text"in s&&typeof s.text==="string")n.push({kind:String(s.type),text:s.text})}return n}function KA({span:a,track:n,onClose:s,onOpenChildTrack:i}){let[l,u]=kn.useState(null),[d,p]=kn.useState(!1),[h,g]=kn.useState(null),[b,y]=kn.useState(!1),v=kn.useRef(null),T=kn.useRef(null);if(kn.useEffect(()=>{if(u(null),g(null),y(!1),!a||!n||!a.entryId)return;T.current=document.activeElement instanceof HTMLElement?document.activeElement:null,p(!0);let z=new AbortController;return FI(n.file,a.entryId,z.signal).then((H)=>{if(z.signal.aborted)return;u(H.entry),setTimeout(()=>v.current?.focus(),50)}).catch((H)=>{if(z.signal.aborted)return;g(H instanceof Error?H:Error(String(H)))}).finally(()=>{if(!z.signal.aborted)p(!1)}),()=>z.abort()},[a,n]),kn.useEffect(()=>{if(!a)return;let z=(H)=>{if(H.key==="Escape")s()};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z),T.current?.focus()}},[a,s]),!a)return null;let M=(z)=>{if(z.target===z.currentTarget)s()},I=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(l??a,null,2)),y(!0),setTimeout(()=>y(!1),1500)}catch{}},A=(l&&typeof l==="object"?l:{}).message,B=A?.usage;return Te.jsxDEV("div",{className:"stats-drawer-overlay",onClick:M,role:"presentation",children:Te.jsxDEV("div",{className:"stats-drawer",role:"dialog","aria-modal":"true","aria-label":"Span details",children:[Te.jsxDEV("div",{className:"stats-drawer-header",children:[Te.jsxDEV("div",{className:"stats-drawer-header-left",children:[Te.jsxDEV("h2",{className:"stats-drawer-title truncate",style:{maxWidth:320},children:a.label},void 0,!1,void 0,this),Te.jsxDEV(ya,{variant:a.isError?"danger":"success",children:a.kind},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{style:{display:"flex",gap:8},children:[Te.jsxDEV("button",{type:"button",onClick:I,className:"stats-drawer-close-btn","aria-label":"Copy raw JSON",title:"Copy raw JSON",children:b?Te.jsxDEV(pl,{size:16},void 0,!1,void 0,this):Te.jsxDEV(gl,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this),Te.jsxDEV("button",{ref:v,type:"button",onClick:s,className:"stats-drawer-close-btn","aria-label":"Close span details",children:Te.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-body",children:Te.jsxDEV("div",{className:"stats-drawer-content",children:[Te.jsxDEV("div",{className:"stats-drawer-metrics-grid",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Duration"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(a.end-a.start)},void 0,!1,void 0,this),a.unterminated&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:"unterminated"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Start"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",style:{fontSize:13},children:new Date(a.start).toLocaleTimeString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a.kind==="model"&&Te.jsxDEV(Te.Fragment,{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Tokens"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(a.tokens??0)},void 0,!1,void 0,this),B&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:[Ce(B.input??0)," in · ",Ce(B.output??0)," out ·"," ",Ce(B.cacheRead??0)," cached"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Cost"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:["$",(a.cost??0).toFixed(4)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"TTFT"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(a.ttft??null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Model"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",style:{fontSize:12},children:A?.model??a.model??"-"},void 0,!1,void 0,this),A?.provider&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:A.provider},void 0,!1,void 0,this),A?.stopReason&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:["stop: ",A.stopReason]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A?.errorMessage&&Te.jsxDEV("div",{className:"stats-drawer-error-block",children:[Te.jsxDEV("div",{className:"stats-drawer-error-label",children:"Error Message"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-error-text",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a.kind==="subagent"&&Te.jsxDEV("div",{children:[a.detail&&Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10},children:a.detail},void 0,!1,void 0,this),a.childTrackId&&i&&Te.jsxDEV("button",{type:"button",className:"stats-segmented-control-btn",style:{marginTop:8,border:"1px solid var(--border)",borderRadius:6},onClick:()=>i(a.childTrackId??""),children:["Open child track ",a.childTrackId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a.kind==="tool"&&a.detail&&Te.jsxDEV("div",{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Args"},void 0,!1,void 0,this),Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10},children:a.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&Te.jsxDEV("div",{children:[Te.jsxDEV(Ua,{variant:"rect",width:"100%",height:80,className:"mb-4"},void 0,!1,void 0,this),Te.jsxDEV(Ua,{variant:"rect",width:"100%",height:160},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h&&Te.jsxDEV("div",{className:"stats-drawer-error",children:[Te.jsxDEV("p",{className:"stats-drawer-error-title",children:"Failed to load entry"},void 0,!1,void 0,this),Te.jsxDEV("p",{className:"stats-drawer-error-message",children:h.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!d&&l!==null&&Nz(A?.content).map((z,H)=>Te.jsxDEV("div",{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",style:{textTransform:"capitalize"},children:z.kind},void 0,!1,void 0,this),Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10,maxHeight:360,overflowY:"auto"},children:z.text},void 0,!1,void 0,this)]},`${z.kind}-${H}`,!0,void 0,this)),!d&&l!==null&&Te.jsxDEV("div",{className:"stats-drawer-json-blocks",children:Te.jsxDEV(Cf,{data:l,title:"Raw Entry",initialCollapsed:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var kf=Q(de(),1);function JA({summary:a}){let n=[{label:"Wall",value:rt(a.wallMs)},{label:"Model",value:rt(a.modelMs)},{label:"Tools",value:rt(a.toolMs)},{label:"Idle",value:rt(a.idleMs)},{label:"Turns",value:Ce(a.turns)},{label:"Requests",value:Ce(a.requests)},{label:"Tool Calls",value:Ce(a.toolCalls)},{label:"Agents",value:Ce(a.subagents)},{label:"Tokens",value:lt(a.totalTokens)},{label:"Cost",value:us(a.costTotal)}];return kf.jsxDEV("div",{className:"stats-trace-summary",children:n.map((s)=>kf.jsxDEV("div",{className:"stats-trace-summary-cell",children:[kf.jsxDEV("span",{className:"stats-trace-summary-label",children:s.label},void 0,!1,void 0,this),kf.jsxDEV("span",{className:"stats-trace-summary-value",children:s.value},void 0,!1,void 0,this)]},s.label,!0,void 0,this))},void 0,!1,void 0,this)}var jt=Q(dt(),1);function Qm(a,n){let s=a.length,i=[n[0],n[s-1]],l=(u,d)=>{let p=0,h=s-1;while(p<h){let g=p+h+1>>1;if(u[g]<=d)p=g;else h=g-1}return Math.min(p,s-2)};return{toU(u){if(u<=a[0])return n[0];if(u>=a[s-1])return n[s-1];let d=l(a,u),p=a[d+1]-a[d];if(p<=0)return n[d];return n[d]+(u-a[d])/p*(n[d+1]-n[d])},toT(u){if(u<=n[0])return a[0];if(u>=n[s-1])return a[s-1];let d=l(n,u),p=n[d+1]-n[d];if(p<=0)return a[d];return a[d]+(u-n[d])/p*(a[d+1]-a[d])},domain:i,gaps:[]}}function zz(a){let n=[];for(let s of a)for(let i of s.spans)n.push([i.start,i.end]);return n.sort((s,i)=>s[0]-i[0]),n}function Hz(a){let{POSITIVE_INFINITY:n,NEGATIVE_INFINITY:s}=Number;for(let i of a)for(let l of i.spans){if(l.start<n)n=l.start;if(l.end>s)s=l.end}if(!Number.isFinite(n))return[0,1];return[n,Math.max(s,n+1)]}function eR(a,n,s){let i=[...new Set(a.filter((p)=>p>=n&&p<=s))].sort((p,h)=>p-h);if(i[0]!==n)i.unshift(n);if(i[i.length-1]!==s)i.push(s);if(i.length<2)return Qm([n,s],[n,s]);let u=(s-n)/(i.length-1),d=i.map((p,h)=>n+h*u);return Qm(i,d)}function Uz(a,n,s){let i=zz(a),l=[];for(let[b,y]of i){let v=b-2000,T=y+2000,M=l[l.length-1];if(M&&v<=M[1]){if(T>M[1])M[1]=T}else l.push([v,T])}if(l.length===0)l.push([n,s]);l[0][0]=Math.max(l[0][0],n),l[l.length-1][1]=Math.min(Math.max(l[l.length-1][1],l[l.length-1][0]),s);let u=[],d=[],p=[],h=l[0][0];for(let b=0;b<l.length;b++){let[y,v]=l[b];if(b===0)u.push(y),d.push(h);else{let T=l[b-1][1],M=y-T;if(M>30000)h+=8000,p.push({t0:T,t1:y,uMid:h-4000});else h+=M;u.push(y),d.push(h)}h+=Math.max(0,v-y),u.push(v),d.push(h)}return{...Qm(u,d),gaps:p}}function tR(a,n,s){let[i,l]=Hz(a);if(n==="turns"){let d=(a.find((p)=>p.id==="main")?.spans??[]).filter((p)=>p.kind==="turn").map((p)=>p.start);return eR(d,i,l)}if(n==="calls"){let u=[];for(let d of a)for(let p of d.spans)if(p.kind==="model"||p.kind==="tool"||p.kind==="background")u.push(p.start,p.end);return eR(u,i,l)}if(s)return Uz(a,i,l);return Qm([i,l],[i,l])}var Fz=90;function qz(a){let n=10**Math.floor(Math.log10(Math.max(a,1)));for(let s of[1,2,5,10])if(n*s>=a)return n*s;return n*10}function Vz(a){let n=new Date(a),s=String(n.getHours()).padStart(2,"0"),i=String(n.getMinutes()).padStart(2,"0"),l=String(n.getSeconds()).padStart(2,"0");return`${s}:${i}:${l}`}function Zu(a){let n=a<0?"-":"+",s=Math.abs(a),i=Math.floor(s/3600000),l=Math.floor(s%3600000/60000),u=Math.floor(s%60000/1000),d=Math.floor(s%1000),p=s%1000!==0,h=`${String(l).padStart(2,"0")}:${String(u).padStart(2,"0")}${p?".":""}${p?String(d).padStart(3,"0"):""}`;return i>0?`${n}${i}:${h}`:`${n}${h}`}function aR(a,n,s,i){let l=s-n;if(l<=0||i<=0)return[];let u=[],d=a.domain[0],p=qz(l*Fz/i),h=d+Math.ceil((n-d)/p)*p,g=0;for(let b=h;b<=s&&g<200;b+=p,g++){let y=a.toT(b),v=Math.round((b-d)/p)%5===0;u.push({u:b,label:v?Vz(y):Zu(b-d),major:v})}return u}var xt=Q(de(),1),Ks=28,l0=22,So=18,oR=3,jz=14,nR=200,i0=10,Gz=2,Xz=4,Yz=56,sR=3,$z=[{kind:"turn",label:"Input"},{kind:"model",label:"Model"},{kind:"tool",label:"Tools"},{kind:"subagent",label:"Agents"},{kind:"background",label:"Bg"}];function Wz(a,n){let s=new Map(a.map((h)=>[h.id,h])),i=new Set;for(let h of a)if(h.parentId)i.add(h.parentId);let l=(h)=>{let g=h.parentId;while(g){if(n.has(g))return!0;g=s.get(g)?.parentId??null}return!1},u=[],d=[],p=Ks+6;for(let h of a){if(l(h))continue;let g=h.id==="main"?0:h.id.split("/").length,b={track:h,depth:g,hasChildren:i.has(h.id),headerY:p,lanes:[],y0:p,y1:p};p+=l0;for(let{kind:y,label:v}of $z){let T=h.spans.filter((w)=>w.kind===y),M=y==="turn"||y==="model"||y==="tool";if(T.length===0&&!(h.id==="main"&&M))continue;let I={track:h,kind:y,label:v,y:p,spans:T};b.lanes.push(I),d.push(I),p+=So+oR}b.y1=p-oR,u.push(b),p+=jz}return{blocks:u,lanes:d,totalHeight:Math.max(p,Ks+48)}}function rR({tracks:a,scale:n,viewport:s,onViewportChange:i,selection:l,onSelect:u,search:d,collapsed:p,onToggleCollapse:h,traceStart:g}){let b=$t(),y=$u[b],v=jt.useRef(null),T=jt.useRef(null),[M,I]=jt.useState(800),[w,A]=jt.useState(null),B=jt.useRef([]),z=jt.useRef(null),H=jt.useRef(null),V=jt.useRef(s);V.current=s;let G=jt.useMemo(()=>Wz(a,p),[a,p]);jt.useEffect(()=>{let k=v.current;if(!k)return;let W=new ResizeObserver((ee)=>{let ne=Math.max(100,Math.floor(ee[0].contentRect.width-nR));I(ne)});return W.observe(k),()=>W.disconnect()},[]);let X=jt.useCallback((k,W)=>{let[ee,ne]=n.domain,te=Math.max(i0,W-k);te=Math.min(te,ne-ee||i0);let le=k;if(le<ee)le=ee;if(le+te>ne)le=ne-te;return{u0:le,u1:le+te}},[n]),Y=jt.useCallback((k)=>{V.current=k,i(k)},[i]),J=jt.useCallback((k,W)=>{let ee=M,{u0:ne,u1:te}=V.current,le=te-ne,fe=W===null?0.5:Math.min(1,Math.max(0,W/ee)),et=ne+le*fe,tt=le*k;Y(X(et-tt*fe,et+tt*(1-fe)))},[M,Y,X]),j=jt.useCallback((k)=>{let{u0:W,u1:ee}=V.current;Y(X(W+k,ee+k))},[Y,X]),se=jt.useCallback((k)=>{let W=n.toU(k.start),ee=n.toU(k.end),ne=Math.max((ee-W)*0.1,i0/2);Y(X(W-ne,ee+ne))},[n,Y,X]);jt.useEffect(()=>{let k=T.current;if(!k)return;let W=(ee)=>{ee.preventDefault();let ne=k.getBoundingClientRect(),te=ee.clientX-ne.left;H.current=te,A(null);let le=k.clientWidth||1,fe=()=>V.current.u1-V.current.u0;if(ee.shiftKey){let et=Math.abs(ee.deltaY)>=Math.abs(ee.deltaX)?ee.deltaY:ee.deltaX;j(et/le*fe());return}if(ee.deltaX!==0)j(ee.deltaX/le*fe());if(ee.deltaY!==0)J(1.0015**ee.deltaY,te)};return k.addEventListener("wheel",W,{passive:!1}),()=>k.removeEventListener("wheel",W)},[J,j]);let ge=jt.useCallback((k,W)=>{let ee=T.current;if(!ee)return null;let ne=ee.getBoundingClientRect(),te=k-ne.left,le=W-ne.top,fe=B.current;for(let et=fe.length-1;et>=0;et--){let tt=fe[et];if(te>=tt.x&&te<=tt.x+tt.w&&le>=tt.y&&le<=tt.y+tt.h)return tt}return null},[]),ye=(k)=>{k.currentTarget.setPointerCapture(k.pointerId),z.current={pointerId:k.pointerId,lastX:k.clientX,moved:!1},k.currentTarget.focus()},Se=(k)=>{let W=k.currentTarget.getBoundingClientRect();H.current=k.clientX-W.left;let ee=z.current;if(ee&&ee.pointerId===k.pointerId){let te=k.clientX-ee.lastX;if(Math.abs(te)>0){if(Math.abs(te)>2)ee.moved=!0;ee.lastX=k.clientX;let le=V.current.u1-V.current.u0;j(-te/(M||1)*le)}A(null);return}let ne=ge(k.clientX,k.clientY);A(ne?{hit:ne,clientX:k.clientX,clientY:k.clientY}:null)},K=(k)=>{let W=z.current;if(z.current=null,W?.moved)return;let ee=ge(k.clientX,k.clientY);if(ee?.kind==="span")u(ee.span.id);else u(null)},pe=(k)=>{let W=ge(k.clientX,k.clientY);if(W?.kind==="span")se(W.span)},be=jt.useCallback((k)=>{if(!l)return;for(let W of G.lanes){let ee=W.spans.findIndex((le)=>le.id===l);if(ee===-1)continue;let ne=W.spans[ee+k];if(!ne)return;u(ne.id);let te=n.toU(ne.start);if(te<s.u0||te>s.u1){let le=s.u1-s.u0;i(X(te-le/2,te+le/2))}return}},[l,G,u,n,s,i,X]),Ue=(k)=>{let W=s.u1-s.u0;switch(k.key){case"w":case"W":J(0.7692307692307692,H.current);break;case"s":case"S":J(1.3,H.current);break;case"a":case"A":j(-W*0.2);break;case"d":case"D":j(W*0.2);break;case"0":i({u0:n.domain[0],u1:n.domain[1]});break;case"f":case"F":{if(!l)break;let ee=a.flatMap((ne)=>ne.spans).find((ne)=>ne.id===l);if(ee)se(ee);break}case"Escape":u(null);break;case",":be(-1);break;case".":be(1);break;default:return}k.preventDefault()};jt.useEffect(()=>{T.current?.focus({preventScroll:!0})},[]),jt.useEffect(()=>{let k=T.current;if(!k)return;let W=requestAnimationFrame(()=>{Zz(k,G,n,s,y,{width:M,selection:l,hoverId:w?.hit.kind==="span"?w.hit.span.id:null,search:d,hits:B})});return()=>cancelAnimationFrame(W)},[G,n,s,y,M,l,w,d]);let He=w?Qz(w,g):null;return xt.jsxDEV("div",{ref:v,className:"stats-trace-timeline",children:[xt.jsxDEV("div",{style:{width:nR,flexShrink:0,position:"relative",height:G.totalHeight},children:G.blocks.map((k)=>xt.jsxDEV("div",{children:[xt.jsxDEV("div",{style:{position:"absolute",top:k.headerY,left:4+k.depth*14,right:8,height:l0,display:"flex",alignItems:"center",gap:5,minWidth:0},children:[k.hasChildren?xt.jsxDEV("button",{type:"button",onClick:()=>h(k.track.id),"aria-label":p.has(k.track.id)?`Expand ${k.track.label}`:`Collapse ${k.track.label}`,className:"stats-trace-chevron",children:p.has(k.track.id)?xt.jsxDEV(hl,{size:12},void 0,!1,void 0,this):xt.jsxDEV(Ys,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this):xt.jsxDEV("span",{style:{width:12,flexShrink:0}},void 0,!1,void 0,this),xt.jsxDEV("span",{className:"stats-trace-gutter-track truncate",style:{minWidth:0},children:k.track.label},void 0,!1,void 0,this),k.track.model&&xt.jsxDEV("span",{className:"stats-trace-gutter-model truncate",style:{flexShrink:1,minWidth:0},children:k.track.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k.lanes.map((W)=>xt.jsxDEV("div",{className:"stats-trace-gutter-lane",style:{top:W.y,left:20+k.depth*14,lineHeight:`${So}px`},children:W.label},`${W.track.id}:${W.kind}`,!1,void 0,this))]},k.track.id,!0,void 0,this))},void 0,!1,void 0,this),xt.jsxDEV("canvas",{ref:T,className:"stats-trace-canvas",width:Math.floor(M*devicePixelRatio),height:Math.floor(G.totalHeight*devicePixelRatio),style:{width:M,height:G.totalHeight},tabIndex:0,role:"application","aria-label":"Trace timeline. W and S zoom, A and D pan, 0 fits all, F focuses the selection.",onPointerDown:ye,onPointerMove:Se,onPointerUp:K,onPointerLeave:()=>{H.current=null,A(null)},onDoubleClick:pe,onKeyDown:Ue},void 0,!1,void 0,this),He]},void 0,!0,void 0,this)}function Mf(a,n,s,i,l){if(a.beginPath(),i>=sR*2+1)a.roundRect(n,s,i,l,sR);else a.rect(n,s,i,l)}function Zz(a,n,s,i,l,u){let d=a.getContext("2d");if(!d)return;let{width:p,selection:h,hoverId:g,search:b,hits:y}=u,v=n.totalHeight,T=devicePixelRatio;d.setTransform(T,0,0,T,0,0),d.clearRect(0,0,p,v);let{u0:M,u1:I}=i,w=Math.max(I-M,0.000000001),A=(H)=>(H-M)/w*p,B=b.trim().toLowerCase(),z=[];for(let H of n.blocks){let V=H.track.spans.filter((G)=>G.kind==="turn");for(let G=0;G<V.length;G++){let X=A(s.toU(V[G].start)),Y=G+1<V.length?A(s.toU(V[G+1].start)):p;if(Y<0||X>p)continue;if(G%2===1)d.fillStyle=l.turnBand,d.fillRect(Math.max(0,X),H.y0,Math.min(p,Y)-Math.max(0,X),H.y1-H.y0);if(X>=0&&X<=p)d.strokeStyle=l.grid,d.beginPath(),d.moveTo(Math.round(X)+0.5,H.y0),d.lineTo(Math.round(X)+0.5,H.y1),d.stroke()}}for(let H of s.gaps){let V=A(H.uMid);if(V<-24||V>p+24)continue;d.save(),d.strokeStyle=l.grid,d.setLineDash([2,4]),d.beginPath(),d.moveTo(V,Ks),d.lineTo(V,v),d.stroke(),d.restore(),d.fillStyle=l.tick,d.font="9px system-ui, sans-serif",d.textAlign="center",d.fillText(`⋯ ${rt(H.t1-H.t0)}`,V,Ks-4),d.textAlign="left"}d.font="9px system-ui, sans-serif";for(let H of aR(s,M,I,p)){let V=Math.round(A(H.u))+0.5;if(d.strokeStyle=l.grid,d.beginPath(),H.major)d.moveTo(V,4),d.lineTo(V,v);else d.moveTo(V,Ks-8),d.lineTo(V,Ks);if(d.stroke(),d.fillStyle=l.tick,H.major)d.fillText(H.label,V+4,11);else d.globalAlpha=0.75,d.fillText(H.label,V+3,Ks-10),d.globalAlpha=1}d.strokeStyle=l.grid,d.beginPath(),d.moveTo(0,Ks+0.5),d.lineTo(p,Ks+0.5),d.stroke();for(let H of n.lanes){let V=H.kind==="turn";for(let G of H.spans){let X=s.toU(G.start);if(X>I)break;let Y=s.toU(G.end);if(Y<M)continue;let J=A(X),j=Math.max(Gz,A(Y)-J),se=H.y,ge=B===""||`${G.label} ${G.detail??""}`.toLowerCase().includes(B),ye=l.category[G.kind];if(d.globalAlpha=ge?1:0.3,V)d.fillStyle=`${ye}3a`,Mf(d,J,se,j,So),d.fill(),d.fillStyle=ye,d.fillRect(J,se,2,So);else d.fillStyle=ye,Mf(d,J,se,j,So),d.fill();if(G.isError)d.fillStyle=`${l.error}55`,Mf(d,J,se,j,So),d.fill(),d.fillStyle=l.error,d.fillRect(J,se,2,So);if(G.kind==="model"&&typeof G.ttft==="number"&&G.ttft>0&&j>20){let K=A(s.toU(G.start+G.ttft));if(K>J+1&&K<J+j-1)d.fillStyle="rgba(0,0,0,0.5)",d.fillRect(K,se+3,1,So-6)}if(G.unterminated)d.save(),d.strokeStyle=l.tick,d.setLineDash([2,2]),d.beginPath(),d.moveTo(J+j-0.5,se),d.lineTo(J+j-0.5,se+So),d.stroke(),d.restore();if(g===G.id)d.fillStyle="rgba(255,255,255,0.16)",Mf(d,J,se,j,So),d.fill();if(h===G.id)d.strokeStyle=l.selection,d.lineWidth=1.5,Mf(d,J-1,se-1,j+2,So+2),d.stroke(),d.lineWidth=1;if(j>Yz)d.save(),d.beginPath(),d.rect(J+3,se,j-6,So),d.clip(),d.fillStyle=V?l.tick:l.spanText,d.font="10px system-ui, sans-serif",d.fillText(G.label,J+5,se+So-5),d.restore();d.globalAlpha=1;let Se=Math.max(j,Xz);z.push({kind:"span",x:J-(Se-j)/2,y:se,w:Se,h:So,span:G,track:H.track})}}for(let H of n.blocks)for(let V of H.track.markers){let G=A(s.toU(V.time));if(G<-6||G>p+6)continue;let X=H.headerY+l0/2;d.fillStyle=l.marker,d.beginPath(),d.moveTo(G,X-4),d.lineTo(G+4,X),d.lineTo(G,X+4),d.lineTo(G-4,X),d.closePath(),d.fill(),z.push({kind:"marker",x:G-5,y:X-5,w:10,h:10,marker:V,track:H.track})}y.current=z}function Qz(a,n){let s=Math.min(a.clientX+14,window.innerWidth-320),i=a.clientY+16>window.innerHeight-140?a.clientY-120:a.clientY+16,l={position:"fixed",left:s,top:i,zIndex:60,maxWidth:300,pointerEvents:"none",background:"var(--surface-2)",border:"1px solid var(--border-strong)",borderRadius:6,padding:"7px 10px",fontSize:11,lineHeight:1.5,boxShadow:"0 1px 2px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.25)"};if(a.hit.kind==="marker"){let{marker:d}=a.hit;return xt.jsxDEV("div",{style:l,children:[xt.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:d.label},void 0,!1,void 0,this),xt.jsxDEV("div",{className:"stats-text-muted",children:[new Date(d.time).toLocaleTimeString()," (",Zu(d.time-n),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let{span:u}=a.hit;return xt.jsxDEV("div",{style:l,children:[xt.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate",children:u.label},void 0,!1,void 0,this),xt.jsxDEV("div",{className:"stats-text-muted",children:[rt(u.end-u.start)," · ",new Date(u.start).toLocaleTimeString()," (",Zu(u.start-n),")",u.unterminated?" · unterminated":""]},void 0,!0,void 0,this),u.kind==="model"&&xt.jsxDEV("div",{className:"stats-text-muted",children:[u.tokens!==void 0&&xt.jsxDEV(xt.Fragment,{children:[u.tokens.toLocaleString()," tok"]},void 0,!0,void 0,this),u.cost!==void 0&&xt.jsxDEV(xt.Fragment,{children:[" · $",u.cost.toFixed(4)]},void 0,!0,void 0,this),u.ttft!==void 0&&xt.jsxDEV(xt.Fragment,{children:[" · TTFT ",rt(u.ttft)]},void 0,!0,void 0,this),u.isError&&xt.jsxDEV(xt.Fragment,{children:" · error"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u.kind==="subagent"&&u.model&&xt.jsxDEV("div",{className:"stats-text-muted",children:u.model},void 0,!1,void 0,this),u.detail&&xt.jsxDEV("div",{className:"stats-text-secondary",style:{wordBreak:"break-word"},children:u.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Js=Q(dt(),1);var Aa=Q(de(),1),Qu=28,iR=20,Kz=340;function Jz(a){let n=[];for(let s of a){let i=s.id==="main"?0:s.id.split("/").length;for(let l of s.spans)n.push({key:l.id,time:l.start,span:l,track:s,depth:i});for(let l=0;l<s.markers.length;l++){let u=s.markers[l];n.push({key:`${s.id}:marker:${l}`,time:u.time,marker:u,track:s,depth:i})}}return n.sort((s,i)=>s.time-i.time),n}function lR({tracks:a,selection:n,onSelect:s,search:i,traceStart:l}){let u=$t(),d=$u[u],p=Js.useRef(null),[h,g]=Js.useState(0),b=Js.useMemo(()=>Jz(a),[a]),y=Js.useMemo(()=>{let I=i.trim().toLowerCase();if(!I)return b;return b.filter((w)=>(w.span?`${w.span.label} ${w.span.detail??""}`:w.marker?.label??"").toLowerCase().includes(I))},[b,i]);Js.useEffect(()=>{if(!n)return;let I=p.current;if(!I)return;let w=y.findIndex((B)=>B.span?.id===n);if(w===-1)return;let A=w*Qu;if(A<I.scrollTop||A+Qu>I.scrollTop+I.clientHeight)I.scrollTop=Math.max(0,A-I.clientHeight/2)},[n,y]);let v=Math.max(0,Math.floor(h/Qu)-iR),T=Math.min(y.length,Math.ceil((h+Kz)/Qu)+iR),M=y.slice(v,T);return Aa.jsxDEV("div",{ref:p,onScroll:(I)=>g(I.currentTarget.scrollTop),className:"stats-trace-list",children:[Aa.jsxDEV("div",{style:{height:y.length*Qu,position:"relative"},children:Aa.jsxDEV("div",{style:{position:"absolute",top:v*Qu,left:0,right:0},children:M.map((I)=>{let w=I.span,A=w!==void 0&&w.id===n,B=I.span?d.category[I.span.kind]:d.marker,z=I.span?.label??I.marker?.label??"",H=I.span?.detail,V=I.span?rt(I.span.end-I.span.start):"",G=I.span?.kind??I.marker?.kind??"",X=Aa.jsxDEV(Aa.Fragment,{children:[Aa.jsxDEV("span",{className:"stats-trace-kind",style:{color:B,background:`${B}1c`},children:G},void 0,!1,void 0,this),I.depth>0&&Aa.jsxDEV("span",{className:"stats-text-muted truncate",style:{flexShrink:0,maxWidth:90,fontSize:9},title:I.track.label,children:I.track.id},void 0,!1,void 0,this),Aa.jsxDEV("span",{className:"stats-text-primary truncate",style:{fontSize:11,minWidth:0,flexShrink:1},children:z},void 0,!1,void 0,this),H&&Aa.jsxDEV("span",{className:"stats-text-muted truncate",style:{fontSize:10,minWidth:0,flex:1},children:H},void 0,!1,void 0,this),Aa.jsxDEV("span",{className:"stats-trace-row-meta",children:[I.span?.isError&&Aa.jsxDEV("span",{style:{color:d.error},children:"error"},void 0,!1,void 0,this),Aa.jsxDEV("span",{children:V},void 0,!1,void 0,this),Aa.jsxDEV("span",{children:Zu(I.time-l)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y={paddingLeft:12+I.depth*12};return w?Aa.jsxDEV("button",{type:"button",onClick:()=>s(w.id),className:"stats-trace-row","data-selected":A?"true":"false",style:Y,children:X},I.key,!1,void 0,this):Aa.jsxDEV("div",{className:"stats-trace-row stats-trace-row-static",style:Y,children:X},I.key,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),y.length===0&&Aa.jsxDEV("div",{className:"stats-text-muted",style:{padding:16,fontSize:12},children:"No matching events"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ft=Q(de(),1),eH=[{value:"time",label:"Duration",title:"Real wall-clock time"},{value:"turns",label:"Turns",title:"Equal width per user turn"},{value:"calls",label:"Calls",title:"Equal width per model/tool call boundary"}];function uR({file:a,active:n,onBack:s}){let{data:i,error:l,loading:u,refetch:d,refreshing:p}=Vt(["trace",a],(te)=>UI(a,te),{pollMs:15000,enabled:n}),[h,g]=wt.useState("time"),[b,y]=wt.useState(!0),[v,T]=wt.useState(null),[M,I]=wt.useState(!1),[w,A]=wt.useState(""),[B,z]=wt.useState(0),[H,V]=wt.useState(new Set),[G,X]=wt.useState(null),Y=wt.useMemo(()=>i?.tracks??[],[i]),J=wt.useMemo(()=>tR(Y,h,b),[Y,h,b]),j=wt.useRef(J),se=wt.useRef(null);wt.useEffect(()=>{if(!i)return;if(se.current===i.file)return;se.current=i.file,T(null),A(""),X(null);let te=new Set;for(let le of i.tracks)if((le.id==="main"?0:le.id.split("/").length)>=1)te.add(le.id);V(te)},[i]),wt.useEffect(()=>{let te=j.current;j.current=J,X((le)=>{if(!le)return le;let fe=te.toT(le.u0),et=te.toT(le.u1),tt=J.toU(fe),Gt=J.toU(et);return Gt-tt>0?{u0:tt,u1:Gt}:null})},[J]);let ge=G??{u0:J.domain[0],u1:J.domain[1]},ye=wt.useMemo(()=>{let te=[];for(let le of Y)for(let fe of le.spans)te.push({span:fe,track:le});return te.sort((le,fe)=>le.span.start-fe.span.start),te},[Y]),Se=wt.useMemo(()=>{let te=w.trim().toLowerCase();if(!te)return[];return ye.filter(({span:le})=>`${le.label} ${le.detail??""}`.toLowerCase().includes(te))},[ye,w]),K=wt.useCallback((te)=>{let le=J.toU(te.start),fe=J.toU(te.end);X((et)=>{let tt=et??{u0:J.domain[0],u1:J.domain[1]};if(le>=tt.u0&&fe<=tt.u1)return et;let Gt=tt.u1-tt.u0,tr=(le+fe)/2,[me,ds]=J.domain,oo=tr-Gt/2;if(oo<me)oo=me;if(oo+Gt>ds)oo=Math.max(me,ds-Gt);return{u0:oo,u1:oo+Gt}})},[J]),pe=wt.useCallback((te)=>{T(te);let le=ye.find(({span:fe})=>fe.id===te);if(le)K(le.span)},[ye,K]),be=wt.useCallback((te)=>{T(te),I(te!==null)},[]),Ue=wt.useCallback((te)=>{if(Se.length===0)return;let le=((B+te)%Se.length+Se.length)%Se.length;z(le),pe(Se[le].span.id)},[Se,B,pe]),He=wt.useCallback((te)=>{V((le)=>{let fe=new Set(le);if(fe.has(te))fe.delete(te);else fe.add(te);return fe})},[]),k=wt.useMemo(()=>{if(!v)return null;return ye.find(({span:te})=>te.id===v)??null},[v,ye]),W=wt.useCallback((te)=>{let le=Y.find((et)=>et.id===te),fe=le?.spans[0];if(V((et)=>{let tt=new Set(et),Gt=le;while(Gt?.parentId)tt.delete(Gt.parentId),Gt=Y.find((tr)=>tr.id===Gt?.parentId);return tt}),fe)pe(fe.id)},[Y,pe]),ee=wt.useCallback((te)=>{if(!te){V(new Set);return}let le=new Set;for(let fe of Y)if(fe.id!=="main")le.add(fe.id);V(le)},[Y]),ne=i?.startedAt??0;return ft.jsxDEV("div",{className:"stats-trace-view",children:[ft.jsxDEV("div",{className:"stats-trace-header",children:[ft.jsxDEV("button",{type:"button",onClick:s,className:"stats-trace-back",children:[ft.jsxDEV(ef,{size:13,"aria-hidden":"true"},void 0,!1,void 0,this),"Sessions"]},void 0,!0,void 0,this),ft.jsxDEV("h2",{className:"stats-trace-title",style:{maxWidth:480,margin:0},children:i?.title??a.split("/").pop()},void 0,!1,void 0,this),i?.cwd&&ft.jsxDEV("span",{className:"stats-trace-cwd",children:i.cwd},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>void d(),className:"stats-trace-icon-btn","aria-label":"Refresh trace",title:"Refresh trace",style:{marginLeft:"auto"},children:ft.jsxDEV(yl,{size:14,className:p?"stats-spin":void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&ft.jsxDEV(ft.Fragment,{children:[ft.jsxDEV(JA,{summary:i.summary},void 0,!1,void 0,this),ft.jsxDEV("div",{className:"stats-trace-toolbar",children:[ft.jsxDEV(Zs,{options:eH,value:h,onChange:g},void 0,!1,void 0,this),h==="time"&&ft.jsxDEV("label",{className:"stats-trace-check",children:[ft.jsxDEV("input",{type:"checkbox",checked:b,onChange:(te)=>y(te.target.checked)},void 0,!1,void 0,this),"Compress idle"]},void 0,!0,void 0,this),ft.jsxDEV("div",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[ft.jsxDEV("input",{type:"search",value:w,onChange:(te)=>{A(te.target.value),z(0)},placeholder:"Search spans…","aria-label":"Search spans",spellCheck:!1,className:"stats-trace-input",style:{width:190}},void 0,!1,void 0,this),w.trim()&&ft.jsxDEV(ft.Fragment,{children:[ft.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:11,fontVariantNumeric:"tabular-nums"},children:Se.length===0?"0":`${B%Math.max(Se.length,1)+1}/${Se.length}`},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>Ue(-1),className:"stats-trace-icon-btn","aria-label":"Previous match",disabled:Se.length===0,children:"‹"},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>Ue(1),className:"stats-trace-icon-btn","aria-label":"Next match",disabled:Se.length===0,children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV("div",{style:{marginLeft:"auto",display:"inline-flex",gap:6},children:[ft.jsxDEV("button",{type:"button",onClick:()=>ee(!1),className:"stats-trace-back",children:"Expand all"},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>ee(!0),className:"stats-trace-back",children:"Collapse all"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV("div",{className:"stats-trace-timeline-card",children:[ft.jsxDEV(ZA,{tracks:Y,scale:J,viewport:ge,onViewportChange:X},void 0,!1,void 0,this),ft.jsxDEV(rR,{tracks:Y,scale:J,viewport:ge,onViewportChange:X,selection:v,onSelect:be,search:w,collapsed:H,onToggleCollapse:He,traceStart:ne},void 0,!1,void 0,this),ft.jsxDEV("div",{className:"stats-trace-toolbar-hint",style:{marginLeft:0},children:"W/S zoom · A/D pan · drag pan · wheel zoom · 0 fit · F focus selection · dbl-click focus · Esc deselect"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV(lR,{tracks:Y,selection:v,onSelect:(te)=>{pe(te),I(!0)},search:w,traceStart:ne},void 0,!1,void 0,this),ft.jsxDEV($A,{toolStats:i.summary.toolStats},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),ft.jsxDEV(KA,{span:M?k?.span??null:null,track:k?.track??null,onClose:()=>I(!1),onOpenChildTrack:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var kt=Q(de(),1);function tH({models:a}){let n=a.slice(0,3);return kt.jsxDEV("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:[n.map((s)=>kt.jsxDEV("span",{className:"stats-text-muted truncate",style:{fontSize:10,border:"1px solid var(--border)",borderRadius:999,padding:"1px 6px",maxWidth:140},children:s},s,!1,void 0,this)),a.length>3&&kt.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:10},children:["+",a.length-3]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function cR({active:a,session:n,onOpenSession:s,refreshTrigger:i}){let[l,u]=If.useState(""),{data:d,error:p,loading:h}=Vt(["sessions",i],(v)=>HI(200,void 0,v),{pollMs:30000,enabled:a&&n===null}),g=If.useMemo(()=>{if(!d)return[];let v=l.trim().toLowerCase();if(!v)return d;return d.filter((T)=>(T.title??"").toLowerCase().includes(v)||T.folder.toLowerCase().includes(v)||T.models.some((M)=>M.toLowerCase().includes(v)))},[d,l]),b=If.useMemo(()=>[{key:"title",header:"Title",render:(v)=>kt.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate",style:{maxWidth:280},children:v.title??v.file.split("/").pop()},void 0,!1,void 0,this)},{key:"folder",header:"Project",render:(v)=>kt.jsxDEV("span",{className:"stats-text-muted truncate",style:{maxWidth:160,display:"inline-block"},children:v.folder.split("/").slice(-2).join("/")},void 0,!1,void 0,this)},{key:"started",header:"Started",render:(v)=>za(v.startedAt)},{key:"duration",header:"Duration",numeric:!0,render:(v)=>rt(v.endedAt-v.startedAt)},{key:"requests",header:"Requests",numeric:!0,render:(v)=>v.requests},{key:"toolCalls",header:"Tools",numeric:!0,render:(v)=>v.toolCalls},{key:"subagents",header:"Agents",numeric:!0,render:(v)=>v.subagents},{key:"tokens",header:"Tokens",numeric:!0,render:(v)=>lt(v.totalTokens)},{key:"cost",header:"Cost",numeric:!0,render:(v)=>us(v.costTotal)},{key:"models",header:"Models",render:(v)=>kt.jsxDEV(tH,{models:v.models},void 0,!1,void 0,this)}],[]),y=(v,T)=>kt.jsxDEV("div",{className:"stats-mobile-card",onClick:T,children:[kt.jsxDEV("div",{className:"stats-mobile-card-header",children:kt.jsxDEV("div",{className:"stats-font-semibold stats-text-primary truncate",children:v.title??v.file.split("/").pop()},void 0,!1,void 0,this)},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-grid",children:[kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Started"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:za(v.startedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(v.endedAt-v.startedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Requests"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:v.requests},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cost"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:us(v.costTotal)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(n!==null)return kt.jsxDEV(uR,{file:n,active:a,onBack:()=>s(null)},void 0,!1,void 0,this);return kt.jsxDEV("div",{className:"stats-route-container",children:kt.jsxDEV(ut,{title:"Sessions",subtitle:"Recent sessions with subagent activity folded in — click one to open its trace",actions:kt.jsxDEV("input",{type:"search",value:l,onChange:(v)=>u(v.target.value),placeholder:"Filter by title, project, model…","aria-label":"Filter sessions",spellCheck:!1,className:"stats-trace-input",style:{width:220}},void 0,!1,void 0,this),children:kt.jsxDEV(Rt,{loading:h,error:p,data:d,children:kt.jsxDEV(Ma,{columns:b,data:g,keyExtractor:(v)=>v.file,onRowClick:(v)=>s(v.file),renderMobileCard:y,emptyText:"No sessions found — run a Sync to index recent activity"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Ra=Q(de(),1);function u0(){let{section:a,setSection:n,range:s,setRange:i,session:l,setSession:u}=eA(),[d,p]=er.useState(0),[h,g]=er.useState(null),[b,y]=er.useState(()=>Date.now()),v=er.useCallback((A)=>{if(A.success)p((B)=>B+1),y(Date.now())},[]),T=er.useCallback(()=>g(null),[]),M=a,I=er.useRef(new Set);I.current.add(M);let w=(A)=>{let B=A===M;switch(A){case"overview":return Ra.jsxDEV(qA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"requests":return Ra.jsxDEV(XA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"traces":return Ra.jsxDEV(cR,{active:B,session:l,onOpenSession:u,refreshTrigger:d},void 0,!1,void 0,this);case"errors":return Ra.jsxDEV(BA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"models":return Ra.jsxDEV(HA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"providers":return Ra.jsxDEV(jA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"tools":return Ra.jsxDEV(YA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"costs":return Ra.jsxDEV(OA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"behavior":return Ra.jsxDEV(EA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"projects":return Ra.jsxDEV(VA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"gain":return Ra.jsxDEV(NA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this)}};return Ra.jsxDEV(Ra.Fragment,{children:[Ra.jsxDEV(KI,{activeSection:M,onSectionChange:n,range:s,onRangeChange:i,updatedAt:b,onSyncComplete:v,children:[...I.current].map((A)=>Ra.jsxDEV("div",{hidden:A!==M,children:w(A)},A,!1,void 0,this))},void 0,!1,void 0,this),Ra.jsxDEV(MA,{id:h,onClose:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var fR=Q(de(),1),aH=dR.createRoot(document.getElementById("root"));aH.render(fR.jsxDEV(u0,{},void 0,!1,void 0,this));
257
+ `);return a}function AB(a,n){let{element:s,datasetIndex:i,index:l}=n,u=a.getDatasetMeta(i).controller,{label:d,value:p}=u.getLabelAndValue(l);return{chart:a,label:d,parsed:u.getParsed(l),raw:a.data.datasets[i].data[l],formattedValue:p,dataset:u.getDataset(),dataIndex:l,datasetIndex:i,element:s}}function MM(a,n){let s=a.chart.ctx,{body:i,footer:l,title:u}=a,{boxWidth:d,boxHeight:p}=n,h=pa(n.bodyFont),g=pa(n.titleFont),b=pa(n.footerFont),y=u.length,v=l.length,T=i.length,M=Na(n.padding),I=M.height,w=0,A=i.reduce((H,V)=>H+V.before.length+V.lines.length+V.after.length,0);if(A+=a.beforeBody.length+a.afterBody.length,y)I+=y*g.lineHeight+(y-1)*n.titleSpacing+n.titleMarginBottom;if(A){let H=n.displayColors?Math.max(p,h.lineHeight):h.lineHeight;I+=T*H+(A-T)*h.lineHeight+(A-1)*n.bodySpacing}if(v)I+=n.footerMarginTop+v*b.lineHeight+(v-1)*n.footerSpacing;let B=0,z=function(H){w=Math.max(w,s.measureText(H).width+B)};return s.save(),s.font=g.string,Lt(a.title,z),s.font=h.string,Lt(a.beforeBody.concat(a.afterBody),z),B=n.displayColors?d+2+n.boxPadding:0,Lt(i,(H)=>{Lt(H.before,z),Lt(H.lines,z),Lt(H.after,z)}),B=0,s.font=b.string,Lt(a.footer,z),s.restore(),w+=M.width,{width:w,height:I}}function RB(a,n){let{y:s,height:i}=n;if(s<i/2)return"top";else if(s>a.height-i/2)return"bottom";return"center"}function _B(a,n,s,i){let{x:l,width:u}=i,d=s.caretSize+s.caretPadding;if(a==="left"&&l+u+d>n.width)return!0;if(a==="right"&&l-u-d<0)return!0}function DB(a,n,s,i){let{x:l,width:u}=s,{width:d,chartArea:{left:p,right:h}}=a,g="center";if(i==="center")g=l<=(p+h)/2?"left":"right";else if(l<=u/2)g="left";else if(l>=d-u/2)g="right";if(_B(g,a,n,s))g="center";return g}function IM(a,n,s){let i=s.yAlign||n.yAlign||RB(a,s);return{xAlign:s.xAlign||n.xAlign||DB(a,n,s,i),yAlign:i}}function EB(a,n){let{x:s,width:i}=a;if(n==="right")s-=i;else if(n==="center")s-=i/2;return s}function OB(a,n,s){let{y:i,height:l}=a;if(n==="top")i+=s;else if(n==="bottom")i-=l+s;else i-=l/2;return i}function AM(a,n,s,i){let{caretSize:l,caretPadding:u,cornerRadius:d}=a,{xAlign:p,yAlign:h}=s,g=l+u,{topLeft:b,topRight:y,bottomLeft:v,bottomRight:T}=ti(d),M=EB(n,p),I=OB(n,h,g);if(h==="center"){if(p==="left")M+=g;else if(p==="right")M-=g}else if(p==="left")M-=Math.max(b,v)+l;else if(p==="right")M+=Math.max(y,T)+l;return{x:mo(M,0,i.width-n.width),y:mo(I,0,i.height-n.height)}}function mm(a,n,s){let i=Na(s.padding);return n==="center"?a.x+a.width/2:n==="right"?a.x+a.width-i.right:a.x+i.left}function RM(a){return ns([],Gs(a))}function PB(a,n,s){return Vs(a,{tooltip:n,tooltipItems:s,type:"tooltip"})}function _M(a,n){let s=n&&n.dataset&&n.dataset.tooltip&&n.dataset.tooltip.callbacks;return s?a.override(s):a}var pI={beforeTitle:os,title(a){if(a.length>0){let n=a[0],s=n.chart.data.labels,i=s?s.length:0;if(this&&this.options&&this.options.mode==="dataset")return n.dataset.label||"";else if(n.label)return n.label;else if(i>0&&n.dataIndex<i)return s[n.dataIndex]}return""},afterTitle:os,beforeBody:os,beforeLabel:os,label(a){if(this&&this.options&&this.options.mode==="dataset")return a.label+": "+a.formattedValue||a.formattedValue;let n=a.dataset.label||"";if(n)n+=": ";let s=a.formattedValue;if(!ht(s))n+=s;return n},labelColor(a){let s=a.chart.getDatasetMeta(a.datasetIndex).controller.getStyle(a.dataIndex);return{borderColor:s.borderColor,backgroundColor:s.backgroundColor,borderWidth:s.borderWidth,borderDash:s.borderDash,borderDashOffset:s.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(a){let s=a.chart.getDatasetMeta(a.datasetIndex).controller.getStyle(a.dataIndex);return{pointStyle:s.pointStyle,rotation:s.rotation}},afterLabel:os,afterBody:os,beforeFooter:os,footer:os,afterFooter:os};function yo(a,n,s,i){let l=a[n].call(s,i);if(typeof l>"u")return pI[n].call(s,i);return l}class kv extends Xs{static positioners=Yd;constructor(a){super();this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=a.chart,this.options=a.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(a){this.options=a,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){let a=this._cachedAnimations;if(a)return a;let n=this.chart,s=this.options.setContext(this.getContext()),i=s.enabled&&n.options.animation&&s.animations,l=new Av(this.chart,i);if(i._cacheable)this._cachedAnimations=Object.freeze(l);return l}getContext(){return this.$context||(this.$context=PB(this.chart.getContext(),this,this._tooltipItems))}getTitle(a,n){let{callbacks:s}=n,i=yo(s,"beforeTitle",this,a),l=yo(s,"title",this,a),u=yo(s,"afterTitle",this,a),d=[];return d=ns(d,Gs(i)),d=ns(d,Gs(l)),d=ns(d,Gs(u)),d}getBeforeBody(a,n){return RM(yo(n.callbacks,"beforeBody",this,a))}getBody(a,n){let{callbacks:s}=n,i=[];return Lt(a,(l)=>{let u={before:[],lines:[],after:[]},d=_M(s,l);ns(u.before,Gs(yo(d,"beforeLabel",this,l))),ns(u.lines,yo(d,"label",this,l)),ns(u.after,Gs(yo(d,"afterLabel",this,l))),i.push(u)}),i}getAfterBody(a,n){return RM(yo(n.callbacks,"afterBody",this,a))}getFooter(a,n){let{callbacks:s}=n,i=yo(s,"beforeFooter",this,a),l=yo(s,"footer",this,a),u=yo(s,"afterFooter",this,a),d=[];return d=ns(d,Gs(i)),d=ns(d,Gs(l)),d=ns(d,Gs(u)),d}_createItems(a){let n=this._active,s=this.chart.data,i=[],l=[],u=[],d=[],p,h;for(p=0,h=n.length;p<h;++p)d.push(AB(this.chart,n[p]));if(a.filter)d=d.filter((g,b,y)=>a.filter(g,b,y,s));if(a.itemSort)d=d.sort((g,b)=>a.itemSort(g,b,s));return Lt(d,(g)=>{let b=_M(a.callbacks,g);i.push(yo(b,"labelColor",this,g)),l.push(yo(b,"labelPointStyle",this,g)),u.push(yo(b,"labelTextColor",this,g))}),this.labelColors=i,this.labelPointStyles=l,this.labelTextColors=u,this.dataPoints=d,d}update(a,n){let s=this.options.setContext(this.getContext()),i=this._active,l,u=[];if(!i.length){if(this.opacity!==0)l={opacity:0}}else{let d=Yd[s.position].call(this,i,this._eventPosition);u=this._createItems(s),this.title=this.getTitle(u,s),this.beforeBody=this.getBeforeBody(u,s),this.body=this.getBody(u,s),this.afterBody=this.getAfterBody(u,s),this.footer=this.getFooter(u,s);let p=this._size=MM(this,s),h=Object.assign({},d,p),g=IM(this.chart,s,h),b=AM(s,h,g,this.chart);this.xAlign=g.xAlign,this.yAlign=g.yAlign,l={opacity:1,x:b.x,y:b.y,width:p.width,height:p.height,caretX:d.x,caretY:d.y}}if(this._tooltipItems=u,this.$context=void 0,l)this._resolveAnimations().update(this,l);if(a&&s.external)s.external.call(this,{chart:this.chart,tooltip:this,replay:n})}drawCaret(a,n,s,i){let l=this.getCaretPosition(a,s,i);n.lineTo(l.x1,l.y1),n.lineTo(l.x2,l.y2),n.lineTo(l.x3,l.y3)}getCaretPosition(a,n,s){let{xAlign:i,yAlign:l}=this,{caretSize:u,cornerRadius:d}=s,{topLeft:p,topRight:h,bottomLeft:g,bottomRight:b}=ti(d),{x:y,y:v}=a,{width:T,height:M}=n,I,w,A,B,z,H;if(l==="center"){if(z=v+M/2,i==="left")I=y,w=I-u,B=z+u,H=z-u;else I=y+T,w=I+u,B=z-u,H=z+u;A=I}else{if(i==="left")w=y+Math.max(p,g)+u;else if(i==="right")w=y+T-Math.max(h,b)-u;else w=this.caretX;if(l==="top")B=v,z=B-u,I=w-u,A=w+u;else B=v+M,z=B+u,I=w+u,A=w-u;H=B}return{x1:I,x2:w,x3:A,y1:B,y2:z,y3:H}}drawTitle(a,n,s){let i=this.title,l=i.length,u,d,p;if(l){let h=il(s.rtl,this.x,this.width);a.x=mm(this,s.titleAlign,s),n.textAlign=h.textAlign(s.titleAlign),n.textBaseline="middle",u=pa(s.titleFont),d=s.titleSpacing,n.fillStyle=s.titleColor,n.font=u.string;for(p=0;p<l;++p)if(n.fillText(i[p],h.x(a.x),a.y+u.lineHeight/2),a.y+=u.lineHeight+d,p+1===l)a.y+=s.titleMarginBottom-d}}_drawColorBox(a,n,s,i,l){let u=this.labelColors[s],d=this.labelPointStyles[s],{boxHeight:p,boxWidth:h}=l,g=pa(l.bodyFont),b=mm(this,"left",l),y=i.x(b),v=p<g.lineHeight?(g.lineHeight-p)/2:0,T=n.y+v;if(l.usePointStyle){let M={radius:Math.min(h,p)/2,pointStyle:d.pointStyle,rotation:d.rotation,borderWidth:1},I=i.leftForLtr(y,h)+h/2,w=T+p/2;a.strokeStyle=l.multiKeyBackground,a.fillStyle=l.multiKeyBackground,im(a,M,I,w),a.strokeStyle=u.borderColor,a.fillStyle=u.backgroundColor,im(a,M,I,w)}else{a.lineWidth=it(u.borderWidth)?Math.max(...Object.values(u.borderWidth)):u.borderWidth||1,a.strokeStyle=u.borderColor,a.setLineDash(u.borderDash||[]),a.lineDashOffset=u.borderDashOffset||0;let M=i.leftForLtr(y,h),I=i.leftForLtr(i.xPlus(y,1),h-2),w=ti(u.borderRadius);if(Object.values(w).some((A)=>A!==0))a.beginPath(),a.fillStyle=l.multiKeyBackground,zu(a,{x:M,y:T,w:h,h:p,radius:w}),a.fill(),a.stroke(),a.fillStyle=u.backgroundColor,a.beginPath(),zu(a,{x:I,y:T+1,w:h-2,h:p-2,radius:w}),a.fill();else a.fillStyle=l.multiKeyBackground,a.fillRect(M,T,h,p),a.strokeRect(M,T,h,p),a.fillStyle=u.backgroundColor,a.fillRect(I,T+1,h-2,p-2)}a.fillStyle=this.labelTextColors[s]}drawBody(a,n,s){let{body:i}=this,{bodySpacing:l,bodyAlign:u,displayColors:d,boxHeight:p,boxWidth:h,boxPadding:g}=s,b=pa(s.bodyFont),y=b.lineHeight,v=0,T=il(s.rtl,this.x,this.width),M=function(X){n.fillText(X,T.x(a.x+v),a.y+y/2),a.y+=y+l},I=T.textAlign(u),w,A,B,z,H,V,G;n.textAlign=u,n.textBaseline="middle",n.font=b.string,a.x=mm(this,I,s),n.fillStyle=s.bodyColor,Lt(this.beforeBody,M),v=d&&I!=="right"?u==="center"?h/2+g:h+2+g:0;for(z=0,V=i.length;z<V;++z){if(w=i[z],A=this.labelTextColors[z],n.fillStyle=A,Lt(w.before,M),B=w.lines,d&&B.length)this._drawColorBox(n,a,z,T,s),y=Math.max(b.lineHeight,p);for(H=0,G=B.length;H<G;++H)M(B[H]),y=b.lineHeight;Lt(w.after,M)}v=0,y=b.lineHeight,Lt(this.afterBody,M),a.y-=l}drawFooter(a,n,s){let i=this.footer,l=i.length,u,d;if(l){let p=il(s.rtl,this.x,this.width);a.x=mm(this,s.footerAlign,s),a.y+=s.footerMarginTop,n.textAlign=p.textAlign(s.footerAlign),n.textBaseline="middle",u=pa(s.footerFont),n.fillStyle=s.footerColor,n.font=u.string;for(d=0;d<l;++d)n.fillText(i[d],p.x(a.x),a.y+u.lineHeight/2),a.y+=u.lineHeight+s.footerSpacing}}drawBackground(a,n,s,i){let{xAlign:l,yAlign:u}=this,{x:d,y:p}=a,{width:h,height:g}=s,{topLeft:b,topRight:y,bottomLeft:v,bottomRight:T}=ti(i.cornerRadius);if(n.fillStyle=i.backgroundColor,n.strokeStyle=i.borderColor,n.lineWidth=i.borderWidth,n.beginPath(),n.moveTo(d+b,p),u==="top")this.drawCaret(a,n,s,i);if(n.lineTo(d+h-y,p),n.quadraticCurveTo(d+h,p,d+h,p+y),u==="center"&&l==="right")this.drawCaret(a,n,s,i);if(n.lineTo(d+h,p+g-T),n.quadraticCurveTo(d+h,p+g,d+h-T,p+g),u==="bottom")this.drawCaret(a,n,s,i);if(n.lineTo(d+v,p+g),n.quadraticCurveTo(d,p+g,d,p+g-v),u==="center"&&l==="left")this.drawCaret(a,n,s,i);if(n.lineTo(d,p+b),n.quadraticCurveTo(d,p,d+b,p),n.closePath(),n.fill(),i.borderWidth>0)n.stroke()}_updateAnimationTarget(a){let n=this.chart,s=this.$animations,i=s&&s.x,l=s&&s.y;if(i||l){let u=Yd[a.position].call(this,this._active,this._eventPosition);if(!u)return;let d=this._size=MM(this,a),p=Object.assign({},u,this._size),h=IM(n,a,p),g=AM(a,p,h,n);if(i._to!==g.x||l._to!==g.y)this.xAlign=h.xAlign,this.yAlign=h.yAlign,this.width=d.width,this.height=d.height,this.caretX=u.x,this.caretY=u.y,this._resolveAnimations().update(this,g)}}_willRender(){return!!this.opacity}draw(a){let n=this.options.setContext(this.getContext()),s=this.opacity;if(!s)return;this._updateAnimationTarget(n);let i={width:this.width,height:this.height},l={x:this.x,y:this.y};s=Math.abs(s)<0.001?0:s;let u=Na(n.padding),d=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;if(n.enabled&&d)a.save(),a.globalAlpha=s,this.drawBackground(l,a,i,n),sv(a,n.textDirection),l.y+=u.top,this.drawTitle(l,a,n),this.drawBody(l,a,n),this.drawFooter(l,a,n),rv(a,n.textDirection),a.restore()}getActiveElements(){return this._active||[]}setActiveElements(a,n){let s=this._active,i=a.map(({datasetIndex:d,index:p})=>{let h=this.chart.getDatasetMeta(d);if(!h)throw Error("Cannot find a dataset at index "+d);return{datasetIndex:d,element:h.data[p],index:p}}),l=!Pd(s,i),u=this._positionChanged(i,n);if(l||u)this._active=i,this._eventPosition=n,this._ignoreReplayEvents=!0,this.update(!0)}handleEvent(a,n,s=!0){if(n&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;let i=this.options,l=this._active||[],u=this._getActiveElements(a,l,n,s),d=this._positionChanged(u,a),p=n||!Pd(u,l)||d;if(p){if(this._active=u,i.enabled||i.external)this._eventPosition={x:a.x,y:a.y},this.update(!0,n)}return p}_getActiveElements(a,n,s,i){let l=this.options;if(a.type==="mouseout")return[];if(!i)return n.filter((d)=>this.chart.data.datasets[d.datasetIndex]&&this.chart.getDatasetMeta(d.datasetIndex).controller.getParsed(d.index)!==void 0);let u=this.chart.getElementsAtEventForMode(a,l.mode,l,s);if(l.reverse)u.reverse();return u}_positionChanged(a,n){let{caretX:s,caretY:i,options:l}=this,u=Yd[l.position].call(this,a,n);return u!==!1&&(s!==u.x||i!==u.y)}}var hI={id:"tooltip",_element:kv,positioners:Yd,afterInit(a,n,s){if(s)a.tooltip=new kv({chart:a,options:s})},beforeUpdate(a,n,s){if(a.tooltip)a.tooltip.initialize(s)},reset(a,n,s){if(a.tooltip)a.tooltip.initialize(s)},afterDraw(a){let n=a.tooltip;if(n&&n._willRender()){let s={tooltip:n};if(a.notifyPlugins("beforeTooltipDraw",{...s,cancelable:!0})===!1)return;n.draw(a.ctx),a.notifyPlugins("afterTooltipDraw",s)}},afterEvent(a,n){if(a.tooltip){let s=n.replay;if(a.tooltip.handleEvent(n.event,s,n.inChartArea))n.changed=!0}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(a,n)=>n.bodyFont.size,boxWidth:(a,n)=>n.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:pI},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:(a)=>a!=="filter"&&a!=="itemSort"&&a!=="external",_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]};var BB=(a,n,s,i)=>{if(typeof n==="string")s=a.push(n)-1,i.unshift({index:s,label:n});else if(isNaN(n))s=null;return s};function NB(a,n,s,i){let l=a.indexOf(n);if(l===-1)return BB(a,n,s,i);let u=a.lastIndexOf(n);return l!==u?s:l}var zB=(a,n)=>a===null?null:mo(Math.round(a),0,n);function DM(a){let n=this.getLabels();if(a>=0&&a<n.length)return n[a];return a}class zv extends cl{static id="category";static defaults={ticks:{callback:DM}};constructor(a){super(a);this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(a){let n=this._addedLabels;if(n.length){let s=this.getLabels();for(let{index:i,label:l}of n)if(s[i]===l)s.splice(i,1);this._addedLabels=[]}super.init(a)}parse(a,n){if(ht(a))return null;let s=this.getLabels();return n=isFinite(n)&&s[n]===a?n:NB(s,a,Ke(n,a),this._addedLabels),zB(n,s.length-1)}determineDataLimits(){let{minDefined:a,maxDefined:n}=this.getUserBounds(),{min:s,max:i}=this.getMinMax(!0);if(this.options.bounds==="ticks"){if(!a)s=0;if(!n)i=this.getLabels().length-1}this.min=s,this.max=i}buildTicks(){let a=this.min,n=this.max,s=this.options.offset,i=[],l=this.getLabels();l=a===0&&n===l.length-1?l:l.slice(a,n+1),this._valueRange=Math.max(l.length-(s?0:1),1),this._startValue=this.min-(s?0.5:0);for(let u=a;u<=n;u++)i.push({value:u});return i}getLabelForValue(a){return DM.call(this,a)}configure(){if(super.configure(),!this.isHorizontal())this._reversePixels=!this._reversePixels}getPixelForValue(a){if(typeof a!=="number")a=this.parse(a);return a===null?NaN:this.getPixelForDecimal((a-this._startValue)/this._valueRange)}getPixelForTick(a){let n=this.ticks;if(a<0||a>n.length-1)return null;return this.getPixelForValue(n[a].value)}getValueForPixel(a){return Math.round(this._startValue+this.getDecimalForPixel(a)*this._valueRange)}getBasePixel(){return this.bottom}}function HB(a,n){let s=[],i=0.00000000000001,{bounds:l,step:u,min:d,max:p,precision:h,count:g,maxTicks:b,maxDigits:y,includeBounds:v}=a,T=u||1,M=b-1,{min:I,max:w}=n,A=!ht(d),B=!ht(p),z=!ht(g),H=(w-I)/(y+1),V=Ux((w-I)/M/T)*T,G,X,Y,J;if(V<0.00000000000001&&!A&&!B)return[{value:I},{value:w}];if(J=Math.ceil(w/V)-Math.floor(I/V),J>M)V=Ux(J*V/M/T)*T;if(!ht(h))G=Math.pow(10,h),V=Math.ceil(V*G)/G;if(l==="ticks")X=Math.floor(I/V)*V,Y=Math.ceil(w/V)*V;else X=I,Y=w;if(A&&B&&u&&bk((p-d)/u,V/1000))J=Math.round(Math.min((p-d)/V,b)),V=(p-d)/J,X=d,Y=p;else if(z)X=A?d:X,Y=B?p:Y,J=g-1,V=(Y-X)/J;else if(J=(Y-X)/V,Bu(J,Math.round(J),V/1000))J=Math.round(J);else J=Math.ceil(J);let j=Math.max(qx(V),qx(X));G=Math.pow(10,ht(h)?j:h),X=Math.round(X*G)/G,Y=Math.round(Y*G)/G;let se=0;if(A){if(v&&X!==d){if(s.push({value:d}),X<d)se++;if(Bu(Math.round((X+se*V)*G)/G,d,EM(d,H,a)))se++}else if(X<d)se++}for(;se<J;++se){let ge=Math.round((X+se*V)*G)/G;if(B&&ge>p)break;s.push({value:ge})}if(B&&v&&Y!==p)if(s.length&&Bu(s[s.length-1].value,p,EM(p,H,a)))s[s.length-1].value=p;else s.push({value:p});else if(!B||Y===p)s.push({value:Y});return s}function EM(a,n,{horizontal:s,minRotation:i}){let l=Fs(i),u=(s?Math.sin(l):Math.cos(l))||0.001,d=0.75*n*(""+a).length;return Math.min(n/u,d)}class Wd extends cl{constructor(a){super(a);this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(a,n){if(ht(a))return null;if((typeof a==="number"||a instanceof Number)&&!isFinite(+a))return null;return+a}handleTickRangeOptions(){let{beginAtZero:a}=this.options,{minDefined:n,maxDefined:s}=this.getUserBounds(),{min:i,max:l}=this,u=(p)=>i=n?i:p,d=(p)=>l=s?l:p;if(a){let p=Ln(i),h=Ln(l);if(p<0&&h<0)d(0);else if(p>0&&h>0)u(0)}if(i===l){let p=l===0?1:Math.abs(l*0.05);if(d(l+p),!a)u(i-p)}this.min=i,this.max=l}getTickLimit(){let a=this.options.ticks,{maxTicksLimit:n,stepSize:s}=a,i;if(s){if(i=Math.ceil(this.max/s)-Math.floor(this.min/s)+1,i>1000)console.warn(`scales.${this.id}.ticks.stepSize: ${s} would result generating up to ${i} ticks. Limiting to 1000.`),i=1000}else i=this.computeTickLimit(),n=n||11;if(n)i=Math.min(n,i);return i}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){let a=this.options,n=a.ticks,s=this.getTickLimit();s=Math.max(2,s);let i={maxTicks:s,bounds:a.bounds,min:a.min,max:a.max,precision:n.precision,step:n.stepSize,count:n.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:n.minRotation||0,includeBounds:n.includeBounds!==!1},l=this._range||this,u=HB(i,l);if(a.bounds==="ticks")Fx(u,this,"value");if(a.reverse)u.reverse(),this.start=this.max,this.end=this.min;else this.start=this.min,this.end=this.max;return u}configure(){let a=this.ticks,n=this.min,s=this.max;if(super.configure(),this.options.offset&&a.length){let i=(s-n)/Math.max(a.length-1,1)/2;n-=i,s+=i}this._startValue=n,this._endValue=s,this._valueRange=s-n}getLabelForValue(a){return sm(a,this.chart.options.locale,this.options.ticks.format)}}class Hv extends Wd{static id="linear";static defaults={ticks:{callback:Bd.formatters.numeric}};determineDataLimits(){let{min:a,max:n}=this.getMinMax(!0);this.min=Kt(a)?a:0,this.max=Kt(n)?n:1,this.handleTickRangeOptions()}computeTickLimit(){let a=this.isHorizontal(),n=a?this.width:this.height,s=Fs(this.options.ticks.minRotation),i=(a?Math.sin(s):Math.cos(s))||0.001,l=this._resolveTickFontOptions(0);return Math.ceil(n/Math.min(40,l.lineHeight/i))}getPixelForValue(a){return a===null?NaN:this.getPixelForDecimal((a-this._startValue)/this._valueRange)}getValueForPixel(a){return this._startValue+this.getDecimalForPixel(a)*this._valueRange}}var Zd=(a)=>Math.floor(Us(a)),ul=(a,n)=>Math.pow(10,Zd(a)+n);function OM(a){return a/Math.pow(10,Zd(a))===1}function PM(a,n,s){let i=Math.pow(10,s),l=Math.floor(a/i);return Math.ceil(n/i)-l}function UB(a,n){let s=n-a,i=Zd(s);while(PM(a,n,i)>10)i++;while(PM(a,n,i)<10)i--;return Math.min(i,Zd(a))}function FB(a,{min:n,max:s}){n=go(a.min,n);let i=[],l=Zd(n),u=UB(n,s),d=u<0?Math.pow(10,Math.abs(u)):1,p=Math.pow(10,u),h=l>u?Math.pow(10,l):0,g=Math.round((n-h)*d)/d,b=Math.floor((n-h)/p/10)*p*10,y=Math.floor((g-b)/Math.pow(10,u)),v=go(a.min,Math.round((h+b+y*Math.pow(10,u))*d)/d);while(v<s){if(i.push({value:v,major:OM(v),significand:y}),y>=10)y=y<15?15:20;else y++;if(y>=20)u++,y=2,d=u>=0?1:d;v=Math.round((h+b+y*Math.pow(10,u))*d)/d}let T=go(a.max,v);return i.push({value:T,major:OM(T),significand:y}),i}class qB extends cl{static id="logarithmic";static defaults={ticks:{callback:Bd.formatters.logarithmic,major:{enabled:!0}}};constructor(a){super(a);this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(a,n){let s=Wd.prototype.parse.apply(this,[a,n]);if(s===0){this._zero=!0;return}return Kt(s)&&s>0?s:null}determineDataLimits(){let{min:a,max:n}=this.getMinMax(!0);if(this.min=Kt(a)?Math.max(0,a):null,this.max=Kt(n)?Math.max(0,n):null,this.options.beginAtZero)this._zero=!0;if(this._zero&&this.min!==this._suggestedMin&&!Kt(this._userMin))this.min=a===ul(this.min,0)?ul(this.min,-1):ul(this.min,0);this.handleTickRangeOptions()}handleTickRangeOptions(){let{minDefined:a,maxDefined:n}=this.getUserBounds(),s=this.min,i=this.max,l=(d)=>s=a?s:d,u=(d)=>i=n?i:d;if(s===i)if(s<=0)l(1),u(10);else l(ul(s,-1)),u(ul(i,1));if(s<=0)l(ul(i,-1));if(i<=0)u(ul(s,1));this.min=s,this.max=i}buildTicks(){let a=this.options,n={min:this._userMin,max:this._userMax},s=FB(n,this);if(a.bounds==="ticks")Fx(s,this,"value");if(a.reverse)s.reverse(),this.start=this.max,this.end=this.min;else this.start=this.min,this.end=this.max;return s}getLabelForValue(a){return a===void 0?"0":sm(a,this.chart.options.locale,this.options.ticks.format)}configure(){let a=this.min;super.configure(),this._startValue=Us(a),this._valueRange=Us(this.max)-Us(a)}getPixelForValue(a){if(a===void 0||a===0)a=this.min;if(a===null||isNaN(a))return NaN;return this.getPixelForDecimal(a===this.min?0:(Us(a)-this._startValue)/this._valueRange)}getValueForPixel(a){let n=this.getDecimalForPixel(a);return Math.pow(10,this._startValue+n*this._valueRange)}}function Mv(a){let n=a.ticks;if(n.display&&a.display){let s=Na(n.backdropPadding);return Ke(n.font&&n.font.size,Jt.font.size)+s.height}return 0}function VB(a,n,s){return s=zt(s)?s:[s],{w:_k(a,n.string,s),h:s.length*n.lineHeight}}function BM(a,n,s,i,l){if(a===i||a===l)return{start:n-s/2,end:n+s/2};else if(a<i||a>l)return{start:n-s,end:n};return{start:n,end:n+s}}function jB(a){let n={l:a.left+a._padding.left,r:a.right-a._padding.right,t:a.top+a._padding.top,b:a.bottom-a._padding.bottom},s=Object.assign({},n),i=[],l=[],u=a._pointLabels.length,d=a.options.pointLabels,p=d.centerPointLabels?na/u:0;for(let h=0;h<u;h++){let g=d.setContext(a.getPointLabelContext(h));l[h]=g.padding;let b=a.getPointPosition(h,a.drawingArea+l[h],p),y=pa(g.font),v=VB(a.ctx,y,a._pointLabels[h]);i[h]=v;let T=fo(a.getIndexAngle(h)+p),M=Math.round(am(T)),I=BM(M,b.x,v.w,0,180),w=BM(M,b.y,v.h,90,270);GB(s,n,T,I,w)}a.setCenterPoint(n.l-s.l,s.r-n.r,n.t-s.t,s.b-n.b),a._pointLabelItems=$B(a,i,l)}function GB(a,n,s,i,l){let u=Math.abs(Math.sin(s)),d=Math.abs(Math.cos(s)),p=0,h=0;if(i.start<n.l)p=(n.l-i.start)/u,a.l=Math.min(a.l,n.l-p);else if(i.end>n.r)p=(i.end-n.r)/u,a.r=Math.max(a.r,n.r+p);if(l.start<n.t)h=(n.t-l.start)/d,a.t=Math.min(a.t,n.t-h);else if(l.end>n.b)h=(l.end-n.b)/d,a.b=Math.max(a.b,n.b+h)}function XB(a,n,s){let i=a.drawingArea,{extra:l,additionalAngle:u,padding:d,size:p}=s,h=a.getPointPosition(n,i+l+d,u),g=Math.round(am(fo(h.angle+po))),b=QB(h.y,p.h,g),y=WB(g),v=ZB(h.x,p.w,y);return{visible:!0,x:h.x,y:b,textAlign:y,left:v,top:b,right:v+p.w,bottom:b+p.h}}function YB(a,n){if(!n)return!0;let{left:s,top:i,right:l,bottom:u}=a;return!(as({x:s,y:i},n)||as({x:s,y:u},n)||as({x:l,y:i},n)||as({x:l,y:u},n))}function $B(a,n,s){let i=[],l=a._pointLabels.length,u=a.options,{centerPointLabels:d,display:p}=u.pointLabels,h={extra:Mv(u)/2,additionalAngle:d?na/l:0},g;for(let b=0;b<l;b++){h.padding=s[b],h.size=n[b];let y=XB(a,b,h);if(i.push(y),p==="auto"){if(y.visible=YB(y,g),y.visible)g=y}}return i}function WB(a){if(a===0||a===180)return"center";else if(a<180)return"left";return"right"}function ZB(a,n,s){if(s==="right")a-=n;else if(s==="center")a-=n/2;return a}function QB(a,n,s){if(s===90||s===270)a-=n/2;else if(s>270||s<90)a-=n;return a}function KB(a,n,s){let{left:i,top:l,right:u,bottom:d}=s,{backdropColor:p}=n;if(!ht(p)){let h=ti(n.borderRadius),g=Na(n.backdropPadding);a.fillStyle=p;let b=i-g.left,y=l-g.top,v=u-i+g.width,T=d-l+g.height;if(Object.values(h).some((M)=>M!==0))a.beginPath(),zu(a,{x:b,y,w:v,h:T,radius:h}),a.fill();else a.fillRect(b,y,v,T)}}function JB(a,n){let{ctx:s,options:{pointLabels:i}}=a;for(let l=n-1;l>=0;l--){let u=a._pointLabelItems[l];if(!u.visible)continue;let d=i.setContext(a.getPointLabelContext(l));KB(s,d,u);let p=pa(d.font),{x:h,y:g,textAlign:b}=u;ei(s,a._pointLabels[l],h,g+p.lineHeight/2,p,{color:d.color,textAlign:b,textBaseline:"middle"})}}function mI(a,n,s,i){let{ctx:l}=a;if(s)l.arc(a.xCenter,a.yCenter,n,0,ho);else{let u=a.getPointPosition(0,n);l.moveTo(u.x,u.y);for(let d=1;d<i;d++)u=a.getPointPosition(d,n),l.lineTo(u.x,u.y)}}function eN(a,n,s,i,l){let u=a.ctx,d=n.circular,{color:p,lineWidth:h}=n;if(!d&&!i||!p||!h||s<0)return;u.save(),u.strokeStyle=p,u.lineWidth=h,u.setLineDash(l.dash||[]),u.lineDashOffset=l.dashOffset,u.beginPath(),mI(a,s,d,i),u.closePath(),u.stroke(),u.restore()}function tN(a,n,s){return Vs(a,{label:s,index:n,type:"pointLabel"})}class aN extends Wd{static id="radialLinear";static defaults={display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:Bd.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback(a){return a},padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(a){super(a);this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){let a=this._padding=Na(Mv(this.options)/2),n=this.width=this.maxWidth-a.width,s=this.height=this.maxHeight-a.height;this.xCenter=Math.floor(this.left+n/2+a.left),this.yCenter=Math.floor(this.top+s/2+a.top),this.drawingArea=Math.floor(Math.min(n,s)/2)}determineDataLimits(){let{min:a,max:n}=this.getMinMax(!1);this.min=Kt(a)&&!isNaN(a)?a:0,this.max=Kt(n)&&!isNaN(n)?n:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/Mv(this.options))}generateTickLabels(a){Wd.prototype.generateTickLabels.call(this,a),this._pointLabels=this.getLabels().map((n,s)=>{let i=Ot(this.options.pointLabels.callback,[n,s],this);return i||i===0?i:""}).filter((n,s)=>this.chart.getDataVisibility(s))}fit(){let a=this.options;if(a.display&&a.pointLabels.display)jB(this);else this.setCenterPoint(0,0,0,0)}setCenterPoint(a,n,s,i){this.xCenter+=Math.floor((a-n)/2),this.yCenter+=Math.floor((s-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(a,n,s,i))}getIndexAngle(a){let n=ho/(this._pointLabels.length||1),s=this.options.startAngle||0;return fo(a*n+Fs(s))}getDistanceFromCenterForValue(a){if(ht(a))return NaN;let n=this.drawingArea/(this.max-this.min);if(this.options.reverse)return(this.max-a)*n;return(a-this.min)*n}getValueForDistanceFromCenter(a){if(ht(a))return NaN;let n=a/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-n:this.min+n}getPointLabelContext(a){let n=this._pointLabels||[];if(a>=0&&a<n.length){let s=n[a];return tN(this.getContext(),a,s)}}getPointPosition(a,n,s=0){let i=this.getIndexAngle(a)-po+s;return{x:Math.cos(i)*n+this.xCenter,y:Math.sin(i)*n+this.yCenter,angle:i}}getPointPositionForValue(a,n){return this.getPointPosition(a,this.getDistanceFromCenterForValue(n))}getBasePosition(a){return this.getPointPositionForValue(a||0,this.getBaseValue())}getPointLabelPosition(a){let{left:n,top:s,right:i,bottom:l}=this._pointLabelItems[a];return{left:n,top:s,right:i,bottom:l}}drawBackground(){let{backgroundColor:a,grid:{circular:n}}=this.options;if(a){let s=this.ctx;s.save(),s.beginPath(),mI(this,this.getDistanceFromCenterForValue(this._endValue),n,this._pointLabels.length),s.closePath(),s.fillStyle=a,s.fill(),s.restore()}}drawGrid(){let a=this.ctx,n=this.options,{angleLines:s,grid:i,border:l}=n,u=this._pointLabels.length,d,p,h;if(n.pointLabels.display)JB(this,u);if(i.display)this.ticks.forEach((g,b)=>{if(b!==0||b===0&&this.min<0){p=this.getDistanceFromCenterForValue(g.value);let y=this.getContext(b),v=i.setContext(y),T=l.setContext(y);eN(this,v,p,u,T)}});if(s.display){a.save();for(d=u-1;d>=0;d--){let g=s.setContext(this.getPointLabelContext(d)),{color:b,lineWidth:y}=g;if(!y||!b)continue;a.lineWidth=y,a.strokeStyle=b,a.setLineDash(g.borderDash),a.lineDashOffset=g.borderDashOffset,p=this.getDistanceFromCenterForValue(n.reverse?this.min:this.max),h=this.getPointPosition(d,p),a.beginPath(),a.moveTo(this.xCenter,this.yCenter),a.lineTo(h.x,h.y),a.stroke()}a.restore()}}drawBorder(){}drawLabels(){let a=this.ctx,n=this.options,s=n.ticks;if(!s.display)return;let i=this.getIndexAngle(0),l,u;a.save(),a.translate(this.xCenter,this.yCenter),a.rotate(i),a.textAlign="center",a.textBaseline="middle",this.ticks.forEach((d,p)=>{if(p===0&&this.min>=0&&!n.reverse)return;let h=s.setContext(this.getContext(p)),g=pa(h.font);if(l=this.getDistanceFromCenterForValue(this.ticks[p].value),h.showLabelBackdrop){a.font=g.string,u=a.measureText(d.label).width,a.fillStyle=h.backdropColor;let b=Na(h.backdropPadding);a.fillRect(-u/2-b.left,-l-g.size/2-b.top,u+b.width,g.size+b.height)}ei(a,d.label,0,-l,g,{color:h.color,strokeColor:h.textStrokeColor,strokeWidth:h.textStrokeWidth})}),a.restore()}drawTitle(){}}var Lm={millisecond:{common:!0,size:1,steps:1000},second:{common:!0,size:1000,steps:60},minute:{common:!0,size:60000,steps:60},hour:{common:!0,size:3600000,steps:24},day:{common:!0,size:86400000,steps:30},week:{common:!1,size:604800000,steps:4},month:{common:!0,size:2628000000,steps:12},quarter:{common:!1,size:7884000000,steps:4},year:{common:!0,size:31540000000}},bo=Object.keys(Lm);function NM(a,n){return a-n}function zM(a,n){if(ht(n))return null;let s=a._adapter,{parser:i,round:l,isoWeekday:u}=a._parseOpts,d=n;if(typeof i==="function")d=i(d);if(!Kt(d))d=typeof i==="string"?s.parse(d,i):s.parse(d);if(d===null)return null;if(l)d=l==="week"&&(Nu(u)||u===!0)?s.startOf(d,"isoWeek",u):s.startOf(d,l);return+d}function HM(a,n,s,i){let l=bo.length;for(let u=bo.indexOf(a);u<l-1;++u){let d=Lm[bo[u]],p=d.steps?d.steps:Number.MAX_SAFE_INTEGER;if(d.common&&Math.ceil((s-n)/(p*d.size))<=i)return bo[u]}return bo[l-1]}function oN(a,n,s,i,l){for(let u=bo.length-1;u>=bo.indexOf(s);u--){let d=bo[u];if(Lm[d].common&&a._adapter.diff(l,i,d)>=n-1)return d}return bo[s?bo.indexOf(s):0]}function nN(a){for(let n=bo.indexOf(a)+1,s=bo.length;n<s;++n)if(Lm[bo[n]].common)return bo[n]}function UM(a,n,s){if(!s)a[n]=!0;else if(s.length){let{lo:i,hi:l}=om(s,n),u=s[i]>=n?s[i]:s[l];a[u]=!0}}function sN(a,n,s,i){let l=a._adapter,u=+l.startOf(n[0].value,i),d=n[n.length-1].value,p,h;for(p=u;p<=d;p=+l.add(p,1,i))if(h=s[p],h>=0)n[h].major=!0;return n}function FM(a,n,s){let i=[],l={},u=n.length,d,p;for(d=0;d<u;++d)p=n[d],l[p]=d,i.push({value:p,major:!1});return u===0||!s?i:sN(a,i,l,s)}class Iv extends cl{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(a){super(a);this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(a,n={}){let s=a.time||(a.time={}),i=this._adapter=new UO._date(a.adapters.date);i.init(n),Ou(s.displayFormats,i.formats()),this._parseOpts={parser:s.parser,round:s.round,isoWeekday:s.isoWeekday},super.init(a),this._normalized=n.normalized}parse(a,n){if(a===void 0)return null;return zM(this,a)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){let a=this.options,n=this._adapter,s=a.time.unit||"day",{min:i,max:l,minDefined:u,maxDefined:d}=this.getUserBounds();function p(h){if(!u&&!isNaN(h.min))i=Math.min(i,h.min);if(!d&&!isNaN(h.max))l=Math.max(l,h.max)}if(!u||!d){if(p(this._getLabelBounds()),a.bounds!=="ticks"||a.ticks.source!=="labels")p(this.getMinMax(!1))}i=Kt(i)&&!isNaN(i)?i:+n.startOf(Date.now(),s),l=Kt(l)&&!isNaN(l)?l:+n.endOf(Date.now(),s)+1,this.min=Math.min(i,l-1),this.max=Math.max(i+1,l)}_getLabelBounds(){let a=this.getLabelTimestamps(),{POSITIVE_INFINITY:n,NEGATIVE_INFINITY:s}=Number;if(a.length)n=a[0],s=a[a.length-1];return{min:n,max:s}}buildTicks(){let a=this.options,{time:n,ticks:s}=a,i=s.source==="labels"?this.getLabelTimestamps():this._generate();if(a.bounds==="ticks"&&i.length)this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1];let l=this.min,u=this.max,d=Lk(i,l,u);if(this._unit=n.unit||(s.autoSkip?HM(n.minUnit,this.min,this.max,this._getLabelCapacity(l)):oN(this,d.length,n.minUnit,this.min,this.max)),this._majorUnit=!s.major.enabled||this._unit==="year"?void 0:nN(this._unit),this.initOffsets(i),a.reverse)d.reverse();return FM(this,d,this._majorUnit)}afterAutoSkip(){if(this.options.offsetAfterAutoskip)this.initOffsets(this.ticks.map((a)=>+a.value))}initOffsets(a=[]){let n=0,s=0,i,l;if(this.options.offset&&a.length){if(i=this.getDecimalForValue(a[0]),a.length===1)n=1-i;else n=(this.getDecimalForValue(a[1])-i)/2;if(l=this.getDecimalForValue(a[a.length-1]),a.length===1)s=l;else s=(l-this.getDecimalForValue(a[a.length-2]))/2}let u=a.length<3?0.5:0.25;n=mo(n,0,u),s=mo(s,0,u),this._offsets={start:n,end:s,factor:1/(n+1+s)}}_generate(){let a=this._adapter,n=this.min,s=this.max,i=this.options,l=i.time,u=l.unit||HM(l.minUnit,n,s,this._getLabelCapacity(n)),d=Ke(i.ticks.stepSize,1),p=u==="week"?l.isoWeekday:!1,h=Nu(p)||p===!0,g={},b=n,y,v;if(h)b=+a.startOf(b,"isoWeek",p);if(b=+a.startOf(b,h?"day":u),a.diff(s,n,u)>1e5*d)throw Error(n+" and "+s+" are too far apart with stepSize of "+d+" "+u);let T=i.ticks.source==="data"&&this.getDataTimestamps();for(y=b,v=0;y<s;y=+a.add(y,d,u),v++)UM(g,y,T);if(y===s||i.bounds==="ticks"||v===1)UM(g,y,T);return Object.keys(g).sort(NM).map((M)=>+M)}getLabelForValue(a){let n=this._adapter,s=this.options.time;if(s.tooltipFormat)return n.format(a,s.tooltipFormat);return n.format(a,s.displayFormats.datetime)}format(a,n){let i=this.options.time.displayFormats,l=this._unit,u=n||i[l];return this._adapter.format(a,u)}_tickFormatFunction(a,n,s,i){let l=this.options,u=l.ticks.callback;if(u)return Ot(u,[a,n,s],this);let d=l.time.displayFormats,p=this._unit,h=this._majorUnit,g=p&&d[p],b=h&&d[h],y=s[n],v=h&&b&&y&&y.major;return this._adapter.format(a,i||(v?b:g))}generateTickLabels(a){let n,s,i;for(n=0,s=a.length;n<s;++n)i=a[n],i.label=this._tickFormatFunction(i.value,n,a)}getDecimalForValue(a){return a===null?NaN:(a-this.min)/(this.max-this.min)}getPixelForValue(a){let n=this._offsets,s=this.getDecimalForValue(a);return this.getPixelForDecimal((n.start+s)*n.factor)}getValueForPixel(a){let n=this._offsets,s=this.getDecimalForPixel(a)/n.factor-n.end;return this.min+s*(this.max-this.min)}_getLabelSize(a){let n=this.options.ticks,s=this.ctx.measureText(a).width,i=Fs(this.isHorizontal()?n.maxRotation:n.minRotation),l=Math.cos(i),u=Math.sin(i),d=this._resolveTickFontOptions(0).size;return{w:s*l+d*u,h:s*u+d*l}}_getLabelCapacity(a){let n=this.options.time,s=n.displayFormats,i=s[n.unit]||s.millisecond,l=this._tickFormatFunction(a,0,FM(this,[a],this._majorUnit),i),u=this._getLabelSize(l),d=Math.floor(this.isHorizontal()?this.width/u.w:this.height/u.h)-1;return d>0?d:1}getDataTimestamps(){let a=this._cache.data||[],n,s;if(a.length)return a;let i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(n=0,s=i.length;n<s;++n)a=a.concat(i[n].controller.getAllParsedValues(this));return this._cache.data=this.normalize(a)}getLabelTimestamps(){let a=this._cache.labels||[],n,s;if(a.length)return a;let i=this.getLabels();for(n=0,s=i.length;n<s;++n)a.push(zM(this,i[n]));return this._cache.labels=this._normalized?a:this.normalize(a)}normalize(a){return Gx(a.sort(NM))}}function gm(a,n,s){let i=0,l=a.length-1,u,d,p,h;if(s){if(n>=a[i].pos&&n<=a[l].pos)({lo:i,hi:l}=Zr(a,"pos",n));({pos:u,time:p}=a[i]),{pos:d,time:h}=a[l]}else{if(n>=a[i].time&&n<=a[l].time)({lo:i,hi:l}=Zr(a,"time",n));({time:u,pos:p}=a[i]),{time:d,pos:h}=a[l]}let g=d-u;return g?p+(h-p)*(n-u)/g:p}class rN extends Iv{static id="timeseries";static defaults=Iv.defaults;constructor(a){super(a);this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){let a=this._getTimestampsForTable(),n=this._table=this.buildLookupTable(a);this._minPos=gm(n,this.min),this._tableRange=gm(n,this.max)-this._minPos,super.initOffsets(a)}buildLookupTable(a){let{min:n,max:s}=this,i=[],l=[],u,d,p,h,g;for(u=0,d=a.length;u<d;++u)if(h=a[u],h>=n&&h<=s)i.push(h);if(i.length<2)return[{time:n,pos:0},{time:s,pos:1}];for(u=0,d=i.length;u<d;++u)if(g=i[u+1],p=i[u-1],h=i[u],Math.round((g+p)/2)!==h)l.push({time:h,pos:u/(d-1)});return l}_generate(){let a=this.min,n=this.max,s=super.getDataTimestamps();if(!s.includes(a)||!s.length)s.splice(0,0,a);if(!s.includes(n)||s.length===1)s.push(n);return s.sort((i,l)=>i-l)}_getTimestampsForTable(){let a=this._cache.all||[];if(a.length)return a;let n=this.getDataTimestamps(),s=this.getLabelTimestamps();if(n.length&&s.length)a=this.normalize(n.concat(s));else a=n.length?n:s;return a=this._cache.all=a,a}getDecimalForValue(a){return(gm(this._table,a)-this._minPos)/this._tableRange}getValueForPixel(a){let n=this._offsets,s=this.getDecimalForPixel(a)/n.factor-n.end;return gm(this._table,s*this._tableRange+this._minPos,!0)}}dl.register(zv,Hv,Pv,Hu,Ov,fI,hI,dI,uI);var dR=Q(vI(),1);var er=Q(dt(),1);var Im=Q(dt(),1);var km=(...a)=>a.filter((n,s,i)=>Boolean(n)&&n.trim()!==""&&i.indexOf(n)===s).join(" ").trim();var SI=(a)=>a.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var LI=(a)=>a.replace(/^([A-Z])|[\s-_]+(\w)/g,(n,s,i)=>i?i.toUpperCase():s.toLowerCase());var qv=(a)=>{let n=LI(a);return n.charAt(0).toUpperCase()+n.slice(1)};var Kd=Q(dt(),1);var Mm={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var CI=(a)=>{for(let n in a)if(n.startsWith("aria-")||n==="role"||n==="title")return!0;return!1};var qu=Q(dt(),1),fN=qu.createContext({});var TI=()=>qu.useContext(fN);var wI=Kd.forwardRef(({color:a,size:n,strokeWidth:s,absoluteStrokeWidth:i,className:l="",children:u,iconNode:d,...p},h)=>{let{size:g=24,strokeWidth:b=2,absoluteStrokeWidth:y=!1,color:v="currentColor",className:T=""}=TI()??{},M=i??y?Number(s??b)*24/Number(n??g):s??b;return Kd.createElement("svg",{ref:h,...Mm,width:n??g??Mm.width,height:n??g??Mm.height,stroke:a??v,strokeWidth:M,className:km("lucide",T,l),...!u&&!CI(p)&&{"aria-hidden":"true"},...p},[...d.map(([I,w])=>Kd.createElement(I,w)),...Array.isArray(u)?u:[u]])});var we=(a,n)=>{let s=Im.forwardRef(({className:i,...l},u)=>Im.createElement(wI,{ref:u,iconNode:n,className:km(`lucide-${SI(qv(a))}`,`lucide-${a}`,i),...l}));return s.displayName=qv(a),s};var pN=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],ni=we("circle-alert",pN);var hN=[["path",{d:"M15 10V9",key:"4dkmfx"}],["path",{d:"M16.472 15a6 6 0 01-8.943 0",key:"7qomzy"}],["path",{d:"M9 10V9",key:"1lazqi"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],si=we("face-slightly-smiling",hN);var mN=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],Jd=we("activity",mN);var gN=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],ef=we("arrow-left",gN);var yN=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],pl=we("check",yN);var bN=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Ys=we("chevron-down",bN);var xN=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],tf=we("chevron-up",xN);var vN=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],hl=we("chevron-right",vN);var SN=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]],af=we("clock",SN);var LN=[["path",{d:"M13.744 17.736a6 6 0 1 1-7.48-7.48",key:"bq4yh3"}],["path",{d:"M15 6h1v4",key:"11y1tn"}],["path",{d:"m6.134 14.768.866-.5 2 3.464",key:"17snzx"}],["circle",{cx:"16",cy:"8",r:"6",key:"14bfc9"}]],ml=we("coins",LN);var CN=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],gl=we("copy",CN);var TN=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],of=we("cpu",TN);var wN=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],nf=we("folder",wN);var kN=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],sf=we("gauge",kN);var MN=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],rf=we("hash",MN);var IN=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],lf=we("inbox",IN);var AN=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],uf=we("layout-dashboard",AN);var RN=[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]],cf=we("list-tree",RN);var _N=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],df=we("menu",_N);var DN=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],ff=we("monitor",DN);var EN=[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]],pf=we("moon",EN);var ON=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],hf=we("plug",ON);var PN=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],yl=we("refresh-cw",PN);var BN=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],mf=we("star",BN);var NN=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],gf=we("sun",NN);var zN=[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]],yf=we("trending-up",zN);var HN=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],bf=we("wrench",HN);var UN=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],$s=we("x",UN);var FN=[["path",{d:"M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z",key:"1v7up4"}]],xf=we("zap",FN);var QI=Q(dt(),1);var Am=[{id:"overview",label:"Overview",icon:uf},{id:"requests",label:"Requests",icon:Jd},{id:"traces",label:"Traces",icon:cf},{id:"errors",label:"Errors",icon:ni},{id:"models",label:"Models",icon:of},{id:"providers",label:"Providers",icon:hf},{id:"tools",label:"Tools",icon:bf},{id:"costs",label:"Costs",icon:ml},{id:"behavior",label:"Behavior",shortLabel:"Behavior",icon:si},{id:"projects",label:"Projects",icon:nf},{id:"gain",label:"Gain",icon:yf}];var sn=Q(de(),1);function Vv({activeSection:a,onSectionChange:n,className:s=""}){return sn.jsxDEV("aside",{className:`stats-nav-rail ${s}`,children:[sn.jsxDEV("div",{className:"stats-nav-rail-header",children:sn.jsxDEV("div",{className:"stats-logo-container",children:[sn.jsxDEV("span",{className:"stats-logo-text",children:"OH MY PI"},void 0,!1,void 0,this),sn.jsxDEV("span",{className:"stats-logo-subtext",children:"Observability"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),sn.jsxDEV("nav",{className:"stats-nav-rail-menu",children:Am.map((i)=>{let l=i.id===a,u=i.icon;return sn.jsxDEV("button",{type:"button",onClick:()=>n(i.id),className:"stats-nav-rail-item","data-active":l?"true":"false","aria-current":l?"page":void 0,children:[sn.jsxDEV(u,{size:16,className:"stats-nav-rail-item-icon"},void 0,!1,void 0,this),sn.jsxDEV("span",{className:"stats-nav-rail-item-label",children:i.label},void 0,!1,void 0,this)]},i.id,!0,void 0,this)})},void 0,!1,void 0,this),sn.jsxDEV("div",{className:"stats-nav-rail-footer",children:sn.jsxDEV("span",{className:"stats-version-tag",children:"OMP Stats v1.0.0"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var jv=Q(de(),1),VN=[{value:"1h",label:"1h"},{value:"24h",label:"24h"},{value:"7d",label:"7d"},{value:"30d",label:"30d"},{value:"90d",label:"90d"},{value:"all",label:"All"}];function kI({value:a,onChange:n,className:s=""}){return jv.jsxDEV("div",{className:`stats-range-control ${s}`,role:"radiogroup","aria-label":"Select time range",children:VN.map((i)=>{let l=i.value===a;return jv.jsxDEV("button",{type:"button",role:"radio","aria-checked":l,"data-active":l?"true":"false",className:"stats-range-control-btn",onClick:()=>n(i.value),children:i.label},i.value,!1,void 0,this)})},void 0,!1,void 0,this)}var Gv=Q(dt(),1);class MI extends Error{status;endpoint;constructor(a,n,s){super(s);this.name="ApiError",this.status=a,this.endpoint=n}}async function ao(a,n){let s=await fetch(a,n);if(!s.ok)throw new MI(s.status,a,`HTTP error ${s.status} on ${a}`);return s.json()}async function II(a="24h",n){return ao(`/api/stats/overview?range=${encodeURIComponent(a)}`,{signal:n})}async function AI(a="24h",n){return ao(`/api/stats/model-dashboard?range=${encodeURIComponent(a)}`,{signal:n})}async function RI(a="24h",n){return ao(`/api/stats/costs?range=${encodeURIComponent(a)}`,{signal:n})}async function Rm(a=50,n){return ao(`/api/stats/recent?limit=${a}`,{signal:n})}async function _I(a="24h",n=50,s){return ao(`/api/stats/errors?range=${encodeURIComponent(a)}&limit=${n}`,{signal:s})}async function DI(a,n){return ao(`/api/request/${a}`,{signal:n})}async function EI(a){return ao("/api/sync",{signal:a})}async function OI(a="24h",n){return ao(`/api/stats/behavior?range=${encodeURIComponent(a)}`,{signal:n})}async function PI(a="24h",n){return ao(`/api/stats/folders?range=${encodeURIComponent(a)}`,{signal:n})}async function BI(a="24h",n,s){let i=new URLSearchParams({range:a});if(n)i.set("project",n);return ao(`/api/stats/gain?${i}`,{signal:s})}async function NI(a="24h",n){return ao(`/api/stats/tools?range=${encodeURIComponent(a)}`,{signal:n})}async function zI(a="24h",n){return ao(`/api/stats/providers?range=${encodeURIComponent(a)}`,{signal:n})}async function HI(a=100,n,s){let i=new URLSearchParams({limit:String(a)});if(n)i.set("q",n);return ao(`/api/sessions?${i}`,{signal:s})}async function UI(a,n){return ao(`/api/session/trace?file=${encodeURIComponent(a)}`,{signal:n})}async function FI(a,n,s){return ao(`/api/session/entry?file=${encodeURIComponent(a)}&id=${encodeURIComponent(n)}`,{signal:s})}var vf=Q(de(),1);function qI({onSyncStart:a,onSyncComplete:n,className:s=""}){let[i,l]=Gv.useState(!1),[u,d]=Gv.useState(null),p=async()=>{if(i)return;if(l(!0),d(null),a)a();try{let h=await EI(),g={processed:typeof h?.processed==="number"?h.processed:0,files:typeof h?.files==="number"?h.files:0,totalMessages:typeof h?.totalMessages==="number"?h.totalMessages:0};if(d({type:"success",message:`Synced: ${g.processed} new request${g.processed===1?"":"s"} found.`}),n)n({success:!0,data:g})}catch(h){let g=h instanceof Error?h.message:String(h);if(d({type:"error",message:`Sync failed: ${g}`}),n)n({success:!1,error:g})}finally{l(!1)}};return vf.jsxDEV("div",{className:`stats-sync-container ${s}`,children:[u&&vf.jsxDEV("span",{className:"stats-sync-status-msg","data-type":u.type,children:u.message},void 0,!1,void 0,this),vf.jsxDEV("button",{type:"button",onClick:p,disabled:i,className:"stats-button stats-button-primary stats-sync-btn","aria-busy":i,children:[vf.jsxDEV(yl,{size:14,className:`stats-sync-icon ${i?"stats-spin":""}`},void 0,!1,void 0,this),i?"Syncing...":"Sync DB"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var _m=Q(dt(),1),VI="omp-stats-theme",jI="(prefers-color-scheme: dark)";function jN(){if(typeof localStorage>"u")return"system";let a=localStorage.getItem(VI);return a==="light"||a==="dark"||a==="system"?a:"system"}function GI(){if(typeof window>"u")return"dark";return window.matchMedia(jI).matches?"dark":"light"}var xl=jN(),Sf=xl==="system"?GI():xl,Xv=new Set;function XI(){for(let a of Xv)a()}function Yv(){if(Sf=xl==="system"?GI():xl,typeof document<"u")document.documentElement.dataset.theme=Sf,document.documentElement.style.colorScheme=Sf}if(typeof window<"u")Yv(),window.matchMedia(jI).addEventListener("change",()=>{if(xl==="system")Yv(),XI()});function GN(a){if(xl=a,typeof localStorage<"u")localStorage.setItem(VI,a);Yv(),XI()}function $v(a){return Xv.add(a),()=>Xv.delete(a)}function $t(){return _m.useSyncExternalStore($v,()=>Sf,()=>"dark")}function YI(){let a=_m.useSyncExternalStore($v,()=>xl,()=>"system"),n=_m.useSyncExternalStore($v,()=>Sf,()=>"dark");return{preference:a,resolved:n,setPreference:GN}}var Wv=Q(de(),1),XN={system:"light",light:"dark",dark:"system"},YN={system:ff,light:gf,dark:pf},$I={system:"System theme",light:"Light theme",dark:"Dark theme"};function WI(){let{preference:a,setPreference:n}=YI(),s=YN[a];return Wv.jsxDEV("button",{type:"button",className:"stats-theme-toggle",onClick:()=>n(XN[a]),"aria-label":`${$I[a]} (click to switch)`,title:`${$I[a]} — click to switch`,children:Wv.jsxDEV(s,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var rn=Q(de(),1);function ZI({activeSection:a,range:n,onRangeChange:s,updatedAt:i,onSyncStart:l,onSyncComplete:u,onMenuToggle:d,className:p=""}){let g=Am.find((y)=>y.id===a)?.label||"Observability",b=(y)=>{if(!y)return"Not updated";return`Updated ${new Date(y).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}`};return rn.jsxDEV("header",{className:`stats-top-bar ${p}`,children:[rn.jsxDEV("div",{className:"stats-top-bar-left",children:[d&&rn.jsxDEV("button",{type:"button",onClick:d,className:"stats-mobile-menu-btn","aria-label":"Open navigation menu",children:rn.jsxDEV(df,{size:20},void 0,!1,void 0,this)},void 0,!1,void 0,this),rn.jsxDEV("h1",{className:"stats-page-title",children:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this),rn.jsxDEV("div",{className:"stats-top-bar-right",children:[rn.jsxDEV("div",{className:"stats-top-bar-meta",children:rn.jsxDEV("span",{className:"stats-last-updated",title:i?new Date(i).toLocaleString():void 0,children:b(i)},void 0,!1,void 0,this)},void 0,!1,void 0,this),rn.jsxDEV(kI,{value:n,onChange:s},void 0,!1,void 0,this),rn.jsxDEV(WI,{},void 0,!1,void 0,this),rn.jsxDEV(qI,{onSyncStart:l,onSyncComplete:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ga=Q(de(),1);function KI({activeSection:a,onSectionChange:n,range:s,onRangeChange:i,updatedAt:l,onSyncStart:u,onSyncComplete:d,children:p}){let[h,g]=QI.useState(!1),b=(y)=>{n(y),g(!1)};return Ga.jsxDEV("div",{className:"stats-app-container",children:[Ga.jsxDEV(Vv,{activeSection:a,onSectionChange:b,className:"stats-desktop-nav"},void 0,!1,void 0,this),h&&Ga.jsxDEV("div",{className:"stats-mobile-drawer-overlay",onClick:()=>g(!1),role:"presentation",children:Ga.jsxDEV("div",{className:"stats-mobile-drawer",onClick:(y)=>y.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Navigation menu",children:[Ga.jsxDEV("div",{className:"stats-mobile-drawer-header",children:[Ga.jsxDEV("div",{className:"stats-logo-container",children:[Ga.jsxDEV("span",{className:"stats-logo-text",children:"OH MY PI"},void 0,!1,void 0,this),Ga.jsxDEV("span",{className:"stats-logo-subtext",children:"Observability"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ga.jsxDEV("button",{type:"button",onClick:()=>g(!1),className:"stats-drawer-close-btn","aria-label":"Close navigation menu",children:Ga.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ga.jsxDEV(Vv,{activeSection:a,onSectionChange:b,className:"stats-mobile-nav"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Ga.jsxDEV("div",{className:"stats-main-pane",children:[Ga.jsxDEV(ZI,{activeSection:a,range:s,onRangeChange:i,updatedAt:l,onSyncStart:u,onSyncComplete:d,onMenuToggle:()=>g(!0)},void 0,!1,void 0,this),Ga.jsxDEV("main",{className:"stats-content-area",children:Ga.jsxDEV("div",{className:"stats-content-inner",children:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var rs=Q(dt(),1),$N=["overview","requests","traces","errors","models","providers","tools","costs","behavior","projects","gain"],JI=["1h","24h","7d","30d","90d","all"];function Zv(a){let n=a.replace(/^#\/?/,""),[s,i]=n.split("?"),l=$N.includes(s)?s:"overview",u="24h",d=null;if(i){let p=new URLSearchParams(i),h=p.get("range");if(JI.includes(h))u=h;d=p.get("s")}return{section:l,range:u,session:d}}function Qv(a,n,s){let i=s?`&s=${encodeURIComponent(s)}`:"";return`/${a}?range=${n}${i}`}function eA(){let[a,n]=rs.useState(()=>Zv(window.location.hash));rs.useEffect(()=>{let d=()=>{n(Zv(window.location.hash))};return window.addEventListener("hashchange",d),()=>{window.removeEventListener("hashchange",d)}},[]);let s=rs.useCallback((d,p,h)=>{window.location.hash=Qv(d,p,h)},[]),i=rs.useCallback((d)=>{s(d,a.range,d==="traces"?a.session:null)},[a.range,a.session,s]),l=rs.useCallback((d)=>{let p=JI.includes(d)?d:"24h";s(a.section,p,a.session)},[a.section,a.session,s]),u=rs.useCallback((d)=>{s(a.section,a.range,d)},[a.section,a.range,s]);return rs.useEffect(()=>{let d=window.location.hash,p=Zv(d),h=`#${Qv(p.section,p.range,p.session)}`;if(d!==h)window.location.hash=Qv(p.section,p.range,p.session)},[]),{section:a.section,setSection:i,range:a.range,setRange:l,session:a.session,setSession:u}}var tA=["January","February","March","April","May","June","July","August","September","October","November","December"],aA=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],WN=["MMMM","yyyy","EEEE","MMM","EEE","yy","MM","dd","HH","hh","mm","ss","M","d","H","h","m","s","a"];function ri(a,n=2){return String(a).padStart(n,"0")}function ZN(a,n){let s=a.getMonth(),i=a.getDay(),l=a.getHours(),u=l%12||12;switch(n){case"yyyy":return ri(a.getFullYear(),4);case"yy":return ri(a.getFullYear()%100);case"MMMM":return tA[s];case"MMM":return tA[s].slice(0,3);case"MM":return ri(s+1);case"M":return String(s+1);case"dd":return ri(a.getDate());case"d":return String(a.getDate());case"EEEE":return aA[i];case"EEE":return aA[i].slice(0,3);case"HH":return ri(l);case"H":return String(l);case"hh":return ri(u);case"h":return String(u);case"mm":return ri(a.getMinutes());case"m":return String(a.getMinutes());case"ss":return ri(a.getSeconds());case"s":return String(a.getSeconds());case"a":return l<12?"AM":"PM"}}function nA(a){let n=a instanceof Date?new Date(a.getTime()):new Date(a);if(Number.isNaN(n.getTime()))throw RangeError("Invalid time value");return n}function Cn(a,n){let s=nA(a),i="";for(let l=0;l<n.length;){if(n[l]==="'"){if(n[l+1]==="'"){i+="'",l+=2;continue}l++;while(l<n.length){if(n[l]!=="'"){i+=n[l++];continue}if(n[l+1]==="'"){i+="'",l+=2;continue}l++;break}continue}let u=n.slice(l),d=WN.find((h)=>u.startsWith(h));if(d){i+=ZN(s,d),l+=d.length;continue}let p=n[l++];if(/[A-Za-z]/.test(p))throw RangeError(`Format string contains an unescaped latin alphabet character \`${p}\``);i+=p}return i}function ii(a,n){return`${a} ${a===1?n:`${n}s`}`}function QN(a,n){let s=(n.getFullYear()-a.getFullYear())*12+n.getMonth()-a.getMonth();if(s===0)return 0;let i=new Date(a);i.setDate(1),i.setFullYear(a.getFullYear(),a.getMonth()+s,1);let l=new Date(i.getFullYear(),i.getMonth()+1,0).getDate();if(i.setDate(Math.min(a.getDate(),l)),i.getTime()>n.getTime())s--;return s}function oA(a,n){let s=(n.getTime()-a.getTime())/1000,i=(n.getTimezoneOffset()-a.getTimezoneOffset())*60,l=Math.round((s-i)/60);if(l<2)return l===0?"less than a minute":"1 minute";if(l<45)return ii(l,"minute");if(l<90)return"about 1 hour";if(l<1440)return`about ${ii(Math.round(l/60),"hour")}`;if(l<2520)return"1 day";if(l<43200)return ii(Math.round(l/1440),"day");if(l<86400)return`about ${ii(Math.round(l/43200),"month")}`;let u=QN(a,n);if(u<12)return ii(Math.round(l/43200),"month");let d=Math.trunc(u/12),p=u%12;if(p<3)return`about ${ii(d,"year")}`;if(p<9)return`over ${ii(d,"year")}`;return`almost ${ii(d+1,"year")}`}function sA(a,n={}){let s=nA(a),i=new Date(Date.now()),l=s.getTime()>i.getTime(),u=l?oA(i,s):oA(s,i);if(!n.addSuffix)return u;return l?`in ${u}`:`${u} ago`}var ba=Q(dt(),1);var Kv=Q(rA(),1),Ho=Q(dt(),1);var lA="label";function iA(a,n){if(typeof a==="function")a(n);else if(a)a.current=n}function JN(a,n){let s=a.options;if(s&&n)Object.assign(s,n)}function uA(a,n){a.labels=n}function cA(a,n,s=lA){let i=[];a.datasets=n.map((l)=>{let u=a.datasets.find((d)=>d[s]===l[s]);if(!u||!l.data||i.includes(u))return{...l};return i.push(u),Object.assign(u,l),u})}function ez(a,n=lA){let s={labels:[],datasets:[]};return uA(s,a.labels),cA(s,a.datasets,n),s}function tz(a,n){let{height:s=150,width:i=300,redraw:l=!1,datasetIdKey:u,type:d,data:p,options:h,plugins:g=[],fallbackContent:b,updateMode:y,...v}=a,T=Ho.useRef(null),M=Ho.useRef(null),I=()=>{if(!T.current)return;M.current=new dl(T.current,{type:d,data:ez(p,u),options:h&&{...h},plugins:g}),iA(n,M.current)},w=()=>{if(iA(n,null),M.current)M.current.destroy(),M.current=null};return Ho.useEffect(()=>{if(!l&&M.current&&h)JN(M.current,h)},[l,h]),Ho.useEffect(()=>{if(!l&&M.current)uA(M.current.config.data,p.labels)},[l,p.labels]),Ho.useEffect(()=>{if(!l&&M.current&&p.datasets)cA(M.current.config.data,p.datasets,u)},[l,p.datasets]),Ho.useEffect(()=>{if(!M.current)return;if(l)w(),setTimeout(I);else M.current.update(y)},[l,h,p.labels,p.datasets,y]),Ho.useEffect(()=>{if(!M.current)return;w(),setTimeout(I)},[d]),Ho.useEffect(()=>(I(),()=>w()),[]),Kv.jsx("canvas",{ref:T,role:"img",height:s,width:i,...v,children:b})}var az=Ho.forwardRef(tz);function dA(a,n){return dl.register(n),Ho.forwardRef((s,i)=>Kv.jsx(az,{...s,ref:i,type:a}))}var Xa=dA("line",_v),li=dA("bar",Rv);var bt=["#ed4abf","#9b4dff","#5ad8e6","#62d394","#c77dff","#ff8fd1","#f5c14b","#ff6b7d"];function fA(a){let n=[...a].sort((s,i)=>i.totalRequests-s.totalRequests||`${s.model}::${s.provider}`.localeCompare(`${i.model}::${i.provider}`));return new Map(n.map((s,i)=>[`${s.model}::${s.provider}`,bt[i%bt.length]]))}var sa={dark:{legendLabel:"#a89fb3",tooltipBackground:"#241a2e",tooltipTitle:"#eae5ef",tooltipBody:"#a89fb3",tooltipBorder:"rgba(255, 255, 255, 0.12)",grid:"rgba(255, 255, 255, 0.06)",tick:"#867a93"},light:{legendLabel:"#5a5462",tooltipBackground:"#ffffff",tooltipTitle:"#241a2e",tooltipBody:"#5a5462",tooltipBorder:"rgba(20, 12, 28, 0.15)",grid:"rgba(20, 12, 28, 0.08)",tick:"#6a6275"}};function is(a){let{chartTheme:n,showLegend:s,defaultLabel:i,formatValue:l,footer:u}=a;return{legend:{display:s,position:"top",align:"start",labels:{color:n.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:n.tooltipBackground,titleColor:n.tooltipTitle,bodyColor:n.tooltipBody,borderColor:n.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(d)=>{let p=d.dataset.label??i,h=d.parsed.y??0;return`${p}: ${l(h)}`},...u?{footer:u}:{}}}}}function ls(a){let{chartTheme:n,formatY:s}=a,i={grid:{color:n.grid,drawBorder:!1},ticks:{color:n.tick,font:{size:11}}},l={...i,ticks:{...i.ticks,callback:(u)=>s(Number(u))},min:0};return{sharedScaleBase:i,yScale:l}}function Vu(a){return{borderColor:a,backgroundColor:`${a}20`,fill:!0,tension:0,pointRadius:3,pointHoverRadius:4,borderWidth:2}}function Sl(a){return{backgroundColor:a,borderColor:a,borderWidth:0,borderRadius:4,maxBarThickness:56}}function ui(a,n){return a.datasets.map((s,i)=>({label:s.label,data:s.data,...n(i)}))}function Dm(a,n,s){if(a.length===0)return{labels:[],datasets:[]};let{initBucket:i,accumulate:l,bucketToValue:u}=s,d=new Map;for(let h of a){let g=d.get(h.timestamp)??i();l(g,h),d.set(h.timestamp,g)}let p=[...d.entries()].sort((h,g)=>h[0]-g[0]);return{labels:p.map(([h])=>Cn(new Date(h),"MMM d")),datasets:[{label:n,data:p.map(([,h])=>u(h))}]}}function ju(a,n){if(a.length===0)return{labels:[],datasets:[]};let{topN:s=5,rankWeight:i,initBucket:l,accumulate:u,bucketToValue:d}=n,p=new Map;for(let A of a){let B=`${A.model}::${A.provider}`,z=p.get(B);if(z)z.weight+=i(A);else p.set(B,{model:A.model,provider:A.provider,weight:i(A)})}let g=[...p.entries()].sort((A,B)=>B[1].weight-A[1].weight).slice(0,s),b=new Set(g.map(([A])=>A)),y=new Map;for(let[,{model:A}]of g)y.set(A,(y.get(A)??0)+1);let v=new Map;for(let[A,{model:B,provider:z}]of g)v.set(A,(y.get(B)??0)>1?`${B} (${z})`:B);let T=[...new Set(a.map((A)=>A.timestamp))].sort((A,B)=>A-B),M=g.map(([A])=>v.get(A)??A);if(a.some((A)=>!b.has(`${A.model}::${A.provider}`)))M.push("Other");let w=new Map;for(let A of T)w.set(A,{});for(let A of a){let B=`${A.model}::${A.provider}`,z=b.has(B)?v.get(B)??A.model:"Other",H=w.get(A.timestamp);if(!H)continue;let V=H[z]??l();u(V,A),H[z]=V}return{labels:T.map((A)=>Cn(new Date(A),"MMM d")),datasets:M.map((A)=>({label:A,data:T.map((B)=>{let z=w.get(B)?.[A];return z?d(z):0})}))}}var Wt=Q(de(),1);function Ws(a){return{borderColor:a,backgroundColor:"transparent",tension:0.4,pointRadius:0,borderWidth:2}}function Em({timestamps:a,values:n,color:s}){let i={labels:a.map((u)=>Cn(new Date(u),"MMM d")),datasets:[{data:n,...Ws(s)}]};return Wt.jsxDEV(Xa,{data:i,options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},scales:{x:{display:!1},y:{display:!1,min:0}}}},void 0,!1,void 0,this)}function Om(a){return{legend:{display:!0,position:"top",labels:{color:a.legendLabel,usePointStyle:!0,padding:16,font:{size:12}}},tooltip:{backgroundColor:a.tooltipBackground,titleColor:a.tooltipTitle,bodyColor:a.tooltipBody,borderColor:a.tooltipBorder,borderWidth:1,cornerRadius:8}}}function pA(a){return{x:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}},min:0}}}function hA(a){return{x:{grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y:{type:"linear",display:!0,position:"left",grid:{color:a.grid},ticks:{color:a.tick,font:{size:11}}},y1:{type:"linear",display:!0,position:"right",grid:{drawOnChartArea:!1},ticks:{color:a.tick,font:{size:11}}}}}function Pm({title:a,subtitle:n,children:s}){return Wt.jsxDEV("div",{className:"stats-panel overflow-hidden",children:[Wt.jsxDEV("div",{className:"px-5 py-4 border-b border-[var(--border-subtle)]",children:[Wt.jsxDEV("h3",{className:"text-sm font-semibold text-[var(--text-primary)]",children:a},void 0,!1,void 0,this),n?Wt.jsxDEV("p",{className:"text-xs text-[var(--text-muted)] mt-1",children:n},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),Wt.jsxDEV("div",{className:"overflow-x-auto",children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function oz(a){if(a==="right")return"text-right";if(a==="center")return"text-center";return""}function Bm({columns:a,gridTemplate:n}){return Wt.jsxDEV("div",{className:"grid gap-3 px-5 py-3 text-[var(--text-muted)] text-xs uppercase tracking-wider font-semibold",style:{gridTemplateColumns:n},children:[a.map((s)=>Wt.jsxDEV("div",{className:oz(s.align),children:s.label},s.label,!1,void 0,this)),Wt.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Nm({children:a}){return Wt.jsxDEV("div",{className:"max-h-[calc(100vh-300px)] overflow-y-auto",children:a},void 0,!1,void 0,this)}function zm({model:a,provider:n}){return Wt.jsxDEV("div",{children:[Wt.jsxDEV("div",{className:"font-medium text-[var(--text-primary)]",children:a},void 0,!1,void 0,this),Wt.jsxDEV("div",{className:"text-xs text-[var(--text-muted)]",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Hm({gridTemplate:a,cells:n,trendCell:s,isExpanded:i,onToggle:l,expandedContent:u}){return Wt.jsxDEV("div",{className:"border-t border-[var(--border-subtle)]",children:[Wt.jsxDEV("button",{type:"button",onClick:l,className:"w-full bg-transparent border-none text-left px-5 py-3 cursor-pointer hover:bg-[var(--bg-hover)] transition-colors",children:Wt.jsxDEV("div",{className:"grid gap-3 items-center",style:{gridTemplateColumns:a},children:[n,Wt.jsxDEV("div",{className:"h-10",children:s},void 0,!1,void 0,this),Wt.jsxDEV("div",{className:"flex justify-center text-[var(--text-muted)]",children:i?Wt.jsxDEV(tf,{size:16},void 0,!1,void 0,this):Wt.jsxDEV(Ys,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),i?Wt.jsxDEV("div",{className:"px-5 py-4 bg-[var(--bg-elevated)] border-t border-[var(--border-subtle)]",children:u},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}function Um(){return Wt.jsxDEV("div",{className:"text-[var(--text-muted)] text-center text-sm",children:"-"},void 0,!1,void 0,this)}function Fm({message:a="No data available"}){return Wt.jsxDEV("div",{className:"h-full flex items-center justify-center text-[var(--text-muted)] text-sm",children:a},void 0,!1,void 0,this)}function Ce(a){return a.toLocaleString()}function lt(a){return a.toLocaleString(void 0,{notation:"compact"})}function us(a,n){if(a===0)return"$0";let s=n!==void 0?n:a>0&&a<0.01?4:2;return`$${a.toLocaleString(void 0,{minimumFractionDigits:s,maximumFractionDigits:s})}`}function ka(a,n,s){return a===0&&n>0?"N/A":us(a,s)}function ln(a,n){let s=a.provider==="xai-oauth"&&a.usage.totalTokens>0&&a.usage.cost.total===0?1:0;return ka(a.usage.cost.total,s,n)}function Ht(a,n=1){return`${(a*100).toFixed(n)}%`}function rt(a,n){if(a===null)return"-";let s=a/1000,i=n!==void 0?n:s<1?2:1;return`${s.toFixed(i)}s`}function qm(a){if(a===null)return"-";return a.toFixed(1)}function za(a){return sA(new Date(a),{addSuffix:!0})}function Jv(a){if(a>=1e9)return`${(a/1e9).toFixed(1)} GB`;if(a>=1e6)return`${(a/1e6).toFixed(1)} MB`;if(a>=1000)return`${(a/1000).toFixed(1)} KB`;return`${a} B`}var Ha=Q(dt(),1),ci=new Map,nz=64;function Vt(a,n,s){let i=JSON.stringify(a),[l,u]=Ha.useState(()=>ci.get(i)?.data??null),[d,p]=Ha.useState(null),[h,g]=Ha.useState(()=>!ci.has(i)),[b,y]=Ha.useState(!1),[v,T]=Ha.useState(()=>ci.get(i)?.updatedAt??null),M=Ha.useRef(n);M.current=n;let I=Ha.useRef(i);I.current=i;let w=s?.enabled??!0,A=s?.pollMs,B=Ha.useRef(null),z=Ha.useRef(!1);z.current=l!==null;let H=Ha.useCallback(async(G)=>{if(B.current)B.current.abort();let X=new AbortController;if(B.current=X,G)y(!0);else g(!0),u(null);p(null);try{let Y=await M.current(X.signal);if(X.signal.aborted)return;if(ci.set(I.current,{data:Y,updatedAt:Date.now()}),ci.size>nz){let J=ci.keys().next().value;if(J!==void 0)ci.delete(J)}u(Y),T(Date.now()),p(null)}catch(Y){if(X.signal.aborted)return;p(Y instanceof Error?Y:Error(String(Y)))}finally{if(!X.signal.aborted){if(g(!1),y(!1),B.current===X)B.current=null}}},[]);Ha.useEffect(()=>{if(!w){g(!1),y(!1);return}let G=ci.get(i);if(G)u(G.data),T(G.updatedAt),g(!1),H(!0);else H(z.current);return()=>{if(B.current)B.current.abort(),B.current=null}},[i,w,H]),Ha.useEffect(()=>{if(!w||!A)return;let G=setInterval(()=>{if(document.hidden)return;H(!0)},A);return()=>{clearInterval(G)}},[w,A,H]);let V=Ha.useCallback(async()=>{await H(!0)},[H]);return{data:l,error:d,loading:h,refreshing:b,refetch:V,updatedAt:v}}var mA=3600000,Vm=24*mA,sz=300000,gA={"1h":{windowLabel:"the last hour",trendLabel:"1h Trend",bucketMs:sz,bucketCount:12,tickFormat:"HH:mm"},"24h":{windowLabel:"the last 24 hours",trendLabel:"24h Trend",bucketMs:mA,bucketCount:24,tickFormat:"HH:mm"},"7d":{windowLabel:"the last 7 days",trendLabel:"7d Trend",bucketMs:Vm,bucketCount:7,tickFormat:"MMM d"},"30d":{windowLabel:"the last 30 days",trendLabel:"30d Trend",bucketMs:Vm,bucketCount:30,tickFormat:"MMM d"},"90d":{windowLabel:"the last 90 days",trendLabel:"90d Trend",bucketMs:Vm,bucketCount:90,tickFormat:"MMM d"},all:{windowLabel:"all time",trendLabel:"Trend",bucketMs:Vm,bucketCount:0,tickFormat:"MMM d"}};function Ll(a){return gA[a]}function Lf(a,n){return Cn(new Date(a),gA[n].tickFormat)}var rz=["main","subagent","advisor"];function jm(a){return a.totalInputTokens+a.totalOutputTokens+a.totalCacheReadTokens+a.totalCacheWriteTokens}function yA(a){let n=new Map;for(let d of a)n.set(d.agentType,d);let s=rz.map((d)=>n.get(d)).filter((d)=>d!==void 0),i=s.reduce((d,p)=>d+jm(p),0),l=s.reduce((d,p)=>d+p.totalCost,0),u=s.map((d)=>{let p=jm(d);return{agentType:d.agentType,tokens:p,requests:d.totalRequests,cost:d.totalCost,share:i>0?p/i:0}});return{totalTokens:i,totalCost:l,segments:u}}function bA(a){let n=a.reduce((h,g)=>h+g.cost,0),s=a.reduce((h,g)=>h+g.unpricedRequests,0),i=new Set(a.map((h)=>h.timestamp)).size,l=i>0?n/i:0,u=new Map;for(let h of a)u.set(h.model,(u.get(h.model)??0)+h.cost);let d="",p=0;for(let[h,g]of u)if(g>p)d=h,p=g;return{totalCost:n,unpricedRequests:s,avgDailyCost:l,topModelName:d,topModelCost:p}}function xA(a,n){if(a.length===0)return new Map;let s=Ll(n),{bucketMs:i,bucketCount:l}=s,u=l>0?(()=>{let h=a.reduce((y,v)=>Math.max(y,v.timestamp),0),b=(h>0?h:Math.floor(Date.now()/i)*i)-(l-1)*i;return Array.from({length:l},(y,v)=>b+v*i)})():Array.from(new Set(a.map((h)=>h.timestamp))).sort((h,g)=>h-g),d=new Map(u.map((h,g)=>[h,g])),p=new Map;for(let h of a){let g=`${h.model}::${h.provider}`,b=p.get(g);if(!b)b={label:`${h.model} (${h.provider})`,data:u.map((v)=>({timestamp:v,avgTtftSeconds:null,avgTokensPerSecond:null,requests:0}))},p.set(g,b);let y=d.get(h.timestamp);if(y===void 0)continue;b.data[y]={timestamp:h.timestamp,avgTtftSeconds:h.avgTtft!==null?h.avgTtft/1000:null,avgTokensPerSecond:h.avgTokensPerSecond,requests:h.requests}}return p}function vA(a,n){let s=a.totalNegation+a.totalRepetition+a.totalBlame,i=new Map;for(let u of n){let d=`${u.model}::${u.provider}`,p=i.get(d),h=u.yelling+u.profanity+u.anguish+u.negation+u.repetition+u.blame;if(p)p.score+=h;else i.set(d,{model:u.model,provider:u.provider,score:h})}let l=null;for(let u of i.values())if(!l||u.score>l.score)l=u;return{totalMessages:a.totalMessages,totalYelling:a.totalYelling,totalProfanity:a.totalProfanity,totalAnguish:a.totalAnguish,totalFrustration:s,highestFrictionModel:l}}function SA(a){let n=[...a].sort((l,u)=>{if(u.totalCost!==l.totalCost)return u.totalCost-l.totalCost;return u.totalRequests-l.totalRequests}),s=n.reduce((l,u)=>Math.max(l,u.totalCost),0),i=n.reduce((l,u)=>Math.max(l,u.totalRequests),0);return n.map((l)=>({...l,costPercentage:s>0?l.totalCost/s*100:0,requestsPercentage:i>0?l.totalRequests/i*100:0}))}function LA(a){let n=a.reduce((s,i)=>Math.max(s,i.calls),0);return a.map((s)=>({...s,errorRate:s.calls>0?s.errors/s.calls:0,callsPercentage:n>0?s.calls/n*100:0}))}var Gm=Q(de(),1);function Gu({message:a="No data available",icon:n=lf,className:s=""}){return Gm.jsxDEV("div",{className:`stats-empty-state ${s}`,children:[Gm.jsxDEV(n,{size:24,className:"stats-empty-state-icon","aria-hidden":"true"},void 0,!1,void 0,this),Gm.jsxDEV("p",{className:"stats-empty-state-message",children:a},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Xu=Q(de(),1);function CA({error:a,onRetry:n,className:s=""}){return Xu.jsxDEV("div",{className:`stats-error-state ${s}`,children:Xu.jsxDEV("div",{className:"stats-error-state-content",children:[Xu.jsxDEV("h4",{className:"stats-error-state-title",children:"Failed to load data"},void 0,!1,void 0,this),a&&Xu.jsxDEV("p",{className:"stats-error-state-message",children:a.message},void 0,!1,void 0,this),n&&Xu.jsxDEV("button",{type:"button",onClick:n,className:"stats-button stats-button-secondary stats-error-state-btn",children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var TA=Q(de(),1);function Ua({variant:a="text",width:n,height:s,className:i=""}){let l={width:n!==void 0?typeof n==="number"?`${n}px`:n:void 0,height:s!==void 0?typeof s==="number"?`${s}px`:s:void 0};return TA.jsxDEV("div",{className:`stats-skeleton ${i}`,"data-variant":a,style:l},void 0,!1,void 0,this)}var Uo=Q(de(),1);function Rt({loading:a,error:n,data:s,empty:i=!1,emptyText:l="No data available",fallback:u,onRetry:d,children:p}){if(n&&s===null)return Uo.jsxDEV(CA,{error:n,onRetry:d},void 0,!1,void 0,this);if(a&&s===null){if(u)return Uo.jsxDEV(Uo.Fragment,{children:u},void 0,!1,void 0,this);return Uo.jsxDEV("div",{className:"stats-boundary-skeleton",children:[Uo.jsxDEV(Ua,{variant:"text",width:"60%",height:24,className:"mb-4"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"rect",width:"100%",height:160,className:"mb-4"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"text",width:"80%",height:20,className:"mb-2"},void 0,!1,void 0,this),Uo.jsxDEV(Ua,{variant:"text",width:"40%",height:20},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}if(!a&&(i||s===null))return Uo.jsxDEV(Gu,{message:l},void 0,!1,void 0,this);return Uo.jsxDEV(Uo.Fragment,{children:p},void 0,!1,void 0,this)}var xo=Q(de(),1);function Ma({columns:a,data:n,keyExtractor:s,onRowClick:i,renderMobileCard:l,emptyText:u="No data available"}){let d=(p,h)=>{if(i&&(p.key==="Enter"||p.key===" "))p.preventDefault(),i(h)};if(n.length===0)return xo.jsxDEV("div",{className:"stats-table-empty",children:u},void 0,!1,void 0,this);return xo.jsxDEV("div",{className:"stats-table-wrapper",children:[l&&xo.jsxDEV("div",{className:"stats-table-mobile-only",children:xo.jsxDEV("div",{className:"stats-table-mobile-list",children:n.map((p)=>{let h=String(s(p));return xo.jsxDEV("div",{className:"stats-table-mobile-card-wrapper",children:l(p,i?()=>i(p):void 0)},h,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),xo.jsxDEV("div",{className:l?"stats-table-desktop-only":"stats-table-container",children:xo.jsxDEV("table",{className:"stats-table",children:[xo.jsxDEV("thead",{children:xo.jsxDEV("tr",{children:a.map((p)=>{let h=["stats-table-th",p.numeric?"stats-text-right":"stats-text-left",p.className||""].filter(Boolean).join(" ");return xo.jsxDEV("th",{className:h,children:p.header},p.key,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),xo.jsxDEV("tbody",{children:n.map((p)=>{let h=String(s(p)),g=typeof i==="function",b=["stats-table-tr",g?"stats-table-tr-clickable":""].filter(Boolean).join(" ");return xo.jsxDEV("tr",{className:b,onClick:g?()=>i(p):void 0,onKeyDown:g?(y)=>d(y,p):void 0,tabIndex:g?0:void 0,role:g?"button":void 0,children:a.map((y)=>{let v=["stats-table-td",y.numeric?"stats-text-right":"stats-text-left",y.className||""].filter(Boolean).join(" ");return xo.jsxDEV("td",{className:v,children:y.render?y.render(p):p[y.key]},y.key,!1,void 0,this)})},h,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Cl=Q(dt(),1),un=Q(de(),1);function Cf({data:a,title:n,initialCollapsed:s=!1}){let[i,l]=Cl.useState(s),[u,d]=Cl.useState(!1),p=Cl.useRef(0),h=JSON.stringify(a,null,2);return Cl.useEffect(()=>()=>window.clearTimeout(p.current),[]),un.jsxDEV("div",{className:"stats-json-block",children:[un.jsxDEV("div",{className:"stats-json-block-header",onClick:()=>l(!i),onKeyDown:(y)=>{if(y.key==="Enter"||y.key===" ")y.preventDefault(),l(!i)},tabIndex:0,role:"button","aria-expanded":!i,children:[un.jsxDEV("span",{className:"stats-json-block-title",children:n||"JSON"},void 0,!1,void 0,this),un.jsxDEV("div",{className:"stats-json-actions",children:[un.jsxDEV("button",{type:"button",className:"stats-json-copy-btn",onClick:async(y)=>{y.stopPropagation();try{await navigator.clipboard.writeText(h),d(!0),window.clearTimeout(p.current),p.current=window.setTimeout(()=>d(!1),1500)}catch{}},"aria-label":u?"Copied to clipboard":"Copy JSON to clipboard",children:[u?un.jsxDEV(pl,{size:13},void 0,!1,void 0,this):un.jsxDEV(gl,{size:13},void 0,!1,void 0,this),u?"Copied":"Copy"]},void 0,!0,void 0,this),un.jsxDEV("span",{className:"stats-json-block-toggle-indicator","data-collapsed":i,children:i?"▶ Show":"▼ Hide"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!i&&un.jsxDEV("div",{className:"stats-json-block-content-wrapper",children:un.jsxDEV("pre",{className:"stats-json-block-content",children:un.jsxDEV("code",{children:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var qe=Q(de(),1);function wA({stats:a}){let n=jm(a);return qe.jsxDEV("div",{className:"stats-metric-cluster",children:[qe.jsxDEV("div",{className:"stats-metric-primary-grid",children:[qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:ka(a.totalCost,a.unpricedRequests,a.totalCost>0&&a.totalCost<0.01?4:2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Requests"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.totalRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",title:"Prompt-input cost saved versus billing the same tokens uncached; cache writes can make this negative",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Savings"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.cacheSavings)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",title:"Prompt input served from cache: cache reads / (uncached input + cache reads)",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Rate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.cacheRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card primary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Error Rate"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ht(a.errorRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-secondary-grid",children:[qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Conversation input not served from cache",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Uncached Input"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalInputTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Conversation input read from the prompt cache",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Cache Read"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalCacheReadTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Output Tokens"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(a.totalOutputTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",title:"Uncached input + cache reads + cache writes + output",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Conversation Total"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:lt(n)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Premium Requests"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.totalPremiumRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Tokens/s"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:qm(a.avgTokensPerSecond)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Avg Latency"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:rt(a.avgDuration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),qe.jsxDEV("div",{className:"stats-metric-card secondary",children:[qe.jsxDEV("div",{className:"stats-metric-label",children:"Avg TTFT"},void 0,!1,void 0,this),qe.jsxDEV("div",{className:"stats-metric-value",children:rt(a.avgTtft)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var di=Q(de(),1);function ut({title:a,subtitle:n,actions:s,children:i,className:l="",...u}){return di.jsxDEV("div",{className:`stats-panel ${l}`,...u,children:[(a||n||s)&&di.jsxDEV("div",{className:"stats-panel-header",children:[di.jsxDEV("div",{className:"stats-panel-header-titles",children:[a&&di.jsxDEV("h3",{className:"stats-panel-title",children:a},void 0,!1,void 0,this),n&&di.jsxDEV("p",{className:"stats-panel-subtitle",children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&di.jsxDEV("div",{className:"stats-panel-actions",children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),di.jsxDEV("div",{className:"stats-panel-body",children:i},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var cs=Q(dt(),1);var kA=Q(de(),1);function ya({variant:a,children:n,className:s=""}){return kA.jsxDEV("span",{className:`stats-status-pill ${s}`,"data-variant":a,children:n},void 0,!1,void 0,this)}var ke=Q(de(),1);function MA({id:a,onClose:n}){let[s,i]=cs.useState(null),[l,u]=cs.useState(!1),[d,p]=cs.useState(null),h=cs.useRef(null),g=cs.useRef(null);if(cs.useEffect(()=>{if(a===null){i(null);return}h.current=document.activeElement,u(!0),p(null),i(null);let y=new AbortController;return DI(a,y.signal).then((v)=>{if(y.signal.aborted)return;i(v),setTimeout(()=>g.current?.focus(),50)}).catch((v)=>{if(y.signal.aborted)return;p(v instanceof Error?v:Error(String(v)))}).finally(()=>{if(!y.signal.aborted)u(!1)}),()=>y.abort()},[a]),cs.useEffect(()=>{if(a===null)return;let y=(v)=>{if(v.key==="Escape")n()};return window.addEventListener("keydown",y),()=>{if(window.removeEventListener("keydown",y),h.current)h.current.focus()}},[a,n]),a===null)return null;return ke.jsxDEV("div",{className:"stats-drawer-overlay",onClick:(y)=>{if(y.target===y.currentTarget)n()},role:"presentation",children:ke.jsxDEV("div",{className:"stats-drawer",role:"dialog","aria-modal":"true","aria-label":"Request details",children:[ke.jsxDEV("div",{className:"stats-drawer-header",children:[ke.jsxDEV("div",{className:"stats-drawer-header-left",children:[ke.jsxDEV("h2",{className:"stats-drawer-title",children:"Request Details"},void 0,!1,void 0,this),s&&ke.jsxDEV("span",{className:"stats-drawer-id",children:["ID: ",a]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("button",{ref:g,type:"button",onClick:n,className:"stats-drawer-close-btn","aria-label":"Close request details",children:ke.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-body",children:[l&&ke.jsxDEV("div",{className:"stats-drawer-loading",children:[ke.jsxDEV(Ua,{variant:"text",width:"60%",height:24,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:80,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:120,className:"mb-4"},void 0,!1,void 0,this),ke.jsxDEV(Ua,{variant:"rect",width:"100%",height:200},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&ke.jsxDEV("div",{className:"stats-drawer-error",children:[ke.jsxDEV("p",{className:"stats-drawer-error-title",children:"Failed to load request details"},void 0,!1,void 0,this),ke.jsxDEV("p",{className:"stats-drawer-error-message",children:d.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s&&ke.jsxDEV("div",{className:"stats-drawer-content",children:[ke.jsxDEV("div",{className:"stats-drawer-status-card",children:[ke.jsxDEV("div",{className:"stats-drawer-status-row",children:[ke.jsxDEV("div",{children:[ke.jsxDEV("div",{className:"stats-drawer-model",children:s.model},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-provider",children:s.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV(ya,{variant:s.errorMessage?"danger":"success",children:s.errorMessage?"Error":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s.errorMessage&&ke.jsxDEV("div",{className:"stats-drawer-error-block",children:[ke.jsxDEV("div",{className:"stats-drawer-error-label",children:"Error Message"},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-error-text",children:s.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metrics-grid",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(ml,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"API-equivalent estimate"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:ln(s,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(mf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Premium"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(s.usage.premiumRequests??0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(rf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Total Tokens"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(s.usage.totalTokens)},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-sub",children:[Ce(s.usage.input)," in · ",Ce(s.usage.output)," out"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(af,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Duration"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(s.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(xf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"TTFT"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(s.ttft)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s.duration&&s.usage.output>0&&ke.jsxDEV("div",{className:"stats-drawer-metric-card",children:[ke.jsxDEV("div",{className:"stats-drawer-metric-label",children:[ke.jsxDEV(sf,{size:14,className:"stats-drawer-metric-icon"},void 0,!1,void 0,this),"Throughput"]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-value",children:(s.usage.output*1000/s.duration).toFixed(1)},void 0,!1,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-metric-sub",children:"tokens/second"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ke.jsxDEV("div",{className:"stats-drawer-json-blocks",children:[ke.jsxDEV(Cf,{data:s.output,title:"Output Payload",initialCollapsed:!1},void 0,!1,void 0,this),ke.jsxDEV(Cf,{data:s,title:"Raw Request Metadata",initialCollapsed:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var e0=Q(de(),1);function Zs({options:a,value:n,onChange:s,className:i=""}){return e0.jsxDEV("div",{className:`stats-segmented-control ${i}`,role:"radiogroup",children:a.map((l)=>{let u=l.value===n;return e0.jsxDEV("button",{type:"button",role:"radio","aria-checked":u,"data-active":u?"true":"false",className:"stats-segmented-control-btn",title:l.title,onClick:()=>s(l.value),children:l.label},String(l.value),!1,void 0,this)})},void 0,!1,void 0,this)}var Me=Q(de(),1);function EA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["behavior",n,s],(d)=>OI(n,d),{pollMs:30000,enabled:a});return Me.jsxDEV("div",{className:"stats-route-container space-y-6",children:Me.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&Me.jsxDEV(Me.Fragment,{children:[Me.jsxDEV(iz,{overall:i.overall,behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this),Me.jsxDEV(lz,{behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this),Me.jsxDEV(uz,{models:i.byModel,behaviorSeries:i.behaviorSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Xm(a,n){if(n<=0)return;return`${(a/n).toFixed(2)} / msg`}function iz({overall:a,behaviorSeries:n}){let s=ba.useMemo(()=>vA(a,n),[a,n]),i=a.totalMessages,l=[{label:"User Messages",value:Ce(a.totalMessages),sub:i>0?"in range":void 0},{label:"Yelling (CAPS)",value:Ce(a.totalYelling),sub:Xm(a.totalYelling,i)},{label:"Profanity Hits",value:Ce(a.totalProfanity),sub:Xm(a.totalProfanity,i)},{label:"Anguish Signals",value:Ce(a.totalAnguish),sub:Xm(a.totalAnguish,i)},{label:"Friction Signals",value:Ce(s.totalFrustration),sub:Xm(s.totalFrustration,i)},{label:"Highest Friction Model",value:s.highestFrictionModel?.model??"—",sub:s.highestFrictionModel?`${Ce(s.highestFrictionModel.score)} hits`:void 0}];return Me.jsxDEV("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-4",children:l.map((u)=>Me.jsxDEV(ut,{className:"stats-behavior-summary-card py-3 px-4",children:[Me.jsxDEV("p",{className:"text-xs stats-text-muted mb-1 font-medium truncate",children:u.label},void 0,!1,void 0,this),Me.jsxDEV("p",{className:"text-lg font-bold stats-text-primary truncate",title:u.value,children:u.value},void 0,!1,void 0,this),u.sub&&Me.jsxDEV("p",{className:"text-xs stats-text-muted mt-0.5",children:u.sub},void 0,!1,void 0,this)]},u.label,!0,void 0,this))},void 0,!1,void 0,this)}var t0=[{value:"yelling",label:"CAPS",title:"Yelling (CAPS)"},{value:"profanity",label:"Profanity",title:"Profanity"},{value:"anguish",label:"Anguish",title:"Anguish (!!!, nooo, ugh, dude, ':(')"},{value:"negation",label:"Negation",title:"Negation (no/nope/wrong, makes no sense)"},{value:"repetition",label:"Repetition",title:"Repetition (i meant, still doesnt)"},{value:"blame",label:"Blame",title:"Blame (you didnt, why did you, stop X-ing)"},{value:"frustration",label:"Frustration",title:"Frustration (neg + rep + blame)"},{value:"total",label:"All",title:"All signals combined"}];function IA(a){if(!Number.isFinite(a))return"-";if(a===0)return"0%";if(Math.abs(a)<1)return`${a.toFixed(1)}%`;return`${a.toFixed(0)}%`}function AA(a,n){if(n==="frustration")return a.negation+a.repetition+a.blame;if(n==="total")return a.yelling+a.profanity+a.anguish+a.negation+a.repetition+a.blame;return a[n]}function RA(a,n){if(n<=0)return 0;return a/n*100}function lz({behaviorSeries:a}){let[n,s]=ba.useState(!1),[i,l]=ba.useState("total"),u=$t(),d=sa[u],p=ba.useMemo(()=>{if(n)return ju(a,{rankWeight:(B)=>B.messages,initBucket:()=>({hits:0,messages:0}),accumulate:(B,z)=>{B.hits+=AA(z,i),B.messages+=z.messages},bucketToValue:(B)=>RA(B.hits,B.messages)});let A=t0.find((B)=>B.value===i)?.title??"Hits";return Dm(a,A,{initBucket:()=>({hits:0,messages:0}),accumulate:(B,z)=>{B.hits+=AA(z,i),B.messages+=z.messages},bucketToValue:(B)=>RA(B.hits,B.messages)})},[a,n,i]),h=ba.useMemo(()=>is({chartTheme:d,showLegend:n,defaultLabel:"Hits",formatValue:IA}),[d,n]),{sharedScaleBase:g,yScale:b}=ba.useMemo(()=>ls({chartTheme:d,formatY:IA}),[d]),y=ba.useMemo(()=>t0.find((A)=>A.value===i)?.title??"",[i]),v=ba.useMemo(()=>{if(!n)return null;return{labels:p.labels,datasets:ui(p,(A)=>Vu(bt[A%bt.length]))}},[p,n]),T=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:h,scales:{x:g,y:b}}),[h,g,b]),M=ba.useMemo(()=>{if(n)return null;return{labels:p.labels,datasets:ui(p,(A)=>Sl(bt[A%bt.length]))}},[p,n]),I=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:h,scales:{x:{...g,stacked:!0},y:{...b,stacked:!0}},layout:{padding:{top:8}}}),[h,g,b]),w=[{value:!1,label:"All Models"},{value:!0,label:"By Model"}];return Me.jsxDEV(ut,{title:"User Friction Signals",subtitle:`${y} as % of user messages per day`,actions:Me.jsxDEV("div",{className:"flex items-center gap-3 flex-wrap",children:[Me.jsxDEV(Zs,{options:t0.map((A)=>({value:A.value,label:A.label,title:A.title})),value:i,onChange:l},void 0,!1,void 0,this),Me.jsxDEV(Zs,{options:w,value:n,onChange:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this),children:Me.jsxDEV("div",{className:"h-[300px]",children:p.labels.length===0?Me.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No friction signal data available"},void 0,!1,void 0,this):n&&v?Me.jsxDEV(Xa,{data:v,options:T},void 0,!1,void 0,this):M?Me.jsxDEV(li,{data:M,options:I},void 0,!1,void 0,this):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var _A="2fr 0.9fr 0.8fr 0.8fr 0.8fr 0.9fr 0.8fr 140px 40px";function DA(a){if(a.totalMessages===0)return 0;return(a.totalYelling+a.totalProfanity+a.totalAnguish+a.totalNegation+a.totalRepetition+a.totalBlame)/a.totalMessages}function Yu(a,n){if(n===0)return"-";let s=a/n*100;if(s===0)return"0%";if(s<1)return`${s.toFixed(1)}%`;return`${s.toFixed(0)}%`}function uz({models:a,behaviorSeries:n}){let[s,i]=ba.useState(null),l=$t(),u=sa[l],d=ba.useMemo(()=>dz(n),[n]),p=ba.useMemo(()=>[...a].sort((h,g)=>{if(g.totalMessages!==h.totalMessages)return g.totalMessages-h.totalMessages;return DA(g)-DA(h)}),[a]);return Me.jsxDEV(Pm,{title:"Behavior Signals by Model",subtitle:"Rates are per user message",children:[Me.jsxDEV(Bm,{gridTemplate:_A,columns:[{label:"Model"},{label:"Messages",align:"right"},{label:"CAPS %",align:"right"},{label:"Profanity %",align:"right"},{label:"Anguish %",align:"right"},{label:"Frustration %",align:"right"},{label:"Hits %",align:"right"},{label:"Trend",align:"center"}]},void 0,!1,void 0,this),Me.jsxDEV(Nm,{children:[p.map((h,g)=>{let b=`${h.model}::${h.provider}`,y=d.get(b)?.data??[],v=bt[g%bt.length],T=s===b,M=h.totalNegation+h.totalRepetition+h.totalBlame,I=h.totalYelling+h.totalProfanity+h.totalAnguish+M;return Me.jsxDEV(Hm,{gridTemplate:_A,isExpanded:T,onToggle:()=>i(T?null:b),cells:[Me.jsxDEV(zm,{model:h.model,provider:h.provider},"name",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Ce(h.totalMessages)},"messages",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalYelling,h.totalMessages)},"caps",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalProfanity,h.totalMessages)},"profanity",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(h.totalAnguish,h.totalMessages)},"anguish",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(M,h.totalMessages)},"frustration",!1,void 0,this),Me.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:Yu(I,h.totalMessages)},"hits",!1,void 0,this)],trendCell:y.length===0?Me.jsxDEV(Um,{},void 0,!1,void 0,this):Me.jsxDEV(Em,{timestamps:y.map((w)=>w.timestamp),values:y.map((w)=>w.total),color:v},void 0,!1,void 0,this),expandedContent:Me.jsxDEV("div",{className:"grid gap-4",style:{gridTemplateColumns:"220px 1fr"},children:[Me.jsxDEV("div",{className:"space-y-4 text-sm",children:[Me.jsxDEV(Tl,{label:"Yelling (CAPS)",total:h.totalYelling,messages:h.totalMessages,valueClass:"text-[#ed4abf]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Profanity",total:h.totalProfanity,messages:h.totalMessages,valueClass:"text-[#ff6b7d]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Anguish (!!!, nooo, dude, ..)",total:h.totalAnguish,messages:h.totalMessages,valueClass:"text-[#9b4dff]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Negation (no/nope/wrong)",total:h.totalNegation,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Repetition (i meant, still doesnt)",total:h.totalRepetition,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Blame (you didnt, stop X-ing)",total:h.totalBlame,messages:h.totalMessages,valueClass:"text-[#5ad8e6]"},void 0,!1,void 0,this),Me.jsxDEV(Tl,{label:"Avg chars / msg",total:h.totalChars,messages:h.totalMessages,valueClass:"stats-text-secondary",mode:"average"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Me.jsxDEV("div",{className:"h-[200px]",children:y.length===0?Me.jsxDEV(Fm,{},void 0,!1,void 0,this):Me.jsxDEV(cz,{data:y,chartTheme:u},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},b,!1,void 0,this)}),p.length===0?Me.jsxDEV("div",{className:"border-t border-[var(--border-subtle)] px-5 py-8 text-center text-[var(--text-muted)] text-sm",children:"No user behavior recorded for this range yet."},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Tl({label:a,total:n,messages:s,valueClass:i,mode:l="rate"}){let u=l==="rate"?"% of msgs":"Per msg",d=ba.useMemo(()=>{if(s===0)return"-";return l==="rate"?Yu(n,s):(n/s).toFixed(0)},[n,s,l]);return Me.jsxDEV("div",{children:[Me.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-1",children:a},void 0,!1,void 0,this),Me.jsxDEV("div",{className:"space-y-0.5 text-[var(--text-secondary)]",children:[Me.jsxDEV("div",{className:"flex items-center justify-between",children:[Me.jsxDEV("span",{className:"stats-text-muted text-xs",children:"Total"},void 0,!1,void 0,this),Me.jsxDEV("span",{className:`font-mono text-xs ${i}`,children:Ce(n)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Me.jsxDEV("div",{className:"flex items-center justify-between",children:[Me.jsxDEV("span",{className:"stats-text-muted text-xs",children:u},void 0,!1,void 0,this),Me.jsxDEV("span",{className:"font-mono text-xs stats-text-primary",children:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var Ym={yelling:"#ed4abf",profanity:"#ff6b7d",anguish:"#9b4dff",frustration:"#5ad8e6"};function cz({data:a,chartTheme:n}){let s=ba.useMemo(()=>({labels:a.map((l)=>Cn(new Date(l.timestamp),"MMM d")),datasets:[{label:"CAPS",data:a.map((l)=>l.yelling),...Ws(Ym.yelling)},{label:"Profanity",data:a.map((l)=>l.profanity),...Ws(Ym.profanity)},{label:"Anguish",data:a.map((l)=>l.anguish),...Ws(Ym.anguish)},{label:"Frustration",data:a.map((l)=>l.frustration),...Ws(Ym.frustration)}]}),[a]),i=ba.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:Om(n),scales:pA(n)}),[n]);return Me.jsxDEV(Xa,{data:s,options:i},void 0,!1,void 0,this)}function dz(a){if(a.length===0)return new Map;let n=[...new Set(a.map((l)=>l.timestamp))].sort((l,u)=>l-u),s=new Map;for(let l of a){let u=`${l.model}::${l.provider}`,d=s.get(u);if(!d)d=new Map,s.set(u,d);let p=d.get(l.timestamp)??{timestamp:l.timestamp,yelling:0,profanity:0,anguish:0,frustration:0,total:0};p.yelling+=l.yelling,p.profanity+=l.profanity,p.anguish+=l.anguish,p.frustration+=l.negation+l.repetition+l.blame,p.total=p.yelling+p.profanity+p.anguish+p.frustration,d.set(l.timestamp,p)}let i=new Map;for(let[l,u]of s){let d=n.map((p)=>u.get(p)??{timestamp:p,yelling:0,profanity:0,anguish:0,frustration:0,total:0});i.set(l,{data:d})}return i}var Fo=Q(dt(),1);var xa=Q(de(),1);function OA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["costs",n,s],(d)=>RI(n,d),{pollMs:30000,enabled:a});return xa.jsxDEV("div",{className:"stats-route-container space-y-6",children:xa.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&xa.jsxDEV(xa.Fragment,{children:[xa.jsxDEV(fz,{costSeries:i.costSeries},void 0,!1,void 0,this),xa.jsxDEV(mz,{costSeries:i.costSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function fz({costSeries:a}){let n=Fo.useMemo(()=>bA(a),[a]),s=[{label:"API-equivalent estimate",value:ka(n.totalCost,n.unpricedRequests),sub:n.unpricedRequests>0?`Excludes ${n.unpricedRequests.toLocaleString()} unpriced subscription request${n.unpricedRequests===1?"":"s"}`:void 0},{label:"Average estimate / Day",value:ka(n.avgDailyCost,n.unpricedRequests)},{label:"Top Model",value:n.topModelName||"—",sub:n.topModelName?`API-equivalent estimate: ${us(n.topModelCost)}`:void 0}];return xa.jsxDEV("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:s.map((i)=>xa.jsxDEV(ut,{className:"stats-cost-overview-card py-4 px-5",children:[xa.jsxDEV("p",{className:"text-xs stats-text-muted mb-1 font-medium uppercase tracking-wider",children:i.label},void 0,!1,void 0,this),xa.jsxDEV("p",{className:"text-2xl font-bold stats-text-primary truncate",title:i.value,children:i.value},void 0,!1,void 0,this),i.sub&&xa.jsxDEV("p",{className:"text-xs stats-text-muted mt-1 font-medium",children:i.sub},void 0,!1,void 0,this)]},i.label,!0,void 0,this))},void 0,!1,void 0,this)}var pz={dark:"rgba(248, 250, 252, 0.7)",light:"rgba(15, 23, 42, 0.6)"};function hz(a){return{id:"costBarLabels",afterDatasetsDraw(n){let{ctx:s}=n;if(!n.data.datasets[0])return;let l=n.getDatasetMeta(0);s.save(),s.font="11px system-ui, sans-serif",s.fillStyle=a,s.textAlign="center",s.textBaseline="bottom";for(let u of l.data){let d=u.$context.parsed.y;if(!d)continue;let p=`$${Math.round(d)}`,{x:h,y:g}=u.getProps(["x","y"],!0);s.fillText(p,h,g-3)}s.restore()}}}function mz({costSeries:a}){let[n,s]=Fo.useState(!1),i=$t(),l=sa[i],u=Fo.useMemo(()=>a.reduce((w,A)=>w+A.unpricedRequests,0),[a]),d=Fo.useMemo(()=>{if(n)return ju(a,{rankWeight:(w)=>w.cost,initBucket:()=>({total:0}),accumulate:(w,A)=>{w.total+=A.cost},bucketToValue:(w)=>w.total});return Dm(a,"API-equivalent estimate",{initBucket:()=>({total:0}),accumulate:(w,A)=>{w.total+=A.cost},bucketToValue:(w)=>w.total})},[a,n]),p=Fo.useMemo(()=>is({chartTheme:l,showLegend:n,defaultLabel:"API-equivalent estimate",formatValue:(w)=>`$${w.toFixed(2)}`,footer:(w)=>{if(!n||w.length<2)return;return`Total: $${w.reduce((B,z)=>B+(z.parsed.y??0),0).toFixed(2)}`}}),[l,n]),{sharedScaleBase:h,yScale:g}=Fo.useMemo(()=>ls({chartTheme:l,formatY:(w)=>`$${Math.round(w)}`}),[l]),b=Fo.useMemo(()=>hz(pz[i]),[i]),y=Fo.useMemo(()=>{if(!n)return null;return{labels:d.labels,datasets:ui(d,(w)=>Vu(bt[w%bt.length]))}},[d,n]),v=Fo.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:p,scales:{x:h,y:g}}),[p,h,g]),T=Fo.useMemo(()=>{if(n)return null;return{labels:d.labels,datasets:ui(d,(w)=>Sl(bt[w%bt.length]))}},[d,n]),M=Fo.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{...p,costBarLabels:{}},scales:{x:{...h,stacked:!0},y:{...g,stacked:!0}},layout:{padding:{top:24}}}),[p,h,g]),I=[{value:!1,label:"All Models"},{value:!0,label:"By Model"}];return xa.jsxDEV(ut,{title:"Daily API-equivalent estimate",subtitle:u>0?`Public API rate-card value over time; excludes ${u.toLocaleString()} unpriced subscription request${u===1?"":"s"}`:"Public API rate-card value over time",actions:xa.jsxDEV(Zs,{options:I,value:n,onChange:s},void 0,!1,void 0,this),children:xa.jsxDEV("div",{className:"h-[300px]",children:d.labels.length===0?xa.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No API-equivalent estimate data available"},void 0,!1,void 0,this):n&&y?xa.jsxDEV(Xa,{data:y,options:v},void 0,!1,void 0,this):T?xa.jsxDEV(li,{data:T,options:M,plugins:[b]},void 0,!1,void 0,this):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var PA=Q(dt(),1);var Ut=Q(de(),1);function BA({active:a,range:n,refreshTrigger:s,onRequestClick:i}){let{data:l,error:u,loading:d}=Vt(["recent-errors-dense",n,s],(g)=>_I(n,50,g),{pollMs:30000,enabled:a}),p=PA.useMemo(()=>[{key:"model",header:"Model",render:(g)=>Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:g.model},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:g.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(g)=>za(g.timestamp)},{key:"errorMessage",header:"Error Message",render:(g)=>Ut.jsxDEV("div",{className:"stats-text-xs stats-text-danger stats-truncate stats-max-w-md stats-font-mono",title:g.errorMessage||"",children:g.errorMessage||"Unknown error"},void 0,!1,void 0,this)},{key:"tokens",header:"Tokens",numeric:!0,render:(g)=>Ce(g.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(g)=>ln(g,4)}],[]);return Ut.jsxDEV("div",{className:"stats-route-container",children:Ut.jsxDEV(ut,{title:"Recent Errors",subtitle:"Up to 50 most recent failed requests in the stats database",children:Ut.jsxDEV(Rt,{loading:d,error:u,data:l,emptyText:"No recent failures in the local stats database",children:Ut.jsxDEV(Ma,{columns:p,data:l||[],keyExtractor:(g)=>g.id||`${g.sessionFile}-${g.entryId}`,onRowClick:(g)=>g.id&&i(g.id),renderMobileCard:(g,b)=>Ut.jsxDEV("div",{className:"stats-mobile-card stats-border-danger",onClick:b,children:[Ut.jsxDEV("div",{className:"stats-mobile-card-header",children:[Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:g.model},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:g.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV(ya,{variant:"danger",children:"Failed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-grid",children:[Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:za(g.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(g,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ut.jsxDEV("div",{children:[Ut.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),Ut.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(g.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),g.errorMessage&&Ut.jsxDEV("div",{className:"stats-mobile-card-error mt-2 stats-font-mono",children:g.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),emptyText:"No recent failures in the local stats database"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var $m=Q(dt(),1);var De=Q(de(),1);function NA({active:a,range:n,refreshTrigger:s}){let[i,l]=$m.useState(null),{data:u,error:d,loading:p}=Vt(["gain",n,s,i],(h)=>BI(n,i,h),{pollMs:30000,enabled:a});return De.jsxDEV("div",{className:"stats-route-container space-y-6",children:De.jsxDEV(Rt,{loading:p,error:d,data:u,children:u&&De.jsxDEV(De.Fragment,{children:[De.jsxDEV(gz,{projects:u.projects,selected:i,onChange:l},void 0,!1,void 0,this),De.jsxDEV(yz,{overall:u.overall},void 0,!1,void 0,this),De.jsxDEV(xz,{bySource:u.bySource},void 0,!1,void 0,this),De.jsxDEV(Sz,{timeSeries:u.timeSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function gz({projects:a,selected:n,onChange:s}){if(a.length===0)return null;return De.jsxDEV("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[De.jsxDEV("span",{className:"stats-text-secondary",style:{fontSize:"0.875rem",whiteSpace:"nowrap"},children:"Project"},void 0,!1,void 0,this),De.jsxDEV("select",{className:"stats-select",value:n??"",onChange:(i)=>s(i.target.value||null),style:{maxWidth:"480px",flex:1},children:[De.jsxDEV("option",{value:"",children:"All projects"},void 0,!1,void 0,this),a.map((i)=>De.jsxDEV("option",{value:i,children:i},i,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function yz({overall:a}){return De.jsxDEV(ut,{title:"Overall Gain",subtitle:"Aggregate snapcompact savings",children:De.jsxDEV("div",{className:"stats-metric-primary-grid",children:[De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Tokens"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:lt(a.savedTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Bytes"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:Jv(a.savedBytes)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Reduction"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:a.reductionPercent!==null?Ht(a.reductionPercent):"—"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{className:"stats-metric-card primary",children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Total Hits"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",children:Ce(a.hits)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function bz({title:a,totals:n}){return De.jsxDEV("div",{className:"stats-metric-card secondary",style:{flex:1},children:[De.jsxDEV("div",{className:"stats-metric-label",style:{fontWeight:600,marginBottom:8},children:a},void 0,!1,void 0,this),De.jsxDEV("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Tokens"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:lt(n.savedTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Saved Bytes"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:Jv(n.savedBytes)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Hits"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:Ce(n.hits)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),De.jsxDEV("div",{children:[De.jsxDEV("div",{className:"stats-metric-label",children:"Reduction"},void 0,!1,void 0,this),De.jsxDEV("div",{className:"stats-metric-value",style:{fontSize:"1rem"},children:n.reductionPercent!==null?Ht(n.reductionPercent):"—"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xz({bySource:a}){return De.jsxDEV(ut,{title:"By Source",subtitle:"Savings breakdown per subsystem",children:De.jsxDEV("div",{style:{display:"flex",gap:16,flexWrap:"wrap"},children:De.jsxDEV(bz,{title:"Snapcompact",totals:a.snapcompact},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var vz={snapcompact:"rgb(34, 197, 94)"};function Sz({timeSeries:a}){let n=$t(),s=sa[n],{data:i,options:l}=$m.useMemo(()=>{let u=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",timeZone:"UTC"}),p={labels:a.map((y)=>u.format(new Date(`${y.date}T00:00:00.000Z`))),datasets:[{label:"Snapcompact",data:a.map((y)=>y.snapcompact),...Vu(vz.snapcompact)}]},{sharedScaleBase:h,yScale:g}=ls({chartTheme:s,formatY:(y)=>lt(y)}),b={responsive:!0,maintainAspectRatio:!1,plugins:is({chartTheme:s,showLegend:!0,defaultLabel:"Tokens Saved",formatValue:lt}),scales:{x:{...h,stacked:!0},y:{...g,stacked:!0}}};return{data:p,options:b}},[a,s]);return De.jsxDEV(ut,{title:"Savings Over Time",subtitle:"Daily token savings",children:De.jsxDEV("div",{style:{height:240},children:a.length===0?De.jsxDEV("div",{className:"stats-table-empty",children:"No time series data yet"},void 0,!1,void 0,this):De.jsxDEV(Xa,{data:i,options:l},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Tn=Q(dt(),1);var Ee=Q(de(),1);function HA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["models",n,s],(p)=>AI(n,p),{pollMs:30000,enabled:a}),d=Tn.useMemo(()=>fA(i?.byModel??[]),[i?.byModel]);return Ee.jsxDEV("div",{className:"stats-route-container space-y-6",children:Ee.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&Ee.jsxDEV(Ee.Fragment,{children:[Ee.jsxDEV(Lz,{modelSeries:i.modelSeries,timeRange:n,colorLookup:d},void 0,!1,void 0,this),Ee.jsxDEV(Tz,{models:i.byModel,performanceSeries:i.modelPerformanceSeries,timeRange:n,colorLookup:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Lz({modelSeries:a,timeRange:n,colorLookup:s}){let i=$t(),l=sa[i],u=Ll(n),d=Tn.useMemo(()=>Cz(a),[a]),p=Tn.useMemo(()=>({labels:d.data.map((g)=>Lf(g.timestamp,n)),datasets:d.series.map((g,b)=>{let y=bt[b%bt.length],v=g.key?s.get(g.key)??y:y,T=g.key??g.label;return{label:g.label,data:d.data.map((M)=>M[T]??0),borderColor:v,backgroundColor:`${v}20`,fill:!0,tension:0.4,pointRadius:0,pointHoverRadius:4,borderWidth:2}})}),[d,s,n]),h=Tn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{position:"top",align:"start",labels:{color:l.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:l.tooltipBackground,titleColor:l.tooltipTitle,bodyColor:l.tooltipBody,borderColor:l.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(g)=>{let b=g.dataset.label??"",y=g.parsed.y;return`${b}: ${(y??0).toFixed(1)}%`}}}},scales:{x:{grid:{color:l.grid,drawBorder:!1},ticks:{color:l.tick,font:{size:11}}},y:{grid:{color:l.grid,drawBorder:!1},ticks:{color:l.tick,font:{size:11},callback:(g)=>`${g}%`},min:0,max:100}}}),[l]);return Ee.jsxDEV(ut,{title:"Model Preference",subtitle:`Share of requests over ${u.windowLabel}`,children:Ee.jsxDEV("div",{className:"h-[280px]",children:d.data.length===0?Ee.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No data available"},void 0,!1,void 0,this):Ee.jsxDEV(Xa,{data:p,options:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Cz(a,n=5){if(a.length===0)return{data:[],series:[]};let s=new Map;for(let y of a){let v=`${y.model}::${y.provider}`,T=s.get(v);if(T)T.total+=y.requests;else s.set(v,{model:y.model,provider:y.provider,total:y.requests})}let l=[...s.entries()].map(([y,v])=>({key:y,...v})).sort((y,v)=>v.total-y.total).slice(0,n),u=new Set(l.map((y)=>y.key)),d=new Map;for(let y of l)d.set(y.model,(d.get(y.model)??0)+1);let p=new Map;for(let y of l){let v=(d.get(y.model)??0)>1;p.set(y.key,v?`${y.model} (${y.provider})`:y.model)}let h=new Map;for(let y of a){let v=`${y.model}::${y.provider}`,T=h.get(y.timestamp)??{timestamp:y.timestamp,total:0};T.total+=y.requests;let M=u.has(v)?v:"Other";T[M]=(T[M]??0)+y.requests,h.set(y.timestamp,T)}let g=l.map((y)=>({key:y.key,label:p.get(y.key)??y.model}));if([...h.values()].some((y)=>(y.Other??0)>0))g.push({label:"Other"});return{data:[...h.values()].sort((y,v)=>(y.timestamp??0)-(v.timestamp??0)).map((y)=>{let v=y.total??0;for(let T of g){let M=T.key??T.label;y[M]=v>0?(y[M]??0)/v*100:0}return y}),series:g}}var zA="2fr 0.9fr 0.9fr 1fr 0.8fr 0.8fr 140px 40px";function Tz({models:a,performanceSeries:n,timeRange:s,colorLookup:i}){let[l,u]=Tn.useState(null),d=Ll(s),p=Tn.useMemo(()=>xA(n,s),[n,s]),h=$t(),g=sa[h],b=Tn.useMemo(()=>[...a].sort((y,v)=>v.totalInputTokens+v.totalOutputTokens-(y.totalInputTokens+y.totalOutputTokens)),[a]);return Ee.jsxDEV(Pm,{title:"Model Statistics",children:[Ee.jsxDEV(Bm,{gridTemplate:zA,columns:[{label:"Model"},{label:"Requests",align:"right"},{label:"API-equivalent estimate",align:"right"},{label:"Tokens",align:"right"},{label:"Tokens/s",align:"right"},{label:"TTFT",align:"right"},{label:d.trendLabel,align:"center"}]},void 0,!1,void 0,this),Ee.jsxDEV(Nm,{children:b.map((y,v)=>{let T=`${y.model}::${y.provider}`,I=p.get(T)?.data??[],w=i.get(T)??bt[v%bt.length],A=l===T,B=y.errorRate*100;return Ee.jsxDEV(Hm,{gridTemplate:zA,isExpanded:A,onToggle:()=>u(A?null:T),cells:[Ee.jsxDEV(zm,{model:y.model,provider:y.provider},"name",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.totalRequests.toLocaleString()},"requests",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:ka(y.totalCost,y.unpricedRequests)},"cost",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:(y.totalInputTokens+y.totalOutputTokens).toLocaleString()},"tokens",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.avgTokensPerSecond?.toFixed(1)??"-"},"tps",!1,void 0,this),Ee.jsxDEV("div",{className:"text-right text-[var(--text-secondary)] font-mono text-sm",children:y.avgTtft?`${(y.avgTtft/1000).toFixed(2)}s`:"-"},"ttft",!1,void 0,this)],trendCell:I.length===0?Ee.jsxDEV(Um,{},void 0,!1,void 0,this):Ee.jsxDEV(Em,{timestamps:I.map((z)=>z.timestamp),values:I.map((z)=>z.avgTokensPerSecond??0),color:w},void 0,!1,void 0,this),expandedContent:Ee.jsxDEV("div",{className:"grid gap-4",style:{gridTemplateColumns:"200px 1fr"},children:[Ee.jsxDEV("div",{className:"space-y-4 text-sm",children:[Ee.jsxDEV("div",{children:[Ee.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-2",children:"Efficiency"},void 0,!1,void 0,this),Ee.jsxDEV("div",{className:"space-y-1 text-[var(--text-secondary)]",children:[Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Error rate"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:B>5?"text-[var(--accent-red)]":"text-[var(--accent-green)]",children:[B.toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Cache rate"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:[(y.cacheRate*100).toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Cache savings"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:y.cacheSavings<0?"text-[var(--accent-red)]":"text-[var(--accent-green)]",children:[(y.cacheSavings*100).toFixed(1),"%"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{children:[Ee.jsxDEV("div",{className:"text-[var(--text-primary)] font-medium mb-2",children:"Latency"},void 0,!1,void 0,this),Ee.jsxDEV("div",{className:"space-y-1 text-[var(--text-secondary)]",children:[Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Avg duration"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:y.avgDuration?`${(y.avgDuration/1000).toFixed(2)}s`:"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"flex items-center justify-between",children:[Ee.jsxDEV("span",{children:"Avg TTFT"},void 0,!1,void 0,this),Ee.jsxDEV("span",{className:"font-mono",children:y.avgTtft?`${(y.avgTtft/1000).toFixed(2)}s`:"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Ee.jsxDEV("div",{className:"h-[200px]",children:I.length===0?Ee.jsxDEV(Fm,{},void 0,!1,void 0,this):Ee.jsxDEV(wz,{data:I,color:w,chartTheme:g,timeRange:s},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},T,!1,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function wz({data:a,color:n,chartTheme:s,timeRange:i}){let l=Tn.useMemo(()=>({labels:a.map((d)=>Lf(d.timestamp,i)),datasets:[{label:"TTFT",data:a.map((d)=>d.avgTtftSeconds??null),...Ws("#5ad8e6"),yAxisID:"y"},{label:"Tokens/s",data:a.map((d)=>d.avgTokensPerSecond??null),...Ws(n),yAxisID:"y1"}]}),[a,n,i]),u=Tn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,plugins:Om(s),scales:hA(s)}),[s]);return Ee.jsxDEV(Xa,{data:l,options:u},void 0,!1,void 0,this)}var Tf=Q(dt(),1);var UA=Q(dt(),1);var vo=Q(de(),1),Wm={main:{label:"Main agent",color:"#ed4abf"},subagent:{label:"Subagents",color:"#9b4dff"},advisor:{label:"Advisor",color:"#5ad8e6"}};function FA({stats:a}){let n=UA.useMemo(()=>yA(a),[a]);if(n.totalTokens===0)return vo.jsxDEV("div",{className:"py-8 text-center stats-text-muted text-sm",children:"No token usage in this range"},void 0,!1,void 0,this);return vo.jsxDEV("div",{className:"space-y-4",children:[vo.jsxDEV("div",{className:"flex h-3 w-full overflow-hidden rounded-full",style:{background:"var(--surface-2)"},children:n.segments.map((s)=>s.share>0&&vo.jsxDEV("div",{className:"h-full",style:{width:`${s.share*100}%`,background:Wm[s.agentType].color},title:`${Wm[s.agentType].label}: ${Ht(s.share)}`},s.agentType,!1,void 0,this))},void 0,!1,void 0,this),vo.jsxDEV("div",{className:"space-y-2",children:n.segments.map((s)=>vo.jsxDEV("div",{className:"flex items-center justify-between gap-3 text-sm",children:[vo.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[vo.jsxDEV("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:Wm[s.agentType].color}},void 0,!1,void 0,this),vo.jsxDEV("span",{className:"stats-text-primary truncate",children:Wm[s.agentType].label},void 0,!1,void 0,this),vo.jsxDEV("span",{className:"stats-text-muted stats-text-xs whitespace-nowrap",children:[Ce(s.requests)," req"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),vo.jsxDEV("div",{className:"flex items-center gap-3 whitespace-nowrap",children:[vo.jsxDEV("span",{className:"stats-text-secondary",children:[lt(s.tokens)," tok"]},void 0,!0,void 0,this),vo.jsxDEV("span",{className:"stats-font-semibold stats-text-primary tabular-nums",children:Ht(s.share)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},s.agentType,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ve=Q(de(),1);function qA({active:a,range:n,refreshTrigger:s,onRequestClick:i}){let{data:l,error:u,loading:d}=Vt(["overview",n,s],(A)=>II(n,A),{pollMs:30000,enabled:a}),{data:p,error:h,loading:g}=Vt(["recent-requests",s],(A)=>Rm(50,A),{pollMs:30000,enabled:a}),b=$t(),y=sa[b],v=Tf.useMemo(()=>{if(!l?.timeSeries)return{labels:[],datasets:[]};let A=l.timeSeries.map((z)=>Cn(new Date(z.timestamp),n==="1h"||n==="24h"?"HH:mm":"MMM d")),B=l.timeSeries.length<=2?3:0;return{labels:A,datasets:[{label:"Requests",data:l.timeSeries.map((z)=>z.requests),borderColor:"#5ad8e6",backgroundColor:"rgba(90, 216, 230, 0.12)",tension:0.2,borderWidth:2,pointRadius:B,pointHoverRadius:4,fill:!0},{label:"Errors",data:l.timeSeries.map((z)=>z.errors),borderColor:"#ff6b7d",backgroundColor:"rgba(255, 107, 125, 0.12)",tension:0.2,borderWidth:2,pointRadius:B,pointHoverRadius:4,fill:!0}]}},[l?.timeSeries,n]),T=Tf.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{display:!0,position:"top",align:"end",labels:{color:y.legendLabel,boxWidth:8,usePointStyle:!0,font:{size:11}}},tooltip:{backgroundColor:y.tooltipBackground,titleColor:y.tooltipTitle,bodyColor:y.tooltipBody,borderColor:y.tooltipBorder,borderWidth:1,cornerRadius:8,padding:10}},scales:{x:{grid:{color:y.grid,drawBorder:!1},ticks:{color:y.tick,font:{size:10}}},y:{grid:{color:y.grid,drawBorder:!1},ticks:{color:y.tick,font:{size:10}},min:0}}}),[y]),M=Tf.useMemo(()=>[{key:"model",header:"Model",render:(A)=>ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:A.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(A)=>za(A.timestamp)},{key:"tokens",header:"Tokens",numeric:!0,render:(A)=>Ce(A.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(A)=>ln(A,4)},{key:"duration",header:"Duration",numeric:!0,render:(A)=>rt(A.duration)},{key:"status",header:"Status",className:"stats-text-center",render:(A)=>ve.jsxDEV(ya,{variant:A.errorMessage?"danger":"success",children:A.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)}],[]),I=(A,B)=>ve.jsxDEV("div",{className:"stats-mobile-card",onClick:B,children:[ve.jsxDEV("div",{className:"stats-mobile-card-header",children:[ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:A.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV(ya,{variant:A.errorMessage?"danger":"success",children:A.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-grid",children:[ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:za(A.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(A,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(A.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{children:[ve.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(A.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A.errorMessage&&ve.jsxDEV("div",{className:"stats-mobile-card-error truncate mt-2",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w=Tf.useMemo(()=>{if(!p)return[];return p.slice(0,10)},[p]);return ve.jsxDEV("div",{className:"stats-route-container space-y-6",children:[ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:l&&ve.jsxDEV(wA,{stats:l.overall},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV(ut,{title:"Conversation Tokens by Agent",subtitle:"Uncached input + cache reads + cache writes + output, grouped by agent type",children:ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:l&&ve.jsxDEV(FA,{stats:l.byAgentType},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[ve.jsxDEV("div",{className:"lg:col-span-2",children:ve.jsxDEV(ut,{title:"System Throughput",subtitle:"Request volume and errors over time",children:ve.jsxDEV(Rt,{loading:d,error:u,data:l,children:ve.jsxDEV("div",{className:"h-[280px]",children:l?.timeSeries&&l.timeSeries.length>0?ve.jsxDEV(Xa,{data:v,options:T},void 0,!1,void 0,this):ve.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No time-series data available"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),ve.jsxDEV("div",{children:ve.jsxDEV(ut,{title:"Operational Feed",subtitle:"Real-time request log",children:ve.jsxDEV(Rt,{loading:g,error:h,data:p,fallback:ve.jsxDEV("div",{className:"space-y-4",children:Array.from({length:5}).map((A,B)=>ve.jsxDEV("div",{className:"flex items-center gap-3",children:[ve.jsxDEV(Ua,{variant:"circle",width:10,height:10},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"flex-1",children:[ve.jsxDEV(Ua,{variant:"text",width:"60%",height:16},void 0,!1,void 0,this),ve.jsxDEV(Ua,{variant:"text",width:"40%",height:12},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},B,!0,void 0,this))},void 0,!1,void 0,this),children:ve.jsxDEV("div",{className:"stats-feed-ledger overflow-y-auto max-h-[280px] pr-2",children:[w.map((A)=>{let B=!!A.errorMessage;return ve.jsxDEV("div",{className:"stats-feed-item flex items-start gap-3 p-2 rounded hover:bg-stats-surface-2 cursor-pointer transition-colors",onClick:()=>A.id&&i(A.id),children:[ve.jsxDEV("div",{className:`w-2 h-2 mt-1.5 rounded-full flex-shrink-0 ${B?"bg-stats-danger":"bg-stats-success"}`},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"flex-1 min-w-0",children:[ve.jsxDEV("div",{className:"flex justify-between items-baseline gap-2",children:[ve.jsxDEV("div",{className:"stats-font-medium stats-text-primary text-sm truncate",children:A.model},void 0,!1,void 0,this),ve.jsxDEV("div",{className:"stats-text-xs stats-text-muted whitespace-nowrap",children:za(A.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV("div",{className:"flex justify-between items-center text-xs stats-text-muted mt-0.5",children:[ve.jsxDEV("div",{children:A.provider},void 0,!1,void 0,this),ve.jsxDEV("div",{children:[A.duration?rt(A.duration):""," ",A.usage.totalTokens>0?`· ${ln(A,4)}`:""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B&&ve.jsxDEV("div",{className:"text-xs text-stats-danger truncate mt-1",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},A.id||`${A.sessionFile}-${A.entryId}`,!0,void 0,this)}),w.length===0&&ve.jsxDEV("div",{className:"py-8 text-center stats-text-muted text-sm",children:"No recent requests found"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ve.jsxDEV(ut,{title:"Recent Requests Preview",subtitle:"Latest transactions processed by the proxy",actions:ve.jsxDEV("a",{href:`#/requests?range=${n}`,className:"stats-button stats-button-secondary text-xs",children:"View All Requests"},void 0,!1,void 0,this),children:ve.jsxDEV(Rt,{loading:g,error:h,data:p,children:ve.jsxDEV(Ma,{columns:M,data:w,keyExtractor:(A)=>A.id||`${A.sessionFile}-${A.entryId}`,onRowClick:(A)=>A.id&&i(A.id),renderMobileCard:I,emptyText:"No recent requests found"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var a0=Q(dt(),1);var ot=Q(de(),1);function VA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["projects",n,s],(g)=>PI(n,g),{pollMs:30000,enabled:a}),d=a0.useMemo(()=>{if(!i)return[];return SA(i)},[i]),p=a0.useMemo(()=>[{key:"folder",header:"Project/Folder",render:(g)=>ot.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate max-w-[440px]",title:g.folder||"(root)",children:g.folder||"(root)"},void 0,!1,void 0,this)},{key:"totalRequests",header:"Requests",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"stats-text-right",children:[ot.jsxDEV("div",{className:"font-mono",children:Ce(g.totalRequests)},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:ot.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"link",style:{width:`${g.requestsPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"totalCost",header:"API-equivalent estimate",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"stats-text-right",children:[ot.jsxDEV("div",{className:"font-mono",children:ka(g.totalCost,g.unpricedRequests)},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:ot.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"success",style:{width:`${g.costPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"totalTokens",header:"Tokens",numeric:!0,render:(g)=>ot.jsxDEV("div",{className:"font-mono",children:Ce(g.totalInputTokens+g.totalOutputTokens)},void 0,!1,void 0,this)},{key:"cacheRate",header:"Cache Rate",numeric:!0,render:(g)=>ot.jsxDEV("span",{className:"font-mono",children:Ht(g.cacheRate)},void 0,!1,void 0,this)},{key:"cacheSavings",header:"Cache Savings",numeric:!0,render:(g)=>ot.jsxDEV("span",{className:`${g.cacheSavings<0?"stats-text-danger":"stats-text-success"} font-medium`,children:Ht(g.cacheSavings)},void 0,!1,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(g)=>ot.jsxDEV(ya,{variant:g.errorRate>0.1?"danger":g.errorRate>0?"warning":"success",children:Ht(g.errorRate)},void 0,!1,void 0,this)},{key:"avgDuration",header:"Avg Duration",numeric:!0,render:(g)=>rt(g.avgDuration)}],[]);return ot.jsxDEV("div",{className:"stats-route-container",children:ot.jsxDEV(ut,{title:"Projects & Folders",subtitle:"Aggregate proxy metrics grouped by folder path",children:ot.jsxDEV(Rt,{loading:u,error:l,data:i,emptyText:"No project folders recorded for this range.",children:ot.jsxDEV(Ma,{columns:p,data:d,keyExtractor:(g)=>g.folder,renderMobileCard:(g)=>ot.jsxDEV("div",{className:"stats-mobile-card",children:[ot.jsxDEV("div",{className:"stats-mobile-card-header mb-2",children:[ot.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:g.folder||"(root)"},void 0,!1,void 0,this),ot.jsxDEV(ya,{variant:g.errorRate>0.1?"danger":g.errorRate>0?"warning":"success",children:[Ht(g.errorRate)," Err"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-grid",children:[ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Requests"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:Ce(g.totalRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:ka(g.totalCost,g.unpricedRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cache Rate"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:Ht(g.cacheRate)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cache Savings"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:Ht(g.cacheSavings)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ot.jsxDEV("div",{children:[ot.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),ot.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(g.avgDuration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),emptyText:"No project folders recorded for this range."},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Ia=Q(dt(),1);var $e=Q(de(),1);function jA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["providers",n,s],(d)=>zI(n,d),{pollMs:30000,enabled:a});return $e.jsxDEV("div",{className:"stats-route-container space-y-6",children:$e.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&$e.jsxDEV($e.Fragment,{children:[$e.jsxDEV(kz,{providers:i.providers},void 0,!1,void 0,this),$e.jsxDEV(Mz,{stats:i},void 0,!1,void 0,this),$e.jsxDEV(Iz,{hourly:i.hourly,providers:i.providers},void 0,!1,void 0,this),$e.jsxDEV(Az,{insights:i.windowInsights},void 0,!1,void 0,this),$e.jsxDEV(Rz,{usageSeries:i.usageSeries},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function kz({providers:a}){let n=Ia.useMemo(()=>a.reduce((l,u)=>l+u.totalTokens,0),[a]),s=Ia.useMemo(()=>a.reduce((l,u)=>l+u.unpricedRequests,0),[a]),i=[{key:"provider",header:"Provider",render:(l)=>$e.jsxDEV("span",{className:"font-medium",children:l.provider},void 0,!1,void 0,this)},{key:"requests",header:"Requests",numeric:!0,render:(l)=>Ce(l.totalRequests)},{key:"errors",header:"Error Rate",numeric:!0,render:(l)=>Ht(l.totalRequests>0?l.failedRequests/l.totalRequests:0)},{key:"models",header:"Models",numeric:!0,render:(l)=>Ce(l.models)},{key:"tokens",header:"Tokens",numeric:!0,render:(l)=>$e.jsxDEV("span",{title:`Input ${lt(l.totalInputTokens)} · Output ${lt(l.totalOutputTokens)} · Cache read ${lt(l.totalCacheReadTokens)} · Cache write ${lt(l.totalCacheWriteTokens)}`,children:lt(l.totalTokens)},void 0,!1,void 0,this)},{key:"share",header:"Share",numeric:!0,render:(l)=>Ht(n>0?l.totalTokens/n:0)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(l)=>ka(l.totalCost,l.unpricedRequests)},{key:"tps",header:"Tok/s",numeric:!0,render:(l)=>qm(l.avgTokensPerSecond)}];return $e.jsxDEV(ut,{title:"Provider Totals",subtitle:s>0?`Token, request, and API-equivalent estimates; excludes ${s.toLocaleString()} unpriced subscription request${s===1?"":"s"}`:"Token, request, and API-equivalent estimates over the active range",children:$e.jsxDEV(Ma,{columns:i,data:a,keyExtractor:(l)=>l.provider,emptyText:"No requests recorded in this range"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Mz({stats:a}){let[n,s]=Ia.useState("tokens"),i=$t(),l=sa[i],u=Ia.useMemo(()=>a.providers.reduce((b,y)=>b+y.unpricedRequests,0),[a.providers]),d=Ia.useMemo(()=>{let b=a.series.map((y)=>({...y,model:y.provider}));return ju(b,{topN:6,rankWeight:(y)=>n==="tokens"?y.totalTokens:y.cost,initBucket:()=>({total:0}),accumulate:(y,v)=>{y.total+=n==="tokens"?v.totalTokens:v.cost},bucketToValue:(y)=>y.total})},[a.series,n]),p=n==="tokens"?lt:(b)=>us(b),h=Ia.useMemo(()=>{let{sharedScaleBase:b,yScale:y}=ls({chartTheme:l,formatY:p});return{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:is({chartTheme:l,showLegend:!0,defaultLabel:n==="tokens"?"Tokens":"API-equivalent estimate",formatValue:p,footer:(v)=>{if(v.length<2)return;let T=v.reduce((M,I)=>M+(I.parsed.y??0),0);return`Total: ${p(T)}`}}),scales:{x:{...b,stacked:!0},y:{...y,stacked:!0}}}},[l,n,p]),g=Ia.useMemo(()=>({labels:d.labels,datasets:ui(d,(b)=>Sl(bt[b%bt.length]))}),[d]);return $e.jsxDEV(ut,{title:"Burn by Provider",subtitle:n==="cost"&&u>0?`API-equivalent estimates over time; excludes ${u.toLocaleString()} unpriced subscription request${u===1?"":"s"}`:"Stacked token or API-equivalent estimate burn over time",actions:$e.jsxDEV(Zs,{options:[{value:"tokens",label:"Tokens"},{value:"cost",label:"API-equivalent estimate"}],value:n,onChange:s},void 0,!1,void 0,this),children:$e.jsxDEV("div",{className:"h-[300px]",children:d.labels.length===0?$e.jsxDEV(Gu,{message:"No provider activity in this range"},void 0,!1,void 0,this):$e.jsxDEV(li,{data:g,options:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var o0="__all__";function Iz({hourly:a,providers:n}){let[s,i]=Ia.useState(o0),l=$t(),u=sa[l],{tokensByHour:d,peakHour:p}=Ia.useMemo(()=>{let y=Array(24).fill(0);for(let T of a){if(s!==o0&&T.provider!==s)continue;y[T.hour]+=T.totalTokens}let v=0;for(let T=1;T<24;T++)if(y[T]>y[v])v=T;return{tokensByHour:y,peakHour:v}},[a,s]),h=d.some((y)=>y>0),g=Ia.useMemo(()=>({labels:Array.from({length:24},(y,v)=>`${String(v).padStart(2,"0")}:00`),datasets:[{label:"Tokens",data:d,...Sl(bt[2]),backgroundColor:d.map((y,v)=>v===p?bt[0]:bt[2])}]}),[d,p]),b=Ia.useMemo(()=>{let{sharedScaleBase:y,yScale:v}=ls({chartTheme:u,formatY:lt});return{responsive:!0,maintainAspectRatio:!1,plugins:is({chartTheme:u,showLegend:!1,defaultLabel:"Tokens",formatValue:lt}),scales:{x:y,y:v}}},[u]);return $e.jsxDEV(ut,{title:"Peak Burn Hours",subtitle:h?`Token burn by local hour of day — peak at ${String(p).padStart(2,"0")}:00`:"Token burn by local hour of day",actions:$e.jsxDEV("select",{className:"stats-select",value:s,onChange:(y)=>i(y.target.value),"aria-label":"Provider",children:[$e.jsxDEV("option",{value:o0,children:"All providers"},void 0,!1,void 0,this),n.map((y)=>$e.jsxDEV("option",{value:y.provider,children:y.provider},y.provider,!1,void 0,this))]},void 0,!0,void 0,this),children:$e.jsxDEV("div",{className:"h-[260px]",children:h?$e.jsxDEV(li,{data:g,options:b},void 0,!1,void 0,this):$e.jsxDEV(Gu,{message:"No activity in this range"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Az({insights:a}){return $e.jsxDEV(ut,{title:"Subscription Windows",subtitle:"What each usage window buys you, and how many accounts peak demand needs",children:$e.jsxDEV(Ma,{columns:[{key:"provider",header:"Provider",render:(s)=>$e.jsxDEV("span",{className:"font-medium",children:s.provider},void 0,!1,void 0,this)},{key:"window",header:"Window",render:(s)=>s.windowLabel},{key:"accounts",header:"Accounts",numeric:!0,render:(s)=>Ce(s.accounts)},{key:"consumed",header:"Windows Burned",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Subscription-window equivalents consumed in range (sum of used-fraction increases across accounts)",children:s.fractionConsumed.toFixed(2)},void 0,!1,void 0,this)},{key:"capacity",header:"Est. Tokens / Window",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Provider tokens burned in range ÷ windows burned — what one full window is worth",children:s.estTokensPerWindow!==null?lt(s.estTokensPerWindow):"—"},void 0,!1,void 0,this)},{key:"peak",header:"Peak Utilization",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Peak of summed used fraction across accounts at any sampled instant",children:Ht(s.peakConcurrentFraction)},void 0,!1,void 0,this)},{key:"ideal",header:"Ideal Accounts",numeric:!0,render:(s)=>$e.jsxDEV("span",{title:"Accounts needed to keep peak demand under 90% of fleet capacity",className:s.idealAccounts>s.accounts?"stats-text-warning font-semibold":void 0,children:[Ce(s.idealAccounts),s.idealAccounts>s.accounts?` (have ${s.accounts})`:""]},void 0,!0,void 0,this)},{key:"exhausted",header:"Exhaustions",numeric:!0,render:(s)=>$e.jsxDEV("span",{className:s.exhaustedEvents>0?"stats-text-warning":void 0,children:Ce(s.exhaustedEvents)},void 0,!1,void 0,this)}],data:a,keyExtractor:(s)=>`${s.provider}::${s.windowKey}`,emptyText:"No usage snapshots recorded yet — they accumulate whenever usage is fetched (TUI footer, /usage, omp usage)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var n0={ok:"#62d394",warning:"#f5c14b",exhausted:"#ff6b7d"};function Rz({usageSeries:a}){let n=Ia.useMemo(()=>[...new Set(a.map((b)=>b.provider))],[a]),[s,i]=Ia.useState(null),l=s!==null&&n.includes(s)?s:n[0]??null,u=$t(),d=sa[u],p=Ia.useMemo(()=>a.filter((b)=>b.provider===l).map((b)=>{let y=[...b.points].reverse().find((v)=>v.usedFraction!==null);return y?{label:`${b.windowLabel} · ${b.accountLabel}`,fraction:y.usedFraction??0,exhausted:y.exhausted,recordedAt:y.timestamp}:null}).filter((b)=>b!==null).sort((b,y)=>y.fraction-b.fraction),[a,l]),h=Ia.useMemo(()=>({labels:p.map((b)=>b.label),datasets:[{label:"Used",data:p.map((b)=>b.fraction*100),backgroundColor:p.map((b)=>b.exhausted?n0.exhausted:b.fraction>=0.8?n0.warning:n0.ok),borderWidth:0,borderRadius:4,barThickness:18}]}),[p]),g=Ia.useMemo(()=>{let{sharedScaleBase:b,yScale:y}=ls({chartTheme:d,formatY:(M)=>`${Math.round(M)}%`}),v=Math.max(100,...p.map((M)=>M.fraction*100)),T=is({chartTheme:d,showLegend:!1,defaultLabel:"Used",formatValue:(M)=>`${M.toFixed(1)}%`});return{indexAxis:"y",responsive:!0,maintainAspectRatio:!1,plugins:{...T,tooltip:{...T.tooltip,callbacks:{label:(M)=>{let I=p[M.dataIndex],w=`${(M.parsed.x??0).toFixed(1)}% used`;return I?`${w} · recorded ${za(I.recordedAt)}`:w}}}},scales:{x:{...y,max:v},y:{...b,grid:{display:!1}}}}},[d,p]);return $e.jsxDEV(ut,{title:"Window Utilization",subtitle:"Latest recorded limit utilization per account and window — red bars are exhausted, amber above 80%",actions:n.length>1?$e.jsxDEV("select",{className:"stats-select",value:l??"",onChange:(b)=>i(b.target.value),"aria-label":"Provider",children:n.map((b)=>$e.jsxDEV("option",{value:b,children:b},b,!1,void 0,this))},void 0,!1,void 0,this):void 0,children:$e.jsxDEV("div",{style:{height:Math.max(160,p.length*34+60)},children:p.length===0?$e.jsxDEV(Gu,{message:"No usage snapshots recorded yet — they accumulate whenever usage is fetched"},void 0,!1,void 0,this):$e.jsxDEV(li,{data:h,options:g},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var GA=Q(dt(),1);var Tt=Q(de(),1);function XA({active:a,refreshTrigger:n,onRequestClick:s}){let{data:i,error:l,loading:u}=Vt(["recent-requests-dense",n],(h)=>Rm(50,h),{pollMs:30000,enabled:a}),d=GA.useMemo(()=>[{key:"model",header:"Model",render:(h)=>Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:h.model},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:h.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"timestamp",header:"Time",render:(h)=>za(h.timestamp)},{key:"tokens",header:"Tokens",numeric:!0,render:(h)=>Ce(h.usage.totalTokens)},{key:"cost",header:"API-equivalent estimate",numeric:!0,render:(h)=>ln(h,4)},{key:"duration",header:"Duration",numeric:!0,render:(h)=>rt(h.duration)},{key:"status",header:"Status",className:"stats-text-center",render:(h)=>Tt.jsxDEV(ya,{variant:h.errorMessage?"danger":"success",children:h.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)}],[]);return Tt.jsxDEV("div",{className:"stats-route-container",children:Tt.jsxDEV(ut,{title:"All Recent Requests",subtitle:"Up to 50 most recent requests processed by OMP",children:Tt.jsxDEV(Rt,{loading:u,error:l,data:i,children:Tt.jsxDEV(Ma,{columns:d,data:i||[],keyExtractor:(h)=>h.id||`${h.sessionFile}-${h.entryId}`,onRowClick:(h)=>h.id&&s(h.id),renderMobileCard:(h,g)=>Tt.jsxDEV("div",{className:"stats-mobile-card",onClick:g,children:[Tt.jsxDEV("div",{className:"stats-mobile-card-header",children:[Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-font-semibold stats-text-primary",children:h.model},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-text-xs stats-text-muted",children:h.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV(ya,{variant:h.errorMessage?"danger":"success",children:h.errorMessage?"Failed":"Success"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-grid",children:[Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Time"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:za(h.timestamp)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"API-equivalent estimate"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:ln(h,4)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Tokens"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:Ce(h.usage.totalTokens)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Tt.jsxDEV("div",{children:[Tt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),Tt.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(h.duration)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h.errorMessage&&Tt.jsxDEV("div",{className:"stats-mobile-card-error truncate mt-2",children:h.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),emptyText:"No recent requests found"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var cn=Q(dt(),1);var re=Q(de(),1);function YA({active:a,range:n,refreshTrigger:s}){let{data:i,error:l,loading:u}=Vt(["tools",n,s],(d)=>NI(n,d),{pollMs:30000,enabled:a});return re.jsxDEV("div",{className:"stats-route-container space-y-6",children:re.jsxDEV(Rt,{loading:u,error:l,data:i,emptyText:"No tool calls recorded for this range.",children:i&&re.jsxDEV(re.Fragment,{children:[re.jsxDEV(_z,{byTool:i.byTool},void 0,!1,void 0,this),re.jsxDEV(Oz,{series:i.series,timeRange:n},void 0,!1,void 0,this),re.jsxDEV(Pz,{byTool:i.byTool},void 0,!1,void 0,this),re.jsxDEV(Bz,{byToolModel:i.byToolModel},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function _z({byTool:a}){let n=cn.useMemo(()=>{let s=0,i=0,l=0,u=0,d=0,p=0,h=0,g=0;for(let b of a)s+=b.calls,i+=b.errors,l+=b.totalTokensShare,u+=b.outputTokensShare,d+=b.costShare,p+=b.unpricedRequestsShare,h+=b.resultChars,g+=b.argsChars;return{calls:s,errors:i,tokens:l,output:u,cost:d,unpricedRequests:p,resultChars:h,argsChars:g,tools:a.length}},[a]);return re.jsxDEV(ut,{title:"Tool Usage",subtitle:"Tokens and API-equivalent estimates are split from invoking turns across each turn's tool calls",children:re.jsxDEV("div",{className:"stats-metric-cluster",children:[re.jsxDEV("div",{className:"stats-metric-primary-grid",children:[re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Tool Calls"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ce(n.calls)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Tools Used"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ce(n.tools)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Error Rate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:Ht(n.calls>0?n.errors/n.calls:0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card primary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed API-equivalent estimate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:ka(n.cost,n.unpricedRequests)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-secondary-grid",children:[re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed Tokens"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:lt(Math.round(n.tokens))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Attributed Output"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:lt(Math.round(n.output))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Result Text"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:[lt(n.resultChars)," chars"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-metric-card secondary",children:[re.jsxDEV("div",{className:"stats-metric-label",children:"Call Arguments"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-metric-value",children:[lt(n.argsChars)," chars"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var Dz=6;function Ez(a){let n=new Map;for(let g of a)n.set(g.tool,(n.get(g.tool)??0)+g.calls);let s=[...n.entries()].sort((g,b)=>b[1]-g[1]),i=s.slice(0,Dz).map(([g])=>g),l=new Set(i),d=s.length>i.length?[...i,"Other"]:i,p=[...new Set(a.map((g)=>g.timestamp))].sort((g,b)=>g-b),h=new Map;for(let g of p)h.set(g,{});for(let g of a){let b=l.has(g.tool)?g.tool:"Other",y=h.get(g.timestamp);if(y)y[b]=(y[b]??0)+g.calls}return{buckets:p,tools:d,data:h}}function Oz({series:a,timeRange:n}){let s=$t(),i=sa[s],l=Ll(n),u=cn.useMemo(()=>Ez(a),[a]),d=cn.useMemo(()=>({labels:u.buckets.map((h)=>Lf(h,n)),datasets:u.tools.map((h,g)=>({label:h,data:u.buckets.map((b)=>u.data.get(b)?.[h]??0),borderColor:bt[g%bt.length],backgroundColor:`${bt[g%bt.length]}30`,fill:!0,tension:0.4,pointRadius:0,pointHoverRadius:4,borderWidth:2}))}),[u,n]),p=cn.useMemo(()=>({responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{legend:{position:"top",align:"start",labels:{color:i.legendLabel,usePointStyle:!0,padding:16,font:{size:12},boxWidth:8}},tooltip:{backgroundColor:i.tooltipBackground,titleColor:i.tooltipTitle,bodyColor:i.tooltipBody,borderColor:i.tooltipBorder,borderWidth:1,padding:12,cornerRadius:8,callbacks:{label:(h)=>`${h.dataset.label??""}: ${Ce(h.parsed.y??0)} calls`}}},scales:{x:{stacked:!0,grid:{color:i.grid,drawBorder:!1},ticks:{color:i.tick,font:{size:11}}},y:{stacked:!0,grid:{color:i.grid,drawBorder:!1},ticks:{color:i.tick,font:{size:11},precision:0},min:0}}}),[i]);return re.jsxDEV(ut,{title:"Calls Over Time",subtitle:`Tool calls over ${l.windowLabel}, stacked by tool`,children:re.jsxDEV("div",{className:"h-[280px]",children:u.buckets.length===0?re.jsxDEV("div",{className:"h-full flex items-center justify-center text-stats-muted text-sm",children:"No data available"},void 0,!1,void 0,this):re.jsxDEV(Xa,{data:d,options:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function s0(a){return a>0.1?"danger":a>0?"warning":"success"}function Pz({byTool:a}){let n=cn.useMemo(()=>LA(a),[a]),s=cn.useMemo(()=>[{key:"tool",header:"Tool",render:(l)=>re.jsxDEV("div",{className:"stats-font-medium stats-text-primary font-mono truncate max-w-[280px]",title:l.tool,children:l.tool},void 0,!1,void 0,this)},{key:"calls",header:"Calls",numeric:!0,render:(l)=>re.jsxDEV("div",{className:"stats-text-right",children:[re.jsxDEV("div",{className:"font-mono",children:Ce(l.calls)},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-progress-bar-track mt-1 ml-auto w-24 h-1",children:re.jsxDEV("div",{className:"stats-progress-bar-fill","data-variant":"link",style:{width:`${l.callsPercentage}%`}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(l)=>re.jsxDEV(ya,{variant:s0(l.errorRate),children:Ht(l.errorRate)},void 0,!1,void 0,this)},{key:"tokens",header:"Attr. Tokens",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",title:"Invoking turns' total tokens, split across each turn's calls",children:lt(Math.round(l.totalTokensShare))},void 0,!1,void 0,this)},{key:"cost",header:"Attr. API-equivalent estimate",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",children:ka(l.costShare,l.unpricedRequestsShare)},void 0,!1,void 0,this)},{key:"resultChars",header:"Result Text",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"font-mono",title:"Characters of tool-result text fed back into context",children:lt(l.resultChars)},void 0,!1,void 0,this)},{key:"lastUsed",header:"Last Used",numeric:!0,render:(l)=>re.jsxDEV("span",{className:"stats-text-secondary",children:za(l.lastUsed)},void 0,!1,void 0,this)}],[]);return re.jsxDEV(ut,{title:"By Tool",subtitle:"Usage per tool, most called first",children:re.jsxDEV(Ma,{columns:s,data:n,keyExtractor:(l)=>l.tool,renderMobileCard:(l)=>re.jsxDEV("div",{className:"stats-mobile-card",children:[re.jsxDEV("div",{className:"stats-mobile-card-header mb-2",children:[re.jsxDEV("div",{className:"stats-font-semibold stats-text-primary font-mono",children:l.tool},void 0,!1,void 0,this),re.jsxDEV(ya,{variant:s0(l.errorRate),children:[Ht(l.errorRate)," Err"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-grid",children:[re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Calls"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:Ce(l.calls)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Attr. Tokens"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:lt(Math.round(l.totalTokensShare))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Attr. API-equivalent estimate"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:ka(l.costShare,l.unpricedRequestsShare)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-mobile-card-label",children:"Result Text"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-mobile-card-value font-mono",children:lt(l.resultChars)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),emptyText:"No tool calls recorded for this range."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Bz({byToolModel:a}){let[n,s]=cn.useState(null),i=cn.useMemo(()=>[...new Set(a.map((d)=>d.tool))].sort(),[a]),l=cn.useMemo(()=>(n?a.filter((p)=>p.tool===n):a).map((p)=>({...p,errorRate:p.calls>0?p.errors/p.calls:0})),[a,n]),u=cn.useMemo(()=>[{key:"tool",header:"Tool",render:(d)=>re.jsxDEV("span",{className:"stats-font-medium stats-text-primary font-mono",children:d.tool},void 0,!1,void 0,this)},{key:"model",header:"Model",render:(d)=>re.jsxDEV("div",{children:[re.jsxDEV("div",{className:"stats-text-primary",children:d.model||"(unknown)"},void 0,!1,void 0,this),re.jsxDEV("div",{className:"stats-text-secondary text-xs",children:d.provider},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},{key:"calls",header:"Calls",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:Ce(d.calls)},void 0,!1,void 0,this)},{key:"errorRate",header:"Error Rate",numeric:!0,render:(d)=>re.jsxDEV(ya,{variant:s0(d.errorRate),children:Ht(d.errorRate)},void 0,!1,void 0,this)},{key:"tokens",header:"Attr. Tokens",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:lt(Math.round(d.totalTokensShare))},void 0,!1,void 0,this)},{key:"cost",header:"Attr. API-equivalent estimate",numeric:!0,render:(d)=>re.jsxDEV("span",{className:"font-mono",children:ka(d.costShare,d.unpricedRequestsShare)},void 0,!1,void 0,this)}],[]);return re.jsxDEV(ut,{title:"By Model",subtitle:"Which models call which tools",children:[re.jsxDEV("div",{className:"mb-4",style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[re.jsxDEV("span",{className:"stats-text-secondary",style:{fontSize:"0.875rem",whiteSpace:"nowrap"},children:"Tool"},void 0,!1,void 0,this),re.jsxDEV("select",{className:"stats-select",value:n??"",onChange:(d)=>s(d.target.value||null),style:{maxWidth:"320px",flex:1},children:[re.jsxDEV("option",{value:"",children:"All tools"},void 0,!1,void 0,this),i.map((d)=>re.jsxDEV("option",{value:d,children:d},d,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),re.jsxDEV(Ma,{columns:u,data:l,keyExtractor:(d)=>`${d.tool}::${d.model}::${d.provider}`,emptyText:"No tool calls recorded for this range."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var If=Q(dt(),1);var wt=Q(dt(),1);var Zm=Q(dt(),1);var Qs=Q(de(),1);function $A({toolStats:a}){let[n,s]=Zm.useState(!1),i=Zm.useMemo(()=>[{key:"tool",header:"Tool",render:(l)=>l.tool},{key:"calls",header:"Calls",numeric:!0,render:(l)=>Ce(l.calls)},{key:"errors",header:"Errors",numeric:!0,render:(l)=>Ce(l.errors)},{key:"total",header:"Total",numeric:!0,render:(l)=>rt(l.totalMs)},{key:"avg",header:"Avg",numeric:!0,render:(l)=>rt(l.calls>0?l.totalMs/l.calls:0)},{key:"max",header:"Max",numeric:!0,render:(l)=>rt(l.maxMs)}],[]);if(a.length===0)return null;return Qs.jsxDEV("div",{className:"stats-panel",children:[Qs.jsxDEV("button",{type:"button",onClick:()=>s((l)=>!l),"aria-expanded":n,style:{display:"flex",alignItems:"center",gap:6,width:"100%",background:"none",border:"none",padding:"10px 14px",cursor:"pointer",textAlign:"left"},children:[n?Qs.jsxDEV(Ys,{size:14,className:"stats-text-muted","aria-hidden":"true"},void 0,!1,void 0,this):Qs.jsxDEV(hl,{size:14,className:"stats-text-muted","aria-hidden":"true"},void 0,!1,void 0,this),Qs.jsxDEV("span",{className:"stats-panel-title",children:"Tool Aggregates"},void 0,!1,void 0,this),Qs.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:11},children:[a.length," tools"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),n&&Qs.jsxDEV("div",{className:"stats-panel-body",children:Qs.jsxDEV(Ma,{columns:i,data:a,keyExtractor:(l)=>l.tool,emptyText:"No tool calls"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var wn=Q(dt(),1);var $u={dark:{category:{turn:"#34d399",model:"#a78bfa",tool:"#fbbf24",subagent:"#38bdf8",background:"#94a3b8"},error:"#f87171",marker:"#facc15",turnBand:"rgba(255, 255, 255, 0.035)",surface:"transparent",grid:"rgba(255, 255, 255, 0.06)",tick:"#867a93",spanText:"#16121c",selection:"#5ad8e6",tooltipBackground:"#241a2e",tooltipTitle:"#eae5ef",tooltipBody:"#a89fb3",tooltipBorder:"rgba(255, 255, 255, 0.12)"},light:{category:{turn:"#059669",model:"#7c3aed",tool:"#d97706",subagent:"#0284c7",background:"#64748b"},error:"#ef4444",marker:"#ca8a04",turnBand:"rgba(0, 0, 0, 0.04)",surface:"transparent",grid:"rgba(20, 12, 28, 0.08)",tick:"#6a6275",spanText:"#ffffff",selection:"#0e7490",tooltipBackground:"#ffffff",tooltipTitle:"#241a2e",tooltipBody:"#5a5462",tooltipBorder:"rgba(20, 12, 28, 0.15)"}};var QA=Q(de(),1),fi=44,r0=["turn","model","tool","subagent"],WA=6,Wu=10;function ZA({tracks:a,scale:n,viewport:s,onViewportChange:i}){let l=$t(),u=$u[l],d=wn.useRef(null),[p,h]=wn.useState(800),g=wn.useRef(null);wn.useEffect(()=>{let B=d.current;if(!B)return;let z=new ResizeObserver((H)=>{h(Math.max(100,Math.floor(H[0].contentRect.width)))});return z.observe(B),()=>z.disconnect()},[]);let[b,y]=n.domain,v=Math.max(y-b,0.000000001),T=wn.useCallback((B)=>(B-b)/v*p,[b,v,p]),M=wn.useCallback((B)=>b+B/Math.max(p,1)*v,[b,v,p]);wn.useEffect(()=>{let B=d.current;if(!B)return;let z=B.getContext("2d");if(!z)return;let H=devicePixelRatio;z.setTransform(H,0,0,H,0,0),z.clearRect(0,0,p,fi);let V=fi/r0.length;for(let Y=0;Y<r0.length;Y++){let J=r0[Y],j=new Float32Array(p);for(let se of a)for(let ge of se.spans){if(ge.kind!==J)continue;let ye=Math.max(0,Math.floor(T(n.toU(ge.start)))),Se=Math.min(p-1,Math.ceil(T(n.toU(ge.end))));for(let K=ye;K<=Se;K++)j[K]=Math.min(1,j[K]+0.34)}z.fillStyle=u.category[J];for(let se=0;se<p;se++){if(j[se]<=0)continue;z.globalAlpha=0.25+j[se]*0.75,z.fillRect(se,Y*V+1,1,V-2)}z.globalAlpha=1}let G=T(s.u0),X=T(s.u1);z.fillStyle=l==="dark"?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",z.fillRect(G,0,X-G,fi),z.strokeStyle=u.selection,z.strokeRect(G+0.5,0.5,X-G-1,fi-1),z.fillStyle=u.selection,z.fillRect(G,0,2,fi),z.fillRect(X-2,0,2,fi)},[a,n,s,u,l,p,T]);let I=(B)=>{let z=B.currentTarget.getBoundingClientRect(),H=B.clientX-z.left,V=T(s.u0),G=T(s.u1),X;if(Math.abs(H-V)<=WA)X="left";else if(Math.abs(H-G)<=WA)X="right";else if(H>V&&H<G)X="move";else{X="create";let Y=M(H);i(wf({u0:Y,u1:Y+Wu},b,y))}g.current={mode:X,startX:H,startViewport:s},B.currentTarget.setPointerCapture(B.pointerId)},w=(B)=>{let z=g.current;if(!z)return;let H=B.currentTarget.getBoundingClientRect(),V=B.clientX-H.left,G=M(V)-M(z.startX),{u0:X,u1:Y}=z.startViewport;if(z.mode==="move")i(wf({u0:X+G,u1:Y+G},b,y));else if(z.mode==="left")i(wf({u0:Math.min(X+G,Y-Wu),u1:Y},b,y));else if(z.mode==="right")i(wf({u0:X,u1:Math.max(Y+G,X+Wu)},b,y));else{let J=M(z.startX),j=M(V);i(wf({u0:Math.min(J,j),u1:Math.max(J,j,Math.min(J,j)+Wu)},b,y))}},A=()=>{g.current=null};return QA.jsxDEV("canvas",{ref:d,width:Math.floor(p*devicePixelRatio),height:Math.floor(fi*devicePixelRatio),style:{width:"100%",height:fi,display:"block",cursor:"crosshair",borderRadius:4,border:"1px solid var(--border)",touchAction:"none"},role:"slider","aria-label":"Timeline overview brush","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round((s.u0-b)/v*100),tabIndex:-1,onPointerDown:I,onPointerMove:w,onPointerUp:A},void 0,!1,void 0,this)}function wf(a,n,s){let i=Math.max(Wu,a.u1-a.u0);i=Math.min(i,s-n||Wu);let l=a.u0;if(l<n)l=n;if(l+i>s)l=s-i;return{u0:l,u1:l+i}}var kn=Q(dt(),1);var Te=Q(de(),1);function Nz(a){let n=[];if(typeof a==="string"){if(a.trim())n.push({kind:"text",text:a});return n}if(!Array.isArray(a))return n;for(let s of a){if(!s||typeof s!=="object"||!("type"in s))continue;if((s.type==="text"||s.type==="thinking")&&"text"in s&&typeof s.text==="string")n.push({kind:String(s.type),text:s.text})}return n}function KA({span:a,track:n,onClose:s,onOpenChildTrack:i}){let[l,u]=kn.useState(null),[d,p]=kn.useState(!1),[h,g]=kn.useState(null),[b,y]=kn.useState(!1),v=kn.useRef(null),T=kn.useRef(null);if(kn.useEffect(()=>{if(u(null),g(null),y(!1),!a||!n||!a.entryId)return;T.current=document.activeElement instanceof HTMLElement?document.activeElement:null,p(!0);let z=new AbortController;return FI(n.file,a.entryId,z.signal).then((H)=>{if(z.signal.aborted)return;u(H.entry),setTimeout(()=>v.current?.focus(),50)}).catch((H)=>{if(z.signal.aborted)return;g(H instanceof Error?H:Error(String(H)))}).finally(()=>{if(!z.signal.aborted)p(!1)}),()=>z.abort()},[a,n]),kn.useEffect(()=>{if(!a)return;let z=(H)=>{if(H.key==="Escape")s()};return window.addEventListener("keydown",z),()=>{window.removeEventListener("keydown",z),T.current?.focus()}},[a,s]),!a)return null;let M=(z)=>{if(z.target===z.currentTarget)s()},I=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(l??a,null,2)),y(!0),setTimeout(()=>y(!1),1500)}catch{}},A=(l&&typeof l==="object"?l:{}).message,B=A?.usage;return Te.jsxDEV("div",{className:"stats-drawer-overlay",onClick:M,role:"presentation",children:Te.jsxDEV("div",{className:"stats-drawer",role:"dialog","aria-modal":"true","aria-label":"Span details",children:[Te.jsxDEV("div",{className:"stats-drawer-header",children:[Te.jsxDEV("div",{className:"stats-drawer-header-left",children:[Te.jsxDEV("h2",{className:"stats-drawer-title truncate",style:{maxWidth:320},children:a.label},void 0,!1,void 0,this),Te.jsxDEV(ya,{variant:a.isError?"danger":"success",children:a.kind},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{style:{display:"flex",gap:8},children:[Te.jsxDEV("button",{type:"button",onClick:I,className:"stats-drawer-close-btn","aria-label":"Copy raw JSON",title:"Copy raw JSON",children:b?Te.jsxDEV(pl,{size:16},void 0,!1,void 0,this):Te.jsxDEV(gl,{size:16},void 0,!1,void 0,this)},void 0,!1,void 0,this),Te.jsxDEV("button",{ref:v,type:"button",onClick:s,className:"stats-drawer-close-btn","aria-label":"Close span details",children:Te.jsxDEV($s,{size:18},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-body",children:Te.jsxDEV("div",{className:"stats-drawer-content",children:[Te.jsxDEV("div",{className:"stats-drawer-metrics-grid",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Duration"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(a.end-a.start)},void 0,!1,void 0,this),a.unterminated&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:"unterminated"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Start"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",style:{fontSize:13},children:new Date(a.start).toLocaleTimeString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a.kind==="model"&&Te.jsxDEV(Te.Fragment,{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Tokens"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:Ce(a.tokens??0)},void 0,!1,void 0,this),B&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:[Ce(B.input??0)," in · ",Ce(B.output??0)," out ·"," ",Ce(B.cacheRead??0)," cached"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Cost"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:["$",(a.cost??0).toFixed(4)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"TTFT"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",children:rt(a.ttft??null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-card",children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Model"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-metric-value",style:{fontSize:12},children:A?.model??a.model??"-"},void 0,!1,void 0,this),A?.provider&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:A.provider},void 0,!1,void 0,this),A?.stopReason&&Te.jsxDEV("div",{className:"stats-drawer-metric-sub",children:["stop: ",A.stopReason]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),A?.errorMessage&&Te.jsxDEV("div",{className:"stats-drawer-error-block",children:[Te.jsxDEV("div",{className:"stats-drawer-error-label",children:"Error Message"},void 0,!1,void 0,this),Te.jsxDEV("div",{className:"stats-drawer-error-text",children:A.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a.kind==="subagent"&&Te.jsxDEV("div",{children:[a.detail&&Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10},children:a.detail},void 0,!1,void 0,this),a.childTrackId&&i&&Te.jsxDEV("button",{type:"button",className:"stats-segmented-control-btn",style:{marginTop:8,border:"1px solid var(--border)",borderRadius:6},onClick:()=>i(a.childTrackId??""),children:["Open child track ",a.childTrackId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a.kind==="tool"&&a.detail&&Te.jsxDEV("div",{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",children:"Args"},void 0,!1,void 0,this),Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10},children:a.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&Te.jsxDEV("div",{children:[Te.jsxDEV(Ua,{variant:"rect",width:"100%",height:80,className:"mb-4"},void 0,!1,void 0,this),Te.jsxDEV(Ua,{variant:"rect",width:"100%",height:160},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h&&Te.jsxDEV("div",{className:"stats-drawer-error",children:[Te.jsxDEV("p",{className:"stats-drawer-error-title",children:"Failed to load entry"},void 0,!1,void 0,this),Te.jsxDEV("p",{className:"stats-drawer-error-message",children:h.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!d&&l!==null&&Nz(A?.content).map((z,H)=>Te.jsxDEV("div",{children:[Te.jsxDEV("div",{className:"stats-drawer-metric-label",style:{textTransform:"capitalize"},children:z.kind},void 0,!1,void 0,this),Te.jsxDEV("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:12,background:"var(--surface-2)",borderRadius:6,padding:10,maxHeight:360,overflowY:"auto"},children:z.text},void 0,!1,void 0,this)]},`${z.kind}-${H}`,!0,void 0,this)),!d&&l!==null&&Te.jsxDEV("div",{className:"stats-drawer-json-blocks",children:Te.jsxDEV(Cf,{data:l,title:"Raw Entry",initialCollapsed:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var kf=Q(de(),1);function JA({summary:a}){let n=[{label:"Wall",value:rt(a.wallMs)},{label:"Model",value:rt(a.modelMs)},{label:"Tools",value:rt(a.toolMs)},{label:"Idle",value:rt(a.idleMs)},{label:"Turns",value:Ce(a.turns)},{label:"Requests",value:Ce(a.requests)},{label:"Tool Calls",value:Ce(a.toolCalls)},{label:"Agents",value:Ce(a.subagents)},{label:"Tokens",value:lt(a.totalTokens)},{label:"Cost",value:us(a.costTotal)}];return kf.jsxDEV("div",{className:"stats-trace-summary",children:n.map((s)=>kf.jsxDEV("div",{className:"stats-trace-summary-cell",children:[kf.jsxDEV("span",{className:"stats-trace-summary-label",children:s.label},void 0,!1,void 0,this),kf.jsxDEV("span",{className:"stats-trace-summary-value",children:s.value},void 0,!1,void 0,this)]},s.label,!0,void 0,this))},void 0,!1,void 0,this)}var jt=Q(dt(),1);function Qm(a,n){let s=a.length,i=[n[0],n[s-1]],l=(u,d)=>{let p=0,h=s-1;while(p<h){let g=p+h+1>>1;if(u[g]<=d)p=g;else h=g-1}return Math.min(p,s-2)};return{toU(u){if(u<=a[0])return n[0];if(u>=a[s-1])return n[s-1];let d=l(a,u),p=a[d+1]-a[d];if(p<=0)return n[d];return n[d]+(u-a[d])/p*(n[d+1]-n[d])},toT(u){if(u<=n[0])return a[0];if(u>=n[s-1])return a[s-1];let d=l(n,u),p=n[d+1]-n[d];if(p<=0)return a[d];return a[d]+(u-n[d])/p*(a[d+1]-a[d])},domain:i,gaps:[]}}function zz(a){let n=[];for(let s of a)for(let i of s.spans)n.push([i.start,i.end]);return n.sort((s,i)=>s[0]-i[0]),n}function Hz(a){let{POSITIVE_INFINITY:n,NEGATIVE_INFINITY:s}=Number;for(let i of a)for(let l of i.spans){if(l.start<n)n=l.start;if(l.end>s)s=l.end}if(!Number.isFinite(n))return[0,1];return[n,Math.max(s,n+1)]}function eR(a,n,s){let i=[...new Set(a.filter((p)=>p>=n&&p<=s))].sort((p,h)=>p-h);if(i[0]!==n)i.unshift(n);if(i[i.length-1]!==s)i.push(s);if(i.length<2)return Qm([n,s],[n,s]);let u=(s-n)/(i.length-1),d=i.map((p,h)=>n+h*u);return Qm(i,d)}function Uz(a,n,s){let i=zz(a),l=[];for(let[b,y]of i){let v=b-2000,T=y+2000,M=l[l.length-1];if(M&&v<=M[1]){if(T>M[1])M[1]=T}else l.push([v,T])}if(l.length===0)l.push([n,s]);l[0][0]=Math.max(l[0][0],n),l[l.length-1][1]=Math.min(Math.max(l[l.length-1][1],l[l.length-1][0]),s);let u=[],d=[],p=[],h=l[0][0];for(let b=0;b<l.length;b++){let[y,v]=l[b];if(b===0)u.push(y),d.push(h);else{let T=l[b-1][1],M=y-T;if(M>30000)h+=8000,p.push({t0:T,t1:y,uMid:h-4000});else h+=M;u.push(y),d.push(h)}h+=Math.max(0,v-y),u.push(v),d.push(h)}return{...Qm(u,d),gaps:p}}function tR(a,n,s){let[i,l]=Hz(a);if(n==="turns"){let d=(a.find((p)=>p.id==="main")?.spans??[]).filter((p)=>p.kind==="turn").map((p)=>p.start);return eR(d,i,l)}if(n==="calls"){let u=[];for(let d of a)for(let p of d.spans)if(p.kind==="model"||p.kind==="tool"||p.kind==="background")u.push(p.start,p.end);return eR(u,i,l)}if(s)return Uz(a,i,l);return Qm([i,l],[i,l])}var Fz=90;function qz(a){let n=10**Math.floor(Math.log10(Math.max(a,1)));for(let s of[1,2,5,10])if(n*s>=a)return n*s;return n*10}function Vz(a){let n=new Date(a),s=String(n.getHours()).padStart(2,"0"),i=String(n.getMinutes()).padStart(2,"0"),l=String(n.getSeconds()).padStart(2,"0");return`${s}:${i}:${l}`}function Zu(a){let n=a<0?"-":"+",s=Math.abs(a),i=Math.floor(s/3600000),l=Math.floor(s%3600000/60000),u=Math.floor(s%60000/1000),d=Math.floor(s%1000),p=s%1000!==0,h=`${String(l).padStart(2,"0")}:${String(u).padStart(2,"0")}${p?".":""}${p?String(d).padStart(3,"0"):""}`;return i>0?`${n}${i}:${h}`:`${n}${h}`}function aR(a,n,s,i){let l=s-n;if(l<=0||i<=0)return[];let u=[],d=a.domain[0],p=qz(l*Fz/i),h=d+Math.ceil((n-d)/p)*p,g=0;for(let b=h;b<=s&&g<200;b+=p,g++){let y=a.toT(b),v=Math.round((b-d)/p)%5===0;u.push({u:b,label:v?Vz(y):Zu(b-d),major:v})}return u}var xt=Q(de(),1),Ks=28,l0=22,So=18,oR=3,jz=14,nR=200,i0=10,Gz=2,Xz=4,Yz=56,sR=3,$z=[{kind:"turn",label:"Input"},{kind:"model",label:"Model"},{kind:"tool",label:"Tools"},{kind:"subagent",label:"Agents"},{kind:"background",label:"Bg"}];function Wz(a,n){let s=new Map(a.map((h)=>[h.id,h])),i=new Set;for(let h of a)if(h.parentId)i.add(h.parentId);let l=(h)=>{let g=h.parentId;while(g){if(n.has(g))return!0;g=s.get(g)?.parentId??null}return!1},u=[],d=[],p=Ks+6;for(let h of a){if(l(h))continue;let g=h.id==="main"?0:h.id.split("/").length,b={track:h,depth:g,hasChildren:i.has(h.id),headerY:p,lanes:[],y0:p,y1:p};p+=l0;for(let{kind:y,label:v}of $z){let T=h.spans.filter((w)=>w.kind===y),M=y==="turn"||y==="model"||y==="tool";if(T.length===0&&!(h.id==="main"&&M))continue;let I={track:h,kind:y,label:v,y:p,spans:T};b.lanes.push(I),d.push(I),p+=So+oR}b.y1=p-oR,u.push(b),p+=jz}return{blocks:u,lanes:d,totalHeight:Math.max(p,Ks+48)}}function rR({tracks:a,scale:n,viewport:s,onViewportChange:i,selection:l,onSelect:u,search:d,collapsed:p,onToggleCollapse:h,traceStart:g}){let b=$t(),y=$u[b],v=jt.useRef(null),T=jt.useRef(null),[M,I]=jt.useState(800),[w,A]=jt.useState(null),B=jt.useRef([]),z=jt.useRef(null),H=jt.useRef(null),V=jt.useRef(s);V.current=s;let G=jt.useMemo(()=>Wz(a,p),[a,p]);jt.useEffect(()=>{let k=v.current;if(!k)return;let W=new ResizeObserver((ee)=>{let ne=Math.max(100,Math.floor(ee[0].contentRect.width-nR));I(ne)});return W.observe(k),()=>W.disconnect()},[]);let X=jt.useCallback((k,W)=>{let[ee,ne]=n.domain,te=Math.max(i0,W-k);te=Math.min(te,ne-ee||i0);let le=k;if(le<ee)le=ee;if(le+te>ne)le=ne-te;return{u0:le,u1:le+te}},[n]),Y=jt.useCallback((k)=>{V.current=k,i(k)},[i]),J=jt.useCallback((k,W)=>{let ee=M,{u0:ne,u1:te}=V.current,le=te-ne,fe=W===null?0.5:Math.min(1,Math.max(0,W/ee)),et=ne+le*fe,tt=le*k;Y(X(et-tt*fe,et+tt*(1-fe)))},[M,Y,X]),j=jt.useCallback((k)=>{let{u0:W,u1:ee}=V.current;Y(X(W+k,ee+k))},[Y,X]),se=jt.useCallback((k)=>{let W=n.toU(k.start),ee=n.toU(k.end),ne=Math.max((ee-W)*0.1,i0/2);Y(X(W-ne,ee+ne))},[n,Y,X]);jt.useEffect(()=>{let k=T.current;if(!k)return;let W=(ee)=>{ee.preventDefault();let ne=k.getBoundingClientRect(),te=ee.clientX-ne.left;H.current=te,A(null);let le=k.clientWidth||1,fe=()=>V.current.u1-V.current.u0;if(ee.shiftKey){let et=Math.abs(ee.deltaY)>=Math.abs(ee.deltaX)?ee.deltaY:ee.deltaX;j(et/le*fe());return}if(ee.deltaX!==0)j(ee.deltaX/le*fe());if(ee.deltaY!==0)J(1.0015**ee.deltaY,te)};return k.addEventListener("wheel",W,{passive:!1}),()=>k.removeEventListener("wheel",W)},[J,j]);let ge=jt.useCallback((k,W)=>{let ee=T.current;if(!ee)return null;let ne=ee.getBoundingClientRect(),te=k-ne.left,le=W-ne.top,fe=B.current;for(let et=fe.length-1;et>=0;et--){let tt=fe[et];if(te>=tt.x&&te<=tt.x+tt.w&&le>=tt.y&&le<=tt.y+tt.h)return tt}return null},[]),ye=(k)=>{k.currentTarget.setPointerCapture(k.pointerId),z.current={pointerId:k.pointerId,lastX:k.clientX,moved:!1},k.currentTarget.focus()},Se=(k)=>{let W=k.currentTarget.getBoundingClientRect();H.current=k.clientX-W.left;let ee=z.current;if(ee&&ee.pointerId===k.pointerId){let te=k.clientX-ee.lastX;if(Math.abs(te)>0){if(Math.abs(te)>2)ee.moved=!0;ee.lastX=k.clientX;let le=V.current.u1-V.current.u0;j(-te/(M||1)*le)}A(null);return}let ne=ge(k.clientX,k.clientY);A(ne?{hit:ne,clientX:k.clientX,clientY:k.clientY}:null)},K=(k)=>{let W=z.current;if(z.current=null,W?.moved)return;let ee=ge(k.clientX,k.clientY);if(ee?.kind==="span")u(ee.span.id);else u(null)},pe=(k)=>{let W=ge(k.clientX,k.clientY);if(W?.kind==="span")se(W.span)},be=jt.useCallback((k)=>{if(!l)return;for(let W of G.lanes){let ee=W.spans.findIndex((le)=>le.id===l);if(ee===-1)continue;let ne=W.spans[ee+k];if(!ne)return;u(ne.id);let te=n.toU(ne.start);if(te<s.u0||te>s.u1){let le=s.u1-s.u0;i(X(te-le/2,te+le/2))}return}},[l,G,u,n,s,i,X]),Ue=(k)=>{let W=s.u1-s.u0;switch(k.key){case"w":case"W":J(0.7692307692307692,H.current);break;case"s":case"S":J(1.3,H.current);break;case"a":case"A":j(-W*0.2);break;case"d":case"D":j(W*0.2);break;case"0":i({u0:n.domain[0],u1:n.domain[1]});break;case"f":case"F":{if(!l)break;let ee=a.flatMap((ne)=>ne.spans).find((ne)=>ne.id===l);if(ee)se(ee);break}case"Escape":u(null);break;case",":be(-1);break;case".":be(1);break;default:return}k.preventDefault()};jt.useEffect(()=>{T.current?.focus({preventScroll:!0})},[]),jt.useEffect(()=>{let k=T.current;if(!k)return;let W=requestAnimationFrame(()=>{Zz(k,G,n,s,y,{width:M,selection:l,hoverId:w?.hit.kind==="span"?w.hit.span.id:null,search:d,hits:B})});return()=>cancelAnimationFrame(W)},[G,n,s,y,M,l,w,d]);let He=w?Qz(w,g):null;return xt.jsxDEV("div",{ref:v,className:"stats-trace-timeline",children:[xt.jsxDEV("div",{style:{width:nR,flexShrink:0,position:"relative",height:G.totalHeight},children:G.blocks.map((k)=>xt.jsxDEV("div",{children:[xt.jsxDEV("div",{style:{position:"absolute",top:k.headerY,left:4+k.depth*14,right:8,height:l0,display:"flex",alignItems:"center",gap:5,minWidth:0},children:[k.hasChildren?xt.jsxDEV("button",{type:"button",onClick:()=>h(k.track.id),"aria-label":p.has(k.track.id)?`Expand ${k.track.label}`:`Collapse ${k.track.label}`,className:"stats-trace-chevron",children:p.has(k.track.id)?xt.jsxDEV(hl,{size:12},void 0,!1,void 0,this):xt.jsxDEV(Ys,{size:12},void 0,!1,void 0,this)},void 0,!1,void 0,this):xt.jsxDEV("span",{style:{width:12,flexShrink:0}},void 0,!1,void 0,this),xt.jsxDEV("span",{className:"stats-trace-gutter-track truncate",style:{minWidth:0},children:k.track.label},void 0,!1,void 0,this),k.track.model&&xt.jsxDEV("span",{className:"stats-trace-gutter-model truncate",style:{flexShrink:1,minWidth:0},children:k.track.model},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k.lanes.map((W)=>xt.jsxDEV("div",{className:"stats-trace-gutter-lane",style:{top:W.y,left:20+k.depth*14,lineHeight:`${So}px`},children:W.label},`${W.track.id}:${W.kind}`,!1,void 0,this))]},k.track.id,!0,void 0,this))},void 0,!1,void 0,this),xt.jsxDEV("canvas",{ref:T,className:"stats-trace-canvas",width:Math.floor(M*devicePixelRatio),height:Math.floor(G.totalHeight*devicePixelRatio),style:{width:M,height:G.totalHeight},tabIndex:0,role:"application","aria-label":"Trace timeline. W and S zoom, A and D pan, 0 fits all, F focuses the selection.",onPointerDown:ye,onPointerMove:Se,onPointerUp:K,onPointerLeave:()=>{H.current=null,A(null)},onDoubleClick:pe,onKeyDown:Ue},void 0,!1,void 0,this),He]},void 0,!0,void 0,this)}function Mf(a,n,s,i,l){if(a.beginPath(),i>=sR*2+1)a.roundRect(n,s,i,l,sR);else a.rect(n,s,i,l)}function Zz(a,n,s,i,l,u){let d=a.getContext("2d");if(!d)return;let{width:p,selection:h,hoverId:g,search:b,hits:y}=u,v=n.totalHeight,T=devicePixelRatio;d.setTransform(T,0,0,T,0,0),d.clearRect(0,0,p,v);let{u0:M,u1:I}=i,w=Math.max(I-M,0.000000001),A=(H)=>(H-M)/w*p,B=b.trim().toLowerCase(),z=[];for(let H of n.blocks){let V=H.track.spans.filter((G)=>G.kind==="turn");for(let G=0;G<V.length;G++){let X=A(s.toU(V[G].start)),Y=G+1<V.length?A(s.toU(V[G+1].start)):p;if(Y<0||X>p)continue;if(G%2===1)d.fillStyle=l.turnBand,d.fillRect(Math.max(0,X),H.y0,Math.min(p,Y)-Math.max(0,X),H.y1-H.y0);if(X>=0&&X<=p)d.strokeStyle=l.grid,d.beginPath(),d.moveTo(Math.round(X)+0.5,H.y0),d.lineTo(Math.round(X)+0.5,H.y1),d.stroke()}}for(let H of s.gaps){let V=A(H.uMid);if(V<-24||V>p+24)continue;d.save(),d.strokeStyle=l.grid,d.setLineDash([2,4]),d.beginPath(),d.moveTo(V,Ks),d.lineTo(V,v),d.stroke(),d.restore(),d.fillStyle=l.tick,d.font="9px system-ui, sans-serif",d.textAlign="center",d.fillText(`⋯ ${rt(H.t1-H.t0)}`,V,Ks-4),d.textAlign="left"}d.font="9px system-ui, sans-serif";for(let H of aR(s,M,I,p)){let V=Math.round(A(H.u))+0.5;if(d.strokeStyle=l.grid,d.beginPath(),H.major)d.moveTo(V,4),d.lineTo(V,v);else d.moveTo(V,Ks-8),d.lineTo(V,Ks);if(d.stroke(),d.fillStyle=l.tick,H.major)d.fillText(H.label,V+4,11);else d.globalAlpha=0.75,d.fillText(H.label,V+3,Ks-10),d.globalAlpha=1}d.strokeStyle=l.grid,d.beginPath(),d.moveTo(0,Ks+0.5),d.lineTo(p,Ks+0.5),d.stroke();for(let H of n.lanes){let V=H.kind==="turn";for(let G of H.spans){let X=s.toU(G.start);if(X>I)break;let Y=s.toU(G.end);if(Y<M)continue;let J=A(X),j=Math.max(Gz,A(Y)-J),se=H.y,ge=B===""||`${G.label} ${G.detail??""}`.toLowerCase().includes(B),ye=l.category[G.kind];if(d.globalAlpha=ge?1:0.3,V)d.fillStyle=`${ye}3a`,Mf(d,J,se,j,So),d.fill(),d.fillStyle=ye,d.fillRect(J,se,2,So);else d.fillStyle=ye,Mf(d,J,se,j,So),d.fill();if(G.isError)d.fillStyle=`${l.error}55`,Mf(d,J,se,j,So),d.fill(),d.fillStyle=l.error,d.fillRect(J,se,2,So);if(G.kind==="model"&&typeof G.ttft==="number"&&G.ttft>0&&j>20){let K=A(s.toU(G.start+G.ttft));if(K>J+1&&K<J+j-1)d.fillStyle="rgba(0,0,0,0.5)",d.fillRect(K,se+3,1,So-6)}if(G.unterminated)d.save(),d.strokeStyle=l.tick,d.setLineDash([2,2]),d.beginPath(),d.moveTo(J+j-0.5,se),d.lineTo(J+j-0.5,se+So),d.stroke(),d.restore();if(g===G.id)d.fillStyle="rgba(255,255,255,0.16)",Mf(d,J,se,j,So),d.fill();if(h===G.id)d.strokeStyle=l.selection,d.lineWidth=1.5,Mf(d,J-1,se-1,j+2,So+2),d.stroke(),d.lineWidth=1;if(j>Yz)d.save(),d.beginPath(),d.rect(J+3,se,j-6,So),d.clip(),d.fillStyle=V?l.tick:l.spanText,d.font="10px system-ui, sans-serif",d.fillText(G.label,J+5,se+So-5),d.restore();d.globalAlpha=1;let Se=Math.max(j,Xz);z.push({kind:"span",x:J-(Se-j)/2,y:se,w:Se,h:So,span:G,track:H.track})}}for(let H of n.blocks)for(let V of H.track.markers){let G=A(s.toU(V.time));if(G<-6||G>p+6)continue;let X=H.headerY+l0/2;d.fillStyle=l.marker,d.beginPath(),d.moveTo(G,X-4),d.lineTo(G+4,X),d.lineTo(G,X+4),d.lineTo(G-4,X),d.closePath(),d.fill(),z.push({kind:"marker",x:G-5,y:X-5,w:10,h:10,marker:V,track:H.track})}y.current=z}function Qz(a,n){let s=Math.min(a.clientX+14,window.innerWidth-320),i=a.clientY+16>window.innerHeight-140?a.clientY-120:a.clientY+16,l={position:"fixed",left:s,top:i,zIndex:60,maxWidth:300,pointerEvents:"none",background:"var(--surface-2)",border:"1px solid var(--border-strong)",borderRadius:6,padding:"7px 10px",fontSize:11,lineHeight:1.5,boxShadow:"0 1px 2px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.25)"};if(a.hit.kind==="marker"){let{marker:d}=a.hit;return xt.jsxDEV("div",{style:l,children:[xt.jsxDEV("div",{className:"stats-font-medium stats-text-primary",children:d.label},void 0,!1,void 0,this),xt.jsxDEV("div",{className:"stats-text-muted",children:[new Date(d.time).toLocaleTimeString()," (",Zu(d.time-n),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}let{span:u}=a.hit;return xt.jsxDEV("div",{style:l,children:[xt.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate",children:u.label},void 0,!1,void 0,this),xt.jsxDEV("div",{className:"stats-text-muted",children:[rt(u.end-u.start)," · ",new Date(u.start).toLocaleTimeString()," (",Zu(u.start-n),")",u.unterminated?" · unterminated":""]},void 0,!0,void 0,this),u.kind==="model"&&xt.jsxDEV("div",{className:"stats-text-muted",children:[u.tokens!==void 0&&xt.jsxDEV(xt.Fragment,{children:[u.tokens.toLocaleString()," tok"]},void 0,!0,void 0,this),u.cost!==void 0&&xt.jsxDEV(xt.Fragment,{children:[" · $",u.cost.toFixed(4)]},void 0,!0,void 0,this),u.ttft!==void 0&&xt.jsxDEV(xt.Fragment,{children:[" · TTFT ",rt(u.ttft)]},void 0,!0,void 0,this),u.isError&&xt.jsxDEV(xt.Fragment,{children:" · error"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u.kind==="subagent"&&u.model&&xt.jsxDEV("div",{className:"stats-text-muted",children:u.model},void 0,!1,void 0,this),u.detail&&xt.jsxDEV("div",{className:"stats-text-secondary",style:{wordBreak:"break-word"},children:u.detail},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Js=Q(dt(),1);var Aa=Q(de(),1),Qu=28,iR=20,Kz=340;function Jz(a){let n=[];for(let s of a){let i=s.id==="main"?0:s.id.split("/").length;for(let l of s.spans)n.push({key:l.id,time:l.start,span:l,track:s,depth:i});for(let l=0;l<s.markers.length;l++){let u=s.markers[l];n.push({key:`${s.id}:marker:${l}`,time:u.time,marker:u,track:s,depth:i})}}return n.sort((s,i)=>s.time-i.time),n}function lR({tracks:a,selection:n,onSelect:s,search:i,traceStart:l}){let u=$t(),d=$u[u],p=Js.useRef(null),[h,g]=Js.useState(0),b=Js.useMemo(()=>Jz(a),[a]),y=Js.useMemo(()=>{let I=i.trim().toLowerCase();if(!I)return b;return b.filter((w)=>(w.span?`${w.span.label} ${w.span.detail??""}`:w.marker?.label??"").toLowerCase().includes(I))},[b,i]);Js.useEffect(()=>{if(!n)return;let I=p.current;if(!I)return;let w=y.findIndex((B)=>B.span?.id===n);if(w===-1)return;let A=w*Qu;if(A<I.scrollTop||A+Qu>I.scrollTop+I.clientHeight)I.scrollTop=Math.max(0,A-I.clientHeight/2)},[n,y]);let v=Math.max(0,Math.floor(h/Qu)-iR),T=Math.min(y.length,Math.ceil((h+Kz)/Qu)+iR),M=y.slice(v,T);return Aa.jsxDEV("div",{ref:p,onScroll:(I)=>g(I.currentTarget.scrollTop),className:"stats-trace-list",children:[Aa.jsxDEV("div",{style:{height:y.length*Qu,position:"relative"},children:Aa.jsxDEV("div",{style:{position:"absolute",top:v*Qu,left:0,right:0},children:M.map((I)=>{let w=I.span,A=w!==void 0&&w.id===n,B=I.span?d.category[I.span.kind]:d.marker,z=I.span?.label??I.marker?.label??"",H=I.span?.detail,V=I.span?rt(I.span.end-I.span.start):"",G=I.span?.kind??I.marker?.kind??"",X=Aa.jsxDEV(Aa.Fragment,{children:[Aa.jsxDEV("span",{className:"stats-trace-kind",style:{color:B,background:`${B}1c`},children:G},void 0,!1,void 0,this),I.depth>0&&Aa.jsxDEV("span",{className:"stats-text-muted truncate",style:{flexShrink:0,maxWidth:90,fontSize:9},title:I.track.label,children:I.track.id},void 0,!1,void 0,this),Aa.jsxDEV("span",{className:"stats-text-primary truncate",style:{fontSize:11,minWidth:0,flexShrink:1},children:z},void 0,!1,void 0,this),H&&Aa.jsxDEV("span",{className:"stats-text-muted truncate",style:{fontSize:10,minWidth:0,flex:1},children:H},void 0,!1,void 0,this),Aa.jsxDEV("span",{className:"stats-trace-row-meta",children:[I.span?.isError&&Aa.jsxDEV("span",{style:{color:d.error},children:"error"},void 0,!1,void 0,this),Aa.jsxDEV("span",{children:V},void 0,!1,void 0,this),Aa.jsxDEV("span",{children:Zu(I.time-l)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y={paddingLeft:12+I.depth*12};return w?Aa.jsxDEV("button",{type:"button",onClick:()=>s(w.id),className:"stats-trace-row","data-selected":A?"true":"false",style:Y,children:X},I.key,!1,void 0,this):Aa.jsxDEV("div",{className:"stats-trace-row stats-trace-row-static",style:Y,children:X},I.key,!1,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),y.length===0&&Aa.jsxDEV("div",{className:"stats-text-muted",style:{padding:16,fontSize:12},children:"No matching events"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var ft=Q(de(),1),eH=[{value:"time",label:"Duration",title:"Real wall-clock time"},{value:"turns",label:"Turns",title:"Equal width per user turn"},{value:"calls",label:"Calls",title:"Equal width per model/tool call boundary"}];function uR({file:a,active:n,onBack:s}){let{data:i,error:l,loading:u,refetch:d,refreshing:p}=Vt(["trace",a],(te)=>UI(a,te),{pollMs:15000,enabled:n}),[h,g]=wt.useState("time"),[b,y]=wt.useState(!0),[v,T]=wt.useState(null),[M,I]=wt.useState(!1),[w,A]=wt.useState(""),[B,z]=wt.useState(0),[H,V]=wt.useState(new Set),[G,X]=wt.useState(null),Y=wt.useMemo(()=>i?.tracks??[],[i]),J=wt.useMemo(()=>tR(Y,h,b),[Y,h,b]),j=wt.useRef(J),se=wt.useRef(null);wt.useEffect(()=>{if(!i)return;if(se.current===i.file)return;se.current=i.file,T(null),A(""),X(null);let te=new Set;for(let le of i.tracks)if((le.id==="main"?0:le.id.split("/").length)>=1)te.add(le.id);V(te)},[i]),wt.useEffect(()=>{let te=j.current;j.current=J,X((le)=>{if(!le)return le;let fe=te.toT(le.u0),et=te.toT(le.u1),tt=J.toU(fe),Gt=J.toU(et);return Gt-tt>0?{u0:tt,u1:Gt}:null})},[J]);let ge=G??{u0:J.domain[0],u1:J.domain[1]},ye=wt.useMemo(()=>{let te=[];for(let le of Y)for(let fe of le.spans)te.push({span:fe,track:le});return te.sort((le,fe)=>le.span.start-fe.span.start),te},[Y]),Se=wt.useMemo(()=>{let te=w.trim().toLowerCase();if(!te)return[];return ye.filter(({span:le})=>`${le.label} ${le.detail??""}`.toLowerCase().includes(te))},[ye,w]),K=wt.useCallback((te)=>{let le=J.toU(te.start),fe=J.toU(te.end);X((et)=>{let tt=et??{u0:J.domain[0],u1:J.domain[1]};if(le>=tt.u0&&fe<=tt.u1)return et;let Gt=tt.u1-tt.u0,tr=(le+fe)/2,[me,ds]=J.domain,oo=tr-Gt/2;if(oo<me)oo=me;if(oo+Gt>ds)oo=Math.max(me,ds-Gt);return{u0:oo,u1:oo+Gt}})},[J]),pe=wt.useCallback((te)=>{T(te);let le=ye.find(({span:fe})=>fe.id===te);if(le)K(le.span)},[ye,K]),be=wt.useCallback((te)=>{T(te),I(te!==null)},[]),Ue=wt.useCallback((te)=>{if(Se.length===0)return;let le=((B+te)%Se.length+Se.length)%Se.length;z(le),pe(Se[le].span.id)},[Se,B,pe]),He=wt.useCallback((te)=>{V((le)=>{let fe=new Set(le);if(fe.has(te))fe.delete(te);else fe.add(te);return fe})},[]),k=wt.useMemo(()=>{if(!v)return null;return ye.find(({span:te})=>te.id===v)??null},[v,ye]),W=wt.useCallback((te)=>{let le=Y.find((et)=>et.id===te),fe=le?.spans[0];if(V((et)=>{let tt=new Set(et),Gt=le;while(Gt?.parentId)tt.delete(Gt.parentId),Gt=Y.find((tr)=>tr.id===Gt?.parentId);return tt}),fe)pe(fe.id)},[Y,pe]),ee=wt.useCallback((te)=>{if(!te){V(new Set);return}let le=new Set;for(let fe of Y)if(fe.id!=="main")le.add(fe.id);V(le)},[Y]),ne=i?.startedAt??0;return ft.jsxDEV("div",{className:"stats-trace-view",children:[ft.jsxDEV("div",{className:"stats-trace-header",children:[ft.jsxDEV("button",{type:"button",onClick:s,className:"stats-trace-back",children:[ft.jsxDEV(ef,{size:13,"aria-hidden":"true"},void 0,!1,void 0,this),"Sessions"]},void 0,!0,void 0,this),ft.jsxDEV("h2",{className:"stats-trace-title",style:{maxWidth:480,margin:0},children:i?.title??a.split("/").pop()},void 0,!1,void 0,this),i?.cwd&&ft.jsxDEV("span",{className:"stats-trace-cwd",children:i.cwd},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>void d(),className:"stats-trace-icon-btn","aria-label":"Refresh trace",title:"Refresh trace",style:{marginLeft:"auto"},children:ft.jsxDEV(yl,{size:14,className:p?"stats-spin":void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV(Rt,{loading:u,error:l,data:i,children:i&&ft.jsxDEV(ft.Fragment,{children:[ft.jsxDEV(JA,{summary:i.summary},void 0,!1,void 0,this),ft.jsxDEV("div",{className:"stats-trace-toolbar",children:[ft.jsxDEV(Zs,{options:eH,value:h,onChange:g},void 0,!1,void 0,this),h==="time"&&ft.jsxDEV("label",{className:"stats-trace-check",children:[ft.jsxDEV("input",{type:"checkbox",checked:b,onChange:(te)=>y(te.target.checked)},void 0,!1,void 0,this),"Compress idle"]},void 0,!0,void 0,this),ft.jsxDEV("div",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[ft.jsxDEV("input",{type:"search",value:w,onChange:(te)=>{A(te.target.value),z(0)},placeholder:"Search spans…","aria-label":"Search spans",spellCheck:!1,className:"stats-trace-input",style:{width:190}},void 0,!1,void 0,this),w.trim()&&ft.jsxDEV(ft.Fragment,{children:[ft.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:11,fontVariantNumeric:"tabular-nums"},children:Se.length===0?"0":`${B%Math.max(Se.length,1)+1}/${Se.length}`},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>Ue(-1),className:"stats-trace-icon-btn","aria-label":"Previous match",disabled:Se.length===0,children:"‹"},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>Ue(1),className:"stats-trace-icon-btn","aria-label":"Next match",disabled:Se.length===0,children:"›"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV("div",{style:{marginLeft:"auto",display:"inline-flex",gap:6},children:[ft.jsxDEV("button",{type:"button",onClick:()=>ee(!1),className:"stats-trace-back",children:"Expand all"},void 0,!1,void 0,this),ft.jsxDEV("button",{type:"button",onClick:()=>ee(!0),className:"stats-trace-back",children:"Collapse all"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV("div",{className:"stats-trace-timeline-card",children:[ft.jsxDEV(ZA,{tracks:Y,scale:J,viewport:ge,onViewportChange:X},void 0,!1,void 0,this),ft.jsxDEV(rR,{tracks:Y,scale:J,viewport:ge,onViewportChange:X,selection:v,onSelect:be,search:w,collapsed:H,onToggleCollapse:He,traceStart:ne},void 0,!1,void 0,this),ft.jsxDEV("div",{className:"stats-trace-toolbar-hint",style:{marginLeft:0},children:"W/S zoom · A/D pan · drag pan · wheel zoom · 0 fit · F focus selection · dbl-click focus · Esc deselect"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ft.jsxDEV(lR,{tracks:Y,selection:v,onSelect:(te)=>{pe(te),I(!0)},search:w,traceStart:ne},void 0,!1,void 0,this),ft.jsxDEV($A,{toolStats:i.summary.toolStats},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),ft.jsxDEV(KA,{span:M?k?.span??null:null,track:k?.track??null,onClose:()=>I(!1),onOpenChildTrack:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var kt=Q(de(),1);function tH({models:a}){let n=a.slice(0,3);return kt.jsxDEV("div",{style:{display:"flex",gap:4,flexWrap:"wrap"},children:[n.map((s)=>kt.jsxDEV("span",{className:"stats-text-muted truncate",style:{fontSize:10,border:"1px solid var(--border)",borderRadius:999,padding:"1px 6px",maxWidth:140},children:s},s,!1,void 0,this)),a.length>3&&kt.jsxDEV("span",{className:"stats-text-muted",style:{fontSize:10},children:["+",a.length-3]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function cR({active:a,session:n,onOpenSession:s,refreshTrigger:i}){let[l,u]=If.useState(""),{data:d,error:p,loading:h}=Vt(["sessions",i],(v)=>HI(200,void 0,v),{pollMs:30000,enabled:a&&n===null}),g=If.useMemo(()=>{if(!d)return[];let v=l.trim().toLowerCase();if(!v)return d;return d.filter((T)=>(T.title??"").toLowerCase().includes(v)||T.folder.toLowerCase().includes(v)||T.models.some((M)=>M.toLowerCase().includes(v)))},[d,l]),b=If.useMemo(()=>[{key:"title",header:"Title",render:(v)=>kt.jsxDEV("div",{className:"stats-font-medium stats-text-primary truncate",style:{maxWidth:280},children:v.title??v.file.split("/").pop()},void 0,!1,void 0,this)},{key:"folder",header:"Project",render:(v)=>kt.jsxDEV("span",{className:"stats-text-muted truncate",style:{maxWidth:160,display:"inline-block"},children:v.folder.split("/").slice(-2).join("/")},void 0,!1,void 0,this)},{key:"started",header:"Started",render:(v)=>za(v.startedAt)},{key:"duration",header:"Duration",numeric:!0,render:(v)=>rt(v.endedAt-v.startedAt)},{key:"requests",header:"Requests",numeric:!0,render:(v)=>v.requests},{key:"toolCalls",header:"Tools",numeric:!0,render:(v)=>v.toolCalls},{key:"subagents",header:"Agents",numeric:!0,render:(v)=>v.subagents},{key:"tokens",header:"Tokens",numeric:!0,render:(v)=>lt(v.totalTokens)},{key:"cost",header:"Cost",numeric:!0,render:(v)=>us(v.costTotal)},{key:"models",header:"Models",render:(v)=>kt.jsxDEV(tH,{models:v.models},void 0,!1,void 0,this)}],[]),y=(v,T)=>kt.jsxDEV("div",{className:"stats-mobile-card",onClick:T,children:[kt.jsxDEV("div",{className:"stats-mobile-card-header",children:kt.jsxDEV("div",{className:"stats-font-semibold stats-text-primary truncate",children:v.title??v.file.split("/").pop()},void 0,!1,void 0,this)},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-grid",children:[kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Started"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:za(v.startedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Duration"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:rt(v.endedAt-v.startedAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Requests"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:v.requests},void 0,!1,void 0,this)]},void 0,!0,void 0,this),kt.jsxDEV("div",{children:[kt.jsxDEV("div",{className:"stats-mobile-card-label",children:"Cost"},void 0,!1,void 0,this),kt.jsxDEV("div",{className:"stats-mobile-card-value",children:us(v.costTotal)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(n!==null)return kt.jsxDEV(uR,{file:n,active:a,onBack:()=>s(null)},void 0,!1,void 0,this);return kt.jsxDEV("div",{className:"stats-route-container",children:kt.jsxDEV(ut,{title:"Sessions",subtitle:"Recent sessions with subagent activity folded in — click one to open its trace",actions:kt.jsxDEV("input",{type:"search",value:l,onChange:(v)=>u(v.target.value),placeholder:"Filter by title, project, model…","aria-label":"Filter sessions",spellCheck:!1,className:"stats-trace-input",style:{width:220}},void 0,!1,void 0,this),children:kt.jsxDEV(Rt,{loading:h,error:p,data:d,children:kt.jsxDEV(Ma,{columns:b,data:g,keyExtractor:(v)=>v.file,onRowClick:(v)=>s(v.file),renderMobileCard:y,emptyText:"No sessions found — run a Sync to index recent activity"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}var Ra=Q(de(),1);function u0(){let{section:a,setSection:n,range:s,setRange:i,session:l,setSession:u}=eA(),[d,p]=er.useState(0),[h,g]=er.useState(null),[b,y]=er.useState(()=>Date.now()),v=er.useCallback((A)=>{if(A.success)p((B)=>B+1),y(Date.now())},[]),T=er.useCallback(()=>g(null),[]),M=a,I=er.useRef(new Set);I.current.add(M);let w=(A)=>{let B=A===M;switch(A){case"overview":return Ra.jsxDEV(qA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"requests":return Ra.jsxDEV(XA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"traces":return Ra.jsxDEV(cR,{active:B,session:l,onOpenSession:u,refreshTrigger:d},void 0,!1,void 0,this);case"errors":return Ra.jsxDEV(BA,{active:B,range:s,refreshTrigger:d,onRequestClick:g},void 0,!1,void 0,this);case"models":return Ra.jsxDEV(HA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"providers":return Ra.jsxDEV(jA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"tools":return Ra.jsxDEV(YA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"costs":return Ra.jsxDEV(OA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"behavior":return Ra.jsxDEV(EA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"projects":return Ra.jsxDEV(VA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this);case"gain":return Ra.jsxDEV(NA,{active:B,range:s,refreshTrigger:d},void 0,!1,void 0,this)}};return Ra.jsxDEV(Ra.Fragment,{children:[Ra.jsxDEV(KI,{activeSection:M,onSectionChange:n,range:s,onRangeChange:i,updatedAt:b,onSyncComplete:v,children:[...I.current].map((A)=>Ra.jsxDEV("div",{hidden:A!==M,children:w(A)},A,!1,void 0,this))},void 0,!1,void 0,this),Ra.jsxDEV(MA,{id:h,onClose:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var fR=Q(de(),1),aH=dR.createRoot(document.getElementById("root"));aH.render(fR.jsxDEV(u0,{},void 0,!1,void 0,this));