const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ContactsMapMapLibre-DAxQZgO0.js","assets/index-CeMilrX4.js","assets/BasemapLayer-CNBmoufo.js","assets/consumer-registry-Hkh6Dv_i.js","assets/link-scoring-FRwcQ0ss.js","assets/ConfirmModal-BF449Kzb.js","assets/triangle-alert-DiFold9L.js","assets/max-0cG3bA4z.js","assets/download-ByVPtD5I.js","assets/database-D2sIhibw.js","assets/useMapViewStore-DgL-E_Uc.js","assets/index-BK59_Mkt.js","assets/refresh-cw-DqhcBXAw.js","assets/target-q6HPYno6.js","assets/funnel-D2SUJQ8o.js","assets/plus-D-z0bUE_.js","assets/easing-CFZ7-xae.js","assets/zap-09srAnh-.js","assets/trash-2-Bu7BoH4P.js","assets/wifi-off-Y-Y9dpWj.js","assets/wifi-DjxkOZ88.js","assets/badge-colors-DnsnMXHA.js","assets/chevron-right-D3QL4sfa.js","assets/node-types-C09ZlzBQ.js","assets/LightSparkline-D652BQd5.js","assets/map-pin-D6_BkIVb.js","assets/usePipelineStore-B80TA53S.js","assets/ping-DgsEwYAS.js","assets/PageLayout-Cw_MXmcE.js","assets/listbox-CGIGCOya.js","assets/element-movement-zLH7y51p.js","assets/MqttModeBadge-C_MEMmDd.js","assets/chat-utils-BJwCtjDV.js","assets/SignalIndicator-CpBGKD5A.js","assets/CollisionExplorerModal-Cvw_f8a6.js","assets/monitor-smartphone-DxkmIgui.js","assets/DataBox-Da-5DbUW.js","assets/circle-question-mark-Bqc_DPUo.js","assets/network-c_XxfhAX.js","assets/activity-BZFnO4kb.js","assets/search-Bph9xP9G.js","assets/index-CLjIU9sF.css","assets/BasemapLayer-B1CfjdFi.css","assets/ContactsMapMapLibre-BwWOEply.css"])))=>i.map(i=>d[i]);
import{d as P,a9 as ss,j as e,r as a,_ as ts,bV as Ee,bW as Fe,a6 as oe,D as ke,ah as Pe,bX as ns,bY as he,R as pe,x as k,bZ as as,L as Oe,b_ as rs,Q as os,b$ as cs,c0 as is,c1 as ls,P as ds,c2 as ms,c3 as xs,V as us,ai as ps,W as Ne,c4 as hs,c5 as fs,bf as re,v as gs,I as js,bk as bs,c as we}from"./index-CeMilrX4.js";import{useDiscoveredNodes as ys}from"./usePipelineStore-B80TA53S.js";import{p as Ns}from"./ping-DgsEwYAS.js";import{c as Ce}from"./node-types-C09ZlzBQ.js";import{P as vs,a as ws,B as ks}from"./PageLayout-Cw_MXmcE.js";import{L as Cs,a as ue}from"./listbox-CGIGCOya.js";import{T as Te,M as Ms}from"./MqttModeBadge-C_MEMmDd.js";import{u as Ss,e as _s,f as Rs,r as Ps}from"./consumer-registry-Hkh6Dv_i.js";import{e as Ts,g as Ls,a as $s}from"./chat-utils-BJwCtjDV.js";import{A as Es,b as Fs}from"./SignalIndicator-CpBGKD5A.js";import{C as Os,S as zs}from"./CollisionExplorerModal-Cvw_f8a6.js";import{E as Ds,T as Hs}from"./target-q6HPYno6.js";import{D as As}from"./DataBox-Da-5DbUW.js";import{a as X,C as Is}from"./badge-colors-DnsnMXHA.js";import{C as ze}from"./circle-question-mark-Bqc_DPUo.js";import{N as Bs}from"./network-c_XxfhAX.js";import{A as De}from"./activity-BZFnO4kb.js";import{T as Vs}from"./trash-2-Bu7BoH4P.js";import{C as qs}from"./ConfirmModal-BF449Kzb.js";import{M as Le}from"./monitor-smartphone-DxkmIgui.js";import{M as Us}from"./map-pin-D6_BkIVb.js";import{S as Ws}from"./search-Bph9xP9G.js";/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Gs=[["path",{d:"M17 7 7 17",key:"15tmo1"}],["path",{d:"M17 17H7V7",key:"1org7z"}]],Qs=P("arrow-down-left",Gs);/**
 * @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 Ys=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],Ks=P("arrow-up-down",Ys);/**
 * @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 Xs=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]],Zs=P("calendar",Xs);/**
 * @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 Js=[["path",{d:"M4 12V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2",key:"jrl274"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 16h2v6",key:"1bxocy"}],["path",{d:"M10 22h4",key:"ceow96"}],["rect",{x:"2",y:"16",width:"4",height:"6",rx:"2",key:"r45zd0"}]],et=P("file-digit",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 st=[["path",{d:"M2 5h20",key:"1fs1ex"}],["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M9 19h6",key:"456am0"}]],tt=P("list-filter",st);/**
 * @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 nt=[["path",{d:"M12.75 7.09a3 3 0 0 1 2.16 2.16",key:"1d4wjd"}],["path",{d:"M17.072 17.072c-1.634 2.17-3.527 3.912-4.471 4.727a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 1.432-4.568",key:"12yil7"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M8.475 2.818A8 8 0 0 1 20 10c0 1.183-.31 2.377-.81 3.533",key:"lhrkcz"}],["path",{d:"M9.13 9.13a3 3 0 0 0 3.74 3.74",key:"13wojd"}]],at=P("map-pin-off",nt);/**
 * @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 rt=[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m15 19-3 3-3-3",key:"11eu04"}],["path",{d:"m19 9 3 3-3 3",key:"1mg7y2"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m5 9-3 3 3 3",key:"j64kie"}],["path",{d:"m9 5 3-3 3 3",key:"l8vdw6"}]],ot=P("move",rt);/**
 * @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 ct=[["path",{d:"M4.9 16.1C1 12.2 1 5.8 4.9 1.9",key:"s0qx1y"}],["path",{d:"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5",key:"1idnkw"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}],["path",{d:"M16.2 4.8c2 2 2.26 5.11.8 7.47",key:"ojru2q"}],["path",{d:"M19.1 1.9a9.96 9.96 0 0 1 0 14.1",key:"rhi7fg"}],["path",{d:"M9.5 18h5",key:"mfy3pd"}],["path",{d:"m8 22 4-11 4 11",key:"25yftu"}]],it=P("radio-tower",ct);/**
 * @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 lt=[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]],He=P("ruler",lt);/**
 * @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 dt=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],mt=P("trending-down",dt);class xt extends a.Component{constructor(c){super(c),this.state={hasError:!1}}static getDerivedStateFromError(c){return{hasError:!0,error:c}}render(){var c;return this.state.hasError?e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"alert","aria-live":"assertive",children:e.jsxs("div",{className:"text-center text-fg-muted p-4",children:[e.jsx("p",{className:"text-lg mb-2",children:"Map failed to load"}),e.jsx("p",{className:"text-sm text-fg-muted",children:((c=this.state.error)==null?void 0:c.message)||"Unknown error"}),e.jsx("p",{className:"text-xs text-fg-muted mt-2",children:"Try refreshing the page or check your browser's WebGL support."})]})}):this.props.children}}const ut=a.lazy(()=>ts(()=>import("./ContactsMapMapLibre-DAxQZgO0.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]))),$e=()=>e.jsx("div",{className:"map-container-16-9 flex items-center justify-center rounded-2xl surface-base",role:"status","aria-live":"polite","aria-label":"Loading map",children:e.jsxs("div",{className:"text-fg-muted flex items-center gap-3",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-sys-blue border-t-transparent rounded-full animate-spin","aria-hidden":"true"}),e.jsx("span",{children:"Loading map..."})]})});function pt({neighbors:o,localNode:c,localHash:f,onRemoveNode:x,selectedNodeHash:g,onNodeSelected:v,highlightedEdgeKey:p,highlightedGhost:d}){return ss()===!1?e.jsx($e,{}):e.jsx(xt,{children:e.jsx(a.Suspense,{fallback:e.jsx($e,{}),children:e.jsx(ut,{neighbors:o,localNode:c,localHash:f,onRemoveNode:x,selectedNodeHash:g,onNodeSelected:v,highlightedEdgeKey:p,highlightedGhost:d})})})}function ht({hash:o,className:c="",size:f="sm",collisionInfo:x,isViterbiResolved:g}){const v=Ee(),p=Fe(),[d,T]=a.useState(!1),S=a.useMemo(()=>oe(o),[o]),L=a.useMemo(()=>x!==void 0?x:S?v.find(j=>j.prefix===S)??null:null,[S,v,x]),$=g??(p.totalPaths>0&&p.avgPathConfidence>=.7),O=a.useCallback(j=>{j.preventDefault(),j.stopPropagation(),T(!0)},[]),B=a.useCallback(()=>{T(!1)},[]);if(!L)return null;const w=f==="sm"?"w-3.5 h-3.5":"w-4 h-4",H=$?"text-sys-cyan hover:text-sys-cyan hover:bg-sys-cyan/10 focus:ring-sys-cyan/50":"text-signal-fair hover:text-sys-indigo hover:bg-signal-fair/10 focus:ring-signal-fair/50",_=$?`Prefix conflict resolved by Viterbi HMM (${(p.avgPathConfidence*100).toFixed(0)}% confidence)`:`Prefix conflict: ${L.candidateCount} nodes share prefix "${S}"`;return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:O,className:`inline-flex items-center justify-center p-0.5 rounded focus:outline-none focus:ring-2 transition-colors cursor-pointer touch-manipulation ${H} ${c}`,title:_,"aria-label":`View prefix conflict for ${S}${$?" (Viterbi resolved)":""}`,children:$?e.jsxs("span",{className:"relative",children:[e.jsx(Ds,{className:w}),e.jsx(ke,{className:"absolute -bottom-0.5 -right-0.5 w-2 h-2 text-sys-green"})]}):e.jsx(et,{className:w})}),e.jsx(Os,{isOpen:d,prefix:L.prefix,candidateHashes:L.candidateHashes,onClose:B})]})}const ft=a.memo(ht),Ae=[{target:"Contacts",fn:"name",minStage:1,when:_s},{target:"Contacts",fn:"traceLinks.directed",minStage:2,when:Rs}];Ps(Ae);function gt(o){return o<1e3?`${Math.round(o)}m`:`${(o/1e3).toFixed(1)}km`}function jt({hash:o,contact:c,isHub:f,isNeighbor:x,distance:g,centrality:v,sparklineData:p,neighborSignal:d,collisionInfo:T,isViterbiResolved:S,isPinging:L,isPingingThis:$,pingResult:O,pingError:B,gatewayInfo:w,lastForwarderPrefix:H,isMobile:_,pathStability:j,onRowClick:E,onPing:fe,onRemove:V}){Ss(Ae);const Z=c.latitude&&c.longitude&&c.latitude!==0&&c.longitude!==0,h=c.node_name||c.name||"Unknown",q=x&&d,z=Ce(c),{isRepeater:U,isCompanion:y,isRoomServer:W,isClient:J,label:ee}=z,ge=x?`${ee} — Direct RF contact (zero-hop neighbor)`:`${ee} — Flood routing (multi-hop via mesh)`,G=c.first_seen?Pe(c.first_seen).replace(/ ago$/i," old"):null;return e.jsxs("div",{className:`contacts-grid-row ${f?"bg-sys-amber/5 border-l-2 border-l-sys-amber":""} ${Z?"cursor-pointer hover:bg-subtle-fill":""}`,onClick:()=>E(o),children:[e.jsxs("div",{className:"contacts-col-node flex items-center gap-2 min-w-0",children:[q&&(d==null?void 0:d.avgSnr)!==null?e.jsx("div",{className:`w-2 h-2 rounded-full flex-shrink-0 self-center ${ns(d.avgSnr)}`}):e.jsx("div",{className:"w-2 flex-shrink-0"}),e.jsx("div",{className:"w-6 h-6 flex items-center justify-center flex-shrink-0",title:ge,children:(()=>{if(W&&U)return e.jsxs("div",{className:"relative w-5 h-5",children:[e.jsx(he,{className:"w-5 h-5 absolute inset-0 text-sys-pink"}),e.jsx(zs,{className:"w-2.5 h-2.5 absolute -bottom-0.5 -right-0.5 text-sys-teal"})]});if(W)return e.jsx(he,{className:"w-5 h-5 text-sys-pink"});if(U)return e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center ring-[1.5px] ring-sys-blue",children:e.jsx(pe,{className:"w-3.5 h-3.5 text-sys-blue"})});if((y||J)&&h!=="Unknown"){const{emoji:b,cleanName:D}=Ts(h);return e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center",style:{backgroundColor:Ls(D)},children:b?e.jsx("span",{className:"text-sm leading-none",children:b}):e.jsx("span",{className:"text-white text-[9px] font-bold tracking-tighter",children:$s(h)})})}return e.jsx("div",{className:"w-6 h-6 rounded-full flex items-center justify-center bg-zinc-500/20",children:e.jsx(ze,{className:"w-3.5 h-3.5 text-sys-amber"})})})()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 overflow-hidden",children:[e.jsx("span",{className:"roster-title truncate",title:h,children:h}),x&&e.jsx(k,{color:X.neighbor,compact:!0,className:"flex-shrink-0",children:"NBR"}),f&&e.jsxs(k,{color:X.hub,compact:!0,className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(Bs,{className:"w-3 h-3"}),"HUB"]}),U&&e.jsx(k,{color:X.repeater,compact:!0,className:"flex-shrink-0",children:"RPT"}),W&&e.jsx(k,{color:X.room,compact:!0,className:"flex-shrink-0",children:"ROOM"}),y&&e.jsx(k,{color:X.companion,compact:!0,className:"flex-shrink-0",children:"COMP"}),J&&e.jsx(k,{color:X.client,compact:!0,className:"flex-shrink-0",children:"CLIENT"}),_&&e.jsxs(k,{color:"cyan",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0",children:[e.jsx(ot,{className:"w-2.5 h-2.5"}),"MOBILE"]}),!Z&&e.jsx("span",{className:"flex items-center gap-0.5 flex-shrink-0 text-fg-muted/50",title:"No GPS location provided",children:e.jsx(at,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx(As,{copy:!0,size:"compact",truncate:[8,6],children:o}),e.jsx(ft,{hash:o,collisionInfo:T,isViterbiResolved:S}),!x&&w&&e.jsxs(k,{color:"zinc",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0",title:`Via ${w.name||w.prefix} (${w.hopCount} hop${w.hopCount!==1?"s":""})`,children:[e.jsx(Es,{className:"w-2.5 h-2.5"}),e.jsx("span",{className:"font-mono",children:w.prefix}),w.hopCount>1&&e.jsxs("span",{className:"opacity-60",children:["+",w.hopCount-1]})]}),H&&!x&&e.jsxs(k,{color:"zinc",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0",title:`Last forwarded by ${H}`,children:[e.jsx(Qs,{className:"w-2.5 h-2.5"}),e.jsx("span",{className:"font-mono",children:H})]}),j!=null&&j!==0&&e.jsx(k,{color:j>0?"green":"amber",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0",title:j>0?"Path stability improving":"Path stability declining",children:j>0?e.jsx(as,{className:"w-2.5 h-2.5"}):e.jsx(mt,{className:"w-2.5 h-2.5"})}),p.length>0&&(()=>{const b=p.reduce((je,se)=>je+se.count,0);if(b===0)return null;const D=b/24;return e.jsxs(k,{color:"zinc",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0",title:`${b} packets in last 24h (~${D.toFixed(1)}/hr)`,children:[e.jsx(it,{className:"w-2.5 h-2.5"}),e.jsxs("span",{children:[D<1?"<1":D.toFixed(0),"/hr"]})]})})(),G&&e.jsxs(k,{color:"zinc",compact:!0,className:"flex items-center gap-0.5 flex-shrink-0 opacity-70",title:`First discovered ${G}`,children:[e.jsx(Zs,{className:"w-2.5 h-2.5"}),e.jsx("span",{children:G})]})]})]})]}),e.jsxs("div",{className:"contacts-col-signal flex items-center justify-end gap-2",children:[q&&(d==null?void 0:d.avgRssi)!==null&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Fs,{rssi:d.avgRssi,className:"w-3.5 h-3.5"}),e.jsx("span",{className:"type-data-xs text-fg-muted",children:Math.round(d.avgRssi)})]}),q&&(d==null?void 0:d.avgSnr)!==null&&e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[d.avgSnr.toFixed(1)," dB"]})]}),e.jsx("div",{className:"contacts-col-distance flex items-center justify-end gap-1 text-fg-muted",children:g!=null&&e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"w-3 h-3"}),e.jsx("span",{className:"type-data-xs",children:gt(g)})]})}),e.jsx("div",{className:"contacts-col-centrality flex items-center justify-end gap-1",children:v>0&&e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"w-3 h-3 text-sys-indigo"}),e.jsxs("span",{className:"type-data-xs text-fg-muted",children:[(v*100).toFixed(0),"%"]})]})}),e.jsx("div",{className:"contacts-col-seen flex items-center justify-end",children:e.jsx("span",{className:"type-data-xs text-fg-primary whitespace-nowrap",children:c.last_seen?Pe(c.last_seen):"—"})}),e.jsxs("div",{className:"contacts-col-actions flex items-center justify-end gap-1",children:[x&&e.jsx(e.Fragment,{children:O?e.jsxs("div",{className:"flex items-center gap-1 text-sys-green",title:`RTT: ${O.rtt_ms.toFixed(0)}ms`,children:[e.jsx(ke,{className:"w-3.5 h-3.5"}),e.jsxs("span",{className:"type-data-xs hidden sm:inline",children:[O.snr_db.toFixed(1),"dB"]})]}):B?e.jsx("span",{className:"text-sys-red text-xs",title:B,children:"✗"}):e.jsx("button",{onClick:b=>fe(o,b),disabled:L,className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-blue hover:bg-sys-blue/10 transition-base disabled:opacity-50 disabled:cursor-not-allowed",title:"Ping neighbor for updated signal info",children:$?e.jsx(Oe,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4 animate-spin"}):e.jsx(Hs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})}),e.jsx("button",{onClick:b=>{b.stopPropagation(),V(o,h)},className:"p-1 sm:p-1.5 radius-inner text-fg-muted/50 hover:text-sys-red hover:bg-sys-red/10 transition-base",title:"Remove contact",children:e.jsx(Vs,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})]})]})}const bt=a.memo(jt),yt=6371e3,Nt=[],vt=[{field:"lastHeard",icon:Is,label:"Recent"},{field:"distance",icon:He,label:"Distance"},{field:"centrality",icon:De,label:"Centrality"}];function wt(o){switch(o){case"room_server":return"room";case"repeater":return"repeater";case"companion":return"companion";case"unknown":return"companion"}}function kt(o){const c=Ce(o);return wt(c.type)}function ve(o,c){const{color:f="primary",border:x=!1}=c??{};return we("flex items-center gap-1.5 px-2 py-1.5 text-sm radius-inner transition-base",o?f==="success"?"bg-sys-green/20 text-sys-green":"bg-sys-blue/20 text-sys-blue":"text-fg-muted hover:text-fg-secondary hover-bg",x&&(o?f==="success"?"border border-sys-green/30":"border border-sys-blue/30":"border border-transparent"))}function Ct(o,c,f,x){const g=(f-o)*Math.PI/180,v=(x-c)*Math.PI/180,p=Math.sin(g/2)*Math.sin(g/2)+Math.cos(o*Math.PI/180)*Math.cos(f*Math.PI/180)*Math.sin(v/2)*Math.sin(v/2),d=2*Math.atan2(Math.sqrt(p),Math.sqrt(1-p));return yt*d}function Mt(){const{stats:o}=rs(),c=os(),f=cs(),x=is(),g=ls(),v=ds(),p=ms(),d=xs(),T=us(),S=ps(),L=Ne[T],$=Ee(),O=Fe(),B=hs(),w=O.totalPaths>0&&O.avgPathConfidence>=.7,H=a.useMemo(()=>{const s=new Map;for(const t of $)s.set(t.prefix,t);return s},[$]),[_,j]=a.useState(null),[E,fe]=a.useState("lastHeard"),[V,Z]=a.useState("desc"),[h,q]=a.useState(""),[z,U]=a.useState(!1),[y,W]=a.useState(new Set),[J,ee]=a.useState(!1),[ge,G]=a.useState(null),[b,D]=a.useState(null),[je,se]=a.useState(new Map),[Ie,te]=a.useState(new Map),[C,Be]=a.useState(25),[Q,ce]=a.useState(25),be=a.useRef(null),ne=a.useMemo(()=>(o==null?void 0:o.neighbors)??{},[o==null?void 0:o.neighbors]),ye=ys(),ie=a.useMemo(()=>{if(ye.size===0)return ne;const s=new Set;for(const n of Object.keys(ne))s.add((n.startsWith("0x")?n.slice(2):n).toLowerCase());let t=null;for(const[n,r]of ye){const i=(n.startsWith("0x")?n.slice(2):n).toLowerCase();s.has(i)||(t||(t={...ne}),t[n]={last_seen:r.lastSeen,name:r.name??void 0,node_name:r.name??void 0,latitude:r.latitude,longitude:r.longitude,is_repeater:r.nodeType==="repeater",contact_type:r.nodeType==="repeater"?"Repeater":r.nodeType==="companion"?"Companion":r.nodeType==="room_server"?"Room Server":void 0})}return t??ne},[ne,ye]),A=a.useMemo(()=>{const t=Date.now()/1e3-L.minutes*60;return Object.fromEntries(Object.entries(ie).filter(([n,r])=>c.has(n)?!1:(r.last_seen??0)>=t))},[ie,c,L.minutes]),R=fs(),Y=o==null?void 0:o.local_hash,Ve=a.useMemo(()=>{const s=new Map;if(!Y||p.size===0)return s;for(const[t,n]of p)if(t.endsWith(`→${Y}`)&&n.hops.length>1){const r=t.split("→")[0],i=n.hops[n.hops.length-1];s.set(r,i)}return s},[p,Y]),le=a.useMemo(()=>{const s=new Map;if(!(R!=null&&R.latitude)||!(R!=null&&R.longitude))return s;for(const[t,n]of Object.entries(A))n.latitude&&n.longitude&&n.latitude!==0&&n.longitude!==0?s.set(t,Ct(R.latitude,R.longitude,n.latitude,n.longitude)):s.set(t,null);return s},[A,R]),{neighborHashSet:de,neighborSignalMap:qe}=a.useMemo(()=>{const s=new Set,t=new Map;for(const n of v)s.add(n.hash),t.set(n.hash,{avgRssi:n.avgRssi,avgSnr:n.avgSnr});return{neighborHashSet:s,neighborSignalMap:t}},[v]),Me=a.useMemo(()=>{const s=h.toLowerCase().trim(),t=s==="neighbor"||s==="neighbors",n=z||t,r=y.size>0;return Object.fromEntries(Object.entries(A).filter(([i,l])=>{if(r){const M=kt(l);if(!y.has(M))return!1}if(n&&!de.has(i))return!1;if(t||!s)return!0;const I=(l.node_name||l.name||"").toLowerCase(),N=oe(i).toLowerCase();return I.includes(s)||N.includes(s)||i.toLowerCase().includes(s)}))},[A,h,z,de,y]),u=a.useMemo(()=>{const s=Object.entries(Me),t=h.toLowerCase().trim(),n=t.length===2&&/^[0-9a-f]{2}$/i.test(t);return s.sort(([r,i],[l,I])=>{if(n){const M=oe(r).toLowerCase(),F=oe(l).toLowerCase(),ae=M===t,me=F===t;if(ae&&!me)return-1;if(me&&!ae)return 1}let N=0;switch(E){case"lastHeard":N=(i.last_seen||0)-(I.last_seen||0);break;case"distance":{const M=le.get(r)??null,F=le.get(l)??null;M===null&&F===null?N=0:M===null?N=1:F===null?N=-1:N=M-F;break}case"centrality":{const M=g.get(r)||0,F=g.get(l)||0;N=M-F;break}}return V==="desc"?-N:N})},[Me,E,V,le,g,h]),m=a.useMemo(()=>{let s=0,t=0,n=0,r=0,i=0;for(const[,l]of u){const I=Ce(l),N=l.latitude&&l.longitude&&l.latitude!==0&&l.longitude!==0;switch(I.type){case"room_server":n++;break;case"repeater":t++;break;case"companion":s++;break;case"unknown":i++;break}N&&r++}return{companions:s,repeaters:t,roomServers:n,total:u.length,withLocation:r,unknown:i}},[u]),Ue=a.useMemo(()=>new Set(x),[x]),Se=a.useMemo(()=>C===0?u:u.slice(0,Q),[u,Q,C]);a.useEffect(()=>{ce(C||u.length)},[E,V,h,z,y,C,u.length]),a.useEffect(()=>{const s=t=>{t.target.closest("[data-dropdown]")||ee(!1)};return document.addEventListener("click",s),()=>document.removeEventListener("click",s)},[]),a.useEffect(()=>{if(C===0)return;const s=new IntersectionObserver(t=>{t[0].isIntersecting&&Q<u.length&&ce(n=>Math.min(n+C,u.length))},{threshold:.1,rootMargin:"100px"});return be.current&&s.observe(be.current),()=>s.disconnect()},[C,Q,u.length]);const We=a.useCallback(s=>{Be(s),ce(s||u.length)},[u.length]),Ge=a.useCallback(s=>{E===s?Z(t=>t==="desc"?"asc":"desc"):(fe(s),Z("desc"))},[E]),Qe=a.useCallback(s=>{const t=A[s];t!=null&&t.latitude&&(t!=null&&t.longitude)&&t.latitude!==0&&t.longitude!==0&&G(s)},[A]),Ye=a.useCallback(()=>{G(null)},[]),Ke=a.useCallback((s,t)=>{j({hash:s,name:t})},[]),Xe=a.useCallback(async(s,t)=>{if(t.stopPropagation(),!b){D(s),se(n=>{const r=new Map(n);return r.delete(s),r}),te(n=>{const r=new Map(n);return r.delete(s),r});try{const n=s.startsWith("0x")?s.slice(0,4):`0x${s.slice(0,2)}`,r=await Ns(n,30);r.success&&r.data?(se(i=>new Map(i).set(s,r.data)),setTimeout(()=>{se(i=>{const l=new Map(i);return l.delete(s),l})},1e4)):(te(i=>new Map(i).set(s,r.error||"Ping failed")),setTimeout(()=>{te(i=>{const l=new Map(i);return l.delete(s),l})},5e3))}catch(n){const r=n instanceof Error?n.message:"Ping failed";te(i=>new Map(i).set(s,r)),setTimeout(()=>{te(i=>{const l=new Map(i);return l.delete(s),l})},5e3)}finally{D(null)}}},[b]);return e.jsxs(vs,{children:[e.jsx(ws,{title:"Contacts",icon:e.jsx(re,{}),subtitle:e.jsx(Ms,{}),controls:e.jsxs("div",{className:"flex items-center gap-3 sm:gap-5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Total:"}),e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:`${m.total} discovered node${m.total!==1?"s":""} on the mesh network`,children:[e.jsx(re,{className:"w-3.5 h-3.5 text-fg-secondary"}),e.jsx("span",{children:m.total})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Types:"}),m.repeaters>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Repeaters",children:[e.jsx(pe,{className:"w-3.5 h-3.5 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Companions",children:[e.jsx(Le,{className:"w-3.5 h-3.5 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Room Servers",children:[e.jsx(he,{className:"w-3.5 h-3.5 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),m.withLocation>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"With GPS location",children:[e.jsx(Us,{className:"w-3.5 h-3.5 text-sys-green"}),e.jsx("span",{children:m.withLocation})]}),m.unknown>0&&e.jsxs("span",{className:"data-box flex items-center gap-1.5 cursor-default",title:"Unknown type",children:[e.jsx(ze,{className:"w-3.5 h-3.5 text-sys-amber"}),e.jsx("span",{children:m.unknown})]})]})]}),e.jsxs("div",{className:"flex sm:hidden items-center gap-1.5",children:[e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(re,{className:"w-3 h-3 text-fg-secondary"}),e.jsx("span",{children:m.total})]}),m.repeaters>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(pe,{className:"w-3 h-3 text-sys-blue"}),e.jsx("span",{children:m.repeaters})]}),m.companions>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(Le,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{children:m.companions})]}),m.roomServers>0&&e.jsxs("span",{className:"data-box !px-1.5 !py-0.5 !text-[10px] flex items-center gap-1",children:[e.jsx(he,{className:"w-3 h-3 text-sys-pink"}),e.jsx("span",{children:m.roomServers})]}),e.jsx(Te,{ranges:Ne,selectedIndex:T,onSelect:S,size:"sm"})]}),e.jsx("div",{className:"hidden sm:block",children:e.jsx(Te,{ranges:Ne,selectedIndex:T,onSelect:S})})]})}),e.jsxs(ks,{children:[e.jsx(pt,{neighbors:A,localNode:R??void 0,localHash:Y,onRemoveNode:f,selectedNodeHash:ge,onNodeSelected:Ye}),e.jsxs(gs,{noPadding:!0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-3 sm:px-4 py-2.5 border-b border-edge-subtle",children:[e.jsx("span",{className:"icon-md flex items-center justify-center text-icon-card-title flex-shrink-0",children:e.jsx(re,{})}),e.jsx("span",{className:"type-micro flex-shrink-0 mr-auto hidden sm:block",children:"Discovered Contacts"}),e.jsx(js,{type:"search",size:"sm",value:h,onChange:s=>q(s.target.value),placeholder:"Search...",leadingIcon:e.jsx(Ws,{className:"w-3.5 h-3.5"}),trailingIcon:h?e.jsx("button",{onClick:()=>{q(""),(h.toLowerCase().trim()==="neighbor"||h.toLowerCase().trim()==="neighbors")&&U(!1)},className:"text-fg-muted hover:text-fg-secondary",children:e.jsx(bs,{className:"w-3 h-3"})}):void 0,className:"w-24 sm:w-32 xl:w-44","aria-label":"Search contacts"}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("div",{className:"relative","data-dropdown":!0,children:[e.jsxs("button",{onClick:()=>ee(!J),className:ve(y.size>0,{border:!0}),title:"Filter by contact type",children:[e.jsx(tt,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Filter"}),y.size>0&&e.jsx("span",{className:"tabular-nums text-xs bg-sys-blue/30 px-1 rounded",children:y.size})]}),J&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 surface-elevated radius-inner py-1 min-w-[140px]",children:[[{key:"repeater",label:"Repeaters"},{key:"companion",label:"Companions"},{key:"room",label:"Rooms"}].map(({key:s,label:t})=>e.jsxs("button",{onClick:()=>{W(n=>{const r=new Set(n);return r.has(s)?r.delete(s):r.add(s),r})},className:"w-full px-3 py-1.5 text-sm text-left hover-bg transition-base flex items-center gap-2",children:[e.jsx("span",{className:we("w-4 h-4 flex items-center justify-center radius-badge border",y.has(s)?"bg-sys-blue border-sys-blue text-white":"border-edge-subtle"),children:y.has(s)&&e.jsx(ke,{className:"w-3 h-3"})}),e.jsx("span",{className:y.has(s)?"text-fg-primary":"text-fg-secondary",children:t})]},s)),y.size>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-edge-subtle my-1"}),e.jsx("button",{onClick:()=>W(new Set),className:"w-full px-3 py-1.5 text-sm text-left text-fg-muted hover:text-fg-secondary hover-bg transition-base",children:"Clear filters"})]})]})]}),de.size>0&&e.jsxs("button",{onClick:()=>U(!z),className:ve(z,{color:"success",border:!0}),title:z?"Show all contacts":"Show only MeshCore neighbors (direct RF contact)",children:[e.jsx(pe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:"Neighbors"})]})]}),e.jsx("div",{className:"h-4 w-px bg-border-subtle flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[vt.map(({field:s,icon:t,label:n})=>e.jsxs("button",{onClick:()=>Ge(s),className:ve(E===s),title:`Sort by ${n.toLowerCase()}`,children:[e.jsx(t,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden xl:inline",children:n}),E===s&&e.jsx(Ks,{className:we("w-3 h-3",V==="asc"&&"rotate-180")})]},s)),e.jsx("div",{className:"h-4 w-px bg-border-subtle"}),e.jsxs(Cs,{value:C,onChange:We,className:"w-auto min-w-[50px] [&_button]:py-1 [&_button]:px-2 [&_button]:text-xs [&_button]:min-h-0","aria-label":"Items per page",children:[e.jsx(ue,{value:25,children:"25"}),e.jsx(ue,{value:50,children:"50"}),e.jsx(ue,{value:100,children:"100"}),e.jsx(ue,{value:0,children:"All"})]})]})]}),u.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"hidden sm:grid contacts-grid-header border-b border-edge-subtle/50 px-3 py-2 type-micro text-fg-muted",children:[e.jsx("div",{className:"contacts-col-node",children:"Node"}),e.jsx("div",{className:"contacts-col-signal text-right",children:"Signal"}),e.jsx("div",{className:"contacts-col-distance text-right",children:"Distance"}),e.jsx("div",{className:"contacts-col-centrality text-right",children:"Centrality"}),e.jsx("div",{className:"contacts-col-seen text-right",children:"Last Seen"}),e.jsx("div",{className:"contacts-col-actions"})]}),e.jsx("div",{className:"divide-y divide-edge-subtle/30",children:Se.map(([s,t])=>{const n=oe(s),r=Ue.has(s),i=de.has(s),l=le.get(s)??null,I=g.get(s)||0,N=i?qe.get(s):void 0,M=n?H.get(n)??null:null,F=B.get(s)??Nt;let ae=null;if(!i&&Y&&p.size>0){const Je=`${s}→${Y}`,xe=p.get(Je);if(xe&&xe.hops.length>0){const _e=xe.hops[0],Re=Object.keys(ie).find(es=>es.toUpperCase().startsWith(_e.toUpperCase())),K=Re?ie[Re]:null;ae={prefix:_e,name:(K==null?void 0:K.node_name)??(K==null?void 0:K.name)??null,hopCount:xe.hopCount}}}const me=d.has(s),Ze=Ve.get(s)??null;return e.jsx(bt,{hash:s,contact:t,isHub:r,isNeighbor:i,distance:l,centrality:I,sparklineData:F,neighborSignal:N,collisionInfo:M,isViterbiResolved:w,isPinging:b!==null,isPingingThis:b===s,pingResult:je.get(s),pingError:Ie.get(s),gatewayInfo:ae,lastForwarderPrefix:Ze,isMobile:me,onRowClick:Qe,onPing:Xe,onRemove:Ke},s)})}),C>0&&Q<u.length&&e.jsxs("div",{ref:be,className:"flex items-center justify-center py-4 text-fg-muted",children:[e.jsx(Oe,{className:"w-4 h-4 animate-spin mr-2"}),e.jsx("span",{className:"text-xs",children:"Loading more..."})]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-edge-subtle/50 text-xs text-fg-muted",children:[e.jsxs("span",{className:"tabular-nums",children:["Showing ",Se.length," of ",u.length]}),C>0&&Q<u.length&&e.jsx("button",{onClick:()=>ce(s=>Math.min(s+C,u.length)),className:"text-sys-blue hover:text-sys-blue/80 transition-base",children:"Load more"})]})]}):e.jsxs("div",{className:"roster-empty",children:[e.jsx(re,{className:"roster-empty-icon"}),e.jsx("div",{className:"type-label text-fg-secondary",children:"No Contacts Discovered"}),e.jsx("div",{className:"type-data-xs text-fg-muted mt-1",children:"Contacts will appear here as they advertise on the mesh network."})]})]})]}),e.jsx(qs,{isOpen:!!_,title:"Remove Contact",message:`Are you sure you would like to remove ${(_==null?void 0:_.name)||"this contact"}?`,confirmLabel:"Remove",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{_&&f(_.hash),j(null)},onCancel:()=>j(null)})]})}const Yt=Object.freeze(Object.defineProperty({__proto__:null,default:Mt},Symbol.toStringTag,{value:"Module"}));export{Yt as C,ft as P,He as R,mt as T};
