import{d as U,a6 as J,R as q,bY as G,r as d,j as n,bk as K,B as Y}from"./index-BOwCLZTK.js";import{c as Q}from"./node-types-C6okL8rE.js";import{M as V}from"./monitor-smartphone-Dd11JEL9.js";import{C as Z}from"./circle-question-mark-XDnZ1ChV.js";import{F as W}from"./funnel-CWx99rlN.js";import{S as ee}from"./search-Ba9CRHru.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 te=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],se=U("circle",te);/**
 * @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 ne=[["path",{d:"M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z",key:"1ptgy4"}],["path",{d:"M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97",key:"1sl1rz"}]],oe=U("droplets",ne);function xe(){return{timeStart:null,timeEnd:null,deviceTypes:new Set,nodeIds:new Set,disabledNodeIds:new Set,nodeFilterMode:"source"}}function re(c,l){const{timeStart:u,timeEnd:t,deviceTypes:o,nodeIds:x,disabledNodeIds:v,nodeFilterMode:w}=c,m=!0,N=o.size>0;let h;if(v.size>0){h=new Set;for(const j of x)v.has(j)||h.add(j)}else h=x;const S=h.size>0;let k=null;if(S){k=new Set;for(const j of h)k.add(J(j))}return{hasTime:m,hasDevice:N,hasNode:S,tStart:u??l.start,tEnd:t??l.end,deviceTypes:o,effectiveNodeIds:h,nodeIdPrefixes:k,nodeFilterMode:w,needsDisambiguation:N||S}}function ae(c,l,u){if(c.timestamp<l.tStart||c.timestamp>l.tEnd)return!1;if(l.needsDisambiguation){const t=u(c);if(l.hasDevice&&!l.deviceTypes.has(t.type))return!1;if(l.hasNode){if(l.nodeFilterMode==="observed"){let o=!1;if(t.hash&&l.effectiveNodeIds.has(t.hash)&&(o=!0),!o&&c.dst_hash&&(l.effectiveNodeIds.has(c.dst_hash)||l.nodeIdPrefixes.has(J(c.dst_hash)))&&(o=!0),!o){const x=c.forwarded_path??c.original_path;if(x&&Array.isArray(x))for(const v of x){const w=String(v).toUpperCase();if(l.nodeIdPrefixes.has(w)){o=!0;break}}}if(!o)return!1}else if(!t.hash||!l.effectiveNodeIds.has(t.hash))return!1}}return!0}function he(c,l,u,t){const o=re(l,t);return c.filter(x=>ae(x,o,u))}function X(c,l){const u=new Date(c*1e3),t=v=>v.toString().padStart(2,"0"),o=`${t(u.getHours())}:${t(u.getMinutes())}`;return l<24?o:`${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][u.getMonth()]} ${u.getDate()} ${o}`}const le=[{type:"repeater",label:"Repeater",icon:q,buttonColor:"primary",iconColor:"text-sys-blue",hoverClass:"hover:border-sys-blue hover:text-sys-blue hover:!bg-transparent"},{type:"companion",label:"Companion",icon:V,buttonColor:"indigo",iconColor:"text-sys-indigo",hoverClass:"hover:border-sys-indigo hover:text-sys-indigo hover:!bg-transparent"},{type:"room_server",label:"Room",icon:G,buttonColor:"purple",iconColor:"text-sys-purple",hoverClass:"hover:border-sys-purple hover:text-sys-purple hover:!bg-transparent"},{type:"unknown",label:"Unknown",icon:Z,buttonColor:"zinc",iconColor:"text-zinc-400",hoverClass:"hover:border-zinc-400 hover:text-zinc-400 hover:!bg-transparent"}],D=60,E=.005;function ie({min:c,max:l,valueStart:u,valueEnd:t,onChange:o}){const x=d.useRef(null),[v,w]=d.useState(null),m=d.useRef({valueStart:u,valueEnd:t,min:c,max:l});m.current={valueStart:u,valueEnd:t,min:c,max:l};const N=d.useRef({offset:0,width:0}),h=l-c||1,S=h/3600,k=u??c,j=t??l,C=(k-c)/h*100,F=(j-c)/h*100,_=u!==null||t!==null,I=d.useCallback(i=>{const a=x.current.getBoundingClientRect(),e=Math.max(0,Math.min(1,(i-a.left)/a.width)),{min:s,max:r}=m.current;return Math.round(s+e*(r-s||1))},[]),R=d.useCallback((i,a)=>{a.preventDefault(),a.stopPropagation();const e=a.currentTarget;e.setPointerCapture(a.pointerId),w(i);const s=f=>{const g=I(f.clientX),{valueStart:y,valueEnd:b,min:p,max:L}=m.current,z=L-p||1;if(i==="start"){const M=Math.min(g,(b??L)-D);o(M<=p+z*E?null:M,b)}else{const M=Math.max(g,(y??p)+D);o(y,M>=L-z*E?null:M)}},r=()=>{w(null),e.removeEventListener("pointermove",s),e.removeEventListener("pointerup",r),e.removeEventListener("pointercancel",r)};e.addEventListener("pointermove",s),e.addEventListener("pointerup",r),e.addEventListener("pointercancel",r)},[I,o]),$=d.useCallback(i=>{i.preventDefault(),i.stopPropagation();const a=i.currentTarget;a.setPointerCapture(i.pointerId),w("range");const e=m.current.valueStart??m.current.min,s=m.current.valueEnd??m.current.max;N.current={offset:I(i.clientX)-e,width:s-e};const r=g=>{const y=I(g.clientX),{min:b,max:p}=m.current,{offset:L,width:z}=N.current;let M=y-L;M=Math.max(b,Math.min(p-z,M));const O=M+z;o(Math.round(M)<=b?null:Math.round(M),Math.round(O)>=p?null:Math.round(O))},f=()=>{w(null),a.removeEventListener("pointermove",r),a.removeEventListener("pointerup",f),a.removeEventListener("pointercancel",f)};a.addEventListener("pointermove",r),a.addEventListener("pointerup",f),a.addEventListener("pointercancel",f)},[I,o]),H=d.useCallback(i=>{const a=I(i.clientX),{valueStart:e,valueEnd:s,min:r,max:f}=m.current,g=f-r||1,y=e??r,b=s??f;if(Math.abs(a-y)<=Math.abs(a-b)){const p=Math.min(a,b-D);o(p<=r+g*E?null:p,s)}else{const p=Math.max(a,y+D);o(e,p>=f-g*E?null:p)}},[I,o]),A=d.useCallback(()=>o(null,null),[o]),T=d.useCallback((i,a)=>{const e=a.key==="ArrowRight"||a.key==="ArrowUp"?1:a.key==="ArrowLeft"||a.key==="ArrowDown"?-1:0;if(!e)return;a.preventDefault();const s=(a.shiftKey?.1:.01)*h,{valueStart:r,valueEnd:f,min:g,max:y}=m.current,b=y-g||1;if(i==="start"){const p=Math.max(g,Math.min((r??g)+e*s,(f??y)-D));o(p<=g+b*E?null:p,f)}else{const p=Math.min(y,Math.max((f??y)+e*s,(r??g)+D));o(r,p>=y-b*E?null:p)}},[h,o]),P=i=>{const a=i==="start"?u!==null:t!==null,e=v===i;return["absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-1 h-4 rounded-full","before:content-[''] before:absolute before:-inset-x-3 before:-inset-y-1","touch-none outline-none",e?"cursor-grabbing":"cursor-ew-resize",e?"bg-sys-blue shadow-[0_0_8px_var(--sys-blue)] scale-x-150 z-20":a?"bg-sys-blue shadow-[0_0_4px_var(--sys-blue)] hover:shadow-[0_0_8px_var(--sys-blue)] hover:scale-x-150 z-10":"bg-edge-subtle hover:bg-fg-muted hover:scale-x-150 z-10",e?"":"transition-[transform,box-shadow,background-color] duration-150 ease-out","focus-visible:ring-2 focus-visible:ring-sys-blue/50"].filter(Boolean).join(" ")};return n.jsxs("div",{className:"flex flex-col gap-0.5 min-w-[160px] sm:min-w-[220px]",children:[n.jsxs("div",{className:"flex items-center justify-between type-data-xs text-fg-muted tabular-nums select-none",children:[n.jsx("span",{className:_&&u!==null?"text-sys-blue":"",children:X(k,S)}),n.jsx("span",{className:_&&t!==null?"text-sys-blue":"",children:X(j,S)})]}),n.jsxs("div",{ref:x,className:"relative h-5 select-none",onPointerDown:H,onDoubleClick:A,children:[n.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-1.5 rounded-full bg-white/[0.06] pointer-events-none"}),_?n.jsx("div",{className:["group/band absolute inset-y-0 touch-none",v==="range"?"cursor-grabbing":"cursor-grab"].join(" "),style:{left:`${C}%`,right:`${100-F}%`},onPointerDown:$,children:n.jsx("div",{className:["absolute inset-x-0 top-1/2 -translate-y-1/2 h-1.5 rounded-full pointer-events-none transition-colors",v==="range"?"bg-sys-blue/40":"bg-sys-blue/25 group-hover/band:bg-sys-blue/35"].join(" ")})}):n.jsx("div",{className:"absolute inset-x-0 top-1/2 -translate-y-1/2 h-1.5 rounded-full bg-white/[0.04] pointer-events-none"}),n.jsx("div",{role:"slider",tabIndex:0,"aria-label":"Range start","aria-valuenow":k,className:P("start"),style:{left:`${C}%`},onPointerDown:i=>R("start",i),onKeyDown:i=>T("start",i)}),n.jsx("div",{role:"slider",tabIndex:0,"aria-label":"Range end","aria-valuenow":j,className:P("end"),style:{left:`${F}%`},onPointerDown:i=>R("end",i),onKeyDown:i=>T("end",i)})]})]})}function fe({parentStartTs:c,parentEndTs:l,neighbors:u,filter:t,onChange:o,scatterDotSize:x,onScatterDotSizeChange:v,scatterOpacity:w,onScatterOpacityChange:m}){const[N,h]=d.useState(""),[S,k]=d.useState(!1),j=d.useRef(null);d.useEffect(()=>{function e(s){j.current&&!j.current.contains(s.target)&&k(!1)}if(S)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[S]);const C=d.useMemo(()=>Object.entries(u).map(([e,s])=>{const r=Q(s);return{hash:e,name:s.name??s.node_name??e.slice(0,8),type:r.type,label:r.label}}).sort((e,s)=>e.name.localeCompare(s.name)),[u]),F=d.useMemo(()=>{if(!N)return C;const e=N.toLowerCase();return C.filter(s=>s.name.toLowerCase().includes(e)||s.hash.toLowerCase().includes(e))},[C,N]),_=t.timeStart!==null||t.timeEnd!==null||t.deviceTypes.size>0||t.nodeIds.size>0,I=d.useCallback((e,s)=>{o({...t,timeStart:e,timeEnd:s})},[t,o]),R=d.useCallback(e=>{const s=new Set(t.deviceTypes);s.has(e)?s.delete(e):s.add(e),o({...t,deviceTypes:s})},[t,o]),$=d.useCallback(e=>{const s=new Set(t.nodeIds);s.has(e)?s.delete(e):s.add(e),o({...t,nodeIds:s}),h("")},[t,o]),H=d.useCallback(e=>{const s=new Set(t.nodeIds);s.delete(e);const r=new Set(t.disabledNodeIds);r.delete(e),o({...t,nodeIds:s,disabledNodeIds:r})},[t,o]),A=d.useCallback(e=>{const s=new Set(t.disabledNodeIds);s.has(e)?s.delete(e):s.add(e),o({...t,disabledNodeIds:s})},[t,o]),T=d.useCallback(()=>{o({...t,nodeFilterMode:t.nodeFilterMode==="source"?"observed":"source"})},[t,o]),P=d.useCallback(()=>{o({timeStart:null,timeEnd:null,deviceTypes:new Set,nodeIds:new Set,disabledNodeIds:new Set,nodeFilterMode:"source"}),h("")},[o]),i=d.useMemo(()=>{const e=new Map;for(const s of t.nodeIds){const r=u[s];e.set(s,(r==null?void 0:r.name)??(r==null?void 0:r.node_name)??s.slice(0,8))}return e},[t.nodeIds,u]),a=!!(v&&m);return n.jsxs("div",{className:"flex flex-col gap-2 card-padding",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[a&&n.jsxs(n.Fragment,{children:[n.jsx(B,{icon:n.jsx(se,{className:"w-3 h-3"}),label:"Size",value:x??.8,onChange:v,min:.3,max:3,step:.1,format:e=>e.toFixed(1)}),n.jsx(B,{icon:n.jsx(oe,{className:"w-3 h-3"}),label:"Opacity",value:w??50,onChange:m,min:5,max:100,step:5,format:e=>`${Math.round(e)}%`}),n.jsx("div",{className:"w-px h-4 bg-edge-subtle shrink-0 hidden sm:block"})]}),n.jsx("div",{className:"flex items-center gap-1.5 text-fg-muted shrink-0",children:n.jsx(W,{className:"w-3.5 h-3.5"})}),n.jsx("div",{className:"flex-1 min-w-[120px]",children:n.jsx(ie,{min:c,max:l,valueStart:t.timeStart,valueEnd:t.timeEnd,onChange:I})}),_&&n.jsxs("button",{type:"button",onClick:P,className:"flex items-center gap-1 px-2 py-0.5 rounded-full type-data-xs text-fg-muted hover:text-fg-primary border border-edge-subtle hover:border-fg-muted/40 transition-colors shrink-0",title:"Clear all filters",children:[n.jsx(K,{className:"w-3 h-3"}),n.jsx("span",{className:"hidden sm:inline",children:"Clear"})]})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-0.5 -mb-0.5 shrink-0",children:le.map(({type:e,label:s,icon:r,buttonColor:f,iconColor:g,hoverClass:y})=>{const b=t.deviceTypes.has(e);return n.jsxs(Y,{color:b?f:"zinc",outline:!b,className:`!h-8 !py-0 ${b?"":y}`,onClick:()=>R(e),title:`Filter by ${s}`,children:[n.jsx(r,{"data-slot":"icon",className:b?"":g}),n.jsx("span",{className:`hidden sm:inline ${b?"":"text-fg-muted"}`,children:s})]},e)})}),n.jsx("div",{className:"w-px h-4 bg-edge-subtle shrink-0 hidden md:block"}),n.jsxs("div",{className:"relative flex items-center gap-1.5 flex-1 min-w-[120px] sm:min-w-[180px] h-8 px-2 rounded-md border border-edge-subtle bg-white/[0.03] transition-colors focus-within:border-sys-blue",ref:j,children:[n.jsx(ee,{className:"w-3 h-3 text-fg-muted/50 shrink-0"}),n.jsx("input",{type:"text",className:"flex-1 min-w-[60px] type-data-xs py-0.5 bg-transparent text-fg-secondary placeholder:text-fg-muted/40 border-none focus:outline-none",placeholder:"Search nodes...",value:N,onChange:e=>{h(e.target.value),k(!0)},onFocus:()=>k(!0)}),S&&F.length>0&&n.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 z-[200] surface-popover border border-edge-subtle radius-inner max-h-48 overflow-y-auto",children:F.slice(0,20).map(e=>{const s=t.nodeIds.has(e.hash);return n.jsxs("button",{type:"button",onClick:()=>$(e.hash),className:`
                      w-full flex items-center gap-2 px-2.5 py-1.5 type-data-xs text-left transition-colors
                      ${s?"bg-sys-indigo/15 text-sys-indigo":"text-fg-secondary hover:bg-subtle-fill"}
                    `,children:[n.jsx("span",{className:"flex-1 truncate",children:e.name}),n.jsx("span",{className:"text-fg-muted type-data-xs shrink-0",children:e.label})]},e.hash)})})]})]}),t.nodeIds.size>0&&n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[Array.from(t.nodeIds).map(e=>{const s=t.disabledNodeIds.has(e);return n.jsxs("span",{role:"button",tabIndex:0,onClick:()=>A(e),onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),A(e))},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full type-data-xs border transition-colors select-none ${s?"bg-zinc-500/10 text-fg-muted border-edge-subtle cursor-pointer hover:bg-zinc-500/15":"bg-sys-indigo/15 text-sys-indigo border-sys-indigo/25 cursor-pointer hover:bg-sys-indigo/25"}`,title:e,children:[i.get(e)??e.slice(0,8),n.jsx("button",{type:"button",onClick:r=>{r.stopPropagation(),H(e)},className:"hover:text-fg-primary transition-colors -mr-0.5",title:"Remove from filter",children:n.jsx(K,{className:"w-3 h-3"})})]},e)}),n.jsx("button",{type:"button",onClick:T,className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full type-data-xs border transition-colors ${t.nodeFilterMode==="observed"?"bg-sys-blue/15 text-sys-blue border-sys-blue/25 hover:bg-sys-blue/25":"bg-white/[0.04] text-fg-muted border-edge-subtle hover:text-fg-secondary hover:border-fg-muted/40"}`,title:t.nodeFilterMode==="source"?"Source Only — showing packets sent by selected node(s)":"Total Observed — showing all packets where selected node(s) appear (source, path, or destination)",children:t.nodeFilterMode==="source"?"Source Only":"Total Observed"})]})]})}const B=d.memo(function({icon:l,label:u,value:t,onChange:o,min:x,max:v,step:w,format:m}){return n.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-fg-muted shrink-0",children:[l,n.jsx("span",{className:"type-data-xs font-medium hidden sm:inline",children:u})]}),n.jsx("input",{type:"range",min:x,max:v,step:w,value:t,onChange:N=>o(parseFloat(N.target.value)),className:"flex-1 h-1 min-w-[60px] bg-subtle-fill rounded appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-2.5 [&::-webkit-slider-thumb]:h-2.5 [&::-webkit-slider-thumb]:bg-sys-blue [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:cursor-pointer"}),n.jsx("span",{className:"type-data-xs text-fg-secondary tabular-nums shrink-0 w-8 text-right",children:m?m(t):t})]})});export{fe as A,le as D,he as a,ie as b,xe as c};
