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