var _t=Object.defineProperty;var Rt=(t,s,n)=>s in t?_t(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var xe=(t,s,n)=>Rt(t,typeof s!="symbol"?s+"":s,n);import{d as He,r as c,j as e,t as Ce,c as it,bg as Nt,c9 as vt,ca as tt,h as ke,cb as Tt,x as Ae,cc as Dt,cd as Et,ce as Lt,k as It,cf as Pt,cg as Ot,ch as Ft,ci as Ht,cj as Bt,bI as $t,ck as $e,bL as zt,cl as Wt,cm as Ut,N as ve,cn as Gt,co as Vt,cp as qt,bi as Kt,K as Yt,Q as Xt,P as Zt,G as Qt,ao as Jt,ap as es,V as ts,ai as ss,cq as ns,cr as ze,cs as rt,aa as as,R as is,a4 as rs}from"./index-CeMilrX4.js";import{L as Se}from"./layers-DVUHhJuY.js";import{u as st,h as ls,r as nt}from"./consumer-registry-Hkh6Dv_i.js";import{C as We,e as os}from"./easing-CFZ7-xae.js";import{T as cs,M as ms}from"./MqttModeBadge-C_MEMmDd.js";import{C as de,P as ds,a as us,B as hs}from"./PageLayout-Cw_MXmcE.js";import{D as xs}from"./DataBox-Da-5DbUW.js";import{E as ps,A as Fe,D as Pe}from"./DataValue-BDllMDjE.js";import{C as fs}from"./CollisionExplorerModal-Cvw_f8a6.js";import{H as lt}from"./hash-CBEVBQJR.js";import{T as Je}from"./triangle-alert-DiFold9L.js";import{L as Ue}from"./LightSparkline-D652BQd5.js";import{A as gs}from"./activity-BZFnO4kb.js";import{c as bs,a as ys,A as js}from"./AnalyzerFilterPanel-DoQoJv94.js";import{useResolveSource as Ns}from"./usePipelineStore-B80TA53S.js";import{R as ye,C as Me}from"./Grid-BuDgMX1I.js";import{S as vs}from"./settings-2-97rHsI_C.js";import{N as ks}from"./network-c_XxfhAX.js";import"./chevron-right-D3QL4sfa.js";import"./map-pin-D6_BkIVb.js";import"./index-BK59_Mkt.js";import"./BasemapLayer-CNBmoufo.js";import"./monitor-smartphone-DxkmIgui.js";import"./node-types-C09ZlzBQ.js";import"./circle-question-mark-Bqc_DPUo.js";import"./funnel-D2SUJQ8o.js";import"./search-Bph9xP9G.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 Ss=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],ws=He("chart-line",Ss);/**
 * @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 Ms=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],ot=He("circle-check-big",Ms);/**
 * @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 Cs=[["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"}]],As=He("grid-3x3",Cs);/**
 * @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 _s=[["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"}]],Rs=He("grip",_s),kt={useAbsoluteThresholds:!0,baselinePercentile:6,spikePercentile:50,baselineDbm:-107,spikeDbm:-100,mergeGapSeconds:45,minSequenceLength:16,similarityToleranceDbm:5};function Ne(t,s){if(t.length===0)return 0;const n=s/100*(t.length-1),a=Math.floor(n),i=Math.ceil(n);return a===i?t[a]:t[a]+(t[i]-t[a])*(n-a)}function ct(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:Ne(s,50),p90:Ne(s,90),p95:Ne(s,95),p99:Ne(s,99),max:s[s.length-1],min:s[0]}}function Ts(t,s={}){const n={...kt,...s};if(t.length<10)return{anomalies:[],thresholds:ct([]),totalSamples:t.length,anomalySamples:0};const a=t.map(y=>y.noise_floor_dbm),i=ct(a),r=[...a].sort((y,v)=>y-v);let l,u;n.useAbsoluteThresholds?(l=n.baselineDbm,u=n.spikeDbm):(l=Ne(r,n.baselinePercentile),u=Ne(r,n.spikePercentile));const o=[...t].sort((y,v)=>y.timestamp-v.timestamp),p=[];let m=null,x=0;for(const y of o)if(y.noise_floor_dbm>l&&y.noise_floor_dbm<u)if(x++,!m)m={startTs:y.timestamp,endTs:y.timestamp,values:[y.noise_floor_dbm],timestamps:[y.timestamp],rollingAvg:y.noise_floor_dbm};else{const N=Math.abs(y.noise_floor_dbm-m.rollingAvg)<=n.similarityToleranceDbm,R=y.timestamp-m.endTs<=n.mergeGapSeconds;N&&R?(m.endTs=y.timestamp,m.values.push(y.noise_floor_dbm),m.timestamps.push(y.timestamp),m.rollingAvg=m.values.reduce((O,B)=>O+B,0)/m.values.length):(m.values.length>=n.minSequenceLength&&p.push(m),m={startTs:y.timestamp,endTs:y.timestamp,values:[y.noise_floor_dbm],timestamps:[y.timestamp],rollingAvg:y.noise_floor_dbm})}else m&&m.values.length>=n.minSequenceLength&&p.push(m),m=null;return m&&m.values.length>=n.minSequenceLength&&p.push(m),p.length===0?{anomalies:[],thresholds:i,totalSamples:t.length,anomalySamples:x,debug:{baselineCutoff:l,spikeCutoff:u,midBandSamples:x}}:{anomalies:p.map(y=>{const v=Math.max(...y.values),j=y.values.reduce((N,R)=>N+R,0)/y.values.length;return{startTs:y.startTs,endTs:y.endTs,peakValue:v,avgValue:j,severity:Ds(j,l,u),sampleCount:y.values.length}}),thresholds:i,totalSamples:t.length,anomalySamples:x,debug:{baselineCutoff:l,spikeCutoff:u,midBandSamples:x}}}function Ds(t,s,n){const a=n-s;if(a===0)return"moderate";const i=(t-s)/a;return i>.66?"critical":i>.33?"severe":"moderate"}const Es=Object.entries(Nt).map(([t,s])=>{const n=parseInt(t,10);return{typeNum:n,key:`TYPE_${n}`,label:s}});function at({sortedTypes:t,highlightedType:s,onTypeHover:n,aggregateShares:a,hoverData:i}){const r=c.useMemo(()=>{if(!i)return null;const o=new Map;for(const p of i.items)o.set(p.key,p.value);return o},[i]),l=r!==null,u=c.useMemo(()=>{const o=new Set(t.map(x=>x.key)),p=t.map(x=>({typeNum:x.typeNum,key:x.key,label:x.label})),m=Es.filter(x=>!o.has(x.key));return[...p,...m]},[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"}),l&&(i==null?void 0:i.timeLabel)&&e.jsx("span",{className:"text-sys-indigo tabular-nums",children:i.timeLabel})]}),e.jsx("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:u.map(o=>{const p=Ce(o.typeNum),m=(r==null?void 0:r.get(o.key))??0,x=a.get(o.key)??0,S=l?m:x,y=S>1e-4,v=a.has(o.key),j=s===o.key,N=s&&!j||l&&m<=1e-4||!l&&!s&&!v;return e.jsxs("div",{className:it("flex items-center gap-1.5 transition-opacity cursor-pointer hover:opacity-80",N&&"opacity-30"),onMouseEnter:()=>n(o.key),children:[e.jsx("div",{className:"shrink-0 w-3 h-3 rounded-xs",style:{backgroundColor:p}}),e.jsx("span",{className:"text-fg-secondary whitespace-nowrap",children:o.label}),y&&e.jsxs("span",{className:it("tabular-nums",l?"text-fg-primary":"text-fg-muted"),children:[(S*100).toFixed(1),"%"]})]},o.key)})})]})}const mt='ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',Ls=2,Is=3,Ps=32,Os=20,Fs=80;function dt(t,s,n,a,i){const r=t.reduce((p,m)=>p+m,0);if(r<=0||t.length===0)return[];const l=t.map((p,m)=>m).sort((p,m)=>t[m]-t[p]),u=l.map(p=>t[p]),o=new Array(t.length);return et(u,l,r,s,n,a,i,o),o}function et(t,s,n,a,i,r,l,u){if(t.length===0)return;if(t.length===1){u[s[0]]={x:a,y:i,w:r,h:l,index:s[0]};return}const o=r*l/n,p=r>=l,m=p?l:r;let x=0,S=1/0,y=0;for(let B=0;B<t.length;B++){const M=x+t[B],z=M*o/m;if(z<=0){y=B+1,x=M;continue}const E=t[0]*o/z,g=t[B]*o/z,d=Math.max(E>z?E/z:z/E,g>z?g/z:z/g);if(d<=S)S=d,y=B+1,x=M;else break}const v=m>0?x*o/m:0;let j=0;for(let B=0;B<y;B++){const z=(x>0?t[B]/x:0)*m;p?u[s[B]]={x:a,y:i+j,w:v,h:z,index:s[B]}:u[s[B]]={x:a+j,y:i,w:z,h:v,index:s[B]},j+=z}const N=t.slice(y),R=s.slice(y),O=n-x;p?et(N,R,O,a+v,i,r-v,l,u):et(N,R,O,a,i+v,r,l-v,u)}function ut(t,s,n,a,i,r){for(const l of s){const u=n[l.index];if(!u)continue;const o=Ls*r,p=l.x*r+o/2,m=l.y*r+o/2,x=l.w*r-o,S=l.h*r-o;if(x<=0||S<=0)continue;const y=Ce(u.typeNum),v=i!==null&&i!==l.index;t.save(),t.globalAlpha=v?.4:1;const j=Is*r;t.beginPath(),t.moveTo(p+j,m),t.lineTo(p+x-j,m),t.quadraticCurveTo(p+x,m,p+x,m+j),t.lineTo(p+x,m+S-j),t.quadraticCurveTo(p+x,m+S,p+x-j,m+S),t.lineTo(p+j,m+S),t.quadraticCurveTo(p,m+S,p,m+S-j),t.lineTo(p,m+j),t.quadraticCurveTo(p,m,p+j,m),t.closePath(),t.fillStyle=y,t.fill(),t.strokeStyle="rgba(0,0,0,0.2)",t.lineWidth=1*r,t.stroke();const N=4*r,R=l.w>36&&l.h>20,O=l.w>36&&l.h>32;if(R){const B=11*r;if(O){const M=a>0?u.size/a*100:0;t.font=`500 ${8*r}px ${mt}`,t.fillStyle="rgba(0,0,0,0.6)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(`${M.toFixed(1)}%`,p+N,m+S-N-B)}t.font=`600 ${9*r}px ${mt}`,t.fillStyle="rgba(0,0,0,0.85)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(u.name,p+N,m+S-N)}t.restore()}}function Hs(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 Bs({data:t,total:s,color:n,position:a,containerWidth:i,isAirtime:r}){if(!t||!a)return null;const l=(t.value/s*100).toFixed(1),u=160,m=i-a.x<u+24?Math.max(8,a.x-u-8):a.x+16;return e.jsx("div",{className:"absolute z-50 pointer-events-none",style:{left:m,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:r?"Airtime":"Count"}),e.jsx("span",{className:"text-fg-primary tabular-nums font-medium",children:r?ht(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:[l,"%"]})]}),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:r?ht(s):s.toLocaleString()})]})]})]})})}function ht(t){return t>=6e4?`${(t/6e4).toFixed(1)}m`:t>=1e3?`${(t/1e3).toFixed(1)}s`:`${Math.round(t)}ms`}function $s({sortedTypes:t,aggregateShares:s,mode:n="share"}){var E,g,d;const[a,i]=c.useState(null),[r,l]=c.useState(null),[u,o]=c.useState(0),[p,m]=c.useState(null),x=c.useRef(null),S=c.useRef(null),y=c.useRef([]),v=n==="airtime",j=c.useMemo(()=>t.reduce((f,k)=>f+(v?k.totalAirtime:k.totalCount),0),[t,v]),N=c.useMemo(()=>t.map((f,k)=>({name:f.label,size:v?f.totalAirtime:f.totalCount,index:k,typeNum:f.typeNum,key:f.key})),[t,v]);c.useEffect(()=>{const f=S.current;if(!f)return;const k=f.parentElement;if(!k)return;const I=k.getBoundingClientRect(),W=I.width,D=I.height;if(W<=0||D<=0)return;const U=window.devicePixelRatio||1;f.width=Math.floor(W*U),f.height=Math.floor(D*U),f.style.width=`${W}px`,f.style.height=`${D}px`;const q=N.map(G=>G.size),ee=dt(q,0,0,W,D);y.current=ee;const J=f.getContext("2d");J&&(J.clearRect(0,0,f.width,f.height),ut(J,ee,N,j,a,U))},[N,j,a]),c.useEffect(()=>{const f=x.current;if(!f)return;const k=new ResizeObserver(()=>{const I=S.current;if(!I)return;const W=f.getBoundingClientRect(),D=W.width,U=W.height;if(D<=0||U<=0)return;const q=window.devicePixelRatio||1;I.width=Math.floor(D*q),I.height=Math.floor(U*q),I.style.width=`${D}px`,I.style.height=`${U}px`;const ee=N.map(L=>L.size),J=dt(ee,0,0,D,U);y.current=J;const G=I.getContext("2d");G&&(G.clearRect(0,0,I.width,I.height),ut(G,J,N,j,a,q))});return k.observe(f),()=>k.disconnect()},[N,j]);const R=c.useCallback(f=>{const k=x.current;if(!k)return;const I=k.getBoundingClientRect(),W=f.clientX-I.left,D=f.clientY-I.top,U=Hs(y.current,W,D);i(U),U!==null?(o(I.width),l({x:W,y:D})):l(null)},[]),O=c.useCallback(()=>{i(null),l(null)},[]),B=c.useCallback(f=>{if(m(f),f){const k=N.findIndex(I=>I.key===f);i(k>=0?k:null)}else i(null)},[N]),M=a!==null?{name:((E=N[a])==null?void 0:E.name)??"",value:((g=N[a])==null?void 0:g.size)??0}:null,z=a!==null?Ce((d=N[a])==null?void 0:d.typeNum):"";return t.length===0||j===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(Se,{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:Ps,right:0,top:0,bottom:Os},ref:x,onMouseMove:R,onMouseLeave:O,children:[e.jsx("canvas",{ref:S,className:"absolute inset-0",style:{cursor:"default"}}),e.jsx(Bs,{data:M,total:j,color:z,position:r,containerWidth:u,isAirtime:v})]})}),e.jsx("div",{style:{minHeight:Fs},children:e.jsx(at,{sortedTypes:t,highlightedType:p,onTypeHover:B,aggregateShares:s})})]})}const Ge=32,Ve=20,zs=300;function je(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 Ws({packets:t,mode:s,startTs:n,endTs:a,radioConfig:i,bucketCount:r,lockedYMax:l,legendMinH:u}){const o=c.useMemo(()=>vt(),[]),p=o.blue,m=o.red,x=o.yellow,[S,y]=c.useState(null),{trendData:v,totals:j}=c.useMemo(()=>{if(t.length===0)return{trendData:[],totals:{rxBytes:0,txBytes:0,rxAirtime:0,txAirtime:0}};const g=a-n,d=Math.min(Math.ceil(g/zs),r),f=g/d,k=[];let I=0,W=0,D=0,U=0;for(const $ of t){const b=$.timestamp;if(b<n||b>=a)continue;const w=tt($),A=ke($,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble}),F={timestamp:b,rxAirtime:0,txAirtime:0,rxBytes:0,txBytes:0};$.transmitted?(F.txAirtime=A,F.txBytes=w,W+=w,U+=A):(F.rxAirtime=A,F.rxBytes=w,I+=w,D+=A),k.push(F)}k.sort(($,b)=>$.timestamp-b.timestamp);const q=new Float64Array(k.length+1),ee=new Float64Array(k.length+1),J=new Float64Array(k.length+1),G=new Float64Array(k.length+1),L=new Float64Array(k.length);for(let $=0;$<k.length;$++)q[$+1]=q[$]+k[$].rxAirtime,ee[$+1]=ee[$]+k[$].txAirtime,J[$+1]=J[$]+k[$].rxBytes,G[$+1]=G[$]+k[$].txBytes,L[$]=k[$].timestamp;const K=$=>{let b=0,w=L.length;for(;b<w;){const A=b+w>>>1;L[A]<$?b=A+1:w=A}return b},te=[],ie=f*1e3;for(let $=0;$<d;$++){const b=n+$*f,w=b+f,A=K(b),F=K(w);if(s==="share"){const Z=J[F]-J[A],ue=G[F]-G[A];te.push({timestamp:b,rx:Z>0?Z:null,tx:ue>0?ue:null})}else{const Z=q[F]-q[A],ue=ee[F]-ee[A],pe=Z/ie*100,fe=ue/ie*100;te.push({timestamp:b,rx:pe>0?pe:null,tx:fe>0?fe:null})}}const ae=2/31;let se=null;return{trendData:te.map($=>{const b=$.rx;return b!==null&&b>0&&(se===null?se=b:se=ae*b+(1-ae)*se),{...$,rxSmooth:se!==null&&se>0?se:null}}),totals:{rxBytes:I,txBytes:W,rxAirtime:D,txAirtime:U}}},[t,n,a,r,s,i]),N=c.useMemo(()=>{if(v.length===0)return s==="share"?100:10;let g=0;for(const f of v){const k=f.rx??0,I=f.tx??0;k>g&&(g=k),I>g&&(g=I)}const d=g*1.1;return s==="share"?d<=100?100:d<=500?Math.ceil(d/100)*100:d<=1e3?Math.ceil(d/200)*200:d<=5e3?Math.ceil(d/500)*500:d<=1e4?Math.ceil(d/1e3)*1e3:Math.ceil(d/5e3)*5e3:Math.max(1,Math.ceil(d))},[v,s]),R=l??N,O=c.useMemo(()=>{if(S!==null&&v[S]){const g=v[S],d=g.rx??0,f=g.tx??0;return s==="share"?{rx:je(d),tx:je(f),total:je(d+f),isHovered:!0}:{rx:`${d.toFixed(2)}%`,tx:`${f.toFixed(2)}%`,total:`${(d+f).toFixed(2)}%`,isHovered:!0}}if(s==="share")return{rx:je(j.rxBytes),tx:je(j.txBytes),total:je(j.rxBytes+j.txBytes),isHovered:!1};{let g=0,d=0,f=0;for(const W of v)(W.rx!==null||W.tx!==null)&&(g+=W.rx??0,d+=W.tx??0,f++);const k=f>0?g/f:0,I=f>0?d/f:0;return{rx:`${k.toFixed(2)}%`,tx:`${I.toFixed(2)}%`,total:`${(k+I).toFixed(2)}%`,isHovered:!1}}},[S,v,j,s]),B=c.useMemo(()=>{const g=a-n,d=g/3600;return[0,.25,.5,.75,1].map(k=>{const I=n+g*k,W=new Date(I*1e3),D=W.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),U=W.toLocaleDateString([],{weekday:"short"}),q=k===.25||k===.75;return{pct:k,label:d>=24?`${U} ${D}`:D,mobileHidden:q}})},[n,a]),M=c.useCallback(g=>{y(g)},[]);if(v.length===0)return e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(Se,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet data available"})]});const z=c.useMemo(()=>s==="airtime"?R<=5?1:R<=10?2:R<=20?5:Math.ceil(R/5):R<=100?25:R<=500?100:R<=1e3?200:R<=5e3?1e3:R<=1e4?2e3:Math.ceil(R/5e3)*1e3,[R,s]),E=c.useMemo(()=>{const g=[];for(let d=0;d<=R;d+=z){const f=(1-d/R)*100;let k;s==="airtime"?k=`${d}%`:d>=1e6?k=`${(d/1e6).toFixed(1)}M`:d>=1e3?k=`${(d/1e3).toFixed(0)}K`:k=`${d}`,g.push({pos:f,label:k})}return g},[R,z,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:Ge,bottom:Ve},children:E.map((g,d)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${g.pos}%`,transform:d===0?"translateY(-100%)":d===E.length-1?"none":"translateY(-50%)",right:0},children:g.label},d))}),e.jsx("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:Ge,right:0,top:0,bottom:Ve},children:e.jsx(Tt,{data:v,yAxisMode:s==="share"?"share":"airtime",yMax:R,onHover:M,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:Ge,height:Ve,paddingTop:4},children:B.map((g,d)=>e.jsx("span",{className:`absolute type-data-xs text-fg-muted/60 tabular-nums ${g.mobileHidden?"hidden sm:inline":""}`,style:{left:`${g.pct*100}%`,transform:g.pct===0?"translateX(0)":g.pct===1?"translateX(-100%)":"translateX(-50%)"},children:g.label},d))})]}),e.jsxs("div",{className:"flex items-end justify-between pb-1",style:{minHeight:u},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:p}}),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:m}}),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:x}}),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:O.rx}),e.jsx(Ae,{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:O.tx}),e.jsx(Ae,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"TX"})]})]})]})]})}const xt=Dt;class Us{constructor(){xe(this,"worker",null);xe(this,"listeners",new Set);xe(this,"currentResult",null);xe(this,"isComputing",!1);xe(this,"debounceTimer",null);xe(this,"debounceMs",250);xe(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,i,r){if(s.length===0||!r){this.currentResult=null,this.notifyListeners();return}const l={startTs:n,endTs:a,mode:i,packetCount:s.length};this.isCacheHit(l)||(this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.computeInternal(s,n,a,i,r,l)},this.debounceMs))}computeInternal(s,n,a,i,r,l){const u=this.ensureWorker();if(!u)return;const o=s.length,p=new Float64Array(o),m=new Float64Array(o),x=new Uint16Array(o),S=new Uint8Array(o),y={spreadingFactor:r.sf,bandwidthHz:r.bw,codingRate:r.cr,preambleLength:r.preamble};for(let j=0;j<o;j++){const N=s[j];p[j]=N.timestamp??0,S[j]=(N.type??N.payload_type??255)&255,x[j]=Math.min(tt(N),65535),i==="airtime"?m[j]=ke(N,y):m[j]=1}this.isComputing=!0,this.lastCacheKey=l,this.notifyListeners();const v={type:"compute",payload:{timestamps:p,airtimeMs:m,byteSizes:x,packetTypes:S,startTs:n,endTs:a,mode:i}};u.postMessage(v,[p.buffer,m.buffer,x.buffer,S.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 qe=new Us;function Gs(t,s,n,a,i){const[r,l]=c.useState(()=>qe.getResult());return c.useEffect(()=>qe.subscribe(u=>{l(u)}),[]),c.useEffect(()=>{qe.compute(t,s,n,a,i)},[t,s,n,a,i]),r}function Vs({mode:t,packets:s,startTs:n,endTs:a,radioConfig:i,sortedTypes:r,aggregateShares:l,noiseFloorAnomalies:u,showNoiseFloorOverlay:o,overlayOpacity:p=.5,startLabel:m,endLabel:x,lockedYMax:S,legendMinH:y,dotSize:v,dotOpacity:j}){const[N,R]=c.useState(null),[O,B]=c.useState(null),M=c.useMemo(()=>(a-n)/3600,[n,a]),z=c.useCallback(G=>{B(G)},[]),g=Gs(s,n,a,t==="share"?"share":"airtime",i),[d,f]=c.useState(null),k=c.useCallback((G,L)=>{R(G),f(L??null)},[]),I=c.useMemo(()=>{if(d===null||!g||g.count===0)return null;const G=n+d*(a-n);let L;M>=168?L=75:M>=72?L=35:M>=24?L=15:M>=3?L=10:L=5;const K=L*60/2;return{start:G-K,end:G+K}},[d,g,n,a,M]),W=c.useMemo(()=>I?new Date((I.start+I.end)/2*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}):null,[I]),D=c.useMemo(()=>{if(N===null||!I)return null;const G=W??"",{start:L,end:K}=I,te=s.filter(b=>b.timestamp>=L&&b.timestamp<K);if(te.length===0)return{timestamp:(L+K)/2,timeLabel:G,items:r.map(b=>({key:b.key,label:b.label,value:0,color:xt(b.typeNum)}))};const ie=new Map,ae=new Map;let se=0,oe=0;for(const b of te){const A=`TYPE_${b.type??b.payload_type??-1}`;if(ie.set(A,(ie.get(A)??0)+1),se++,i){const F=ke(b,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble});ae.set(A,(ae.get(A)??0)+F),oe+=F}}const $=r.map(b=>{let w;return t==="airtime"?w=oe>0?(ae.get(b.key)??0)/oe:0:w=se>0?(ie.get(b.key)??0)/se:0,{key:b.key,label:b.label,value:w,color:xt(b.typeNum)}});return{timestamp:(L+K)/2,timeLabel:G,items:$}},[N,I,W,s,r,t,i]),U=t==="share",q=S??(g==null?void 0:g.maxValue)??(U?240:10),ee=c.useMemo(()=>{if(!U)return 5;const G=[10,20,25,50,100,200,250,500,1e3],L=q/4.5;for(const K of G)if(K>=L)return K;return q>5e3?Math.ceil(L/1e3)*1e3:Math.ceil(L/100)*100},[q,U]),J=c.useMemo(()=>{const G=[];for(let L=0;L<=q;L+=ee){const K=(1-L/q)*100;G.push({pos:K,label:U?`${L}B`:`${L}%`})}return G},[q,ee,U]);return!g||g.count===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(Se,{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:J.map((G,L)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${G.pos}%`,transform:L===0?"translateY(-100%)":L===J.length-1?"none":"translateY(-50%)",right:0},children:G.label},L))}),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(Et,{scatterData:g,yAxisMode:t==="share"?"share":"airtime",onHover:k,noiseFloorAnomalies:u,showNoiseFloorOverlay:o,overlayOpacity:p,highlightedType:O,timeRangeHours:M,yAxisMaxOverride:S,dotSize:v,dotOpacity:j,startTs:n,endTs:a,externalAxes:!0}),W&&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:W})]}),m&&x&&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:m}),e.jsx("span",{children:x})]})]}),e.jsx("div",{style:{minHeight:y},children:e.jsx(at,{sortedTypes:r,highlightedType:O,onTypeHover:z,aggregateShares:l,hoverData:D})})]})}function qs({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 Ks({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(Rs,{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(ws,{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(Se,{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(Lt,{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(As,{className:"w-3.5 h-3.5"})})]})}function Ys({enabled:t,onChange:s,anomalyCount:n=0,showTuning:a=!1,onTuningChange:i}){return e.jsxs("div",{className:"relative inline-flex items-center gap-1",children:[t&&i&&e.jsx("button",{onClick:()=>i(!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(vs,{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(ps,{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})]})}const St=[{target:"PacketAnalyzer",fn:"type",minStage:1},{target:"PacketAnalyzer",fn:"airtime",minStage:1,when:ls}];nt(St);const pt=360,Xs=500,Zs={sf:10,bw:25e4,cr:5,preamble:8},Ke=32;function ft(t,s){const n=new Date(t*1e3),a=l=>l.toString().padStart(2,"0"),i=`${a(n.getHours())}:${a(n.getMinutes())}`;return s<24?i:`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][n.getMonth()]} ${n.getDate()} ${i}`}function Qs(t){return Nt[t]??`TYPE_${t.toString(16).toUpperCase()}`}function Js(t,s){const n=new Map;for(const i of t){const r=i.type??i.payload_type??-1,l=ke(i,{spreadingFactor:s.sf,bandwidthHz:s.bw,codingRate:s.cr,preambleLength:s.preamble}),u=n.get(r)??{count:0,airtime:0};n.set(r,{count:u.count+1,airtime:u.airtime+l})}const a=[];for(const[i,r]of n)a.push({typeNum:i,key:`TYPE_${i}`,label:Qs(i),totalCount:r.count,totalAirtime:r.airtime});return a.sort((i,r)=>r.totalCount-i.totalCount)}function en(t,s,n,a,i,r,l=0){const u=n-s,o=u/a,p=o*1e3,m=u/3600,x=s-l*o,S=n+l*o,y=a+2*l,v=[];for(let j=0;j<y;j++){const N=x+j*o,R=new Date(N*1e3),O=m>=24?R.toLocaleDateString([],{weekday:"short",hour:"2-digit",minute:"2-digit",hour12:!1}):R.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),B={timestamp:N,time:O,counts:{},shares:{},airtimes:{},total:0,totalAirtime:0,bucketDurationMs:p};for(const M of r)B.counts[M.key]=0,B.airtimes[M.key]=0;v.push(B)}for(const j of t){const N=j.timestamp;if(N<x||N>=S)continue;const R=Math.min(Math.floor((N-x)/o),y-1),O=`TYPE_${j.type??j.payload_type??-1}`;v[R].counts[O]=(v[R].counts[O]??0)+1,v[R].total++;const B=ke(j,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble});v[R].airtimes[O]=(v[R].airtimes[O]??0)+B,v[R].totalAirtime+=B}for(const j of v)for(const N of r)j.shares[N.key]=j.total>0?j.counts[N.key]/j.total*100:0;return{buckets:v,visibleStart:l,visibleEnd:l+a}}function tn(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 i=Math.floor(a);i%2===0&&i--;const r=i+2,l=(12*s*s-3*i*i-12*i-9)/(-4*i-4),u=Math.round(l),o=[u>0?i:r,u>1?i:r,u>2?i:r];let p=new Float32Array(t);const m=new Float32Array(n);for(const x of o){const S=(x-1)/2;sn(p,m,n,S);const y=p;p=m,m.set(y)}return Array.from(p)}function sn(t,s,n,a){const i=a*2+1;let r=0;for(let l=0;l<=a;l++)r+=t[Math.min(l,n-1)];for(let l=0;l<a;l++)r+=t[0];for(let l=0;l<n;l++){s[l]=r/i;const u=l-a,o=l+a+1;r-=t[Math.max(0,Math.min(u,n-1))],r+=t[Math.max(0,Math.min(o,n-1))]}}function nn(t,s){if(t.length===0)return[];if(s<=1)return[...t];const n=t.length,a=new Float32Array(n),i=Math.floor(s/2);let r=0,l=0;for(let u=0;u<=Math.min(i,n-1);u++)r+=t[u],l++;for(let u=0;u<n;u++){a[u]=r/l;const o=u-i,p=u+i+1;o>=0&&(r-=t[o],l--),p<n&&(r+=t[p],l++)}return Array.from(a)}const an={ema:1800,ultra:14400},rn={ema:"sma",ultra:"gaussian"};function wt(t,s,n){const a=an[t],i=rn[t]??"sma";if(!a)return{sigma:0,window:1,handleSize:0};let r=Math.round(a/s);r=Math.max(3,Math.min(r,Math.floor(n/3))),r%2===0&&(r+=1);const l=Math.ceil(i==="gaussian"?r*Math.sqrt(4/12)*3:r/2);return i==="gaussian"?{sigma:r*Math.sqrt(.3333333333333333),window:r,handleSize:l}:{sigma:0,window:r,handleSize:l}}function ln(t,s,n,a="ultra",i,r,l){var z;const{buckets:u,visibleStart:o,visibleEnd:p}=t,m=u.length,x=n.length,S=p-o;if(m===0||x===0)return[];const y=l&&i!==void 0&&r!==void 0?(r-i)/l:(z=u[0])!=null&&z.bucketDurationMs?u[0].bucketDurationMs/1e3:240,v=Array.from({length:x},()=>new Array(m).fill(0));for(let E=0;E<m;E++){const g=u[E];if(s==="share"){if(g.total>0)for(let d=0;d<x;d++)v[d][E]=(g.counts[n[d].key]??0)/g.total}else{let d=0;for(let f=0;f<x;f++)d+=g.airtimes[n[f].key]??0;if(d>0)for(let f=0;f<x;f++)v[f][E]=(g.airtimes[n[f].key]??0)/d}}const{sigma:j,window:N}=wt(a,y,S);let R;j>0?R=v.map(E=>tn(E,j)):R=v.map(E=>nn(E,N));for(let E=0;E<m;E++){let g=0;for(let d=0;d<x;d++)R[d][E]=Math.max(0,R[d][E]),g+=R[d][E];if(g>0){const d=1/g;for(let f=0;f<x;f++)R[f][E]*=d}}const O=S>pt?Math.ceil(S/pt):1,B=Math.ceil(S/O),M=[];for(let E=0;E<B;E++){const g=o+E*O,d=Math.min(o+(E+1)*O,p),f=d-g,k=new Array(x).fill(0);for(let D=g;D<d;D++)for(let U=0;U<x;U++)k[U]+=R[U][D];for(let D=0;D<x;D++)k[D]/=f;let I=0;for(let D=0;D<x;D++)I+=k[D];if(I>0){const D=1/I;for(let U=0;U<x;U++)k[U]*=D}const W={timestamp:u[g].timestamp,time:u[g].time};for(let D=0;D<x;D++)W[n[D].key]=k[D];M.push(W)}return M}const Ye=80;function on(t,s,n,a,i){const u=Math.max(1,Math.ceil((n-s)/300));if(a==="airtime"){const o=new Float64Array(u);for(const m of t){const x=m.timestamp;if(x<s||x>=n)continue;const S=Math.min(Math.floor((x-s)/300),u-1);o[S]+=ke(m,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble})}let p=0;for(let m=0;m<u;m++){const x=o[m]/3e5*100;x>p&&(p=x)}return Math.max(1,Math.ceil(p*1.1))}else{let o=0;for(const p of t){const m=p.timestamp;if(m<s||m>=n)continue;const x=tt(p);x>o&&(o=x)}return o<=240?240:Math.ceil(o*1.1/50)*50}}function cn({packets:t,allPackets:s,startTs:n,endTs:a,parentStartTs:i,parentEndTs:r,bucketCount:l,radioConfig:u=Zs,mode:o="share",smoothing:p="stats",noiseFloorAnomalies:m=null,showNoiseFloorOverlay:x=!1,overlayOpacity:S=.5,dotSize:y,dotOpacity:v}){st(St);const j=It(),[N,R]=c.useState(null),[O,B]=c.useState(null),[M,z]=c.useState([]),E=c.useRef(null),g=c.useRef(0);c.useEffect(()=>{const b=Math.abs(t.length-g.current);if(b===0&&M.length>0)return;E.current&&clearTimeout(E.current);const w=b>100?50:Xs;return E.current=setTimeout(()=>{g.current=t.length,z(t)},w),()=>{E.current&&clearTimeout(E.current)}},[t,M.length]);const d=c.useMemo(()=>Js(M,u),[M,u]),f=c.useMemo(()=>{if(p!=="ema"&&p!=="ultra")return 0;const w=(a-n)/l,{handleSize:A}=wt(p,w,l);return A},[p,n,a,l]),k=c.useMemo(()=>en(M,n,a,l,u,d,f),[M,n,a,l,u,d,f]),I=c.useMemo(()=>d.reduce((b,w)=>b+w.totalCount,0),[d]),W=c.useMemo(()=>d.reduce((b,w)=>b+w.totalAirtime,0),[d]),{sortedTypes:D,aggregateShares:U}=c.useMemo(()=>{const b=new Map,w=o==="share"?I:W;if(w>0)for(const F of d){const Z=o==="share"?F.totalCount:F.totalAirtime;b.set(F.key,Z/w)}return{sortedTypes:[...d].sort((F,Z)=>(b.get(Z.key)??0)-(b.get(F.key)??0)),aggregateShares:b}},[d,I,W,o]),q=c.useMemo(()=>ln(k,o,D,p,n,a,l),[k,o,D,p,n,a,l]),ee=c.useCallback(b=>R(b),[]),J=c.useCallback(b=>B(b),[]),G=c.useCallback(b=>R(b),[]),L=c.useMemo(()=>{if(O===null||!q[O])return null;const b=q[O];return{timestamp:b.timestamp,timeLabel:b.time,items:D.map(w=>({key:w.key,label:w.label,value:b[w.key]??0,color:Ce(w.typeNum)}))}},[O,q,D]),K=c.useMemo(()=>{const b=q.map(A=>A.timestamp),w=D.map(A=>({key:A.key,label:A.label,color:Ce(A.typeNum),values:q.map(F=>F[A.key]??0)}));return{timestamps:b,series:w}},[q,D]),te=null,ie=s&&i!==void 0&&r!==void 0&&(n!==i||a!==r),ae=c.useMemo(()=>{if(!(!ie||!s||i===void 0||r===void 0))return on(s,i,r,o,u)},[ie,s,i,r,o,u]);if(M.length===0)return t.length===0?e.jsxs("div",{className:"h-full flex items-center justify-center text-fg-muted",children:[e.jsx(Se,{className:"w-6 h-6 mr-2 opacity-50"}),e.jsx("span",{children:"No packet data available"})]}):null;if(p==="mosaic")return e.jsx($s,{sortedTypes:D,aggregateShares:U,mode:o});const se=(a-n)/3600,oe=ft(n,se),$=ft(a,se);return p==="stats"?e.jsx(Vs,{mode:o,packets:M,startTs:n,endTs:a,radioConfig:u,sortedTypes:D,aggregateShares:U,noiseFloorAnomalies:m,showNoiseFloorOverlay:x,overlayOpacity:S,startLabel:oe,endLabel:$,lockedYMax:ae,legendMinH:Ye,dotSize:y,dotOpacity:v}):p==="trend"?e.jsx(Ws,{packets:M,mode:o,startTs:n,endTs:a,radioConfig:u,bucketCount:l,lockedYMax:ae,legendMinH:Ye}):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:Ke,bottom:20},children:[0,20,40,60,80,100].map((b,w,A)=>e.jsxs("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${(1-b/100)*100}%`,transform:w===0?"translateY(-100%)":w===A.length-1?"none":"translateY(-50%)",right:0},children:[b,"%"]},b))}),e.jsx("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:Ke,right:0,top:0,bottom:20},children:e.jsx(Pt,{timestamps:K.timestamps,series:K.series,highlightedKey:N,cursorColor:j.cursor,onHover:J,onSeriesHover:G,overlayLine:te,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:Ke,height:20,paddingTop:4},children:[e.jsx("span",{children:oe}),e.jsx("span",{children:$})]})]}),e.jsx("div",{style:{minHeight:Ye},children:e.jsx(at,{sortedTypes:D,highlightedType:N,onTypeHover:ee,aggregateShares:U,hoverData:L})})]})}const mn=c.memo(cn),Xe={ZOOM_DURATION:400,BLINK_DURATION:600},le={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.08},dn={"1x":1,"2x":2,"4x":4,"8x":8,"16x":16,"36x":36},gt=[1,5,10,25,50,100,150],un=22.5,Mt=un*Math.PI/180,bt=Math.sin(Mt),yt=Math.cos(Mt);function hn(t,s,n,a){const i=Math.PI/180,r=(a-s)*i,l=t*i,u=n*i,o=Math.sin(r)*Math.cos(u),p=Math.cos(l)*Math.sin(u)-Math.sin(l)*Math.cos(u)*Math.cos(r);return(Math.atan2(o,p)*180/Math.PI+360)%360}function xn(t,s,n,a){const r=Math.PI/180,l=(n-t)*r,u=(a-s)*r,o=Math.sin(l/2)**2+Math.cos(t*r)*Math.cos(n*r)*Math.sin(u/2)**2;return 6371*2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o))}const pn=[{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 fn(t){var s;return((s=pn.find(n=>t>=n.min))==null?void 0:s.label)??"Critical"}function jt(t,s,n){const a=zt(t,n);return s[a]||"#808080"}function gn({neighbors:t,quickNeighbors:s,localLat:n,localLon:a,onStatsChange:i,title:r,badge:l,stats:u}){const[o,p]=c.useState(null),[m,x]=c.useState(new Set),[S,y]=c.useState({width:0,height:0}),[v,j]=c.useState("1x"),[N,R]=c.useState(1),O=c.useRef(null),B=c.useRef({}),M=c.useRef(null),z=c.useRef(N);z.current=N;const E=Ot(),g=Ft(),d=Ht(),f=Bt(),k=vt(),I=$t(),W=f?d.primary:d.secondary,D=f?.15:.4,U=f?.08:.25,q=f?k.blue:d.primary;c.useEffect(()=>{const h=M.current;if(!h)return;const P=new ResizeObserver(T=>{for(const H of T){const{width:Y,height:Q}=H.contentRect;Y>0&&Q>0&&y({width:Y,height:Q})}});P.observe(h);const _=h.getBoundingClientRect();return _.width>0&&_.height>0&&y({width:_.width,height:_.height}),()=>P.disconnect()},[]);const ee=c.useMemo(()=>{const h=new Set;if(s)for(const P of s)h.add(P.hash);return h},[s]),J=c.useMemo(()=>{const h=new Map;if(s)for(const P of s)h.set(P.hash,{snr:P.avgSnr,rssi:P.avgRssi});return h},[s]),{processedNeighbors:G,maxDistance:L,totalNeighbors:K,zeroHopCount:te}=c.useMemo(()=>{const h=[];for(const[T,H]of Object.entries(t)){if(!H.latitude||!H.longitude||H.latitude===0||H.longitude===0||!ee.has(T))continue;const Q=hn(n,a,H.latitude,H.longitude),ne=xn(n,a,H.latitude,H.longitude),X=J.get(T);h.push({hash:T.slice(0,8),name:H.node_name||H.name||"Unknown",snr:(X==null?void 0:X.snr)??H.snr??null,rssi:(X==null?void 0:X.rssi)??H.rssi??null,bearing:Q,distance:ne,normalizedDistance:0,lastSeen:H.last_seen,isZeroHop:!0})}const _=(h.length>0?Math.max(...h.map(T=>T.distance)):0)*le.DATA_HEADROOM;return h.sort((T,H)=>(T.snr??-1/0)-(H.snr??-1/0)),{processedNeighbors:h,maxDistance:_,totalNeighbors:h.length,zeroHopCount:h.length}},[t,n,a,ee,J]);c.useEffect(()=>{i==null||i({zeroHopCount:te,totalCount:K,maxDistanceKm:L})},[te,K,L]),c.useEffect(()=>{const h=dn[v],P=z.current;O.current&&cancelAnimationFrame(O.current);const _=performance.now(),T=H=>{const Y=H-_,Q=Math.min(Y/Xe.ZOOM_DURATION,1),ne=os(Q),X=P+(h-P)*ne;R(X),Q<1?O.current=requestAnimationFrame(T):O.current=null};return O.current=requestAnimationFrame(T),()=>{O.current&&cancelAnimationFrame(O.current)}},[v]);const ie=L/N,ae=c.useMemo(()=>gt.filter(h=>h<=ie*1.1),[ie]);c.useEffect(()=>{const h=[];for(const _ of G){const T=B.current[_.hash];T!==void 0&&T!==_.lastSeen&&h.push(_.hash),B.current[_.hash]=_.lastSeen}if(h.length===0)return;queueMicrotask(()=>{x(_=>new Set([..._,...h]))});const P=setTimeout(()=>{x(_=>{const T=new Set(_);return h.forEach(H=>T.delete(H)),T})},Xe.BLINK_DURATION);return()=>clearTimeout(P)},[G]);const se=n!==0&&a!==0,oe=c.useMemo(()=>{const{width:h,height:P}=S,_=h/2,T=P/2,H=Math.min(h,P),Y=Math.max(10,H/2-le.PADDING),Q=Math.max(10,Y-le.LABEL_INSET);return{width:h,height:P,centerX:_,centerY:T,radius:Q,labelRadius:Y}},[S]),{width:$,height:b,centerX:w,centerY:A,radius:F,labelRadius:Z}=oe,ue=c.useId(),pe=c.useCallback((h,P)=>{const _=h*Math.PI/180;return{x:w+F*P*Math.sin(_),y:A-F*P*Math.cos(_)}},[w,A,F]),fe=c.useCallback(h=>{const _={N:0,NE:45,E:90,SE:135,S:180,SW:225,W:270,NW:315}[h]*Math.PI/180;return{x:w+Z*Math.sin(_),y:A-Z*Math.cos(_)}},[w,A,Z]),_e=c.useCallback(h=>{p(h)},[]),Re=c.useCallback(h=>{j(h)},[]),Te=c.useCallback(h=>L<=0?0:h/L*N,[L,N]),De=h=>`${h}km`,we=28,Ee=c.useMemo(()=>{const h=[{x:w,y:A-Z},{x:w+Z*Math.SQRT1_2,y:A-Z*Math.SQRT1_2}],P=ae.map(T=>{const H=T/L*N,Y=w+F*H*bt,Q=A-F*H*yt;return{km:T,scale:H,lx:Y,ly:Q}}).filter(T=>T.scale>=.02).sort((T,H)=>H.km-T.km),_=[];for(const T of P){const H=_.some(Q=>{const ne=Q.lx-T.lx,X=Q.ly-T.ly;return Math.sqrt(ne*ne+X*X)<we}),Y=h.some(Q=>{const ne=Q.x-T.lx,X=Q.y-T.ly;return Math.sqrt(ne*ne+X*X)<we});!H&&!Y&&_.push(T)}return _},[ae,L,N,w,A,F,Z]),Le=S.width>0&&S.height>0;return se?K===0?e.jsxs("div",{ref:M,className:"flex flex-col items-center justify-center h-full text-fg-secondary",children:[e.jsx(We,{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:M,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:w-F-le.LABEL_INSET-4,top:A-F-le.LABEL_INSET-4,width:(F+le.LABEL_INSET)*2+8,height:(F+le.LABEL_INSET)*2+8,borderRadius:"50%",padding:4,boxSizing:"border-box",backgroundColor:f?"var(--zinc-925)":"var(--zinc-75)"}}),e.jsxs("svg",{width:$,height:b,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 ${Xe.BLINK_DURATION}ms ease-out forwards;
                }
              `}),e.jsx("clipPath",{id:ue,children:e.jsx("circle",{cx:w,cy:A,r:F})})]}),(()=>{const h=F+le.LABEL_INSET+12,P=f?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.15)",_=f?"rgba(59, 130, 246, 0.4)":"rgba(59, 130, 246, 0.5)",T=6,H=16,Y=4,Q=[0,90,180,270],ne=[45,135,225,315];return e.jsxs("g",{className:"radar-frame","aria-hidden":"true",children:[e.jsx("circle",{cx:w,cy:A,r:h,fill:"none",stroke:P,strokeWidth:1,strokeDasharray:"2 6"}),ne.map(X=>{const re=X*Math.PI/180,ce=Math.cos(re),me=Math.sin(re),he=h+Y,C=h+Y+H,V=w+he*me,be=A-he*ce,Ie=w+C*me,Be=A-C*ce;return e.jsxs("g",{children:[e.jsx("line",{x1:V,y1:be,x2:Ie,y2:Be,stroke:_,strokeWidth:1}),e.jsx("line",{x1:Ie-4*ce,y1:Be-4*me,x2:Ie+4*ce,y2:Be+4*me,stroke:_,strokeWidth:1})]},`corner-${X}`)}),Q.map(X=>{const re=X*Math.PI/180,ce=w+(h-T)*Math.sin(re),me=A-(h-T)*Math.cos(re),he=w+(h+2)*Math.sin(re),C=A-(h+2)*Math.cos(re);return e.jsx("line",{x1:ce,y1:me,x2:he,y2:C,stroke:P,strokeWidth:1},`tick-cardinal-${X}`)}),ne.map(X=>{const re=X*Math.PI/180,ce=w+(h-4)*Math.sin(re),me=A-(h-4)*Math.cos(re),he=w+(h+1)*Math.sin(re),C=A-(h+1)*Math.cos(re);return e.jsx("line",{x1:ce,y1:me,x2:he,y2:C,stroke:P,strokeWidth:1},`tick-intercardinal-${X}`)})]})})(),(()=>{const h=F+le.LABEL_INSET+4,P=[0,...gt.map(_=>{const T=Te(_);return T<=0?0:Math.min(F*T,h)}),h];return P.slice(0,-1).map((_,T)=>{const H=P[T+1],Y=H-_;return Y<.5||T%2!==0?null:e.jsx("circle",{cx:w,cy:A,r:(H+_)/2,fill:"none",stroke:"var(--subtle-fill)",strokeWidth:Y},`band-${T}`)})})(),ae.map(h=>{const P=Te(h);if(P<.02)return null;const _=Ee.some(Y=>Y.km===h),T=w+F*P*bt,H=A-F*P*yt;return e.jsx("g",{children:_&&e.jsx("text",{x:T+4,y:H-2,textAnchor:"start",dominantBaseline:"auto",fill:d.secondary,fontSize:10,fontFamily:$e,children:De(h)})},`ring-${h}`)}),["N","E","S","W"].map(h=>{const _={N:0,E:90,S:180,W:270}[h]*Math.PI/180;return e.jsx("line",{x1:w,y1:A,x2:w+F*Math.sin(_),y2:A-F*Math.cos(_),stroke:W,strokeOpacity:D,strokeWidth:1,strokeDasharray:"4 4"},h)}),["NE","SE","SW","NW"].map(h=>{const _={NE:45,SE:135,SW:225,NW:315}[h]*Math.PI/180;return e.jsx("line",{x1:w,y1:A,x2:w+F*Math.sin(_),y2:A-F*Math.cos(_),stroke:W,strokeOpacity:U,strokeWidth:1,strokeDasharray:"4 4"},`diag-${h}`)}),["N","E","S","W"].map(h=>{const P=fe(h),_=h==="E"?"end":h==="W"?"start":"middle",T=h==="N"?"hanging":h==="S"?"auto":"middle";return e.jsx("text",{x:P.x,y:P.y,textAnchor:_,dominantBaseline:T,fill:q,fontSize:le.CARDINAL_FONT_SIZE,fontWeight:700,fontFamily:$e,"aria-hidden":"true",children:h},h)}),["NE","SE","SW","NW"].map(h=>{const P=fe(h),_=h==="NE"||h==="SE"?"end":"start",T=h==="NE"||h==="NW"?"hanging":"auto";return e.jsx("text",{x:P.x,y:P.y,textAnchor:_,dominantBaseline:T,fill:q,fontSize:le.INTERCARDINAL_FONT_SIZE,fontWeight:600,fontFamily:$e,"aria-hidden":"true",children:h},h)}),e.jsx("circle",{cx:w,cy:A,r:le.LOCAL_DOT_RADIUS,fill:g.chart6,stroke:f?"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(#${ue})`,children:G.map(h=>{const P=L>0?h.distance/L*N:0;if(P>1)return null;const{x:_,y:T}=pe(h.bearing,P),H=h.snr!==null?jt(h.snr,E,I):"#808080",Y=(o==null?void 0:o.hash)===h.hash,Q=m.has(h.hash),ne=le.DOT_RADIUS_HOVERED*1.5;return e.jsxs("g",{role:"img","aria-label":`${h.name}: ${h.distance.toFixed(1)}km ${h.bearing.toFixed(0)}°`,children:[Q&&e.jsx("circle",{cx:_,cy:T,r:ne,fill:"none",stroke:f?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.7)",strokeWidth:2,className:"neighbor-blink-ring"}),Y&&e.jsx("circle",{cx:_,cy:T,r:ne,fill:H,opacity:.3}),e.jsx("circle",{cx:_,cy:T,r:Y?le.DOT_RADIUS_HOVERED:le.DOT_RADIUS,fill:H,stroke:f?"rgba(0,0,0,0.5)":"rgba(0,0,0,0.25)",strokeWidth:1,style:{cursor:"pointer",transition:"r 0.15s"},onMouseEnter:()=>_e(h),onMouseLeave:()=>_e(null)})]},h.hash)})})]})]}),o&&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:o.name}),e.jsx("div",{className:"type-data-xs text-fg-secondary",children:o.hash}),o.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:jt(o.snr,E,I)},children:[o.snr.toFixed(1)," dB"]}),e.jsxs("span",{className:"text-fg-secondary ml-1",children:["(",fn(o.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:[o.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:[o.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:[r&&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(We,{className:"w-3.5 h-3.5"})}),l&&e.jsx(Ae,{color:"zinc",children:l})]}),e.jsx("span",{className:"type-micro text-left text-[10px] leading-tight px-1",children:r})]}),e.jsx("div",{className:"flex flex-col gap-1 flex-1",role:"group","aria-label":"Zoom level",children:["1x","2x","4x","8x","16x","36x"].map(h=>e.jsx("button",{onClick:()=>Re(h),"aria-pressed":v===h,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 ${v===h?"bg-sys-blue/20 text-sys-blue":"bg-subtle-fill/80 text-fg-secondary hover:bg-subtle-fill-strong hover:text-fg-primary"}`,children:h},h))})]})]}):e.jsxs("div",{ref:M,className:"flex flex-col items-center justify-center h-full text-fg-secondary",children:[e.jsx(We,{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 bn=c.memo(gn),Ze={repeater:"var(--sys-blue)",companion:"var(--sys-cyan)",room_server:"var(--sys-indigo)"};function yn(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 jn({neighbors:t,timeRangeLabel:s}){const n=c.useMemo(()=>{const a={repeater:0,companion:0,room_server:0};for(const l of Object.values(t)){const u=yn(l);a[u]=(a[u]||0)+1}const i=Object.values(a).reduce((l,u)=>l+u,0);return{items:[{label:"Repeaters",count:a.repeater,percent:0,color:Ze.repeater},{label:"Companions",count:a.companion,percent:0,color:Ze.companion},{label:"Room Servers",count:a.room_server,percent:0,color:Ze.room_server}].map(l=>({...l,percent:i>0?l.count/i*100:0})).filter(l=>l.count>0).sort((l,u)=>u.count-l.count),total:i}},[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(Ae,{color:"zinc",children:s})]}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:n.total})]})]})}const Nn=c.memo(jn);function Qe({children:t,minHeight:s="100%",rootMargin:n="200px 0px",keepMounted:a=!0,className:i=""}){const r=c.useRef(null),[l,u]=c.useState(!1),[o,p]=c.useState(!1);c.useEffect(()=>{const x=r.current;if(!x)return;const S=new IntersectionObserver(([y])=>{const v=y.isIntersecting;p(v),v&&u(!0)},{rootMargin:n,threshold:0});return S.observe(x),()=>{S.disconnect()}},[n]);const m=o||a&&l;return e.jsx("div",{ref:r,className:`h-full w-full ${i}`,style:{minHeight:s},children:m?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 Ct=[{target:"DisambiguationCard",fn:"disambiguation.collisions",minStage:2}];nt(Ct);const vn=.9,kn=.7,Sn=.5,wn=10,Mn=25,Oe={excellent:"text-signal-excellent",good:"text-signal-good",fair:"text-signal-fair",poor:"text-sys-blue"},Cn={excellent:"bg-signal-excellent/10",good:"bg-signal-good/10",fair:"bg-signal-fair/10",poor:"bg-sys-blue/10"};function An(t){return t>=vn?"excellent":t>=kn?"good":t>=Sn?"fair":"poor"}function _n(t){return t<=wn?"excellent":t<=Mn?"good":"poor"}function Rn(){st(Ct);const t=Wt(),s=Ut(),[n,a]=c.useState(null),i=c.useCallback((m,x)=>{a({prefix:m,candidateHashes:x})},[]),r=c.useCallback(()=>{a(null)},[]);if(!s)return e.jsxs(de,{neomorphic:!0,children:[e.jsx(ve,{icon:e.jsx(lt,{}),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(Gt,{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 l=An(t.avgConfidence),u=_n(t.collisionRate),o=l==="poor"||u==="poor"?"poor":l==="fair"||u==="fair"?"fair":l==="good"||u==="good"?"good":"excellent",p=o==="excellent"||o==="good"?ot:Je;return e.jsxs(de,{neomorphic:!0,className:"flex flex-col overflow-hidden",children:[e.jsx(ve,{icon:e.jsx(lt,{}),title:"Prefix Conflicts",badgeColor:"zinc",actions:o==="poor"?e.jsxs(Ae,{color:"red",children:[e.jsx(Je,{className:"w-3 h-3"}),"Needs Attention"]}):e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full ${Cn[o]}`,children:[e.jsx(p,{className:`w-3.5 h-3.5 ${Oe[o]}`}),e.jsx("span",{className:`type-data-xs font-medium ${Oe[o]}`,children:o==="excellent"?"Excellent":o==="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 2-character prefixes observed in packet paths.",children:[e.jsx("span",{className:"type-data-xl text-fg-primary",children:e.jsx(Fe,{value:t.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(Fe,{value:t.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 ${t.collisionPrefixes>0?"text-sys-blue":"text-fg-primary"}`,children:e.jsx(Fe,{value:t.collisionPrefixes,priority:"low"})}),e.jsx("span",{className:`type-micro mt-0.5 sm:mt-1 ${t.collisionPrefixes>0?"text-sys-blue":"text-fg-muted"}`,children:"Conflicts"})]})]}),t.highCollisionPrefixes.length>0&&e.jsxs("div",{className:"pt-3",children:[e.jsx("div",{className:"data-box-label",children:"Problem Prefixes"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 content-start",children:t.highCollisionPrefixes.map(({prefix:m,candidateCount:x,candidateHashes:S})=>e.jsxs("button",{type:"button",onClick:()=>i(m,S),className:"inline-flex items-center gap-0.5 group",title:`${x} candidates - click to explore`,children:[e.jsx(xs,{children:m}),e.jsxs("span",{className:"text-fg-muted type-data-xs group-hover:text-fg-secondary transition-colors",children:["×",x]})]},m))})]}),t.lowConfidencePrefixes.length===0&&t.collisionPrefixes===0&&e.jsx("div",{className:"flex-1 flex items-center",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ot,{className:"w-3.5 h-3.5 text-signal-excellent"}),e.jsx("span",{className:"type-data-xs text-signal-excellent",children:"All 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 ${Oe[l]}`,children:[(t.avgConfidence*100).toFixed(1),"%"]})]}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-help",title:"Percentage of 2-character 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 ${Oe[u]}`,children:[t.collisionRate.toFixed(1),"%"]})]})]})]}),e.jsx(fs,{isOpen:!!n,prefix:(n==null?void 0:n.prefix)||"",candidateHashes:(n==null?void 0:n.candidateHashes)||[],onClose:r})]})}const At=[{target:"PacketHealth",fn:"type",minStage:1},{target:"PacketHealth",fn:"duplicates",minStage:1}];nt(At);const Tn=new Set(["Duplicate","Empty payload","Path too long","Unknown"]),ge=24;function Dn(t,s){const n=Date.now()/1e3,a=s*60,i=n-a,r=a/ge,l=new Array(ge).fill(0),u=new Array(ge).fill(0),o=new Array(ge).fill(0),p=new Array(ge).fill(0);let m=0,x=0,S=0,y=0,v=0,j=0;for(const M of t){if(M.packet_origin==="tx_local")continue;const z=M.timestamp;if(z<i||z>n)continue;m++;const E=Math.min(ge-1,Math.floor((z-i)/r));u[E]++,M.transmitted||M.packet_origin==="tx_forward"?(x++,l[E]++):(M.is_duplicate||M.drop_reason==="Duplicate")&&S++,M.drop_reason&&Tn.has(M.drop_reason)&&y++,Kt(M.route??M.route_type)&&(v++,o[E]++),M._packetVersion===1&&(j++,p[E]++)}const N=[],R=[],O=[];for(let M=0;M<ge;M++){const z=u[M],E=l[M],g=(i+M*r)*1e3;N.push({count:z>0?Math.round(E/z*100):0,timestamp:g}),R.push({count:z>0?Math.round(o[M]/z*100):0,timestamp:g}),O.push({count:z>0?Math.round(p[M]/z*100):0,timestamp:g})}const B=m-S;return{totalRx:m,uniqueRx:B,forwarded:x,duplicates:S,waste:y,efficiency:m>0?x/m*100:0,duplicateRate:m>0?S/m*100:0,wasteRate:m>0?y/m*100:0,sparkline:N,transport:v,v2:j,transportSparkline:R,v2Sparkline:O}}function En(t){return t>=90?"excellent":t>=75?"good":t>=60?"fair":"poor"}const Ln={excellent:"bg-status-success",good:"bg-sys-blue",fair:"bg-status-warning",poor:"bg-status-danger"};function In({packets:t,rangeMinutes:s,rangeHours:n,timeRangeLabel:a,isLoaded:i=!0}){st(At);const r=c.useMemo(()=>Dn(t,s),[t,s]),[l,u]=c.useState(null),o=c.useCallback(async()=>{try{const x=await Vt(n);x.success&&x.data&&u(x.data.count)}catch{}},[n]);c.useEffect(()=>{o()},[o]);const p=En(r.efficiency),m=r.totalRx>0;return e.jsx(de,{neomorphic:!0,isLoaded:i,skeletonType:"chart",children:i&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{icon:e.jsx(gs,{}),title:"Packet Health",badge:a,badgeColor:"zinc"}),e.jsx(qt,{children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("div",{className:"type-data-xl text-fg-primary",children:[m?e.jsx(Fe,{value:Math.round(r.efficiency*10)/10,className:"font-mono tabular-nums",priority:"medium",format:{minimumFractionDigits:1,maximumFractionDigits:1}}):e.jsx("span",{className:"opacity-30",children:"—"}),e.jsx("span",{className:"type-data-sm text-fg-muted ml-0.5",children:"%"})]}),m&&e.jsx("div",{className:`w-2 h-2 rounded-full ${Ln[p]}`})]}),e.jsx("div",{className:"type-micro mb-2 cursor-help",title:"Forwarded packets / total received. CRC failures, garbled packets, and RF collisions that destroy packets before reaching software are not included in this ratio — see CRC Errors for hardware-level failures.",children:"FORWARDING RATE"}),e.jsx("div",{className:"flex-1 min-h-[28px] max-h-[48px] mb-2",children:e.jsx(Ue,{data:r.sparkline,width:9999,height:36,className:"w-full"})}),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",children:[e.jsx("div",{className:"data-box-label",children:"Transport"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px]",children:e.jsx(Ue,{data:r.transportSparkline,width:9999,height:24,className:"w-full",color:"var(--sys-amber)"})}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-sys-amber",children:m?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:r.transport}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(Pe,{children:r.uniqueRx})]}):"—"})]})]}),e.jsxs("div",{className:"flex-1 min-w-0 radius-inner depth-stroke-inset p-2",children:[e.jsx("div",{className:"data-box-label",children:"V2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px]",children:e.jsx(Ue,{data:r.v2Sparkline,width:9999,height:24,className:"w-full",color:"var(--sys-teal)"})}),e.jsx("div",{className:"data-box data-box-compact shrink-0 text-sys-teal",children:m?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:r.v2}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(Pe,{children:r.uniqueRx})]}):"—"})]})]})]}),e.jsxs("div",{className:"flex gap-2 sm:gap-3 mt-auto",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Dupes"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:m?`${r.duplicateRate.toFixed(1)}%`:"—"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Waste"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:m?`${r.wasteRate.toFixed(1)}%`:"—"})]}),l!==null&&l>0&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"data-box-label flex items-center gap-1",children:[e.jsx(Je,{className:"w-3 h-3 text-status-warning"}),"CRC"]}),e.jsx("div",{className:"data-box data-box-fill data-box-left text-status-warning",children:l})]})]})]})})]})})}function ma(){var De,we,Ee,Le,h,P,_,T,H,Y,Q,ne,X,re,ce,me,he;const t=Yt(),s=Xt(),n=Zt(),a=Qt(),i=Jt(),r=es(),l=t!==null&&i,u=c.useRef(!1);l&&!u.current&&(u.current=!0);const o=u.current,p=ts(),m=ss(),x=ns(),[S,y]=c.useState(null),[,v]=c.useState(null),[j]=c.useState(null),[N,R]=c.useState(()=>{const C=localStorage.getItem("statistics-view-mode");return C==="share"||C==="airtime"?C:"airtime"});c.useEffect(()=>{localStorage.setItem("statistics-view-mode",N)},[N]);const[O,B]=c.useState(()=>{const C=localStorage.getItem("statistics-smoothing-mode");return["ema","ultra","mosaic","stats","trend"].includes(C)?C:"stats"});c.useEffect(()=>{localStorage.setItem("statistics-smoothing-mode",O)},[O]);const[M,z]=c.useState(!1),[E,g]=c.useState(!1),[d,f]=c.useState(kt),[k,I]=c.useState(.5),[W,D]=c.useState(bs),[U,q]=c.useState(.5),[ee,J]=c.useState(85),G=c.useMemo(()=>({0:0,1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9})[p]??3,[p]),L=ze[G].hours,K=L*60,te=ze[G],ie=rt(L),ae=r.isBackgroundLoading,se=c.useCallback(C=>{const be={0:1,1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10}[C]??4;m(be)},[m]),oe=c.useMemo(()=>{var V;if(!((V=t==null?void 0:t.config)!=null&&V.radio))return null;const C=t.config.radio;return{sf:C.spreading_factor??10,bw:C.bandwidth??25e4,cr:C.coding_rate??5,preamble:C.preamble_length??8}},[(we=(De=t==null?void 0:t.config)==null?void 0:De.radio)==null?void 0:we.spreading_factor,(Le=(Ee=t==null?void 0:t.config)==null?void 0:Ee.radio)==null?void 0:Le.bandwidth,(P=(h=t==null?void 0:t.config)==null?void 0:h.radio)==null?void 0:P.coding_rate,(T=(_=t==null?void 0:t.config)==null?void 0:_.radio)==null?void 0:T.preamble_length]),$=c.useMemo(()=>x.length===0?{timestamps:[],values:[]}:{timestamps:x.map(C=>C.timestamp),values:x.map(C=>C.noise_floor_dbm)},[x]),b=c.useMemo(()=>{if(x.length<10)return{anomalies:[],debug:void 0};const C=Ts(x,d);return{anomalies:C.anomalies,debug:C.debug}},[x,d]),w=b.anomalies,A=c.useMemo(()=>{const C=(t==null?void 0:t.neighbors)??{};return Object.fromEntries(Object.entries(C).filter(([V])=>!s.has(V)))},[t==null?void 0:t.neighbors,s]),F=c.useMemo(()=>{const C=Date.now()/1e3-L*3600;return Object.fromEntries(Object.entries(A).filter(([,V])=>V.last_seen>=C))},[A,L]),Z=c.useMemo(()=>{const C=K*60/ie,V=Math.floor(Date.now()/1e3),be=Math.floor(V/C)*C;return{start:be-K*60,end:be}},[K,ie]),ue=W.timeStart??Z.start,pe=W.timeEnd??Z.end,fe=(pe-ue)/3600,_e=rt(fe),Re=Ns(),Te=c.useMemo(()=>ys(a,W,Re,Z),[a,W,Re,Z]);return e.jsxs(ds,{children:[e.jsx(us,{title:"Statistics",icon:e.jsx(as,{}),subtitle:e.jsx(ms,{}),controls:e.jsx(cs,{ranges:ze,selectedIndex:G,onSelect:se,isPending:ae})}),j&&e.jsx(de,{className:"border border-sys-red/50 bg-sys-red/10",children:e.jsx("p",{className:"text-sys-red",children:j})}),M&&E&&e.jsxs(de,{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:["(",te.label,")"]})]}),e.jsx("button",{onClick:()=>f(C=>({...C,useAbsoluteThresholds:!C.useAbsoluteThresholds})),className:`type-data-xs px-2 py-1 rounded transition-colors ${d.useAbsoluteThresholds?"bg-sys-indigo/30 text-sys-indigo":"bg-elevated text-fg-muted hover:text-fg-secondary"}`,children:d.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:[((Y=(H=b.debug)==null?void 0:H.baselineCutoff)==null?void 0:Y.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:[((ne=(Q=b.debug)==null?void 0:Q.spikeCutoff)==null?void 0:ne.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:((X=b.debug)==null?void 0:X.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:w.length})]})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-edge-subtle space-y-4",children:[d.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 (",d.baselineDbm," dBm)"]}),e.jsx("input",{type:"range",min:"-120",max:"-60",value:d.baselineDbm,onChange:C=>f(V=>({...V,baselineDbm:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Spike (",d.spikeDbm," dBm)"]}),e.jsx("input",{type:"range",min:"-100",max:"-20",value:d.spikeDbm,onChange:C=>f(V=>({...V,spikeDbm:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Merge Gap (",d.mergeGapSeconds,"s)"]}),e.jsx("input",{type:"range",min:"5",max:"120",step:"5",value:d.mergeGapSeconds,onChange:C=>f(V=>({...V,mergeGapSeconds:Number(C.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 (",d.minSequenceLength,")"]}),e.jsx("input",{type:"range",min:"2",max:"20",value:d.minSequenceLength,onChange:C=>f(V=>({...V,minSequenceLength:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Similarity (±",d.similarityToleranceDbm," dBm)"]}),e.jsx("input",{type:"range",min:"1",max:"15",value:d.similarityToleranceDbm,onChange:C=>f(V=>({...V,similarityToleranceDbm:Number(C.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(k*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:k,onChange:C=>I(Number(C.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",d.baselinePercentile,")"]}),e.jsx("input",{type:"range",min:"1",max:"50",value:d.baselinePercentile,onChange:C=>f(V=>({...V,baselinePercentile:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Spike (P",d.spikePercentile,")"]}),e.jsx("input",{type:"range",min:"50",max:"99",value:d.spikePercentile,onChange:C=>f(V=>({...V,spikePercentile:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Merge Gap (",d.mergeGapSeconds,"s)"]}),e.jsx("input",{type:"range",min:"5",max:"120",step:"5",value:d.mergeGapSeconds,onChange:C=>f(V=>({...V,mergeGapSeconds:Number(C.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 (",d.minSequenceLength,")"]}),e.jsx("input",{type:"range",min:"2",max:"20",value:d.minSequenceLength,onChange:C=>f(V=>({...V,minSequenceLength:Number(C.target.value)})),className:"w-full accent-sys-indigo"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"type-micro block mb-1",children:["Similarity (±",d.similarityToleranceDbm," dBm)"]}),e.jsx("input",{type:"range",min:"1",max:"15",value:d.similarityToleranceDbm,onChange:C=>f(V=>({...V,similarityToleranceDbm:Number(C.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(k*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:k,onChange:C=>I(Number(C.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:[d.useAbsoluteThresholds?`useAbsoluteThresholds: true, baselineDbm: ${d.baselineDbm}, spikeDbm: ${d.spikeDbm}`:`useAbsoluteThresholds: false, baselinePercentile: ${d.baselinePercentile}, spikePercentile: ${d.spikePercentile}`,", mergeGapSeconds: ",d.mergeGapSeconds,", minSequenceLength: ",d.minSequenceLength,", similarityToleranceDbm: ",d.similarityToleranceDbm]})]})]})]}),e.jsxs(hs,{ready:o,children:[e.jsx("div",{className:"sm:hidden",children:ae&&e.jsx(ye,{template:"auto",children:e.jsx(de,{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 ",te.label," data..."]}),r.loadProgress&&e.jsxs("p",{className:"type-data-xs text-fg-muted mt-0.5",children:[r.loadProgress.loaded.toLocaleString()," packets (",r.loadProgress.percent,"%)"]})]})]})})})}),e.jsxs(e.Fragment,{children:[e.jsx(ye,{template:"hero-auto",children:e.jsx(de,{neomorphic:!0,skeletonType:"chart",children:o&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{icon:e.jsx(Se,{}),title:"Packet Analyzer",badge:te.label,badgeColor:"zinc",stackActionsOnMobile:!0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:[O==="stats"&&e.jsx(Ys,{enabled:M,onChange:z,anomalyCount:w.length,showTuning:E,onTuningChange:g}),e.jsx(Ks,{smoothing:O,onChange:B}),e.jsx(qs,{mode:N,onChange:R})]})}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(mn,{packets:Te,allPackets:a,startTs:ue,endTs:pe,parentStartTs:Z.start,parentEndTs:Z.end,bucketCount:_e,radioConfig:oe??void 0,mode:N,smoothing:O,noiseFloorAnomalies:w,showNoiseFloorOverlay:M,overlayOpacity:k,dotSize:U,dotOpacity:ee/100})})]})})}),e.jsx(ye,{template:"auto",className:"relative z-10",children:e.jsx(de,{neomorphic:!0,noPadding:!0,className:"overflow-visible",children:o&&e.jsx(js,{parentStartTs:Z.start,parentEndTs:Z.end,neighbors:A,filter:W,onChange:D,...O==="stats"?{scatterDotSize:U,onScatterDotSizeChange:q,scatterOpacity:ee,onScatterOpacityChange:J}:{}})})}),e.jsxs(ye,{template:"panel",children:[e.jsx(Me,{span:12,md:6,children:e.jsx(de,{neomorphic:!1,skeletonType:"chart",noPadding:o,className:"!bg-transparent !ring-0 !shadow-none !overflow-visible -mx-4 sm:mx-0 !px-0 !pr-0",children:o&&e.jsx(Qe,{children:e.jsx(bn,{neighbors:F,quickNeighbors:n,localLat:((ce=(re=t==null?void 0:t.config)==null?void 0:re.repeater)==null?void 0:ce.latitude)??0,localLon:((he=(me=t==null?void 0:t.config)==null?void 0:me.repeater)==null?void 0:he.longitude)??0,onStatsChange:v,title:"Link Quality",badge:te.label})})})}),e.jsx(Me,{span:12,md:6,children:e.jsx(de,{neomorphic:!0,skeletonType:"chart",children:o&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{icon:e.jsx(ks,{}),title:"Network Composition",badge:te.label,badgeColor:"zinc"}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Qe,{children:e.jsx(Nn,{neighbors:F,timeRangeLabel:te.label})})})]})})})]}),e.jsxs(ye,{template:"panel",children:[e.jsx(Me,{span:12,md:6,children:e.jsx(Rn,{})}),e.jsx(Me,{span:12,md:6,children:e.jsx(In,{packets:a,rangeMinutes:K,rangeHours:L,timeRangeLabel:te.label})})]}),e.jsx(ye,{template:"panel",children:e.jsx(Me,{span:12,children:e.jsx(de,{neomorphic:!0,skeletonType:"chart",children:o&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{icon:e.jsx(is,{}),title:"NOISE FLOOR dBm",stackActionsOnMobile:!0,actions:S?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:S.min.toFixed(0)})]}),e.jsxs("span",{className:"type-data-xs text-fg-muted whitespace-nowrap",children:["avg ",e.jsx("span",{className:"data-box",children:S.avg.toFixed(0)})]}),e.jsxs("span",{className:"type-data-xs text-fg-muted whitespace-nowrap",children:["max ",e.jsx("span",{className:"data-box",children:S.max.toFixed(0)})]})]}):null}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Qe,{children:e.jsx(rs,{timestamps:$.timestamps,values:$.values,onStatsChange:y})})})]})})})})]})]})]})}export{ma as default};
