import{u as z,I as j,C as q,S as b,a as F}from"./useChartStats-BWMLYU8s.js";import{u as K}from"./usePlotlyChart-zffLq8Zp.js";import{d as L,u as O,a as U,l as d,w as v,a7 as G,e as g,k as p,i as a,g as w,A as H,t as E,f as u,j as l,ad as J,h as Q,K as W,B as X,O as D,o as i}from"./index-BebFsTBB.js";import{e as Y,a as Z}from"./chart-BJS5fRTR.js";const tt={class:"flex h-full flex-col-reverse gap-4 md:flex-row"},et={class:"chart-container"},at={key:0,class:"loader"},it=L({__name:"PortChart",props:{chartData:{},loading:{type:Boolean},connectionStatus:{}},setup(m){const x=m,e=O(),o=U(),h=X("chartContainer"),f=D([]),{debouncedDrawPlot:R,allColors:B,allRemoteAddrs:y,allPorts:M}=K(h,d(()=>x.chartData),{onIPClick:t=>P(t),onSelected(t){if(t&&t.points){f.value=t.points,o.selectedIP=void 0,o.selectedPort=void 0,o.selectedCount=t.points.length;const s=new Set;t.points.forEach(r=>{const n=y.value[r.pointIndex];n&&(Array.isArray(n)?n.forEach(c=>c&&s.add(c)):s.add(n))}),o.selectedIPCount=s.size}else f.value=[],o.selectedCount=0,o.selectedIPCount=0},xRange:e.state.x_range,yRange:e.state.y_range,onRelayout:t=>{if(t["xaxis.range[0]"]&&t["xaxis.range[1]"]){const s=t["xaxis.range[0]"].toString(),r=t["xaxis.range[1]"].toString();e.state.x_range=[s,r],e.state.sync_time_with_chart&&(e.state.time_start=s,e.state.time_end=r)}if(t["yaxis.range[0]"]&&t["yaxis.range[1]"]){const s=t["yaxis.range[0]"],r=t["yaxis.range[1]"];if(e.state.y_range=[s.toString(),r.toString()],e.state.sync_ports_with_chart){const n=Math.max(Math.round(Number(s)),0),c=Math.min(Math.round(Number(r)),65535);e.state.dst_port=[`${n}-${c}`]}}(t["xaxis.autorange"]||t["yaxis.autorange"])&&(t["xaxis.autorange"]&&(e.state.x_range=[],e.state.sync_time_with_chart&&(e.state.time_start="",e.state.time_end="")),t["yaxis.autorange"]&&(e.state.y_range=[],e.state.sync_ports_with_chart&&(e.state.dst_port=[])))}}),{selectedIP:_,selectedPort:C,selectedColor:N,highlightIP:P,highlightPort:T,resetSelection:A}=z(h,B,y,M),V=d(()=>e.state.x_range),$=d(()=>e.state.y_range),{ipCounts:k,portCounts:S}=F(d(()=>x.chartData),V,$);v(()=>x.chartData,()=>{R()},{deep:!0});const I=D(!1);return G(()=>{I.value=!0}),(t,s)=>(i(),g(W,null,[I.value?(i(),p(J,{key:0,to:"#chart-actions"},[a(_)||a(C)||a(o).selectedCount>0?(i(),g("button",{key:0,type:"button",onClick:s[0]||(s[0]=r=>a(A)()),class:"border border-stone-700 bg-stone-800 px-2 py-1 text-xs text-nowrap text-stone-100 hover:bg-stone-700"},[w(a(j),{size:"16",color:a(N)},null,8,["color"]),H(" "+E(a(o).selectedCount)+" events ("+E(a(o).selectedIPCount)+" IPs) ",1),s[1]||(s[1]=u("kbd",{class:"ml-1 text-[10px] opacity-50"},"ESC",-1))])):l("",!0)])):l("",!0),u("div",tt,[w(q,null,{default:Q(()=>[a(k).length>0?(i(),p(b,{key:0,open:"",title:"Top IPs",items:a(k),type:"ip","label-key":"ip","selected-item":a(_),onClick:a(P),onExclude:a(Y)},null,8,["items","selected-item","onClick","onExclude"])):l("",!0),a(S).length>0?(i(),p(b,{key:1,title:"Top Ports",items:a(S),type:"port","label-key":"port","selected-item":a(C),onClick:a(T),onExclude:a(Z)},null,8,["items","selected-item","onClick","onExclude"])):l("",!0)]),_:1}),u("div",et,[m.loading?(i(),g("div",at)):l("",!0),u("div",{ref_key:"chartContainer",ref:h,class:"h-full min-h-0 w-full"},null,512)])])],64))}});export{it as default};