"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@turf/bbox"),i=require("../../../../utils/tile-math.js"),t=require("../constants.js"),u=require("../utils/getGhostZoneBounds.js"),s=require("../utils/getTileGridBounds.js"),o=require("../utils/smartFitBounds.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(r),d=function(r){var a=r.mapRef,d=r.isMapReady,c=r.subjectWellCoords,f=r.circleGeoJSON,l=r.radius,p=r.hasCenteredRef,v=r.ghostZone;e.useEffect((function(){var e;if(d&&!p.current&&(c||v)){var r=null===(e=a.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,o=e.circleGeoJSON,a=e.radius,d=e.subjectWellCoords,c="radius"===(null==r?void 0:r.type)&&r.radius>t.MapConfig.Radius.Max;if(r&&!c){var f=u.getGhostZoneBounds(r);if(f)return f.bounds}if(o&&a&&a<=t.MapConfig.Radius.Max)return n.default(o);if(!d)return null;var l=i.pointToTile(d.longitude,d.latitude);return s.getTileGridBounds(l)}({ghostZone:v,circleGeoJSON:f,radius:l,subjectWellCoords:c});M&&(p.current=!0,o.smartFitBounds(r,M))}}}}),[d,c,f,l,a,p,v])};exports.useMapBounds=function(r){var i=r.mapRef,u=r.circleGeoJSON,s=r.selectionMode,a=r.subjectWell,c=r.subjectWellCoords,f=r.radius,l=r.isMapReady,p=r.ghostZone,v=e.useRef(!1),R=e.useRef(f),M=e.useRef(s);d({mapRef:i,isMapReady:l,subjectWellCoords:c,circleGeoJSON:u,radius:f,hasCenteredRef:v,ghostZone:p}),function(r){var i=r.mapRef,u=r.isMapReady,s=r.radius,a=r.circleGeoJSON,d=r.subjectWell,c=r.hasCenteredRef,f=r.previousRadiusRef;e.useEffect((function(){var e;if(u&&c.current&&f.current!==s){f.current=s;var r=null===(e=i.current)||void 0===e?void 0:e.getMap();if(r){if(!(s>t.MapConfig.Radius.Max)){if(a&&d){var l=n.default(a);o.smartFitBounds(r,l,{duration:300})}return function(){r.stop()}}r.setZoom(1)}}}),[u,s,a,d,i,c,f])}({mapRef:i,isMapReady:l,radius:f,circleGeoJSON:u,subjectWell:a,hasCenteredRef:v,previousRadiusRef:R}),function(r){var i=r.mapRef,u=r.isMapReady,s=r.selectionMode,a=r.circleGeoJSON,d=r.radius,c=r.hasCenteredRef,f=r.previousSelectionModeRef;e.useEffect((function(){var e;if(u&&c.current&&f.current!==s){var r=f.current;if(f.current=s,"lasso"!==r){var l=null===(e=i.current)||void 0===e?void 0:e.getMap();if(l){if("radius"===s&&a&&d<=t.MapConfig.Radius.Max){var p=n.default(a);o.smartFitBounds(l,p,{duration:300})}return function(){l.stop()}}}}}),[u,s,a,d,i,c,f])}({mapRef:i,isMapReady:l,selectionMode:s,circleGeoJSON:u,radius:f,hasCenteredRef:v,previousSelectionModeRef:M})};
//# sourceMappingURL=useMapBounds.js.map
