"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),o=require("react"),n=require("../utils/smartFitBounds.js"),t=require("../utils/resolveResetBounds.js"),a=require("../constants.js"),i=require("./useMapViewState.js"),u=require("./useSyncViewportBounds.js"),l=require("./useIsMapMoving.js"),s=require("./useTileSafeEnforcement.js"),r=require("./useZoomLimitState.js"),d=require("./useMapBounds.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=c(e);exports.useMapCameraControl=function(e){var c=e.mapRef,m=e.subjectWellCoords,M=e.subjectWell,p=e.isLoadAllWells,v=e.isMapReady,h=e.selectionZone,C=e.shouldRecenter,S=e.onRecenterComplete,Z=e.radius,b=e.selectionMode,g=e.circleGeoJSON,j=o.useState(!1),y=f.default(j,2),O=y[0],R=y[1],q=i.useMapViewState(c,m),W=q.viewState,I=q.distance,B=q.handleMove,E=q.handleZoomIn,k=q.handleZoomOut,w=q.canZoomIn,T=q.canZoomOut,z=u.useSyncViewportBounds(c),D=z.handleMove,V=z.handleMoveEnd,A=l.useIsMapMoving(c),F=A.isMoving,G=A.handleMoveStart,J=A.handleMoveEnd,L=s.useTileSafeEnforcement({mapRef:c,isEnabled:!p}).handleResize,N=r.useZoomLimitState(),x=o.useCallback((function(e){B(e),D(),e.originalEvent&&R(!1)}),[B,D]),_=o.useCallback((function(){R(!1)}),[]),P=function(e,n,t,a,i){var u=o.useCallback((function(){requestAnimationFrame((function(){t(),a()}))}),[t,a]);return{handleZoomInWithSync:o.useCallback((function(){e(),u(),null==i||i()}),[e,u,i]),handleZoomOutWithSync:o.useCallback((function(){n(),u(),null==i||i()}),[n,u,i])}}(E,k,D,V,_),H=P.handleZoomInWithSync,K=P.handleZoomOutWithSync,Q=o.useCallback((function(){V(),J()}),[V,J]),U=o.useCallback((function(){var e,o=null===(e=c.current)||void 0===e?void 0:e.getMap();if(o){var i=t.resolveResetBounds({selectionZone:h,circleGeoJSON:g,subjectWellCoords:m});i?n.smartFitBounds(o,i.value,{padding:i.padding,duration:300}):o.flyTo({center:[a.MapConfig.DefaultCoords.longitude,a.MapConfig.DefaultCoords.latitude],zoom:a.MapConfig.Zoom.Initial,duration:300}),R(!0)}}),[h,g,m,c]);return function(e,n,t,i,u,l){o.useEffect((function(){if(n&&t){if(i)u();else{var o,s=null===(o=e.current)||void 0===o?void 0:o.getMap();s&&s.flyTo({center:[a.MapConfig.DefaultCoords.longitude,a.MapConfig.DefaultCoords.latitude],zoom:a.MapConfig.Zoom.Initial,duration:300})}null==l||l()}}),[n,t,i,u,l,e])}(c,C,v,m,U,S),d.useMapBounds({mapRef:c,circleGeoJSON:g,selectionMode:b,subjectWell:M,subjectWellCoords:m,radius:Z,isMapReady:v,ghostZone:h}),{viewState:W,distance:I,canZoomIn:w,canZoomOut:T,isZoomReset:O,isTooZoomedOut:N,effectiveZoomedOut:N&&!F,handleMove:x,handleMoveStart:G,handleMoveEnd:Q,handleZoomInWithSync:H,handleZoomOutWithSync:K,handleResetZoom:U,tileSafeOnResize:L}};
//# sourceMappingURL=useMapCameraControl.js.map
