const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BuFgUdF6.js","assets/index-C9lzYVvf.css"])))=>i.map(i=>d[i]);
import{e as Z,f as bs,h as Dt,k as Rt,J as js,n as ws,o as Ns,p as Ee,q as vs,r as f,M as ks,t as Ms,_ as st,v as nt,w as At,x as Pt,y as Cs,z as te,D as Ts,j as t,d as Ke,m as ge,S as Lt,E as $t,U as Ss,F as _s,G as Pe,P as Bs,H as Ds,K as Q,L as Rs,N as As,O as Y,Q as we,R as Ft,T as Et,V as ne,W as Ps,X as Ls,Y as je,$ as $s,a0 as at,a1 as Fs,a2 as Le,a3 as Es,a4 as Is,a5 as Hs,a6 as ie,a7 as It,a8 as Ht,a9 as zs,B as $e,aa as zt,ab as Ot,ac as Os,ad as Ne,ae as ee,af as Gt,ag as Wt,ah as Gs,ai as Ws,aj as qs,ak as Xs,al as Us,am as Ie,u as qt,an as Vs,ao as ot,ap as me,aq as Me,ar as Xt,as as Ys,at as Ce,au as Js,av as Zs,aw as Ks,ax as rt,ay as Qs,c as J,az as en,aA as Ut,aB as it,aC as Vt,aD as Yt,aE as tn,aF as ve,aG as sn,aH as nn,aI as an,aJ as Qe,aK as on,aL as Jt,aM as Zt,aN as rn,aO as ln,Z as lt,aP as cn,aQ as dn,aR as un,aS as ct}from"./index-BuFgUdF6.js";import{C as dt,P as mn,a as fn,B as pn}from"./PageLayout-DKfh0Blq.js";import{u as fe,r as pe,h as hn,a as xn,b as gn,i as yn}from"./consumer-registry-YGO4kl9s.js";import{A as re,D as Ye}from"./DataValue-LCAdfD-L.js";import{c as bn}from"./node-types-DgK-t_34.js";import{b as Kt,c as ye,a as jn,d as wn,F as Te}from"./meshcore-tx-constants-DgpFTAmf.js";import{S as Nn,u as Je,P as vn,T as kn,C as Qt}from"./PacketList-MBM6Eu99.js";import{useGetDecodedContent as Mn,useResolveSource as Cn}from"./usePipelineStore-Chyk9TCr.js";import{A as ut}from"./arrow-right-DMRkyqKR.js";import{T as es,M as Tn}from"./MqttModeBadge-BeRzf62U.js";import{L as ts}from"./LightSparkline-D-p7t3p_.js";import{c as Sn}from"./link-scoring-DMBYgePn.js";import{Z as _n}from"./zap-CcGk7ixp.js";import{A as Bn,N as Dn}from"./AutoConfigureDialog-BFchIKu3.js";import{g as Rn,e as He,a as An,f as Pn}from"./chat-utils-DXcrFuPC.js";import{C as Ln}from"./ChatBubble-DmijBf8_.js";import{M as ss}from"./message-square-text-DfGKmQJa.js";import{C as mt}from"./chevron-right-Bn33xBBB.js";import{H as $n}from"./hash-B0n1oBpr.js";import{M as Fn}from"./message-square-Ct41fk6H.js";import{S as En}from"./shield-check-DDpvzgE3.js";import{W as In}from"./wand-sparkles-MByCKABI.js";import{u as ue}from"./index-tC-yebOi.js";import{H as Hn}from"./useMapViewStore-CYTMhi1e.js";import{R as ft}from"./Grid-CVvPTnwu.js";import"./chevron-up-DLh9FCfg.js";import"./primitives-BvUzgqAa.js";import"./badge-colors-Dl76Mz8m.js";import"./SignalIndicator-DlCNJ53K.js";import"./arrow-up-m4nuWusa.js";import"./arrow-down-P3Gn06Ex.js";import"./payload-detail-C-jD4akC.js";import"./map-pin-DUIK7gpx.js";import"./circle-question-mark-NwPFAIxO.js";import"./layers-BrblF2UQ.js";import"./clock-CiO_tPRQ.js";import"./route-D01DJn_x.js";import"./activity-CU9M_dkq.js";import"./database-6NHqXCMW.js";import"./shield-BMVOQHpc.js";import"./index-CjY609r3.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 zn=[["path",{d:"M15 11a1 1 0 0 0 1 1h2.939a1 1 0 0 1 .75 1.811l-6.835 6.836a1.207 1.207 0 0 1-1.707 0L4.31 13.81a1 1 0 0 1 .75-1.811H8a1 1 0 0 0 1-1V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1z",key:"1eaqc3"}]],pt=Z("arrow-big-down",zn);/**
 * @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 On=[["path",{d:"M9 13a1 1 0 0 0-1-1H5.061a1 1 0 0 1-.75-1.811l6.836-6.835a1.207 1.207 0 0 1 1.707 0l6.835 6.835a1 1 0 0 1-.75 1.811H16a1 1 0 0 0-1 1v6a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1z",key:"lh0v7k"}]],ht=Z("arrow-big-up",On);/**
 * @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 Gn=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],ns=Z("chart-column",Gn);/**
 * @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 Wn=[["line",{x1:"12",x2:"18",y1:"12",y2:"18",key:"1rg63v"}],["line",{x1:"12",x2:"18",y1:"18",y2:"12",key:"ebkxgr"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],qn=Z("copy-x",Wn);/**
 * @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 Xn=[["path",{d:"m21.12 6.4-6.05-4.06a2 2 0 0 0-2.17-.05L2.95 8.41a2 2 0 0 0-.95 1.7v5.82a2 2 0 0 0 .88 1.66l6.05 4.07a2 2 0 0 0 2.17.05l9.95-6.12a2 2 0 0 0 .95-1.7V8.06a2 2 0 0 0-.88-1.66Z",key:"1u2ovd"}],["path",{d:"M10 22v-8L2.25 9.15",key:"11pn4q"}],["path",{d:"m10 14 11.77-6.87",key:"1kt1wh"}]],Un=Z("cuboid",Xn);/**
 * @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 Vn=[["path",{d:"M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0",key:"1dfaln"}],["path",{d:"M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4",key:"1qnva7"}]],as=Z("ear",Vn);/**
 * @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 Yn=[["path",{d:"M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z",key:"q8bfy3"}],["path",{d:"M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14",key:"1853fq"}],["path",{d:"M8 6v8",key:"15ugcq"}]],Jn=Z("megaphone",Yn);/**
 * @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 Zn=[["path",{d:"M18 11h-4a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1h4",key:"17ldeb"}],["path",{d:"M6 7v13a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7",key:"nc37y6"}],["rect",{width:"16",height:"5",x:"4",y:"2",rx:"1",key:"3jeezo"}]],Kn=Z("pill-bottle",Zn);/**
 * @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 Qn=[["path",{d:"M4 10a7.31 7.31 0 0 0 10 10Z",key:"1fzpp3"}],["path",{d:"m9 15 3-3",key:"88sc13"}],["path",{d:"M17 13a6 6 0 0 0-6-6",key:"15cc6u"}],["path",{d:"M21 13A10 10 0 0 0 11 3",key:"11nf8s"}]],ea=Z("satellite-dish",Qn);/**
 * @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 ta=[["path",{d:"m12.5 17-.5-1-.5 1h1z",key:"3me087"}],["path",{d:"M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z",key:"1o5pge"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}]],os=Z("skull",ta);/**
 * @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 sa=[["circle",{cx:"7",cy:"7",r:"5",key:"x29byf"}],["circle",{cx:"17",cy:"17",r:"5",key:"1op1d2"}],["path",{d:"M12 17h10",key:"ls21zv"}],["path",{d:"m3.46 10.54 7.08-7.08",key:"1rehiu"}]],na=Z("tablets",sa);/**
 * @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 aa=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],oa=Z("timer",aa);function ra(...e){const n=!Array.isArray(e[0]),o=n?0:-1,s=e[0+o],r=e[1+o],a=e[2+o],c=e[3+o],i=bs(r,a,c);return n?i(s):i}function ia(e,n,o={}){const s=e.get();let r=null,a=s,c;const i=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,d=()=>{r&&(r.stop(),r=null)},u=()=>{d();const m=gt(e.get()),j=gt(a);m!==j&&(r=new js({keyframes:[m,j],velocity:e.getVelocity(),type:"spring",restDelta:.001,restSpeed:.01,...o,onUpdate:c}))};if(e.attach((m,j)=>{a=m,c=l=>j(xt(l,i)),Dt.postRender(()=>{var l;u(),(l=e.events.animationStart)==null||l.notify(),r==null||r.then(()=>{var x;(x=e.events.animationComplete)==null||x.notify()})})},d),Rt(n)){const m=n.on("change",l=>e.set(xt(l,i))),j=e.on("destroy",m);return()=>{m(),j()}}return d}function xt(e,n){return n?e+n:e}function gt(e){return typeof e=="number"?e:parseFloat(e)}function rs(e,n){const o=ue(n()),s=()=>o.set(n());return s(),ws(()=>{const r=()=>Dt.preRender(s,!1,!0),a=e.map(c=>c.on("change",r));return()=>{a.forEach(c=>c()),Ns(s)}}),o}function la(e){Ee.current=[],e();const n=rs(Ee.current,e);return Ee.current=void 0,n}function ca(e,n,o,s){if(typeof e=="function")return la(e);const a=ra(n,o,s);return Array.isArray(e)?yt(e,a):yt([e],([c])=>a(c))}function yt(e,n){const o=vs(()=>[]);return rs(e,()=>{o.length=0;const s=e.length;for(let r=0;r<s;r++)o[r]=e[r].get();return n(o)})}function da(e,n={}){const{isStatic:o}=f.useContext(ks),s=()=>Rt(e)?e.get():e;if(o)return ca(s);const r=ue(s());return f.useInsertionEffect(()=>ia(r,e,n),[r,JSON.stringify(n)]),r}function Se(e,n={}){return da(e,{type:"spring",...n})}const oe=Ms(()=>({result:null,isComputing:!1})),ua=500,ma=300;let ce=null,_e=null;function fa(e){var o;const n=(o=e==null?void 0:e.config)==null?void 0:o.radio;return`${(n==null?void 0:n.spreading_factor)??7}:${(n==null?void 0:n.bandwidth)??125e3}:${(n==null?void 0:n.coding_rate)??5}:${(n==null?void 0:n.preamble_length)??8}`}function pa(){if(ce)return ce;if(typeof window>"u")return null;try{ce=new Worker(new URL("/assets/dashboard-bucketing.worker-BwrZMAuc.js",import.meta.url),{type:"module"}),ce.onmessage=e=>{if(e.data.type==="error"){console.error("[DashboardBucketing] Worker error:",e.data.error),oe.setState({isComputing:!1});return}oe.setState({result:e.data.payload,isComputing:!1})},ce.onerror=e=>{console.error("[DashboardBucketing] Worker error:",e),oe.setState({isComputing:!1})}}catch(e){console.error("[DashboardBucketing] Failed to init worker:",e)}return ce}function ha(e,n,o,s){const r=pa();if(!r)return;const a=e.length,c=new Float64Array(a),i=new Float64Array(a),d=new Uint16Array(a),u=new Uint8Array(a),m=new Uint8Array(a),j=new Uint8Array(a),l=new Uint8Array(a),x=new Float32Array(a),N=new Float32Array(a),h=new Uint32Array(a),y=new Map;let C=0;for(let B=0;B<a;B++){const v=e[B];c[B]=v.timestamp??0,i[B]=At(v,s),d[B]=Math.min(v.length??v.payload_length??0,65535),u[B]=(v.type??v.payload_type??0)&15;const w=v.packet_origin;m[B]=w==="tx_local"?1:w==="tx_forward"?2:0,j[B]=v.transmitted?1:0,l[B]=v.drop_reason?1:0,x[B]=v.snr??0,N[B]=v.rssi??0;const b=v.packet_hash??"";let p=y.get(b);p===void 0&&(p=C++,y.set(b,p)),h[B]=p}oe.setState({isComputing:!0});const T={type:"compute",payload:{timestamps:c,airtimeMs:i,byteSizes:d,payloadTypes:u,origins:m,transmitted:j,dropped:l,snrValues:x,rssiValues:N,hashIndices:h,rangeMinutes:n,bucketCount:o}};r.postMessage(T,[c.buffer,i.buffer,d.buffer,u.buffer,m.buffer,j.buffer,l.buffer,x.buffer,N.buffer,h.buffer])}function ze(e){return Object.keys(e).map(n=>parseInt(n,10)).filter(n=>e[n]>0).sort((n,o)=>e[o]-e[n])}function xa(e,n,o){const s={...e,received:[...e.received],unique_received:[...e.unique_received],transmitted:[...e.transmitted],forwarded:[...e.forwarded],dropped:[...e.dropped],receivedBytesBuckets:e.receivedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType},countByType:{...m.countByType}})),forwardedBytesBuckets:e.forwardedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType},countByType:{...m.countByType}})),droppedBytesBuckets:e.droppedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType},countByType:{...m.countByType}})),receivedTotalByType:{...e.receivedTotalByType},receivedCountByType:{...e.receivedCountByType},forwardedTotalByType:{...e.forwardedTotalByType},droppedTotalByType:{...e.droppedTotalByType}},{start_time:r,end_time:a,bucket_duration_seconds:c,bucket_count:i}=e,d=new Set;for(const m of n){const j=m.timestamp??0;if(j<r||j>a)continue;const l=Math.floor((j-r)/c);if(l<0||l>=i)continue;d.has(l)||(d.add(l),s.received[l]={...s.received[l]},s.unique_received[l]={...s.unique_received[l]},s.transmitted[l]={...s.transmitted[l]},s.forwarded[l]={...s.forwarded[l]},s.dropped[l]={...s.dropped[l]});const x=At(m,o),N=m.length??m.payload_length??0,h=m.type??m.payload_type??0,y=m.packet_origin;y==="tx_local"?(s.transmitted[l].count++,s.transmitted[l].airtime_ms+=x):y==="tx_forward"||m.transmitted?(s.forwarded[l].count++,s.forwarded[l].airtime_ms+=x,s.forwardedBytesBuckets[l].bytesByType[h]=(s.forwardedBytesBuckets[l].bytesByType[h]??0)+N,s.forwardedBytesBuckets[l].totalBytes+=N,s.forwardedBytesBuckets[l].countByType[h]=(s.forwardedBytesBuckets[l].countByType[h]??0)+1,s.forwardedBytesBuckets[l].totalCount++,s.forwardedTotalByType[h]=(s.forwardedTotalByType[h]??0)+N,s.totalForwardedCount++):m.drop_reason&&(s.dropped[l].count++,s.dropped[l].airtime_ms+=x,s.droppedBytesBuckets[l].bytesByType[h]=(s.droppedBytesBuckets[l].bytesByType[h]??0)+N,s.droppedBytesBuckets[l].totalBytes+=N,s.droppedBytesBuckets[l].countByType[h]=(s.droppedBytesBuckets[l].countByType[h]??0)+1,s.droppedBytesBuckets[l].totalCount++,s.droppedTotalByType[h]=(s.droppedTotalByType[h]??0)+N,s.totalDroppedCount++),y!=="tx_local"&&(s.received[l].count++,s.received[l].airtime_ms+=x,s.unique_received[l].count++,s.unique_received[l].airtime_ms+=x,s.receivedBytesBuckets[l].bytesByType[h]=(s.receivedBytesBuckets[l].bytesByType[h]??0)+N,s.receivedBytesBuckets[l].totalBytes+=N,s.receivedBytesBuckets[l].countByType[h]=(s.receivedBytesBuckets[l].countByType[h]??0)+1,s.receivedBytesBuckets[l].totalCount++,s.receivedTotalByType[h]=(s.receivedTotalByType[h]??0)+N,s.receivedCountByType[h]=(s.receivedCountByType[h]??0)+1,s.totalReceivedBytes+=N)}const u=s.time_range_minutes/60;return s.kbPerHour=u>0?Math.round(s.totalReceivedBytes/1024/u):0,s.forwardedRatePerHour=u>0?Math.round(s.totalForwardedCount/u):0,s.droppedRatePerHour=u>0?Math.round(s.totalDroppedCount/u):0,s.receivedActiveTypes=ze(s.receivedTotalByType),s.forwardedActiveTypes=ze(s.forwardedTotalByType),s.droppedActiveTypes=ze(s.droppedTotalByType),s}typeof window<"u"&&Promise.all([st(()=>import("./index-BuFgUdF6.js").then(e=>e.ho),__vite__mapDeps([0,1])),st(()=>import("./index-BuFgUdF6.js").then(e=>e.hn),__vite__mapDeps([0,1]))]).then(([e,n])=>{const{DASHBOARD_TIME_RANGES:o}=n;let s=0,r=-1,a="";e.useStore.subscribe(c=>{const i=c.packets.length,d=c.globalTimeRangeIndex,u=fa(c.stats);if(i===s&&d===r&&u===a)return;const m=s,j=r,l=a;if(s=i,r=d,a=u,i===0)return;const x=o[d]??o[4],N=x.minutes,h=x.buckets,y=c.stats,C=nt(y),T=i-m,B=d!==j,v=u!==l,w=oe.getState().result;if(!B&&!v&&T>0&&T<ua&&w!==null&&w.time_range_minutes===N&&w.bucket_count===h){const p=c.packets.slice(i-T),_=xa(w,p,C);oe.setState({result:_})}else _e&&clearTimeout(_e),_e=setTimeout(()=>{_e=null;const p=e.useStore.getState();if(p.packets.length===0||!p.stats)return;const _=o[p.globalTimeRangeIndex]??o[4],k=nt(p.stats);ha(p.packets,_.minutes,_.buckets,k)},ma)})});const ga=()=>oe(e=>e.result),is=[{target:"ReceivedChart",fn:"type",minStage:1},{target:"ReceivedChart",fn:"airtime",minStage:1,when:hn}];pe(is);function ya(e){const o=new Date(e*1e3).getHours();return o>=6&&o<18}function bt(e){return new Date(e*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})}const he=32,Oe=20,ba=[.25,.5,.75,1];function ja({buckets:e,activeTypes:n,totalByType:o,mode:s="bytes"}){fe(is);const r=Pt(),[a,c]=f.useState(null),[i,d]=f.useState(null),[u,m]=f.useState(null),j=f.useCallback((v,w,b)=>{c(w),d(b)},[]),l=e.length>0&&n.length>0,x=a?ya(a.start):null,N=a?bt(a.start):"",h=u!==null&&x!==null&&u!==x;x!==u&&m(x);const y=f.useMemo(()=>Cs(e),[e]),C=s==="count"?te:Ts,T=f.useMemo(()=>y===0?[]:ba.map(v=>({pct:v,label:C(Math.round(y*v)),pos:(1-v)*100})),[y,C]),B=f.useMemo(()=>{if(e.length===0)return[];const v=e.length,w=Math.max(1,Math.floor(v/6)),b=[];for(let p=0;p<v;p+=w)b.push({label:bt(e[p].start),pos:(p+.5)/v*100});return b},[e]);return t.jsxs("div",{className:"flex flex-col h-full relative",children:[t.jsx("div",{className:"h-5 relative mb-1 shrink-0",children:a&&i!==null&&t.jsxs("div",{className:"absolute flex items-center gap-1.5 type-data-sm -translate-x-1/2",style:{left:`calc(${he}px + ${i*100}% * (1 - ${he}px / 100%))`},children:[t.jsx(Ke,{mode:"wait",children:t.jsx(ge.span,{initial:h?{opacity:0,scale:.5,rotate:-90}:!1,animate:{opacity:1,scale:1,rotate:0},exit:{opacity:0,scale:.5,rotate:90},transition:{duration:.25,ease:"easeOut"},children:x?t.jsx(Lt,{className:"w-4 h-4 text-sys-amber"}):t.jsx($t,{className:"w-4 h-4 text-sys-blue"})},x?"sun":"moon")}),t.jsx("span",{className:"text-fg-secondary",children:N})]})}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsx("div",{className:"absolute top-0 left-0 flex flex-col justify-between",style:{width:he,bottom:Oe},"aria-hidden":"true",children:T.map(({pct:v,label:w,pos:b})=>t.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${b}%`,transform:v===1?"none":"translateY(-50%)",right:0},children:w},v))}),t.jsx("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:he,right:0,top:0,bottom:Oe},children:l&&t.jsx(Ss,{buckets:e,activeTypes:n,gridColor:r.grid,axisTickColor:r.axisTick,onHover:j,yAxisFormat:s,externalAxes:!0})}),t.jsx("div",{className:"absolute left-0 right-0 bottom-0 pointer-events-none",style:{left:he,height:Oe},"aria-hidden":"true",children:B.map((v,w)=>t.jsx("span",{className:"type-data-xs text-fg-secondary absolute top-1",style:{left:`${v.pos}%`,transform:w===0?"none":w===B.length-1?"translateX(-100%)":"translateX(-50%)"},children:v.label},w))})]}),t.jsx("div",{className:"pt-2 px-1 pb-2 shrink-0",children:l&&t.jsx(_s,{activeTypes:n,totalByType:o,formatMode:s})})]})}const jt={top:8,right:8,bottom:28,left:48},wt={top:0,right:0,bottom:0,left:0};let Be=null,Nt=0;const wa=1e3;function Na(){const e=performance.now();return Be&&e-Nt<wa||(Be=getComputedStyle(document.documentElement).getPropertyValue("--font-data").trim()||'"JetBrains Mono", ui-monospace, monospace',Nt=e),Be}const Fe=.15;function va(e,n,o,s,r,a,c,i){const d=n.length,u=window.devicePixelRatio||1,m=Math.round(1*u),j=(i-m)/2;if(d===0||s.length===0)return{baselineY:a+j+m/2,fwdHalf:j,drpHalf:j,fwdCeil:1,drpCeil:1,gapPx:m};const l=c/d,x=new Float64Array(d),N=new Float64Array(d);let h=0,y=0;for(let g=0;g<d;g++){let D=0,P=0;const R=n[g].countByType,L=o[g].countByType;for(const S of s)D+=R[S]??0,P+=L[S]??0;x[g]=D,N[g]=P,D>h&&(h=D),P>y&&(y=P)}h===0&&y===0?(h=1,y=1):h===0?h=1:y===0&&(y=1);const C=h*1.05,T=y*1.05,B=C+T;let v=C/B;v=Math.max(Fe,Math.min(1-Fe,v));const w=i-m,b=v*w,p=(1-v)*w,_=a+b,k=a+b+m,A=a+b+m/2;for(let g=0;g<d;g++){const D=r+g*l;let P=_;const R=n[g].countByType;if(x[g]>0)for(const F of s){const M=R[F]??0;if(M===0)continue;const $=M/C*b,E=P-$;e.fillStyle=Pe(F),e.fillRect(D,E,l,$),P=E}let L=k;const S=o[g].countByType;if(N[g]>0){const F=S[Q]??0;if(F>0){const M=F/T*p;e.fillStyle=Pe(Q),e.fillRect(D,L,l,M),L+=M}for(const M of s){if(M===Q)continue;const $=S[M]??0;if($===0)continue;const E=$/T*p;e.fillStyle=Pe(M),e.fillRect(D,L,l,E),L+=E}}}return{baselineY:A,fwdHalf:b,drpHalf:p,fwdCeil:C,drpCeil:T,gapPx:m}}function ka(e,n,o,s,r,a,c,i,d,u,m=!1){if(n.length===0)return;const{baselineY:j,fwdHalf:l,drpHalf:x,fwdCeil:N,drpCeil:h,gapPx:y}=d,C=Na(),T=j-Math.ceil(y/2),B=j+Math.floor(y/2);e.save(),e.strokeStyle=c,e.lineWidth=1*u,e.setLineDash([]);const v=[.5,1];for(const w of v){const b=Math.round(T-w*l)+.5;e.beginPath(),e.moveTo(o,b),e.lineTo(o+r,b),e.stroke();const p=Math.round(B+w*x)+.5;e.beginPath(),e.moveTo(o,p),e.lineTo(o+r,p),e.stroke()}if(e.restore(),e.clearRect(o,j-Math.ceil(y/2),r,y),!m){e.save(),e.font=`bold ${10*u}px ${C}`,e.textAlign="left";const w=4*u,b=2*u;for(const p of v){const _=Math.round(N*p),k=Math.round(h*p),A=p===1,g=T-p*l,D=B+p*x;_>0&&(e.fillStyle=Y.green,e.globalAlpha=.7,A?(e.textBaseline="top",e.fillText(te(_),w,g+b)):(e.textBaseline="middle",e.fillText(te(_),w,g))),k>0&&(e.fillStyle=Y.red,e.globalAlpha=.7,A?(e.textBaseline="bottom",e.fillText(te(k),w,D-b)):(e.textBaseline="middle",e.fillText(te(k),w,D)))}e.globalAlpha=1,e.restore()}if(!m){e.save(),e.font=`${12*u}px ${C}`,e.fillStyle=i,e.textBaseline="top",e.textAlign="center";const w=8*u,b=n.length,p=Math.max(1,Math.floor(b/6)),_=r/b;for(let k=0;k<b;k+=p){const A=o+k*_+_/2,D=new Date(n[k].start*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1});e.fillText(D,A,s+a+w)}e.restore()}}function Ma({allTypes:e,forwardedTotalByType:n,droppedTotalByType:o}){return t.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1 font-mono text-xs",children:e.map(s=>{const r=n[s]??0,a=o[s]??0;if(r===0&&a===0)return null;const c=s===Q?"CRC":Bs[s]??`TYPE_${s}`;return t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:"shrink-0 w-3 h-3 rounded-xs",style:{backgroundColor:Pe(s)}}),t.jsx("span",{className:"text-fg-secondary whitespace-nowrap",children:c}),t.jsxs("span",{className:"tabular-nums",children:[t.jsxs("span",{className:"text-sys-green",children:["▲",te(r)]})," ",t.jsxs("span",{className:"text-sys-red",children:["▼",te(a)]})]})]},s)})})}function Ca(e,n,o){const s=e.length;let r=0,a=0;for(let m=0;m<s;m++){let j=0,l=0;for(const x of o)j+=e[m].countByType[x]??0,l+=n[m].countByType[x]??0;j>r&&(r=j),l>a&&(a=l)}r===0&&a===0?(r=1,a=1):r===0?r=1:a===0&&(a=1);const c=r*1.05,i=a*1.05,d=c+i;let u=c/d;return u=Math.max(Fe,Math.min(1-Fe,u)),{fwdMax:Math.round(c),drpMax:Math.round(i),fwdFrac:u}}function Ta({forwardedBuckets:e,droppedBuckets:n,allTypes:o,onHover:s,gridColor:r,axisTickColor:a,externalAxes:c=!1}){const i=f.useRef(null),d=f.useRef(null),u=f.useRef(e),m=f.useRef(n),j=f.useRef(o),l=f.useRef(c);u.current=e,m.current=n,j.current=o,l.current=c;const x=c?wt:jt,N=typeof document<"u"&&document.documentElement.dataset.mode!=="light",h=r||(N?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"),y=a||(N?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.6)"),C=f.useRef({gridColor:h,axisTickColor:y});C.current={gridColor:h,axisTickColor:y};const T=e.length,B=f.useMemo(()=>{const b=e.map(_=>_.start),p=e.map(()=>1);return[b,p]},[T]),v=f.useCallback(b=>{if(!i.current||e.length===0)return;const p=i.current.getBoundingClientRect(),_=b.clientX-p.left,k=c?wt:jt,A=k.left,g=p.width-k.left-k.right,P=(_-A)/g;if(P<0||P>1){s==null||s(null,null,null);return}const R=Math.min(e.length-1,Math.max(0,Math.floor(P*e.length)));s==null||s(R,e[R],P)},[e,s]),w=f.useCallback(()=>{s==null||s(null,null,null)},[s]);return f.useEffect(()=>{if(!i.current||T===0)return;const b=i.current;let p=null;const _=Ds(()=>{const k=b.getBoundingClientRect(),A=Math.floor(k.width)||400,g=Math.floor(k.height)||200,D={width:A,height:g,padding:[x.top,x.right,x.bottom,x.left],cursor:{show:!1},scales:{x:{time:!1},y:{range:[0,1]}},axes:[{show:!1},{show:!1}],series:[{},{show:!1}],legend:{show:!1},hooks:{draw:[R=>{const L=R.ctx,{left:S,top:F,width:M,height:$}=R.bbox,E=window.devicePixelRatio||1,W=C.current,I=u.current;I.length>=2&&As(L,I[0].start,I[I.length-1].end,S,F,M,$);const O=va(L,u.current,m.current,j.current,S,F,M,$);ka(L,u.current,S,F,M,$,W.gridColor,W.axisTickColor,O,E,l.current)}]}},P=new Rs(D,B,b);d.current=P,p=new ResizeObserver(()=>{const R=b.getBoundingClientRect();R.width>0&&R.height>0&&d.current&&d.current.setSize({width:Math.floor(R.width),height:Math.floor(R.height)})}),p.observe(b)});return()=>{var k;_(),p==null||p.disconnect(),(k=d.current)==null||k.destroy(),d.current=null}},[T]),f.useEffect(()=>{d.current&&d.current.redraw()},[e,n,o]),e.length===0?t.jsx("div",{className:"h-full flex items-center justify-center text-fg-muted",children:"No data available"}):t.jsx("div",{ref:i,className:"w-full h-full",onMouseMove:v,onMouseLeave:w})}const Sa=f.memo(Ta),ls=[{target:"RepeaterAnalyticsCard",fn:"type",minStage:1}];pe(ls);function _a(e){const o=new Date(e*1e3).getHours();return o>=6&&o<18}function vt(e){return new Date(e*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})}const xe=32,Ge=20,Ba=[.5,1];function Da({forwardedBuckets:e,droppedBuckets:n,forwardedActiveTypes:o,droppedActiveTypes:s,forwardedCount:r,droppedCount:a,crcCount:c,crcHistory:i,receivedCount:d,forwardedTotalByType:u,droppedTotalByType:m,startTime:j,bucketDurationSeconds:l,bucketCount:x,timeRangeMinutes:N}){fe(ls);const h=Pt(),y=we(),[C,T]=f.useState(null),[B,v]=f.useState(null),[w,b]=f.useState(null),p=f.useCallback((G,H,U)=>{T(H),v(U)},[]),_=Math.max(1,N/60),k=f.useMemo(()=>Ft(y,_),[y,_]),A=f.useMemo(()=>k?Et(k):0,[k]),g=Math.round(A*10)/10,D=Math.round((k==null?void 0:k.avgBackoffMs)??0),{fwdMirror:P,drpMirror:R,allTypes:L,fwdTotals:S,drpTotals:F}=f.useMemo(()=>{const G=e.map(X=>({start:X.start,end:X.end,countByType:{...X.countByType}})),H=new Array(x).fill(0);for(const X of i){let K=Math.floor((X.timestamp-j)/l);K<0&&(K=0),!(K>=x)&&H[K]++}const U=n.map((X,K)=>({start:X.start,end:X.end,countByType:{...X.countByType,...H[K]>0?{[Q]:H[K]}:{}}})),V=new Set([...o,...s]);c>0&&V.add(Q);const se={...u},ae={...m};c>0&&(ae[Q]=c);const ke=[...V].sort((X,K)=>{const ys=(se[X]??0)+(ae[X]??0);return(se[K]??0)+(ae[K]??0)-ys});return{fwdMirror:G,drpMirror:U,allTypes:ke,fwdTotals:se,drpTotals:ae}},[e,n,o,s,i,c,j,l,x,u,m]),M=L.length>0&&P.length>0,$=C?_a(C.start):null,E=C?vt(C.start):"",W=w!==null&&$!==null&&w!==$;$!==w&&b($);const I=f.useMemo(()=>M?Ca(P,R,L):null,[M,P,R,L]),O=f.useMemo(()=>{if(!I)return[];const{fwdMax:G,drpMax:H,fwdFrac:U}=I,V=[];for(const se of Ba){const ae=Math.round(G*se);if(ae>0){const X=(1-se)*U*100;V.push({label:te(ae),pos:X,color:"green"})}const ke=Math.round(H*se);if(ke>0){const X=(U+se*(1-U))*100;V.push({label:te(ke),pos:X,color:"red"})}}return V},[I]),z=f.useMemo(()=>{if(P.length===0)return[];const G=P.length,H=Math.max(1,Math.floor(G/6)),U=[];for(let V=0;V<G;V+=H)U.push({label:vt(P[V].start),pos:(V+.5)/G*100});return U},[P]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-wrap gap-4 sm:gap-8",children:[t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:M?t.jsx(re,{value:r,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(ne,{color:"zinc",className:"mb-0.5 sm:mb-1 flex items-center gap-1 cursor-default",title:"Forwarded — packets this repeater received and re-broadcast to extend mesh range",children:[t.jsx(ht,{className:"w-3 h-3 text-sys-green"}),"FWD"]})]}),t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:M?t.jsx(re,{value:a+c,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(ne,{color:"zinc",className:"mb-0.5 sm:mb-1 flex items-center gap-1 cursor-default",title:"Dropped — packets discarded as duplicates, out-of-range, or failed validation (includes CRC errors)",children:[t.jsx(pt,{className:"w-3 h-3 text-sys-red"}),"Drop"]})]}),t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:M?t.jsxs("span",{className:"font-mono tabular-nums",children:[g,"%"]}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(ne,{color:"zinc",className:"mb-0.5 sm:mb-1 flex items-center gap-1 cursor-default",title:"Duplicate — packets already seen and discarded to prevent broadcast storms in the mesh",children:[t.jsx(qn,{className:"w-3 h-3 text-sys-amber"}),"Dupe"]})]}),t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:M?t.jsxs("span",{className:"font-mono tabular-nums",children:[D,"ms"]}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(ne,{color:"zinc",className:"mb-0.5 sm:mb-1 flex items-center gap-1 cursor-default",title:"LBT Mean — average Listen-Before-Talk delay before transmitting. Higher values indicate a busier channel",children:[t.jsx(as,{className:"w-3 h-3 text-sys-blue"}),"LBT Mean"]})]})]}),t.jsx("div",{className:"h-5 relative mb-1 mt-2 shrink-0",children:C&&B!==null&&t.jsxs("div",{className:"absolute flex items-center gap-1.5 type-data-sm -translate-x-1/2",style:{left:`calc(${xe}px + ${B*100}% * (1 - ${xe}px / 100%))`},children:[t.jsx(Ke,{mode:"wait",children:t.jsx(ge.span,{initial:W?{opacity:0,scale:.5,rotate:-90}:!1,animate:{opacity:1,scale:1,rotate:0},exit:{opacity:0,scale:.5,rotate:90},transition:{duration:.25,ease:"easeOut"},children:$?t.jsx(Lt,{className:"w-4 h-4 text-sys-amber"}):t.jsx($t,{className:"w-4 h-4 text-sys-blue"})},$?"sun":"moon")}),t.jsx("span",{className:"text-fg-secondary",children:E})]})}),t.jsxs("div",{className:"flex-1 min-h-0 relative",children:[t.jsx("div",{className:"absolute top-0 left-0",style:{width:xe,bottom:Ge},"aria-hidden":"true",children:O.map(({label:G,pos:H,color:U},V)=>t.jsx("span",{className:`type-data-xs text-right pr-1.5 ${U==="green"?"text-sys-green/70":"text-sys-red/70"}`,style:{position:"absolute",top:`${H}%`,transform:H<=1?"none":H>=99?"translateY(-100%)":"translateY(-50%)",right:0},children:G},V))}),t.jsxs("div",{className:"absolute overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",style:{left:xe,right:0,top:0,bottom:Ge},children:[M&&I&&t.jsx("div",{className:"absolute inset-x-0 top-0 pointer-events-none",style:{height:`${I.fwdFrac*100}%`,background:"var(--sys-blue)",opacity:.1}}),M&&t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"data-box data-box-compact flex items-center gap-1 absolute z-10 pointer-events-none",style:{top:8,left:8,background:"var(--surface)",borderColor:"var(--edge-subtle)"},children:[t.jsx(ht,{className:"w-3 h-3 text-sys-green"}),t.jsx("span",{children:"FWD"})]}),t.jsxs("span",{className:"data-box data-box-compact flex items-center gap-1 absolute z-10 pointer-events-none",style:{bottom:8,left:8,background:"var(--surface)",borderColor:"var(--edge-subtle)"},children:[t.jsx(pt,{className:"w-3 h-3 text-sys-red"}),t.jsx("span",{children:"DROP"})]})]}),t.jsx("div",{className:`absolute inset-0 flex items-center transition-opacity duration-300 ${M?"opacity-0 pointer-events-none":"opacity-100"}`,"aria-hidden":M,children:t.jsx("div",{className:"w-full flex items-center gap-1",children:t.jsx("div",{className:"flex-1 flex items-end gap-1 h-1/2",children:[45,72,33,58,80,42,65,28,55,75,38,62].map((G,H)=>t.jsx("div",{className:"flex-1 bg-subtle-fill rounded-sm animate-pulse",style:{height:`${G}%`}},`u${H}`))})})}),t.jsx("div",{className:`h-full transition-opacity duration-300 ${M?"opacity-100":"opacity-0"}`,children:M&&t.jsx(Sa,{forwardedBuckets:P,droppedBuckets:R,allTypes:L,gridColor:h.grid,axisTickColor:h.axisTick,onHover:p,externalAxes:!0})}),M&&I&&t.jsx("div",{className:"absolute inset-x-0 bottom-0 pointer-events-none",style:{top:`${I.fwdFrac*100}%`,background:"var(--sys-red)",opacity:.1}})]}),t.jsx("div",{className:"absolute left-0 right-0 bottom-0 pointer-events-none",style:{left:xe,height:Ge},"aria-hidden":"true",children:z.map((G,H)=>t.jsx("span",{className:"type-data-xs text-fg-secondary absolute top-1",style:{left:`${G.pos}%`,transform:H===0?"none":H===z.length-1?"translateX(-100%)":"translateX(-50%)"},children:G.label},H))})]}),t.jsx("div",{className:"pt-2 px-1 pb-2 shrink-0",children:M&&t.jsx(Ma,{allTypes:L,forwardedTotalByType:S,droppedTotalByType:F})})]})}const Ra=2,Aa=1;function Pa(e,n,o){const s=d=>(d==null?void 0:d.reduce((u,m)=>u+m.count,0))??0,r=s(n),a=s(o),c=r||(e==null?void 0:e.rx_count)||1,i=a||(e==null?void 0:e.dropped_count)||0;return c>0?i/(c+i)*100:0}function La(e,n,o){const s=r=>(r==null?void 0:r.reduce((a,c)=>a+c.count,0))??0;if(n!=null&&n.length&&o){const a=s(n)*100,c=n.length*o*1e3;return a/c*100}if(e){const r=(e.uptime_seconds||1)*1e3;return(e.total_airtime_ms||e.airtime_used_ms||0)/r*100}return 0}function kt(e,n,o){return jn(Math.max(n,Math.min(o,e)))}function $a(e,n,o,s,r){let a=Kt(e);n>20?a+=Te*2:n>12&&(a+=Te),o>8&&(a+=Te);const c=kt(a,0,Ra);let i=wn(e);o>8&&(i+=Te);const d=kt(i,0,Aa),u=ye(c),m=ye(d),j=s!==null?ye(s):null;let l="stable";return j!==null&&(u>j?l="increase":u<j&&(l="decrease")),{floodFactor:c,directFactor:d,floodSlots:u,directSlots:m,adjustment:l,duplicateRate:Math.round(n*100)/100,txUtilization:Math.round(o*1e3)/1e3,zeroHopCount:e}}function Fa({stats:e,receivedBuckets:n,droppedBuckets:o,forwardedBuckets:s,bucketDurationSeconds:r,timeRangeLabel:a,isLoaded:c=!0}){var E,W,I,O;const[i,d]=f.useState(!1),[u,m]=f.useState("idle"),j=Ps(),l=f.useCallback(async(z,G)=>{if(u!=="applying"){m("applying");try{const H=await Ls({tx_delay_factor:z,direct_tx_delay_factor:G});H!=null&&H.success?(m("success"),setTimeout(()=>m("idle"),2e3)):(m("error"),setTimeout(()=>m("idle"),2500))}catch{m("error"),setTimeout(()=>m("idle"),2500)}}},[u]);if(!c)return t.jsx(je,{children:t.jsx($s,{})});const x=10080*60,h=Math.floor(Date.now()/1e3)-x,y=Object.values((e==null?void 0:e.neighbors)??{}).filter(z=>z.zero_hop&&z.last_seen>=h&&bn(z).isRepeater).length,C=j.filter(z=>z.status==="active"||z.lastSeen>=h).length,T=Math.max(y,C),B=Pa(e,n,o),v=La(e,s,r),w=((W=(E=e==null?void 0:e.config)==null?void 0:E.delays)==null?void 0:W.tx_delay_factor)??null,b=((O=(I=e==null?void 0:e.config)==null?void 0:I.delays)==null?void 0:O.direct_tx_delay_factor)??null,p=$a(T,B,v,w),_=T!==1,k=Kt(T),A=[`${T} repeater${_?"s":""} heard in the last 7 days (base ×${k.toFixed(1)}).`];p.floodFactor===k&&B<=12&&v<=8?A.push("No modifiers applied — network looks healthy."):(B>20?A.push(`High duplicate rate (${B.toFixed(1)}%) suggests frequent collisions — window widened.`):B>12&&A.push(`Elevated duplicate rate (${B.toFixed(1)}%) — window widened one step.`),v>8&&A.push(`Channel is busy (${v.toFixed(1)}% TX util) — extra spacing added.`));const g=[`Direct uses one forwarder — ×${p.directFactor.toFixed(1)} backoff for channel contention.`];v>8&&g.push("Busy channel — small extra backoff.");const D=[`Flood ×${p.floodFactor.toFixed(1)} (${p.floodSlots} slot${p.floodSlots!==1?"s":""})`,...A,"",`Direct ×${p.directFactor.toFixed(1)}`,...g,"","Click to copy CLI commands"].join(`
`),P=w!==null?ye(w):null,R=b!==null?ye(b):null,L=P!==null&&p.floodSlots!==P,S=R!==null&&p.directSlots!==R,F=L||S,M=async()=>{const z=`set txdelay ${p.floodFactor.toFixed(1)}
set direct.txdelay ${p.directFactor.toFixed(1)}`;await Es(z),d(!0),setTimeout(()=>d(!1),1500)},$=()=>l(p.floodFactor,p.directFactor);return t.jsxs(je,{children:[t.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3 flex-wrap",children:[t.jsx(Nn,{className:"w-4 h-4 text-icon-card-title flex-shrink-0"}),t.jsx("span",{className:"type-micro",children:"DELAY DOCTOR"}),a&&t.jsx(ne,{color:"zinc",className:"hidden sm:inline-flex",children:a})]}),t.jsxs("button",{onClick:M,className:"flex gap-3 mb-2 sm:mb-3 w-full text-left hover:bg-subtle-fill radius-inner transition-base p-1 -m-1 group",title:D,children:[t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsx("span",{className:"type-data-xl text-fg-primary",children:t.jsxs(Ye,{children:["×",p.floodFactor.toFixed(1)]})}),t.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Flood"})]}),t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsx("span",{className:"type-data-xl text-sys-blue",children:t.jsxs(Ye,{children:["×",p.directFactor.toFixed(1)]})}),t.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Direct"})]}),t.jsx("div",{className:"flex items-center self-center opacity-0 group-hover:opacity-100 transition-opacity",children:i?t.jsx(at,{className:"w-4 h-4 text-sys-green"}):t.jsx(Fs,{className:"w-4 h-4 text-fg-muted"})})]}),t.jsx("div",{className:"flex-1 py-2",children:t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("div",{className:"data-box-label",children:"Dupe"}),t.jsxs("div",{className:`data-box data-box-fill data-box-left ${p.duplicateRate>8?"text-status-warning":""}`,children:[p.duplicateRate.toFixed(1),"%"]})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx("div",{className:"data-box-label",children:"TX Util"}),t.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[p.txUtilization.toFixed(2),"%"]})]})]})}),t.jsx("div",{className:"pt-2 mt-auto",children:t.jsxs("div",{className:"flex items-end justify-between gap-2",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"data-box-label",children:"Current"}),t.jsx("div",{className:"flex gap-2",children:w!==null?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"data-box data-box-fill data-box-left",children:["×",w.toFixed(2)]})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"data-box data-box-fill data-box-left",style:{color:"var(--sys-blue)"},children:["×",(b==null?void 0:b.toFixed(2))??"—"]})})]}):t.jsx("span",{className:"text-sm text-fg-muted",children:"No config"})})]}),F&&t.jsxs("button",{onClick:$,disabled:u==="applying"||u==="success",className:`flex items-center gap-1.5 px-2.5 py-1.5 radius-inner type-micro font-medium transition-base
                ${u==="success"?"bg-sys-green/15 text-sys-green":u==="error"?"bg-sys-red/15 text-sys-red":u==="applying"?"bg-subtle-fill text-fg-muted":"bg-sys-blue/10 text-sys-blue hover:bg-sys-blue/20"}`,title:`Apply ×${p.floodFactor.toFixed(1)} flood, ×${p.directFactor.toFixed(1)} direct`,children:[u==="success"?"Rx'd":u==="error"?"Failed":"Apply",u==="applying"?t.jsx(Le,{className:"w-3.5 h-3.5 animate-spin"}):u==="success"?t.jsx(at,{className:"w-3.5 h-3.5"}):t.jsxs("span",{className:"relative inline-flex items-end w-6 h-3.5",children:[t.jsx(Kn,{className:"w-3.5 h-3.5 absolute left-0 bottom-0"}),t.jsx(na,{className:"w-3 h-3 absolute right-0 bottom-0"})]})]})]})})]})}const cs=[{target:"RecentPackets",fn:"rssi",minStage:1},{target:"RecentPackets",fn:"snr",minStage:1}];pe(cs);const Ea=25;function Ia(){fe(cs);const e=we(),n=Is(),o=Hs(),s=ie(),r=Mn(),a=Je(x=>x.requestChannel),[c,i]=f.useState(!0),d=f.useCallback(x=>i(x),[]),u=f.useMemo(()=>[...e.length<=100?e:e.slice(-100)].sort((N,h)=>(h.timestamp??0)-(N.timestamp??0)),[e]),m=s==null?void 0:s.local_hash,j=s==null?void 0:s.neighbors,l=Cn();return t.jsxs(je,{noPadding:!0,className:"!overflow-visible",children:[t.jsx(It,{listHeader:!0,icon:t.jsx(zt,{}),title:"Recent Packets",actions:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(Ht,{enabled:c,onChange:d,label:"Hide Dupes",size:"sm"}),o&&t.jsx(zs,{showLabel:!0}),t.jsxs($e,{color:"primary",outline:!0,href:"/packets",children:["View all",t.jsx(ut,{"data-slot":"icon"})]})]})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-1",children:t.jsx(vn,{packets:u,allPackets:e,localHash:m,neighbors:j,resolveSource:l,getDecodedContent:r,onChannelClick:a,loading:n,maxPackets:Ea,showPagination:!1,flashNewest:!0,hideDupes:c,emptyMessage:"No packets received",footerAction:t.jsxs($e,{color:"primary",outline:!0,href:"/packets",children:["View all",t.jsx(ut,{"data-slot":"icon"})]})})})]})}const Ha={stable:"M5 12h14",up:"M5 15l7-7 7 7",down:"M19 9l-7 7-7-7"};function za({trend:e}){return t.jsx("span",{className:`mini-widget-trend ${e}`,children:t.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:Ha[e]})})})}function Oa(){return t.jsx("div",{className:"mini-widget-loading",children:t.jsx("div",{className:"mini-widget-loading-spinner"})})}function Ga({message:e}){return t.jsx("div",{className:"mini-widget-error",children:t.jsx("span",{title:e,children:"No data"})})}function le({title:e,icon:n,value:o,unit:s,valueSize:r="md",status:a,subtitle:c,subtitleValue:i,trend:d,headerRight:u,children:m,isLoading:j=!1,error:l,className:x="",onClick:N,isLoaded:h}){const y=["mini-widget-value",r==="lg"&&"mini-widget-value-lg",r==="sm"&&"mini-widget-value-sm"].filter(Boolean).join(" "),C=["mini-widget",x].filter(Boolean).join(" ");return t.jsxs(je,{noPadding:!0,className:C,onClick:N,isLoaded:h,children:[t.jsxs("div",{className:"mini-widget-header",children:[n,t.jsx("span",{className:"mini-widget-title",children:e}),a&&a!=="unknown"&&t.jsx("div",{className:`mini-widget-status-dot ${a}`}),d&&t.jsx(za,{trend:d}),u&&t.jsx("span",{className:"ml-auto flex items-center",children:u})]}),j?t.jsx(Oa,{}):l?t.jsx(Ga,{message:l}):t.jsxs("div",{className:"mini-widget-content",children:[(o!==void 0||c||i)&&t.jsxs("div",{className:"mini-widget-value-row",children:[o!==void 0&&t.jsxs("div",{className:y,children:[typeof o=="number"?t.jsx(re,{value:o,className:"font-mono tabular-nums",priority:"medium",format:Number.isInteger(o)?void 0:{minimumFractionDigits:1,maximumFractionDigits:1}}):t.jsx(Ye,{children:o}),s&&t.jsx("span",{className:"mini-widget-unit",children:s})]}),(c||i)&&t.jsxs("span",{className:"mini-widget-badge-group",children:[c&&!i&&t.jsx("span",{className:"data-box mini-widget-subtitle-box",children:c}),c&&i&&t.jsx("span",{className:"mini-widget-subtitle truncate",children:c}),i&&t.jsx("span",{className:"data-box mini-widget-subtitle-box",children:i})]})]}),m]})]})}const Wa={DELTA_CRITICAL:10,SLOPE_CRITICAL:4,JITTER_CRITICAL:6,DELTA_WARNING:5,SLOPE_WARNING:2,JITTER_WARNING:4},ds={baselineMedian:null,baselineP10:null,baselineP90:null,currentMedian:null,currentSampleCount:0,delta:0,slope:0,jitter:0,penalty:0,penaltyReason:null,computedAt:0,isReliable:!1};function Ze(e,n){if(e.length===0)return null;const o=[...e].sort((c,i)=>c-i),s=n/100*(o.length-1),r=Math.floor(s),a=Math.ceil(s);return r===a?o[r]:o[r]+(o[a]-o[r])*(s-r)}function Mt(e){return Ze(e,50)}function qa(e){if(e.length<2)return 0;const n=e.reduce((r,a)=>r+a,0)/e.length,s=e.map(r=>Math.pow(r-n,2)).reduce((r,a)=>r+a,0)/e.length;return Math.sqrt(s)}function Xa(e){if(e.length<2)return 0;const n=e.length;let o=0,s=0,r=0,a=0;const c=e[0].timestamp;for(const d of e){const u=(d.timestamp-c)/3600,m=d.value;o+=u,s+=m,r+=u*m,a+=u*u}const i=n*a-o*o;return Math.abs(i)<1e-4?0:(n*r-o*s)/i}function Ua(e,n,o){const s=Wa;return e>=s.DELTA_CRITICAL?[2,`Noise floor ${e.toFixed(1)} dB above baseline`]:n>=s.SLOPE_CRITICAL?[2,`Noise floor rising ${n.toFixed(1)} dB/hour`]:o>=s.JITTER_CRITICAL?[2,`Noise floor unstable (±${o.toFixed(1)} dB)`]:e>=s.DELTA_WARNING?[1,`Noise floor ${e.toFixed(1)} dB above baseline`]:n>=s.SLOPE_WARNING?[1,`Noise floor rising ${n.toFixed(1)} dB/hour`]:o>=s.JITTER_WARNING?[1,`Noise floor variable (±${o.toFixed(1)} dB)`]:[0,null]}function Va(e){if(e.length===0)return{...ds,computedAt:Math.floor(Date.now()/1e3)};const n=Math.floor(Date.now()/1e3),o=e.filter(y=>Number.isFinite(y)),s=e.length>0?[e[e.length-1]]:[],r=e.slice(-4).filter(y=>Number.isFinite(y)),a=Mt(o),c=Ze(o,10),i=Ze(o,90),d=Mt(s),u=d!==null&&c!==null?d-c:0,m=r.map((y,C)=>({timestamp:n-(r.length-1-C)*3600,value:y})),j=Xa(m),l=qa(r),x=o.length>=12,[N,h]=x?Ua(u,j,l):[0,null];return{baselineMedian:a,baselineP10:c,baselineP90:i,currentMedian:d,currentSampleCount:s.length,delta:u,slope:j,jitter:l,penalty:N,penaltyReason:h,computedAt:n,isReliable:x}}const Ya={lbtStats:null,noiseFloor:null,sparklineNoiseFloor:[],noiseFloorWindowHistory:[],linkQuality:null,channelHealth:null,nfTrend:ds,radioConfig:null,trends:null,stats:null,recentPackets:[],quickNeighbors:[],isLoading:!0,error:null,refresh:async()=>{}},us=f.createContext(Ya);function Ja({children:e}){var R;const n=ie(),o=we(),s=Ot(),r=Os(),a=Ne(),c=ee[a],i=Math.max(1,c.minutes/60),d=n===null,[u,m]=f.useState(null),j=f.useCallback(async()=>{try{const L=await Gt(Math.ceil(i));if(L.success&&L.data){m(L.data.history);return}const S=await Wt(Math.ceil(i));S.success&&S.data&&S.data.count>0&&m(null)}catch{}},[i]);f.useEffect(()=>{j();const L=setInterval(j,6e4);return()=>clearInterval(L)},[j]);const l=f.useMemo(()=>Ft(o,i,u),[o,i,u]),x=(n==null?void 0:n.noise_floor_dbm)??null,N=f.useMemo(()=>Gs(x)?x:null,[x]),h=f.useMemo(()=>{var S;const L=(S=n==null?void 0:n.config)==null?void 0:S.radio;return L?{sf:L.spreading_factor??7,bwHz:L.bandwidth??125e3}:null},[(R=n==null?void 0:n.config)==null?void 0:R.radio]),y=Ws(i),C=qs(i),T=n==null?void 0:n.neighbors,B=f.useMemo(()=>Object.fromEntries(Object.entries(T??{}).filter(([S])=>!r.has(S))),[T,r]),v=f.useMemo(()=>s.filter(L=>!r.has(L.hash)),[s,r]),w=f.useMemo(()=>Va(y),[y]),b=f.useMemo(()=>Xs(v,B,h),[v,B,h]),p=f.useMemo(()=>Us(l,N,b),[l,N,b]),[_,k]=f.useState({noiseFloor:null,networkScore:null,channelHealth:null}),A=f.useRef(0);f.useEffect(()=>{const L=()=>{const F=Date.now();F-A.current>3e4&&(A.current=F,k({noiseFloor:N,networkScore:(b==null?void 0:b.networkScore)??null,channelHealth:(p==null?void 0:p.score)??null}))};L();const S=setInterval(L,5e3);return()=>clearInterval(S)},[N,b==null?void 0:b.networkScore,p==null?void 0:p.score]);const g=f.useMemo(()=>({noiseFloor:{current:N,previous:_.noiseFloor,trend:N!==null?Ie(N,_.noiseFloor,2,!0):"stable"},networkScore:{current:(b==null?void 0:b.networkScore)??0,previous:_.networkScore,trend:Ie((b==null?void 0:b.networkScore)??0,_.networkScore,3,!1)},channelHealth:{current:(p==null?void 0:p.score)??0,previous:_.channelHealth,trend:Ie((p==null?void 0:p.score)??0,_.channelHealth,3,!1)}}),[N,b==null?void 0:b.networkScore,p==null?void 0:p.score,_]),P={lbtStats:l,noiseFloor:N,sparklineNoiseFloor:y,noiseFloorWindowHistory:C,linkQuality:b,channelHealth:p,nfTrend:w,radioConfig:h,trends:g,stats:n,recentPackets:o,quickNeighbors:s,isLoading:d,error:null,refresh:async()=>{}};return t.jsx(us.Provider,{value:P,children:e})}function et(){const e=f.useContext(us);if(e===void 0)throw new Error("useLBTData must be used within an LBTDataProvider");return e}function Za(e){return e<100?"excellent":e<250?"good":e<500?"fair":e<1e3?"congested":"critical"}function Ka(e){return e===0?"No backoffs":"Retries"}function Qa(e,n){return e===0?void 0:`${n.toFixed(0)}%`}function eo(){const{lbtStats:e,isLoading:n,error:o}=et(),s=qt(),r=(e==null?void 0:e.avgBackoffMs)??0,a=(e==null?void 0:e.retryRate)??0,c=e?Za(r):"unknown",i=e==null?void 0:e.sparklineBackoff,d=f.useMemo(()=>!i||i.length<2?[]:i.map((u,m)=>({timestamp:Date.now()-(i.length-1-m)*36e5,count:u})),[i]);return t.jsx(le,{title:"LBT Backoff",icon:t.jsx(oa,{className:"mini-widget-icon"}),value:Math.round(r),unit:"ms",status:c,subtitle:e?Ka(r):void 0,subtitleValue:e?Qa(r,a):void 0,isLoading:n,error:o,onClick:()=>s("/packets"),children:t.jsx("div",{className:"mini-widget-sparkline w-full",children:t.jsx(ts,{data:d,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}const ms=[{target:"LinkLeaders",fn:"path",minStage:1,when:xn},{target:"LinkLeaders",fn:"src_hash",minStage:1,when:gn}];pe(ms);function to(){fe(ms);const e=qt(),n=Ot(),o=we(),s=ie(),r=Ne(),c=ee[r].minutes*60,i=Vs(),d=f.useMemo(()=>{if(i===0)return o;const p=i-c;return o.filter(_=>_.timestamp>=p)},[o,c,i]),u=s===null,m=s!=null&&s.local_hash?ot(s.local_hash):"",j=(s==null?void 0:s.neighbors)??{},{neighborHashes:l,neighborNames:x}=f.useMemo(()=>{const p=new Set,_=new Map;for(const k of n){p.add(k.hash);const A=j[k.hash],g=(A==null?void 0:A.name)||(A==null?void 0:A.node_name)||k.prefix;_.set(k.hash,g)}return{neighborHashes:p,neighborNames:_}},[n,j]),N=f.useMemo(()=>{if(l.size===0||d.length===0||!m)return{champion:null,listener:null,loudest:null};const{scores:p}=Sn(d,l,m),_=[];for(const[D,P]of p)P.blendedScore!==0&&_.push({...P,name:x.get(D)??ot(D)});let k=null,A=null,g=null;for(const D of _)(!k||D.blendedScore>k.blendedScore)&&(k=D),(!A||D.listenerScore>A.listenerScore)&&(A=D),(!g||D.loudScore>g.loudScore)&&(g=D);return{champion:k,listener:A,loudest:g}},[d,l,m,x]),h=p=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["🏆 Champion: ",p.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Blended Score: ",p.blendedScore,t.jsx("span",{className:"text-fg-muted/60 ml-1",children:"(Listener + Loud)"})]}),t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1 space-y-0.5",children:[t.jsxs("div",{children:["Listener: ",p.listenerScore,"/100 (",p.listenerCount," shared paths)"]}),t.jsxs("div",{children:["Loud: ",p.loudScore,"/100 (",p.loudCount," packets relayed)"]})]})]}),y=p=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["👂 Best Listener: ",p.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",p.listenerScore,"/100"]}),t.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:t.jsxs("div",{children:[p.listenerCount," packets where they heard your transmissions"]})})]}),C=p=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["📢 Loudest: ",p.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",p.loudScore,"/100"]}),t.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:t.jsxs("div",{children:[p.loudCount," packets they relayed directly to you"]})})]}),{champion:T,listener:B,loudest:v}=N,b=T||B||v?t.jsxs("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:[T&&t.jsx(me,{content:h(T),children:t.jsxs("div",{className:"flex items-center gap-1 text-xs sm:text-sm radius-badge px-1 -mx-1 hover-bg transition-base cursor-default",children:[t.jsx(kn,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-map-neighbor-color flex-shrink-0"}),t.jsx("span",{className:"font-semibold text-map-neighbor-color font-mono truncate flex-1 min-w-0",children:T.name}),t.jsx("span",{className:"text-map-neighbor-color pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right",children:T.blendedScore})]})}),B&&t.jsx(me,{content:y(B),children:t.jsxs("div",{className:"flex items-center gap-1 text-xs sm:text-sm radius-badge px-1 -mx-1 hover-bg transition-base cursor-default",children:[t.jsx(as,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-fg-muted flex-shrink-0"}),t.jsx("span",{className:"text-fg-muted font-mono truncate flex-1 min-w-0",children:B.name}),t.jsx("span",{className:"text-fg-muted pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right",children:B.listenerScore})]})}),v&&t.jsx(me,{content:C(v),children:t.jsxs("div",{className:"flex items-center gap-1 text-xs sm:text-sm radius-badge px-1 -mx-1 hover-bg transition-base cursor-default",children:[t.jsx(Jn,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-fg-muted flex-shrink-0"}),t.jsx("span",{className:"text-fg-muted font-mono truncate flex-1 min-w-0",children:v.name}),t.jsx("span",{className:"text-fg-muted pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right",children:v.loudScore})]})})]}):n.length===0?t.jsx("div",{className:"flex items-center justify-center text-xs sm:text-sm text-fg-muted mt-auto",children:"No direct neighbors"}):t.jsx("div",{className:"flex items-center justify-center text-xs sm:text-sm text-fg-muted mt-auto",children:"No routing data yet"});return t.jsx(le,{title:"Link Leaders",icon:t.jsx(ea,{className:"mini-widget-icon"}),isLoading:u,onClick:()=>e("/contacts"),children:b})}function so(e){return e<15?"excellent":e<30?"good":e<45?"fair":e<60?"congested":"critical"}function no(e){return e<15?"Clear channel":e<30?"Light traffic":e<45?"Moderate traffic":e<60?"Heavy traffic":e<75?"Congested":"Severe congestion"}function ao(){const{lbtStats:e,isLoading:n,error:o}=et(),s=e?Et(e):0,r=e?so(s):"unknown",a=(e==null?void 0:e.maxBackoffMs)??0,c=e?a>200?"Peak":no(s):void 0,i=e&&a>200?`${Math.round(a)}ms`:void 0,d=e==null?void 0:e.sparklineCollisionRisk,u=f.useMemo(()=>!d||d.length<2?[]:d.map((j,l)=>({timestamp:Date.now()-(d.length-1-l)*36e5,count:j})),[d]),m=Math.round(s*10)/10;return t.jsx(le,{title:"Collision Risk",icon:t.jsx(_n,{className:"mini-widget-icon"}),value:m,unit:"%",status:r,subtitle:c,subtitleValue:i,isLoading:n,error:o,children:t.jsx("div",{className:"mini-widget-sparkline w-full",children:t.jsx(ts,{data:u,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}function oo(e){return e<30?"excellent":e<50?"good":e<70?"fair":e<90?"congested":"critical"}function ro(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function io(){var h,y;const[e,n]=f.useState(!1),[o]=f.useState(0),{stats:s,lbtStats:r,isLoading:a}=et(),c=((y=(h=s==null?void 0:s.config)==null?void 0:h.duty_cycle)==null?void 0:y.enforcement_enabled)??!1,i=f.useMemo(()=>{if(!s)return null;if(!c){const w=s.airtime_used_ms??0,b=s.max_airtime_ms??1,p=b>0?w/b*100:0;return{usedMs:w,maxMs:b,remainingMs:Math.max(0,b-w),utilizationPercent:p}}const C=s.airtime_used_ms??0,T=s.max_airtime_ms??1,B=s.airtime_remaining_ms??0,v=s.utilization_percent??(T>0?C/T*100:0);return{usedMs:C,maxMs:T,remainingMs:B,utilizationPercent:v}},[s,c]),d=f.useMemo(()=>{if(!r||r.totalPacketsWithLBT===0)return 100;const C=r.totalPacketsWithLBT-r.packetsWithRetries,T=r.totalPacketsWithLBT;return C/T*100},[r]),u=(i==null?void 0:i.utilizationPercent)??0,m=oo(u),j=(i==null?void 0:i.remainingMs)??0,l=d<95?"1st Try":"Remaining",x=d<95?`${d.toFixed(0)}%`:ro(j),N=i?t.jsx("div",{className:"mini-widget-progress mt-auto",children:t.jsx("div",{className:`mini-widget-progress-bar ${m}`,style:{width:`${Math.min(u,100)}%`}})}):null;return t.jsx(le,{title:"Duty Cycle",icon:t.jsx(zt,{className:"mini-widget-icon"}),value:u.toFixed(1),unit:"%",status:m,subtitle:l,subtitleValue:x,isLoading:a,children:N})}function lo(){return t.jsxs("div",{className:"mini-widget",children:[t.jsxs("div",{className:"mini-widget-header",children:[t.jsx(Me,{className:"w-4 h-4"}),t.jsx(Me,{className:"h-3 w-16"})]}),t.jsx(Me,{className:"h-7 w-12 mt-2"}),t.jsx(Me,{className:"h-3 w-20 mt-2"})]})}function co(){return t.jsx("div",{className:"widget-row",children:Array.from({length:5}).map((e,n)=>t.jsx(lo,{},n))})}const fs=[{target:"MeshHealth",fn:"type",minStage:1}];pe(fs);function uo({className:e="",isLoaded:n,leading:o}){fe(fs);const s=Xt(),r=n??s??!0;return t.jsxs("div",{className:`mesh-health-container relative ${e}`,children:[t.jsxs("div",{className:"mesh-health-header",children:[t.jsx(Ys,{className:"w-4 h-4 text-sys-blue"}),t.jsx("span",{className:"type-label text-fg-muted",children:"MESH HEALTH"})]}),r?t.jsx(Ja,{children:t.jsxs("div",{className:"widget-row",children:[o&&t.jsx("div",{className:"widget-leading",children:o}),t.jsx(eo,{}),t.jsx(ao,{}),t.jsx(io,{}),t.jsx(to,{})]})}):t.jsx(co,{})]})}const ps=[{target:"PublicChannel",fn:"decrypt",minStage:2,when:yn}];pe(ps);let hs="",xs="",Ct="";function mo(){const e=new Date,n=e.toDateString();if(n!==Ct){Ct=n,hs=n;const o=new Date(e);o.setDate(o.getDate()-1),xs=o.toDateString()}}function fo(e){mo();const n=new Date(e*1e3).toDateString();return n===hs?"Today":n===xs?"Yesterday":new Date(e*1e3).toLocaleDateString([],{weekday:"short",month:"short",day:"numeric"})}function po(e,n,o){return`${e||""}|${n}|${o}`}function ho(e,n){const o=e.message,s=n.message;return o.timestamp===s.timestamp&&o.text===s.text&&o.senderName===s.senderName&&o.channelHash===s.channelHash&&o.channelName===s.channelName&&e.isChannelSelected===n.isChannelSelected&&e.onChannelClick===n.onChannelClick}const xo=f.memo(function({message:n,onChannelClick:o,isChannelSelected:s}){const r=n.channelName||n.channelHash.slice(0,6);return t.jsx("div",{style:{transform:"translateZ(0)",willChange:"transform"},children:t.jsx(Ln,{senderName:n.senderName||"Unknown",text:n.text,timestamp:n.timestamp,bubbleVariant:"subtle",nameAccessory:t.jsx(Qt,{channelName:r,active:s,onClick:()=>o==null?void 0:o(n.channelHash)})})})},ho);function go({open:e,onClose:n,messages:o,onLoadMore:s,hasMoreToLoad:r,isDecoding:a,initialChannel:c}){const i=f.useRef(null),d=f.useRef(!0),u=Ne(),m=Ut(),j=f.useRef(!1);f.useEffect(()=>{e?(j.current=!0,it.resume()):j.current&&it.pause()},[e]);const l=f.useMemo(()=>{const g=Date.now()/1e3,D=ee[u].minutes,P=g-D*60;return[...o].filter(R=>R.timestamp>=P).sort((R,L)=>R.timestamp-L.timestamp)},[o,u]),x=f.useCallback(()=>{const g=i.current;g&&(d.current=g.scrollTop>=-50)},[]),N=f.useMemo(()=>{const g=new Map;for(const D of l){const P=D.channelHash,R=g.get(P);R?R.count++:g.set(P,{name:D.channelName||D.channelHash.slice(0,6),hash:D.channelHash,count:1})}return Array.from(g.values()).sort((D,P)=>P.count-D.count)},[l]),h=N.length,[y,C]=f.useState(null),[T,B]=f.useState(!1);f.useEffect(()=>{e&&c&&C(c)},[e,c]);const v=f.useCallback(()=>{s(y,N)},[s,y,N]),w=f.useMemo(()=>y?l.filter(g=>g.channelHash===y):l,[l,y]),b=f.useMemo(()=>{const g=[];let D="";for(const P of w){const R=fo(P.timestamp);R!==D&&(g.push({type:"date",date:R}),D=R),g.push({type:"message",message:P})}return g},[w]);f.useLayoutEffect(()=>{const g=i.current;g&&d.current&&(g.scrollTop=0)},[w.length]);const p=19,_=N.slice(0,p),k=N.slice(p),A=k.length>0;return t.jsx(Vt,{open:e,onClose:n,size:"lg",motionPlus:!0,solid:!0,children:t.jsxs(Yt,{className:"p-0 flex flex-col h-[80vh] max-h-[700px] rounded-2xl",children:[t.jsx("div",{className:"flex-shrink-0 px-4 sm:px-5 py-3 sm:py-4",children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(ss,{className:"size-5 text-icon-card-title flex-shrink-0"}),t.jsx("h2",{className:"type-micro",children:"Public Channels"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(es,{ranges:ee,selectedIndex:u,onSelect:m,size:"sm"}),t.jsx("button",{onClick:n,className:"sm:hidden min-h-[44px] min-w-[44px] px-3 flex items-center justify-center text-[15px] font-medium text-sys-blue active:text-sys-blue/70 transition-base radius-inner active:bg-subtle-fill",children:"Done"}),t.jsx("button",{onClick:n,className:"hidden sm:flex items-center justify-center p-2 text-fg-muted hover:text-fg-primary transition-base radius-inner hover:bg-subtle","aria-label":"Close",children:t.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]})}),t.jsx("div",{className:"flex-shrink-0 px-3 pb-2 relative z-10 isolate",style:{minHeight:h>0?void 0:0},children:h>0&&t.jsxs("div",{className:"flex flex-wrap gap-1",children:[t.jsxs("button",{onClick:()=>C(null),className:J("px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",y===null?"bg-sys-blue/20 text-sys-blue ring-sys-blue/30":"bg-subtle-fill text-fg-secondary ring-edge-subtle hover:bg-subtle-fill-strong"),children:["All ",h]}),_.map(g=>t.jsx("button",{onClick:()=>C(g.hash),className:J("flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",y===g.hash?"bg-sys-blue/20 text-sys-blue ring-sys-blue/30":"bg-subtle-fill text-fg-secondary ring-edge-subtle hover:bg-subtle-fill-strong"),children:t.jsx("span",{className:"truncate max-w-[80px]",children:g.name})},g.hash)),A&&t.jsxs("div",{className:"relative",children:[t.jsxs("button",{onClick:()=>B(!T),className:J("flex items-center gap-0.5 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",T||k.some(g=>g.hash===y)?"bg-sys-blue/20 text-sys-blue ring-sys-blue/30":"bg-subtle-fill text-fg-secondary ring-edge-subtle hover:bg-subtle-fill-strong"),children:["+",k.length,t.jsx(tn,{className:J("size-3 transition-transform",T&&"rotate-180")})]}),T&&t.jsx("div",{className:J("absolute top-full left-0 mt-1 z-50","min-w-[140px] max-h-[200px] overflow-y-auto","p-1 rounded-lg","bg-elevated backdrop-blur-xl","ring-1 ring-edge-subtle shadow-xl"),children:k.map(g=>t.jsxs("button",{onClick:()=>{C(g.hash),B(!1)},className:J("w-full flex items-center gap-1.5 px-2 py-1 rounded text-xs font-medium transition-all text-left",y===g.hash?"bg-sys-blue/20 text-sys-blue":"text-fg-secondary hover:bg-subtle-fill-strong"),children:[t.jsx($n,{className:"size-2.5 opacity-60 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:g.name}),t.jsxs("span",{className:"opacity-60 ml-auto",children:["(",g.count,")"]})]},g.hash))})]})]})}),t.jsx("div",{ref:i,onScroll:x,className:J("flex-1 overflow-y-auto overflow-x-hidden","mx-3 mb-3 radius-inner depth-stroke-inset","flex flex-col-reverse"),children:a&&w.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[300px] text-fg-muted px-4 py-4",children:[t.jsx(Le,{className:"size-12 mb-4 text-sys-indigo animate-spin"}),t.jsx("p",{className:"text-lg font-medium",children:"Loading messages..."})]}):w.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[300px] text-fg-muted px-4 py-4",children:[t.jsx(Fn,{className:"size-16 mb-4 opacity-20"}),t.jsx("p",{className:"text-lg font-medium",children:"No messages yet"}),t.jsx("p",{className:"text-sm mt-1 opacity-70",children:y?"No messages in this channel":"Public channel messages will appear here"})]}):t.jsxs("div",{className:"px-4 py-4",children:[r&&t.jsx("div",{className:"flex justify-center mb-4",children:t.jsx("button",{onClick:v,disabled:a,className:J("px-4 py-1.5 rounded-full","text-[11px] font-medium","ring-1 ring-inset",a?"bg-subtle-fill text-fg-muted ring-edge-subtle cursor-wait":"bg-sys-blue/10 text-sys-blue ring-sys-blue/20 hover:bg-sys-blue/20 hover:ring-sys-blue/30"),children:a?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(Le,{className:"size-3 animate-spin"}),"Loading..."]}):"Load older messages"})}),b.map((g,D)=>{if(g.type==="date")return t.jsx("div",{className:"flex justify-center my-4",children:t.jsx("span",{className:J("px-3.5 py-1.5 rounded-full","bg-subtle-fill backdrop-blur-sm","text-[11px] text-fg-muted/80 font-medium","ring-1 ring-edge-subtle"),children:g.date})},`date-${g.date}-${D}`);const P=`msg-${g.message.timestamp}-${g.message.senderName||"anon"}-${g.message.channelHash}`;return t.jsx("div",{children:t.jsx(xo,{message:g.message,onChannelClick:C,isChannelSelected:y===g.message.channelHash})},P)})]})}),t.jsx("div",{className:"flex-shrink-0 px-5 py-2 text-center",children:t.jsxs("p",{className:"text-[11px] text-fg-muted",children:[w.length," messages · ",h," ",h===1?"channel":"channels",a&&t.jsxs("span",{className:"ml-2 text-sys-indigo",children:[t.jsx(Le,{className:"inline size-3 animate-spin mr-1"}),"Decrypting..."]})]})})]})})}function yo(e){const n=[],o=new Set;for(const s of e.values()){const r=s.decoded;if(!r||!r.decrypted||r.macCorrupted||!r.text)continue;const a=po(r.senderName,r.channelHash,r.text);o.has(a)||(o.add(a),n.push({timestamp:s.timestamp,channelName:r.channelName,channelHash:r.channelHash,senderName:r.senderName,text:r.text,rssi:s.rssi,snr:s.snr}))}return n}function bo({isLoaded:e}){const n=Xt(),o=e??n??!0;fe(ps);const s=we(),[r,a]=f.useState(!1),[c,i]=f.useState(null),d=Ne(),u=f.useCallback(()=>{i(null),a(!0),Ce.getState().queueDecryption(s)},[s]),m=Je(_=>_.requestedHash),j=Je(_=>_.clearRequest);f.useEffect(()=>{m&&(i(m),a(!0),Ce.getState().queueDecryption(s),j())},[m,j,s]);const l=Js(),x=Zs(),N=Ks(),h=f.useMemo(()=>yo(l),[l]),y=f.useMemo(()=>{const _=Date.now()/1e3,k=ee[d].minutes,A=_-k*60;return h.filter(g=>g.timestamp>=A)},[h,d]),C=f.useMemo(()=>y.length===0?null:y.reduce((_,k)=>k.timestamp>_.timestamp?k:_),[y]),T=x.isDecoding,v=f.useMemo(()=>{const _=Date.now()/1e3,k=ee[d].minutes,A=_-k*60,g=new Set;let D=0;for(const P of s)(P.type??P.payload_type)===rt.GRP_TXT&&((P.timestamp??0)<A||g.has(P.packet_hash)||(g.add(P.packet_hash),D++));return D},[s,d]),w=Qs(),b=f.useMemo(()=>{const _=Date.now()/1e3,k=ee[d].minutes,A=_-k*60;for(const g of s)if((g.type??g.payload_type)===rt.GRP_TXT&&!((g.timestamp??0)<A)&&!w.has(g.packet_hash))return!0;return!1},[s,w,d]),p=f.useCallback((_,k)=>{if(!T){if(_){const A=k.find(g=>g.hash===_);if(A){Ce.getState().queueChannelDecryption(s,A.name);return}}Ce.getState().queueDecryption(s)}},[s,T]);return o?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:u,className:J("group cursor-pointer rounded-2xl transition-all duration-150","bg-surface/80 backdrop-blur-lg depth-raised","hover:bg-subtle-fill","px-3 py-2.5 sm:px-4 sm:py-3"),children:t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-shrink-0",children:[t.jsx(ss,{className:"size-4 text-icon-card-title flex-shrink-0"}),t.jsx("span",{className:"type-micro",children:"CHAT ACTIVITY"}),v>0&&t.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-subtle-fill ring-1 ring-inset ring-edge-subtle text-sm tabular-nums text-fg-secondary",children:v}),t.jsx(mt,{className:"size-4 text-fg-muted group-hover:text-sys-indigo transition-colors ml-auto sm:hidden"})]}),t.jsxs("div",{className:"flex items-center gap-2 sm:gap-1.5 min-w-0 overflow-hidden",children:[t.jsx(Ke,{mode:"wait",initial:!1,children:C?t.jsxs(ge.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},exit:{opacity:0,y:-16},transition:{duration:.2,ease:[.4,0,.2,1]},className:"flex items-center gap-2 sm:gap-1.5 min-w-0",children:[C.channelName&&t.jsx("span",{className:"hidden sm:inline-flex",children:t.jsx(Qt,{channelName:C.channelName})}),t.jsx("div",{className:"hidden sm:flex w-[30px] h-[30px] clay-avatar",style:{"--avatar-color":Rn(He(C.senderName||"").cleanName)},children:He(C.senderName||"").emoji?t.jsx("span",{className:"text-base",children:He(C.senderName||"").emoji}):t.jsx("span",{className:"text-white text-xs font-bold tracking-tighter",children:An(C.senderName||"")})}),t.jsx("div",{className:"inline-flex items-center px-3 py-1.5 rounded-2xl rounded-tr-md bg-[#007AFF] shadow-sm min-w-0 flex-1 sm:flex-initial sm:max-w-xs sm:-ml-px",children:t.jsx("span",{className:"text-sm text-white truncate tracking-wide",children:Pn(C.text,{isOutgoing:!0})})}),t.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-subtle-fill ring-1 ring-inset ring-edge-subtle text-sm tabular-nums text-fg-secondary flex-shrink-0",children:en(C.timestamp)})]},`msg-${C.timestamp}-${C.senderName}-${C.channelHash}`):N?t.jsx(ge.span,{initial:{opacity:0},animate:{opacity:1},className:"text-sm text-fg-muted italic",children:"No messages yet"},"empty"):t.jsxs(ge.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,y:-16},transition:{duration:.15},className:"flex items-center gap-2 sm:gap-1.5",children:[t.jsx("div",{className:"hidden sm:block w-8 h-4 rounded bg-subtle-fill-strong animate-pulse"}),t.jsx("div",{className:"hidden sm:block w-[30px] h-[30px] rounded-full bg-subtle-fill-strong animate-pulse"}),t.jsx("div",{className:"h-8 w-32 sm:w-48 rounded-2xl bg-subtle-fill-strong animate-pulse"}),t.jsx("div",{className:"w-12 h-6 rounded-md bg-subtle-fill-strong animate-pulse"})]},"skeleton")}),t.jsx(mt,{className:"size-4 text-fg-muted group-hover:text-sys-indigo transition-colors flex-shrink-0 hidden sm:block ml-1"})]})]})}),t.jsx(go,{open:r,onClose:()=>a(!1),messages:h,onLoadMore:p,hasMoreToLoad:b,isDecoding:T,initialChannel:c})]}):t.jsx("div",{className:"h-14 rounded-xl bg-elevated/50 animate-pulse"})}const q=2,jo=2,De=5,Re=4,be=20,We=Qe(Y.cyan),qe=Qe(Y.amber),Xe=Qe(Y.red);function tt(e,n,o){const s=o.length;if(s===0)return null;let r=0,a=0;for(let w=0;w<s;w++){const b=o[w].allowedDelta+o[w].droppedDelta;b>r&&(r=b);const p=o[w].newlyGuarded.length;p>a&&(a=p)}if(r===0&&a===0)return null;const c=Math.max(1,De-a),i=r>0?Math.max(1,Math.ceil(r/c)):1,d=e-Re*2,u=n-Re*2,m=(d-q*(be-1))/be,j=(u-q*(De-1))/De,l=Math.max(3,Math.min(m,j)),x=l+q,N=s,h=0,y=be*x-q,C=Re+(d-y)/2,T=De*x-q,B=Re+(u-T),v=Math.min(jo,l/3);return{quantum:i,tileSize:l,colStep:x,visibleCols:N,startIdx:h,offsetX:C,offsetY:B,gridH:T,r:v}}function wo(e,n,o,s,r){e.clearRect(0,0,o*(window.devicePixelRatio||1),s*(window.devicePixelRatio||1));const a=tt(o,s,n);if(a)for(let c=0;c<a.visibleCols;c++){const i=n[a.startIdx+c],d=Math.ceil(i.allowedDelta/a.quantum),u=Math.ceil(i.droppedDelta/a.quantum),m=i.newlyGuarded.length,j=d+u+m;if(j===0)continue;const l=a.offsetX+c*a.colStep,x=(r==null?void 0:r.col)===c,N=x?r.segment:null;for(let h=0;h<d;h++){const y=a.offsetY+a.gridH-(h+1)*a.colStep+q,C=N==="allowed"?1:x?.35:1;e.fillStyle=`rgba(${We.r},${We.g},${We.b},${C})`,e.beginPath(),e.roundRect(l,y,a.tileSize,a.tileSize,a.r),e.fill()}for(let h=0;h<u;h++){const y=a.offsetY+a.gridH-(d+h+1)*a.colStep+q;if(y<a.offsetY-a.tileSize)break;const C=N==="dropped"?1:x?.35:1;e.fillStyle=`rgba(${qe.r},${qe.g},${qe.b},${C})`,e.beginPath(),e.roundRect(l,y,a.tileSize,a.tileSize,a.r),e.fill()}for(let h=0;h<m;h++){const y=a.offsetY+a.gridH-(d+u+h+1)*a.colStep+q;if(y<a.offsetY-a.tileSize)break;const C=N==="guarded"?1:x?.35:1;e.fillStyle=`rgba(${Xe.r},${Xe.g},${Xe.b},${C})`,e.beginPath(),e.roundRect(l,y,a.tileSize,a.tileSize,a.r),e.fill()}if(x&&N){e.save(),e.strokeStyle="rgba(255,255,255,0.4)",e.lineWidth=1;let h=0,y=0;N==="allowed"&&d>0?(h=a.offsetY+a.gridH-d*a.colStep+q,y=d*a.colStep-q):N==="dropped"&&u>0?(h=a.offsetY+a.gridH-(d+u)*a.colStep+q,y=u*a.colStep-q):N==="guarded"&&m>0&&(h=a.offsetY+a.gridH-j*a.colStep+q,y=m*a.colStep-q),y>0&&(e.beginPath(),e.roundRect(l-1,h-1,a.tileSize+2,y+2,a.r+1),e.stroke()),e.restore()}}}function No(e,n,o,s,r){const a=tt(o,s,r);if(!a)return null;const c=Math.floor((e-a.offsetX+q/2)/a.colStep);if(c<0||c>=a.visibleCols)return null;const i=r[a.startIdx+c],d=Math.ceil(i.allowedDelta/a.quantum),u=Math.ceil(i.droppedDelta/a.quantum),m=i.newlyGuarded.length,j=d+u+m;if(j===0)return null;const l=a.offsetX+c*a.colStep;if(e<l||e>l+a.tileSize)return null;const x=a.offsetY+a.gridH,N=x-d*a.colStep+q,h=x-(d+u)*a.colStep+q,y=x-j*a.colStep+q;return m>0&&n>=y&&n<h?{col:c,segment:"guarded"}:u>0&&n>=h&&n<N?{col:c,segment:"dropped"}:d>0&&n>=N&&n<=x?{col:c,segment:"allowed"}:null}function Ue(e){return new Date(e*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const de=5;function vo(e){if(e<60)return`${Math.round(e)}s`;if(e<3600)return`${Math.floor(e/60)}m`;const n=Math.floor(e/3600),o=Math.floor(e%3600/60);return o>0?`${n}h ${o}m`:`${n}h`}function ko(e,n,o,s){const r=e.allowedDelta+e.droppedDelta;if(n==="allowed")return t.jsxs("div",{className:"min-w-[120px] space-y-1",children:[t.jsx("div",{className:"text-[10px] text-fg-muted tabular-nums",children:Ue(e.ts)}),t.jsxs("div",{className:"text-xs tabular-nums",children:[t.jsx("span",{className:"text-sys-cyan font-medium",children:e.allowedDelta}),t.jsx("span",{className:"text-fg-muted",children:" adverts allowed"})]}),e.trackedCount>0&&t.jsxs("div",{className:"text-[10px] text-fg-muted tabular-nums",children:[e.trackedCount," sources tracked"]}),r>0&&t.jsxs("div",{className:"text-[10px] text-fg-muted tabular-nums",children:[Math.round(e.allowedDelta/r*100),"% of traffic"]})]});if(n==="dropped"){const a=r>0?Math.round(e.droppedDelta/r*100):0,c=a-o;return t.jsxs("div",{className:"min-w-[140px] max-w-[240px] space-y-1",children:[t.jsx("div",{className:"text-[10px] text-fg-muted tabular-nums",children:Ue(e.ts)}),t.jsxs("div",{className:"text-xs tabular-nums",children:[t.jsx("span",{className:"text-sys-amber font-medium",children:e.droppedDelta}),t.jsx("span",{className:"text-fg-muted",children:" adverts dropped"})]}),r>0&&t.jsxs("div",{className:"text-[10px] tabular-nums",children:[t.jsxs("span",{className:a>50?"text-sys-amber":"text-fg-muted",children:[a,"% drop rate"]}),Math.abs(c)>=5&&t.jsxs("span",{className:c>0?"text-sys-amber":"text-sys-cyan",children:[" ","(",c>0?"+":"",c,"% vs avg)"]})]}),e.drops.length>0&&t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:[e.drops.slice(0,de).map((i,d)=>t.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[t.jsx("span",{className:"font-mono truncate",children:i.name||i.pubkey.slice(0,8)}),t.jsx("span",{className:"text-fg-muted text-[10px] truncate flex-shrink-0 max-w-[100px]",children:i.reason})]},`${i.pubkey}-${d}`)),e.drops.length>de&&t.jsxs("div",{className:"text-[10px] text-fg-muted",children:["+",e.drops.length-de," more"]})]})]})}return t.jsxs("div",{className:"min-w-[140px] max-w-[220px] space-y-1",children:[t.jsx("div",{className:"text-[10px] text-fg-muted tabular-nums",children:Ue(e.ts)}),t.jsxs("div",{className:"text-xs text-sys-red font-medium",children:[e.newlyGuarded.length," newly guarded"]}),e.newlyGuarded.length>0&&t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:[e.newlyGuarded.slice(0,de).map(a=>t.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[t.jsx("span",{className:"font-mono truncate",children:s(a.pubkey)}),t.jsx("span",{className:"text-fg-muted tabular-nums flex-shrink-0",children:vo(a.remaining)})]},a.pubkey)),e.newlyGuarded.length>de&&t.jsxs("div",{className:"text-[10px] text-fg-muted",children:["+",e.newlyGuarded.length-de," more"]})]})]})}function Mo(e){if(e.length<=be)return e;const n=Math.ceil(e.length/be),o=[];for(let s=0;s<e.length;s+=n){const r=e.slice(s,s+n),a={ts:r[r.length-1].ts,allowedDelta:0,droppedDelta:0,newlyGuarded:[],penalties:r[r.length-1].penalties,drops:[],trackedCount:r[r.length-1].trackedCount};for(const c of r)a.allowedDelta+=c.allowedDelta,a.droppedDelta+=c.droppedDelta,a.newlyGuarded=a.newlyGuarded.concat(c.newlyGuarded),a.drops=a.drops.concat(c.drops);o.push(a)}return o}function Co(){var A,g,D,P,R,L;const e=ve(),n=sn(),o=f.useMemo(()=>Mo(n),[n]),s=f.useRef(null),r=f.useRef(null),{show:a,hide:c,updatePosition:i}=nn(),d=f.useRef(!1),u=f.useRef(null),m=ie(),j=an(),[l,x]=f.useState(!1),N=(g=(A=m==null?void 0:m.config)==null?void 0:A.repeater)==null?void 0:g.advert_rate_limit,h=(P=(D=m==null?void 0:m.config)==null?void 0:D.repeater)==null?void 0:P.advert_penalty_box,y=(L=(R=m==null?void 0:m.config)==null?void 0:R.repeater)==null?void 0:L.advert_adaptive,C=(e==null?void 0:e.stats.adverts_allowed)??0,T=(e==null?void 0:e.stats.adverts_dropped)??0,B=f.useMemo(()=>{const S=new Set;for(const F of o)for(const M of F.newlyGuarded)S.add(M.pubkey);return S.size},[o]),v=f.useMemo(()=>{const S=new Map;for(const M of(e==null?void 0:e.recent_drops)??[])M.name&&S.set(M.pubkey,M.name);const F=(m==null?void 0:m.neighbors)??{};for(const[M,$]of Object.entries(F))if(!S.has(M)){const E=$.name||$.node_name;E&&S.set(M,E)}return M=>S.get(M)||M.slice(0,8)},[e==null?void 0:e.recent_drops,m==null?void 0:m.neighbors]),w=f.useMemo(()=>{let S=0,F=0;for(const $ of o)S+=$.allowedDelta,F+=$.droppedDelta;const M=S+F;return M>0?Math.round(F/M*100):0},[o]),b="10m",p=f.useCallback(()=>{const S=s.current,F=r.current;if(!S||!F)return;const M=F.getBoundingClientRect(),$=window.devicePixelRatio||1,E=Math.floor(M.width),W=Math.floor(M.height);if(E===0||W===0)return;S.width=E*$,S.height=W*$,S.style.width=`${E}px`,S.style.height=`${W}px`;const I=S.getContext("2d");I&&(I.scale($,$),wo(I,o,E,W,u.current))},[o]);f.useEffect(()=>{p();const S=new ResizeObserver(()=>p());return r.current&&S.observe(r.current),()=>S.disconnect()},[p]);const _=f.useCallback(S=>{const F=r.current;if(!F||o.length===0)return;const M=F.getBoundingClientRect(),$=Math.floor(M.width),E=Math.floor(M.height),W=S.clientX-M.left,I=S.clientY-M.top,O=No(W,I,$,E,o);if(!O){u.current&&(u.current=null,p()),d.current&&(d.current=!1,c());return}const z=u.current;(!z||z.col!==O.col||z.segment!==O.segment)&&(u.current=O,p());const G=tt($,E,o);if(!G)return;const H=o[G.startIdx+O.col],U=ko(H,O.segment,w,v);d.current?i(S.clientX,S.clientY):d.current=!0,a(U,S.clientX,S.clientY)},[o,w,v,a,c,i,p]),k=f.useCallback(()=>{u.current&&(u.current=null,p()),d.current&&(d.current=!1,c())},[c,p]);return t.jsxs(je,{noPadding:!0,isLoaded:!0,className:"mini-widget overflow-hidden flex flex-col",children:[t.jsxs("div",{className:"mini-widget-header",children:[t.jsx(En,{className:"mini-widget-icon"}),t.jsx("span",{className:"mini-widget-title",children:"Advert Decisions"}),t.jsx(ne,{color:"zinc",children:b})]}),t.jsx("div",{ref:r,className:"h-28 mx-2 overflow-hidden radius-inner depth-stroke-inset bg-chart-inner",onMouseMove:_,onMouseLeave:k,children:o.length>0?t.jsx("canvas",{ref:s,className:"block w-full h-full"}):t.jsx("div",{className:"flex items-center justify-center w-full h-full text-xs text-fg-muted",children:"Waiting for data…"})}),t.jsxs("div",{className:"grid grid-cols-2 gap-x-3 sm:gap-x-4 gap-y-1 px-3 py-2.5 type-data-xs",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"shrink-0 w-3 h-3 rounded-xs bg-sys-cyan"}),t.jsx("span",{className:"text-fg-secondary uppercase tracking-wide whitespace-nowrap",children:"Allow"}),t.jsx("span",{className:"tabular-nums text-fg-muted shrink-0",children:t.jsx(re,{value:C,priority:"low"})})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"shrink-0 w-3 h-3 rounded-xs bg-sys-amber"}),t.jsx("span",{className:"text-fg-secondary uppercase tracking-wide whitespace-nowrap",children:"Drop"}),t.jsx("span",{className:"tabular-nums text-fg-muted shrink-0",children:t.jsx(re,{value:T,priority:"low"})})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"shrink-0 w-3 h-3 rounded-xs bg-sys-red"}),t.jsx("span",{className:"text-fg-secondary uppercase tracking-wide whitespace-nowrap",children:"In Jail"}),t.jsx("span",{className:"tabular-nums text-fg-muted shrink-0",children:B})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"shrink-0 w-3 h-3 rounded-xs bg-zinc-500/30"}),t.jsx("span",{className:"text-fg-secondary uppercase tracking-wide whitespace-nowrap",children:"Tracked"}),t.jsx("span",{className:"tabular-nums text-fg-muted shrink-0",children:(e==null?void 0:e.tracked_pubkeys)??0})]})]}),t.jsx("div",{className:"mt-auto px-2 pb-2",children:t.jsxs($e,{color:"primary",outline:!0,className:"w-full justify-center",onClick:()=>x(!0),children:[t.jsx(In,{"data-slot":"icon"}),"Adapt"]})}),t.jsx(Bn,{open:l,onClose:()=>x(!1),currentConfig:{tokenBucket:N,penaltyBox:h,adaptive:y},onApplied:async()=>{await j({force:!0}).catch(()=>{})}})]})}const To=f.memo(Co);function So(e){if(e<60)return`${Math.round(e)}s`;if(e<3600)return`${Math.floor(e/60)}m`;const n=Math.floor(e/3600),o=Math.floor(e%3600/60);return o>0?`${n}h ${o}m`:`${n}h`}function _o(){const e=ve(),n=ie();return{all:f.useMemo(()=>{if(!(e!=null&&e.active_penalties))return[];const s=new Map;for(const i of e.recent_drops??[])i.name&&s.set(i.pubkey,i.name);const r=(n==null?void 0:n.neighbors)??{};for(const[i,d]of Object.entries(r))if(!s.has(i)){const u=d.name||d.node_name;u&&s.set(i,u)}const a=new Map,c=new Map;for(const i of e.recent_drops??[])a.has(i.pubkey)||a.set(i.pubkey,i.reason),c.set(i.pubkey,(c.get(i.pubkey)??0)+1);return Object.entries(e.active_penalties).sort(([,i],[,d])=>d-i).map(([i,d])=>({pubkey:i,name:s.get(i)||i.slice(0,8),remaining:d,reason:a.get(i),dropCount:c.get(i)??0}))},[e,n==null?void 0:n.neighbors]),isLoading:!e,penaltyCount:e?Object.keys(e.active_penalties??{}).length:0}}function gs({offender:e,rank:n}){const o=n===0;return t.jsx(me,{content:t.jsxs("div",{className:"max-w-[260px]",children:[t.jsx("div",{className:"font-semibold mb-1",children:e.name}),t.jsx("div",{className:"text-fg-muted text-xs font-mono mb-1",children:e.pubkey}),t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1 space-y-0.5 text-xs",children:[t.jsxs("div",{children:["Penalty: ",So(e.remaining)," remaining"]}),e.reason&&t.jsxs("div",{children:["Reason: ",e.reason]}),t.jsxs("div",{children:["Recent drops: ",e.dropCount]})]})]}),children:t.jsx("div",{className:"text-xs sm:text-sm radius-badge px-1 -mx-1 hover-bg transition-base cursor-default",children:t.jsx("span",{className:`font-mono truncate ${o?"font-semibold text-sys-red":"text-fg-muted"}`,children:e.name})})})}function Bo({open:e,onClose:n,offenders:o}){return t.jsxs(Vt,{open:e,onClose:n,size:"sm",children:[t.jsx(on,{icon:t.jsx(os,{size:20}),title:`Jail (${o.length})`,onClose:n}),t.jsx(Yt,{className:"flex flex-col gap-1 max-h-[60vh] overflow-y-auto",children:o.length===0?t.jsx("div",{className:"text-center text-sm text-fg-muted py-4",children:"No active penalties"}):o.map(s=>t.jsx(gs,{offender:s},s.pubkey))})]})}function Do(){const{all:e,isLoading:n,penaltyCount:o}=_o(),s=ve(),[r,a]=f.useState(!1),c=f.useCallback(()=>a(!0),[]),i=f.useCallback(()=>a(!1),[]),d=e.slice(0,3),u=(s==null?void 0:s.recent_drops)??[],m=o===0&&u.length>0&&!n,j=u.slice(0,3);return t.jsxs(t.Fragment,{children:[t.jsxs(le,{title:"Most Wanted",icon:t.jsx(os,{className:"mini-widget-icon"}),isLoading:n,isLoaded:!0,children:[d.length>0?t.jsx("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:d.map((l,x)=>t.jsx(gs,{offender:l,rank:x},l.pubkey))}):m?t.jsx("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:j.map((l,x)=>t.jsx(me,{content:t.jsxs("div",{className:"max-w-[260px]",children:[t.jsx("div",{className:"font-semibold mb-1",children:l.name||l.pubkey}),t.jsx("div",{className:"text-fg-muted text-xs font-mono mb-1",children:l.pubkey}),t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1 text-xs",children:[t.jsxs("div",{children:["Reason: ",l.reason]}),t.jsxs("div",{children:[Math.round(l.seconds_ago),"s ago"]})]})]}),children:t.jsxs("div",{className:"flex items-center gap-1 text-xs sm:text-sm radius-badge px-1 -mx-1 hover-bg transition-base cursor-default",children:[t.jsx("span",{className:`font-mono truncate flex-1 min-w-0 ${x===0?"font-semibold text-sys-amber":"text-fg-muted"}`,children:l.name||l.pubkey.slice(0,8)}),t.jsx("span",{className:`pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right truncate ${x===0?"text-sys-amber":"text-fg-muted"}`,children:l.reason.replace(/^Token bucket: /,"").replace(/^Penalty: /,"")})]})},l.pubkey))}):o===0&&!n?t.jsx("div",{className:"flex items-center justify-center text-xs text-fg-muted mt-auto",children:"No active penalties"}):null,o>0?t.jsxs("div",{className:"flex items-center mt-auto pt-0.5",children:[t.jsxs("span",{className:"text-[10px] text-fg-muted tabular-nums",children:[o," in jail"]}),o>3&&t.jsx($e,{plain:!0,className:"ml-auto text-[10px] text-sys-blue hover:underline",onClick:c,children:"Show All"})]}):m?t.jsx("div",{className:"flex items-center mt-auto pt-0.5",children:t.jsxs("span",{className:"text-[10px] text-sys-amber tabular-nums",children:[u.length," recent drop",u.length!==1?"s":""]})}):null]}),t.jsx(Bo,{open:r,onClose:i,offenders:e})]})}const Tt=[{key:"quiet",color:Y.green,label:"Quiet"},{key:"normal",color:Y.blue,label:"Normal"},{key:"busy",color:Y.amber,label:"Busy"},{key:"congested",color:Y.red,label:"Congested"}],St={quiet:"text-sys-green",normal:"text-sys-blue",busy:"text-sys-amber",congested:"text-sys-red"},_t=2,Ro=4;function Ao(e,n,o,s){const{quietMax:r,normalMax:a,busyMax:c,ewmaValue:i}=n;e.clearRect(0,0,o,s);const d=Math.max(c*2,i*1.3,c+.5),u=_t*3,m=o-u,j=[{start:0,end:r,color:Y.green},{start:r,end:a,color:Y.blue},{start:a,end:c,color:Y.amber},{start:c,end:d,color:Y.red}],l=[];let x=0;for(const k of j){const A=(k.end-k.start)/d*m;l.push({...k,px:x,pw:A}),x+=A+_t}const N=8,h=N,y=s-N-2;for(const k of l)e.fillStyle=k.color,e.globalAlpha=1,e.beginPath(),e.roundRect(k.px,h,k.pw,y,Ro),e.fill();function C(k){const A=Math.max(0,Math.min(k,d));for(const D of l)if(A<=D.end){const P=D.end>D.start?(A-D.start)/(D.end-D.start):0;return D.px+P*D.pw}const g=l[l.length-1];return g.px+g.pw}const T=C(i),B=4,v=4,w=h-1,b=h+y+1,p=lt[900],_=lt[200];e.fillStyle=p,e.beginPath(),e.moveTo(T-v,w-B),e.lineTo(T+v,w-B),e.lineTo(T,w),e.closePath(),e.fill(),e.fillStyle=_,e.beginPath(),e.moveTo(T-(v-1),w-B+.5),e.lineTo(T+(v-1),w-B+.5),e.lineTo(T,w-.5),e.closePath(),e.fill();for(const[k,A]of[[p,-1],[_,0],[p,1]])e.strokeStyle=k,e.lineWidth=1,e.beginPath(),e.moveTo(T+A,w),e.lineTo(T+A,b),e.stroke()}const Ae={stiffness:120,damping:20,mass:.8};function Po(){var g,D,P,R,L,S,F;const e=ve(),n=Jt(),o=Zt(),s=rn(),r=ie(),a=f.useRef(null),c=f.useRef(null),i=(D=(g=r==null?void 0:r.config)==null?void 0:g.repeater)==null?void 0:D.advert_adaptive,d=(e==null?void 0:e.adaptive.current_tier)??"normal",u=e==null?void 0:e.adaptive.pending_tier,m=!!u&&u!==d,j=((P=i==null?void 0:i.thresholds)==null?void 0:P.quiet_max)??.05,l=((R=i==null?void 0:i.thresholds)==null?void 0:R.normal_max)??.2,x=((L=i==null?void 0:i.thresholds)==null?void 0:L.busy_max)??.5,N=ue(s),h=Se(N,Ae),y=ue(j),C=ue(l),T=ue(x),B=Se(y,Ae),v=Se(C,Ae),w=Se(T,Ae);f.useEffect(()=>{N.set(s)},[s,N]),f.useEffect(()=>{y.set(j)},[j,y]),f.useEffect(()=>{C.set(l)},[l,C]),f.useEffect(()=>{T.set(x)},[x,T]);const b=f.useCallback(()=>{const M=a.current,$=c.current;if(!M||!$)return;const E=$.getBoundingClientRect(),W=window.devicePixelRatio||1,I=Math.floor(E.width),O=Math.floor(E.height);if(I===0||O===0)return;M.width=I*W,M.height=O*W,M.style.width=`${I}px`,M.style.height=`${O}px`;const z=M.getContext("2d");z&&(z.scale(W,W),Ao(z,{quietMax:B.get(),normalMax:v.get(),busyMax:w.get(),ewmaValue:h.get()},I,O))},[B,v,w,h]);f.useEffect(()=>{const M=[h.on("change",()=>b()),B.on("change",()=>b()),v.on("change",()=>b()),w.on("change",()=>b())];return()=>M.forEach($=>$())},[h,B,v,w,b]),f.useEffect(()=>{b();const M=new ResizeObserver(()=>b());return c.current&&M.observe(c.current),()=>M.disconnect()},[b]);const p=((S=Tt.find(M=>M.key===d))==null?void 0:S.label)??d,_=St[d]??"text-fg-muted",k=!e&&!o,A=o&&!n;return t.jsxs(le,{title:"Adaptive Tier",icon:t.jsx(ln,{className:"mini-widget-icon"}),isLoading:k,isLoaded:!0,error:A?"Adaptive tier data unavailable":null,headerRight:t.jsxs("span",{className:"text-[10px] text-fg-muted tabular-nums",children:[t.jsx("span",{className:"data-box data-box-compact",children:s.toFixed(2)}),t.jsx("span",{className:"ml-0.5 text-fg-muted/60",children:"adv/min"})]}),children:[t.jsx("div",{ref:c,className:"w-full h-8 sm:h-10 md:h-12",children:t.jsx("canvas",{ref:a,className:"block w-full h-full"})}),t.jsxs("div",{className:J("data-box data-box-fill text-center font-semibold uppercase tracking-wide mt-1",_),children:[p,m&&t.jsxs("span",{className:J("ml-1.5 text-[10px] font-normal animate-pulse",St[u]??"text-fg-muted"),children:["→ ",((F=Tt.find(M=>M.key===u))==null?void 0:F.label)??u]})]})]})}const Lo=f.memo(Po);function Bt(e){if(e<60)return`${e}s`;if(e<3600){const s=Math.floor(e/60),r=e%60;return r>0?`${s}m ${r}s`:`${s}m`}const n=Math.floor(e/3600),o=Math.floor(e%3600/60);return o>0?`${n}h ${o}m`:`${n}h`}function $o(){var l;const e=ve(),n=((e==null?void 0:e.stats.drop_rate)??0)*100,o=(e==null?void 0:e.stats.adverts_allowed)??0,s=(e==null?void 0:e.stats.adverts_dropped)??0,r=(e==null?void 0:e.tracked_pubkeys)??0,a=(e==null?void 0:e.effective_limits)??null,c=((l=e==null?void 0:e.metrics)==null?void 0:l.duplicate_ratio_ewma)??0,i=(e==null?void 0:e.stats.adverts_duplicate_reheard)??0,d=o+s,u=d>0?o/d*100:100,m=!e,j=d>0?s/d*100:0;return t.jsx(le,{title:"Drop Rate",icon:t.jsx(ns,{className:"mini-widget-icon"}),value:Math.round(n),unit:"%",isLoading:m,isLoaded:!0,headerRight:t.jsxs("span",{className:"text-[10px] text-fg-muted tabular-nums",children:["Tracked ",t.jsx("span",{className:"data-box data-box-compact ml-0.5",children:r})]}),children:d>0&&t.jsx(me,{content:t.jsxs("div",{className:"min-w-[140px] space-y-1",children:[t.jsx("div",{className:"text-xs text-fg-secondary font-medium",children:"Effective Limits"}),a?t.jsxs("div",{className:"space-y-0.5 text-[10px] tabular-nums",children:[t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Bucket"}),t.jsxs("span",{children:[a.bucket_capacity," tokens"]})]}),t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Refill"}),t.jsxs("span",{children:[a.refill_tokens," / ",Bt(a.refill_interval_seconds)]})]}),a.min_interval_seconds>0&&t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Min interval"}),t.jsx("span",{children:Bt(a.min_interval_seconds)})]})]}):t.jsx("div",{className:"text-[10px] text-fg-muted",children:"Limits not available"}),t.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1 space-y-0.5 text-[10px] tabular-nums",children:[t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Tracked"}),t.jsxs("span",{children:[r," pubkey",r!==1?"s":""]})]}),i>0&&t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Deduped"}),t.jsxs("span",{children:[i.toLocaleString()," (",Math.round(c*100),"%)"]})]})]})]}),children:t.jsxs("div",{className:"w-full mt-auto cursor-default",children:[t.jsxs("div",{className:"flex h-1.5 gap-0.5",children:[t.jsx("div",{className:"h-full rounded-full bg-sys-cyan transition-all duration-500",style:{width:`${u}%`}}),t.jsx("div",{className:"h-full rounded-full bg-sys-red transition-all duration-500",style:{width:`${j}%`}})]}),t.jsxs("div",{className:"flex justify-between mt-0.5",children:[t.jsx("span",{className:"type-data-xs text-sys-cyan/70 tabular-nums",children:o.toLocaleString()}),t.jsx("span",{className:"type-data-xs text-sys-red/70 tabular-nums",children:s.toLocaleString()})]})]})})})}const Fo="/assets/spam-can-JZXwgFOy.svg",Eo=1376,Ve=768,Io=[{x:0,w:280,stretch:!1},{x:280,w:4,stretch:!0},{x:284,w:808,stretch:!1},{x:1092,w:4,stretch:!0},{x:1096,w:280,stretch:!1}];function Ho(){return t.jsx("div",{className:"relative h-full w-full overflow-hidden rounded-[var(--radius-card)]",children:t.jsx("div",{className:"absolute inset-0 flex","data-spam-can":!0,children:Io.map(({x:e,w:n,stretch:o})=>t.jsx("svg",{viewBox:`${e} 0 ${n} ${Ve}`,preserveAspectRatio:"none",style:o?{height:"100%",flex:"1 1 0",minWidth:0}:{height:"100%",aspectRatio:`${n} / ${Ve}`,flexShrink:0},children:t.jsx("image",{href:Fo,width:Eo,height:Ve})},e))})})}const zo=f.memo(Ho);function Oo(){const e=Jt();return!Zt()||!e?null:t.jsxs("div",{className:"mesh-health-container relative",children:[t.jsxs("div",{className:"mesh-health-header",children:[t.jsx(Un,{className:"w-4 h-4 text-sys-blue"}),t.jsx("span",{className:"type-label text-fg-muted",children:"SPAMGUARD"})]}),t.jsxs("div",{className:"widget-row",children:[t.jsx("div",{className:"widget-leading",children:t.jsx(To,{})}),t.jsx(Lo,{}),t.jsx($o,{}),t.jsx(Do,{}),t.jsx(zo,{})]})]})}function Dr(){var g,D,P;const e=ie(),n=cn(),o=dn(),s=ga(),r=f.useRef(!1);o&&!r.current&&(r.current=!0);const a=r.current,c=Ne(),i=Ut(),d=un(),u=ee[c]??ee[4],m=d.isBackgroundLoading&&c>=5,[j,l]=f.useState([]),[x,N]=f.useState(0),[h,y]=f.useState(()=>localStorage.getItem("rx-crc-overlay")==="true"),C=f.useCallback(()=>{y(R=>{const L=!R;return localStorage.setItem("rx-crc-overlay",String(L)),L})},[]),[T,B]=f.useState(()=>localStorage.getItem("rx-analytics-view")==="true"),v=f.useCallback(R=>{B(R),localStorage.setItem("rx-analytics-view",String(R))},[]);f.useEffect(()=>{const R=u.minutes/60;Promise.all([Wt(R),Gt(R,5e4)]).then(([L,S])=>{var F,M;N((L.success&&((F=L.data)==null?void 0:F.count)!=null?L.data.count:S.success&&((M=S.data)==null?void 0:M.count)!=null?S.data.count:0)??0),l(S.success&&S.data?S.data.history:[])})},[u.minutes]);const w=f.useMemo(()=>{const R=O=>(O==null?void 0:O.reduce((z,G)=>z+G.count,0))??0,L=R(s==null?void 0:s.received),S=R(s==null?void 0:s.unique_received),F=R(s==null?void 0:s.forwarded),M=R(s==null?void 0:s.dropped),$=R(s==null?void 0:s.transmitted),E=((s==null?void 0:s.time_range_minutes)??u.minutes)/60,W=E>0?Math.round(L/E):0,I=E>0?Math.round(F/E):0;return{received:L,uniqueReceived:S,forwarded:F,dropped:M,transmitted:$,rxPerHour:W,fwdPerHour:I}},[s,u.minutes]),b=f.useMemo(()=>s?{totalBytes:s.totalReceivedBytes,kbPerHour:s.kbPerHour}:{totalBytes:0,kbPerHour:0},[s]),p=f.useMemo(()=>{if(!s)return[];const{receivedBytesBuckets:R,start_time:L,bucket_duration_seconds:S,bucket_count:F}=s,M=new Array(F).fill(0);for(const $ of j){let E=Math.floor(($.timestamp-L)/S);E<0&&(E=0),!(E>=F)&&M[E]++}return R.map(($,E)=>({start:$.start,end:$.end,bytesByType:{...$.countByType,...h&&M[E]>0?{[Q]:M[E]}:{}},totalBytes:$.totalCount}))},[s,j,h]),_=f.useMemo(()=>{if(!s)return[];const{receivedCountByType:R}=s,L=Object.keys(R).map(S=>parseInt(S,10)).filter(S=>(R[S]??0)>0).sort((S,F)=>(R[F]??0)-(R[S]??0));return h&&x>0&&L.unshift(Q),L},[s,x,h]),k=f.useMemo(()=>{if(!s)return{};const R={...s.receivedCountByType??{}};return h&&x>0&&(R[Q]=x),R},[s,x,h]),A=(e==null?void 0:e.node_name)??((g=e==null?void 0:e.config)==null?void 0:g.node_name)??"Unknown Node";return f.useEffect(()=>{A&&A!=="Unknown Node"&&(document.title=`pyMC: ${A}`)},[A]),n?t.jsxs(dt,{neomorphic:!0,className:"p-8 text-center",children:[t.jsx("p",{className:"type-subheading text-sys-red mb-2",children:"Failed to connect to backend"}),t.jsx("p",{className:"type-body text-fg-muted",children:n}),t.jsx("p",{className:"type-data-sm text-fg-muted mt-4",children:"Make sure the backend is running on port 8000"})]}):t.jsxs(mn,{children:[t.jsx(fn,{title:A,icon:t.jsx(Hn,{}),subtitle:t.jsx(Tn,{}),controls:t.jsx(es,{ranges:ee,selectedIndex:c,onSelect:i,isPending:m})}),t.jsxs(pn,{ready:a,children:[t.jsx(bo,{}),t.jsx(ft,{template:"hero-auto",children:t.jsxs(dt,{neomorphic:!0,children:[t.jsx(It,{icon:t.jsx(ns,{}),title:"PACKETS RECEIVED",badge:u.label,badgeColor:"zinc",titleExtra:t.jsx(Ht,{enabled:T,onChange:v,size:"sm",label:t.jsx("span",{className:"font-mono text-xs text-fg-muted uppercase tracking-wide",children:"Advanced"})}),actions:a?t.jsx("div",{className:"flex items-center gap-1.5",children:T?t.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"CRC errors — packets corrupted during radio transmission",children:[t.jsx(ct,{className:"w-3.5 h-3.5 text-sys-red"}),t.jsxs("span",{children:["CRC ",x.toLocaleString()]})]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:C,className:"p-1 rounded hover:bg-zinc-500/20 active:bg-zinc-500/30 transition-colors touch-manipulation",title:h?"Hide CRC Errors":"Show CRC Errors","aria-label":h?"Hide CRC error overlay":"Show CRC error overlay","aria-pressed":h,children:t.jsx(ct,{className:`w-3.5 h-3.5 transition-colors ${h?"text-sys-red":"text-fg-muted"}`})}),t.jsxs("div",{className:"data-box",children:[b.kbPerHour," KB/hr"]})]})}):void 0}),t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:T?t.jsx(Da,{forwardedBuckets:(s==null?void 0:s.forwardedBytesBuckets)??[],droppedBuckets:(s==null?void 0:s.droppedBytesBuckets)??[],forwardedActiveTypes:(s==null?void 0:s.forwardedActiveTypes)??[],droppedActiveTypes:(s==null?void 0:s.droppedActiveTypes)??[],forwardedCount:w.forwarded,droppedCount:w.dropped,crcCount:x,crcHistory:j,receivedCount:w.received,forwardedTotalByType:(s==null?void 0:s.forwardedTotalByType)??{},droppedTotalByType:(s==null?void 0:s.droppedTotalByType)??{},startTime:(s==null?void 0:s.start_time)??0,bucketDurationSeconds:(s==null?void 0:s.bucket_duration_seconds)??1,bucketCount:(s==null?void 0:s.bucket_count)??0,timeRangeMinutes:u.minutes}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-wrap gap-4 sm:gap-8",children:[t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:a?t.jsx(re,{value:w.received,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsx(ne,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"Total Rx"})]}),t.jsxs("div",{className:"flex items-end gap-2",children:[t.jsx("div",{className:"type-data-xl text-fg-primary",children:a?t.jsx(re,{value:w.uniqueReceived,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsx(ne,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"Unique"})]})]}),t.jsx("div",{className:"mt-2 flex-1 min-h-0",children:t.jsx(ja,{buckets:p,activeTypes:_,totalByType:k,mode:"count"})})]})})]})}),t.jsx(uo,{leading:t.jsx(Fa,{stats:e,localHash:e==null?void 0:e.local_hash,receivedBuckets:s==null?void 0:s.received,droppedBuckets:s==null?void 0:s.dropped,forwardedBuckets:s==null?void 0:s.forwarded,bucketDurationSeconds:s==null?void 0:s.bucket_duration_seconds,timeRangeLabel:u.label})}),t.jsx(Oo,{}),t.jsx(Ia,{}),e&&t.jsx(ft,{template:"auto",children:t.jsx(Dn,{nodeName:A,publicKey:e.public_key,pathHashMode:(P=(D=e.config)==null?void 0:D.mesh)==null?void 0:P.path_hash_mode})})]})]})}export{Dr as default};
