import{j as e}from"./index-DItyo5Xo.js";import{b as t}from"./recharts-bmHCCfxU.js";import{M as o,S as n,L as r,a as i,P as s}from"./maplibre-gl-B4OIi1RV.js";import"./maplibre-gl-CFO9X1Ek.js";const a="#4F46E5",l="#F9D26F",d="#B49DFF",c="#39D98A",u="#B49DFF";function p(e,t,o,n=!1,r=!1,i=!1){let s;s=r?c:i?u:e?a:t?"#6366F1":o?"transparent":l;const p=e||t||!o||r||i;return`<div style="\n    width: 14px;\n    height: 14px;\n    background: ${s};\n    border-radius: 50%;\n    border: ${p?0:5}px solid ${p?"transparent":"#4338CA"};\n    box-sizing: border-box;\n    transition: box-shadow 0.15s ease;\n    ${n?`box-shadow: 0 0 0 3px ${d}40, 0 0 8px ${d}60;`:""}\n  "></div>`}const m={id:"path-line",type:"line",paint:{"line-color":"#3B3F4A","line-width":2,"line-opacity":.7},layout:{"line-cap":"round","line-join":"round"}};function x({resolvedPath:d,localNode:x,hubNodes:h=[],hoveredHopIndex:f,onHoverHop:b}){const g=t.useRef(null),y=t.useMemo(()=>new Set(h),[h]),[j,k]=t.useState(null),{positions:v,markers:C,pathLineGeoJSON:N}=t.useMemo(()=>{const e=[],t=[],o=[];d.hops.forEach((n,r)=>{const i=n.candidates.filter(e=>{return t=e.latitude,o=e.longitude,0!==t||0!==o;var t,o});if(0===i.length)return;const s=[...i].sort((e,t)=>t.probability-e.probability)[0];o.push([s.longitude,s.latitude]);const a=!0===n.isSource,l=!0===n.isDestination;i.forEach((o,s)=>{const d=[o.latitude,o.longitude];e.push(d);const c=0===s;t.push({position:d,prefix:n.prefix,confidence:n.confidence,candidateCount:i.length,hopIndex:r,candidate:o,isHub:y.has(o.hash),isPrimary:c,isSource:a,isDestination:l})})});const n={type:"FeatureCollection",features:o.length>=2?[{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:o}}]:[]};return{positions:e,markers:t,pathLineGeoJSON:n}},[d,y]),{center:S,zoom:F}=t.useMemo(()=>{if(0===v.length)return x?{center:[x.longitude,x.latitude],zoom:10}:{center:[0,0],zoom:2};let e=1/0,t=-1/0,o=1/0,n=-1/0;for(const[c,u]of v)c<e&&(e=c),c>t&&(t=c),u<o&&(o=u),u>n&&(n=u);const r=(e+t)/2,i=(o+n)/2,s=t-e,a=n-o,l=Math.max(s,a);let d;return d=l<.01?15:l<.05?13:l<.1?12:l<.5?10:l<1?9:l<5?7:5,{center:[i,r],zoom:d}},[v,x]);t.useEffect(()=>{if(!g.current||v.length<2)return;let e=1/0,t=-1/0,o=1/0,n=-1/0;for(const[r,i]of v)r<e&&(e=r),r>t&&(t=r),i<o&&(o=i),i>n&&(n=i);g.current.fitBounds([[o,e],[n,t]],{padding:30,maxZoom:16,duration:0})},[v]);const L=t.useCallback(e=>{k({longitude:e.position[1],latitude:e.position[0],marker:e})},[]);return 0===v.length?e.jsx("div",{className:"h-[200px] flex items-center justify-center text-text-muted text-sm bg-bg-elevated",children:"No mappable path data"}):e.jsxs(o,{ref:g,initialViewState:{longitude:S[0],latitude:S[1],zoom:F},style:{height:"200px",width:"100%"},mapStyle:"https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",attributionControl:!1,children:[N.features.length>0&&e.jsx(n,{id:"path-line-source",type:"geojson",data:N,children:e.jsx(r,{...m})}),C.map(t=>{const o=f===t.hopIndex;return e.jsx(i,{longitude:t.position[1],latitude:t.position[0],anchor:"center",onClick:()=>L(t),children:e.jsx("div",{style:{cursor:"pointer",opacity:t.isPrimary?1:.5},onMouseEnter:()=>null==b?void 0:b(t.hopIndex),onMouseLeave:()=>null==b?void 0:b(null),dangerouslySetInnerHTML:{__html:p(t.candidate.isLocal||!1,t.isHub,t.isPrimary,o,t.isSource,t.isDestination)}})},`${t.hopIndex}-${t.candidate.hash}`)}),j&&e.jsx(s,{longitude:j.longitude,latitude:j.latitude,anchor:"bottom",offset:[0,-12],closeOnClick:!1,onClose:()=>k(null),className:"maplibre-popup",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-semibold",children:j.marker.candidate.name}),j.marker.isSource&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:c,color:"#000"},children:"SRC"}),j.marker.isDestination&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:u,color:"#000"},children:"DST"}),j.marker.isHub&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:"#FBBF24",color:"#000"},children:"HUB"}),j.marker.candidate.isLocal&&e.jsx("span",{className:"px-1 py-0.5 text-[8px] font-bold rounded",style:{backgroundColor:a,color:"#fff"},children:"LOCAL"})]}),e.jsxs("div",{className:"text-text-muted font-mono text-[10px]",children:[j.marker.prefix," • ",j.marker.candidate.hash.slice(0,10),"..."]}),!j.marker.isPrimary&&j.marker.candidateCount>1&&e.jsxs("div",{style:{color:l},children:["Alternative (",(100*j.marker.candidate.probability).toFixed(0),"%)"]}),j.marker.isPrimary&&j.marker.candidateCount>1&&e.jsxs("div",{className:"text-text-muted",children:[j.marker.candidateCount," candidates"]})]})})]})}export{x as default};
