import{e as U,c_ as J,ao as q,aa as G,cE as Q,cs as V,r as d,j as n,bM as K,B as Y}from"./index-BuFgUdF6.js";import{c as Z}from"./node-types-DgK-t_34.js";import{C as W}from"./circle-question-mark-NwPFAIxO.js";import{F as ee}from"./funnel-DqVoB6_M.js";import{S as te}from"./search-s6rZk7pl.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 se=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],ne=U("circle",se);/**
 * @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 oe=[["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"}]],re=U("droplets",oe);function xe(){return{timeStart:null,timeEnd:null,deviceTypes:new Set,nodeIds:new Set,disabledNodeIds:new Set,nodeFilterMode:"source"}}function ae(c,l){const{timeStart:u,timeEnd:t,deviceTypes:o,nodeIds:m,disabledNodeIds:v,nodeFilterMode:w}=c,p=!0,N=o.size>0;let h;if(v.size>0){h=new Set;for(const S of m)v.has(S)||h.add(S)}else h=m;const k=h.size>0;let M=null;return k&&(M=J(h)),{hasTime:p,hasDevice:N,hasNode:k,tStart:u??l.start,tEnd:t??l.end,deviceTypes:o,effectiveNodeIds:h,nodeIdPrefixes:M,nodeFilterMode:w,needsDisambiguation:N||k}}function le(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)if(l.effectiveNodeIds.has(c.dst_hash))o=!0;else{const m=q(c.dst_hash);l.nodeIdPrefixes.has(m)&&(o=!0)}if(!o){const m=c.forwarded_path??c.original_path;if(m&&Array.isArray(m))for(const v of m){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=ae(l,t);return c.filter(m=>le(m,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 ie=[{type:"repeater",label:"Repeater",icon:G,buttonColor:"primary",iconColor:"text-sys-blue",hoverClass:"hover:border-sys-blue hover:text-sys-blue hover:!bg-transparent"},{type:"companion",label:"Companion",icon:Q,buttonColor:"indigo",iconColor:"text-sys-indigo",hoverClass:"hover:border-sys-indigo hover:text-sys-indigo hover:!bg-transparent"},{type:"room_server",label:"Room",icon:V,buttonColor:"purple",iconColor:"text-sys-purple",hoverClass:"hover:border-sys-purple hover:text-sys-purple hover:!bg-transparent"},{type:"unknown",label:"Unknown",icon:W,buttonColor:"zinc",iconColor:"text-zinc-400",hoverClass:"hover:border-zinc-400 hover:text-zinc-400 hover:!bg-transparent"}],D=60,E=.005;function de({min:c,max:l,valueStart:u,valueEnd:t,onChange:o}){const m=d.useRef(null),[v,w]=d.useState(null),p=d.useRef({valueStart:u,valueEnd:t,min:c,max:l});p.current={valueStart:u,valueEnd:t,min:c,max:l};const N=d.useRef({offset:0,width:0}),h=l-c||1,k=h/3600,M=u??c,S=t??l,C=(M-c)/h*100,_=(S-c)/h*100,F=u!==null||t!==null,I=d.useCallback(i=>{const a=m.current.getBoundingClientRect(),e=Math.max(0,Math.min(1,(i-a.left)/a.width)),{min:s,max:r}=p.current;return Math.round(s+e*(r-s||1))},[]),P=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:x,min:b,max:L}=p.current,z=L-b||1;if(i==="start"){const j=Math.min(g,(x??L)-D);o(j<=b+z*E?null:j,x)}else{const j=Math.max(g,(y??b)+D);o(y,j>=L-z*E?null:j)}},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=p.current.valueStart??p.current.min,s=p.current.valueEnd??p.current.max;N.current={offset:I(i.clientX)-e,width:s-e};const r=g=>{const y=I(g.clientX),{min:x,max:b}=p.current,{offset:L,width:z}=N.current;let j=y-L;j=Math.max(x,Math.min(b-z,j));const O=j+z;o(Math.round(j)<=x?null:Math.round(j),Math.round(O)>=b?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}=p.current,g=f-r||1,y=e??r,x=s??f;if(Math.abs(a-y)<=Math.abs(a-x)){const b=Math.min(a,x-D);o(b<=r+g*E?null:b,s)}else{const b=Math.max(a,y+D);o(e,b>=f-g*E?null:b)}},[I,o]),A=d.useCallback(()=>o(null,null),[o]),R=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}=p.current,x=y-g||1;if(i==="start"){const b=Math.max(g,Math.min((r??g)+e*s,(f??y)-D));o(b<=g+x*E?null:b,f)}else{const b=Math.min(y,Math.max((f??y)+e*s,(r??g)+D));o(r,b>=y-x*E?null:b)}},[h,o]),T=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:F&&u!==null?"text-sys-blue":"",children:X(M,k)}),n.jsx("span",{className:F&&t!==null?"text-sys-blue":"",children:X(S,k)})]}),n.jsxs("div",{ref:m,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"}),F?n.jsx("div",{className:["group/band absolute inset-y-0 touch-none",v==="range"?"cursor-grabbing":"cursor-grab"].join(" "),style:{left:`${C}%`,right:`${100-_}%`},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":M,className:T("start"),style:{left:`${C}%`},onPointerDown:i=>P("start",i),onKeyDown:i=>R("start",i)}),n.jsx("div",{role:"slider",tabIndex:0,"aria-label":"Range end","aria-valuenow":S,className:T("end"),style:{left:`${_}%`},onPointerDown:i=>P("end",i),onKeyDown:i=>R("end",i)})]})]})}function fe({parentStartTs:c,parentEndTs:l,neighbors:u,filter:t,onChange:o,scatterDotSize:m,onScatterDotSizeChange:v,scatterOpacity:w,onScatterOpacityChange:p}){const[N,h]=d.useState(""),[k,M]=d.useState(!1),S=d.useRef(null);d.useEffect(()=>{function e(s){S.current&&!S.current.contains(s.target)&&M(!1)}if(k)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[k]);const C=d.useMemo(()=>Object.entries(u).map(([e,s])=>{const r=Z(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]),_=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]),F=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]),P=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]),R=d.useCallback(()=>{o({...t,nodeFilterMode:t.nodeFilterMode==="source"?"observed":"source"})},[t,o]),T=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&&p);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(ne,{className:"w-3 h-3"}),label:"Size",value:m??.8,onChange:v,min:.3,max:3,step:.1,format:e=>e.toFixed(1)}),n.jsx(B,{icon:n.jsx(re,{className:"w-3 h-3"}),label:"Opacity",value:w??50,onChange:p,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(ee,{className:"w-3.5 h-3.5"})}),n.jsx("div",{className:"flex-1 min-w-[120px]",children:n.jsx(de,{min:c,max:l,valueStart:t.timeStart,valueEnd:t.timeEnd,onChange:I})}),F&&n.jsxs("button",{type:"button",onClick:T,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:ie.map(({type:e,label:s,icon:r,buttonColor:f,iconColor:g,hoverClass:y})=>{const x=t.deviceTypes.has(e);return n.jsxs(Y,{color:x?f:"zinc",outline:!x,className:`!h-8 !py-0 ${x?"":y}`,onClick:()=>P(e),title:`Filter by ${s}`,children:[n.jsx(r,{"data-slot":"icon",className:x?"":g}),n.jsx("span",{className:`hidden sm:inline ${x?"":"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:S,children:[n.jsx(te,{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),M(!0)},onFocus:()=>M(!0)}),k&&_.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:_.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:R,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:m,max:v,step:w,format:p}){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:m,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:p?p(t):t})]})});export{fe as A,ie as D,he as a,de as b,xe as c};
