import{useRef as e,useEffect as r}from"react";import i from"@turf/bbox";import{pointToTile as t}from"../../../../utils/tile-math.js";import{MapConfig as o}from"../constants.js";import{getGhostZoneBounds as a}from"../utils/getGhostZoneBounds.js";import{getTileGridBounds as s}from"../utils/getTileGridBounds.js";import{smartFitBounds as u}from"../utils/smartFitBounds.js";var n=function(e){var n=e.mapRef,d=e.isMapReady,c=e.subjectWellCoords,l=e.circleGeoJSON,f=e.radius,p=e.hasCenteredRef,v=e.ghostZone;r((function(){var e;if(d&&!p.current&&(c||v)){var r=null===(e=n.current)||void 0===e?void 0:e.getMap();if(r){var R=r.getCanvas();if(!(R.clientWidth<=0||R.clientHeight<=0)){var m=function(e){var r=e.ghostZone,u=e.circleGeoJSON,n=e.radius,d=e.subjectWellCoords,c="radius"===(null==r?void 0:r.type)&&r.radius>o.Radius.Max;if(r&&!c){var l=a(r);if(l)return l.bounds}if(u&&n&&n<=o.Radius.Max)return i(u);if(!d)return null;var f=t(d.longitude,d.latitude);return s(f)}({ghostZone:v,circleGeoJSON:l,radius:f,subjectWellCoords:c});m&&(p.current=!0,u(r,m))}}}}),[d,c,l,f,n,p,v])},d=function(t){var a=t.mapRef,s=t.circleGeoJSON,d=t.selectionMode,c=t.subjectWell,l=t.subjectWellCoords,f=t.radius,p=t.isMapReady,v=t.ghostZone,R=e(!1),m=e(f),M=e(d);n({mapRef:a,isMapReady:p,subjectWellCoords:l,circleGeoJSON:s,radius:f,hasCenteredRef:R,ghostZone:v}),function(e){var t=e.mapRef,a=e.isMapReady,s=e.radius,n=e.circleGeoJSON,d=e.subjectWell,c=e.hasCenteredRef,l=e.previousRadiusRef;r((function(){var e;if(a&&c.current&&l.current!==s){l.current=s;var r=null===(e=t.current)||void 0===e?void 0:e.getMap();if(r){if(!(s>o.Radius.Max)){if(n&&d){var f=i(n);u(r,f,{duration:300})}return function(){r.stop()}}r.setZoom(1)}}}),[a,s,n,d,t,c,l])}({mapRef:a,isMapReady:p,radius:f,circleGeoJSON:s,subjectWell:c,hasCenteredRef:R,previousRadiusRef:m}),function(e){var t=e.mapRef,a=e.isMapReady,s=e.selectionMode,n=e.circleGeoJSON,d=e.radius,c=e.hasCenteredRef,l=e.previousSelectionModeRef;r((function(){var e;if(a&&c.current&&l.current!==s){var r=l.current;if(l.current=s,"lasso"!==r){var f=null===(e=t.current)||void 0===e?void 0:e.getMap();if(f){if("radius"===s&&n&&d<=o.Radius.Max){var p=i(n);u(f,p,{duration:300})}return function(){f.stop()}}}}}),[a,s,n,d,t,c,l])}({mapRef:a,isMapReady:p,selectionMode:d,circleGeoJSON:s,radius:f,hasCenteredRef:R,previousSelectionModeRef:M})};export{d as useMapBounds};
//# sourceMappingURL=useMapBounds.js.map
