var Rt=Object.defineProperty;var Tt=(t,s,n)=>s in t?Rt(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ye=(t,s,n)=>Tt(t,typeof s!="symbol"?s+"":s,n);import{e as Re,r as o,j as e,G as Ae,c as at,P as Nt,cF as vt,cG as et,w as we,cH as Dt,V as _e,cI as Lt,cJ as Et,cK as It,x as Pt,cL as Ot,cM as Ft,cN as Ht,cO as Bt,cP as $t,cb as zt,cQ as $e,ce as Wt,cR as Ut,cS as Gt,a7 as ke,cT as Vt,bY as it,c3 as qt,af as kt,ag as Kt,cU as Yt,bK as Xt,a6 as Zt,ac as Qt,ab as Jt,Q as es,aQ as ts,aR as ss,ad as ns,aA as as,cV as ze,aj as is,cW as rt,as as rs,aa as ls,cX as os}from"./index-BuFgUdF6.js";import{L as Se}from"./layers-BrblF2UQ.js";import{u as tt,h as cs,r as st}from"./consumer-registry-YGO4kl9s.js";import{e as ms}from"./easing-DkQiIJc0.js";import{C as We}from"./compass-DF0afhxw.js";import{T as ds,M as us}from"./MqttModeBadge-BeRzf62U.js";import{C as he,P as hs,a as xs,B as ps}from"./PageLayout-DKfh0Blq.js";import{A as Ue,D as Oe}from"./DataValue-LCAdfD-L.js";import{C as fs}from"./CollisionExplorerModal-ggc1GI4m.js";import{H as lt}from"./hash-B0n1oBpr.js";import{L as Fe}from"./LightSparkline-D-p7t3p_.js";import{A as gs}from"./activity-CU9M_dkq.js";import{c as bs,a as ys,A as js}from"./AnalyzerFilterPanel-fA_Td8vT.js";import{useResolveSource as Ns}from"./usePipelineStore-Chyk9TCr.js";import{R as je,C as Ce}from"./Grid-CVvPTnwu.js";import{S as vs}from"./settings-2-u_EftbnC.js";import{N as ks}from"./network-C306J38x.js";import"./chevron-right-Bn33xBBB.js";import"./map-pin-DUIK7gpx.js";import"./index-tC-yebOi.js";import"./index-CjY609r3.js";import"./maplibre-gl-CiCFUTvH.js";import"./BasemapLayer-9KgDoniZ.js";import"./share-2-Rt2CcEoP.js";import"./node-types-DgK-t_34.js";import"./circle-question-mark-NwPFAIxO.js";import"./funnel-DqVoB6_M.js";import"./search-s6rZk7pl.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 ws=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]],Ss=Re("chart-line",ws);/**
 * @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=Re("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=[["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"}]],As=Re("ear-off",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=[["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"}]],Rs=Re("grid-3x3",_s);/**
 * @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 Ts=[["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"}]],Ds=Re("grip",Ts),wt={useAbsoluteThresholds:!0,baselinePercentile:6,spikePercentile:50,baselineDbm:-107,spikeDbm:-100,mergeGapSeconds:45,minSequenceLength:16,similarityToleranceDbm:5};function ve(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:ve(s,50),p90:ve(s,90),p95:ve(s,95),p99:ve(s,99),max:s[s.length-1],min:s[0]}}function Ls(t,s={}){const n={...wt,...s};if(t.length<10)return{anomalies:[],thresholds:ct([]),totalSamples:t.length,anomalySamples:0};const a=t.map(b=>b.noise_floor_dbm),i=ct(a),l=[...a].sort((b,k)=>b-k);let r,u;n.useAbsoluteThresholds?(r=n.baselineDbm,u=n.spikeDbm):(r=ve(l,n.baselinePercentile),u=ve(l,n.spikePercentile));const c=[...t].sort((b,k)=>b.timestamp-k.timestamp),p=[];let m=null,x=0;for(const b of c)if(b.noise_floor_dbm>r&&b.noise_floor_dbm<u)if(x++,!m)m={startTs:b.timestamp,endTs:b.timestamp,values:[b.noise_floor_dbm],timestamps:[b.timestamp],rollingAvg:b.noise_floor_dbm};else{const S=Math.abs(b.noise_floor_dbm-m.rollingAvg)<=n.similarityToleranceDbm,A=b.timestamp-m.endTs<=n.mergeGapSeconds;S&&A?(m.endTs=b.timestamp,m.values.push(b.noise_floor_dbm),m.timestamps.push(b.timestamp),m.rollingAvg=m.values.reduce(($,O)=>$+O,0)/m.values.length):(m.values.length>=n.minSequenceLength&&p.push(m),m={startTs:b.timestamp,endTs:b.timestamp,values:[b.noise_floor_dbm],timestamps:[b.timestamp],rollingAvg:b.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:r,spikeCutoff:u,midBandSamples:x}}:{anomalies:p.map(b=>{const k=Math.max(...b.values),N=b.values.reduce((S,A)=>S+A,0)/b.values.length;return{startTs:b.startTs,endTs:b.endTs,peakValue:k,avgValue:N,severity:Es(N,r,u),sampleCount:b.values.length}}),thresholds:i,totalSamples:t.length,anomalySamples:x,debug:{baselineCutoff:r,spikeCutoff:u,midBandSamples:x}}}function Es(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 Is=Object.entries(Nt).map(([t,s])=>{const n=parseInt(t,10);return{typeNum:n,key:`TYPE_${n}`,label:s}});function nt({sortedTypes:t,highlightedType:s,onTypeHover:n,aggregateShares:a,hoverData:i}){const l=o.useMemo(()=>{if(!i)return null;const c=new Map;for(const p of i.items)c.set(p.key,p.value);return c},[i]),r=l!==null,u=o.useMemo(()=>{const c=new Set(t.map(x=>x.key)),p=t.map(x=>({typeNum:x.typeNum,key:x.key,label:x.label})),m=Is.filter(x=>!c.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"}),r&&(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(c=>{const p=Ae(c.typeNum),m=(l==null?void 0:l.get(c.key))??0,x=a.get(c.key)??0,w=r?m:x,b=w>1e-4,k=a.has(c.key),N=s===c.key,S=s&&!N||r&&m<=1e-4||!r&&!s&&!k;return e.jsxs("div",{className:at("flex items-center gap-1.5 transition-opacity cursor-pointer hover:opacity-80",S&&"opacity-30"),onMouseEnter:()=>n(c.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:c.label}),b&&e.jsxs("span",{className:at("tabular-nums",r?"text-fg-primary":"text-fg-muted"),children:[(w*100).toFixed(1),"%"]})]},c.key)})})]})}const mt='ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',Ps=2,Os=3,Fs=32,Hs=20,Bs=80;function dt(t,s,n,a,i){const l=t.reduce((p,m)=>p+m,0);if(l<=0||t.length===0)return[];const r=t.map((p,m)=>m).sort((p,m)=>t[m]-t[p]),u=r.map(p=>t[p]),c=new Array(t.length);return Je(u,r,l,s,n,a,i,c),c}function Je(t,s,n,a,i,l,r,u){if(t.length===0)return;if(t.length===1){u[s[0]]={x:a,y:i,w:l,h:r,index:s[0]};return}const c=l*r/n,p=l>=r,m=p?r:l;let x=0,w=1/0,b=0;for(let O=0;O<t.length;O++){const H=x+t[O],q=H*c/m;if(q<=0){b=O+1,x=H;continue}const I=t[0]*c/q,j=t[O]*c/q,f=Math.max(I>q?I/q:q/I,j>q?j/q:q/j);if(f<=w)w=f,b=O+1,x=H;else break}const k=m>0?x*c/m:0;let N=0;for(let O=0;O<b;O++){const q=(x>0?t[O]/x:0)*m;p?u[s[O]]={x:a,y:i+N,w:k,h:q,index:s[O]}:u[s[O]]={x:a+N,y:i,w:q,h:k,index:s[O]},N+=q}const S=t.slice(b),A=s.slice(b),$=n-x;p?Je(S,A,$,a+k,i,l-k,r,u):Je(S,A,$,a,i+k,l,r-k,u)}function ut(t,s,n,a,i,l){for(const r of s){const u=n[r.index];if(!u)continue;const c=Ps*l,p=r.x*l+c/2,m=r.y*l+c/2,x=r.w*l-c,w=r.h*l-c;if(x<=0||w<=0)continue;const b=Ae(u.typeNum),k=i!==null&&i!==r.index;t.save(),t.globalAlpha=k?.4:1;const N=Os*l;t.beginPath(),t.moveTo(p+N,m),t.lineTo(p+x-N,m),t.quadraticCurveTo(p+x,m,p+x,m+N),t.lineTo(p+x,m+w-N),t.quadraticCurveTo(p+x,m+w,p+x-N,m+w),t.lineTo(p+N,m+w),t.quadraticCurveTo(p,m+w,p,m+w-N),t.lineTo(p,m+N),t.quadraticCurveTo(p,m,p+N,m),t.closePath(),t.fillStyle=b,t.fill(),t.strokeStyle="rgba(0,0,0,0.2)",t.lineWidth=1*l,t.stroke();const S=4*l,A=r.w>36&&r.h>20,$=r.w>36&&r.h>32;if(A){const O=11*l;if($){const H=a>0?u.size/a*100:0;t.font=`500 ${8*l}px ${mt}`,t.fillStyle="rgba(0,0,0,0.6)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(`${H.toFixed(1)}%`,p+S,m+w-S-O)}t.font=`600 ${9*l}px ${mt}`,t.fillStyle="rgba(0,0,0,0.85)",t.textBaseline="alphabetic",t.textAlign="left",t.fillText(u.name,p+S,m+w-S)}t.restore()}}function $s(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:i,isAirtime:l}){if(!t||!a)return null;const r=(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:l?"Airtime":"Count"}),e.jsx("span",{className:"text-fg-primary tabular-nums font-medium",children:l?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:[r,"%"]})]}),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:l?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 Ws({sortedTypes:t,aggregateShares:s,mode:n="share"}){var I,j,f;const[a,i]=o.useState(null),[l,r]=o.useState(null),[u,c]=o.useState(0),[p,m]=o.useState(null),x=o.useRef(null),w=o.useRef(null),b=o.useRef([]),k=n==="airtime",N=o.useMemo(()=>t.reduce((d,y)=>d+(k?y.totalAirtime:y.totalCount),0),[t,k]),S=o.useMemo(()=>t.map((d,y)=>({name:d.label,size:k?d.totalAirtime:d.totalCount,index:y,typeNum:d.typeNum,key:d.key})),[t,k]);o.useEffect(()=>{const d=w.current;if(!d)return;const y=d.parentElement;if(!y)return;const E=y.getBoundingClientRect(),G=E.width,g=E.height;if(G<=0||g<=0)return;const R=window.devicePixelRatio||1;d.width=Math.floor(G*R),d.height=Math.floor(g*R),d.style.width=`${G}px`,d.style.height=`${g}px`;const z=S.map(W=>W.size),J=dt(z,0,0,G,g);b.current=J;const Z=d.getContext("2d");Z&&(Z.clearRect(0,0,d.width,d.height),ut(Z,J,S,N,a,R))},[S,N,a]),o.useEffect(()=>{const d=x.current;if(!d)return;const y=new ResizeObserver(()=>{const E=w.current;if(!E)return;const G=d.getBoundingClientRect(),g=G.width,R=G.height;if(g<=0||R<=0)return;const z=window.devicePixelRatio||1;E.width=Math.floor(g*z),E.height=Math.floor(R*z),E.style.width=`${g}px`,E.style.height=`${R}px`;const J=S.map(D=>D.size),Z=dt(J,0,0,g,R);b.current=Z;const W=E.getContext("2d");W&&(W.clearRect(0,0,E.width,E.height),ut(W,Z,S,N,a,z))});return y.observe(d),()=>y.disconnect()},[S,N]);const A=o.useCallback(d=>{const y=x.current;if(!y)return;const E=y.getBoundingClientRect(),G=d.clientX-E.left,g=d.clientY-E.top,R=$s(b.current,G,g);i(R),R!==null?(c(E.width),r({x:G,y:g})):r(null)},[]),$=o.useCallback(()=>{i(null),r(null)},[]),O=o.useCallback(d=>{if(m(d),d){const y=S.findIndex(E=>E.key===d);i(y>=0?y:null)}else i(null)},[S]),H=a!==null?{name:((I=S[a])==null?void 0:I.name)??"",value:((j=S[a])==null?void 0:j.size)??0}:null,q=a!==null?Ae((f=S[a])==null?void 0:f.typeNum):"";return t.length===0||N===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:Fs,right:0,top:0,bottom:Hs},ref:x,onMouseMove:A,onMouseLeave:$,children:[e.jsx("canvas",{ref:w,className:"absolute inset-0",style:{cursor:"default"}}),e.jsx(zs,{data:H,total:N,color:q,position:l,containerWidth:u,isAirtime:k})]})}),e.jsx("div",{style:{minHeight:Bs},children:e.jsx(nt,{sortedTypes:t,highlightedType:p,onTypeHover:O,aggregateShares:s})})]})}const Ge=32,Ve=20,Us=300;function Ne(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 Gs({packets:t,mode:s,startTs:n,endTs:a,radioConfig:i,bucketCount:l,lockedYMax:r,legendMinH:u}){const c=o.useMemo(()=>vt(),[]),p=c.blue,m=c.red,x=c.yellow,[w,b]=o.useState(null),{trendData:k,totals:N}=o.useMemo(()=>{if(t.length===0)return{trendData:[],totals:{rxBytes:0,txBytes:0,rxAirtime:0,txAirtime:0}};const j=a-n,f=Math.min(Math.ceil(j/Us),l),d=j/f,y=[];let E=0,G=0,g=0,R=0;for(const U of t){const v=U.timestamp;if(v<n||v>=a)continue;const M=et(U),_=we(U,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble}),F={timestamp:v,rxAirtime:0,txAirtime:0,rxBytes:0,txBytes:0};U.transmitted?(F.txAirtime=_,F.txBytes=M,G+=M,R+=_):(F.rxAirtime=_,F.rxBytes=M,E+=M,g+=_),y.push(F)}y.sort((U,v)=>U.timestamp-v.timestamp);const z=new Float64Array(y.length+1),J=new Float64Array(y.length+1),Z=new Float64Array(y.length+1),W=new Float64Array(y.length+1),D=new Float64Array(y.length);for(let U=0;U<y.length;U++)z[U+1]=z[U]+y[U].rxAirtime,J[U+1]=J[U]+y[U].txAirtime,Z[U+1]=Z[U]+y[U].rxBytes,W[U+1]=W[U]+y[U].txBytes,D[U]=y[U].timestamp;const K=U=>{let v=0,M=D.length;for(;v<M;){const _=v+M>>>1;D[_]<U?v=_+1:M=_}return v},se=[],ie=d*1e3;for(let U=0;U<f;U++){const v=n+U*d,M=v+d,_=K(v),F=K(M);if(s==="share"){const te=Z[F]-Z[_],xe=W[F]-W[_];se.push({timestamp:v,rx:te>0?te:null,tx:xe>0?xe:null})}else{const te=z[F]-z[_],xe=J[F]-J[_],oe=te/ie*100,ge=xe/ie*100;se.push({timestamp:v,rx:oe>0?oe:null,tx:ge>0?ge:null})}}const ee=2/31;let ne=null;return{trendData:se.map(U=>{const v=U.rx;return v!==null&&v>0&&(ne===null?ne=v:ne=ee*v+(1-ee)*ne),{...U,rxSmooth:ne!==null&&ne>0?ne:null}}),totals:{rxBytes:E,txBytes:G,rxAirtime:g,txAirtime:R}}},[t,n,a,l,s,i]),S=o.useMemo(()=>{if(k.length===0)return s==="share"?100:10;let j=0;for(const d of k){const y=d.rx??0,E=d.tx??0;y>j&&(j=y),E>j&&(j=E)}const f=j*1.1;return s==="share"?f<=100?100:f<=500?Math.ceil(f/100)*100:f<=1e3?Math.ceil(f/200)*200:f<=5e3?Math.ceil(f/500)*500:f<=1e4?Math.ceil(f/1e3)*1e3:Math.ceil(f/5e3)*5e3:Math.max(1,Math.ceil(f))},[k,s]),A=r??S,$=o.useMemo(()=>{if(w!==null&&k[w]){const j=k[w],f=j.rx??0,d=j.tx??0;return s==="share"?{rx:Ne(f),tx:Ne(d),total:Ne(f+d),isHovered:!0}:{rx:`${f.toFixed(2)}%`,tx:`${d.toFixed(2)}%`,total:`${(f+d).toFixed(2)}%`,isHovered:!0}}if(s==="share")return{rx:Ne(N.rxBytes),tx:Ne(N.txBytes),total:Ne(N.rxBytes+N.txBytes),isHovered:!1};{let j=0,f=0,d=0;for(const G of k)(G.rx!==null||G.tx!==null)&&(j+=G.rx??0,f+=G.tx??0,d++);const y=d>0?j/d:0,E=d>0?f/d:0;return{rx:`${y.toFixed(2)}%`,tx:`${E.toFixed(2)}%`,total:`${(y+E).toFixed(2)}%`,isHovered:!1}}},[w,k,N,s]),O=o.useMemo(()=>{const j=a-n,f=j/3600;return[0,.25,.5,.75,1].map(y=>{const E=n+j*y,G=new Date(E*1e3),g=G.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),R=G.toLocaleDateString([],{weekday:"short"}),z=y===.25||y===.75;return{pct:y,label:f>=24?`${R} ${g}`:g,mobileHidden:z}})},[n,a]),H=o.useCallback(j=>{b(j)},[]);if(k.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 q=o.useMemo(()=>s==="airtime"?A<=5?1:A<=10?2:A<=20?5:Math.ceil(A/5):A<=100?25:A<=500?100:A<=1e3?200:A<=5e3?1e3:A<=1e4?2e3:Math.ceil(A/5e3)*1e3,[A,s]),I=o.useMemo(()=>{const j=[];for(let f=0;f<=A;f+=q){const d=(1-f/A)*100;let y;s==="airtime"?y=`${f}%`:f>=1e6?y=`${(f/1e6).toFixed(1)}M`:f>=1e3?y=`${(f/1e3).toFixed(0)}K`:y=`${f}`,j.push({pos:d,label:y})}return j},[A,q,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:I.map((j,f)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${j.pos}%`,transform:f===0?"translateY(-100%)":f===I.length-1?"none":"translateY(-50%)",right:0},children:j.label},f))}),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(Dt,{data:k,yAxisMode:s==="share"?"share":"airtime",yMax:A,onHover:H,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:O.map((j,f)=>e.jsx("span",{className:`absolute type-data-xs text-fg-muted/60 tabular-nums ${j.mobileHidden?"hidden sm:inline":""}`,style:{left:`${j.pct*100}%`,transform:j.pct===0?"translateX(0)":j.pct===1?"translateX(-100%)":"translateX(-50%)"},children:j.label},f))})]}),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:$.rx}),e.jsx(_e,{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(_e,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"TX"})]})]})]})]})}const xt=Lt;class Vs{constructor(){ye(this,"worker",null);ye(this,"listeners",new Set);ye(this,"currentResult",null);ye(this,"isComputing",!1);ye(this,"debounceTimer",null);ye(this,"debounceMs",250);ye(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,l){if(s.length===0||!l){this.currentResult=null,this.notifyListeners();return}const r={startTs:n,endTs:a,mode:i,packetCount:s.length};this.isCacheHit(r)||(this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.computeInternal(s,n,a,i,l,r)},this.debounceMs))}computeInternal(s,n,a,i,l,r){const u=this.ensureWorker();if(!u)return;const c=s.length,p=new Float64Array(c),m=new Float64Array(c),x=new Uint16Array(c),w=new Uint8Array(c),b={spreadingFactor:l.sf,bandwidthHz:l.bw,codingRate:l.cr,preambleLength:l.preamble};for(let N=0;N<c;N++){const S=s[N];p[N]=S.timestamp??0,w[N]=(S.type??S.payload_type??255)&255,x[N]=Math.min(et(S),65535),i==="airtime"?m[N]=we(S,b):m[N]=1}this.isComputing=!0,this.lastCacheKey=r,this.notifyListeners();const k={type:"compute",payload:{timestamps:p,airtimeMs:m,byteSizes:x,packetTypes:w,startTs:n,endTs:a,mode:i}};u.postMessage(k,[p.buffer,m.buffer,x.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 qe=new Vs;function qs(t,s,n,a,i){const[l,r]=o.useState(()=>qe.getResult());return o.useEffect(()=>qe.subscribe(u=>{r(u)}),[]),o.useEffect(()=>{qe.compute(t,s,n,a,i)},[t,s,n,a,i]),l}function Ks({mode:t,packets:s,startTs:n,endTs:a,radioConfig:i,sortedTypes:l,aggregateShares:r,noiseFloorAnomalies:u,showNoiseFloorOverlay:c,overlayOpacity:p=.5,startLabel:m,endLabel:x,lockedYMax:w,legendMinH:b,dotSize:k,dotOpacity:N}){const[S,A]=o.useState(null),[$,O]=o.useState(null),H=o.useMemo(()=>(a-n)/3600,[n,a]),q=o.useCallback(W=>{O(W)},[]),j=qs(s,n,a,t==="share"?"share":"airtime",i),[f,d]=o.useState(null),y=o.useCallback((W,D)=>{A(W),d(D??null)},[]),E=o.useMemo(()=>{if(f===null||!j||j.count===0)return null;const W=n+f*(a-n);let D;H>=168?D=75:H>=72?D=35:H>=24?D=15:H>=3?D=10:D=5;const K=D*60/2;return{start:W-K,end:W+K}},[f,j,n,a,H]),G=o.useMemo(()=>E?new Date((E.start+E.end)/2*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}):null,[E]),g=o.useMemo(()=>{if(S===null||!E)return null;const W=G??"",{start:D,end:K}=E,se=s.filter(v=>v.timestamp>=D&&v.timestamp<K);if(se.length===0)return{timestamp:(D+K)/2,timeLabel:W,items:l.map(v=>({key:v.key,label:v.label,value:0,color:xt(v.typeNum)}))};const ie=new Map,ee=new Map;let ne=0,ce=0;for(const v of se){const _=`TYPE_${v.type??v.payload_type??-1}`;if(ie.set(_,(ie.get(_)??0)+1),ne++,i){const F=we(v,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble});ee.set(_,(ee.get(_)??0)+F),ce+=F}}const U=l.map(v=>{let M;return t==="airtime"?M=ce>0?(ee.get(v.key)??0)/ce:0:M=ne>0?(ie.get(v.key)??0)/ne:0,{key:v.key,label:v.label,value:M,color:xt(v.typeNum)}});return{timestamp:(D+K)/2,timeLabel:W,items:U}},[S,E,G,s,l,t,i]),R=t==="share",z=w??(j==null?void 0:j.maxValue)??(R?240:10),J=o.useMemo(()=>{if(!R)return 5;const W=[10,20,25,50,100,200,250,500,1e3],D=z/4.5;for(const K of W)if(K>=D)return K;return z>5e3?Math.ceil(D/1e3)*1e3:Math.ceil(D/100)*100},[z,R]),Z=o.useMemo(()=>{const W=[];for(let D=0;D<=z;D+=J){const K=(1-D/z)*100;W.push({pos:K,label:R?`${D}B`:`${D}%`})}return W},[z,J,R]);return!j||j.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:Z.map((W,D)=>e.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${W.pos}%`,transform:D===0?"translateY(-100%)":D===Z.length-1?"none":"translateY(-50%)",right:0},children:W.label},D))}),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:j,yAxisMode:t==="share"?"share":"airtime",onHover:y,noiseFloorAnomalies:u,showNoiseFloorOverlay:c,overlayOpacity:p,highlightedType:$,timeRangeHours:H,yAxisMaxOverride:w,dotSize:k,dotOpacity:N,startTs:n,endTs:a,externalAxes:!0}),G&&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:G})]}),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:b},children:e.jsx(nt,{sortedTypes:l,highlightedType:$,onTypeHover:q,aggregateShares:r,hoverData:g})})]})}function Ys({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 Xs({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(Ds,{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(Ss,{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(It,{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(Rs,{className:"w-3.5 h-3.5"})})]})}function Zs({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(As,{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:cs}];st(St);const pt=360,Qs=500,Js={sf:10,bw:25e4,cr:5,preamble:8},Ke=32;function ft(t,s){const n=new Date(t*1e3),a=r=>r.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 en(t){return Nt[t]??`TYPE_${t.toString(16).toUpperCase()}`}function tn(t,s){const n=new Map;for(const i of t){const l=i.type??i.payload_type??-1,r=we(i,{spreadingFactor:s.sf,bandwidthHz:s.bw,codingRate:s.cr,preambleLength:s.preamble}),u=n.get(l)??{count:0,airtime:0};n.set(l,{count:u.count+1,airtime:u.airtime+r})}const a=[];for(const[i,l]of n)a.push({typeNum:i,key:`TYPE_${i}`,label:en(i),totalCount:l.count,totalAirtime:l.airtime});return a.sort((i,l)=>l.totalCount-i.totalCount)}function sn(t,s,n,a,i,l,r=0){const u=n-s,c=u/a,p=c*1e3,m=u/3600,x=s-r*c,w=n+r*c,b=a+2*r,k=[];for(let N=0;N<b;N++){const S=x+N*c,A=new Date(S*1e3),$=m>=24?A.toLocaleDateString([],{weekday:"short",hour:"2-digit",minute:"2-digit",hour12:!1}):A.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1}),O={timestamp:S,time:$,counts:{},shares:{},airtimes:{},total:0,totalAirtime:0,bucketDurationMs:p};for(const H of l)O.counts[H.key]=0,O.airtimes[H.key]=0;k.push(O)}for(const N of t){const S=N.timestamp;if(S<x||S>=w)continue;const A=Math.min(Math.floor((S-x)/c),b-1),$=`TYPE_${N.type??N.payload_type??-1}`;k[A].counts[$]=(k[A].counts[$]??0)+1,k[A].total++;const O=we(N,{spreadingFactor:i.sf,bandwidthHz:i.bw,codingRate:i.cr,preambleLength:i.preamble});k[A].airtimes[$]=(k[A].airtimes[$]??0)+O,k[A].totalAirtime+=O}for(const N of k)for(const S of l)N.shares[S.key]=N.total>0?N.counts[S.key]/N.total*100:0;return{buckets:k,visibleStart:r,visibleEnd:r+a}}function nn(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 l=i+2,r=(12*s*s-3*i*i-12*i-9)/(-4*i-4),u=Math.round(r),c=[u>0?i:l,u>1?i:l,u>2?i:l];let p=new Float32Array(t);const m=new Float32Array(n);for(const x of c){const w=(x-1)/2;an(p,m,n,w);const b=p;p=m,m.set(b)}return Array.from(p)}function an(t,s,n,a){const i=a*2+1;let l=0;for(let r=0;r<=a;r++)l+=t[Math.min(r,n-1)];for(let r=0;r<a;r++)l+=t[0];for(let r=0;r<n;r++){s[r]=l/i;const u=r-a,c=r+a+1;l-=t[Math.max(0,Math.min(u,n-1))],l+=t[Math.max(0,Math.min(c,n-1))]}}function rn(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 l=0,r=0;for(let u=0;u<=Math.min(i,n-1);u++)l+=t[u],r++;for(let u=0;u<n;u++){a[u]=l/r;const c=u-i,p=u+i+1;c>=0&&(l-=t[c],r--),p<n&&(l+=t[p],r++)}return Array.from(a)}const ln={ema:1800,ultra:14400},on={ema:"sma",ultra:"gaussian"};function Mt(t,s,n){const a=ln[t],i=on[t]??"sma";if(!a)return{sigma:0,window:1,handleSize:0};let l=Math.round(a/s);l=Math.max(3,Math.min(l,Math.floor(n/3))),l%2===0&&(l+=1);const r=Math.ceil(i==="gaussian"?l*Math.sqrt(4/12)*3:l/2);return i==="gaussian"?{sigma:l*Math.sqrt(.3333333333333333),window:l,handleSize:r}:{sigma:0,window:l,handleSize:r}}function cn(t,s,n,a="ultra",i,l,r){var q;const{buckets:u,visibleStart:c,visibleEnd:p}=t,m=u.length,x=n.length,w=p-c;if(m===0||x===0)return[];const b=r&&i!==void 0&&l!==void 0?(l-i)/r:(q=u[0])!=null&&q.bucketDurationMs?u[0].bucketDurationMs/1e3:240,k=Array.from({length:x},()=>new Array(m).fill(0));for(let I=0;I<m;I++){const j=u[I];if(s==="share"){if(j.total>0)for(let f=0;f<x;f++)k[f][I]=(j.counts[n[f].key]??0)/j.total}else{let f=0;for(let d=0;d<x;d++)f+=j.airtimes[n[d].key]??0;if(f>0)for(let d=0;d<x;d++)k[d][I]=(j.airtimes[n[d].key]??0)/f}}const{sigma:N,window:S}=Mt(a,b,w);let A;N>0?A=k.map(I=>nn(I,N)):A=k.map(I=>rn(I,S));for(let I=0;I<m;I++){let j=0;for(let f=0;f<x;f++)A[f][I]=Math.max(0,A[f][I]),j+=A[f][I];if(j>0){const f=1/j;for(let d=0;d<x;d++)A[d][I]*=f}}const $=w>pt?Math.ceil(w/pt):1,O=Math.ceil(w/$),H=[];for(let I=0;I<O;I++){const j=c+I*$,f=Math.min(c+(I+1)*$,p),d=f-j,y=new Array(x).fill(0);for(let g=j;g<f;g++)for(let R=0;R<x;R++)y[R]+=A[R][g];for(let g=0;g<x;g++)y[g]/=d;let E=0;for(let g=0;g<x;g++)E+=y[g];if(E>0){const g=1/E;for(let R=0;R<x;R++)y[R]*=g}const G={timestamp:u[j].timestamp,time:u[j].time};for(let g=0;g<x;g++)G[n[g].key]=y[g];H.push(G)}return H}const Ye=80;function mn(t,s,n,a,i){const u=Math.max(1,Math.ceil((n-s)/300));if(a==="airtime"){const c=new Float64Array(u);for(const m of t){const x=m.timestamp;if(x<s||x>=n)continue;const w=Math.min(Math.floor((x-s)/300),u-1);c[w]+=we(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=c[m]/3e5*100;x>p&&(p=x)}return Math.max(1,Math.ceil(p*1.1))}else{let c=0;for(const p of t){const m=p.timestamp;if(m<s||m>=n)continue;const x=et(p);x>c&&(c=x)}return c<=240?240:Math.ceil(c*1.1/50)*50}}function dn({packets:t,allPackets:s,startTs:n,endTs:a,parentStartTs:i,parentEndTs:l,bucketCount:r,radioConfig:u=Js,mode:c="share",smoothing:p="stats",noiseFloorAnomalies:m=null,showNoiseFloorOverlay:x=!1,overlayOpacity:w=.5,dotSize:b,dotOpacity:k}){tt(St);const N=Pt(),[S,A]=o.useState(null),[$,O]=o.useState(null),[H,q]=o.useState([]),I=o.useRef(null),j=o.useRef(0);o.useEffect(()=>{const v=Math.abs(t.length-j.current);if(v===0&&H.length>0)return;I.current&&clearTimeout(I.current);const M=v>100?50:Qs;return I.current=setTimeout(()=>{j.current=t.length,q(t)},M),()=>{I.current&&clearTimeout(I.current)}},[t,H.length]);const f=o.useMemo(()=>tn(H,u),[H,u]),d=o.useMemo(()=>{if(p!=="ema"&&p!=="ultra")return 0;const M=(a-n)/r,{handleSize:_}=Mt(p,M,r);return _},[p,n,a,r]),y=o.useMemo(()=>sn(H,n,a,r,u,f,d),[H,n,a,r,u,f,d]),E=o.useMemo(()=>f.reduce((v,M)=>v+M.totalCount,0),[f]),G=o.useMemo(()=>f.reduce((v,M)=>v+M.totalAirtime,0),[f]),{sortedTypes:g,aggregateShares:R}=o.useMemo(()=>{const v=new Map,M=c==="share"?E:G;if(M>0)for(const F of f){const te=c==="share"?F.totalCount:F.totalAirtime;v.set(F.key,te/M)}return{sortedTypes:[...f].sort((F,te)=>(v.get(te.key)??0)-(v.get(F.key)??0)),aggregateShares:v}},[f,E,G,c]),z=o.useMemo(()=>cn(y,c,g,p,n,a,r),[y,c,g,p,n,a,r]),J=o.useCallback(v=>A(v),[]),Z=o.useCallback(v=>O(v),[]),W=o.useCallback(v=>A(v),[]),D=o.useMemo(()=>{if($===null||!z[$])return null;const v=z[$];return{timestamp:v.timestamp,timeLabel:v.time,items:g.map(M=>({key:M.key,label:M.label,value:v[M.key]??0,color:Ae(M.typeNum)}))}},[$,z,g]),K=o.useMemo(()=>{const v=z.map(_=>_.timestamp),M=g.map(_=>({key:_.key,label:_.label,color:Ae(_.typeNum),values:z.map(F=>F[_.key]??0)}));return{timestamps:v,series:M}},[z,g]),se=null,ie=s&&i!==void 0&&l!==void 0&&(n!==i||a!==l),ee=o.useMemo(()=>{if(!(!ie||!s||i===void 0||l===void 0))return mn(s,i,l,c,u)},[ie,s,i,l,c,u]);if(H.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(Ws,{sortedTypes:g,aggregateShares:R,mode:c});const ne=(a-n)/3600,ce=ft(n,ne),U=ft(a,ne);return p==="stats"?e.jsx(Ks,{mode:c,packets:H,startTs:n,endTs:a,radioConfig:u,sortedTypes:g,aggregateShares:R,noiseFloorAnomalies:m,showNoiseFloorOverlay:x,overlayOpacity:w,startLabel:ce,endLabel:U,lockedYMax:ee,legendMinH:Ye,dotSize:b,dotOpacity:k}):p==="trend"?e.jsx(Gs,{packets:H,mode:c,startTs:n,endTs:a,radioConfig:u,bucketCount:r,lockedYMax:ee,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((v,M,_)=>e.jsxs("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${(1-v/100)*100}%`,transform:M===0?"translateY(-100%)":M===_.length-1?"none":"translateY(-50%)",right:0},children:[v,"%"]},v))}),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(Ot,{timestamps:K.timestamps,series:K.series,highlightedKey:S,cursorColor:N.cursor,onHover:Z,onSeriesHover:W,overlayLine:se,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:ce}),e.jsx("span",{children:U})]})]}),e.jsx("div",{style:{minHeight:Ye},children:e.jsx(nt,{sortedTypes:g,highlightedType:S,onTypeHover:J,aggregateShares:R,hoverData:D})})]})}const un=o.memo(dn),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},hn={"1x":1,"2x":2,"4x":4,"8x":8,"16x":16,"36x":36},gt=[1,5,10,25,50,100,150],xn=22.5,Ct=xn*Math.PI/180,bt=Math.sin(Ct),yt=Math.cos(Ct);function pn(t,s,n,a){const i=Math.PI/180,l=(a-s)*i,r=t*i,u=n*i,c=Math.sin(l)*Math.cos(u),p=Math.cos(r)*Math.sin(u)-Math.sin(r)*Math.cos(u)*Math.cos(l);return(Math.atan2(c,p)*180/Math.PI+360)%360}function fn(t,s,n,a){const l=Math.PI/180,r=(n-t)*l,u=(a-s)*l,c=Math.sin(r/2)**2+Math.cos(t*l)*Math.cos(n*l)*Math.sin(u/2)**2;return 6371*2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c))}const gn=[{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 bn(t){var s;return((s=gn.find(n=>t>=n.min))==null?void 0:s.label)??"Critical"}function jt(t,s,n){const a=Wt(t,n);return s[a]||"#808080"}function yn({neighbors:t,quickNeighbors:s,localLat:n,localLon:a,onStatsChange:i,title:l,badge:r,stats:u}){const[c,p]=o.useState(null),[m,x]=o.useState(new Set),[w,b]=o.useState({width:0,height:0}),[k,N]=o.useState("1x"),[S,A]=o.useState(1),$=o.useRef(null),O=o.useRef({}),H=o.useRef(null),q=o.useRef(S);q.current=S;const I=Ft(),j=Ht(),f=Bt(),d=$t(),y=vt(),E=zt(),G=d?f.primary:f.secondary,g=d?.15:.4,R=d?.08:.25,z=d?y.blue:f.primary;o.useEffect(()=>{const h=H.current;if(!h)return;const P=new ResizeObserver(L=>{for(const B of L){const{width:Y,height:Q}=B.contentRect;Y>0&&Q>0&&b({width:Y,height:Q})}});P.observe(h);const T=h.getBoundingClientRect();return T.width>0&&T.height>0&&b({width:T.width,height:T.height}),()=>P.disconnect()},[]);const J=o.useMemo(()=>{const h=new Set;if(s)for(const P of s)h.add(P.hash);return h},[s]),Z=o.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:W,maxDistance:D,totalNeighbors:K,zeroHopCount:se}=o.useMemo(()=>{const h=[];for(const[L,B]of Object.entries(t)){if(!B.latitude||!B.longitude||B.latitude===0||B.longitude===0||!J.has(L))continue;const Q=pn(n,a,B.latitude,B.longitude),ae=fn(n,a,B.latitude,B.longitude),X=Z.get(L);h.push({hash:L.slice(0,8),name:B.node_name||B.name||"Unknown",snr:(X==null?void 0:X.snr)??B.snr??null,rssi:(X==null?void 0:X.rssi)??B.rssi??null,bearing:Q,distance:ae,normalizedDistance:0,lastSeen:B.last_seen,isZeroHop:!0})}const T=(h.length>0?Math.max(...h.map(L=>L.distance)):0)*le.DATA_HEADROOM;return h.sort((L,B)=>(L.snr??-1/0)-(B.snr??-1/0)),{processedNeighbors:h,maxDistance:T,totalNeighbors:h.length,zeroHopCount:h.length}},[t,n,a,J,Z]);o.useEffect(()=>{i==null||i({zeroHopCount:se,totalCount:K,maxDistanceKm:D})},[se,K,D]),o.useEffect(()=>{const h=hn[k],P=q.current;$.current&&cancelAnimationFrame($.current);const T=performance.now(),L=B=>{const Y=B-T,Q=Math.min(Y/Xe.ZOOM_DURATION,1),ae=ms(Q),X=P+(h-P)*ae;A(X),Q<1?$.current=requestAnimationFrame(L):$.current=null};return $.current=requestAnimationFrame(L),()=>{$.current&&cancelAnimationFrame($.current)}},[k]);const ie=D/S,ee=o.useMemo(()=>gt.filter(h=>h<=ie*1.1),[ie]);o.useEffect(()=>{const h=[];for(const T of W){const L=O.current[T.hash];L!==void 0&&L!==T.lastSeen&&h.push(T.hash),O.current[T.hash]=T.lastSeen}if(h.length===0)return;queueMicrotask(()=>{x(T=>new Set([...T,...h]))});const P=setTimeout(()=>{x(T=>{const L=new Set(T);return h.forEach(B=>L.delete(B)),L})},Xe.BLINK_DURATION);return()=>clearTimeout(P)},[W]);const ne=n!==0&&a!==0,ce=o.useMemo(()=>{const{width:h,height:P}=w,T=h/2,L=P/2,B=Math.min(h,P),Y=Math.max(10,B/2-le.PADDING),Q=Math.max(10,Y-le.LABEL_INSET);return{width:h,height:P,centerX:T,centerY:L,radius:Q,labelRadius:Y}},[w]),{width:U,height:v,centerX:M,centerY:_,radius:F,labelRadius:te}=ce,xe=o.useId(),oe=o.useCallback((h,P)=>{const T=h*Math.PI/180;return{x:M+F*P*Math.sin(T),y:_-F*P*Math.cos(T)}},[M,_,F]),ge=o.useCallback(h=>{const T={N:0,NE:45,E:90,SE:135,S:180,SW:225,W:270,NW:315}[h]*Math.PI/180;return{x:M+te*Math.sin(T),y:_-te*Math.cos(T)}},[M,_,te]),Me=o.useCallback(h=>{p(h)},[]),Be=o.useCallback(h=>{N(h)},[]),Te=o.useCallback(h=>D<=0?0:h/D*S,[D,S]),De=h=>`${h}km`,Le=28,Ee=o.useMemo(()=>{const h=[{x:M,y:_-te},{x:M+te*Math.SQRT1_2,y:_-te*Math.SQRT1_2}],P=ee.map(L=>{const B=L/D*S,Y=M+F*B*bt,Q=_-F*B*yt;return{km:L,scale:B,lx:Y,ly:Q}}).filter(L=>L.scale>=.02).sort((L,B)=>B.km-L.km),T=[];for(const L of P){const B=T.some(Q=>{const ae=Q.lx-L.lx,X=Q.ly-L.ly;return Math.sqrt(ae*ae+X*X)<Le}),Y=h.some(Q=>{const ae=Q.x-L.lx,X=Q.y-L.ly;return Math.sqrt(ae*ae+X*X)<Le});!B&&!Y&&T.push(L)}return T},[ee,D,S,M,_,F,te]),Ie=w.width>0&&w.height>0;return ne?K===0?e.jsxs("div",{ref:H,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:H,className:"relative flex-1 min-w-0 h-full overflow-visible -ml-4 sm:-ml-5",children:[Ie&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute depth-stroke-inset",style:{left:M-F-le.LABEL_INSET-4,top:_-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:d?"var(--zinc-925)":"var(--zinc-75)"}}),e.jsxs("svg",{width:U,height:v,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:xe,children:e.jsx("circle",{cx:M,cy:_,r:F})})]}),(()=>{const h=F+le.LABEL_INSET+12,P=d?"rgba(255, 255, 255, 0.12)":"rgba(0, 0, 0, 0.15)",T=d?"rgba(59, 130, 246, 0.4)":"rgba(59, 130, 246, 0.5)",L=6,B=16,Y=4,Q=[0,90,180,270],ae=[45,135,225,315];return e.jsxs("g",{className:"radar-frame","aria-hidden":"true",children:[e.jsx("circle",{cx:M,cy:_,r:h,fill:"none",stroke:P,strokeWidth:1,strokeDasharray:"2 6"}),ae.map(X=>{const re=X*Math.PI/180,de=Math.cos(re),ue=Math.sin(re),pe=h+Y,fe=h+Y+B,Pe=M+pe*ue,C=_-pe*de,V=M+fe*ue,be=_-fe*de;return e.jsxs("g",{children:[e.jsx("line",{x1:Pe,y1:C,x2:V,y2:be,stroke:T,strokeWidth:1}),e.jsx("line",{x1:V-4*de,y1:be-4*ue,x2:V+4*de,y2:be+4*ue,stroke:T,strokeWidth:1})]},`corner-${X}`)}),Q.map(X=>{const re=X*Math.PI/180,de=M+(h-L)*Math.sin(re),ue=_-(h-L)*Math.cos(re),pe=M+(h+2)*Math.sin(re),fe=_-(h+2)*Math.cos(re);return e.jsx("line",{x1:de,y1:ue,x2:pe,y2:fe,stroke:P,strokeWidth:1},`tick-cardinal-${X}`)}),ae.map(X=>{const re=X*Math.PI/180,de=M+(h-4)*Math.sin(re),ue=_-(h-4)*Math.cos(re),pe=M+(h+1)*Math.sin(re),fe=_-(h+1)*Math.cos(re);return e.jsx("line",{x1:de,y1:ue,x2:pe,y2:fe,stroke:P,strokeWidth:1},`tick-intercardinal-${X}`)})]})})(),(()=>{const h=F+le.LABEL_INSET+4,P=[0,...gt.map(T=>{const L=Te(T);return L<=0?0:Math.min(F*L,h)}),h];return P.slice(0,-1).map((T,L)=>{const B=P[L+1],Y=B-T;return Y<.5||L%2!==0?null:e.jsx("circle",{cx:M,cy:_,r:(B+T)/2,fill:"none",stroke:"var(--subtle-fill)",strokeWidth:Y},`band-${L}`)})})(),ee.map(h=>{const P=Te(h);if(P<.02)return null;const T=Ee.some(Y=>Y.km===h),L=M+F*P*bt,B=_-F*P*yt;return e.jsx("g",{children:T&&e.jsx("text",{x:L+4,y:B-2,textAnchor:"start",dominantBaseline:"auto",fill:f.secondary,fontSize:10,fontFamily:$e,children:De(h)})},`ring-${h}`)}),["N","E","S","W"].map(h=>{const T={N:0,E:90,S:180,W:270}[h]*Math.PI/180;return e.jsx("line",{x1:M,y1:_,x2:M+F*Math.sin(T),y2:_-F*Math.cos(T),stroke:G,strokeOpacity:g,strokeWidth:1,strokeDasharray:"4 4"},h)}),["NE","SE","SW","NW"].map(h=>{const T={NE:45,SE:135,SW:225,NW:315}[h]*Math.PI/180;return e.jsx("line",{x1:M,y1:_,x2:M+F*Math.sin(T),y2:_-F*Math.cos(T),stroke:G,strokeOpacity:R,strokeWidth:1,strokeDasharray:"4 4"},`diag-${h}`)}),["N","E","S","W"].map(h=>{const P=ge(h),T=h==="E"?"end":h==="W"?"start":"middle",L=h==="N"?"hanging":h==="S"?"auto":"middle";return e.jsx("text",{x:P.x,y:P.y,textAnchor:T,dominantBaseline:L,fill:z,fontSize:le.CARDINAL_FONT_SIZE,fontWeight:700,fontFamily:$e,"aria-hidden":"true",children:h},h)}),["NE","SE","SW","NW"].map(h=>{const P=ge(h),T=h==="NE"||h==="SE"?"end":"start",L=h==="NE"||h==="NW"?"hanging":"auto";return e.jsx("text",{x:P.x,y:P.y,textAnchor:T,dominantBaseline:L,fill:z,fontSize:le.INTERCARDINAL_FONT_SIZE,fontWeight:600,fontFamily:$e,"aria-hidden":"true",children:h},h)}),e.jsx("circle",{cx:M,cy:_,r:le.LOCAL_DOT_RADIUS,fill:j.chart6,stroke:d?"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(#${xe})`,children:W.map(h=>{const P=D>0?h.distance/D*S:0;if(P>1)return null;const{x:T,y:L}=oe(h.bearing,P),B=h.snr!==null?jt(h.snr,I,E):"#808080",Y=(c==null?void 0:c.hash)===h.hash,Q=m.has(h.hash),ae=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:T,cy:L,r:ae,fill:"none",stroke:d?"rgba(255,255,255,0.9)":"rgba(0,0,0,0.7)",strokeWidth:2,className:"neighbor-blink-ring"}),Y&&e.jsx("circle",{cx:T,cy:L,r:ae,fill:B,opacity:.3}),e.jsx("circle",{cx:T,cy:L,r:Y?le.DOT_RADIUS_HOVERED:le.DOT_RADIUS,fill:B,stroke:d?"rgba(0,0,0,0.5)":"rgba(0,0,0,0.25)",strokeWidth:1,style:{cursor:"pointer",transition:"r 0.15s"},onMouseEnter:()=>Me(h),onMouseLeave:()=>Me(null)})]},h.hash)})})]})]}),c&&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:c.name}),e.jsx("div",{className:"type-data-xs text-fg-secondary",children:c.hash}),c.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(c.snr,I,E)},children:[c.snr.toFixed(1)," dB"]}),e.jsxs("span",{className:"text-fg-secondary ml-1",children:["(",bn(c.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:[c.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:[c.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:[l&&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"})}),r&&e.jsx(_e,{color:"zinc",children:r})]}),e.jsx("span",{className:"type-micro text-left text-[10px] leading-tight px-1",children:l})]}),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:()=>Be(h),"aria-pressed":k===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 ${k===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:H,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 jn=o.memo(yn),Ze={repeater:"var(--sys-blue)",companion:"var(--sys-cyan)",room_server:"var(--sys-indigo)"};function Nn(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 vn({neighbors:t,timeRangeLabel:s}){const n=o.useMemo(()=>{const a={repeater:0,companion:0,room_server:0};for(const r of Object.values(t)){const u=Nn(r);a[u]=(a[u]||0)+1}const i=Object.values(a).reduce((r,u)=>r+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(r=>({...r,percent:i>0?r.count/i*100:0})).filter(r=>r.count>0).sort((r,u)=>u.count-r.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(_e,{color:"zinc",children:s})]}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:n.total})]})]})}const kn=o.memo(vn);function Qe({children:t,minHeight:s="100%",rootMargin:n="200px 0px",keepMounted:a=!0,className:i=""}){const l=o.useRef(null),[r,u]=o.useState(!1),[c,p]=o.useState(!1);o.useEffect(()=>{const x=l.current;if(!x)return;const w=new IntersectionObserver(([b])=>{const k=b.isIntersecting;p(k),k&&u(!0)},{rootMargin:n,threshold:0});return w.observe(x),()=>{w.disconnect()}},[n]);const m=c||a&&r;return e.jsx("div",{ref:l,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 At=[{target:"DisambiguationCard",fn:"disambiguation.collisions",minStage:2}];st(At);const wn=.9,Sn=.7,Mn=.5,Cn=10,An=25,He={excellent:"text-signal-excellent",good:"text-signal-good",fair:"text-signal-fair",poor:"text-sys-blue"},_n={excellent:"bg-signal-excellent/10",good:"bg-signal-good/10",fair:"bg-signal-fair/10",poor:"bg-sys-blue/10"};function Rn(t){return t>=wn?"excellent":t>=Sn?"good":t>=Mn?"fair":"poor"}function Tn(t){return t<=Cn?"excellent":t<=An?"good":"poor"}function Dn(){tt(At);const t=Ut(),s=Gt(),[n,a]=o.useState(null),i=o.useCallback((m,x)=>{a({prefix:m,candidateHashes:x})},[]),l=o.useCallback(()=>{a(null)},[]);if(!s)return e.jsxs(he,{neomorphic:!0,children:[e.jsx(ke,{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(Vt,{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 r=Rn(t.avgConfidence),u=Tn(t.collisionRate),c=r==="poor"||u==="poor"?"poor":r==="fair"||u==="fair"?"fair":r==="good"||u==="good"?"good":"excellent",p=c==="excellent"||c==="good"?ot:it;return e.jsxs(he,{neomorphic:!0,className:"flex flex-col overflow-hidden",children:[e.jsx(ke,{icon:e.jsx(lt,{}),title:"Prefix Conflicts",badgeColor:"zinc",actions:c==="poor"?e.jsxs(_e,{color:"red",children:[e.jsx(it,{className:"w-3 h-3"}),"Needs Attention"]}):e.jsxs("div",{className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full ${_n[c]}`,children:[e.jsx(p,{className:`w-3.5 h-3.5 ${He[c]}`}),e.jsx("span",{className:`type-data-xs font-medium ${He[c]}`,children:c==="excellent"?"Excellent":c==="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(Ue,{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(Ue,{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(Ue,{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:w})=>e.jsxs("button",{type:"button",onClick:()=>i(m,w),className:"inline-flex items-center gap-0.5 group",title:`${x} candidates - click to explore`,children:[e.jsx(qt,{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 ${He[r]}`,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 ${He[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:l})]})}const _t=[{target:"PacketHealth",fn:"type",minStage:1},{target:"PacketHealth",fn:"duplicates",minStage:1}];st(_t);const me=24;function Ln(t,s,n,a){const i=Date.now()/1e3,l=s*60,r=i-l,u=l/me,c=new Array(me).fill(0),p=new Array(me).fill(0),m=new Array(me).fill(0),x=new Array(me).fill(0),w=new Array(me).fill(0),b=new Array(me).fill(0);let k=0,N=0,S=0,A=0,$=0,O=0,H=0;if(a&&a.length>0)for(const g of a){const R=g.timestamp;if(R<r||R>i)continue;H++;const z=Math.min(me-1,Math.floor((R-r)/u));z>=0&&w[z]++}else if(n!=null&&n>0){H=n;const g=n/me;for(let R=0;R<me;R++)w[R]=g}for(const g of t){if(g.packet_origin==="tx_local")continue;const R=g.timestamp;if(R<r||R>i)continue;k++;const z=Math.min(me-1,Math.floor((R-r)/u));p[z]++,g.transmitted||g.packet_origin==="tx_forward"?(N++,c[z]++):g.is_duplicate||g.drop_reason==="Duplicate"?S++:g.drop_reason&&(A++,b[z]++),Xt(g.route??g.route_type)&&($++,m[z]++),g._packetVersion===1&&(O++,x[z]++)}const q=H,I=k+q,j=[],f=[],d=[],y=[],E=[];for(let g=0;g<me;g++){const R=p[g],z=c[g],J=w[g],Z=b[g],W=(r+g*u)*1e3,D=R+J;j.push({count:D>0?z/D*100:0,timestamp:W}),f.push({count:D>0?(Z+J)/D*100:0,timestamp:W}),d.push({count:D>0?J/D*100:0,timestamp:W}),y.push({count:R>0?m[g]/R*100:0,timestamp:W}),E.push({count:R>0?x[g]/R*100:0,timestamp:W})}const G=k-S;return{totalRx:k,uniqueRx:G,forwarded:N,duplicates:S,waste:A,efficiency:I>0?N/I*100:0,duplicateRate:I>0?S/I*100:0,wasteRate:I>0?(A+q)/I*100:0,sparkline:j,wasteSparkline:f,crcSparkline:d,transport:$,v2:O,transportSparkline:y,v2Sparkline:E}}function En({packets:t,rangeMinutes:s,rangeHours:n,timeRangeLabel:a,isLoaded:i=!0}){tt(_t);const[l,r]=o.useState(null),[u,c]=o.useState(null),p=o.useCallback(async()=>{try{const w=await kt(n);if(w.success&&w.data){r(w.data.count??w.data.history.length),c(w.data.history);return}const b=await Kt(n);b.success&&b.data&&(r(b.data.count),c(null))}catch{}},[n]);o.useEffect(()=>{p()},[p]);const m=o.useMemo(()=>Ln(t,s,l,u),[t,s,l,u]),x=m.totalRx>0;return e.jsx(he,{neomorphic:!0,isLoaded:i,skeletonType:"chart",children:i&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{icon:e.jsx(gs,{}),title:"Packet Health",badge:a,badgeColor:"zinc"}),e.jsx(Yt,{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:x?`${m.wasteRate.toFixed(1)}%`:"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(Fe,{data:m.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:l!==null?l:"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(Fe,{data:m.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:x?e.jsxs(e.Fragment,{children:[e.jsx(Oe,{children:m.transport}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(Oe,{children:m.uniqueRx})]}):"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(Fe,{data:m.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:x?e.jsxs(e.Fragment,{children:[e.jsx(Oe,{children:m.v2}),e.jsx("span",{className:"punc-slash",children:"/"}),e.jsx(Oe,{children:m.uniqueRx})]}):"—"})]}),e.jsx("div",{className:"flex-1 min-h-[20px] max-h-[28px] w-full",children:e.jsx(Fe,{data:m.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:x?`${m.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:x?`${m.efficiency.toFixed(1)}%`:"—"})]})]})]})})]})})}function da(){var Ee,Ie,h,P,T,L,B,Y,Q,ae,X,re,de,ue,pe,fe,Pe;const t=Zt(),s=Qt(),n=Jt(),a=es(),i=ts(),l=ss(),r=t!==null&&i,u=o.useRef(!1);r&&!u.current&&(u.current=!0);const c=u.current,p=ns(),m=as(),[x,w]=o.useState([]),[b,k]=o.useState(null),[,N]=o.useState(null),[S]=o.useState(null),[A,$]=o.useState(()=>{const C=localStorage.getItem("statistics-view-mode");return C==="share"||C==="airtime"?C:"airtime"});o.useEffect(()=>{localStorage.setItem("statistics-view-mode",A)},[A]);const[O,H]=o.useState(()=>{const C=localStorage.getItem("statistics-smoothing-mode");return["ema","ultra","mosaic","stats","trend"].includes(C)?C:"stats"});o.useEffect(()=>{localStorage.setItem("statistics-smoothing-mode",O)},[O]);const[q,I]=o.useState(!1),[j,f]=o.useState(!1),[d,y]=o.useState(wt),[E,G]=o.useState(.5),[g,R]=o.useState(bs),[z,J]=o.useState(.5),[Z,W]=o.useState(85),D=o.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]),K=ze[D].hours,se=is(K),ie=K*60,ee=ze[D],ne=rt(K),ce=l.isBackgroundLoading,U=o.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]),v=o.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}},[(Ie=(Ee=t==null?void 0:t.config)==null?void 0:Ee.radio)==null?void 0:Ie.spreading_factor,(P=(h=t==null?void 0:t.config)==null?void 0:h.radio)==null?void 0:P.bandwidth,(L=(T=t==null?void 0:t.config)==null?void 0:T.radio)==null?void 0:L.coding_rate,(Y=(B=t==null?void 0:t.config)==null?void 0:B.radio)==null?void 0:Y.preamble_length]);o.useEffect(()=>{kt(K).then(C=>{C.success&&C.data?w(C.data.history.map(V=>V.timestamp)):w([])})},[K]);const M=o.useMemo(()=>se.length===0?{timestamps:[],values:[]}:{timestamps:se.map(C=>C.timestamp),values:se.map(C=>C.noise_floor_dbm)},[se]),_=o.useMemo(()=>{if(se.length<10)return{anomalies:[],debug:void 0};const C=Ls(se,d);return{anomalies:C.anomalies,debug:C.debug}},[se,d]),F=_.anomalies,te=o.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]),xe=o.useMemo(()=>{const C=Date.now()/1e3-K*3600;return Object.fromEntries(Object.entries(te).filter(([,V])=>V.last_seen>=C))},[te,K]),oe=o.useMemo(()=>{const C=ie*60/ne,V=Math.floor(Date.now()/1e3),be=Math.floor(V/C)*C;return{start:be-ie*60,end:be}},[ie,ne]),ge=g.timeStart??oe.start,Me=g.timeEnd??oe.end,Be=(Me-ge)/3600,Te=rt(Be),De=Ns(),Le=o.useMemo(()=>ys(a,g,De,oe),[a,g,De,oe]);return e.jsxs(hs,{children:[e.jsx(xs,{title:"Statistics",icon:e.jsx(rs,{}),subtitle:e.jsx(us,{}),controls:e.jsx(ds,{ranges:ze,selectedIndex:D,onSelect:U,isPending:ce})}),S&&e.jsx(he,{className:"border border-sys-red/50 bg-sys-red/10",children:e.jsx("p",{className:"text-sys-red",children:S})}),q&&j&&e.jsxs(he,{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:["(",ee.label,")"]})]}),e.jsx("button",{onClick:()=>y(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:[((ae=(Q=_.debug)==null?void 0:Q.baselineCutoff)==null?void 0:ae.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:[((re=(X=_.debug)==null?void 0:X.spikeCutoff)==null?void 0:re.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:((de=_.debug)==null?void 0:de.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:[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=>y(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=>y(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=>y(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=>y(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=>y(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(E*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:E,onChange:C=>G(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=>y(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=>y(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=>y(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=>y(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=>y(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(E*100),"%)"]}),e.jsx("input",{type:"range",min:"0.1",max:"1",step:"0.05",value:E,onChange:C=>G(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(ps,{ready:c,children:[e.jsx("div",{className:"sm:hidden",children:ce&&e.jsx(je,{template:"auto",children:e.jsx(he,{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 ",ee.label," data..."]}),l.loadProgress&&e.jsxs("p",{className:"type-data-xs text-fg-muted mt-0.5",children:[l.loadProgress.loaded.toLocaleString()," packets (",l.loadProgress.percent,"%)"]})]})]})})})}),e.jsxs(e.Fragment,{children:[e.jsx(je,{template:"hero-auto",children:e.jsx(he,{neomorphic:!0,skeletonType:"chart",children:c&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{icon:e.jsx(Se,{}),title:"Packet Analyzer",badge:ee.label,badgeColor:"zinc",stackActionsOnMobile:!0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:[O==="stats"&&e.jsx(Zs,{enabled:q,onChange:I,anomalyCount:F.length,showTuning:j,onTuningChange:f}),e.jsx(Xs,{smoothing:O,onChange:H}),e.jsx(Ys,{mode:A,onChange:$})]})}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(un,{packets:Le,allPackets:a,startTs:ge,endTs:Me,parentStartTs:oe.start,parentEndTs:oe.end,bucketCount:Te,radioConfig:v??void 0,mode:A,smoothing:O,noiseFloorAnomalies:F,showNoiseFloorOverlay:q,overlayOpacity:E,dotSize:z,dotOpacity:Z/100})})]})})}),e.jsx(je,{template:"auto",className:"relative z-10",children:e.jsx(he,{neomorphic:!0,noPadding:!0,className:"overflow-visible",children:c&&e.jsx(js,{parentStartTs:oe.start,parentEndTs:oe.end,neighbors:te,filter:g,onChange:R,...O==="stats"?{scatterDotSize:z,onScatterDotSizeChange:J,scatterOpacity:Z,onScatterOpacityChange:W}:{}})})}),e.jsxs(je,{template:"panel",children:[e.jsx(Ce,{span:12,md:6,children:e.jsx(he,{neomorphic:!1,skeletonType:"chart",noPadding:c,className:"!bg-transparent !ring-0 !shadow-none !overflow-visible -mx-4 sm:mx-0 !px-0 !pr-0",children:c&&e.jsx(Qe,{children:e.jsx(jn,{neighbors:xe,quickNeighbors:n,localLat:((pe=(ue=t==null?void 0:t.config)==null?void 0:ue.repeater)==null?void 0:pe.latitude)??0,localLon:((Pe=(fe=t==null?void 0:t.config)==null?void 0:fe.repeater)==null?void 0:Pe.longitude)??0,onStatsChange:N,title:"Link Quality",badge:ee.label})})})}),e.jsx(Ce,{span:12,md:6,children:e.jsx(he,{neomorphic:!0,skeletonType:"chart",children:c&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{icon:e.jsx(ks,{}),title:"Network Composition",badge:ee.label,badgeColor:"zinc"}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Qe,{children:e.jsx(kn,{neighbors:xe,timeRangeLabel:ee.label})})})]})})})]}),e.jsxs(je,{template:"panel",children:[e.jsx(Ce,{span:12,md:6,children:e.jsx(Dn,{})}),e.jsx(Ce,{span:12,md:6,children:e.jsx(En,{packets:a,rangeMinutes:ie,rangeHours:K,timeRangeLabel:ee.label})})]}),e.jsx(je,{template:"panel",children:e.jsx(Ce,{span:12,children:e.jsx(he,{neomorphic:!0,skeletonType:"chart",children:c&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{icon:e.jsx(ls,{}),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(Qe,{children:e.jsx(os,{timestamps:M.timestamps,values:M.values,onStatsChange:k,crcTimestamps:x})})})]})})})})]})]})]})}export{da as default};
