internal/dashboard/frontend/dist/assets/MapChart-C57JGIgp.js

import{d as we,u as be,a as Ie,w as _e,a8 as Pe,ae as Ae,a7 as Me,e as ee,k as P,i as s,g as te,A as Le,t as oe,f as d,j as S,q as $e,U as Ee,ad as Re,h as Te,K as je,B as ze,P as Be,O as p,ag as se,o as y,l as w,L as Ue}from"./index-BebFsTBB.js";import{u as Fe,I as Ne,C as Ve,S as ne,a as qe}from"./useChartStats-BWMLYU8s.js";import{P as j,j as Oe,k as We,h as He,n as Ke,o as Ge,m as Je,q as Qe,r as ae,s as Xe,u as Ye,v as Ze,e as De,w as et}from"./chart-BJS5fRTR.js";const tt={class:"flex items-center gap-2"},ot={class:"flex h-full flex-col-reverse gap-4 md:flex-row"},st={class:"chart-container"},rt=we({__name:"MapChart",props:{chartData:{},loading:{type:Boolean},connectionStatus:{}},setup(z){const A=z,u=be(),r=ze("chartContainer"),c=Ie(),B=p([]),b=p([]),U=p([]),M=p([]),F=p([]),v=p(1),m=p({lat:0,lon:0}),f=p(0);let L=null;const C=new Map;function N(a,t){if(!a||!t)return[-60,60];const l=t/a,g=Math.min(90,119*l);return[-g,g]}const le=se(()=>{const a=v.value,{lat:t,lon:l}=m.value;if(a>1.1){const g=90/a,x=180/a;u.state.lat_range=[(t-g).toString(),(t+g).toString()],u.state.lon_range=[(l-x).toString(),(l+x).toString()]}else u.state.lat_range=[],u.state.lon_range=[]},400);async function $(a=!1){if(!r.value)return;const t=A.chartData,l=!a&&t===L&&t.length>=f.value&&f.value>0;if(!a&&t===L&&t.length===f.value&&f.value>0)return;l||(C.clear(),f.value=0),(l?t.slice(f.value):t).forEach(e=>{if(e.latitude!==void 0&&e.longitude!==void 0){const n=`${e.latitude.toFixed(4)}_${e.longitude.toFixed(4)}`;C.has(n)||C.set(n,{lat:e.latitude,lon:e.longitude,count:0,ips:new Set,events:new Set,city:e.city||"",country:e.country||"",remoteAddrInts:[],remoteAddrs:[]});const o=C.get(n);o.count++,o.ips.add(e.remote_addr),e.event&&o.events.add(e.event),o.remoteAddrInts.push(e.remote_addr_int),o.remoteAddrs.push(e.remote_addr)}}),L=t,f.value=t.length;const x=[],G=[],J=[],E=[],R=[],Q=[],X=[],Y=[];C.forEach(e=>{x.push(e.lat),G.push(e.lon);const n=Oe+Math.log10(e.count+1)*We;E.push(n);const o=new Map;e.remoteAddrs.forEach(_=>o.set(_,(o.get(_)||0)+1));const i=Array.from(e.ips).sort((_,Se)=>(o.get(Se)||0)-(o.get(_)||0)),h=i.slice(0,5).join(", "),T=i.length>5?` (+${i.length-5} more)`:"",Ce=Array.from(e.events).sort().slice(0,3).join(", "),I=Be.get(e.country),xe=I?`${I[1]}`:e.country||"Unknown",ke=I?I[0]:"";J.push(`<b>${ke} ${e.city||"Unknown City"}, ${xe}</b><br>Events: ${e.count}<br>IPs: ${h}${T}<br>Types: ${Ce}`),R.push(n),Q.push(i),X.push(e.count),Y.push(e.country)});const me=[{type:c.mapType,mode:"markers",lat:x,lon:G,text:J,marker:{size:E,color:R,showscale:!1,line:{color:Ge,width:Ke}},hoverinfo:"text",hoverlabel:He}],Z=r.value.clientWidth,D=r.value.clientHeight,he=N(Z,D),ye={autosize:!0,width:Z,height:D,geo:{projection:{scale:v.value,type:"mercator"},center:m.value,showland:!0,showocean:!0,showcountries:!0,coastlinecolor:Ze,countrycolor:ae,landcolor:Ye,oceancolor:Xe,showsubunits:!0,subunitcolor:ae,bgcolor:"transparent",resolution:110,showframe:!1,lataxis:{range:he},lonaxis:{range:[-180,180]}},margin:Qe,paper_bgcolor:"transparent",plot_bgcolor:"transparent",map:{style:"dark"},modebar:Je},ve={responsive:!0,displaylogo:!1};await j.react(r.value,me,ye,ve),B.value=R,b.value=Q,U.value=E,M.value=X,F.value=Y;const k=r.value;k.removeAllListeners?.("plotly_click"),k.on("plotly_click",e=>{const n=e.points[0]?.pointIndex;if(n!==void 0){let o=b.value[n];Array.isArray(o)&&(o=o[0]),o&&O(o)}}),k.on("plotly_selected",e=>{if(e&&e.points){c.selectedIP=void 0,c.selectedPort=void 0;let n=0;const o=new Set;e.points.forEach(i=>{n+=M.value[i.pointIndex]||0;const h=b.value[i.pointIndex];h&&(Array.isArray(h)?h.forEach(T=>o.add(T)):o.add(h))}),c.selectedCount=n,c.selectedIPCount=o.size}else c.selectedCount=0,c.selectedIPCount=0}),k.removeAllListeners?.("plotly_relayout"),k.on("plotly_relayout",e=>{if(e["geo.autorange"]){u.state.lat_range=[],u.state.lon_range=[],v.value=1,m.value={lat:0,lon:0};return}let n=v.value;e["geo.projection.scale"]!==void 0?n=e["geo.projection.scale"]:e.geo?.projection?.scale!==void 0&&(n=e.geo.projection.scale);let o=m.value.lat,i=m.value.lon;e["geo.center.lat"]!==void 0&&(o=e["geo.center.lat"]),e["geo.center.lon"]!==void 0&&(i=e["geo.center.lon"]),e["geo.center"]!==void 0&&(e["geo.center"].lat!==void 0&&(o=e["geo.center"].lat),e["geo.center"].lon!==void 0&&(i=e["geo.center"].lon)),e.geo?.center!==void 0&&(e.geo.center.lat!==void 0&&(o=e.geo.center.lat),e.geo.center.lon!==void 0&&(i=e.geo.center.lon)),v.value=n,m.value={lat:o,lon:i},le()})}const{selectedIP:V,selectedCountry:q,selectedColor:re,highlightIP:O,highlightCountry:ce,resetSelection:ie}=Fe(r,B,b,void 0,U,M,F),ue=w(()=>u.state.x_range),de=w(()=>u.state.y_range),pe=w(()=>u.state.lat_range),ge=w(()=>u.state.lon_range),{ipCounts:W,countryCounts:H}=qe(w(()=>A.chartData),ue,de,pe,ge);_e(()=>A.chartData,()=>{$()},{deep:!0}),Pe(()=>{r.value&&j.purge(r.value)});const fe=se(()=>{if(r.value){const a=r.value;if(a.data?.length){const t=a.clientWidth,l=a.clientHeight,g=N(t,l);j.relayout(a,{width:t,height:l,"geo.lataxis.range":g})}else $(!0)}},100);Ae(r,fe);const K=p(!1);return Me(()=>{K.value=!0}),(a,t)=>(y(),ee(je,null,[K.value?(y(),P(Re,{key:0,to:"#chart-actions"},[s(V)||s(q)||s(c).selectedCount>0?(y(),ee("button",{key:0,type:"button",onClick:t[0]||(t[0]=l=>s(ie)()),class:"btn-secondary py-0.5 whitespace-nowrap"},[te(s(Ne),{class:"text-[10px]",color:s(re)},null,8,["color"]),Le(" "+oe(s(c).selectedCount)+" events ("+oe(s(c).selectedIPCount)+" IPs) ",1),t[3]||(t[3]=d("kbd",{class:"ml-1 text-[10px] opacity-50"},"ESC",-1))])):S("",!0),d("div",tt,[t[5]||(t[5]=d("label",{for:"map-type",class:"filter-label"},"Map Type:",-1)),$e(d("select",{id:"map-type","onUpdate:modelValue":t[1]||(t[1]=l=>s(c).mapType=l),class:"select",onChange:t[2]||(t[2]=l=>$(!0))},[...t[4]||(t[4]=[d("option",{value:"scattergeo"},"Simple",-1),d("option",{value:"scattermap"},"Carto Map",-1)])],544),[[Ee,s(c).mapType]])])])):S("",!0),d("div",ot,[te(Ve,null,{default:Te(()=>[s(W).length>0?(y(),P(ne,{key:0,open:"",title:"Top IPs",items:s(W),type:"ip","selected-item":s(V),onClick:s(O),onExclude:s(De)},null,8,["items","selected-item","onClick","onExclude"])):S("",!0),s(H).length>0?(y(),P(ne,{key:1,title:"Top Countries",items:s(H),type:"country","selected-item":s(q),onClick:s(ce),onExclude:s(et)},null,8,["items","selected-item","onClick","onExclude"])):S("",!0)]),_:1}),d("div",st,[z.loading?(y(),P(Ue,{key:0})):S("",!0),d("div",{ref_key:"chartContainer",ref:r,class:"h-full min-h-0 w-full touch-none overflow-hidden"},null,512)])])],64))}});export{rt as default};