const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-C4inJ1rU.js","assets/index-DuWodFP7.css"])))=>i.map(i=>d[i]);
import{e as Z,k as ps,n as Tt,o as St,J as xs,p as gs,q as ys,t as $e,v as bs,r as h,M as js,w as ws,_ as et,x as tt,y as _t,z as Bt,D as Ns,E as ee,F as vs,j as t,d as Je,m as Re,G as Dt,H as Rt,U as ks,K as Ms,L as De,P as Cs,N as Ts,O as Q,Q as Ss,T as _s,V as Y,W as Pe,X as At,Y as Lt,$ as se,a0 as Bs,a1 as Ds,a2 as be,a3 as Rs,a4 as st,a5 as As,a6 as Ls,a7 as Ps,a8 as $s,a9 as Fs,aa as ie,f as Pt,ab as $t,ac as Es,B as Ae,R as Ft,ad as Et,ae as Hs,af as je,ag as ne,ah as Ht,ai as It,aj as Is,ak as zs,al as Os,am as Gs,an as Ws,ao as Fe,u as zt,ap as qs,aq as nt,ar as me,as as ve,at as Ot,au as Us,av as Xs,c as J,aw as Vs,ax as Gt,ay as Wt,az as qt,aA as Ys,aB as Js,aC as we,aD as Zs,aE as Ks,aF as Qs,S as en,aG as Ze,aH as tn,aI as Ut,aJ as Xt,aK as sn,aL as nn,Z as at,aM as an,aN as on,aO as rn,aP as ot}from"./index-C4inJ1rU.js";import{C as rt,P as ln,a as cn,B as dn}from"./PageLayout-CdGXajgM.js";import{u as fe,r as he,h as un,a as mn,b as fn,i as hn}from"./consumer-registry-BEMotsU4.js";import{A as re,D as Xe}from"./DataValue-BEBX-lAu.js";import{c as pn}from"./node-types-chTBCezS.js";import{b as Vt,c as ge,a as xn,d as gn,F as ke}from"./meshcore-tx-constants-DgpFTAmf.js";import{S as yn,u as Ve,P as bn,T as jn,C as Yt}from"./PacketList-BweJrvfo.js";import{useGetDecodedContent as wn,useResolveSource as Nn}from"./usePipelineStore-BdsvnjJV.js";import{A as it}from"./arrow-right-CKEtkWtu.js";import{T as Jt}from"./TimeRangeStepper-DNUdgVzA.js";import{L as Zt}from"./LightSparkline-CReUcxTn.js";import{c as vn}from"./link-scoring-BT92qwBN.js";import{T as kn}from"./timer-Dt_XcSi6.js";import{Z as Mn}from"./zap-NBmxZJvi.js";import{A as Cn,N as Tn}from"./AutoConfigureDialog-DMNUnKrx.js";import{g as Sn,e as Ee,a as _n,f as Bn}from"./chat-utils-C6kvX8nY.js";import{C as Dn}from"./ChatBubble-CKqMOZK4.js";import{M as Kt}from"./message-square-text-oWvumC9a.js";import{C as lt}from"./chevron-right-CU8UihKL.js";import{H as Rn}from"./hash-v3bMIFKt.js";import{M as An}from"./message-square-0NHS7JT6.js";import{M as Ln}from"./MqttModeBadge-BTwynmjt.js";import{W as Pn}from"./wand-sparkles-CmoRvTcx.js";import{u as ue}from"./index-BXWmGYBj.js";import{H as $n}from"./useMapViewStore-MJt-JUde.js";import{R as ct}from"./Grid-rJkrpDAP.js";import"./chevron-up-DRV4Id7V.js";import"./primitives-DQOaSDoo.js";import"./badge-colors-Dl76Mz8m.js";import"./SignalIndicator-BTMFmuDD.js";import"./arrow-up-BNlEstyM.js";import"./arrow-down-B1116rTz.js";import"./payload-detail-BWRHeO7M.js";import"./map-pin-DlTTkXK_.js";import"./layers-B_54Ow0Q.js";import"./clock-BOSF_clE.js";import"./route-CoO8LxNT.js";import"./activity-Q-NGsRUt.js";import"./shield-rLi3RwxU.js";import"./floating-4TW7J4UF.js";import"./index-CLVX1WuQ.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 Fn=[["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"}]],dt=Z("arrow-big-down",Fn);/**
 * @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 En=[["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"}]],ut=Z("arrow-big-up",En);/**
 * @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 Hn=[["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"}]],Qt=Z("chart-column",Hn);/**
 * @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 In=[["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"}]],zn=Z("copy-x",In);/**
 * @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:"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"}]],Gn=Z("cuboid",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 Wn=[["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"}]],es=Z("ear",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 qn=[["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"}]],Un=Z("megaphone",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 Xn=[["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"}]],Vn=Z("pill-bottle",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 Yn=[["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"}]],Jn=Z("satellite-dish",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:"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"}]],ts=Z("skull",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 Kn=[["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"}]],Qn=Z("tablets",Kn);function ea(...e){const n=!Array.isArray(e[0]),o=n?0:-1,s=e[0+o],r=e[1+o],a=e[2+o],d=e[3+o],c=ps(r,a,d);return n?c(s):c}function ta(e,n,o={}){const s=e.get();let r=null,a=s,d;const c=typeof s=="string"?s.replace(/[\d.-]/g,""):void 0,f=()=>{r&&(r.stop(),r=null)},m=()=>{f();const u=ft(e.get()),y=ft(a);u!==y&&(r=new xs({keyframes:[u,y],velocity:e.getVelocity(),type:"spring",restDelta:.001,restSpeed:.01,...o,onUpdate:d}))};if(e.attach((u,y)=>{a=u,d=l=>y(mt(l,c)),Tt.postRender(()=>{var l;m(),(l=e.events.animationStart)==null||l.notify(),r==null||r.then(()=>{var x;(x=e.events.animationComplete)==null||x.notify()})})},f),St(n)){const u=n.on("change",l=>e.set(mt(l,c))),y=e.on("destroy",u);return()=>{u(),y()}}return f}function mt(e,n){return n?e+n:e}function ft(e){return typeof e=="number"?e:parseFloat(e)}function ss(e,n){const o=ue(n()),s=()=>o.set(n());return s(),gs(()=>{const r=()=>Tt.preRender(s,!1,!0),a=e.map(d=>d.on("change",r));return()=>{a.forEach(d=>d()),ys(s)}}),o}function sa(e){$e.current=[],e();const n=ss($e.current,e);return $e.current=void 0,n}function na(e,n,o,s){if(typeof e=="function")return sa(e);const a=ea(n,o,s);return Array.isArray(e)?ht(e,a):ht([e],([d])=>a(d))}function ht(e,n){const o=bs(()=>[]);return ss(e,()=>{o.length=0;const s=e.length;for(let r=0;r<s;r++)o[r]=e[r].get();return n(o)})}function aa(e,n={}){const{isStatic:o}=h.useContext(js),s=()=>St(e)?e.get():e;if(o)return na(s);const r=ue(s());return h.useInsertionEffect(()=>ta(r,e,n),[r,JSON.stringify(n)]),r}function Me(e,n={}){return aa(e,{type:"spring",...n})}const oe=ws(()=>({result:null,isComputing:!1})),oa=500,ra=300;let ce=null,Ce=null;function ia(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 la(){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 ca(e,n,o,s){const r=la();if(!r)return;const a=e.length,d=new Float64Array(a),c=new Float64Array(a),f=new Uint16Array(a),m=new Uint8Array(a),u=new Uint8Array(a),y=new Uint8Array(a),l=new Uint8Array(a),x=new Float32Array(a),b=new Float32Array(a),p=new Uint32Array(a),g=new Map;let D=0;for(let S=0;S<a;S++){const v=e[S];d[S]=v.timestamp??0,c[S]=_t(v,s),f[S]=Math.min(v.length??v.payload_length??0,65535),m[S]=(v.type??v.payload_type??0)&15;const w=v.packet_origin;u[S]=w==="tx_local"?1:w==="tx_forward"?2:0,y[S]=v.transmitted?1:0,l[S]=v.drop_reason?1:0,x[S]=v.snr??0,b[S]=v.rssi??0;const j=v.packet_hash??"";let i=g.get(j);i===void 0&&(i=D++,g.set(j,i)),p[S]=i}oe.setState({isComputing:!0});const T={type:"compute",payload:{timestamps:d,airtimeMs:c,byteSizes:f,payloadTypes:m,origins:u,transmitted:y,dropped:l,snrValues:x,rssiValues:b,hashIndices:p,rangeMinutes:n,bucketCount:o}};r.postMessage(T,[d.buffer,c.buffer,f.buffer,m.buffer,u.buffer,y.buffer,l.buffer,x.buffer,b.buffer,p.buffer])}function He(e){return Object.keys(e).map(n=>parseInt(n,10)).filter(n=>e[n]>0).sort((n,o)=>e[o]-e[n])}function da(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(u=>({...u,bytesByType:{...u.bytesByType},countByType:{...u.countByType}})),forwardedBytesBuckets:e.forwardedBytesBuckets.map(u=>({...u,bytesByType:{...u.bytesByType},countByType:{...u.countByType}})),droppedBytesBuckets:e.droppedBytesBuckets.map(u=>({...u,bytesByType:{...u.bytesByType},countByType:{...u.countByType}})),receivedTotalByType:{...e.receivedTotalByType},receivedCountByType:{...e.receivedCountByType},forwardedTotalByType:{...e.forwardedTotalByType},droppedTotalByType:{...e.droppedTotalByType}},{start_time:r,end_time:a,bucket_duration_seconds:d,bucket_count:c}=e,f=new Set;for(const u of n){const y=u.timestamp??0;if(y<r||y>a)continue;const l=Math.floor((y-r)/d);if(l<0||l>=c)continue;f.has(l)||(f.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=_t(u,o),b=u.length??u.payload_length??0,p=u.type??u.payload_type??0,g=u.packet_origin;g==="tx_local"?(s.transmitted[l].count++,s.transmitted[l].airtime_ms+=x):g==="tx_forward"||u.transmitted?(s.forwarded[l].count++,s.forwarded[l].airtime_ms+=x,s.forwardedBytesBuckets[l].bytesByType[p]=(s.forwardedBytesBuckets[l].bytesByType[p]??0)+b,s.forwardedBytesBuckets[l].totalBytes+=b,s.forwardedBytesBuckets[l].countByType[p]=(s.forwardedBytesBuckets[l].countByType[p]??0)+1,s.forwardedBytesBuckets[l].totalCount++,s.forwardedTotalByType[p]=(s.forwardedTotalByType[p]??0)+b,s.totalForwardedCount++):u.drop_reason&&(s.dropped[l].count++,s.dropped[l].airtime_ms+=x,s.droppedBytesBuckets[l].bytesByType[p]=(s.droppedBytesBuckets[l].bytesByType[p]??0)+b,s.droppedBytesBuckets[l].totalBytes+=b,s.droppedBytesBuckets[l].countByType[p]=(s.droppedBytesBuckets[l].countByType[p]??0)+1,s.droppedBytesBuckets[l].totalCount++,s.droppedTotalByType[p]=(s.droppedTotalByType[p]??0)+b,s.totalDroppedCount++),g!=="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[p]=(s.receivedBytesBuckets[l].bytesByType[p]??0)+b,s.receivedBytesBuckets[l].totalBytes+=b,s.receivedBytesBuckets[l].countByType[p]=(s.receivedBytesBuckets[l].countByType[p]??0)+1,s.receivedBytesBuckets[l].totalCount++,s.receivedTotalByType[p]=(s.receivedTotalByType[p]??0)+b,s.receivedCountByType[p]=(s.receivedCountByType[p]??0)+1,s.totalReceivedBytes+=b)}const m=s.time_range_minutes/60;return s.kbPerHour=m>0?Math.round(s.totalReceivedBytes/1024/m):0,s.forwardedRatePerHour=m>0?Math.round(s.totalForwardedCount/m):0,s.droppedRatePerHour=m>0?Math.round(s.totalDroppedCount/m):0,s.receivedActiveTypes=He(s.receivedTotalByType),s.forwardedActiveTypes=He(s.forwardedTotalByType),s.droppedActiveTypes=He(s.droppedTotalByType),s}typeof window<"u"&&Promise.all([et(()=>import("./index-C4inJ1rU.js").then(e=>e.hz),__vite__mapDeps([0,1])),et(()=>import("./index-C4inJ1rU.js").then(e=>e.hy),__vite__mapDeps([0,1]))]).then(([e,n])=>{const{DASHBOARD_TIME_RANGES:o}=n;let s=0,r=-1,a="";e.useStore.subscribe(d=>{const c=d.packets.length,f=d.globalTimeRangeIndex,m=ia(d.stats);if(c===s&&f===r&&m===a)return;const u=s,y=r,l=a;if(s=c,r=f,a=m,c===0)return;const x=o[f]??o[4],b=x.minutes,p=x.buckets,g=d.stats,D=tt(g),T=c-u,S=f!==y,v=m!==l,w=oe.getState().result;if(!S&&!v&&T>0&&T<oa&&w!==null&&w.time_range_minutes===b&&w.bucket_count===p){const i=d.packets.slice(c-T),_=da(w,i,D);oe.setState({result:_})}else Ce&&clearTimeout(Ce),Ce=setTimeout(()=>{Ce=null;const i=e.useStore.getState();if(i.packets.length===0||!i.stats)return;const _=o[i.globalTimeRangeIndex]??o[4],k=tt(i.stats);ca(i.packets,_.minutes,_.buckets,k)},ra)})});const ua=()=>oe(e=>e.result),ns=[{target:"ReceivedChart",fn:"type",minStage:1},{target:"ReceivedChart",fn:"airtime",minStage:1,when:un}];he(ns);function ma(e){const o=new Date(e*1e3).getHours();return o>=6&&o<18}function pt(e){return new Date(e*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})}const pe=32,Ie=20,fa=[.25,.5,.75,1];function ha({buckets:e,activeTypes:n,totalByType:o,mode:s="bytes"}){fe(ns);const r=Bt(),[a,d]=h.useState(null),[c,f]=h.useState(null),[m,u]=h.useState(null),y=h.useCallback((v,w,j)=>{d(w),f(j)},[]),l=e.length>0&&n.length>0,x=a?ma(a.start):null,b=a?pt(a.start):"",p=m!==null&&x!==null&&m!==x;x!==m&&u(x);const g=h.useMemo(()=>Ns(e),[e]),D=s==="count"?ee:vs,T=h.useMemo(()=>g===0?[]:fa.map(v=>({pct:v,label:D(Math.round(g*v)),pos:(1-v)*100})),[g,D]),S=h.useMemo(()=>{if(e.length===0)return[];const v=e.length,w=Math.max(1,Math.floor(v/6)),j=[];for(let i=0;i<v;i+=w)j.push({label:pt(e[i].start),pos:(i+.5)/v*100});return j},[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&&c!==null&&t.jsxs("div",{className:"absolute flex items-center gap-1.5 type-data-sm -translate-x-1/2",style:{left:`calc(${pe}px + ${c*100}% * (1 - ${pe}px / 100%))`},children:[t.jsx(Je,{mode:"wait",children:t.jsx(Re.span,{initial:p?{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(Dt,{className:"w-4 h-4 text-sys-amber"}):t.jsx(Rt,{className:"w-4 h-4 text-sys-blue"})},x?"sun":"moon")}),t.jsx("span",{className:"text-fg-secondary",children:b})]})}),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:pe,bottom:Ie},"aria-hidden":"true",children:T.map(({pct:v,label:w,pos:j})=>t.jsx("span",{className:"type-data-xs text-fg-secondary text-right pr-1.5",style:{position:"absolute",top:`${j}%`,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:pe,right:0,top:0,bottom:Ie},children:l&&t.jsx(ks,{buckets:e,activeTypes:n,gridColor:r.grid,axisTickColor:r.axisTick,onHover:y,yAxisFormat:s,externalAxes:!0})}),t.jsx("div",{className:"absolute left-0 right-0 bottom-0 pointer-events-none",style:{left:pe,height:Ie},"aria-hidden":"true",children:S.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===S.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(Ms,{activeTypes:n,totalByType:o,formatMode:s})})]})}const xt={top:8,right:8,bottom:28,left:48},gt={top:0,right:0,bottom:0,left:0};let Te=null,yt=0;const pa=1e3;function xa(){const e=performance.now();return Te&&e-yt<pa||(Te=getComputedStyle(document.documentElement).getPropertyValue("--font-data").trim()||'"JetBrains Mono", ui-monospace, monospace',yt=e),Te}const Le=.15;function ga(e,n,o,s,r,a,d,c){const f=n.length,m=window.devicePixelRatio||1,u=Math.round(1*m),y=(c-u)/2;if(f===0||s.length===0)return{baselineY:a+y+u/2,fwdHalf:y,drpHalf:y,fwdCeil:1,drpCeil:1,gapPx:u};const l=d/f,x=new Float64Array(f),b=new Float64Array(f);let p=0,g=0;for(let A=0;A<f;A++){let L=0,P=0;const B=n[A].countByType,R=o[A].countByType;for(const M of s)L+=B[M]??0,P+=R[M]??0;x[A]=L,b[A]=P,L>p&&(p=L),P>g&&(g=P)}p===0&&g===0?(p=1,g=1):p===0?p=1:g===0&&(g=1);const D=p*1.05,T=g*1.05,S=D+T;let v=D/S;v=Math.max(Le,Math.min(1-Le,v));const w=c-u,j=v*w,i=(1-v)*w,_=a+j,k=a+j+u,C=a+j+u/2;for(let A=0;A<f;A++){const L=r+A*l;let P=_;const B=n[A].countByType;if(x[A]>0)for(const $ of s){const N=B[$]??0;if(N===0)continue;const F=N/D*j,E=P-F;e.fillStyle=De($),e.fillRect(L,E,l,F),P=E}let R=k;const M=o[A].countByType;if(b[A]>0){const $=M[Q]??0;if($>0){const N=$/T*i;e.fillStyle=De(Q),e.fillRect(L,R,l,N),R+=N}for(const N of s){if(N===Q)continue;const F=M[N]??0;if(F===0)continue;const E=F/T*i;e.fillStyle=De(N),e.fillRect(L,R,l,E),R+=E}}}return{baselineY:C,fwdHalf:j,drpHalf:i,fwdCeil:D,drpCeil:T,gapPx:u}}function ya(e,n,o,s,r,a,d,c,f,m,u=!1){if(n.length===0)return;const{baselineY:y,fwdHalf:l,drpHalf:x,fwdCeil:b,drpCeil:p,gapPx:g}=f,D=xa(),T=y-Math.ceil(g/2),S=y+Math.floor(g/2);e.save(),e.strokeStyle=d,e.lineWidth=1*m,e.setLineDash([]);const v=[.5,1];for(const w of v){const j=Math.round(T-w*l)+.5;e.beginPath(),e.moveTo(o,j),e.lineTo(o+r,j),e.stroke();const i=Math.round(S+w*x)+.5;e.beginPath(),e.moveTo(o,i),e.lineTo(o+r,i),e.stroke()}if(e.restore(),e.clearRect(o,y-Math.ceil(g/2),r,g),!u){e.save(),e.font=`bold ${10*m}px ${D}`,e.textAlign="left";const w=4*m,j=2*m;for(const i of v){const _=Math.round(b*i),k=Math.round(p*i),C=i===1,A=T-i*l,L=S+i*x;_>0&&(e.fillStyle=Y.green,e.globalAlpha=.7,C?(e.textBaseline="top",e.fillText(ee(_),w,A+j)):(e.textBaseline="middle",e.fillText(ee(_),w,A))),k>0&&(e.fillStyle=Y.red,e.globalAlpha=.7,C?(e.textBaseline="bottom",e.fillText(ee(k),w,L-j)):(e.textBaseline="middle",e.fillText(ee(k),w,L)))}e.globalAlpha=1,e.restore()}if(!u){e.save(),e.font=`${12*m}px ${D}`,e.fillStyle=c,e.textBaseline="top",e.textAlign="center";const w=8*m,j=n.length,i=Math.max(1,Math.floor(j/6)),_=r/j;for(let k=0;k<j;k+=i){const C=o+k*_+_/2,L=new Date(n[k].start*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1});e.fillText(L,C,s+a+w)}e.restore()}}function ba({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 d=s===Q?"CRC":Cs[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:De(s)}}),t.jsx("span",{className:"text-fg-secondary whitespace-nowrap",children:d}),t.jsxs("span",{className:"tabular-nums",children:[t.jsxs("span",{className:"text-sys-green",children:["▲",ee(r)]})," ",t.jsxs("span",{className:"text-sys-red",children:["▼",ee(a)]})]})]},s)})})}function ja(e,n,o){const s=e.length;let r=0,a=0;for(let u=0;u<s;u++){let y=0,l=0;for(const x of o)y+=e[u].countByType[x]??0,l+=n[u].countByType[x]??0;y>r&&(r=y),l>a&&(a=l)}r===0&&a===0?(r=1,a=1):r===0?r=1:a===0&&(a=1);const d=r*1.05,c=a*1.05,f=d+c;let m=d/f;return m=Math.max(Le,Math.min(1-Le,m)),{fwdMax:Math.round(d),drpMax:Math.round(c),fwdFrac:m}}function wa({forwardedBuckets:e,droppedBuckets:n,allTypes:o,onHover:s,gridColor:r,axisTickColor:a,externalAxes:d=!1}){const c=h.useRef(null),f=h.useRef(null),m=h.useRef(e),u=h.useRef(n),y=h.useRef(o),l=h.useRef(d);m.current=e,u.current=n,y.current=o,l.current=d;const x=d?gt:xt,b=typeof document<"u"&&document.documentElement.dataset.mode!=="light",p=r||(b?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"),g=a||(b?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.6)"),D=h.useRef({gridColor:p,axisTickColor:g});D.current={gridColor:p,axisTickColor:g};const T=e.length,S=h.useMemo(()=>{const j=e.map(_=>_.start),i=e.map(()=>1);return[j,i]},[T]),v=h.useCallback(j=>{if(!c.current||e.length===0)return;const i=c.current.getBoundingClientRect(),_=j.clientX-i.left,k=d?gt:xt,C=k.left,A=i.width-k.left-k.right,P=(_-C)/A;if(P<0||P>1){s==null||s(null,null,null);return}const B=Math.min(e.length-1,Math.max(0,Math.floor(P*e.length)));s==null||s(B,e[B],P)},[e,s]),w=h.useCallback(()=>{s==null||s(null,null,null)},[s]);return h.useEffect(()=>{if(!c.current||T===0)return;const j=c.current;let i=null;const _=Ts(()=>{const k=j.getBoundingClientRect(),C=Math.floor(k.width)||400,A=Math.floor(k.height)||200,L={width:C,height:A,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:[B=>{const R=B.ctx,{left:M,top:$,width:N,height:F}=B.bbox,E=window.devicePixelRatio||1,W=D.current,H=m.current;H.length>=2&&_s(R,H[0].start,H[H.length-1].end,M,$,N,F);const O=ga(R,m.current,u.current,y.current,M,$,N,F);ya(R,m.current,M,$,N,F,W.gridColor,W.axisTickColor,O,E,l.current)}]}},P=new Ss(L,S,j);f.current=P,i=new ResizeObserver(()=>{const B=j.getBoundingClientRect();B.width>0&&B.height>0&&f.current&&f.current.setSize({width:Math.floor(B.width),height:Math.floor(B.height)})}),i.observe(j)});return()=>{var k;_(),i==null||i.disconnect(),(k=f.current)==null||k.destroy(),f.current=null}},[T]),h.useEffect(()=>{f.current&&f.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:c,className:"w-full h-full",onMouseMove:v,onMouseLeave:w})}const Na=h.memo(wa),as=[{target:"RepeaterAnalyticsCard",fn:"type",minStage:1}];he(as);function va(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 xe=32,ze=20,ka=[.5,1];function Ma({forwardedBuckets:e,droppedBuckets:n,forwardedActiveTypes:o,droppedActiveTypes:s,forwardedCount:r,droppedCount:a,crcCount:d,crcHistory:c,receivedCount:f,forwardedTotalByType:m,droppedTotalByType:u,startTime:y,bucketDurationSeconds:l,bucketCount:x,timeRangeMinutes:b}){fe(as);const p=Bt(),g=Pe(),[D,T]=h.useState(null),[S,v]=h.useState(null),[w,j]=h.useState(null),i=h.useCallback((G,I,X)=>{T(I),v(X)},[]),_=Math.max(1,b/60),k=h.useMemo(()=>At(g,_),[g,_]),C=h.useMemo(()=>k?Lt(k):0,[k]),A=Math.round(C*10)/10,L=Math.round((k==null?void 0:k.avgBackoffMs)??0),{fwdMirror:P,drpMirror:B,allTypes:R,fwdTotals:M,drpTotals:$}=h.useMemo(()=>{const G=e.map(U=>({start:U.start,end:U.end,countByType:{...U.countByType}})),I=new Array(x).fill(0);for(const U of c){let K=Math.floor((U.timestamp-y)/l);K<0&&(K=0),!(K>=x)&&I[K]++}const X=n.map((U,K)=>({start:U.start,end:U.end,countByType:{...U.countByType,...I[K]>0?{[Q]:I[K]}:{}}})),V=new Set([...o,...s]);d>0&&V.add(Q);const te={...m},ae={...u};d>0&&(ae[Q]=d);const Ne=[...V].sort((U,K)=>{const hs=(te[U]??0)+(ae[U]??0);return(te[K]??0)+(ae[K]??0)-hs});return{fwdMirror:G,drpMirror:X,allTypes:Ne,fwdTotals:te,drpTotals:ae}},[e,n,o,s,c,d,y,l,x,m,u]),N=R.length>0&&P.length>0,F=D?va(D.start):null,E=D?bt(D.start):"",W=w!==null&&F!==null&&w!==F;F!==w&&j(F);const H=h.useMemo(()=>N?ja(P,B,R):null,[N,P,B,R]),O=h.useMemo(()=>{if(!H)return[];const{fwdMax:G,drpMax:I,fwdFrac:X}=H,V=[];for(const te of ka){const ae=Math.round(G*te);if(ae>0){const U=(1-te)*X*100;V.push({label:ee(ae),pos:U,color:"green"})}const Ne=Math.round(I*te);if(Ne>0){const U=(X+te*(1-X))*100;V.push({label:ee(Ne),pos:U,color:"red"})}}return V},[H]),z=h.useMemo(()=>{if(P.length===0)return[];const G=P.length,I=Math.max(1,Math.floor(G/6)),X=[];for(let V=0;V<G;V+=I)X.push({label:bt(P[V].start),pos:(V+.5)/G*100});return X},[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:N?t.jsx(re,{value:r,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(se,{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(ut,{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:N?t.jsx(re,{value:a+d,className:"font-mono tabular-nums",priority:"high"}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(se,{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(dt,{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:N?t.jsxs("span",{className:"font-mono tabular-nums",children:[A,"%"]}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(se,{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(zn,{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:N?t.jsxs("span",{className:"font-mono tabular-nums",children:[L,"ms"]}):t.jsx("span",{className:"opacity-30",children:"—"})}),t.jsxs(se,{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(es,{className:"w-3 h-3 text-sys-blue"}),"LBT Mean"]})]})]}),t.jsx("div",{className:"h-5 relative mb-1 mt-2 shrink-0",children:D&&S!==null&&t.jsxs("div",{className:"absolute flex items-center gap-1.5 type-data-sm -translate-x-1/2",style:{left:`calc(${xe}px + ${S*100}% * (1 - ${xe}px / 100%))`},children:[t.jsx(Je,{mode:"wait",children:t.jsx(Re.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:F?t.jsx(Dt,{className:"w-4 h-4 text-sys-amber"}):t.jsx(Rt,{className:"w-4 h-4 text-sys-blue"})},F?"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:ze},"aria-hidden":"true",children:O.map(({label:G,pos:I,color:X},V)=>t.jsx("span",{className:`type-data-xs text-right pr-1.5 ${X==="green"?"text-sys-green/70":"text-sys-red/70"}`,style:{position:"absolute",top:`${I}%`,transform:I<=1?"none":I>=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:ze},children:[N&&H&&t.jsx("div",{className:"absolute inset-x-0 top-0 pointer-events-none",style:{height:`${H.fwdFrac*100}%`,background:"var(--sys-blue)",opacity:.1}}),N&&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(ut,{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(dt,{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 ${N?"opacity-0 pointer-events-none":"opacity-100"}`,"aria-hidden":N,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,I)=>t.jsx("div",{className:"flex-1 bg-subtle-fill rounded-sm animate-pulse",style:{height:`${G}%`}},`u${I}`))})})}),t.jsx("div",{className:`h-full transition-opacity duration-300 ${N?"opacity-100":"opacity-0"}`,children:N&&t.jsx(Na,{forwardedBuckets:P,droppedBuckets:B,allTypes:R,gridColor:p.grid,axisTickColor:p.axisTick,onHover:i,externalAxes:!0})}),N&&H&&t.jsx("div",{className:"absolute inset-x-0 bottom-0 pointer-events-none",style:{top:`${H.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:ze},"aria-hidden":"true",children:z.map((G,I)=>t.jsx("span",{className:"type-data-xs text-fg-secondary absolute top-1",style:{left:`${G.pos}%`,transform:I===0?"none":I===z.length-1?"translateX(-100%)":"translateX(-50%)"},children:G.label},I))})]}),t.jsx("div",{className:"pt-2 px-1 pb-2 shrink-0",children:N&&t.jsx(ba,{allTypes:R,forwardedTotalByType:M,droppedTotalByType:$})})]})}const Ca=2,Ta=1;function Sa(e,n,o){const s=f=>(f==null?void 0:f.reduce((m,u)=>m+u.count,0))??0,r=s(n),a=s(o),d=r||(e==null?void 0:e.rx_count)||1,c=a||(e==null?void 0:e.dropped_count)||0;return d>0?c/(d+c)*100:0}function _a(e,n,o){const s=r=>(r==null?void 0:r.reduce((a,d)=>a+d.count,0))??0;if(n!=null&&n.length&&o){const a=s(n)*100,d=n.length*o*1e3;return a/d*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 jt(e,n,o){return xn(Math.max(n,Math.min(o,e)))}function Ba(e,n,o,s,r){let a=Vt(e);n>20?a+=ke*2:n>12&&(a+=ke),o>8&&(a+=ke);const d=jt(a,0,Ca);let c=gn(e);o>8&&(c+=ke);const f=jt(c,0,Ta),m=ge(d),u=ge(f),y=s!==null?ge(s):null;let l="stable";return y!==null&&(m>y?l="increase":m<y&&(l="decrease")),{floodFactor:d,directFactor:f,floodSlots:m,directSlots:u,adjustment:l,duplicateRate:Math.round(n*100)/100,txUtilization:Math.round(o*1e3)/1e3,zeroHopCount:e}}function Da({stats:e,receivedBuckets:n,droppedBuckets:o,forwardedBuckets:s,bucketDurationSeconds:r,timeRangeLabel:a,isLoaded:d=!0}){var E,W,H,O;const[c,f]=h.useState(!1),[m,u]=h.useState("idle"),y=Bs(),l=h.useCallback(async(z,G)=>{if(m!=="applying"){u("applying");try{const I=await Ds({tx_delay_factor:z,direct_tx_delay_factor:G});I!=null&&I.success?(u("success"),setTimeout(()=>u("idle"),2e3)):(u("error"),setTimeout(()=>u("idle"),2500))}catch{u("error"),setTimeout(()=>u("idle"),2500)}}},[m]);if(!d)return t.jsx(be,{children:t.jsx(Rs,{})});const x=10080*60,p=Math.floor(Date.now()/1e3)-x,g=Object.values((e==null?void 0:e.neighbors)??{}).filter(z=>z.zero_hop&&z.last_seen>=p&&pn(z).isRepeater).length,D=y.filter(z=>z.status==="active"||z.lastSeen>=p).length,T=Math.max(g,D),S=Sa(e,n,o),v=_a(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,j=((O=(H=e==null?void 0:e.config)==null?void 0:H.delays)==null?void 0:O.direct_tx_delay_factor)??null,i=Ba(T,S,v,w),_=T!==1,k=Vt(T),C=[`${T} repeater${_?"s":""} heard in the last 7 days (base ×${k.toFixed(1)}).`];i.floodFactor===k&&S<=12&&v<=8?C.push("No modifiers applied — network looks healthy."):(S>20?C.push(`High duplicate rate (${S.toFixed(1)}%) suggests frequent collisions — window widened.`):S>12&&C.push(`Elevated duplicate rate (${S.toFixed(1)}%) — window widened one step.`),v>8&&C.push(`Channel is busy (${v.toFixed(1)}% TX util) — extra spacing added.`));const A=[`Direct uses one forwarder — ×${i.directFactor.toFixed(1)} backoff for channel contention.`];v>8&&A.push("Busy channel — small extra backoff.");const L=[`Flood ×${i.floodFactor.toFixed(1)} (${i.floodSlots} slot${i.floodSlots!==1?"s":""})`,...C,"",`Direct ×${i.directFactor.toFixed(1)}`,...A,"","Click to copy CLI commands"].join(`
`),P=w!==null?ge(w):null,B=j!==null?ge(j):null,R=P!==null&&i.floodSlots!==P,M=B!==null&&i.directSlots!==B,$=R||M,N=async()=>{const z=`set txdelay ${i.floodFactor.toFixed(1)}
set direct.txdelay ${i.directFactor.toFixed(1)}`;await Ps(z),f(!0),setTimeout(()=>f(!1),1500)},F=()=>l(i.floodFactor,i.directFactor);return t.jsxs(be,{children:[t.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3 flex-wrap",children:[t.jsx(yn,{className:"w-4 h-4 text-icon-card-title flex-shrink-0"}),t.jsx("span",{className:"type-micro",children:"DELAY DOCTOR"}),a&&t.jsx(se,{color:"zinc",className:"hidden sm:inline-flex",children:a})]}),t.jsxs("button",{onClick:N,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:L,children:[t.jsxs("div",{className:"flex-1 flex flex-col",children:[t.jsx("span",{className:"type-data-xl text-fg-primary",children:t.jsxs(Xe,{children:["×",i.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(Xe,{children:["×",i.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:c?t.jsx(st,{className:"w-4 h-4 text-sys-green"}):t.jsx(As,{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 ${i.duplicateRate>8?"text-status-warning":""}`,children:[i.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:[i.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:["×",(j==null?void 0:j.toFixed(2))??"—"]})})]}):t.jsx("span",{className:"text-sm text-fg-muted",children:"No config"})})]}),$&&t.jsxs("button",{onClick:F,disabled:m==="applying"||m==="success",className:`flex items-center gap-1.5 px-2.5 py-1.5 radius-inner type-micro font-medium transition-base
                ${m==="success"?"bg-sys-green/15 text-sys-green":m==="error"?"bg-sys-red/15 text-sys-red":m==="applying"?"bg-subtle-fill text-fg-muted":"bg-sys-blue/10 text-sys-blue hover:bg-sys-blue/20"}`,title:`Apply ×${i.floodFactor.toFixed(1)} flood, ×${i.directFactor.toFixed(1)} direct`,children:[m==="success"?"Rx'd":m==="error"?"Failed":"Apply",m==="applying"?t.jsx(Ls,{className:"w-3.5 h-3.5 animate-spin"}):m==="success"?t.jsx(st,{className:"w-3.5 h-3.5"}):t.jsxs("span",{className:"relative inline-flex items-end w-6 h-3.5",children:[t.jsx(Vn,{className:"w-3.5 h-3.5 absolute left-0 bottom-0"}),t.jsx(Qn,{className:"w-3 h-3 absolute right-0 bottom-0"})]})]})]})})]})}const os=[{target:"RecentPackets",fn:"rssi",minStage:1},{target:"RecentPackets",fn:"snr",minStage:1}];he(os);const Ra=25;function Aa(){fe(os);const e=Pe(),n=$s(),o=Fs(),s=ie(),r=wn(),a=Ve(x=>x.requestChannel),[d,c]=h.useState(!0),f=h.useCallback(x=>c(x),[]),m=h.useMemo(()=>[...e.length<=100?e:e.slice(-100)].sort((b,p)=>(p.timestamp??0)-(b.timestamp??0)),[e]),u=s==null?void 0:s.local_hash,y=s==null?void 0:s.neighbors,l=Nn();return t.jsxs(be,{noPadding:!0,className:"!overflow-visible",children:[t.jsx(Pt,{listHeader:!0,icon:t.jsx(Ft,{}),title:"Recent Packets",actions:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx($t,{enabled:d,onChange:f,label:"Hide Dupes",size:"sm"}),o&&t.jsx(Es,{showLabel:!0}),t.jsxs(Ae,{color:"primary",outline:!0,href:"/packets",children:["View all",t.jsx(it,{"data-slot":"icon"})]})]})}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-1",children:t.jsx(bn,{packets:m,allPackets:e,localHash:u,neighbors:y,resolveSource:l,getDecodedContent:r,onChannelClick:a,loading:n,maxPackets:Ra,showPagination:!1,flashNewest:!0,hideDupes:d,emptyMessage:"No packets received",footerAction:t.jsxs(Ae,{color:"primary",outline:!0,href:"/packets",children:["View all",t.jsx(it,{"data-slot":"icon"})]})})})]})}const La={stable:"M5 12h14",up:"M5 15l7-7 7 7",down:"M19 9l-7 7-7-7"};function Pa({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:La[e]})})})}function $a(){return t.jsx("div",{className:"mini-widget-loading",children:t.jsx("div",{className:"mini-widget-loading-spinner"})})}function Fa({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:d,subtitleValue:c,trend:f,headerRight:m,children:u,isLoading:y=!1,error:l,className:x="",onClick:b,isLoaded:p}){const g=["mini-widget-value",r==="lg"&&"mini-widget-value-lg",r==="sm"&&"mini-widget-value-sm"].filter(Boolean).join(" "),D=["mini-widget",x].filter(Boolean).join(" ");return t.jsxs(be,{noPadding:!0,className:D,onClick:b,isLoaded:p,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}`}),f&&t.jsx(Pa,{trend:f}),m&&t.jsx("span",{className:"ml-auto flex items-center",children:m})]}),y?t.jsx($a,{}):l?t.jsx(Fa,{message:l}):t.jsxs("div",{className:"mini-widget-content",children:[(o!==void 0||d||c)&&t.jsxs("div",{className:"mini-widget-value-row",children:[o!==void 0&&t.jsxs("div",{className:g,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(Xe,{children:o}),s&&t.jsx("span",{className:"mini-widget-unit",children:s})]}),(d||c)&&t.jsxs("span",{className:"mini-widget-badge-group",children:[d&&!c&&t.jsx("span",{className:"data-box mini-widget-subtitle-box",children:d}),d&&c&&t.jsx("span",{className:"mini-widget-subtitle truncate",children:d}),c&&t.jsx("span",{className:"data-box mini-widget-subtitle-box",children:c})]})]}),u]})]})}const Ea={DELTA_CRITICAL:10,SLOPE_CRITICAL:4,JITTER_CRITICAL:6,DELTA_WARNING:5,SLOPE_WARNING:2,JITTER_WARNING:4},rs={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 Ye(e,n){if(e.length===0)return null;const o=[...e].sort((d,c)=>d-c),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 wt(e){return Ye(e,50)}function Ha(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 Ia(e){if(e.length<2)return 0;const n=e.length;let o=0,s=0,r=0,a=0;const d=e[0].timestamp;for(const f of e){const m=(f.timestamp-d)/3600,u=f.value;o+=m,s+=u,r+=m*u,a+=m*m}const c=n*a-o*o;return Math.abs(c)<1e-4?0:(n*r-o*s)/c}function za(e,n,o){const s=Ea;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 Oa(e){if(e.length===0)return{...rs,computedAt:Math.floor(Date.now()/1e3)};const n=Math.floor(Date.now()/1e3),o=e.filter(g=>Number.isFinite(g)),s=e.length>0?[e[e.length-1]]:[],r=e.slice(-4).filter(g=>Number.isFinite(g)),a=wt(o),d=Ye(o,10),c=Ye(o,90),f=wt(s),m=f!==null&&d!==null?f-d:0,u=r.map((g,D)=>({timestamp:n-(r.length-1-D)*3600,value:g})),y=Ia(u),l=Ha(r),x=o.length>=12,[b,p]=x?za(m,y,l):[0,null];return{baselineMedian:a,baselineP10:d,baselineP90:c,currentMedian:f,currentSampleCount:s.length,delta:m,slope:y,jitter:l,penalty:b,penaltyReason:p,computedAt:n,isReliable:x}}const Ga={lbtStats:null,noiseFloor:null,sparklineNoiseFloor:[],noiseFloorWindowHistory:[],linkQuality:null,channelHealth:null,nfTrend:rs,radioConfig:null,trends:null,stats:null,recentPackets:[],quickNeighbors:[],isLoading:!0,error:null,refresh:async()=>{}},is=h.createContext(Ga);function Wa({children:e}){var B;const n=ie(),o=Pe(),s=Et(),r=Hs(),a=je(),d=ne[a],c=Math.max(1,d.minutes/60),f=n===null,[m,u]=h.useState(null),y=h.useCallback(async()=>{try{const R=await Ht(Math.ceil(c));if(R.success&&R.data){u(R.data.history);return}const M=await It(Math.ceil(c));M.success&&M.data&&M.data.count>0&&u(null)}catch{}},[c]);h.useEffect(()=>{y();const R=setInterval(y,6e4);return()=>clearInterval(R)},[y]);const l=h.useMemo(()=>At(o,c,m),[o,c,m]),x=(n==null?void 0:n.noise_floor_dbm)??null,b=h.useMemo(()=>Is(x)?x:null,[x]),p=h.useMemo(()=>{var M;const R=(M=n==null?void 0:n.config)==null?void 0:M.radio;return R?{sf:R.spreading_factor??7,bwHz:R.bandwidth??125e3}:null},[(B=n==null?void 0:n.config)==null?void 0:B.radio]),g=zs(c),D=Os(c),T=n==null?void 0:n.neighbors,S=h.useMemo(()=>Object.fromEntries(Object.entries(T??{}).filter(([M])=>!r.has(M))),[T,r]),v=h.useMemo(()=>s.filter(R=>!r.has(R.hash)),[s,r]),w=h.useMemo(()=>Oa(g),[g]),j=h.useMemo(()=>Gs(v,S,p),[v,S,p]),i=h.useMemo(()=>Ws(l,b,j),[l,b,j]),[_,k]=h.useState({noiseFloor:null,networkScore:null,channelHealth:null}),C=h.useRef(0);h.useEffect(()=>{const R=()=>{const $=Date.now();$-C.current>3e4&&(C.current=$,k({noiseFloor:b,networkScore:(j==null?void 0:j.networkScore)??null,channelHealth:(i==null?void 0:i.score)??null}))};R();const M=setInterval(R,5e3);return()=>clearInterval(M)},[b,j==null?void 0:j.networkScore,i==null?void 0:i.score]);const A=h.useMemo(()=>({noiseFloor:{current:b,previous:_.noiseFloor,trend:b!==null?Fe(b,_.noiseFloor,2,!0):"stable"},networkScore:{current:(j==null?void 0:j.networkScore)??0,previous:_.networkScore,trend:Fe((j==null?void 0:j.networkScore)??0,_.networkScore,3,!1)},channelHealth:{current:(i==null?void 0:i.score)??0,previous:_.channelHealth,trend:Fe((i==null?void 0:i.score)??0,_.channelHealth,3,!1)}}),[b,j==null?void 0:j.networkScore,i==null?void 0:i.score,_]),P={lbtStats:l,noiseFloor:b,sparklineNoiseFloor:g,noiseFloorWindowHistory:D,linkQuality:j,channelHealth:i,nfTrend:w,radioConfig:p,trends:A,stats:n,recentPackets:o,quickNeighbors:s,isLoading:f,error:null,refresh:async()=>{}};return t.jsx(is.Provider,{value:P,children:e})}function Ke(){const e=h.useContext(is);if(e===void 0)throw new Error("useLBTData must be used within an LBTDataProvider");return e}function qa(e){return e<100?"excellent":e<250?"good":e<500?"fair":e<1e3?"congested":"critical"}function Ua(e){return e===0?"No backoffs":"Retries"}function Xa(e,n){return e===0?void 0:`${n.toFixed(0)}%`}function Va(){const{lbtStats:e,isLoading:n,error:o}=Ke(),s=zt(),r=(e==null?void 0:e.avgBackoffMs)??0,a=(e==null?void 0:e.retryRate)??0,d=e?qa(r):"unknown",c=e==null?void 0:e.sparklineBackoff,f=h.useMemo(()=>!c||c.length<2?[]:c.map((m,u)=>({timestamp:Date.now()-(c.length-1-u)*36e5,count:m})),[c]);return t.jsx(le,{title:"LBT Backoff",icon:t.jsx(kn,{className:"mini-widget-icon"}),value:Math.round(r),unit:"ms",status:d,subtitle:e?Ua(r):void 0,subtitleValue:e?Xa(r,a):void 0,isLoading:n,error:o,onClick:()=>s("/packets"),children:t.jsx("div",{className:"mini-widget-sparkline w-full",children:t.jsx(Zt,{data:f,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}const ls=[{target:"LinkLeaders",fn:"path",minStage:1,when:mn},{target:"LinkLeaders",fn:"src_hash",minStage:1,when:fn}];he(ls);function Ya(){fe(ls);const e=zt(),n=Et(),o=Pe(),s=ie(),r=je(),d=ne[r].minutes*60,c=qs(),f=h.useMemo(()=>{if(c===0)return o;const i=c-d;return o.filter(_=>_.timestamp>=i)},[o,d,c]),m=s===null,u=s!=null&&s.local_hash?nt(s.local_hash):"",y=(s==null?void 0:s.neighbors)??{},{neighborHashes:l,neighborNames:x}=h.useMemo(()=>{const i=new Set,_=new Map;for(const k of n){i.add(k.hash);const C=y[k.hash],A=(C==null?void 0:C.name)||(C==null?void 0:C.node_name)||k.prefix;_.set(k.hash,A)}return{neighborHashes:i,neighborNames:_}},[n,y]),b=h.useMemo(()=>{if(l.size===0||f.length===0||!u)return{champion:null,listener:null,loudest:null};const{scores:i}=vn(f,l,u),_=[];for(const[L,P]of i)P.blendedScore!==0&&_.push({...P,name:x.get(L)??nt(L)});let k=null,C=null,A=null;for(const L of _)(!k||L.blendedScore>k.blendedScore)&&(k=L),(!C||L.listenerScore>C.listenerScore)&&(C=L),(!A||L.loudScore>A.loudScore)&&(A=L);return{champion:k,listener:C,loudest:A}},[f,l,u,x]),p=i=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["🏆 Champion: ",i.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Blended Score: ",i.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: ",i.listenerScore,"/100 (",i.listenerCount," shared paths)"]}),t.jsxs("div",{children:["Loud: ",i.loudScore,"/100 (",i.loudCount," packets relayed)"]})]})]}),g=i=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["👂 Best Listener: ",i.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",i.listenerScore,"/100"]}),t.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:t.jsxs("div",{children:[i.listenerCount," packets where they heard your transmissions"]})})]}),D=i=>t.jsxs("div",{className:"max-w-[220px]",children:[t.jsxs("div",{className:"font-semibold mb-1",children:["📢 Loudest: ",i.name]}),t.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",i.loudScore,"/100"]}),t.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:t.jsxs("div",{children:[i.loudCount," packets they relayed directly to you"]})})]}),{champion:T,listener:S,loudest:v}=b,j=T||S||v?t.jsxs("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:[T&&t.jsx(me,{content:p(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(jn,{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})]})}),S&&t.jsx(me,{content:g(S),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(es,{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:S.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:S.listenerScore})]})}),v&&t.jsx(me,{content:D(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(Un,{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(Jn,{className:"mini-widget-icon"}),isLoading:m,onClick:()=>e("/contacts"),children:j})}function Ja(e){return e<15?"excellent":e<30?"good":e<45?"fair":e<60?"congested":"critical"}function Za(e){return e<15?"Clear channel":e<30?"Light traffic":e<45?"Moderate traffic":e<60?"Heavy traffic":e<75?"Congested":"Severe congestion"}function Ka(){const{lbtStats:e,isLoading:n,error:o}=Ke(),s=e?Lt(e):0,r=e?Ja(s):"unknown",a=(e==null?void 0:e.maxBackoffMs)??0,d=e?a>200?"Peak":Za(s):void 0,c=e&&a>200?`${Math.round(a)}ms`:void 0,f=e==null?void 0:e.sparklineCollisionRisk,m=h.useMemo(()=>!f||f.length<2?[]:f.map((y,l)=>({timestamp:Date.now()-(f.length-1-l)*36e5,count:y})),[f]),u=Math.round(s*10)/10;return t.jsx(le,{title:"Collision Risk",icon:t.jsx(Mn,{className:"mini-widget-icon"}),value:u,unit:"%",status:r,subtitle:d,subtitleValue:c,isLoading:n,error:o,children:t.jsx("div",{className:"mini-widget-sparkline w-full",children:t.jsx(Zt,{data:m,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}function Qa(e){return e<30?"excellent":e<50?"good":e<70?"fair":e<90?"congested":"critical"}function eo(e){return e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${(e/6e4).toFixed(1)}m`}function to(){var p,g;const[e,n]=h.useState(!1),[o]=h.useState(0),{stats:s,lbtStats:r,isLoading:a}=Ke(),d=((g=(p=s==null?void 0:s.config)==null?void 0:p.duty_cycle)==null?void 0:g.enforcement_enabled)??!1,c=h.useMemo(()=>{if(!s)return null;if(!d){const w=s.airtime_used_ms??0,j=s.max_airtime_ms??1,i=j>0?w/j*100:0;return{usedMs:w,maxMs:j,remainingMs:Math.max(0,j-w),utilizationPercent:i}}const D=s.airtime_used_ms??0,T=s.max_airtime_ms??1,S=s.airtime_remaining_ms??0,v=s.utilization_percent??(T>0?D/T*100:0);return{usedMs:D,maxMs:T,remainingMs:S,utilizationPercent:v}},[s,d]),f=h.useMemo(()=>{if(!r||r.totalPacketsWithLBT===0)return 100;const D=r.totalPacketsWithLBT-r.packetsWithRetries,T=r.totalPacketsWithLBT;return D/T*100},[r]),m=(c==null?void 0:c.utilizationPercent)??0,u=Qa(m),y=(c==null?void 0:c.remainingMs)??0,l=f<95?"1st Try":"Remaining",x=f<95?`${f.toFixed(0)}%`:eo(y),b=c?t.jsx("div",{className:"mini-widget-progress mt-auto",children:t.jsx("div",{className:`mini-widget-progress-bar ${u}`,style:{width:`${Math.min(m,100)}%`}})}):null;return t.jsx(le,{title:"Duty Cycle",icon:t.jsx(Ft,{className:"mini-widget-icon"}),value:m.toFixed(1),unit:"%",status:u,subtitle:l,subtitleValue:x,isLoading:a,children:b})}function so(){return t.jsxs("div",{className:"mini-widget",children:[t.jsxs("div",{className:"mini-widget-header",children:[t.jsx(ve,{className:"w-4 h-4"}),t.jsx(ve,{className:"h-3 w-16"})]}),t.jsx(ve,{className:"h-7 w-12 mt-2"}),t.jsx(ve,{className:"h-3 w-20 mt-2"})]})}function no(){return t.jsx("div",{className:"widget-row",children:Array.from({length:5}).map((e,n)=>t.jsx(so,{},n))})}const cs=[{target:"MeshHealth",fn:"type",minStage:1}];he(cs);function ao({className:e="",isLoaded:n,leading:o}){fe(cs);const s=Ot(),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(Us,{className:"w-4 h-4 text-sys-blue"}),t.jsx("span",{className:"type-label text-fg-muted",children:"MESH HEALTH"})]}),r?t.jsx(Wa,{children:t.jsxs("div",{className:"widget-row",children:[o&&t.jsx("div",{className:"widget-leading",children:o}),t.jsx(Va,{}),t.jsx(Ka,{}),t.jsx(to,{}),t.jsx(Ya,{})]})}):t.jsx(no,{})]})}const ds=[{target:"PublicChannel",fn:"decrypt",minStage:2,when:hn}];he(ds);let us="",ms="",Nt="";function oo(){const e=new Date,n=e.toDateString();if(n!==Nt){Nt=n,us=n;const o=new Date(e);o.setDate(o.getDate()-1),ms=o.toDateString()}}function ro(e){oo();const n=new Date(e*1e3).toDateString();return n===us?"Today":n===ms?"Yesterday":new Date(e*1e3).toLocaleDateString([],{weekday:"short",month:"short",day:"numeric"})}function io(e,n,o){return`${e||""}|${n}|${o}`}function lo(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 co=h.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(Dn,{senderName:n.senderName||"Unknown",text:n.text,timestamp:n.timestamp,bubbleVariant:"subtle",nameAccessory:t.jsx(Yt,{channelName:r,active:s,onClick:()=>o==null?void 0:o(n.channelHash)})})})},lo);function uo({open:e,onClose:n,messages:o,initialChannel:s}){const r=h.useRef(null),a=h.useRef(!0),d=je(),c=Gt(),f=h.useMemo(()=>{const i=Date.now()/1e3,_=ne[d].minutes,k=i-_*60;return[...o].filter(C=>C.timestamp>=k).sort((C,A)=>C.timestamp-A.timestamp)},[o,d]),m=h.useCallback(()=>{const i=r.current;i&&(a.current=i.scrollTop>=-50)},[]),u=h.useMemo(()=>{const i=new Map;for(const _ of f){const k=_.channelHash,C=i.get(k);C?C.count++:i.set(k,{name:_.channelName||_.channelHash.slice(0,6),hash:_.channelHash,count:1})}return Array.from(i.values()).sort((_,k)=>k.count-_.count)},[f]),y=u.length,[l,x]=h.useState(null),[b,p]=h.useState(!1);h.useEffect(()=>{e&&s&&x(s)},[e,s]);const g=h.useMemo(()=>l?f.filter(i=>i.channelHash===l):f,[f,l]),D=h.useMemo(()=>{const i=[];let _="";for(const k of g){const C=ro(k.timestamp);C!==_&&(i.push({type:"date",date:C}),_=C),i.push({type:"message",message:k})}return i},[g]);h.useLayoutEffect(()=>{const i=r.current;i&&a.current&&(i.scrollTop=0)},[g.length]);const T=h.useCallback(()=>{if(g.length===0)return;const i=[...g].sort((B,R)=>B.timestamp-R.timestamp),_=u.find(B=>B.hash===l),k=(_==null?void 0:_.name)??"All_Channels";let C=`Chat Export - ${k}
`;C+=`Generated: ${new Date().toLocaleString()}

`,i.forEach(B=>{const R=new Date(B.timestamp).toLocaleString(),M=B.senderName||"Unknown",$=B.channelName?`[${B.channelName}] `:"";C+=`[${R}] ${$}${M}: ${B.text}
`});const A=new Blob([C],{type:"text/plain"}),L=URL.createObjectURL(A),P=document.createElement("a");P.href=L,P.download=`chat_export_${k.replace(/\s+/g,"_")}_${Date.now()}.txt`,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(L)},[g,l,u]),S=19,v=u.slice(0,S),w=u.slice(S),j=w.length>0;return t.jsx(Wt,{open:e,onClose:n,size:"lg",motionPlus:!0,solid:!0,children:t.jsxs(qt,{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(Kt,{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("button",{onClick:T,disabled:g.length===0,className:J("hidden sm:flex items-center justify-center p-2 transition-base radius-inner",g.length===0?"text-fg-muted/50 cursor-not-allowed":"text-fg-muted hover:text-fg-primary hover:bg-subtle"),"aria-label":"Export Chat History",title:"Export Chat History",children:t.jsx(Ys,{className:"w-5 h-5"})}),t.jsx(Jt,{ranges:ne,selectedIndex:d,onSelect:c,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:y>0?void 0:0},children:y>0&&t.jsxs("div",{className:"flex flex-wrap gap-1",children:[t.jsxs("button",{onClick:()=>x(null),className:J("px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",l===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 ",y]}),v.map(i=>t.jsx("button",{onClick:()=>x(i.hash),className:J("flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",l===i.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:i.name})},i.hash)),j&&t.jsxs("div",{className:"relative",children:[t.jsxs("button",{onClick:()=>p(!b),className:J("flex items-center gap-0.5 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",b||w.some(i=>i.hash===l)?"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:["+",w.length,t.jsx(Js,{className:J("size-3 transition-transform",b&&"rotate-180")})]}),b&&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:w.map(i=>t.jsxs("button",{onClick:()=>{x(i.hash),p(!1)},className:J("w-full flex items-center gap-1.5 px-2 py-1 rounded text-xs font-medium transition-all text-left",l===i.hash?"bg-sys-blue/20 text-sys-blue":"text-fg-secondary hover:bg-subtle-fill-strong"),children:[t.jsx(Rn,{className:"size-2.5 opacity-60 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:i.name}),t.jsxs("span",{className:"opacity-60 ml-auto",children:["(",i.count,")"]})]},i.hash))})]})]})}),t.jsx("div",{ref:r,onScroll:m,className:J("flex-1 overflow-y-auto overflow-x-hidden","mx-3 mb-3 radius-inner depth-stroke-inset","flex flex-col-reverse"),children:g.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(An,{className:"size-16 mb-4 opacity-20"}),t.jsx("p",{className:"text-lg font-medium",children:"No public chat in this range yet"}),t.jsx("p",{className:"text-sm mt-1 opacity-70 text-center max-w-sm",children:l?"No messages in this channel for the selected range.":"Public channel messages will appear here when decoded for this range."})]}):t.jsx("div",{className:"px-4 py-4",children:D.map((i,_)=>{if(i.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:i.date})},`date-${i.date}-${_}`);const k=`msg-${i.message.timestamp}-${i.message.senderName||"anon"}-${i.message.channelHash}`;return t.jsx("div",{children:t.jsx(co,{message:i.message,onChannelClick:x,isChannelSelected:l===i.message.channelHash})},k)})})}),t.jsx("div",{className:"flex-shrink-0 px-5 py-2 text-center",children:t.jsxs("p",{className:"text-[11px] text-fg-muted",children:[g.length," messages · ",y," ",y===1?"channel":"channels"]})})]})})}function mo(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=io(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 fo({isLoaded:e}){const n=Ot(),o=e??n??!0;fe(ds);const[s,r]=h.useState(!1),[a,d]=h.useState(null),c=je(),f=h.useCallback(()=>{d(null),r(!0)},[]),m=Ve(g=>g.requestedHash),u=Ve(g=>g.clearRequest);h.useEffect(()=>{m&&(d(m),r(!0),u())},[m,u]);const y=Xs(),l=h.useMemo(()=>mo(y),[y]),x=h.useMemo(()=>{const g=Date.now()/1e3,D=ne[c].minutes,T=g-D*60;return l.filter(S=>S.timestamp>=T)},[l,c]),b=h.useMemo(()=>x.length===0?null:x.reduce((g,D)=>D.timestamp>g.timestamp?D:g),[x]),p=x.length;return o?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:f,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(Kt,{className:"size-4 text-icon-card-title flex-shrink-0"}),t.jsx("span",{className:"type-micro",children:"CHAT ACTIVITY"}),p>0&&t.jsxs("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:[p," messages"]}),t.jsx(lt,{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(Je,{mode:"wait",initial:!1,children:b?t.jsxs(Re.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:[b.channelName&&t.jsx("span",{className:"hidden sm:inline-flex",children:t.jsx(Yt,{channelName:b.channelName})}),t.jsx("div",{className:"hidden sm:flex w-[30px] h-[30px] clay-avatar",style:{"--avatar-color":Sn(Ee(b.senderName||"").cleanName)},children:Ee(b.senderName||"").emoji?t.jsx("span",{className:"text-base",children:Ee(b.senderName||"").emoji}):t.jsx("span",{className:"text-white text-xs font-bold tracking-tighter",children:_n(b.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:Bn(b.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:Vs(b.timestamp)})]},`msg-${b.timestamp}-${b.senderName}-${b.channelHash}`):t.jsx(Re.span,{initial:{opacity:0},animate:{opacity:1},className:"text-sm text-fg-muted italic",children:"No public chat in this range yet"},"empty")}),t.jsx(lt,{className:"size-4 text-fg-muted group-hover:text-sys-indigo transition-colors flex-shrink-0 hidden sm:block ml-1"})]})]})}),t.jsx(uo,{open:s,onClose:()=>r(!1),messages:l,initialChannel:a})]}):t.jsx("div",{className:"h-14 rounded-xl bg-elevated/50 animate-pulse"})}const q=2,ho=2,Se=5,_e=4,ye=20,Oe=Ze(Y.cyan),Ge=Ze(Y.amber),We=Ze(Y.red);function Qe(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 j=o[w].allowedDelta+o[w].droppedDelta;j>r&&(r=j);const i=o[w].newlyGuarded.length;i>a&&(a=i)}if(r===0&&a===0)return null;const d=Math.max(1,Se-a),c=r>0?Math.max(1,Math.ceil(r/d)):1,f=e-_e*2,m=n-_e*2,u=(f-q*(ye-1))/ye,y=(m-q*(Se-1))/Se,l=Math.max(3,Math.min(u,y)),x=l+q,b=s,p=0,g=ye*x-q,D=_e+(f-g)/2,T=Se*x-q,S=_e+(m-T),v=Math.min(ho,l/3);return{quantum:c,tileSize:l,colStep:x,visibleCols:b,startIdx:p,offsetX:D,offsetY:S,gridH:T,r:v}}function po(e,n,o,s,r){e.clearRect(0,0,o*(window.devicePixelRatio||1),s*(window.devicePixelRatio||1));const a=Qe(o,s,n);if(a)for(let d=0;d<a.visibleCols;d++){const c=n[a.startIdx+d],f=Math.ceil(c.allowedDelta/a.quantum),m=Math.ceil(c.droppedDelta/a.quantum),u=c.newlyGuarded.length,y=f+m+u;if(y===0)continue;const l=a.offsetX+d*a.colStep,x=(r==null?void 0:r.col)===d,b=x?r.segment:null;for(let p=0;p<f;p++){const g=a.offsetY+a.gridH-(p+1)*a.colStep+q,D=b==="allowed"?1:x?.35:1;e.fillStyle=`rgba(${Oe.r},${Oe.g},${Oe.b},${D})`,e.beginPath(),e.roundRect(l,g,a.tileSize,a.tileSize,a.r),e.fill()}for(let p=0;p<m;p++){const g=a.offsetY+a.gridH-(f+p+1)*a.colStep+q;if(g<a.offsetY-a.tileSize)break;const D=b==="dropped"?1:x?.35:1;e.fillStyle=`rgba(${Ge.r},${Ge.g},${Ge.b},${D})`,e.beginPath(),e.roundRect(l,g,a.tileSize,a.tileSize,a.r),e.fill()}for(let p=0;p<u;p++){const g=a.offsetY+a.gridH-(f+m+p+1)*a.colStep+q;if(g<a.offsetY-a.tileSize)break;const D=b==="guarded"?1:x?.35:1;e.fillStyle=`rgba(${We.r},${We.g},${We.b},${D})`,e.beginPath(),e.roundRect(l,g,a.tileSize,a.tileSize,a.r),e.fill()}if(x&&b){e.save(),e.strokeStyle="rgba(255,255,255,0.4)",e.lineWidth=1;let p=0,g=0;b==="allowed"&&f>0?(p=a.offsetY+a.gridH-f*a.colStep+q,g=f*a.colStep-q):b==="dropped"&&m>0?(p=a.offsetY+a.gridH-(f+m)*a.colStep+q,g=m*a.colStep-q):b==="guarded"&&u>0&&(p=a.offsetY+a.gridH-y*a.colStep+q,g=u*a.colStep-q),g>0&&(e.beginPath(),e.roundRect(l-1,p-1,a.tileSize+2,g+2,a.r+1),e.stroke()),e.restore()}}}function xo(e,n,o,s,r){const a=Qe(o,s,r);if(!a)return null;const d=Math.floor((e-a.offsetX+q/2)/a.colStep);if(d<0||d>=a.visibleCols)return null;const c=r[a.startIdx+d],f=Math.ceil(c.allowedDelta/a.quantum),m=Math.ceil(c.droppedDelta/a.quantum),u=c.newlyGuarded.length,y=f+m+u;if(y===0)return null;const l=a.offsetX+d*a.colStep;if(e<l||e>l+a.tileSize)return null;const x=a.offsetY+a.gridH,b=x-f*a.colStep+q,p=x-(f+m)*a.colStep+q,g=x-y*a.colStep+q;return u>0&&n>=g&&n<p?{col:d,segment:"guarded"}:m>0&&n>=p&&n<b?{col:d,segment:"dropped"}:f>0&&n>=b&&n<=x?{col:d,segment:"allowed"}:null}function qe(e){return new Date(e*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}const de=5;function go(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 yo(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:qe(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,d=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:qe(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(d)>=5&&t.jsxs("span",{className:d>0?"text-sys-amber":"text-sys-cyan",children:[" ","(",d>0?"+":"",d,"% 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((c,f)=>t.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[t.jsx("span",{className:"font-mono truncate",children:c.name||c.pubkey.slice(0,8)}),t.jsx("span",{className:"text-fg-muted text-[10px] truncate flex-shrink-0 max-w-[100px]",children:c.reason})]},`${c.pubkey}-${f}`)),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:qe(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:go(a.remaining)})]},a.pubkey)),e.newlyGuarded.length>de&&t.jsxs("div",{className:"text-[10px] text-fg-muted",children:["+",e.newlyGuarded.length-de," more"]})]})]})}function bo(e){if(e.length<=ye)return e;const n=Math.ceil(e.length/ye),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 d of r)a.allowedDelta+=d.allowedDelta,a.droppedDelta+=d.droppedDelta,a.newlyGuarded=a.newlyGuarded.concat(d.newlyGuarded),a.drops=a.drops.concat(d.drops);o.push(a)}return o}function jo(){var C,A,L,P,B,R;const e=we(),n=Zs(),o=h.useMemo(()=>bo(n),[n]),s=h.useRef(null),r=h.useRef(null),{show:a,hide:d,updatePosition:c}=Ks(),f=h.useRef(!1),m=h.useRef(null),u=ie(),y=Qs(),[l,x]=h.useState(!1),b=(A=(C=u==null?void 0:u.config)==null?void 0:C.repeater)==null?void 0:A.advert_rate_limit,p=(P=(L=u==null?void 0:u.config)==null?void 0:L.repeater)==null?void 0:P.advert_penalty_box,g=(R=(B=u==null?void 0:u.config)==null?void 0:B.repeater)==null?void 0:R.advert_adaptive,D=(e==null?void 0:e.stats.adverts_allowed)??0,T=(e==null?void 0:e.stats.adverts_dropped)??0,S=h.useMemo(()=>{const M=new Set;for(const $ of o)for(const N of $.newlyGuarded)M.add(N.pubkey);return M.size},[o]),v=h.useMemo(()=>{const M=new Map;for(const N of(e==null?void 0:e.recent_drops)??[])N.name&&M.set(N.pubkey,N.name);const $=(u==null?void 0:u.neighbors)??{};for(const[N,F]of Object.entries($))if(!M.has(N)){const E=F.name||F.node_name;E&&M.set(N,E)}return N=>M.get(N)||N.slice(0,8)},[e==null?void 0:e.recent_drops,u==null?void 0:u.neighbors]),w=h.useMemo(()=>{let M=0,$=0;for(const F of o)M+=F.allowedDelta,$+=F.droppedDelta;const N=M+$;return N>0?Math.round($/N*100):0},[o]),j="10m",i=h.useCallback(()=>{const M=s.current,$=r.current;if(!M||!$)return;const N=$.getBoundingClientRect(),F=window.devicePixelRatio||1,E=Math.floor(N.width),W=Math.floor(N.height);if(E===0||W===0)return;M.width=E*F,M.height=W*F,M.style.width=`${E}px`,M.style.height=`${W}px`;const H=M.getContext("2d");H&&(H.scale(F,F),po(H,o,E,W,m.current))},[o]);h.useEffect(()=>{i();const M=new ResizeObserver(()=>i());return r.current&&M.observe(r.current),()=>M.disconnect()},[i]);const _=h.useCallback(M=>{const $=r.current;if(!$||o.length===0)return;const N=$.getBoundingClientRect(),F=Math.floor(N.width),E=Math.floor(N.height),W=M.clientX-N.left,H=M.clientY-N.top,O=xo(W,H,F,E,o);if(!O){m.current&&(m.current=null,i()),f.current&&(f.current=!1,d());return}const z=m.current;(!z||z.col!==O.col||z.segment!==O.segment)&&(m.current=O,i());const G=Qe(F,E,o);if(!G)return;const I=o[G.startIdx+O.col],X=yo(I,O.segment,w,v);f.current?c(M.clientX,M.clientY):f.current=!0,a(X,M.clientX,M.clientY)},[o,w,v,a,d,c,i]),k=h.useCallback(()=>{m.current&&(m.current=null,i()),f.current&&(f.current=!1,d())},[d,i]);return t.jsxs(be,{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(se,{color:"zinc",children:j})]}),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:D,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:S})]}),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(Ae,{color:"primary",outline:!0,className:"w-full justify-center",onClick:()=>x(!0),children:[t.jsx(Pn,{"data-slot":"icon"}),"Adapt"]})}),t.jsx(Cn,{open:l,onClose:()=>x(!1),currentConfig:{tokenBucket:b,penaltyBox:p,adaptive:g},onApplied:async()=>{await y({force:!0}).catch(()=>{})}})]})}const wo=h.memo(jo);function No(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 vo(){const e=we(),n=ie();return{all:h.useMemo(()=>{if(!(e!=null&&e.active_penalties))return[];const s=new Map;for(const c of e.recent_drops??[])c.name&&s.set(c.pubkey,c.name);const r=(n==null?void 0:n.neighbors)??{};for(const[c,f]of Object.entries(r))if(!s.has(c)){const m=f.name||f.node_name;m&&s.set(c,m)}const a=new Map,d=new Map;for(const c of e.recent_drops??[])a.has(c.pubkey)||a.set(c.pubkey,c.reason),d.set(c.pubkey,(d.get(c.pubkey)??0)+1);return Object.entries(e.active_penalties).sort(([,c],[,f])=>f-c).map(([c,f])=>({pubkey:c,name:s.get(c)||c.slice(0,8),remaining:f,reason:a.get(c),dropCount:d.get(c)??0}))},[e,n==null?void 0:n.neighbors]),isLoading:!e,penaltyCount:e?Object.keys(e.active_penalties??{}).length:0}}function fs({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: ",No(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 ko({open:e,onClose:n,offenders:o}){return t.jsxs(Wt,{open:e,onClose:n,size:"sm",children:[t.jsx(tn,{icon:t.jsx(ts,{size:20}),title:`Jail (${o.length})`,onClose:n}),t.jsx(qt,{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(fs,{offender:s},s.pubkey))})]})}function Mo(){const{all:e,isLoading:n,penaltyCount:o}=vo(),s=we(),[r,a]=h.useState(!1),d=h.useCallback(()=>a(!0),[]),c=h.useCallback(()=>a(!1),[]),f=e.slice(0,3),m=(s==null?void 0:s.recent_drops)??[],u=o===0&&m.length>0&&!n,y=m.slice(0,3);return t.jsxs(t.Fragment,{children:[t.jsxs(le,{title:"Most Wanted",icon:t.jsx(ts,{className:"mini-widget-icon"}),isLoading:n,isLoaded:!0,children:[f.length>0?t.jsx("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:f.map((l,x)=>t.jsx(fs,{offender:l,rank:x},l.pubkey))}):u?t.jsx("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:y.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(Ae,{plain:!0,className:"ml-auto text-[10px] text-sys-blue hover:underline",onClick:d,children:"Show All"})]}):u?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:[m.length," recent drop",m.length!==1?"s":""]})}):null]}),t.jsx(ko,{open:r,onClose:c,offenders:e})]})}const vt=[{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"}],kt={quiet:"text-sys-green",normal:"text-sys-blue",busy:"text-sys-amber",congested:"text-sys-red"},Mt=2,Co=4;function To(e,n,o,s){const{quietMax:r,normalMax:a,busyMax:d,ewmaValue:c}=n;e.clearRect(0,0,o,s);const f=Math.max(d*2,c*1.3,d+.5),m=Mt*3,u=o-m,y=[{start:0,end:r,color:Y.green},{start:r,end:a,color:Y.blue},{start:a,end:d,color:Y.amber},{start:d,end:f,color:Y.red}],l=[];let x=0;for(const k of y){const C=(k.end-k.start)/f*u;l.push({...k,px:x,pw:C}),x+=C+Mt}const b=8,p=b,g=s-b-2;for(const k of l)e.fillStyle=k.color,e.globalAlpha=1,e.beginPath(),e.roundRect(k.px,p,k.pw,g,Co),e.fill();function D(k){const C=Math.max(0,Math.min(k,f));for(const L of l)if(C<=L.end){const P=L.end>L.start?(C-L.start)/(L.end-L.start):0;return L.px+P*L.pw}const A=l[l.length-1];return A.px+A.pw}const T=D(c),S=4,v=4,w=p-1,j=p+g+1,i=at[900],_=at[200];e.fillStyle=i,e.beginPath(),e.moveTo(T-v,w-S),e.lineTo(T+v,w-S),e.lineTo(T,w),e.closePath(),e.fill(),e.fillStyle=_,e.beginPath(),e.moveTo(T-(v-1),w-S+.5),e.lineTo(T+(v-1),w-S+.5),e.lineTo(T,w-.5),e.closePath(),e.fill();for(const[k,C]of[[i,-1],[_,0],[i,1]])e.strokeStyle=k,e.lineWidth=1,e.beginPath(),e.moveTo(T+C,w),e.lineTo(T+C,j),e.stroke()}const Be={stiffness:120,damping:20,mass:.8};function So(){var A,L,P,B,R,M,$;const e=we(),n=Ut(),o=Xt(),s=sn(),r=ie(),a=h.useRef(null),d=h.useRef(null),c=(L=(A=r==null?void 0:r.config)==null?void 0:A.repeater)==null?void 0:L.advert_adaptive,f=(e==null?void 0:e.adaptive.current_tier)??"normal",m=e==null?void 0:e.adaptive.pending_tier,u=!!m&&m!==f,y=((P=c==null?void 0:c.thresholds)==null?void 0:P.quiet_max)??.05,l=((B=c==null?void 0:c.thresholds)==null?void 0:B.normal_max)??.2,x=((R=c==null?void 0:c.thresholds)==null?void 0:R.busy_max)??.5,b=ue(s),p=Me(b,Be),g=ue(y),D=ue(l),T=ue(x),S=Me(g,Be),v=Me(D,Be),w=Me(T,Be);h.useEffect(()=>{b.set(s)},[s,b]),h.useEffect(()=>{g.set(y)},[y,g]),h.useEffect(()=>{D.set(l)},[l,D]),h.useEffect(()=>{T.set(x)},[x,T]);const j=h.useCallback(()=>{const N=a.current,F=d.current;if(!N||!F)return;const E=F.getBoundingClientRect(),W=window.devicePixelRatio||1,H=Math.floor(E.width),O=Math.floor(E.height);if(H===0||O===0)return;N.width=H*W,N.height=O*W,N.style.width=`${H}px`,N.style.height=`${O}px`;const z=N.getContext("2d");z&&(z.scale(W,W),To(z,{quietMax:S.get(),normalMax:v.get(),busyMax:w.get(),ewmaValue:p.get()},H,O))},[S,v,w,p]);h.useEffect(()=>{const N=[p.on("change",()=>j()),S.on("change",()=>j()),v.on("change",()=>j()),w.on("change",()=>j())];return()=>N.forEach(F=>F())},[p,S,v,w,j]),h.useEffect(()=>{j();const N=new ResizeObserver(()=>j());return d.current&&N.observe(d.current),()=>N.disconnect()},[j]);const i=((M=vt.find(N=>N.key===f))==null?void 0:M.label)??f,_=kt[f]??"text-fg-muted",k=!e&&!o,C=o&&!n;return t.jsxs(le,{title:"Adaptive Tier",icon:t.jsx(nn,{className:"mini-widget-icon"}),isLoading:k,isLoaded:!0,error:C?"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:d,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:[i,u&&t.jsxs("span",{className:J("ml-1.5 text-[10px] font-normal animate-pulse",kt[m]??"text-fg-muted"),children:["→ ",(($=vt.find(N=>N.key===m))==null?void 0:$.label)??m]})]})]})}const _o=h.memo(So);function Ct(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 Bo(){var l;const e=we(),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,d=((l=e==null?void 0:e.metrics)==null?void 0:l.duplicate_ratio_ewma)??0,c=(e==null?void 0:e.stats.adverts_duplicate_reheard)??0,f=o+s,m=f>0?o/f*100:100,u=!e,y=f>0?s/f*100:0;return t.jsx(le,{title:"Drop Rate",icon:t.jsx(Qt,{className:"mini-widget-icon"}),value:Math.round(n),unit:"%",isLoading:u,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:f>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," / ",Ct(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:Ct(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":""]})]}),c>0&&t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx("span",{className:"text-fg-muted",children:"Deduped"}),t.jsxs("span",{children:[c.toLocaleString()," (",Math.round(d*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:`${m}%`}}),t.jsx("div",{className:"h-full rounded-full bg-sys-red transition-all duration-500",style:{width:`${y}%`}})]}),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 Do="/assets/spam-can-JZXwgFOy.svg",Ro=1376,Ue=768,Ao=[{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 Lo(){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:Ao.map(({x:e,w:n,stretch:o})=>t.jsx("svg",{viewBox:`${e} 0 ${n} ${Ue}`,preserveAspectRatio:"none",style:o?{height:"100%",flex:"1 1 0",minWidth:0}:{height:"100%",aspectRatio:`${n} / ${Ue}`,flexShrink:0},children:t.jsx("image",{href:Do,width:Ro,height:Ue})},e))})})}const Po=h.memo(Lo);function $o(){const e=Ut();return!Xt()||!e?null:t.jsxs("div",{className:"mesh-health-container relative",children:[t.jsxs("div",{className:"mesh-health-header",children:[t.jsx(Gn,{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(wo,{})}),t.jsx(_o,{}),t.jsx(Bo,{}),t.jsx(Mo,{}),t.jsx(Po,{})]})]})}function Mr(){var A,L,P;const e=ie(),n=an(),o=on(),s=ua(),r=h.useRef(!1);o&&!r.current&&(r.current=!0);const a=r.current,d=je(),c=Gt(),f=rn(),m=ne[d]??ne[4],u=f.isBackgroundLoading&&d>=5,[y,l]=h.useState([]),[x,b]=h.useState(0),[p,g]=h.useState(()=>localStorage.getItem("rx-crc-overlay")==="true"),D=h.useCallback(()=>{g(B=>{const R=!B;return localStorage.setItem("rx-crc-overlay",String(R)),R})},[]),[T,S]=h.useState(()=>localStorage.getItem("rx-analytics-view")==="true"),v=h.useCallback(B=>{S(B),localStorage.setItem("rx-analytics-view",String(B))},[]);h.useEffect(()=>{const B=Math.ceil(m.minutes/60);Promise.all([It(B),Ht(B,5e4)]).then(([R,M])=>{var $,N;b((R.success&&(($=R.data)==null?void 0:$.count)!=null?R.data.count:M.success&&((N=M.data)==null?void 0:N.count)!=null?M.data.count:0)??0),l(M.success&&M.data?M.data.history:[])})},[m.minutes]);const w=h.useMemo(()=>{const B=O=>(O==null?void 0:O.reduce((z,G)=>z+G.count,0))??0,R=B(s==null?void 0:s.received),M=B(s==null?void 0:s.unique_received),$=B(s==null?void 0:s.forwarded),N=B(s==null?void 0:s.dropped),F=B(s==null?void 0:s.transmitted),E=((s==null?void 0:s.time_range_minutes)??m.minutes)/60,W=E>0?Math.round(R/E):0,H=E>0?Math.round($/E):0;return{received:R,uniqueReceived:M,forwarded:$,dropped:N,transmitted:F,rxPerHour:W,fwdPerHour:H}},[s,m.minutes]),j=h.useMemo(()=>s?{totalBytes:s.totalReceivedBytes,kbPerHour:s.kbPerHour}:{totalBytes:0,kbPerHour:0},[s]),i=h.useMemo(()=>{if(!s)return[];const{receivedBytesBuckets:B,start_time:R,bucket_duration_seconds:M,bucket_count:$}=s,N=new Array($).fill(0);for(const F of y){let E=Math.floor((F.timestamp-R)/M);E<0&&(E=0),!(E>=$)&&N[E]++}return B.map((F,E)=>({start:F.start,end:F.end,bytesByType:{...F.countByType,...p&&N[E]>0?{[Q]:N[E]}:{}},totalBytes:F.totalCount}))},[s,y,p]),_=h.useMemo(()=>{if(!s)return[];const{receivedCountByType:B}=s,R=Object.keys(B).map(M=>parseInt(M,10)).filter(M=>(B[M]??0)>0).sort((M,$)=>(B[$]??0)-(B[M]??0));return p&&x>0&&R.unshift(Q),R},[s,x,p]),k=h.useMemo(()=>{if(!s)return{};const B={...s.receivedCountByType??{}};return p&&x>0&&(B[Q]=x),B},[s,x,p]),C=(e==null?void 0:e.node_name)??((A=e==null?void 0:e.config)==null?void 0:A.node_name)??"Unknown Node";return h.useEffect(()=>{C&&C!=="Unknown Node"&&(document.title=`pyMC: ${C}`)},[C]),n?t.jsxs(rt,{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(ln,{children:[t.jsx(cn,{title:C,icon:t.jsx($n,{}),subtitle:t.jsx(Ln,{}),controls:t.jsx(Jt,{ranges:ne,selectedIndex:d,onSelect:c,isPending:u})}),t.jsxs(dn,{ready:a,children:[t.jsx(fo,{}),t.jsx(ct,{template:"hero-auto",children:t.jsxs(rt,{neomorphic:!0,children:[t.jsx(Pt,{icon:t.jsx(Qt,{}),title:"PACKETS RECEIVED",badge:m.label,badgeColor:"zinc",titleExtra:t.jsx($t,{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(ot,{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:D,className:"p-1 rounded hover:bg-zinc-500/20 active:bg-zinc-500/30 transition-colors touch-manipulation",title:p?"Hide CRC Errors":"Show CRC Errors","aria-label":p?"Hide CRC error overlay":"Show CRC error overlay","aria-pressed":p,children:t.jsx(ot,{className:`w-3.5 h-3.5 transition-colors ${p?"text-sys-red":"text-fg-muted"}`})}),t.jsxs("div",{className:"data-box",children:[j.kbPerHour," KB/hr"]})]})}):void 0}),t.jsx("div",{className:"flex-1 min-h-0 flex flex-col",children:T?t.jsx(Ma,{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:y,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:m.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(se,{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(se,{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(ha,{buckets:i,activeTypes:_,totalByType:k,mode:"count"})})]})})]})}),t.jsx(ao,{leading:t.jsx(Da,{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:m.label})}),t.jsx($o,{}),t.jsx(Aa,{}),e&&t.jsx(ct,{template:"auto",children:t.jsx(Tn,{nodeName:C,publicKey:e.public_key,pathHashMode:(P=(L=e.config)==null?void 0:L.mesh)==null?void 0:P.path_hash_mode})})]})]})}export{Mr as default};
