const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BOwCLZTK.js","assets/index-DH0lUVGm.css"])))=>i.map(i=>d[i]);
import{d as E,e as lt,_ as je,f as Ne,h as Pe,k as ct,r as h,j as e,A as Fe,m as Q,S as dt,M as mt,U as ut,n as xt,o as ft,p as ht,q as pt,t as gt,v as H,w as fe,x as U,y as yt,z as bt,D as ve,E as jt,L as ee,F as Nt,G as te,H as vt,J as wt,K as se,N as Le,T as kt,O as Ct,B as we,R as Ae,P as Ee,Q as Tt,V as G,W as L,X as Mt,Y as _t,$ as Bt,a0 as St,a1 as Dt,a2 as Rt,a3 as oe,u as he,a4 as Pt,a5 as Ft,a6 as ke,a7 as ie,a8 as Y,a9 as He,aa as Lt,ab as K,ac as At,ad as Et,ae as Ht,af as Ce,ag as $t,c as F,ah as It,ai as $e,aj as Te,ak as Ot,al as zt,am as qt,an as Wt,ao as Ut,ap as Vt}from"./index-BOwCLZTK.js";import{C as Me,P as Gt,a as Xt,B as Yt}from"./PageLayout-QKntxcnp.js";import{u as I,r as O,h as Kt,a as Jt,b as Zt,i as Qt}from"./consumer-registry-CTjikLma.js";import{A as V,D as A,E as es}from"./DataValue-x_TMPgMk.js";import{c as ts}from"./node-types-C6okL8rE.js";import{b as Ie,c as W,a as ss,d as ns,F as J}from"./meshcore-tx-constants-DgpFTAmf.js";import{S as as,u as ue,P as os,T as is,C as Oe}from"./PacketList-DquMVCqT.js";import{useGetDecodedContent as rs,useResolveSource as ls}from"./usePipelineStore-Cw6U5jyB.js";import{A as _e}from"./SignalIndicator-Calk-LyB.js";import{T as ze,M as cs}from"./MqttModeBadge-CSj5wNzF.js";import{L as qe}from"./LightSparkline-C68RXWon.js";import{c as ds}from"./link-scoring-CgjOR3NF.js";import{Z as ms}from"./zap-Bd-kARJ1.js";import{N as us}from"./NodeInformationCard-PgTi9luy.js";import{g as xs,e as re,a as fs,f as hs}from"./chat-utils-D21OFED5.js";import{M as We,C as ps}from"./ChatBubble-CCVYaLOe.js";import{C as Be}from"./chevron-right-DJVm4pVP.js";import{H as gs}from"./hash-Dwn2PbMF.js";import{M as ys}from"./message-square-BcKhgYbO.js";import{H as bs}from"./useMapViewStore-DpXuD1iT.js";import{R as le,C as ce}from"./Grid-eFMUBxsw.js";import{C as js}from"./circle-x-BJVhIbR2.js";import"./index-2RIoVPos.js";import"./primitives-DEqdAn1G.js";import"./badge-colors-DCbxcv7o.js";import"./arrow-up-BqsZCBBC.js";import"./map-pin-C2z_C0J3.js";import"./circle-question-mark-XDnZ1ChV.js";import"./triangle-alert-SO3tIa8w.js";import"./DataBox-BVnEv6Au.js";import"./layers-Dg2mpSl7.js";import"./activity-D5uH2SFx.js";import"./circle-check-CmQaOkab.js";import"./database-C6oOGn9y.js";import"./shield-DYw72pvS.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 Ns=[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]],vs=E("arrow-up-right",Ns);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ws=[["path",{d:"M2 13a2 2 0 0 0 2-2V7a2 2 0 0 1 4 0v13a2 2 0 0 0 4 0V4a2 2 0 0 1 4 0v13a2 2 0 0 0 4 0v-4a2 2 0 0 1 2-2",key:"57tc96"}]],ks=E("audio-waveform",ws);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Cs=[["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"}]],Ts=E("chart-column",Cs);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ms=[["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"}]],_s=E("ear",Ms);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Bs=[["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"}]],Ss=E("megaphone",Bs);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ds=[["path",{d:"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"}]],Rs=E("pill-bottle",Ds);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ps=[["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"}]],Fs=E("satellite-dish",Ps);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ls=[["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"}]],As=E("tablets",Ls);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Es=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],Hs=E("timer",Es),$=lt(()=>({result:null,isComputing:!1})),$s=500,Is=300;let z=null,Z=null;function Os(t){var a;const n=(a=t==null?void 0:t.config)==null?void 0:a.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 zs(){if(z)return z;if(typeof window>"u")return null;try{z=new Worker(new URL("/assets/dashboard-bucketing.worker-RVncOvX0.js",import.meta.url),{type:"module"}),z.onmessage=t=>{if(t.data.type==="error"){console.error("[DashboardBucketing] Worker error:",t.data.error),$.setState({isComputing:!1});return}$.setState({result:t.data.payload,isComputing:!1})},z.onerror=t=>{console.error("[DashboardBucketing] Worker error:",t),$.setState({isComputing:!1})}}catch(t){console.error("[DashboardBucketing] Failed to init worker:",t)}return z}function qs(t,n,a,s){const o=zs();if(!o)return;const i=t.length,d=new Float64Array(i),r=new Float64Array(i),c=new Uint16Array(i),u=new Uint8Array(i),m=new Uint8Array(i),x=new Uint8Array(i),l=new Uint8Array(i),j=new Float32Array(i),b=new Float32Array(i),g=new Uint32Array(i),v=new Map;let w=0;for(let y=0;y<i;y++){const N=t[y];d[y]=N.timestamp??0,r[y]=Pe(N,s),c[y]=Math.min(N.length??N.payload_length??0,65535),u[y]=(N.type??N.payload_type??0)&15;const k=N.packet_origin;m[y]=k==="tx_local"?1:k==="tx_forward"?2:0,x[y]=N.transmitted?1:0,l[y]=N.drop_reason?1:0,j[y]=N.snr??0,b[y]=N.rssi??0;const D=N.packet_hash??"";let f=v.get(D);f===void 0&&(f=w++,v.set(D,f)),g[y]=f}$.setState({isComputing:!0});const C={type:"compute",payload:{timestamps:d,airtimeMs:r,byteSizes:c,payloadTypes:u,origins:m,transmitted:x,dropped:l,snrValues:j,rssiValues:b,hashIndices:g,rangeMinutes:n,bucketCount:a}};o.postMessage(C,[d.buffer,r.buffer,c.buffer,u.buffer,m.buffer,x.buffer,l.buffer,j.buffer,b.buffer,g.buffer])}function de(t){return Object.keys(t).map(n=>parseInt(n,10)).filter(n=>t[n]>0).sort((n,a)=>t[a]-t[n])}function Ws(t,n,a){const s={...t,received:[...t.received],unique_received:[...t.unique_received],transmitted:[...t.transmitted],forwarded:[...t.forwarded],dropped:[...t.dropped],receivedBytesBuckets:t.receivedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType}})),forwardedBytesBuckets:t.forwardedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType}})),droppedBytesBuckets:t.droppedBytesBuckets.map(m=>({...m,bytesByType:{...m.bytesByType}})),receivedTotalByType:{...t.receivedTotalByType},forwardedTotalByType:{...t.forwardedTotalByType},droppedTotalByType:{...t.droppedTotalByType}},{start_time:o,end_time:i,bucket_duration_seconds:d,bucket_count:r}=t,c=new Set;for(const m of n){const x=m.timestamp??0;if(x<o||x>i)continue;const l=Math.floor((x-o)/d);if(l<0||l>=r)continue;c.has(l)||(c.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 j=Pe(m,a),b=m.length??m.payload_length??0,g=m.type??m.payload_type??0,v=m.packet_origin;v==="tx_local"?(s.transmitted[l].count++,s.transmitted[l].airtime_ms+=j):v==="tx_forward"||m.transmitted?(s.forwarded[l].count++,s.forwarded[l].airtime_ms+=j,s.forwardedBytesBuckets[l].bytesByType[g]=(s.forwardedBytesBuckets[l].bytesByType[g]??0)+b,s.forwardedBytesBuckets[l].totalBytes+=b,s.forwardedTotalByType[g]=(s.forwardedTotalByType[g]??0)+b,s.totalForwardedCount++):m.drop_reason&&(s.dropped[l].count++,s.dropped[l].airtime_ms+=j,s.droppedBytesBuckets[l].bytesByType[g]=(s.droppedBytesBuckets[l].bytesByType[g]??0)+b,s.droppedBytesBuckets[l].totalBytes+=b,s.droppedTotalByType[g]=(s.droppedTotalByType[g]??0)+b,s.totalDroppedCount++),v!=="tx_local"&&(s.received[l].count++,s.received[l].airtime_ms+=j,s.unique_received[l].count++,s.unique_received[l].airtime_ms+=j,s.receivedBytesBuckets[l].bytesByType[g]=(s.receivedBytesBuckets[l].bytesByType[g]??0)+b,s.receivedBytesBuckets[l].totalBytes+=b,s.receivedTotalByType[g]=(s.receivedTotalByType[g]??0)+b,s.totalReceivedBytes+=b)}const u=s.time_range_minutes/60;return s.kbPerHour=u>0?Math.round(s.totalReceivedBytes/1024/u):0,s.forwardedRatePerHour=u>0?Math.round(s.totalForwardedCount/u):0,s.droppedRatePerHour=u>0?Math.round(s.totalDroppedCount/u):0,s.receivedActiveTypes=de(s.receivedTotalByType),s.forwardedActiveTypes=de(s.forwardedTotalByType),s.droppedActiveTypes=de(s.droppedTotalByType),s}typeof window<"u"&&Promise.all([je(()=>import("./index-BOwCLZTK.js").then(t=>t.fI),__vite__mapDeps([0,1])),je(()=>import("./index-BOwCLZTK.js").then(t=>t.fH),__vite__mapDeps([0,1]))]).then(([t,n])=>{const{DASHBOARD_TIME_RANGES:a}=n;let s=0,o=-1,i="";t.useStore.subscribe(d=>{const r=d.packets.length,c=d.globalTimeRangeIndex,u=Os(d.stats);if(r===s&&c===o&&u===i)return;const m=s,x=o,l=i;if(s=r,o=c,i=u,r===0)return;const j=a[c]??a[4],b=j.minutes,g=j.buckets,v=d.stats,w=Ne(v),C=r-m,y=c!==x,N=u!==l,k=$.getState().result;if(!y&&!N&&C>0&&C<$s&&k!==null&&k.time_range_minutes===b&&k.bucket_count===g){const f=d.packets.slice(r-C),T=Ws(k,f,w);$.setState({result:T})}else Z&&clearTimeout(Z),Z=setTimeout(()=>{Z=null;const f=t.useStore.getState();if(f.packets.length===0||!f.stats)return;const T=a[f.globalTimeRangeIndex]??a[4],_=Ne(f.stats);qs(f.packets,T.minutes,T.buckets,_)},Is)})});const Us=()=>$(t=>t.result),Ue=[{target:"ReceivedChart",fn:"type",minStage:1},{target:"ReceivedChart",fn:"airtime",minStage:1,when:Kt}];O(Ue);function Vs(t){const a=new Date(t*1e3).getHours();return a>=6&&a<18}function Gs(t){return new Date(t*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})}function Xs({buckets:t,activeTypes:n,totalByType:a}){I(Ue);const s=ct(),[o,i]=h.useState(null),[d,r]=h.useState(null),[c,u]=h.useState(null),m=h.useCallback((v,w,C)=>{i(w),r(C)},[]),x=t.length>0&&n.length>0,l=o?Vs(o.start):null,j=o?Gs(o.start):"",b=c!==null&&l!==null&&c!==l;l!==c&&u(l);const g=48;return e.jsxs("div",{className:"flex flex-col h-full relative",children:[e.jsx("div",{className:"h-5 relative mb-1 shrink-0",children:o&&d!==null&&e.jsxs("div",{className:"absolute flex items-center gap-1.5 type-data-sm -translate-x-1/2",style:{left:`calc(${g}px + ${d*100}% * (1 - ${g}px / 100%))`},children:[e.jsx(Fe,{mode:"wait",children:e.jsx(Q.span,{initial:b?{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:l?e.jsx(dt,{className:"w-4 h-4 text-sys-amber"}):e.jsx(mt,{className:"w-4 h-4 text-sys-blue"})},l?"sun":"moon")}),e.jsx("span",{className:"text-fg-secondary",children:j})]})}),e.jsx("div",{className:"flex-1 min-h-0",children:x&&e.jsx(ut,{buckets:t,activeTypes:n,gridColor:s.grid,axisTickColor:s.axisTick,onHover:m})}),e.jsx("div",{className:"pt-2 px-1 pb-2 shrink-0",children:x&&e.jsx(xt,{activeTypes:n,totalByType:a})})]})}function Ys(t,n,a){var i,d;if(t.length<=a)return t;const s=t.length/a,o=[];for(let r=0;r<a;r++){const c=Math.floor(r*s),u=Math.floor((r+1)*s),m=t.slice(c,u),x={start:((i=m[0])==null?void 0:i.start)??0,end:((d=m.at(-1))==null?void 0:d.end)??0,bytesByType:{},totalBytes:0};for(const l of m){x.totalBytes+=l.totalBytes;for(const j of n){const b=l.bytesByType[j]??0;b>0&&(x.bytesByType[j]=(x.bytesByType[j]??0)+b)}}o.push(x)}return o}function Ks(t,n,a,s,o,i,d){if(n.length===0)return;const r=Ys(n,a,pt.statsCard),c=r.length,u=i/c,m=r.map(l=>l.totalBytes),x=Math.max(...m);if(x!==0){for(let l=0;l<c;l++){const j=r[l],b=s+l*u,g=j.totalBytes;if(g===0)continue;const w=g/x*d;let y=o+d-w+w;for(const N of a){const k=j.bytesByType[N]??0;if(k===0)continue;const D=k/g*w,f=y-D;t.fillStyle=gt(N),t.globalAlpha=.85,t.fillRect(b,f,u,D),y=f}}t.globalAlpha=1}}function Js({buckets:t,activeTypes:n}){const a=h.useRef(null),s=h.useRef(t),o=h.useRef(n);s.current=t,o.current=n;const i=h.useMemo(()=>{const d=t.map(c=>c.start),r=t.map(()=>1);return[d,r]},[t]);return h.useEffect(()=>{if(!a.current||t.length===0)return;const d=a.current;let r=null,c=null;const u=ft(()=>{const m=d.getBoundingClientRect(),x=Math.floor(m.width)||200,l=Math.floor(m.height)||60,j={width:x,height:l,padding:[0,0,0,0],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 g=b.ctx,{left:v,top:w,width:C,height:y}=b.bbox;Ks(g,s.current,o.current,v,w,C,y)}]}};r=new ht(j,i,d),c=new ResizeObserver(()=>{const b=d.getBoundingClientRect();b.width>0&&b.height>0&&(r==null||r.setSize({width:Math.floor(b.width),height:Math.floor(b.height)}))}),c.observe(d)});return()=>{u(),c==null||c.disconnect(),r==null||r.destroy()}},[i,t.length]),t.length===0?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"w-full h-0.5 rounded-full bg-fg-muted/15"})}):e.jsx("div",{ref:a,className:"w-full h-full"})}const Ve=h.memo(Js),Ge=[{target:"ForwardedCard",fn:"type",minStage:1}];O(Ge);function Zs({value:t,receivedCount:n,buckets:a,activeTypes:s,ratePerHour:o,timeRangeLabel:i,icon:d,isLoaded:r=!0}){I(Ge);const c=n>0?(t/n*100).toFixed(1):null;return r?e.jsxs(H,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3",children:[d&&e.jsx("span",{className:"icon-sm text-icon-card-title",children:d}),e.jsx("span",{className:"type-micro",children:"FORWARDED"}),i&&e.jsx(U,{color:"zinc",className:"hidden sm:inline-flex",children:i})]}),e.jsx("div",{className:"type-data-xl text-fg-primary",children:e.jsx(V,{value:t,className:"font-mono tabular-nums",priority:"high"})}),e.jsx("div",{className:"flex-1 mt-1 overflow-hidden min-h-[40px] sm:min-h-[60px]",children:s.length>0?e.jsx(Ve,{buckets:a,activeTypes:s}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx("div",{className:"w-full h-0.5 rounded-full bg-fg-muted/15"})})}),e.jsx("div",{className:"pt-1.5 sm:pt-2 mt-1",children:e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Rate"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[o,"/hr"]})]}),c!==null&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Ratio"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[c,"%"]})]})]})})]}):e.jsx(H,{children:e.jsx(fe,{})})}const Xe=[{target:"DroppedCard",fn:"type",minStage:1}];O(Xe);function Qs({value:t,receivedCount:n,buckets:a,activeTypes:s,ratePerHour:o,timeRangeLabel:i,icon:d,isLoaded:r=!0}){I(Xe);const c=n>0?(t/n*100).toFixed(1):null;return r?e.jsxs(H,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3",children:[d&&e.jsx("span",{className:"icon-sm text-icon-card-title",children:d}),e.jsx("span",{className:"type-micro",children:"DROPPED"}),i&&e.jsx(U,{color:"zinc",className:"hidden sm:inline-flex",children:i})]}),e.jsx("div",{className:"type-data-xl text-fg-primary",children:e.jsx(V,{value:t,className:"font-mono tabular-nums",priority:"high"})}),e.jsx("div",{className:"flex-1 mt-1 overflow-hidden min-h-[40px] sm:min-h-[60px]",children:s.length>0?e.jsx(Ve,{buckets:a,activeTypes:s}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx("div",{className:"w-full h-0.5 rounded-full bg-fg-muted/15"})})}),e.jsx("div",{className:"pt-1.5 sm:pt-2 mt-1",children:e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Rate"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[o,"/hr"]})]}),c!==null&&e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Drop %"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[c,"%"]})]})]})})]}):e.jsx(H,{children:e.jsx(fe,{})})}const en=2,tn=1;function sn(t,n,a){const s=c=>(c==null?void 0:c.reduce((u,m)=>u+m.count,0))??0,o=s(n),i=s(a),d=o||(t==null?void 0:t.rx_count)||1,r=i||(t==null?void 0:t.dropped_count)||0;return d>0?r/(d+r)*100:0}function nn(t,n,a){const s=o=>(o==null?void 0:o.reduce((i,d)=>i+d.count,0))??0;if(n!=null&&n.length&&a){const i=s(n)*100,d=n.length*a*1e3;return i/d*100}if(t){const o=(t.uptime_seconds||1)*1e3;return(t.total_airtime_ms||t.airtime_used_ms||0)/o*100}return 0}function Se(t,n,a){return ss(Math.max(n,Math.min(a,t)))}function an(t,n,a,s,o){let i=Ie(t);n>20?i+=J*2:n>12&&(i+=J),a>8&&(i+=J);const d=Se(i,0,en);let r=ns(t);a>8&&(r+=J);const c=Se(r,0,tn),u=W(d),m=W(c),x=s!==null?W(s):null;let l="stable";return x!==null&&(u>x?l="increase":u<x&&(l="decrease")),{floodFactor:d,directFactor:c,floodSlots:u,directSlots:m,adjustment:l,duplicateRate:Math.round(n*100)/100,txUtilization:Math.round(a*1e3)/1e3,zeroHopCount:t}}function on({stats:t,receivedBuckets:n,droppedBuckets:a,forwardedBuckets:s,bucketDurationSeconds:o,timeRangeLabel:i,isLoaded:d=!0}){var pe,ge,ye,be;const[r,c]=h.useState(!1),[u,m]=h.useState("idle"),x=yt(),l=h.useCallback(async(P,rt)=>{if(u!=="applying"){m("applying");try{const ae=await bt({tx_delay_factor:P,direct_tx_delay_factor:rt});ae!=null&&ae.success?(m("success"),setTimeout(()=>m("idle"),2e3)):(m("error"),setTimeout(()=>m("idle"),2500))}catch{m("error"),setTimeout(()=>m("idle"),2500)}}},[u]);if(!d)return e.jsx(H,{children:e.jsx(fe,{})});const j=10080*60,g=Math.floor(Date.now()/1e3)-j,v=Object.values((t==null?void 0:t.neighbors)??{}).filter(P=>P.zero_hop&&P.last_seen>=g&&ts(P).isRepeater).length,w=x.filter(P=>P.status==="active"||P.lastSeen>=g).length,C=Math.max(v,w),y=sn(t,n,a),N=nn(t,s,o),k=((ge=(pe=t==null?void 0:t.config)==null?void 0:pe.delays)==null?void 0:ge.tx_delay_factor)??null,D=((be=(ye=t==null?void 0:t.config)==null?void 0:ye.delays)==null?void 0:be.direct_tx_delay_factor)??null,f=an(C,y,N,k),T=C!==1,_=Ie(C),B=[`${C} repeater${T?"s":""} heard in the last 7 days (base ×${_.toFixed(1)}).`];f.floodFactor===_&&y<=12&&N<=8?B.push("No modifiers applied — network looks healthy."):(y>20?B.push(`High duplicate rate (${y.toFixed(1)}%) suggests frequent collisions — window widened.`):y>12&&B.push(`Elevated duplicate rate (${y.toFixed(1)}%) — window widened one step.`),N>8&&B.push(`Channel is busy (${N.toFixed(1)}% TX util) — extra spacing added.`));const p=[`Direct uses one forwarder — ×${f.directFactor.toFixed(1)} backoff for channel contention.`];N>8&&p.push("Busy channel — small extra backoff.");const M=[`Flood ×${f.floodFactor.toFixed(1)} (${f.floodSlots} slot${f.floodSlots!==1?"s":""})`,...B,"",`Direct ×${f.directFactor.toFixed(1)}`,...p,"","Click to copy CLI commands"].join(`
`),S=k!==null?W(k):null,R=D!==null?W(D):null,ne=S!==null&&f.floodSlots!==S,nt=R!==null&&f.directSlots!==R,at=ne||nt,ot=async()=>{const P=`set txdelay ${f.floodFactor.toFixed(1)}
set direct.txdelay ${f.directFactor.toFixed(1)}`;await Nt(P),c(!0),setTimeout(()=>c(!1),1500)},it=()=>l(f.floodFactor,f.directFactor);return e.jsxs(H,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3 flex-wrap",children:[e.jsx(as,{className:"w-4 h-4 text-icon-card-title flex-shrink-0"}),e.jsx("span",{className:"type-micro",children:"DELAY DOCTOR"}),i&&e.jsx(U,{color:"zinc",className:"hidden sm:inline-flex",children:i})]}),e.jsxs("button",{onClick:ot,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:M,children:[e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("span",{className:"type-data-xl text-fg-primary",children:e.jsxs(A,{children:["×",f.floodFactor.toFixed(1)]})}),e.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Flood"})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx("span",{className:"type-data-xl text-sys-blue",children:e.jsxs(A,{children:["×",f.directFactor.toFixed(1)]})}),e.jsx("span",{className:"type-micro text-fg-muted mt-0.5 sm:mt-1",children:"Direct"})]}),e.jsx("div",{className:"flex items-center self-center opacity-0 group-hover:opacity-100 transition-opacity",children:r?e.jsx(ve,{className:"w-4 h-4 text-sys-green"}):e.jsx(jt,{className:"w-4 h-4 text-fg-muted"})})]}),e.jsx("div",{className:"flex-1 py-2",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"data-box-label",children:"Dupe"}),e.jsxs("div",{className:`data-box data-box-fill data-box-left ${f.duplicateRate>8?"text-status-warning":""}`,children:[f.duplicateRate.toFixed(1),"%"]})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"data-box-label",children:"TX Util"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[f.txUtilization.toFixed(2),"%"]})]})]})}),e.jsx("div",{className:"pt-2 mt-auto",children:e.jsxs("div",{className:"flex items-end justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Current"}),e.jsx("div",{className:"flex gap-2",children:k!==null?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:["×",k.toFixed(2)]})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"data-box data-box-fill data-box-left",style:{color:"var(--sys-blue)"},children:["×",(D==null?void 0:D.toFixed(2))??"—"]})})]}):e.jsx("span",{className:"text-sm text-fg-muted",children:"No config"})})]}),at&&e.jsxs("button",{onClick:it,disabled:u==="applying"||u==="success",className:`flex items-center gap-1.5 px-2.5 py-1.5 radius-inner type-micro font-medium transition-base
                ${u==="success"?"bg-sys-green/15 text-sys-green":u==="error"?"bg-sys-red/15 text-sys-red":u==="applying"?"bg-subtle-fill text-fg-muted":"bg-sys-blue/10 text-sys-blue hover:bg-sys-blue/20"}`,title:`Apply ×${f.floodFactor.toFixed(1)} flood, ×${f.directFactor.toFixed(1)} direct`,children:[u==="success"?"Rx'd":u==="error"?"Failed":"Apply",u==="applying"?e.jsx(ee,{className:"w-3.5 h-3.5 animate-spin"}):u==="success"?e.jsx(ve,{className:"w-3.5 h-3.5"}):e.jsxs("span",{className:"relative inline-flex items-end w-6 h-3.5",children:[e.jsx(Rs,{className:"w-3.5 h-3.5 absolute left-0 bottom-0"}),e.jsx(As,{className:"w-3 h-3 absolute right-0 bottom-0"})]})]})]})})]})}const Ye=[{target:"RecentPackets",fn:"rssi",minStage:1},{target:"RecentPackets",fn:"snr",minStage:1}];O(Ye);const rn=25;function ln(){I(Ye);const t=te(),n=vt(),a=wt(),s=se(),o=rs(),i=ue(j=>j.requestChannel),[d,r]=h.useState(!0),c=h.useCallback(j=>r(j),[]),u=h.useMemo(()=>[...t.length<=100?t:t.slice(-100)].sort((b,g)=>(g.timestamp??0)-(b.timestamp??0)),[t]),m=s==null?void 0:s.local_hash,x=s==null?void 0:s.neighbors,l=ls();return e.jsxs(H,{noPadding:!0,className:"!overflow-visible",children:[e.jsx(Le,{listHeader:!0,icon:e.jsx(Ae,{}),title:"Recent Packets",actions:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(kt,{enabled:d,onChange:c,label:"Hide Dupes",size:"sm"}),a&&e.jsx(Ct,{showLabel:!0}),e.jsxs(we,{color:"primary",outline:!0,href:"/packets",children:["View all",e.jsx(_e,{"data-slot":"icon"})]})]})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-1",children:e.jsx(os,{packets:u,allPackets:t,localHash:m,neighbors:x,resolveSource:l,getDecodedContent:o,onChannelClick:i,loading:n,maxPackets:rn,showPagination:!1,flashNewest:!0,hideDupes:d,emptyMessage:"No packets received",footerAction:e.jsxs(we,{color:"primary",outline:!0,href:"/packets",children:["View all",e.jsx(_e,{"data-slot":"icon"})]})})})]})}const cn={stable:"M5 12h14",up:"M5 15l7-7 7 7",down:"M19 9l-7 7-7-7"};function dn({trend:t}){return e.jsx("span",{className:`mini-widget-trend ${t}`,children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:cn[t]})})})}function mn(){return e.jsx("div",{className:"mini-widget-loading",children:e.jsx("div",{className:"mini-widget-loading-spinner"})})}function un({message:t}){return e.jsx("div",{className:"mini-widget-error",children:e.jsx("span",{title:t,children:"No data"})})}function q({title:t,icon:n,value:a,unit:s,valueSize:o="md",status:i,subtitle:d,subtitleValue:r,trend:c,children:u,isLoading:m=!1,error:x,className:l="",onClick:j}){const b=["mini-widget-value",o==="lg"&&"mini-widget-value-lg",o==="sm"&&"mini-widget-value-sm"].filter(Boolean).join(" "),g=["mini-widget",l].filter(Boolean).join(" ");return e.jsxs(H,{noPadding:!0,className:g,onClick:j,children:[e.jsxs("div",{className:"mini-widget-header",children:[n,e.jsx("span",{className:"mini-widget-title",children:t}),i&&i!=="unknown"&&e.jsx("div",{className:`mini-widget-status-dot ${i}`}),c&&e.jsx(dn,{trend:c})]}),m?e.jsx(mn,{}):x?e.jsx(un,{message:x}):e.jsxs("div",{className:"mini-widget-content",children:[(a!==void 0||d||r)&&e.jsxs("div",{className:"mini-widget-value-row",children:[a!==void 0&&e.jsxs("div",{className:b,children:[typeof a=="number"?e.jsx(V,{value:a,className:"font-mono tabular-nums",priority:"medium",format:Number.isInteger(a)?void 0:{minimumFractionDigits:1,maximumFractionDigits:1}}):e.jsx(A,{children:a}),s&&e.jsx("span",{className:"mini-widget-unit",children:s})]}),(d||r)&&e.jsxs("span",{className:"mini-widget-badge-group",children:[d&&!r&&e.jsx("span",{className:"data-box mini-widget-subtitle-box",children:d}),d&&r&&e.jsx("span",{className:"mini-widget-subtitle truncate",children:d}),r&&e.jsx("span",{className:"data-box mini-widget-subtitle-box",children:r})]})]}),u]})]})}const xn={DELTA_CRITICAL:10,SLOPE_CRITICAL:4,JITTER_CRITICAL:6,DELTA_WARNING:5,SLOPE_WARNING:2,JITTER_WARNING:4},Ke={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 xe(t,n){if(t.length===0)return null;const a=[...t].sort((d,r)=>d-r),s=n/100*(a.length-1),o=Math.floor(s),i=Math.ceil(s);return o===i?a[o]:a[o]+(a[i]-a[o])*(s-o)}function De(t){return xe(t,50)}function fn(t){if(t.length<2)return 0;const n=t.reduce((o,i)=>o+i,0)/t.length,s=t.map(o=>Math.pow(o-n,2)).reduce((o,i)=>o+i,0)/t.length;return Math.sqrt(s)}function hn(t){if(t.length<2)return 0;const n=t.length;let a=0,s=0,o=0,i=0;const d=t[0].timestamp;for(const c of t){const u=(c.timestamp-d)/3600,m=c.value;a+=u,s+=m,o+=u*m,i+=u*u}const r=n*i-a*a;return Math.abs(r)<1e-4?0:(n*o-a*s)/r}function pn(t,n,a){const s=xn;return t>=s.DELTA_CRITICAL?[2,`Noise floor ${t.toFixed(1)} dB above baseline`]:n>=s.SLOPE_CRITICAL?[2,`Noise floor rising ${n.toFixed(1)} dB/hour`]:a>=s.JITTER_CRITICAL?[2,`Noise floor unstable (±${a.toFixed(1)} dB)`]:t>=s.DELTA_WARNING?[1,`Noise floor ${t.toFixed(1)} dB above baseline`]:n>=s.SLOPE_WARNING?[1,`Noise floor rising ${n.toFixed(1)} dB/hour`]:a>=s.JITTER_WARNING?[1,`Noise floor variable (±${a.toFixed(1)} dB)`]:[0,null]}function gn(t){if(t.length===0)return{...Ke,computedAt:Math.floor(Date.now()/1e3)};const n=Math.floor(Date.now()/1e3),a=t.filter(v=>Number.isFinite(v)),s=t.length>0?[t[t.length-1]]:[],o=t.slice(-4).filter(v=>Number.isFinite(v)),i=De(a),d=xe(a,10),r=xe(a,90),c=De(s),u=c!==null&&d!==null?c-d:0,m=o.map((v,w)=>({timestamp:n-(o.length-1-w)*3600,value:v})),x=hn(m),l=fn(o),j=a.length>=12,[b,g]=j?pn(u,x,l):[0,null];return{baselineMedian:i,baselineP10:d,baselineP90:r,currentMedian:c,currentSampleCount:s.length,delta:u,slope:x,jitter:l,penalty:b,penaltyReason:g,computedAt:n,isReliable:j}}const yn={lbtStats:null,noiseFloor:null,sparklineNoiseFloor:[],noiseFloorWindowHistory:[],linkQuality:null,channelHealth:null,nfTrend:Ke,radioConfig:null,trends:null,stats:null,recentPackets:[],quickNeighbors:[],isLoading:!0,error:null,refresh:async()=>{}},Je=h.createContext(yn);function bn({children:t}){var p;const n=se(),a=te(),s=Ee(),o=Tt(),i=G(),d=L[i],r=Math.max(1,d.minutes/60),c=n===null,u=h.useMemo(()=>Mt(a,r),[a,r]),m=(n==null?void 0:n.noise_floor_dbm)??null,x=h.useMemo(()=>_t(m)?m:null,[m]),l=h.useMemo(()=>{var S;const M=(S=n==null?void 0:n.config)==null?void 0:S.radio;return M?{sf:M.spreading_factor??7,bwHz:M.bandwidth??125e3}:null},[(p=n==null?void 0:n.config)==null?void 0:p.radio]),j=Bt(r),b=St(r),g=n==null?void 0:n.neighbors,v=h.useMemo(()=>Object.fromEntries(Object.entries(g??{}).filter(([S])=>!o.has(S))),[g,o]),w=h.useMemo(()=>s.filter(M=>!o.has(M.hash)),[s,o]),C=h.useMemo(()=>gn(j),[j]),y=h.useMemo(()=>Dt(w,v,l),[w,v,l]),N=h.useMemo(()=>Rt(u,x,y),[u,x,y]),[k,D]=h.useState({noiseFloor:null,networkScore:null,channelHealth:null}),f=h.useRef(0);h.useEffect(()=>{const M=()=>{const R=Date.now();R-f.current>3e4&&(f.current=R,D({noiseFloor:x,networkScore:(y==null?void 0:y.networkScore)??null,channelHealth:(N==null?void 0:N.score)??null}))};M();const S=setInterval(M,5e3);return()=>clearInterval(S)},[x,y==null?void 0:y.networkScore,N==null?void 0:N.score]);const T=h.useMemo(()=>({noiseFloor:{current:x,previous:k.noiseFloor,trend:x!==null?oe(x,k.noiseFloor,2,!0):"stable"},networkScore:{current:(y==null?void 0:y.networkScore)??0,previous:k.networkScore,trend:oe((y==null?void 0:y.networkScore)??0,k.networkScore,3,!1)},channelHealth:{current:(N==null?void 0:N.score)??0,previous:k.channelHealth,trend:oe((N==null?void 0:N.score)??0,k.channelHealth,3,!1)}}),[x,y==null?void 0:y.networkScore,N==null?void 0:N.score,k]),B={lbtStats:u,noiseFloor:x,sparklineNoiseFloor:j,noiseFloorWindowHistory:b,linkQuality:y,channelHealth:N,nfTrend:C,radioConfig:l,trends:T,stats:n,recentPackets:a,quickNeighbors:s,isLoading:c,error:null,refresh:async()=>{}};return e.jsx(Je.Provider,{value:B,children:t})}function X(){const t=h.useContext(Je);if(t===void 0)throw new Error("useLBTData must be used within an LBTDataProvider");return t}function jn(t){return t<100?"excellent":t<250?"good":t<500?"fair":t<1e3?"congested":"critical"}function Nn(t){return t===0?"No backoffs":"Retries"}function vn(t,n){return t===0?void 0:`${n.toFixed(0)}%`}function wn(){const{lbtStats:t,isLoading:n,error:a}=X(),s=he(),o=(t==null?void 0:t.avgBackoffMs)??0,i=(t==null?void 0:t.retryRate)??0,d=t?jn(o):"unknown",r=t==null?void 0:t.sparklineBackoff,c=h.useMemo(()=>!r||r.length<2?[]:r.map((u,m)=>({timestamp:Date.now()-(r.length-1-m)*36e5,count:u})),[r]);return e.jsx(q,{title:"LBT Backoff",icon:e.jsx(Hs,{className:"mini-widget-icon"}),value:Math.round(o),unit:"ms",status:d,subtitle:t?Nn(o):void 0,subtitleValue:t?vn(o,i):void 0,isLoading:n,error:a,onClick:()=>s("/packets"),children:e.jsx("div",{className:"mini-widget-sparkline w-full",children:e.jsx(qe,{data:c,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}function me(t){return t===0?"—":t<1?"<1":Math.round(t).toString()}function kn(){const{lbtStats:t,isLoading:n,error:a}=X(),s=he(),o=(t==null?void 0:t.channelBusyCount)??0,i=(t==null?void 0:t.totalPacketsWithLBT)??0,d=(t==null?void 0:t.channelBusyRate)??0,r=(t==null?void 0:t.retryRate)??0,c=(t==null?void 0:t.avgBackoffMs)??0,u=(t==null?void 0:t.minBackoffMs)??0,m=(t==null?void 0:t.maxBackoffMs)??0,x=r>0?Math.max(0,(r-d)/r*100):100;return e.jsx(q,{title:"Ch. Busy",icon:e.jsx(es,{className:"mini-widget-icon"}),isLoading:n,error:a,onClick:()=>s("/packets"),children:e.jsx("div",{className:"mini-widget-body-grid",children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] widget-4col gap-x-2 gap-y-1 w-full min-w-0 items-baseline",children:[e.jsx("span",{className:"text-fg-muted text-[10px] sm:text-sm",title:`${o} packets exceeded max CAD attempts (5) out of ${i} total transmissions.`,children:"Failed"}),e.jsxs("div",{className:"data-box data-box-compact sm:data-box justify-self-end",title:`${o} packets exceeded max CAD attempts (5) out of ${i} total transmissions.`,children:[e.jsx(A,{children:o}),e.jsx("span",{className:"text-fg-muted punc-slash",children:"/"}),e.jsx(A,{children:i})]}),e.jsx("span",{className:"text-fg-muted text-[10px] sm:text-sm",title:`${x.toFixed(1)}% of packets that needed LBT retries were sent successfully.`,children:"Sent"}),e.jsx("div",{className:"data-box data-box-compact sm:data-box justify-self-end",title:`${x.toFixed(1)}% of packets that needed LBT retries were sent successfully.`,children:e.jsxs(A,{children:[x.toFixed(0),"%"]})}),e.jsx("span",{className:"text-fg-muted text-[10px] sm:text-sm",title:`Average LBT backoff delay: ${c.toFixed(0)}ms.`,children:"Mean"}),e.jsxs("div",{className:"data-box data-box-compact sm:data-box justify-self-end",title:`Average LBT backoff delay: ${c.toFixed(0)}ms.`,children:[e.jsx(A,{children:me(c)}),e.jsx("span",{className:"text-fg-muted text-xs",children:"ms"})]}),e.jsx("span",{className:"text-fg-muted text-[10px] sm:text-sm",title:`Backoff range: ${u.toFixed(0)}ms min, ${m.toFixed(0)}ms max.`,children:"Range"}),e.jsxs("div",{className:"data-box data-box-compact sm:data-box justify-self-end",title:`Backoff range: ${u.toFixed(0)}ms min, ${m.toFixed(0)}ms max.`,children:[e.jsx(A,{children:me(u)}),e.jsx("span",{className:"text-fg-muted punc-slash",children:"/"}),e.jsx(A,{children:me(m)})]})]})})})}function Cn(t){return t===null||t<-110?"excellent":t<-100?"good":t<-90?"fair":t<-80?"congested":"critical"}function Tn(t){return t===null?"No reading":t<-115?"Very quiet":t<-105?"Quiet":t<-95?"Moderate":t<-85?"Elevated":"High interference"}function Mn(){const{noiseFloor:t,noiseFloorWindowHistory:n,trends:a,isLoading:s,error:o}=X(),i=Cn(t),d=a==null?void 0:a.noiseFloor.trend,{timestamps:r,values:c}=h.useMemo(()=>!n||n.length<2?{timestamps:[],values:[]}:{timestamps:n.map(m=>m.timestamp),values:n.map(m=>m.noise_floor_dbm)},[n]),u=t!==null?Math.round(t):"—";return e.jsx(q,{title:"Noise Floor",icon:e.jsx(ks,{className:"mini-widget-icon"}),value:u,unit:t!==null?"dBm":void 0,status:i,trend:d,subtitle:Tn(t),isLoading:s,error:o,children:e.jsx("div",{className:"mini-widget-sparkline w-full",children:e.jsx(Pt,{timestamps:r,values:c,compact:!0,height:22})})})}const Ze=[{target:"LinkLeaders",fn:"path",minStage:1,when:Jt},{target:"LinkLeaders",fn:"src_hash",minStage:1,when:Zt}];O(Ze);function _n(){I(Ze);const t=he(),n=Ee(),a=te(),s=se(),o=G(),d=L[o].minutes*60,r=Ft(),c=h.useMemo(()=>{if(r===0)return a;const f=r-d;return a.filter(T=>T.timestamp>=f)},[a,d,r]),u=s===null,m=s!=null&&s.local_hash?ke(s.local_hash):"",x=(s==null?void 0:s.neighbors)??{},{neighborHashes:l,neighborNames:j}=h.useMemo(()=>{const f=new Set,T=new Map;for(const _ of n){f.add(_.hash);const B=x[_.hash],p=(B==null?void 0:B.name)||(B==null?void 0:B.node_name)||_.prefix;T.set(_.hash,p)}return{neighborHashes:f,neighborNames:T}},[n,x]),b=h.useMemo(()=>{if(l.size===0||c.length===0||!m)return{champion:null,listener:null,loudest:null};const{scores:f}=ds(c,l,m),T=[];for(const[M,S]of f)S.blendedScore!==0&&T.push({...S,name:j.get(M)??ke(M)});let _=null,B=null,p=null;for(const M of T)(!_||M.blendedScore>_.blendedScore)&&(_=M),(!B||M.listenerScore>B.listenerScore)&&(B=M),(!p||M.loudScore>p.loudScore)&&(p=M);return{champion:_,listener:B,loudest:p}},[c,l,m,j]),g=f=>e.jsxs("div",{className:"max-w-[220px]",children:[e.jsxs("div",{className:"font-semibold mb-1",children:["🏆 Champion: ",f.name]}),e.jsxs("div",{className:"text-fg-muted mb-1",children:["Blended Score: ",f.blendedScore,e.jsx("span",{className:"text-fg-muted/60 ml-1",children:"(Listener + Loud)"})]}),e.jsxs("div",{className:"border-t border-edge-subtle pt-1 mt-1 space-y-0.5",children:[e.jsxs("div",{children:["Listener: ",f.listenerScore,"/100 (",f.listenerCount," shared paths)"]}),e.jsxs("div",{children:["Loud: ",f.loudScore,"/100 (",f.loudCount," packets relayed)"]})]})]}),v=f=>e.jsxs("div",{className:"max-w-[220px]",children:[e.jsxs("div",{className:"font-semibold mb-1",children:["👂 Best Listener: ",f.name]}),e.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",f.listenerScore,"/100"]}),e.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:e.jsxs("div",{children:[f.listenerCount," packets where they heard your transmissions"]})})]}),w=f=>e.jsxs("div",{className:"max-w-[220px]",children:[e.jsxs("div",{className:"font-semibold mb-1",children:["📢 Loudest: ",f.name]}),e.jsxs("div",{className:"text-fg-muted mb-1",children:["Score: ",f.loudScore,"/100"]}),e.jsx("div",{className:"border-t border-edge-subtle pt-1 mt-1",children:e.jsxs("div",{children:[f.loudCount," packets they relayed directly to you"]})})]}),{champion:C,listener:y,loudest:N}=b,D=C||y||N?e.jsxs("div",{className:"flex flex-col gap-0 sm:gap-0.5",children:[C&&e.jsx(ie,{content:g(C),children:e.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:[e.jsx(is,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-map-neighbor-color flex-shrink-0"}),e.jsx("span",{className:"font-semibold text-map-neighbor-color font-mono truncate flex-1 min-w-0",children:C.name}),e.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:C.blendedScore})]})}),y&&e.jsx(ie,{content:v(y),children:e.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:[e.jsx(_s,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted font-mono truncate flex-1 min-w-0",children:y.name}),e.jsx("span",{className:"text-fg-muted pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right",children:y.listenerScore})]})}),N&&e.jsx(ie,{content:w(N),children:e.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:[e.jsx(Ss,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3 text-fg-muted flex-shrink-0"}),e.jsx("span",{className:"text-fg-muted font-mono truncate flex-1 min-w-0",children:N.name}),e.jsx("span",{className:"text-fg-muted pl-1 sm:pl-2 tabular-nums flex-shrink-0 w-7 sm:w-9 text-right",children:N.loudScore})]})})]}):n.length===0?e.jsx("div",{className:"flex items-center justify-center text-xs sm:text-sm text-fg-muted mt-auto",children:"No direct neighbors"}):e.jsx("div",{className:"flex items-center justify-center text-xs sm:text-sm text-fg-muted mt-auto",children:"No routing data yet"});return e.jsx(q,{title:"Link Leaders",icon:e.jsx(Fs,{className:"mini-widget-icon"}),isLoading:u,onClick:()=>t("/contacts"),children:D})}function Bn(t){const{retryRate:n,channelBusyCount:a,totalPacketsWithLBT:s,avgBackoffMs:o,maxBackoffMs:i}=t;if(s===0)return 0;const d=Math.min(s/10,1),r=.15,c=Math.log(1+n*r)/Math.log(1+100*r)*40,u=a/s*100,m=Math.min(u*.5,25);let x=0;o>100&&(x=Math.min(Math.log10(o/100)*8,15));let l=0;i>500&&o>0&&i>o*2&&(l=Math.min((i-500)/200,5));const b=(c+m+x+l)*d;return Math.min(b,85)}function Sn(t){return t<15?"excellent":t<30?"good":t<45?"fair":t<60?"congested":"critical"}function Dn(t){return t<15?"Clear channel":t<30?"Light traffic":t<45?"Moderate traffic":t<60?"Heavy traffic":t<75?"Congested":"Severe congestion"}function Rn(){const{lbtStats:t,isLoading:n,error:a}=X(),s=t?Bn(t):0,o=t?Sn(s):"unknown",i=(t==null?void 0:t.maxBackoffMs)??0,d=t?i>200?"Peak":Dn(s):void 0,r=t&&i>200?`${Math.round(i)}ms`:void 0,c=t==null?void 0:t.sparklineCollisionRisk,u=h.useMemo(()=>!c||c.length<2?[]:c.map((x,l)=>({timestamp:Date.now()-(c.length-1-l)*36e5,count:x})),[c]),m=Math.round(s*10)/10;return e.jsx(q,{title:"Collision Risk",icon:e.jsx(ms,{className:"mini-widget-icon"}),value:m,unit:"%",status:o,subtitle:d,subtitleValue:r,isLoading:n,error:a,children:e.jsx("div",{className:"mini-widget-sparkline w-full",children:e.jsx(qe,{data:u,width:9999,height:24,invertScale:!0,isLoading:n,className:"w-full"})})})}function Pn(t){return t<30?"excellent":t<50?"good":t<70?"fair":t<90?"congested":"critical"}function Fn(t){return t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${(t/6e4).toFixed(1)}m`}function Ln(){var g,v;const[t,n]=h.useState(!1),[a]=h.useState(0),{stats:s,lbtStats:o,isLoading:i}=X(),d=((v=(g=s==null?void 0:s.config)==null?void 0:g.duty_cycle)==null?void 0:v.enforcement_enabled)??!1,r=h.useMemo(()=>{if(!s)return null;if(!d){const k=s.airtime_used_ms??0,D=s.max_airtime_ms??1,f=D>0?k/D*100:0;return{usedMs:k,maxMs:D,remainingMs:Math.max(0,D-k),utilizationPercent:f}}const w=s.airtime_used_ms??0,C=s.max_airtime_ms??1,y=s.airtime_remaining_ms??0,N=s.utilization_percent??(C>0?w/C*100:0);return{usedMs:w,maxMs:C,remainingMs:y,utilizationPercent:N}},[s,d]),c=h.useMemo(()=>{if(!o||o.totalPacketsWithLBT===0)return 100;const w=o.totalPacketsWithLBT-o.packetsWithRetries,C=o.totalPacketsWithLBT;return w/C*100},[o]),u=(r==null?void 0:r.utilizationPercent)??0,m=Pn(u),x=(r==null?void 0:r.remainingMs)??0,l=c<95?"1st Try":"Remaining",j=c<95?`${c.toFixed(0)}%`:Fn(x),b=r?e.jsx("div",{className:"mini-widget-progress mt-auto",children:e.jsx("div",{className:`mini-widget-progress-bar ${m}`,style:{width:`${Math.min(u,100)}%`}})}):null;return e.jsx(q,{title:"Duty Cycle",icon:e.jsx(Ae,{className:"mini-widget-icon"}),value:u.toFixed(1),unit:"%",status:m,subtitle:l,subtitleValue:j,isLoading:i,children:b})}function An(){return e.jsxs("div",{className:"mini-widget",children:[e.jsxs("div",{className:"mini-widget-header",children:[e.jsx(Y,{className:"w-4 h-4"}),e.jsx(Y,{className:"h-3 w-16"})]}),e.jsx(Y,{className:"h-7 w-12 mt-2"}),e.jsx(Y,{className:"h-3 w-20 mt-2"})]})}function En(){return e.jsx("div",{className:"widget-row",children:Array.from({length:6}).map((t,n)=>e.jsx(An,{},n))})}const Qe=[{target:"MeshHealth",fn:"type",minStage:1}];O(Qe);function Hn({className:t="",isLoaded:n}){I(Qe);const a=He(),s=n??a??!0;return e.jsxs("div",{className:`mesh-health-container relative ${t}`,children:[e.jsxs("div",{className:"mesh-health-header",children:[e.jsx(Lt,{className:"w-4 h-4 text-sys-blue"}),e.jsx("span",{className:"type-label text-fg-muted",children:"MESH HEALTH"})]}),s?e.jsx(bn,{children:e.jsxs("div",{className:"widget-row",children:[e.jsx(wn,{}),e.jsx(Rn,{}),e.jsx(Mn,{}),e.jsx(Ln,{}),e.jsx(kn,{}),e.jsx(_n,{})]})}):e.jsx(En,{})]})}const et=[{target:"PublicChannel",fn:"decrypt",minStage:2,when:Qt}];O(et);let tt="",st="",Re="";function $n(){const t=new Date,n=t.toDateString();if(n!==Re){Re=n,tt=n;const a=new Date(t);a.setDate(a.getDate()-1),st=a.toDateString()}}function In(t){$n();const n=new Date(t*1e3).toDateString();return n===tt?"Today":n===st?"Yesterday":new Date(t*1e3).toLocaleDateString([],{weekday:"short",month:"short",day:"numeric"})}function On(t,n,a){return`${t||""}|${n}|${a}`}function zn(t,n){const a=t.message,s=n.message;return a.timestamp===s.timestamp&&a.text===s.text&&a.senderName===s.senderName&&a.channelHash===s.channelHash&&a.channelName===s.channelName&&t.isChannelSelected===n.isChannelSelected&&t.onChannelClick===n.onChannelClick}const qn=h.memo(function({message:n,onChannelClick:a,isChannelSelected:s}){const o=n.channelName||n.channelHash.slice(0,6);return e.jsx("div",{style:{transform:"translateZ(0)",willChange:"transform"},children:e.jsx(ps,{senderName:n.senderName||"Unknown",text:n.text,timestamp:n.timestamp,nameAccessory:e.jsx(Oe,{channelName:o,active:s,onClick:()=>a==null?void 0:a(n.channelHash)})})})},zn);function Wn({open:t,onClose:n,messages:a,onLoadMore:s,hasMoreToLoad:o,isDecoding:i,initialChannel:d}){const r=h.useRef(null),c=h.useRef(!0),u=G(),m=$e(),x=h.useRef(!1);h.useEffect(()=>{t?(x.current=!0,Te.resume()):x.current&&Te.pause()},[t]);const l=h.useMemo(()=>{const p=Date.now()/1e3,M=L[u].minutes,S=p-M*60;return[...a].filter(R=>R.timestamp>=S).sort((R,ne)=>R.timestamp-ne.timestamp)},[a,u]),j=h.useCallback(()=>{const p=r.current;p&&(c.current=p.scrollTop>=-50)},[]),b=h.useMemo(()=>{const p=new Map;for(const M of l){const S=M.channelHash,R=p.get(S);R?R.count++:p.set(S,{name:M.channelName||M.channelHash.slice(0,6),hash:M.channelHash,count:1})}return Array.from(p.values()).sort((M,S)=>S.count-M.count)},[l]),g=b.length,[v,w]=h.useState(null),[C,y]=h.useState(!1);h.useEffect(()=>{t&&d&&w(d)},[t,d]);const N=h.useCallback(()=>{s(v,b)},[s,v,b]),k=h.useMemo(()=>v?l.filter(p=>p.channelHash===v):l,[l,v]),D=h.useMemo(()=>{const p=[];let M="";for(const S of k){const R=In(S.timestamp);R!==M&&(p.push({type:"date",date:R}),M=R),p.push({type:"message",message:S})}return p},[k]);h.useLayoutEffect(()=>{const p=r.current;p&&c.current&&(p.scrollTop=0)},[k.length]);const f=19,T=b.slice(0,f),_=b.slice(f),B=_.length>0;return e.jsx(Ot,{open:t,onClose:n,size:"lg",motionPlus:!0,solid:!0,children:e.jsxs(zt,{className:"p-0 flex flex-col h-[80vh] max-h-[700px] rounded-2xl",children:[e.jsx("div",{className:"flex-shrink-0 px-4 sm:px-5 py-3 sm:py-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(We,{className:"size-5 text-icon-card-title flex-shrink-0"}),e.jsx("h2",{className:"type-micro",children:"Public Channels"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{ranges:L,selectedIndex:u,onSelect:m,size:"sm"}),e.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"}),e.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:e.jsx("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]})]})}),e.jsx("div",{className:"flex-shrink-0 px-3 pb-2 relative z-10 isolate",style:{minHeight:g>0?void 0:0},children:g>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsxs("button",{onClick:()=>w(null),className:F("px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",v===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 ",g]}),T.map(p=>e.jsx("button",{onClick:()=>w(p.hash),className:F("flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",v===p.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:e.jsx("span",{className:"truncate max-w-[80px]",children:p.name})},p.hash)),B&&e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>y(!C),className:F("flex items-center gap-0.5 px-2 py-0.5 rounded text-xs font-medium transition-all","ring-1 ring-inset",C||_.some(p=>p.hash===v)?"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:["+",_.length,e.jsx(qt,{className:F("size-3 transition-transform",C&&"rotate-180")})]}),C&&e.jsx("div",{className:F("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:_.map(p=>e.jsxs("button",{onClick:()=>{w(p.hash),y(!1)},className:F("w-full flex items-center gap-1.5 px-2 py-1 rounded text-xs font-medium transition-all text-left",v===p.hash?"bg-sys-blue/20 text-sys-blue":"text-fg-secondary hover:bg-subtle-fill-strong"),children:[e.jsx(gs,{className:"size-2.5 opacity-60 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:p.name}),e.jsxs("span",{className:"opacity-60 ml-auto",children:["(",p.count,")"]})]},p.hash))})]})]})}),e.jsx("div",{ref:r,onScroll:j,className:F("flex-1 overflow-y-auto overflow-x-hidden","mx-3 mb-3 rounded-md","bg-body","ring-1 ring-inset ring-edge-subtle","flex flex-col-reverse"),children:i&&k.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[300px] text-fg-muted px-4 py-4",children:[e.jsx(ee,{className:"size-12 mb-4 text-sys-indigo animate-spin"}),e.jsx("p",{className:"text-lg font-medium",children:"Loading messages..."})]}):k.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[300px] text-fg-muted px-4 py-4",children:[e.jsx(ys,{className:"size-16 mb-4 opacity-20"}),e.jsx("p",{className:"text-lg font-medium",children:"No messages yet"}),e.jsx("p",{className:"text-sm mt-1 opacity-70",children:v?"No messages in this channel":"Public channel messages will appear here"})]}):e.jsxs("div",{className:"px-4 py-4",children:[o&&e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("button",{onClick:N,disabled:i,className:F("px-4 py-1.5 rounded-full","text-[11px] font-medium","ring-1 ring-inset",i?"bg-subtle-fill text-fg-muted ring-edge-subtle cursor-wait":"bg-sys-blue/10 text-sys-blue ring-sys-blue/20 hover:bg-sys-blue/20 hover:ring-sys-blue/30"),children:i?e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ee,{className:"size-3 animate-spin"}),"Loading..."]}):"Load older messages"})}),D.map((p,M)=>{if(p.type==="date")return e.jsx("div",{className:"flex justify-center my-4",children:e.jsx("span",{className:F("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:p.date})},`date-${p.date}-${M}`);const S=`msg-${p.message.timestamp}-${p.message.senderName||"anon"}-${p.message.channelHash}`;return e.jsx("div",{className:"mb-3",children:e.jsx(qn,{message:p.message,onChannelClick:w,isChannelSelected:v===p.message.channelHash})},S)})]})}),e.jsx("div",{className:"flex-shrink-0 px-5 py-2 text-center",children:e.jsxs("p",{className:"text-[11px] text-fg-muted",children:[k.length," messages · ",g," ",g===1?"channel":"channels",i&&e.jsxs("span",{className:"ml-2 text-sys-indigo",children:[e.jsx(ee,{className:"inline size-3 animate-spin mr-1"}),"Decrypting..."]})]})})]})})}function Un(t){const n=[],a=new Set;for(const s of t.values()){const o=s.decoded;if(!o||!o.decrypted||o.macCorrupted||!o.text)continue;const i=On(o.senderName,o.channelHash,o.text);a.has(i)||(a.add(i),n.push({timestamp:s.timestamp,channelName:o.channelName,channelHash:o.channelHash,senderName:o.senderName,text:o.text,rssi:s.rssi,snr:s.snr}))}return n}function Vn({isLoaded:t}){const n=He(),a=t??n??!0;I(et);const s=te(),[o,i]=h.useState(!1),[d,r]=h.useState(null),c=G(),u=h.useCallback(()=>{r(null),i(!0),K.getState().queueDecryption(s)},[s]),m=ue(T=>T.requestedHash),x=ue(T=>T.clearRequest);h.useEffect(()=>{m&&(r(m),i(!0),K.getState().queueDecryption(s),x())},[m,x,s]);const l=At(),j=Et(),b=Ht(),g=h.useMemo(()=>Un(l),[l]),v=h.useMemo(()=>{const T=Date.now()/1e3,_=L[c].minutes,B=T-_*60;return g.filter(p=>p.timestamp>=B)},[g,c]),w=h.useMemo(()=>v.length===0?null:v.reduce((T,_)=>_.timestamp>T.timestamp?_:T),[v]),C=j.isDecoding,N=h.useMemo(()=>{const T=Date.now()/1e3,_=L[c].minutes,B=T-_*60,p=new Set;let M=0;for(const S of s)(S.type??S.payload_type)===Ce.GRP_TXT&&((S.timestamp??0)<B||p.has(S.packet_hash)||(p.add(S.packet_hash),M++));return M},[s,c]),k=$t(),D=h.useMemo(()=>{const T=Date.now()/1e3,_=L[c].minutes,B=T-_*60;for(const p of s)if((p.type??p.payload_type)===Ce.GRP_TXT&&!((p.timestamp??0)<B)&&!k.has(p.packet_hash))return!0;return!1},[s,k,c]),f=h.useCallback((T,_)=>{if(!C){if(T){const B=_.find(p=>p.hash===T);if(B){console.log(`[PublicChannelCard] Fast-path load for #${B.name}`),K.getState().queueChannelDecryption(s,B.name);return}}K.getState().queueDecryption(s)}},[s,C]);return a?e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:u,className:F("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:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-shrink-0",children:[e.jsx(We,{className:"size-4 text-icon-card-title flex-shrink-0"}),e.jsx("span",{className:"type-micro",children:"CHAT ACTIVITY"}),N>0&&e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-md bg-subtle-fill ring-1 ring-inset ring-edge-subtle text-sm tabular-nums text-fg-secondary",children:N}),e.jsx(Be,{className:"size-4 text-fg-muted group-hover:text-sys-indigo transition-colors ml-auto sm:hidden"})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-1.5 min-w-0 overflow-hidden",children:[e.jsx(Fe,{mode:"wait",initial:!1,children:w?e.jsxs(Q.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:[w.channelName&&e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(Oe,{channelName:w.channelName})}),e.jsx("div",{className:"hidden sm:flex w-[30px] h-[30px] rounded-full items-center justify-center flex-shrink-0 ring-1 ring-edge-subtle",style:{backgroundColor:xs(re(w.senderName||"").cleanName)},children:re(w.senderName||"").emoji?e.jsx("span",{className:"text-base",children:re(w.senderName||"").emoji}):e.jsx("span",{className:"text-white text-xs font-bold tracking-tighter",children:fs(w.senderName||"")})}),e.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:e.jsx("span",{className:"text-sm text-white truncate tracking-wide",children:hs(w.text)})}),e.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:It(w.timestamp)})]},`msg-${w.timestamp}-${w.senderName}-${w.channelHash}`):b?e.jsx(Q.span,{initial:{opacity:0},animate:{opacity:1},className:"text-sm text-fg-muted italic",children:"No messages yet"},"empty"):e.jsxs(Q.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,y:-16},transition:{duration:.15},className:"flex items-center gap-2 sm:gap-1.5",children:[e.jsx("div",{className:"hidden sm:block w-8 h-4 rounded bg-subtle-fill-strong animate-pulse"}),e.jsx("div",{className:"hidden sm:block w-[30px] h-[30px] rounded-full bg-subtle-fill-strong animate-pulse"}),e.jsx("div",{className:"h-8 w-32 sm:w-48 rounded-2xl bg-subtle-fill-strong animate-pulse"}),e.jsx("div",{className:"w-12 h-6 rounded-md bg-subtle-fill-strong animate-pulse"})]},"skeleton")}),e.jsx(Be,{className:"size-4 text-fg-muted group-hover:text-sys-indigo transition-colors flex-shrink-0 hidden sm:block ml-1"})]})]})}),e.jsx(Wn,{open:o,onClose:()=>i(!1),messages:g,onLoadMore:f,hasMoreToLoad:D,isDecoding:C,initialChannel:d})]}):e.jsx("div",{className:"h-14 rounded-xl bg-elevated/50 animate-pulse"})}function _a(){var b;const t=se(),n=Wt(),a=Ut(),s=Us(),o=h.useRef(!1);a&&!o.current&&(o.current=!0);const i=o.current,d=G(),r=$e(),c=Vt(),u=L[d]??L[4],m=c.isBackgroundLoading&&d>=5,x=h.useMemo(()=>{const g=T=>(T==null?void 0:T.reduce((_,B)=>_+B.count,0))??0,v=g(s==null?void 0:s.received),w=g(s==null?void 0:s.unique_received),C=g(s==null?void 0:s.forwarded),y=g(s==null?void 0:s.dropped),N=g(s==null?void 0:s.transmitted),k=((s==null?void 0:s.time_range_minutes)??u.minutes)/60,D=k>0?Math.round(v/k):0,f=k>0?Math.round(C/k):0;return{received:v,uniqueReceived:w,forwarded:C,dropped:y,transmitted:N,rxPerHour:D,fwdPerHour:f}},[s,u.minutes]),l=h.useMemo(()=>s?{totalBytes:s.totalReceivedBytes,kbPerHour:s.kbPerHour}:{totalBytes:0,kbPerHour:0},[s]),j=(t==null?void 0:t.node_name)??((b=t==null?void 0:t.config)==null?void 0:b.node_name)??"Unknown Node";return h.useEffect(()=>{j&&j!=="Unknown Node"&&(document.title=`pyMC: ${j}`)},[j]),n?e.jsxs(Me,{neomorphic:!0,className:"p-8 text-center",children:[e.jsx("p",{className:"type-subheading text-sys-red mb-2",children:"Failed to connect to backend"}),e.jsx("p",{className:"type-body text-fg-muted",children:n}),e.jsx("p",{className:"type-data-sm text-fg-muted mt-4",children:"Make sure the backend is running on port 8000"})]}):e.jsxs(Gt,{children:[e.jsx(Xt,{title:j,icon:e.jsx(bs,{}),subtitle:e.jsx(cs,{}),controls:e.jsx(ze,{ranges:L,selectedIndex:d,onSelect:r,isPending:m})}),e.jsxs(Yt,{ready:i,children:[e.jsx(Vn,{}),e.jsx(le,{template:"hero-auto",children:e.jsxs(Me,{neomorphic:!0,children:[e.jsx(Le,{icon:e.jsx(Ts,{}),title:"PACKETS RECEIVED",badge:u.label,badgeColor:"zinc",actions:i?e.jsxs("div",{className:"data-box",children:[l.kbPerHour," KB/hr"]}):e.jsx("div",{className:"data-box opacity-0",children:"0 KB/hr"})}),e.jsxs("div",{className:"flex flex-wrap gap-4 sm:gap-8",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"type-data-xl text-fg-primary",children:i?e.jsx(V,{value:x.received,className:"font-mono tabular-nums",priority:"high"}):e.jsx("span",{className:"opacity-30",children:"—"})}),e.jsx(U,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"Total Rx"})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("div",{className:"type-data-xl text-fg-primary",children:i?e.jsx(V,{value:x.uniqueReceived,className:"font-mono tabular-nums",priority:"high"}):e.jsx("span",{className:"opacity-30",children:"—"})}),e.jsx(U,{color:"zinc",className:"mb-0.5 sm:mb-1",children:"Unique"})]})]}),e.jsxs("div",{className:"mt-2 flex-1 min-h-0 relative",children:[e.jsx("div",{className:`absolute inset-0 flex items-end gap-1 transition-opacity duration-300 ${i?"opacity-0 pointer-events-none":"opacity-100"}`,"aria-hidden":i,children:[45,72,33,58,80,42,65,28,55,75,38,62].map((g,v)=>e.jsx("div",{className:"flex-1 bg-subtle-fill rounded-sm animate-pulse",style:{height:`${g}%`}},v))}),e.jsx("div",{className:`h-full transition-opacity duration-300 ${i?"opacity-100":"opacity-0"}`,children:e.jsx(Xs,{buckets:(s==null?void 0:s.receivedBytesBuckets)??[],activeTypes:(s==null?void 0:s.receivedActiveTypes)??[],totalByType:(s==null?void 0:s.receivedTotalByType)??{}})})]})]})}),e.jsxs(le,{template:"compact",children:[e.jsx(ce,{span:6,lg:4,children:e.jsx(Zs,{value:x.forwarded,receivedCount:x.received,buckets:(s==null?void 0:s.forwardedBytesBuckets)??[],activeTypes:(s==null?void 0:s.forwardedActiveTypes)??[],ratePerHour:(s==null?void 0:s.forwardedRatePerHour)??0,timeRangeLabel:u.label,icon:e.jsx(vs,{className:"w-4 h-4"})})}),e.jsx(ce,{span:6,lg:4,children:e.jsx(Qs,{value:x.dropped,receivedCount:x.received,buckets:(s==null?void 0:s.droppedBytesBuckets)??[],activeTypes:(s==null?void 0:s.droppedActiveTypes)??[],ratePerHour:(s==null?void 0:s.droppedRatePerHour)??0,timeRangeLabel:u.label,icon:e.jsx(js,{className:"w-4 h-4"})})}),e.jsx(ce,{span:12,lg:4,children:e.jsx(on,{stats:t,localHash:t==null?void 0:t.local_hash,receivedBuckets:s==null?void 0:s.received,droppedBuckets:s==null?void 0:s.dropped,forwardedBuckets:s==null?void 0:s.forwarded,bucketDurationSeconds:s==null?void 0:s.bucket_duration_seconds,timeRangeLabel:u.label})})]}),e.jsx(Hn,{}),e.jsx(ln,{}),t&&e.jsx(le,{template:"auto",children:e.jsx(us,{nodeName:j,repeaterVersion:t.version,coreVersion:t.core_version,localHash:t.local_hash,publicKey:t.public_key})})]})]})}export{_a as default};
