import{a as t}from"./rolldown-runtime-C_ttsnZz.js";import{St as e,q as i}from"./index-BT8Vuu3B.js";import{n as o}from"./context-BrD4AniQ-_nW8oMsv.js";import{n as r,t as n}from"./styles-hx5_Dz4D-CjeaMkGu.js";import{o as l,t as s}from"./maplibre-CUYkxr-D-BaX6BEaK.js";var u=t(e(),1),a=i();function d({latitude:t,longitude:e,anchor:i,offset:d=[0,-35],onClose:h,children:c}){let f=(0,u.useRef)(null),{current:g}=l(),{activeMarker:m,clusterPoints:p,mapPadding:w}=o(),b=(0,u.useRef)(p),v=(0,u.useRef)(m);return(0,u.useEffect)(()=>{let t=b.current!==p,e=v.current===m;t&&e&&void 0!==m&&h?.(),b.current=p,v.current=m},[p,m,h]),(0,u.useEffect)(()=>{let t,e=f?.current,i={width:0,height:0},o=new ResizeObserver(()=>{t&&clearTimeout(t),t=window.setTimeout(()=>{(()=>{if(!g||!e||void 0===m)return;let t=g.getBounds(),o=g.getCenter(),n=g.getCanvas(),l=e.getElement()?.getBoundingClientRect();if(!t||!l)return;let s=Math.abs(l.width-i.width),u=Math.abs(l.height-i.height);if(0!==i.width&&s<15&&u<15)return;i={width:l.width,height:l.height};let a=n.getBoundingClientRect(),d={width:n.clientWidth,height:n.clientHeight,top:a.top,left:a.left};r(l,{latitude:o.lat,longitude:o.lng},{left:t.getWest(),right:t.getEast(),top:t.getNorth(),bottom:t.getSouth()},d,{left:w.left||0,right:w.right||0,top:w.top||0,bottom:w.bottom||0},t=>{g.easeTo({center:[t.longitude,t.latitude],duration:500})})})()},100)}),n=e?.getElement();return n&&o.observe(n),()=>{t&&clearTimeout(t),o.disconnect()}},[g,f,m,w.top,w.bottom,w.left,w.right]),void 0===t||void 0===e?null:(0,a.jsx)(s,{ref:f,className:"maplibre-popup",focusAfterOpen:!0,latitude:t,longitude:e,anchor:i,offset:d,onClose:h,closeButton:!1,children:(0,a.jsx)("div",{className:n,children:c})})}export{d as default};
//# sourceMappingURL=Maptiler-BtYYeJoo-Bt0ODadT.js.map