var Ht=Object.defineProperty;var Bt=(t,s,n)=>s in t?Ht(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var we=(t,s,n)=>Bt(t,typeof s!="symbol"?s+"":s,n);import{e as Oe,r as l,j as e,L as Ve,c as mt,P as _t,cI as Tt,cJ as qe,y as Ie,cK as $t,$ as Pe,cL as zt,cq as Te,cM as Wt,cN as Ut,z as Gt,cj as Vt,cO as qt,cP as Kt,cQ as Xt,cR as Yt,cS as Zt,cd as Qt,cT as Ke,cg as Jt,cU as es,cV as ts,f as Ee,cW as ss,bY as dt,c4 as ns,ah as Rt,ai as as,cX as is,bI as rs,aa as ls,ae as os,ad as cs,W as ms,aN as ds,aO as us,af as hs,ax as xs,cY as Xe,al as ps,cZ as ut,au as fs,R as gs,c_ as ys}from"./index-C4inJ1rU.js";import{L as De}from"./layers-B_54Ow0Q.js";import{u as lt,h as bs,r as ot}from"./consumer-registry-BEMotsU4.js";import{e as js}from"./easing-C4vSIYXU.js";import{C as Ye}from"./compass-BqGOlCkL.js";import{T as vs}from"./TimeRangeStepper-DNUdgVzA.js";import{C as be,P as Ns,a as ws,B as ks}from"./PageLayout-CdGXajgM.js";import{A as Ze,D as ze}from"./DataValue-BEBX-lAu.js";import{C as Ss}from"./CollisionExplorerModal-D4h1t6K4.js";import{H as ht}from"./hash-v3bMIFKt.js";import{L as We}from"./LightSparkline-CReUcxTn.js";import{A as Ms}from"./activity-Q-NGsRUt.js";import{c as Cs,a as As,A as _s}from"./AnalyzerFilterPanel-Boxqs6Ze.js";import{useResolveSource as Ts}from"./usePipelineStore-BdsvnjJV.js";import{M as Rs}from"./MqttModeBadge-BTwynmjt.js";import{R as Ae,C as Le}from"./Grid-rJkrpDAP.js";import{S as Es}from"./settings-2-BHdXfxPS.js";import{N as Is}from"./network-DX08B81j.js";import"./chevron-right-CU8UihKL.js";import"./floating-4TW7J4UF.js";import"./index-BXWmGYBj.js";import"./index-CLVX1WuQ.js";import"./maplibre-gl-ClZLWYTA.js";import"./layer-D6BnwDKL.js";import"./BasemapLayer-zAPrA2Lm.js";import"./map-pin-DlTTkXK_.js";import"./share-2-CGZnW2u_.js";import"./node-types-chTBCezS.js";import"./funnel-MRZBOee_.js";import"./search-qUivGgU1.js";/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ds=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],Et=Oe("chart-line",Ds);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ls=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],xt=Oe("circle-check-big",Ls);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ps=[["path",{d:"M6 18.5a3.5 3.5 0 1 0 7 0c0-1.57.92-2.52 2.04-3.46",key:"1qngmn"}],["path",{d:"M6 8.5c0-.75.13-1.47.36-2.14",key:"b06bma"}],["path",{d:"M8.8 3.15A6.5 6.5 0 0 1 19 8.5c0 1.63-.44 2.81-1.09 3.76",key:"g10hsz"}],["path",{d:"M12.5 6A2.5 2.5 0 0 1 15 8.5M10 13a2 2 0 0 0 1.82-1.18",key:"ygzou7"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]],Os=Oe("ear-off",Ps);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Fs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Hs=Oe("grid-3x3",Fs);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Bs=[["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"19",cy:"5",r:"1",key:"w8mnmm"}],["circle",{cx:"5",cy:"5",r:"1",key:"lttvr7"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}],["circle",{cx:"19",cy:"19",r:"1",key:"shf9b7"}],["circle",{cx:"5",cy:"19",r:"1",key:"bfqh0e"}]],$s=Oe("grip",Bs),It={useAbsoluteThresholds:!0,baselinePercentile:6,spikePercentile:50,baselineDbm:-107,spikeDbm:-100,mergeGapSeconds:45,minSequenceLength:16,similarityToleranceDbm:5};function Re(t,s){if(t.length===0)return 0;const n=s/100*(t.length-1),a=Math.floor(n),r=Math.ceil(n);return a===r?t[a]:t[a]+(t[r]-t[a])*(n-a)}function pt(t){if(t.length===0)return{median:0,p90:0,p95:0,p99:0,max:0,min:0};const s=[...t].sort((n,a)=>n-a);return{median:Re(s,50),p90:Re(s,90),p95:Re(s,95),p99:Re(s,99),max:s[s.length-1],min:s[0]}}function zs(t,s={}){const n={...It,...s};if(t.length<10)return{anomalies:[],thresholds:pt([]),totalSamples:t.length,anomalySamples:0};const a=t.map(b=>b.noise_floor_dbm),r=pt(a),i=[...a].sort((b,k)=>b-k);let o,m;n.useAbsoluteThresholds?(o=n.baselineDbm,m=n.spikeDbm):(o=Re(i,n.baselinePercentile),m=Re(i,n.spikePercentile));const x=[...t].sort((b,k)=>b.timestamp-k.timestamp),h=[];let d=null,p=0;for(const b of x)if(b.noise_floor_dbm>o&&b.noise_floor_dbm<m)if(p++,!d)d={startTs:b.timestamp,endTs:b.timestamp,values:[b.noise_floor_dbm],timestamps:[b.timestamp],rollingAvg:b.noise_floor_dbm};else{const j=Math.abs(b.noise_floor_dbm-d.rollingAvg)<=n.similarityToleranceDbm,M=b.timestamp-d.endTs<=n.mergeGapSeconds;j&&M?(d.endTs=b.timestamp,d.values.push(b.noise_floor_dbm),d.timestamps.push(b.timestamp),d.rollingAvg=d.values.reduce((_,T)=>_+T,0)/d.values.length):(d.values.length>=n.minSequenceLength&&h.push(d),d={startTs:b.timestamp,endTs:b.timestamp,values:[b.noise_floor_dbm],timestamps:[b.timestamp],rollingAvg:b.noise_floor_dbm})}else d&&d.values.length>=n.minSequenceLength&&h.push(d),d=null;return d&&d.values.length>=n.minSequenceLength&&h.push(d),h.length===0?{anomalies:[],thresholds:r,totalSamples:t.length,anomalySamples:p,debug:{baselineCutoff:o,spikeCutoff:m,midBandSamples:p}}:{anomalies:h.map(b=>{const k=Math.max(...b.values),f=b.values.reduce((j,M)=>j+M,0)/b.values.length;return{startTs:b.startTs,endTs:b.endTs,peakValue:k,avgValue:f,severity:Ws(f,o,m),sampleCount:b.values.length}}),thresholds:r,totalSamples:t.length,anomalySamples:p,debug:{baselineCutoff:o,spikeCutoff:m,midBandSamples:p}}}function Ws(t,s,n){const a=n-s;if(a===0)return"moderate";const r=(t-s)/a;return r>.66?"critical":r>.33?"severe":"moderate"}const Us=Object.entries(_t).map(([t,s])=>{const n=parseInt(t,10);return{typeNum:n,key:`TYPE_${n}`,label:s}});function ct({sortedTypes:t,highlightedType:s,onTypeHover:n,aggregateShares:a,hoverData:r,overlayLines:i}){const o=l.useMemo(()=>{if(!r)return null;const h=new Map;for(const d of r.items)h.set(d.key,d.value);return h},[r]),m=o!==null,x=l.useMemo(()=>{const h=new Set(t.map(w=>w.key)),d=t.map(w=>({typeNum:w.typeNum,key:w.key,label:w.label})),p=Us.filter(w=>!h.has(w.key));return[...d,...p]},[t]);return e.jsxs("div",{className:"flex-shrink-0 pt-2 sm:pt-3 mt-1 sm:mt-2 px-0 sm:pr-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mx-0 sm:ml-9 sm:mr-0 mb-1 sm:mb-1.5 type-data-xs",children:[e.jsx("span",{className:"text-fg-muted",children:"Packet Types"}),m&&(r==null?void 0:r.timeLabel)&&e.jsx("span",{className:"text-sys-indigo tabular-nums",children:r.timeLabel})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 sm:gap-x-4 gap-y-1 type-data-xs mx-0 sm:ml-9 sm:mr-0",onMouseLeave:()=>n(null),children:[x.map(h=>{const d=Ve(h.typeNum),p=(o==null?void 0:o.get(h.key))??0,w=a.get(h.key)??0,b=m?p:w,k=b>1e-4,f=a.has(h.key),j=s===h.key,M=s&&!j||m&&p<=1e-4||!m&&!s&&!f;return e.jsxs("div",{className:mt("flex items-center gap-1.5 transition-opacity cursor-pointer hover:opacity-80",M&&"opacity-30"),onMouseEnter:()=>n(h.key),children:[e.jsx("div",{className:"shrink-0 w-3 h-3 rounded-xs",style:{backgroundColor:d}}),e.jsx("span",{className:"text-fg-secondary whitespace-nowrap",children:h.label}),k&&e.jsxs("span",{className:mt("tabular-nums",m?"text-fg-primary":"text-fg-muted"),children:[(b*100).toFixed(1),"%"]})]},h.key)}),i&&i.map(h=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"shrink-0 w-3 h-0.5 rounded-full",style:{backgroundColor:h.color,opacity:h.opacity??1}}),e.jsx("span",{className:"text-fg-secondary whitespace-nowrap",children:h.label})]},h.label))]})]})}const ft='ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',Gs=2,Vs=3,qs=32,Ks=20,Xs=80;function gt(t,s,n,a,r){const i=t.reduce((h,d)=>h+d,0);if(i<=0||t.length===0)return[];const o=t.map((h,d)=>d).sort((h,d)=>t[d]-t[h]),m=o.map(h=>t[h]),x=new Array(t.length);return rt(m,o,i,s,n,a,r,x),x}function rt(t,s,n,a,r,i,o,m){if(t.length===0)return;if(t.length===1){m[s[0]]={x:a,y:r,w:i,h:o,index:s[0]};return}const x=i*o/n,h=i>=o,d=h?o:i;let p=0,w=1/0,b=0;for(let T=0;T<t.length;T++){const X=p+t[T],Y=X*x/d;if(Y<=0){b=T+1,p=X;continue}const H=t[0]*x/Y,N=t[T]*x/Y,v=Math.max(H>Y?H/Y:Y/H,N>Y?N/Y:Y/N);if(v<=w)w=v,b=T+1,p=X;else break}const k=d>0?p*x/d:0;let f=0;for(let T=0;T<b;T++){const Y=(p>0?t[T]/p:0)*d;h?m[s[T]]={x:a,y:r+f,w:k,h:Y,index:s[T]}:m[s[T]]={x:a+f,y:r,w:Y,h:k,index:s[T]},f+=Y}const j=t.slice(b),M=s.slice(b),_=n-p;h?rt(j,M,_,a+k,r,i-k,o,m):rt(j,M,_,a,r+k,i,o-k,m)}function yt(t,s,n,a,r,i){for(const o of s){const m=n[o.index];if(!m)continue;const x=Gs*i,h=o.x*i+x/2,d=o.y*i+x/2,p=o.w*i-x,w=o.h*i-x;if(p<=0||w<=0)continue;const b=Ve(m.typeNum),k=r!==null&&r!==o.index;t.save(),t.globalAlpha=k?.4:1;const f=Vs*i;t.beginPath(),t.moveTo(h+f,d),t.lineTo(h+p-f,d),t.quadraticCurveTo(h+p,d,h+p,d+f),t.lineTo(h+p,d+w-f),t.quadraticCurveTo(h+p,d+w,h+p-f,d+w),t.lineTo(h+f,d+w),t.quadraticCurveTo(h,d+w,h,d+w-f),t.lineTo(h,d+f),t.quadraticCurveTo(h,d,h+f,d),t.closePath(),t.fillStyle=b,t.fill(),t.strokeStyle="rgba(0,0,0,0.2)",t.lineWidth=1*i,t.stroke();const j=4*i,M=o.w>36&&o.h>20,_=o.w>36&&o.h>32;if(M){const T=11*i;if(_){const X=a>0?m.size/a*100:0;t.font=`500 ${8*i}px ${ft}`,t.fillStyle="rgba(0,0,0,0.6)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(`${X.toFixed(1)}%`,h+j,d+w-j-T)}t.font=`600 ${9*i}px ${ft}`,t.fillStyle="rgba(0,0,0,0.85)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(m.name,h+j,d+w-j)}t.restore()}}function Ys(t,s,n){for(const a of t)if(s>=a.x&&s<=a.x+a.w&&n>=a.y&&n<=a.y+a.h)return a.index;return null}function Zs({data:t,total:s,color:n,position:a,containerWidth:r,isAirtime:i}){if(!t||!a)return null;const o=(t.value/s*100).toFixed(1),m=160,d=r-a.x<m+24?Math.max(8,a.x-m-8):a.x+16;return e.jsx("div",{className:"absolute z-50 pointer-events-none",style:{left:d,top:Math.max(8,a.y-60)},children:e.jsxs("div",{className:"bg-tooltip-bg border border-edge-subtle rounded-lg px-3 py-2 shadow-xl min-w-[140px]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:n}}),e.jsx("span",{className:"type-data-sm font-semibold text-fg-primary",children:t.name})]}),e.jsxs("div",{className:"space-y-0.5 type-data-xs text-fg-muted",children:[e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{children:i?"Airtime":"Count"}),e.jsx("span",{className:"text-fg-primary tabular-nums font-medium",children:i?bt(t.value):t.value.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{children:"Share"}),e.jsxs("span",{className:"text-fg-primary tabular-nums font-medium",children:[o,"%"]})]}),e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{className:"text-fg-primary tabular-nums font-medium",children:i?bt(s):s.toLocaleString()})]})]})]})})}function bt(t){return t>=6e4?`${(t/6e4).toFixed(1)}m`:t>=1e3?`${(t/1e3).toFixed(1)}s`:`${Math.round(t)}ms`}function Qs({sortedTypes:t,aggregateShares:s,mode:n="share"}){var H,N,v;const[a,r]=l.useState(null),[i,o]=l.useState(null),[m,x]=l.useState(0),[h,d]=l.useState(null),p=l.useRef(null),w=l.useRef(null),b=l.useRef([]),k=n==="airtime",f=l.useMemo(()=>t.reduce((c,g)=>c+(k?g.totalAirtime:g.totalCount),0),[t,k]),j=l.useMemo(()=>t.map((c,g)=>({name:c.label,size:k?c.totalAirtime:c.totalCount,index:g,typeNum:c.typeNum,key:c.key})),[t,k]);l.useEffect(()=>{const c=w.current;if(!c)return;const g=c.parentElement;if(!g)return;const I=g.getBoundingClientRect(),U=I.width,y=I.height;if(U<=0||y<=0)return;const E=window.devicePixelRatio||1;c.width=Math.floor(U*E),c.height=Math.floor(y*E),c.style.width=`${U}px`,c.style.height=`${y}px`;const q=j.map(G=>G.size),ie=gt(q,0,0,U,y);b.current=ie;const se=c.getContext("2d");se&&(se.clearRect(0,0,c.width,c.height),yt(se,ie,j,f,a,E))},[j,f,a]),l.useEffect(()=>{const c=p.current;if(!c)return;const g=new ResizeObserver(()=>{const I=w.current;if(!I)return;const U=c.getBoundingClientRect(),y=U.width,E=U.height;if(y<=0||E<=0)return;const q=window.devicePixelRatio||1;I.width=Math.floor(y*q),I.height=Math.floor(E*q),I.style.width=`${y}px`,I.style.height=`${E}px`;const ie=j.map(Z=>Z.size),se=gt(ie,0,0,y,E);b.current=se;const G=I.getContext("2d");G&&(G.clearRect(0,0,I.width,I.height),yt(G,se,j,f,a,q))});return g.observe(c),()=>g.disconnect()},[j,f]);const M=l.useCallback(c=>{const g=p.current;if(!g)return;const I=g.getBoundingClientRect(),U=c.clientX-I.left,y=c.clientY-I.top,E=Ys(b.current,U,y);r(E),E!==null?(x(I.width),o({x:U,y})):o(null)},[]),_=l.useCallback(()=>{r(null),o(null)},[]),T=l.useCallback(c=>{if(d(c),c){const g=j.findIndex(I=>I.key===c);r(g>=0?g:null)}else r(null)},[j]),X=a!==null?{name:((H=j[a])==null?void 0:H.name)??"",value:((N=j[a])==null?void 0:N.size)??0}:null,Y=a!==null?Ve((v=j[a])==null?void 0:v.typeNum):"";return t.length===0||f===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(De,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet type data available"})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 min-h-0 relative",children:e.jsxs("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:qs,right:0,top:0,bottom:Ks},ref:p,onMouseMove:M,onMouseLeave:_,children:[e.jsx("canvas",{ref:w,className:"absolute inset-0",style:{cursor:"default"}}),e.jsx(Zs,{data:X,total:f,color:Y,position:i,containerWidth:m,isAirtime:k})]})}),e.jsx("div",{style:{minHeight:Xs},children:e.jsx(ct,{sortedTypes:t,highlightedType:h,onTypeHover:T,aggregateShares:s})})]})}const Qe=32,Je=20,Js=300;function _e(t){return t>=1e9?`${(t/1e9).toFixed(1)} Gb`:t>=1e6?`${(t/1e6).toFixed(1)} Mb`:t>=1e3?`${(t/1e3).toFixed(1)} Kb`:`${t.toFixed(0)} B`}function en({packets:t,mode:s,startTs:n,endTs:a,radioConfig:r,bucketCount:i,lockedYMax:o,legendMinH:m}){const x=l.useMemo(()=>Tt(),[]),h=x.blue,d=x.red,p=x.yellow,[w,b]=l.useState(null),{trendData:k,totals:f}=l.useMemo(()=>{if(t.length===0)return{trendData:[],totals:{rxBytes:0,txBytes:0,rxAirtime:0,txAirtime:0}};const N=a-n,v=Math.min(Math.ceil(N/Js),i),c=N/v,g=[];let I=0,U=0,y=0,E=0;for(const C of t){const z=C.timestamp;if(z<n||z>=a)continue;const B=qe(C),L=Ie(C,{spreadingFactor:r.sf,bandwidthHz:r.bw,codingRate:r.cr,preambleLength:r.preamble}),$={timestamp:z,rxAirtime:0,txAirtime:0,rxBytes:0,txBytes:0};C.transmitted?($.txAirtime=L,$.txBytes=B,U+=B,E+=L):($.rxAirtime=L,$.rxBytes=B,I+=B,y+=L),g.push($)}g.sort((C,z)=>C.timestamp-z.timestamp);const q=new Float64Array(g.length+1),ie=new Float64Array(g.length+1),se=new Float64Array(g.length+1),G=new Float64Array(g.length+1),Z=new Float64Array(g.length);for(let C=0;C<g.length;C++)q[C+1]=q[C]+g[C].rxAirtime,ie[C+1]=ie[C]+g[C].txAirtime,se[C+1]=se[C]+g[C].rxBytes,G[C+1]=G[C]+g[C].txBytes,Z[C]=g[C].timestamp;const oe=C=>{let z=0,B=Z.length;for(;z<B;){const L=z+B>>>1;Z[L]<C?z=L+1:B=L}return z},pe=[],J=c*1e3;for(let C=0;C<v;C++){const z=n+C*c,B=z+c,L=oe(z),$=oe(B);if(s==="share"){const V=se[$]-se[L],S=G[$]-G[L];pe.push({timestamp:z,rx:V>0?V:null,tx:S>0?S:null})}else{const V=q[$]-q[L],S=ie[$]-ie[L],F=V/J*100,W=S/J*100;pe.push({timestamp:z,rx:F>0?F:null,tx:W>0?W:null})}}const O=2/31;let Q=null;return{trendData:pe.map(C=>{const z=C.rx;return z!==null&&z>0&&(Q===null?Q=z:Q=O*z+(1-O)*Q),{...C,rxSmooth:Q!==null&&Q>0?Q:null}}),totals:{rxBytes:I,txBytes:U,rxAirtime:y,txAirtime:E}}},[t,n,a,i,s,r]),j=l.useMemo(()=>{if(k.length===0)return s==="share"?100:10;let N=0;for(const c of k){const g=c.rx??0,I=c.tx??0;g>N&&(N=g),I>N&&(N=I)}const v=N*1.1;return s==="share"?v<=100?100:v<=500?Math.ceil(v/100)*100:v<=1e3?Math.ceil(v/200)*200:v<=5e3?Math.ceil(v/500)*500:v<=1e4?Math.ceil(v/1e3)*1e3:Math.ceil(v/5e3)*5e3:Math.max(1,Math.ceil(v))},[k,s]),M=o??j,_=l.useMemo(()=>{if(w!==null&&k[w]){const N=k[w],v=N.rx??0,c=N.tx??0;return s==="share"?{rx:_e(v),tx:_e(c),total:_e(v+c),isHovered:!0}:{rx:`${v.toFixed(2)}%`,tx:`${c.toFixed(2)}%`,total:`${(v+c).toFixed(2)}%`,isHovered:!0}}if(s==="share")return{rx:_e(f.rxBytes),tx:_e(f.txBytes),total:_e(f.rxBytes+f.txBytes),isHovered:!1};{let N=0,v=0,c=0;for(const U of k)(U.rx!==null||U.tx!==null)&&(N+=U.rx??0,v+=U.tx??0,c++);const g=c>0?N/c:0,I=c>0?v/c:0;return{rx:`${g.toFixed(2)}%`,tx:`${I.toFixed(2)}%`,total:`${(g+I).toFixed(2)}%`,isHovered:!1}}},[w,k,f,s]),T=l.useMemo(()=>{const N=a-n,v=N/3600;return[0,.25,.5,.75,1].map(g=>{const I=n+N*g,U=new Date(I*1e3),y=U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),E=U.toLocaleDateString([],{weekday:"short"}),q=g===.25||g===.75;return{pct:g,label:v>=24?`${E} ${y}`:y,mobileHidden:q}})},[n,a]),X=l.useCallback(N=>{b(N)},[]);if(k.length===0)return e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(De,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet data available"})]});const Y=l.useMemo(()=>s==="airtime"?M<=5?1:M<=10?2:M<=20?5:Math.ceil(M/5):M<=100?25:M<=500?100:M<=1e3?200:M<=5e3?1e3:M<=1e4?2e3:Math.ceil(M/5e3)*1e3,[M,s]),H=l.useMemo(()=>{const N=[];for(let v=0;v<=M;v+=Y){const c=(1-v/M)*100;let g;s==="airtime"?g=`${v}%`:v>=1e6?g=`${(v/1e6).toFixed(1)}M`:v>=1e3?g=`${(v/1e3).toFixed(0)}K`:g=`${v}`,N.push({pos:c,label:g})}return N},[M,Y,s]);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-1 min-h-0 relative",children:[e.jsx("div",{className:"absolute top-0 left-0 flex flex-col justify-between",style:{width:Qe,bottom:Je},children:H.map((N,v)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${N.pos}%`,transform:v===0?"translateY(-100%)":v===H.length-1?"none":"translateY(-50%)",right:0},children:N.label},v))}),e.jsx("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:Qe,right:0,top:0,bottom:Je},children:e.jsx($t,{data:k,yAxisMode:s==="share"?"share":"airtime",yMax:M,onHover:X,startTs:n,endTs:a,externalAxes:!0})}),e.jsx("div",{className:"absolute left-0 right-0 bottom-0 flex items-center pointer-events-none",style:{left:Qe,height:Je,paddingTop:4},children:T.map((N,v)=>e.jsx("span",{className:`absolute type-data-xs text-fg-muted/60 tabular-nums ${N.mobileHidden?"hidden sm:inline":""}`,style:{left:`${N.pct*100}%`,transform:N.pct===0?"translateX(0)":N.pct===1?"translateX(-100%)":"translateX(-50%)"},children:N.label},v))})]}),e.jsxs("div",{className:"flex items-end justify-between pb-1",style:{minHeight:m},children:[e.jsxs("div",{className:"flex items-center gap-3 sm:gap-5 type-data-sm pl-2 sm:pl-11",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-4 sm:w-5 h-[2px] rounded-full",style:{backgroundColor:h}}),e.jsx("span",{className:"text-fg-secondary",children:"RX"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-4 sm:w-5 h-[2px] rounded-full",style:{backgroundColor:d}}),e.jsx("span",{className:"text-fg-secondary",children:"TX"})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5",children:[e.jsx("div",{className:"w-5 h-[2px] rounded-full",style:{backgroundColor:p}}),e.jsx("span",{className:"text-fg-secondary",children:"Avg"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 sm:gap-8",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"type-data-xl text-fg-primary",children:_.rx}),e.jsx(Pe,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"RX"})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"type-data-xl text-fg-primary",children:_.tx}),e.jsx(Pe,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"TX"})]})]})]})]})}const jt=zt;class tn{constructor(){we(this,"worker",null);we(this,"listeners",new Set);we(this,"currentResult",null);we(this,"isComputing",!1);we(this,"debounceTimer",null);we(this,"debounceMs",250);we(this,"lastCacheKey",null)}ensureWorker(){if(this.worker)return this.worker;if(typeof window>"u")return null;try{this.worker=new Worker(new URL("/assets/bucketing.worker-D0TT0k8y.js",import.meta.url),{type:"module"}),this.worker.onmessage=s=>{this.handleWorkerMessage(s.data)},this.worker.onerror=s=>{console.error("[BucketingService] Worker error:",s),this.isComputing=!1,this.notifyListeners()}}catch(s){console.error("[BucketingService] Failed to initialize worker:",s)}return this.worker}handleWorkerMessage(s){if(this.isComputing=!1,s.type==="error"){this.currentResult=null,this.notifyListeners();return}const n=s.payload;this.currentResult={points:n.points,rawValues:n.rawValues,packetTypes:n.packetTypes,timestamps:n.timestamps,count:n.count,minTime:n.minTime,maxTime:n.maxTime,minValue:n.minValue,maxValue:n.maxValue,rawMinValue:n.rawMinValue,rawMaxValue:n.rawMaxValue,unit:"%",stats:{p5:n.p5,p50:n.p50,p95:n.p95,uniqueValues:n.uniqueValues,topValues:n.topValues}},this.notifyListeners()}notifyListeners(){for(const s of this.listeners)try{s(this.currentResult,this.isComputing)}catch(n){console.error("[BucketingService] Listener error:",n)}}isCacheHit(s){return!this.lastCacheKey||!this.currentResult?!1:this.lastCacheKey.startTs===s.startTs&&this.lastCacheKey.endTs===s.endTs&&this.lastCacheKey.mode===s.mode&&this.lastCacheKey.packetCount===s.packetCount}compute(s,n,a,r,i){if(s.length===0||!i){this.currentResult=null,this.notifyListeners();return}const o={startTs:n,endTs:a,mode:r,packetCount:s.length};this.isCacheHit(o)||(this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.computeInternal(s,n,a,r,i,o)},this.debounceMs))}computeInternal(s,n,a,r,i,o){const m=this.ensureWorker();if(!m)return;const x=s.length,h=new Float64Array(x),d=new Float64Array(x),p=new Uint16Array(x),w=new Uint8Array(x),b={spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble};for(let f=0;f<x;f++){const j=s[f];h[f]=j.timestamp??0,w[f]=(j.type??j.payload_type??255)&255,p[f]=Math.min(qe(j),65535),r==="airtime"?d[f]=Ie(j,b):d[f]=1}this.isComputing=!0,this.lastCacheKey=o,this.notifyListeners();const k={type:"compute",payload:{timestamps:h,airtimeMs:d,byteSizes:p,packetTypes:w,startTs:n,endTs:a,mode:r}};m.postMessage(k,[h.buffer,d.buffer,p.buffer,w.buffer])}getResult(){return this.currentResult}isWorking(){return this.isComputing}subscribe(s){return this.listeners.add(s),s(this.currentResult,this.isComputing),()=>{this.listeners.delete(s)}}clear(){this.currentResult=null,this.lastCacheKey=null,this.notifyListeners()}terminate(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.worker&&(this.worker.terminate(),this.worker=null),this.listeners.clear()}}const et=new tn;function sn(t,s,n,a,r){const[i,o]=l.useState(()=>et.getResult());return l.useEffect(()=>et.subscribe(m=>{o(m)}),[]),l.useEffect(()=>{et.compute(t,s,n,a,r)},[t,s,n,a,r]),i}function nn({mode:t,packets:s,startTs:n,endTs:a,radioConfig:r,sortedTypes:i,aggregateShares:o,noiseFloorAnomalies:m,showNoiseFloorOverlay:x,overlayOpacity:h=.5,startLabel:d,endLabel:p,lockedYMax:w,legendMinH:b,dotSize:k,dotOpacity:f,channelGroups:j,channelToGroup:M,decodedMessages:_}){const[T,X]=l.useState(null),[Y,H]=l.useState(null),N=l.useMemo(()=>(a-n)/3600,[n,a]),v=l.useCallback(J=>{H(J)},[]),g=sn(s,n,a,t==="share"?"share":"airtime",r),[I,U]=l.useState(null),y=l.useCallback((J,O)=>{X(J),U(O??null)},[]),E=l.useMemo(()=>{if(I===null||!g||g.count===0)return null;const J=n+I*(a-n);let O;N>=168?O=75:N>=72?O=35:N>=24?O=15:N>=3?O=10:O=5;const Q=O*60/2;return{start:J-Q,end:J+Q}},[I,g,n,a,N]),q=l.useMemo(()=>E?new Date((E.start+E.end)/2*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}):null,[E]),ie=l.useMemo(()=>{if(T===null||!E)return null;const J=q??"",{start:O,end:Q}=E,de=s.filter(V=>V.timestamp>=O&&V.timestamp<Q);if(de.length===0)return{timestamp:(O+Q)/2,timeLabel:J,items:i.map(V=>({key:V.key,label:V.label,value:0,color:jt(V.typeNum)}))};const C=new Map,z=new Map;let B=0,L=0;for(const V of de){const F=`TYPE_${V.type??V.payload_type??-1}`;if(C.set(F,(C.get(F)??0)+1),B++,r){const W=Ie(V,{spreadingFactor:r.sf,bandwidthHz:r.bw,codingRate:r.cr,preambleLength:r.preamble});z.set(F,(z.get(F)??0)+W),L+=W}}const $=i.map(V=>{let S;return t==="airtime"?S=L>0?(z.get(V.key)??0)/L:0:S=B>0?(C.get(V.key)??0)/B:0,{key:V.key,label:V.label,value:S,color:jt(V.typeNum)}});return{timestamp:(O+Q)/2,timeLabel:J,items:$}},[T,E,q,s,i,t,r]),se=t==="share",G=w??(g==null?void 0:g.maxValue)??(se?240:10),Z=l.useMemo(()=>{if(!se)return 5;const J=[10,20,25,50,100,200,250,500,1e3],O=G/4.5;for(const Q of J)if(Q>=O)return Q;return G>5e3?Math.ceil(O/1e3)*1e3:Math.ceil(O/100)*100},[G,se]),oe=l.useMemo(()=>{const J=[];for(let O=0;O<=G;O+=Z){const Q=(1-O/G)*100;J.push({pos:Q,label:se?`${O}B`:`${O}%`})}return J},[G,Z,se]),pe=l.useMemo(()=>{var Q,de;if(!j||j.length===0||!M||!_)return null;const J=a-n||1,O=j.map(C=>({xs:[],ys:[]}));for(const C of s){const z=C.timestamp;if(z<n||z>=a||(C.type??C.payload_type)!==Te.GRP_TXT||!C.packet_hash)continue;const L=_.get(C.packet_hash),$=(de=(Q=L==null?void 0:L.decoded)==null?void 0:Q.channelName)==null?void 0:de.toLowerCase();if(!$)continue;const V=M.get($);if(V===void 0)continue;const S=(z-n)/J,F=se?qe(C):.3;O[V].xs.push(S),O[V].ys.push(F)}return j.map((C,z)=>({label:C.label,color:C.color,xs:new Float32Array(O[z].xs),ys:new Float32Array(O[z].ys),count:O[z].xs.length})).filter(C=>C.count>0)},[s,j,M,_,n,a,se]);return!g||g.count===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(De,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet data available"})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-1 min-h-0 relative",children:[e.jsx("div",{className:"absolute top-0 left-0 flex flex-col justify-between",style:{width:32,bottom:20},children:oe.map((J,O)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${J.pos}%`,transform:O===0?"translateY(-100%)":O===oe.length-1?"none":"translateY(-50%)",right:0},children:J.label},O))}),e.jsxs("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:32,right:0,top:0,bottom:20},children:[e.jsx(Wt,{scatterData:g,yAxisMode:t==="share"?"share":"airtime",onHover:y,noiseFloorAnomalies:m,showNoiseFloorOverlay:x,overlayOpacity:h,highlightedType:Y,timeRangeHours:N,yAxisMaxOverride:w,dotSize:k,dotOpacity:f,startTs:n,endTs:a,externalAxes:!0,channelGroupOverlays:pe}),q&&e.jsx("div",{className:"absolute top-1 right-1 px-2 py-0.5 bg-elevated/90 rounded type-data-xs text-sys-indigo pointer-events-none z-10",children:q})]}),d&&p&&e.jsxs("div",{className:"absolute left-0 right-0 bottom-0 flex justify-between pointer-events-none type-data-xs text-fg-muted/60",style:{left:32,height:20,paddingTop:4},children:[e.jsx("span",{children:d}),e.jsx("span",{children:p})]})]}),e.jsx("div",{style:{minHeight:b},children:e.jsx(ct,{sortedTypes:i,highlightedType:Y,onTypeHover:v,aggregateShares:o,hoverData:ie})})]})}function an({mode:t,onChange:s}){return e.jsxs("div",{className:"toggle-group toggle-group-sm",children:[e.jsx("button",{onClick:()=>s("share"),className:`toggle-group-item ${t==="share"?"active":""}`,children:"Total"}),e.jsx("button",{onClick:()=>s("airtime"),className:`toggle-group-item ${t==="airtime"?"active":""}`,children:"Airtime"})]})}function rn({smoothing:t,onChange:s}){return e.jsxs("div",{className:"toggle-group toggle-group-sm",children:[e.jsx("button",{onClick:()=>s("stats"),className:`toggle-group-item ${t==="stats"?"active":""}`,title:"Statistics view (scatter plot)",children:e.jsx($s,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>s("trend"),className:`toggle-group-item ${t==="trend"?"active":""}`,title:"Trend line chart",children:e.jsx(Et,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>s("ema"),className:`toggle-group-item ${t==="ema"?"active":""}`,title:"Stacked area (moderate smoothing)",children:e.jsx(De,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>s("ultra"),className:`toggle-group-item ${t==="ultra"?"active":""}`,title:"Stacked area (heavy smoothing)",children:e.jsx(Ut,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>s("mosaic"),className:`toggle-group-item ${t==="mosaic"?"active":""}`,title:"Mosaic view (treemap)",children:e.jsx(Hs,{className:"w-3.5 h-3.5"})})]})}function ln({enabled:t,onChange:s,anomalyCount:n=0,showTuning:a=!1,onTuningChange:r}){return e.jsxs("div",{className:"relative inline-flex items-center gap-1",children:[t&&r&&e.jsx("button",{onClick:()=>r(!a),className:`toggle-group toggle-group-sm ${a?"active":""}`,title:a?"Hide tuning panel":"Show tuning panel",children:e.jsx("span",{className:`toggle-group-item ${a?"active":""}`,children:e.jsx(Es,{className:"w-3.5 h-3.5"})})}),e.jsx("button",{onClick:()=>s(!t),className:`toggle-group toggle-group-sm ${t?"active":""}`,title:t?"Hide noise floor anomalies":"Show noise floor anomalies",children:e.jsx("span",{className:`toggle-group-item ${t?"active":""}`,children:e.jsx(Os,{className:"w-3.5 h-3.5"})})}),n>0&&e.jsx("span",{className:"absolute -top-2 -right-2 min-w-[18px] h-[18px] px-1 rounded-full bg-sys-red text-white text-xs font-bold flex items-center justify-center pointer-events-none z-10",children:n>99?"99+":n})]})}function on({enabled:t,onChange:s,channelName:n="#wardrive"}){const a=n.startsWith("#")?n:`#${n}`;return e.jsx("button",{onClick:()=>s(!t),className:`toggle-group toggle-group-sm ${t?"active":""}`,title:t?`Hide ${a} trendlines`:`Show ${a} trendlines`,children:e.jsxs("span",{className:`toggle-group-item ${t?"active":""}`,children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"ml-1 text-xs font-medium",children:a})]})})}const Dt=[{target:"PacketAnalyzer",fn:"type",minStage:1},{target:"PacketAnalyzer",fn:"airtime",minStage:1,when:bs}];ot(Dt);const Se=-100,Ge=new Map,vt=360,cn=500,mn={sf:10,bw:25e4,cr:5,preamble:8},tt=32;function Nt(t,s){const n=new Date(t*1e3),a=o=>o.toString().padStart(2,"0"),r=`${a(n.getHours())}:${a(n.getMinutes())}`;return s<24?r:`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()]} ${n.getDate()} ${r}`}function dn(t){return t<=Se?"":_t[t]??`TYPE_${t.toString(16).toUpperCase()}`}function wt(t){return Ge.get(t)??Ve(t)}function un(t,s){const n=new Map;for(const r of t){const i=r.type??r.payload_type??-1,o=Ie(r,{spreadingFactor:s.sf,bandwidthHz:s.bw,codingRate:s.cr,preambleLength:s.preamble}),m=n.get(i)??{count:0,airtime:0};n.set(i,{count:m.count+1,airtime:m.airtime+o})}const a=[];for(const[r,i]of n)a.push({typeNum:r,key:`TYPE_${r}`,label:dn(r),totalCount:i.count,totalAirtime:i.airtime});return a.sort((r,i)=>i.totalCount-r.totalCount)}function hn(t,s,n,a,r,i,o=0){const m=n-s,x=m/a,h=x*1e3,d=m/3600,p=s-o*x,w=n+o*x,b=a+2*o,k=[];for(let f=0;f<b;f++){const j=p+f*x,M=new Date(j*1e3),_=d>=24?M.toLocaleDateString([],{weekday:"short",hour:"2-digit",minute:"2-digit",hour12:!1}):M.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),T={timestamp:j,time:_,counts:{},shares:{},airtimes:{},total:0,totalAirtime:0,bucketDurationMs:h};for(const X of i)T.counts[X.key]=0,T.airtimes[X.key]=0;k.push(T)}for(const f of t){const j=f.timestamp;if(j<p||j>=w)continue;const M=Math.min(Math.floor((j-p)/x),b-1),_=`TYPE_${f.type??f.payload_type??-1}`;k[M].counts[_]=(k[M].counts[_]??0)+1,k[M].total++;const T=Ie(f,{spreadingFactor:r.sf,bandwidthHz:r.bw,codingRate:r.cr,preambleLength:r.preamble});k[M].airtimes[_]=(k[M].airtimes[_]??0)+T,k[M].totalAirtime+=T}for(const f of k)for(const j of i)f.shares[j.key]=f.total>0?f.counts[j.key]/f.total*100:0;return{buckets:k,visibleStart:o,visibleEnd:o+a}}function xn(t,s){const n=t.length;if(n===0)return[];if(s<.5)return[...t];const a=Math.sqrt(12*s*s/3+1);let r=Math.floor(a);r%2===0&&r--;const i=r+2,o=(12*s*s-3*r*r-12*r-9)/(-4*r-4),m=Math.round(o),x=[m>0?r:i,m>1?r:i,m>2?r:i];let h=new Float32Array(t);const d=new Float32Array(n);for(const p of x){const w=(p-1)/2;pn(h,d,n,w);const b=h;h=d,d.set(b)}return Array.from(h)}function pn(t,s,n,a){const r=a*2+1;let i=0;for(let o=0;o<=a;o++)i+=t[Math.min(o,n-1)];for(let o=0;o<a;o++)i+=t[0];for(let o=0;o<n;o++){s[o]=i/r;const m=o-a,x=o+a+1;i-=t[Math.max(0,Math.min(m,n-1))],i+=t[Math.max(0,Math.min(x,n-1))]}}function fn(t,s){if(t.length===0)return[];if(s<=1)return[...t];const n=t.length,a=new Float32Array(n),r=Math.floor(s/2);let i=0,o=0;for(let m=0;m<=Math.min(r,n-1);m++)i+=t[m],o++;for(let m=0;m<n;m++){a[m]=i/o;const x=m-r,h=m+r+1;x>=0&&(i-=t[x],o--),h<n&&(i+=t[h],o++)}return Array.from(a)}const gn={ema:1800,ultra:14400},yn={ema:"sma",ultra:"gaussian"};function Lt(t,s,n){const a=gn[t],r=yn[t]??"sma";if(!a)return{sigma:0,window:1,handleSize:0};let i=Math.round(a/s);i=Math.max(3,Math.min(i,Math.floor(n/3))),i%2===0&&(i+=1);const o=Math.ceil(r==="gaussian"?i*Math.sqrt(4/12)*3:i/2);return r==="gaussian"?{sigma:i*Math.sqrt(.3333333333333333),window:i,handleSize:o}:{sigma:0,window:i,handleSize:o}}function bn(t,s,n,a="ultra",r,i,o){var Y;const{buckets:m,visibleStart:x,visibleEnd:h}=t,d=m.length,p=n.length,w=h-x;if(d===0||p===0)return[];const b=o&&r!==void 0&&i!==void 0?(i-r)/o:(Y=m[0])!=null&&Y.bucketDurationMs?m[0].bucketDurationMs/1e3:240,k=Array.from({length:p},()=>new Array(d).fill(0));for(let H=0;H<d;H++){const N=m[H];if(s==="share"){if(N.total>0)for(let v=0;v<p;v++)k[v][H]=(N.counts[n[v].key]??0)/N.total}else{let v=0;for(let c=0;c<p;c++)v+=N.airtimes[n[c].key]??0;if(v>0)for(let c=0;c<p;c++)k[c][H]=(N.airtimes[n[c].key]??0)/v}}const{sigma:f,window:j}=Lt(a,b,w);let M;f>0?M=k.map(H=>xn(H,f)):M=k.map(H=>fn(H,j));for(let H=0;H<d;H++){let N=0;for(let v=0;v<p;v++)M[v][H]=Math.max(0,M[v][H]),N+=M[v][H];if(N>0){const v=1/N;for(let c=0;c<p;c++)M[c][H]*=v}}const _=w>vt?Math.ceil(w/vt):1,T=Math.ceil(w/_),X=[];for(let H=0;H<T;H++){const N=x+H*_,v=Math.min(x+(H+1)*_,h),c=v-N,g=new Array(p).fill(0);for(let y=N;y<v;y++)for(let E=0;E<p;E++)g[E]+=M[E][y];for(let y=0;y<p;y++)g[y]/=c;let I=0;for(let y=0;y<p;y++)I+=g[y];if(I>0){const y=1/I;for(let E=0;E<p;E++)g[E]*=y}const U={timestamp:m[N].timestamp,time:m[N].time};for(let y=0;y<p;y++)U[n[y].key]=g[y];X.push(U)}return X}const st=80;function jn(t,s,n,a,r){const m=Math.max(1,Math.ceil((n-s)/300));if(a==="airtime"){const x=new Float64Array(m);for(const d of t){const p=d.timestamp;if(p<s||p>=n)continue;const w=Math.min(Math.floor((p-s)/300),m-1);x[w]+=Ie(d,{spreadingFactor:r.sf,bandwidthHz:r.bw,codingRate:r.cr,preambleLength:r.preamble})}let h=0;for(let d=0;d<m;d++){const p=x[d]/3e5*100;p>h&&(h=p)}return Math.max(1,Math.ceil(h*1.1))}else{let x=0;for(const h of t){const d=h.timestamp;if(d<s||d>=n)continue;const p=qe(h);p>x&&(x=p)}return x<=240?240:Math.ceil(x*1.1/50)*50}}function vn({packets:t,allPackets:s,startTs:n,endTs:a,parentStartTs:r,parentEndTs:i,bucketCount:o,radioConfig:m=mn,mode:x="share",smoothing:h="stats",noiseFloorAnomalies:d=null,showNoiseFloorOverlay:p=!1,overlayOpacity:w=.5,dotSize:b,dotOpacity:k,showChannelTrendlines:f=!1,channelGroups:j=[]}){lt(Dt);const M=Gt(),[_,T]=l.useState(null),[X,Y]=l.useState(null),H=Vt(S=>S.stableMessages),[N,v]=l.useState([]),c=l.useRef(null),g=l.useRef(0);l.useEffect(()=>{const S=Math.abs(t.length-g.current);if(S===0&&N.length>0)return;c.current&&clearTimeout(c.current);const F=S>100?50:cn;return c.current=setTimeout(()=>{g.current=t.length,v(t)},F),()=>{c.current&&clearTimeout(c.current)}},[t,N.length]);const I=l.useMemo(()=>{const S=new Map;if(f){for(let F=0;F<j.length;F++)for(const W of j[F].channels)S.set(`#${W.toLowerCase()}`,F);Ge.clear();for(let F=0;F<j.length;F++)Ge.set(Se-F,j[F].color)}else Ge.clear();return S},[j,f]),U=l.useMemo(()=>!f||j.length===0||I.size===0?N:N.map(S=>{var ye,je;if((S.type??S.payload_type)!==Te.GRP_TXT||!S.packet_hash)return S;const W=H.get(S.packet_hash),ue=(je=(ye=W==null?void 0:W.decoded)==null?void 0:ye.channelName)==null?void 0:je.toLowerCase();if(!ue)return S;const xe=I.get(ue);return xe===void 0?S:{...S,type:Se-xe}}),[N,f,j,I,H]),y=l.useMemo(()=>{var F;const S=un(U,m);if(f){for(const W of S)if(W.typeNum<=Se){const ue=-(W.typeNum-Se);W.label=((F=j[ue])==null?void 0:F.label)??W.label}}return S},[U,m,f,j]),E=l.useMemo(()=>{if(h!=="ema"&&h!=="ultra")return 0;const F=(a-n)/o,{handleSize:W}=Lt(h,F,o);return W},[h,n,a,o]),q=l.useMemo(()=>hn(U,n,a,o,m,y,E),[U,n,a,o,m,y,E]),ie=l.useMemo(()=>y.reduce((S,F)=>S+F.totalCount,0),[y]),se=l.useMemo(()=>y.reduce((S,F)=>S+F.totalAirtime,0),[y]),{sortedTypes:G,aggregateShares:Z}=l.useMemo(()=>{const S=new Map,F=x==="share"?ie:se;if(F>0)for(const le of y){const u=x==="share"?le.totalCount:le.totalAirtime;S.set(le.key,u/F)}const W=y.filter(le=>le.typeNum>Se),ue=y.filter(le=>le.typeNum<=Se),xe=`TYPE_${Te.GRP_TXT}`,ye=ue.reduce((le,u)=>le+(S.get(u.key)??0),S.get(xe)??0);W.sort((le,u)=>{const D=le.typeNum===Te.GRP_TXT?ye:S.get(le.key)??0;return(u.typeNum===Te.GRP_TXT?ye:S.get(u.key)??0)-D}),ue.sort((le,u)=>(S.get(u.key)??0)-(S.get(le.key)??0));const je=W.findIndex(le=>le.typeNum===Te.GRP_TXT),ke=je>=0?je+1:W.length;return{sortedTypes:[...W.slice(0,ke),...ue,...W.slice(ke)],aggregateShares:S}},[y,ie,se,x]),oe=l.useMemo(()=>bn(q,x,G,h,n,a,o),[q,x,G,h,n,a,o]),pe=l.useCallback(S=>T(S),[]),J=l.useCallback(S=>Y(S),[]),O=l.useCallback(S=>T(S),[]),Q=l.useMemo(()=>{if(X===null||!oe[X])return null;const S=oe[X];return{timestamp:S.timestamp,timeLabel:S.time,items:G.map(F=>({key:F.key,label:F.label,value:S[F.key]??0,color:wt(F.typeNum)}))}},[X,oe,G]),de=l.useMemo(()=>{const S=oe.map(W=>W.timestamp),F=G.map(W=>({key:W.key,label:W.label,color:wt(W.typeNum),values:oe.map(ue=>ue[W.key]??0)}));return{timestamps:S,series:F}},[oe,G]),C=null,z=s&&r!==void 0&&i!==void 0&&(n!==r||a!==i),B=l.useMemo(()=>{if(!(!z||!s||r===void 0||i===void 0))return jn(s,r,i,x,m)},[z,s,r,i,x,m]);if(N.length===0)return t.length===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(De,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet data available"})]}):null;if(h==="mosaic")return e.jsx(Qs,{sortedTypes:G,aggregateShares:Z,mode:x});const L=(a-n)/3600,$=Nt(n,L),V=Nt(a,L);return h==="stats"?e.jsx(nn,{mode:x,packets:N,startTs:n,endTs:a,radioConfig:m,sortedTypes:G,aggregateShares:Z,noiseFloorAnomalies:d,showNoiseFloorOverlay:p,overlayOpacity:w,startLabel:$,endLabel:V,lockedYMax:B,legendMinH:st,dotSize:b,dotOpacity:k,channelGroups:f?j:void 0,channelToGroup:I,decodedMessages:H}):h==="trend"?e.jsx(en,{packets:N,mode:x,startTs:n,endTs:a,radioConfig:m,bucketCount:o,lockedYMax:B,legendMinH:st}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex-1 min-h-0 relative",children:[e.jsx("div",{className:"absolute top-0 left-0 flex flex-col justify-between",style:{width:tt,bottom:20},children:[0,20,40,60,80,100].map((S,F,W)=>e.jsxs("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${(1-S/100)*100}%`,transform:F===0?"translateY(-100%)":F===W.length-1?"none":"translateY(-50%)",right:0},children:[S,"%"]},S))}),e.jsx("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:tt,right:0,top:0,bottom:20},children:e.jsx(qt,{timestamps:de.timestamps,series:de.series,highlightedKey:_,cursorColor:M.cursor,onHover:J,onSeriesHover:O,overlayLines:C,startTs:n,endTs:a,externalAxes:!0})}),e.jsxs("div",{className:"absolute left-0 right-0 bottom-0 flex justify-between pointer-events-none type-data-xs text-fg-muted/60",style:{left:tt,height:20,paddingTop:4},children:[e.jsx("span",{children:$}),e.jsx("span",{children:V})]})]}),e.jsx("div",{style:{minHeight:st},children:e.jsx(ct,{sortedTypes:G,highlightedType:_,onTypeHover:pe,aggregateShares:Z,hoverData:Q,overlayLines:C})})]})}const Nn=l.memo(vn),nt={ZOOM_DURATION:400,BLINK_DURATION:600},he={PADDING:6,DOT_RADIUS:5,DOT_RADIUS_HOVERED:7,LOCAL_DOT_RADIUS:5,CARDINAL_FONT_SIZE:10,INTERCARDINAL_FONT_SIZE:9,LABEL_INSET:8,DATA_HEADROOM:1.6,OUTLIER_DISTANCE_KM:1e3},wn={"1x":1,"2x":2,"4x":4,"8x":8,"16x":16,"36x":36,"64x":64},kt=[1,5,10,25,50,100,150],kn=22.5,Pt=kn*Math.PI/180,St=Math.sin(Pt),Mt=Math.cos(Pt);function Sn(t,s,n,a){const r=Math.PI/180,i=(a-s)*r,o=t*r,m=n*r,x=Math.sin(i)*Math.cos(m),h=Math.cos(o)*Math.sin(m)-Math.sin(o)*Math.cos(m)*Math.cos(i);return(Math.atan2(x,h)*180/Math.PI+360)%360}function Mn(t,s,n,a){const i=Math.PI/180,o=(n-t)*i,m=(a-s)*i,x=Math.sin(o/2)**2+Math.cos(t*i)*Math.cos(n*i)*Math.sin(m/2)**2;return 6371*2*Math.atan2(Math.sqrt(x),Math.sqrt(1-x))}const Cn=[{min:10,label:"Excellent"},{min:7,label:"Very Good"},{min:4,label:"Good"},{min:1,label:"Fair+"},{min:-2,label:"Fair"},{min:-5,label:"Fair-"},{min:-8,label:"Poor"},{min:-11,label:"Bad"},{min:-1/0,label:"Critical"}];function An(t){var s;return((s=Cn.find(n=>t>=n.min))==null?void 0:s.label)??"Critical"}function Ct(t,s,n){const a=Jt(t,n);return s[a]||"#808080"}function _n({neighbors:t,quickNeighbors:s,localLat:n,localLon:a,onStatsChange:r,title:i,badge:o,stats:m}){const[x,h]=l.useState(null),[d,p]=l.useState(new Set),[w,b]=l.useState({width:0,height:0}),[k,f]=l.useState("1x"),[j,M]=l.useState(1),_=l.useRef(null),T=l.useRef({}),X=l.useRef(null),Y=l.useRef(j);Y.current=j;const H=Kt(),N=Xt(),v=Yt(),c=Zt(),g=Tt(),I=Qt(),U=c?v.primary:v.secondary,y=c?.15:.4,E=c?.08:.25,q=c?g.blue:v.primary;l.useEffect(()=>{const u=X.current;if(!u)return;const D=new ResizeObserver(P=>{for(const ne of P){const{width:ae,height:K}=ne.contentRect;ae>0&&K>0&&b({width:ae,height:K})}});D.observe(u);const R=u.getBoundingClientRect();return R.width>0&&R.height>0&&b({width:R.width,height:R.height}),()=>D.disconnect()},[]);const ie=l.useMemo(()=>{const u=new Set;if(s)for(const D of s)u.add(D.hash);return u},[s]),se=l.useMemo(()=>{const u=new Map;if(s)for(const D of s)u.set(D.hash,{snr:D.avgSnr,rssi:D.avgRssi});return u},[s]),{processedNeighbors:G,maxDistance:Z,totalNeighbors:oe,zeroHopCount:pe}=l.useMemo(()=>{const u=[];for(const[K,ee]of Object.entries(t)){if(!ee.latitude||!ee.longitude||ee.latitude===0||ee.longitude===0)continue;const re=ie.has(K),me=Sn(n,a,ee.latitude,ee.longitude),fe=Mn(n,a,ee.latitude,ee.longitude),ce=se.get(K);u.push({hash:K.slice(0,8),name:ee.node_name||ee.name||"Unknown",snr:re?(ce==null?void 0:ce.snr)??ee.snr??null:null,rssi:re?(ce==null?void 0:ce.rssi)??ee.rssi??null:null,bearing:me,distance:fe,normalizedDistance:0,lastSeen:ee.last_seen,isZeroHop:re})}const D=u.map(K=>K.distance).filter(K=>Number.isFinite(K)&&K>0),R=D.filter(K=>K<=he.OUTLIER_DISTANCE_KM),P=R.length>0?R:D,ae=(P.length>0?Math.max(...P):0)*he.DATA_HEADROOM;return u.sort((K,ee)=>(K.snr??-1/0)-(ee.snr??-1/0)),{processedNeighbors:u,maxDistance:ae,totalNeighbors:u.length,zeroHopCount:u.filter(K=>K.isZeroHop).length}},[t,n,a,ie,se]);l.useEffect(()=>{r==null||r({zeroHopCount:pe,totalCount:oe,maxDistanceKm:Z})},[pe,oe,Z]),l.useEffect(()=>{const u=wn[k],D=Y.current;_.current&&cancelAnimationFrame(_.current);const R=performance.now(),P=ne=>{const ae=ne-R,K=Math.min(ae/nt.ZOOM_DURATION,1),ee=js(K),re=D+(u-D)*ee;M(re),K<1?_.current=requestAnimationFrame(P):_.current=null};return _.current=requestAnimationFrame(P),()=>{_.current&&cancelAnimationFrame(_.current)}},[k]);const J=Z/j,O=l.useMemo(()=>kt.filter(u=>u<=J*1.1),[J]);l.useEffect(()=>{const u=[];for(const R of G){const P=T.current[R.hash];P!==void 0&&P!==R.lastSeen&&u.push(R.hash),T.current[R.hash]=R.lastSeen}if(u.length===0)return;queueMicrotask(()=>{p(R=>new Set([...R,...u]))});const D=setTimeout(()=>{p(R=>{const P=new Set(R);return u.forEach(ne=>P.delete(ne)),P})},nt.BLINK_DURATION);return()=>clearTimeout(D)},[G]);const Q=n!==0&&a!==0,de=l.useMemo(()=>{const{width:u,height:D}=w,R=u/2,P=D/2,ne=Math.min(u,D),ae=Math.max(10,ne/2-he.PADDING),K=Math.max(10,ae-he.LABEL_INSET);return{width:u,height:D,centerX:R,centerY:P,radius:K,labelRadius:ae}},[w]),{width:C,height:z,centerX:B,centerY:L,radius:$,labelRadius:V}=de,S=l.useId(),F=l.useCallback((u,D)=>{const R=u*Math.PI/180;return{x:B+$*D*Math.sin(R),y:L-$*D*Math.cos(R)}},[B,L,$]),W=l.useCallback(u=>{const R={N:0,NE:45,E:90,SE:135,S:180,SW:225,W:270,NW:315}[u]*Math.PI/180;return{x:B+V*Math.sin(R),y:L-V*Math.cos(R)}},[B,L,V]),ue=l.useCallback(u=>{h(u)},[]),xe=l.useCallback(u=>{f(u)},[]),ye=l.useCallback(u=>Z<=0?0:u/Z*j,[Z,j]),je=u=>`${u}km`,ke=28,Fe=l.useMemo(()=>{const u=[{x:B,y:L-V},{x:B+V*Math.SQRT1_2,y:L-V*Math.SQRT1_2}],D=O.map(P=>{const ne=P/Z*j,ae=B+$*ne*St,K=L-$*ne*Mt;return{km:P,scale:ne,lx:ae,ly:K}}).filter(P=>P.scale>=.02).sort((P,ne)=>ne.km-P.km),R=[];for(const P of D){const ne=R.some(K=>{const ee=K.lx-P.lx,re=K.ly-P.ly;return Math.sqrt(ee*ee+re*re)<ke}),ae=u.some(K=>{const ee=K.x-P.lx,re=K.y-P.ly;return Math.sqrt(ee*ee+re*re)<ke});!ne&&!ae&&R.push(P)}return R},[O,Z,j,B,L,$,V]),le=w.width>0&&w.height>0;return Q?oe===0?e.jsxs("div",{ref:X,className:"flex flex-col items-center justify-center h-full text-fg-secondary",children:[e.jsx(Ye,{className:"w-8 h-8 mb-2 opacity-50"}),e.jsx("p",{children:"No nodes with location data"})]}):e.jsxs("div",{className:"flex h-full w-full overflow-visible",children:[e.jsxs("div",{ref:X,className:"relative flex-1 min-w-0 h-full overflow-visible -ml-4 sm:-ml-5",children:[le&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute depth-stroke-inset",style:{left:B-$-he.LABEL_INSET-4,top:L-$-he.LABEL_INSET-4,width:($+he.LABEL_INSET)*2+8,height:($+he.LABEL_INSET)*2+8,borderRadius:"50%",padding:4,boxSizing:"border-box",backgroundColor:c?"var(--zinc-925)":"var(--zinc-75)"}}),e.jsxs("svg",{width:C,height:z,className:"absolute inset-0 z-0",style:{overflow:"visible"},children:[e.jsxs("defs",{children:[e.jsx("style",{children:`
                @keyframes neighbor-blink-scale {
                  0%, 100% {
                    transform: scale(1);
                    opacity: 0;
                  }
                  50% {
                    transform: scale(1.3);
                    opacity: 0.8;
                  }
                }
                .neighbor-blink-ring {
                  transform-origin: center;
                  animation: neighbor-blink-scale ${nt.BLINK_DURATION}ms ease-out forwards;
                }
              `}),e.jsx("clipPath",{id:S,children:e.jsx("circle",{cx:B,cy:L,r:$})})]}),(()=>{const u=$+he.LABEL_INSET+12,D=c?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.15)",R=c?"rgba(59, 130, 246, 0.4)":"rgba(59, 130, 246, 0.5)",P=6,ne=16,ae=4,K=[0,90,180,270],ee=[45,135,225,315];return e.jsxs("g",{className:"radar-frame","aria-hidden":"true",children:[e.jsx("circle",{cx:B,cy:L,r:u,fill:"none",stroke:D,strokeWidth:1,strokeDasharray:"2 6"}),ee.map(re=>{const me=re*Math.PI/180,fe=Math.cos(me),ce=Math.sin(me),ve=u+ae,Ne=u+ae+ne,He=B+ve*ce,Be=L-ve*fe,Me=B+Ne*ce,Ce=L-Ne*fe;return e.jsxs("g",{children:[e.jsx("line",{x1:He,y1:Be,x2:Me,y2:Ce,stroke:R,strokeWidth:1}),e.jsx("line",{x1:Me-4*fe,y1:Ce-4*ce,x2:Me+4*fe,y2:Ce+4*ce,stroke:R,strokeWidth:1})]},`corner-${re}`)}),K.map(re=>{const me=re*Math.PI/180,fe=B+(u-P)*Math.sin(me),ce=L-(u-P)*Math.cos(me),ve=B+(u+2)*Math.sin(me),Ne=L-(u+2)*Math.cos(me);return e.jsx("line",{x1:fe,y1:ce,x2:ve,y2:Ne,stroke:D,strokeWidth:1},`tick-cardinal-${re}`)}),ee.map(re=>{const me=re*Math.PI/180,fe=B+(u-4)*Math.sin(me),ce=L-(u-4)*Math.cos(me),ve=B+(u+1)*Math.sin(me),Ne=L-(u+1)*Math.cos(me);return e.jsx("line",{x1:fe,y1:ce,x2:ve,y2:Ne,stroke:D,strokeWidth:1},`tick-intercardinal-${re}`)})]})})(),(()=>{const u=$+he.LABEL_INSET+4,D=[0,...kt.map(R=>{const P=ye(R);return P<=0?0:Math.min($*P,u)}),u];return D.slice(0,-1).map((R,P)=>{const ne=D[P+1],ae=ne-R;return ae<.5||P%2!==0?null:e.jsx("circle",{cx:B,cy:L,r:(ne+R)/2,fill:"none",stroke:"var(--subtle-fill)",strokeWidth:ae},`band-${P}`)})})(),O.map(u=>{const D=ye(u);if(D<.02)return null;const R=Fe.some(ae=>ae.km===u),P=B+$*D*St,ne=L-$*D*Mt;return e.jsx("g",{children:R&&e.jsx("text",{x:P+4,y:ne-2,textAnchor:"start",dominantBaseline:"auto",fill:v.secondary,fontSize:10,fontFamily:Ke,children:je(u)})},`ring-${u}`)}),["N","E","S","W"].map(u=>{const R={N:0,E:90,S:180,W:270}[u]*Math.PI/180;return e.jsx("line",{x1:B,y1:L,x2:B+$*Math.sin(R),y2:L-$*Math.cos(R),stroke:U,strokeOpacity:y,strokeWidth:1,strokeDasharray:"4 4"},u)}),["NE","SE","SW","NW"].map(u=>{const R={NE:45,SE:135,SW:225,NW:315}[u]*Math.PI/180;return e.jsx("line",{x1:B,y1:L,x2:B+$*Math.sin(R),y2:L-$*Math.cos(R),stroke:U,strokeOpacity:E,strokeWidth:1,strokeDasharray:"4 4"},`diag-${u}`)}),["N","E","S","W"].map(u=>{const D=W(u),R=u==="E"?"end":u==="W"?"start":"middle",P=u==="N"?"hanging":u==="S"?"auto":"middle";return e.jsx("text",{x:D.x,y:D.y,textAnchor:R,dominantBaseline:P,fill:q,fontSize:he.CARDINAL_FONT_SIZE,fontWeight:700,fontFamily:Ke,"aria-hidden":"true",children:u},u)}),["NE","SE","SW","NW"].map(u=>{const D=W(u),R=u==="NE"||u==="SE"?"end":"start",P=u==="NE"||u==="NW"?"hanging":"auto";return e.jsx("text",{x:D.x,y:D.y,textAnchor:R,dominantBaseline:P,fill:q,fontSize:he.INTERCARDINAL_FONT_SIZE,fontWeight:600,fontFamily:Ke,"aria-hidden":"true",children:u},u)}),e.jsx("circle",{cx:B,cy:L,r:he.LOCAL_DOT_RADIUS,fill:N.chart6,stroke:c?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",strokeWidth:1,role:"img","aria-label":"Local node"}),e.jsx("g",{clipPath:`url(#${S})`,children:G.map(u=>{const D=Z>0?u.distance/Z*j:0;if(D>1)return null;const{x:R,y:P}=F(u.bearing,D),ne=u.snr!==null?Ct(u.snr,H,I):"#808080",ae=(x==null?void 0:x.hash)===u.hash,K=d.has(u.hash),ee=he.DOT_RADIUS_HOVERED*1.5;return e.jsxs("g",{role:"img","aria-label":`${u.name}: ${u.distance.toFixed(1)}km ${u.bearing.toFixed(0)}°`,children:[K&&e.jsx("circle",{cx:R,cy:P,r:ee,fill:"none",stroke:c?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.7)",strokeWidth:2,className:"neighbor-blink-ring"}),ae&&e.jsx("circle",{cx:R,cy:P,r:ee,fill:ne,opacity:.3}),e.jsx("circle",{cx:R,cy:P,r:ae?he.DOT_RADIUS_HOVERED:he.DOT_RADIUS,fill:ne,stroke:c?"rgba(0,0,0,0.5)":"rgba(0,0,0,0.25)",strokeWidth:1,style:{cursor:"pointer",transition:"r 0.15s"},onMouseEnter:()=>ue(u),onMouseLeave:()=>ue(null)})]},u.hash)})})]})]}),x&&e.jsxs("div",{className:"absolute bg-tooltip-bg border border-edge-subtle rounded-lg px-3 py-2 text-sm pointer-events-none z-10 shadow-xl",style:{left:"50%",bottom:8,transform:"translateX(-50%)"},children:[e.jsx("div",{className:"font-medium text-fg-primary",children:x.name}),e.jsx("div",{className:"type-data-xs text-fg-secondary",children:x.hash}),x.snr!==null?e.jsx("div",{className:"flex gap-3 mt-1 text-xs",children:e.jsxs("span",{children:[e.jsx("span",{className:"text-fg-secondary",children:"SNR:"})," ",e.jsxs("span",{className:"tabular-nums",style:{color:Ct(x.snr,H,I)},children:[x.snr.toFixed(1)," dB"]}),e.jsxs("span",{className:"text-fg-secondary ml-1",children:["(",An(x.snr),")"]})]})}):e.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:"No SNR data"}),e.jsxs("div",{className:"flex gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-fg-secondary",children:"Distance:"})," ",e.jsxs("span",{className:"tabular-nums text-fg-primary",children:[x.distance.toFixed(2)," km"]})]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-fg-secondary",children:"Bearing:"})," ",e.jsxs("span",{className:"tabular-nums text-fg-primary",children:[x.bearing.toFixed(0),"°"]})]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 px-1.5 pt-4 sm:pt-5 pb-2 flex-shrink-0 depth-raised radius-inset self-stretch",style:{width:"calc(100% / 6)"},children:[i&&e.jsxs("div",{className:"flex flex-col items-start gap-1 pb-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"icon-md flex items-center justify-center text-icon-card-title",children:e.jsx(Ye,{className:"w-3.5 h-3.5"})}),o&&e.jsx(Pe,{color:"zinc",children:o})]}),e.jsx("span",{className:"type-micro text-left text-[10px] leading-tight px-1",children:i})]}),e.jsx("div",{className:"flex flex-col gap-1 flex-1",role:"group","aria-label":"Zoom level",children:["1x","2x","4x","8x","16x","36x","64x"].map(u=>e.jsx("button",{onClick:()=>xe(u),"aria-pressed":k===u,className:`flex flex-1 items-center justify-center min-w-[44px] sm:min-w-[32px] text-xs font-medium radius-inner depth-stroke-raised transition-colors ${k===u?"bg-sys-blue/20 text-sys-blue":"bg-subtle-fill/80 text-fg-secondary hover:bg-subtle-fill-strong hover:text-fg-primary"}`,children:u},u))})]})]}):e.jsxs("div",{ref:X,className:"flex flex-col items-center justify-center h-full text-fg-secondary",children:[e.jsx(Ye,{className:"w-8 h-8 mb-2 opacity-50"}),e.jsx("p",{children:"Local node coordinates not configured"}),e.jsx("p",{className:"text-xs mt-1",children:"Set latitude/longitude in config to enable"})]})}const Tn=l.memo(_n),at={repeater:"var(--sys-blue)",companion:"var(--sys-cyan)",room_server:"var(--sys-indigo)"};function Rn(t){if(t.contact_type){const s=t.contact_type.toLowerCase();if(s==="repeater"||s==="rep")return"repeater";if(s==="room server"||s==="room_server"||s==="room"||s==="server")return"room_server";if(s==="companion"||s==="client"||s==="cli")return"companion"}return t.is_repeater?"repeater":"companion"}function En({neighbors:t,timeRangeLabel:s}){const n=l.useMemo(()=>{const a={repeater:0,companion:0,room_server:0};for(const o of Object.values(t)){const m=Rn(o);a[m]=(a[m]||0)+1}const r=Object.values(a).reduce((o,m)=>o+m,0);return{items:[{label:"Repeaters",count:a.repeater,percent:0,color:at.repeater},{label:"Companions",count:a.companion,percent:0,color:at.companion},{label:"Room Servers",count:a.room_server,percent:0,color:at.room_server}].map(o=>({...o,percent:r>0?o.count/r*100:0})).filter(o=>o.count>0).sort((o,m)=>m.count-o.count),total:r}},[t]);return n.total===0?e.jsx("div",{className:"h-full flex items-center justify-center text-fg-muted type-body-sm",children:"No neighbors discovered yet"}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"flex-1 flex flex-col justify-evenly",children:n.items.map(a=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"type-data-sm text-fg-secondary",children:a.label}),e.jsxs("span",{className:"type-data-sm text-fg-secondary tabular-nums",children:[a.count," ",e.jsxs("span",{className:"text-fg-secondary/60",children:["(",a.percent.toFixed(0),"%)"]})]})]}),e.jsx("div",{className:"h-2.5 bg-subtle-fill/80 overflow-hidden rounded-full depth-stroke-inset",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 ease-out",style:{width:`${a.percent}%`,backgroundColor:a.color,minWidth:a.count>0?"4px":"0"}})})]},a.label))}),e.jsxs("div",{className:"mt-auto pt-2",children:[e.jsxs("div",{className:"data-box-label flex items-center gap-1.5",children:["Total Nodes",s&&e.jsx(Pe,{color:"zinc",children:s})]}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:n.total})]})]})}const In=l.memo(En);function it({children:t,minHeight:s="100%",rootMargin:n="200px 0px",keepMounted:a=!0,className:r=""}){const i=l.useRef(null),[o,m]=l.useState(!1),[x,h]=l.useState(!1);l.useEffect(()=>{const p=i.current;if(!p)return;const w=new IntersectionObserver(([b])=>{const k=b.isIntersecting;h(k),k&&m(!0)},{rootMargin:n,threshold:0});return w.observe(p),()=>{w.disconnect()}},[n]);const d=x||a&&o;return e.jsx("div",{ref:i,className:`h-full w-full ${r}`,style:{minHeight:s},children:d?t:e.jsx("div",{className:"h-full w-full flex items-center justify-center text-fg-muted/50",children:e.jsx("div",{className:"animate-pulse text-xs",children:"Loading chart..."})})})}const Ot=[{target:"DisambiguationCard",fn:"disambiguation.collisions",minStage:2}];ot(Ot);const Dn=.9,Ln=.7,Pn=.5,On=10,Fn=25,Ue={excellent:"text-signal-excellent",good:"text-signal-good",fair:"text-signal-fair",poor:"text-sys-blue"},Hn={excellent:"bg-signal-excellent/10",good:"bg-signal-good/10",fair:"bg-signal-fair/10",poor:"bg-sys-blue/10"},Bn=[{value:"auto",label:"Auto",title:"Use the path hash widths actually observed in packet paths."},{value:"1",label:"1B",title:"Force legacy 1-byte / 2-hex-character prefix conflict view."},{value:"2",label:"2B",title:"Force 2-byte / 4-hex-character prefix conflict view."},{value:"3",label:"3B",title:"Force 3-byte / 6-hex-character prefix conflict view."}],At="openhop.prefixConflictWidth";function $n(t){return t>=Dn?"excellent":t>=Ln?"good":t>=Pn?"fair":"poor"}function zn(t){return t<=On?"excellent":t<=Fn?"good":"poor"}function Wn(t){return t==="auto"||t==="1"||t==="2"||t==="3"}function Un(){var M;lt(Ot);const t=es(),s=ts(),[n,a]=l.useState(()=>{if(typeof window>"u")return"auto";const _=window.localStorage.getItem(At);return Wn(_)?_:"auto"}),i=(n==="auto"||(M=t.byHashSize)==null?void 0:M[Number(n)])??t,o=n==="auto"?"Auto":`${n}B`,[m,x]=l.useState(null),h=l.useCallback(_=>{a(_),typeof window<"u"&&window.localStorage.setItem(At,_)},[]),d=l.useCallback((_,T)=>{x({prefix:_,candidateHashes:T})},[]),p=l.useCallback(()=>{x(null)},[]);if(!s)return e.jsxs(be,{neomorphic:!0,children:[e.jsx(Ee,{icon:e.jsx(ht,{}),title:"Prefix Conflicts"}),e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-fg-secondary",children:[e.jsx(ss,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"type-data-xs",children:"No topology data available"}),e.jsx("p",{className:"type-data-xs opacity-70",children:"Run deep analysis to see stats"})]})})]});const w=$n(i.avgConfidence),b=zn(i.collisionRate),k=i.collisionPrefixes>0||i.lowConfidencePrefixes.length>0,f=k?b==="poor"||i.lowConfidencePrefixes.length>0?"poor":b:"excellent",j=f==="excellent"||f==="good"?xt:dt;return e.jsxs(be,{neomorphic:!0,className:"flex flex-col overflow-hidden",children:[e.jsx(Ee,{icon:e.jsx(ht,{}),title:"Prefix Conflicts",badgeColor:"zinc",actions:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("div",{className:"inline-flex rounded-lg bg-subtle-fill-strong p-0.5","aria-label":"Prefix width",children:Bn.map(_=>{const T=_.value===n;return e.jsx("button",{type:"button",title:_.title,onClick:()=>h(_.value),className:`px-2 py-0.5 rounded-md type-data-xs transition-colors ${T?"bg-surface text-fg-primary shadow-sm":"text-fg-muted hover:text-fg-secondary"}`,children:_.label},_.value)})}),f==="poor"?e.jsxs(Pe,{color:"red",children:[e.jsx(dt,{className:"w-3 h-3"}),"Needs Attention"]}):e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full ${Hn[f]}`,children:[e.jsx(j,{className:`w-3.5 h-3.5 ${Ue[f]}`}),e.jsx("span",{className:`type-data-xs font-medium ${Ue[f]}`,children:f==="excellent"?"Excellent":f==="good"?"Good":"Fair"})]})]})}),e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex-1 flex flex-col radius-inner depth-stroke-inset px-3 py-2.5 sm:py-3 cursor-help",title:"Total unique path-hop prefixes observed at the active MeshCore hash width.",children:[e.jsx("span",{className:"type-data-xl text-fg-primary",children:e.jsx(Ze,{value:i.totalPrefixes,priority:"low"})}),e.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Prefixes"})]}),e.jsxs("div",{className:"flex-1 flex flex-col radius-inner depth-stroke-inset px-3 py-2.5 sm:py-3 cursor-help",title:"Prefixes that map to exactly one known node. No disambiguation needed.",children:[e.jsx("span",{className:"type-data-xl text-fg-primary",children:e.jsx(Ze,{value:i.unambiguousPrefixes,priority:"low"})}),e.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Unique"})]}),e.jsxs("div",{className:"flex-1 flex flex-col radius-inner depth-stroke-inset px-3 py-2.5 sm:py-3 cursor-help",title:"Prefixes matching multiple known nodes. Click a prefix below to explore candidates.",children:[e.jsx("span",{className:`type-data-xl ${i.collisionPrefixes>0?"text-sys-blue":"text-fg-primary"}`,children:e.jsx(Ze,{value:i.collisionPrefixes,priority:"low"})}),e.jsx("span",{className:`type-micro mt-0.5 sm:mt-1 ${i.collisionPrefixes>0?"text-sys-blue":"text-fg-muted"}`,children:"Conflicts"})]})]}),i.highCollisionPrefixes.length>0&&e.jsxs("div",{className:"pt-3",children:[e.jsxs("div",{className:"data-box-label",children:["Problem Prefixes · ",o]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 content-start",children:i.highCollisionPrefixes.map(({prefix:_,candidateCount:T,candidateHashes:X})=>e.jsxs("button",{type:"button",onClick:()=>d(_,X),className:"inline-flex items-center gap-0.5 group",title:`${T} candidates - click to explore`,children:[e.jsx(ns,{children:_}),e.jsxs("span",{className:"text-fg-muted type-data-xs group-hover:text-fg-secondary transition-colors",children:["×",T]})]},_))})]}),!k&&e.jsx("div",{className:"flex-1 flex items-center",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{className:"w-3.5 h-3.5 text-signal-excellent"}),e.jsxs("span",{className:"type-data-xs text-signal-excellent",children:["All ",o," prefixes uniquely identified"]})]})}),e.jsxs("div",{className:"flex gap-2 sm:gap-3 mt-auto pt-3",children:[e.jsxs("div",{className:"flex-1 min-w-0 cursor-help",title:"Average confidence score across all disambiguated prefixes. Higher = more certain node identification.",children:[e.jsx("div",{className:"data-box-label",children:"Confidence"}),e.jsxs("div",{className:`data-box data-box-fill data-box-left ${Ue[w]}`,children:[(i.avgConfidence*100).toFixed(1),"%"]})]}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-help",title:"Percentage of path-hop prefixes that match multiple known nodes. Lower is better.",children:[e.jsx("div",{className:"data-box-label",children:"Collisions"}),e.jsxs("div",{className:`data-box data-box-fill data-box-left ${Ue[b]}`,children:[i.collisionRate.toFixed(1),"%"]})]})]})]}),e.jsx(Ss,{isOpen:!!m,prefix:(m==null?void 0:m.prefix)||"",candidateHashes:(m==null?void 0:m.candidateHashes)||[],onClose:p})]})}const Ft=[{target:"PacketHealth",fn:"type",minStage:1},{target:"PacketHealth",fn:"duplicates",minStage:1}];ot(Ft);const ge=24;function Gn(t,s,n,a){const r=Date.now()/1e3,i=s*60,o=r-i,m=i/ge,x=new Array(ge).fill(0),h=new Array(ge).fill(0),d=new Array(ge).fill(0),p=new Array(ge).fill(0),w=new Array(ge).fill(0),b=new Array(ge).fill(0);let k=0,f=0,j=0,M=0,_=0,T=0,X=0;if(a&&a.length>0)for(const y of a){const E=y.timestamp;if(E<o||E>r)continue;X++;const q=Math.min(ge-1,Math.floor((E-o)/m));q>=0&&w[q]++}else if(n!=null&&n>0){X=n;const y=n/ge;for(let E=0;E<ge;E++)w[E]=y}for(const y of t){if(y.packet_origin==="tx_local")continue;const E=y.timestamp;if(E<o||E>r)continue;k++;const q=Math.min(ge-1,Math.floor((E-o)/m));h[q]++,y.transmitted||y.packet_origin==="tx_forward"?(f++,x[q]++):y.is_duplicate||y.drop_reason==="Duplicate"?j++:y.drop_reason&&(M++,b[q]++),rs(y.route??y.route_type)&&(_++,d[q]++),y._packetVersion===1&&(T++,p[q]++)}const Y=X,H=k+Y,N=[],v=[],c=[],g=[],I=[];for(let y=0;y<ge;y++){const E=h[y],q=x[y],ie=w[y],se=b[y],G=(o+y*m)*1e3,Z=E+ie;N.push({count:Z>0?q/Z*100:0,timestamp:G}),v.push({count:Z>0?(se+ie)/Z*100:0,timestamp:G}),c.push({count:Z>0?ie/Z*100:0,timestamp:G}),g.push({count:E>0?d[y]/E*100:0,timestamp:G}),I.push({count:E>0?p[y]/E*100:0,timestamp:G})}const U=k-j;return{totalRx:k,uniqueRx:U,forwarded:f,duplicates:j,waste:M,efficiency:H>0?f/H*100:0,duplicateRate:H>0?j/H*100:0,wasteRate:H>0?(M+Y)/H*100:0,sparkline:N,wasteSparkline:v,crcSparkline:c,transport:_,v2:T,transportSparkline:g,v2Sparkline:I}}function Vn({packets:t,rangeMinutes:s,rangeHours:n,timeRangeLabel:a,isLoaded:r=!0}){lt(Ft);const[i,o]=l.useState(null),[m,x]=l.useState(null),h=l.useCallback(async()=>{try{const w=await Rt(n);if(w.success&&w.data){o(w.data.count??w.data.history.length),x(w.data.history);return}const b=await as(n);b.success&&b.data&&(o(b.data.count),x(null))}catch{}},[n]);l.useEffect(()=>{h()},[h]);const d=l.useMemo(()=>Gn(t,s,i,m),[t,s,i,m]),p=d.totalRx>0;return e.jsx(be,{neomorphic:!0,isLoaded:r,skeletonType:"chart",children:r&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{icon:e.jsx(Ms,{}),title:"Packet Health",badge:a,badgeColor:"zinc"}),e.jsx(is,{children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex gap-2 sm:gap-3 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0 radius-inner depth-stroke-inset p-2 flex flex-col h-full cursor-help",title:"Total useless traffic: Software drops (e.g. empty, crypto) + Hardware CRC errors. Excludes duplicates.",children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("div",{className:"data-box-label",children:"Discarded"}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-sys-indigo",children:p?`${d.wasteRate.toFixed(1)}%`:"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(We,{data:d.wasteSparkline,width:9999,height:24,className:"w-full",color:"var(--sys-indigo)",invertScale:!0})})]}),e.jsxs("div",{className:"flex-1 min-w-0 radius-inner depth-stroke-inset p-2 flex flex-col h-full cursor-help",title:"Packets lost at the radio hardware level due to corruption or interference.",children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("div",{className:"data-box-label flex items-center gap-1",children:"CRC Errors"}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-status-warning",children:i!==null?i:"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(We,{data:d.crcSparkline,width:9999,height:24,className:"w-full",color:"var(--status-warning)",invertScale:!0})})]})]}),e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0 radius-inner depth-stroke-inset p-2 flex flex-col h-full cursor-help",title:"Packets with Transport headers (reliable messaging)",children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("div",{className:"data-box-label",children:"Transport"}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-sys-amber",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ze,{children:d.transport}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(ze,{children:d.uniqueRx})]}):"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(We,{data:d.transportSparkline,width:9999,height:24,className:"w-full",color:"var(--sys-amber)"})})]}),e.jsxs("div",{className:"flex-1 min-w-0 radius-inner depth-stroke-inset p-2 flex flex-col h-full cursor-help",title:"Packets using V2 protocol format",children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("div",{className:"data-box-label",children:"V2"}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-sys-teal",children:p?e.jsxs(e.Fragment,{children:[e.jsx(ze,{children:d.v2}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(ze,{children:d.uniqueRx})]}):"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(We,{data:d.v2Sparkline,width:9999,height:24,className:"w-full",color:"var(--sys-teal)"})})]})]}),e.jsxs("div",{className:"flex gap-2 sm:gap-3 mt-auto",children:[e.jsxs("div",{className:"flex-1 min-w-0 cursor-help",title:"Redundant packets dropped because they were already received",children:[e.jsx("div",{className:"data-box-label",children:"Dupes"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:p?`${d.duplicateRate.toFixed(1)}%`:"—"})]}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-help",title:"Packets successfully retransmitted to extend the mesh",children:[e.jsx("div",{className:"data-box-label",children:"Forwarded"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:p?`${d.efficiency.toFixed(1)}%`:"—"})]})]})]})})]})})}function Sa(){var D,R,P,ne,ae,K,ee,re,me,fe,ce,ve,Ne,He,Be,Me,Ce;const t=ls(),s=os(),n=cs(),a=ms(),r=ds(),i=us(),o=t!==null&&r,m=l.useRef(!1);o&&!m.current&&(m.current=!0);const x=m.current,h=hs(),d=xs(),[p,w]=l.useState([]),[b,k]=l.useState(null),[,f]=l.useState(null),[j]=l.useState(null),[M,_]=l.useState(()=>{const A=localStorage.getItem("statistics-view-mode");return A==="share"||A==="airtime"?A:"airtime"});l.useEffect(()=>{localStorage.setItem("statistics-view-mode",M)},[M]);const[T,X]=l.useState(()=>{const A=localStorage.getItem("statistics-smoothing-mode");return["ema","ultra","mosaic","stats","trend"].includes(A)?A:"stats"});l.useEffect(()=>{localStorage.setItem("statistics-smoothing-mode",T)},[T]);const[Y,H]=l.useState(!1),[N,v]=l.useState(!1),[c,g]=l.useState(It),[I,U]=l.useState(.5),[y,E]=l.useState(Cs),[q,ie]=l.useState(.5),[se,G]=l.useState(85),[Z,oe]=l.useState(()=>localStorage.getItem("statistics-channel-trendlines")==="true");l.useEffect(()=>{localStorage.setItem("statistics-channel-trendlines",Z.toString())},[Z]);const pe=[{label:"Wardrivers",channels:["wardrive","wardriving"],color:"var(--sys-red)"},{label:"Bots",channels:["volcano","meshai","bot","ai-bot","emergency","meshbud","test"],color:"#991B1B"}],J=l.useMemo(()=>({0:0,1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9})[h]??3,[h]),O=Xe[J].hours,Q=ps(O),de=O*60,C=Xe[J],z=ut(O),B=i.isBackgroundLoading,L=l.useCallback(A=>{const $e={0:1,1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10}[A]??4;d($e)},[d]),$=l.useMemo(()=>{var te;if(!((te=t==null?void 0:t.config)!=null&&te.radio))return null;const A=t.config.radio;return{sf:A.spreading_factor??10,bw:A.bandwidth??25e4,cr:A.coding_rate??5,preamble:A.preamble_length??8}},[(R=(D=t==null?void 0:t.config)==null?void 0:D.radio)==null?void 0:R.spreading_factor,(ne=(P=t==null?void 0:t.config)==null?void 0:P.radio)==null?void 0:ne.bandwidth,(K=(ae=t==null?void 0:t.config)==null?void 0:ae.radio)==null?void 0:K.coding_rate,(re=(ee=t==null?void 0:t.config)==null?void 0:ee.radio)==null?void 0:re.preamble_length]);l.useEffect(()=>{Rt(O).then(A=>{A.success&&A.data?w(A.data.history.map(te=>te.timestamp)):w([])})},[O]);const V=l.useMemo(()=>Q.length===0?{timestamps:[],values:[]}:{timestamps:Q.map(A=>A.timestamp),values:Q.map(A=>A.noise_floor_dbm)},[Q]),S=l.useMemo(()=>{if(Q.length<10)return{anomalies:[],debug:void 0};const A=zs(Q,c);return{anomalies:A.anomalies,debug:A.debug}},[Q,c]),F=S.anomalies,W=l.useMemo(()=>{const A=(t==null?void 0:t.neighbors)??{};return Object.fromEntries(Object.entries(A).filter(([te])=>!s.has(te)))},[t==null?void 0:t.neighbors,s]),ue=l.useMemo(()=>{const A=Date.now()/1e3-O*3600;return Object.fromEntries(Object.entries(W).filter(([,te])=>te.last_seen>=A))},[W,O]),xe=l.useMemo(()=>{const A=de*60/z,te=Math.floor(Date.now()/1e3),$e=Math.floor(te/A)*A;return{start:$e-de*60,end:$e}},[de,z]),ye=y.timeStart??xe.start,je=y.timeEnd??xe.end,ke=(je-ye)/3600,Fe=ut(ke),le=Ts(),u=l.useMemo(()=>As(a,y,le,xe),[a,y,le,xe]);return e.jsxs(Ns,{children:[e.jsx(ws,{title:"Statistics",icon:e.jsx(fs,{}),subtitle:e.jsx(Rs,{}),controls:e.jsx(vs,{ranges:Xe,selectedIndex:J,onSelect:L,isPending:B})}),j&&e.jsx(be,{className:"border border-sys-red/50 bg-sys-red/10",children:e.jsx("p",{className:"text-sys-red",children:j})}),Y&&N&&e.jsxs(be,{className:"border border-sys-indigo/30 bg-surface/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"type-label",children:"Anomaly Detection Tuning"}),e.jsxs("span",{className:"type-data-xs text-fg-muted",children:["(",C.label,")"]})]}),e.jsx("button",{onClick:()=>g(A=>({...A,useAbsoluteThresholds:!A.useAbsoluteThresholds})),className:`type-data-xs px-2 py-1 rounded transition-colors ${c.useAbsoluteThresholds?"bg-sys-indigo/30 text-sys-indigo":"bg-elevated text-fg-muted hover:text-fg-secondary"}`,children:c.useAbsoluteThresholds?"Absolute dBm":"Percentile"})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"type-micro",children:"Baseline"}),e.jsxs("span",{className:"ml-2 type-data-sm text-status-warning",children:[((fe=(me=S.debug)==null?void 0:me.baselineCutoff)==null?void 0:fe.toFixed(1))??"—"," dBm"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"type-micro",children:"Spike"}),e.jsxs("span",{className:"ml-2 type-data-sm text-status-warning",children:[((ve=(ce=S.debug)==null?void 0:ce.spikeCutoff)==null?void 0:ve.toFixed(1))??"—"," dBm"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"type-micro",children:"Mid-band"}),e.jsx("span",{className:"ml-2 type-data-sm text-sys-indigo",children:((Ne=S.debug)==null?void 0:Ne.midBandSamples)??0})]}),e.jsxs("div",{children:[e.jsx("span",{className:"type-micro",children:"Anomalies"}),e.jsx("span",{className:"ml-2 type-data-sm text-status-danger",children:F.length})]})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-edge-subtle space-y-4",children:[c.useAbsoluteThresholds?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Baseline (",c.baselineDbm," dBm)"]}),e.jsx("input",{type:"range",min:"-120",max:"-60",value:c.baselineDbm,onChange:A=>g(te=>({...te,baselineDbm:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Spike (",c.spikeDbm," dBm)"]}),e.jsx("input",{type:"range",min:"-100",max:"-20",value:c.spikeDbm,onChange:A=>g(te=>({...te,spikeDbm:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Merge Gap (",c.mergeGapSeconds,"s)"]}),e.jsx("input",{type:"range",min:"5",max:"120",step:"5",value:c.mergeGapSeconds,onChange:A=>g(te=>({...te,mergeGapSeconds:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Min Sequence (",c.minSequenceLength,")"]}),e.jsx("input",{type:"range",min:"2",max:"20",value:c.minSequenceLength,onChange:A=>g(te=>({...te,minSequenceLength:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Similarity (±",c.similarityToleranceDbm," dBm)"]}),e.jsx("input",{type:"range",min:"1",max:"15",value:c.similarityToleranceDbm,onChange:A=>g(te=>({...te,similarityToleranceDbm:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Opacity (",Math.round(I*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:I,onChange:A=>U(Number(A.target.value)),className:"w-full accent-sys-indigo"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Baseline (P",c.baselinePercentile,")"]}),e.jsx("input",{type:"range",min:"1",max:"50",value:c.baselinePercentile,onChange:A=>g(te=>({...te,baselinePercentile:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Spike (P",c.spikePercentile,")"]}),e.jsx("input",{type:"range",min:"50",max:"99",value:c.spikePercentile,onChange:A=>g(te=>({...te,spikePercentile:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Merge Gap (",c.mergeGapSeconds,"s)"]}),e.jsx("input",{type:"range",min:"5",max:"120",step:"5",value:c.mergeGapSeconds,onChange:A=>g(te=>({...te,mergeGapSeconds:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Min Sequence (",c.minSequenceLength,")"]}),e.jsx("input",{type:"range",min:"2",max:"20",value:c.minSequenceLength,onChange:A=>g(te=>({...te,minSequenceLength:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Similarity (±",c.similarityToleranceDbm," dBm)"]}),e.jsx("input",{type:"range",min:"1",max:"15",value:c.similarityToleranceDbm,onChange:A=>g(te=>({...te,similarityToleranceDbm:Number(A.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Opacity (",Math.round(I*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:I,onChange:A=>U(Number(A.target.value)),className:"w-full accent-sys-indigo"})]})]})]}),e.jsxs("div",{className:"mt-4 p-3 bg-elevated radius-inner",children:[e.jsx("div",{className:"type-micro mb-1",children:"Config output"}),e.jsxs("div",{className:"type-data-sm text-status-success",children:[c.useAbsoluteThresholds?`useAbsoluteThresholds: true, baselineDbm: ${c.baselineDbm}, spikeDbm: ${c.spikeDbm}`:`useAbsoluteThresholds: false, baselinePercentile: ${c.baselinePercentile}, spikePercentile: ${c.spikePercentile}`,", mergeGapSeconds: ",c.mergeGapSeconds,", minSequenceLength: ",c.minSequenceLength,", similarityToleranceDbm: ",c.similarityToleranceDbm]})]})]})]}),e.jsxs(ks,{ready:x,children:[e.jsx("div",{className:"sm:hidden",children:B&&e.jsx(Ae,{template:"auto",children:e.jsx(be,{className:"border border-sys-blue/30 bg-sys-blue/5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex h-3 w-3",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-sys-blue opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-sys-blue"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"type-body-sm text-fg-primary",children:["Loading ",C.label," data..."]}),i.loadProgress&&e.jsxs("p",{className:"type-data-xs text-fg-muted mt-0.5",children:[i.loadProgress.loaded.toLocaleString()," packets (",i.loadProgress.percent,"%)"]})]})]})})})}),e.jsxs(e.Fragment,{children:[e.jsx(Ae,{template:"hero-auto",children:e.jsx(be,{neomorphic:!0,skeletonType:"chart",children:x&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{icon:e.jsx(De,{}),title:"Packet Analyzer",badge:C.label,badgeColor:"zinc",stackActionsOnMobile:!0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:[T==="stats"&&e.jsx(ln,{enabled:Y,onChange:H,anomalyCount:F.length,showTuning:N,onTuningChange:v}),(T==="ema"||T==="ultra")&&M==="airtime"&&e.jsx(on,{enabled:Z,onChange:oe,channelName:pe.map(A=>A.label).join(" & ")}),e.jsx(rn,{smoothing:T,onChange:X}),e.jsx(an,{mode:M,onChange:_})]})}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Nn,{packets:u,allPackets:a,startTs:ye,endTs:je,parentStartTs:xe.start,parentEndTs:xe.end,bucketCount:Fe,radioConfig:$??void 0,mode:M,smoothing:T,noiseFloorAnomalies:F,showNoiseFloorOverlay:Y,overlayOpacity:I,dotSize:q,dotOpacity:se/100,showChannelTrendlines:Z,channelGroups:pe})})]})})}),e.jsx(Ae,{template:"auto",className:"relative z-10",children:e.jsx(be,{neomorphic:!0,noPadding:!0,className:"overflow-visible",children:x&&e.jsx(_s,{parentStartTs:xe.start,parentEndTs:xe.end,neighbors:W,filter:y,onChange:E,...T==="stats"?{scatterDotSize:q,onScatterDotSizeChange:ie,scatterOpacity:se,onScatterOpacityChange:G}:{}})})}),e.jsxs(Ae,{template:"panel",children:[e.jsx(Le,{span:12,md:6,children:e.jsx(be,{neomorphic:!1,skeletonType:"chart",noPadding:x,className:"!bg-transparent !ring-0 !shadow-none !overflow-visible -mx-4 sm:mx-0 !px-0 !pr-0",children:x&&e.jsx(it,{children:e.jsx(Tn,{neighbors:ue,quickNeighbors:n,localLat:((Be=(He=t==null?void 0:t.config)==null?void 0:He.repeater)==null?void 0:Be.latitude)??0,localLon:((Ce=(Me=t==null?void 0:t.config)==null?void 0:Me.repeater)==null?void 0:Ce.longitude)??0,onStatsChange:f,title:"Link Quality",badge:C.label})})})}),e.jsx(Le,{span:12,md:6,children:e.jsx(be,{neomorphic:!0,skeletonType:"chart",children:x&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{icon:e.jsx(Is,{}),title:"Network Composition",badge:C.label,badgeColor:"zinc"}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(it,{children:e.jsx(In,{neighbors:ue,timeRangeLabel:C.label})})})]})})})]}),e.jsxs(Ae,{template:"panel",children:[e.jsx(Le,{span:12,md:6,children:e.jsx(Un,{})}),e.jsx(Le,{span:12,md:6,children:e.jsx(Vn,{packets:a,rangeMinutes:de,rangeHours:O,timeRangeLabel:C.label})})]}),e.jsx(Ae,{template:"panel",children:e.jsx(Le,{span:12,children:e.jsx(be,{neomorphic:!0,skeletonType:"chart",children:x&&e.jsxs(e.Fragment,{children:[e.jsx(Ee,{icon:e.jsx(gs,{}),title:"NOISE FLOOR dBm",stackActionsOnMobile:!0,actions:b?e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsxs("span",{className:"type-data-xs text-fg-muted whitespace-nowrap",children:["min ",e.jsx("span",{className:"data-box",children:b.min.toFixed(0)})]}),e.jsxs("span",{className:"type-data-xs text-fg-muted whitespace-nowrap",children:["avg ",e.jsx("span",{className:"data-box",children:b.avg.toFixed(0)})]}),e.jsxs("span",{className:"type-data-xs text-fg-muted whitespace-nowrap",children:["max ",e.jsx("span",{className:"data-box",children:b.max.toFixed(0)})]})]}):null}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(it,{children:e.jsx(ys,{timestamps:V.timestamps,values:V.values,onStatsChange:k,crcTimestamps:p})})})]})})})})]})]})]})}export{Sa as default};
