"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),r=require("@turf/bbox"),u=require("@turf/circle"),o=require("zustand"),s=require("../../../../stores/viewport-store/ViewportStoreContext.js"),i=require("../../../../stores/filter-store/useFilterStore.js"),n=require("../../../../stores/utils/useContextOrThrow.js"),l=require("../constants.js"),a=require("../utils/getGhostZoneBounds.js"),d=require("../utils/getTileGridBounds.js"),f=require("../../../../constants.js"),c=require("../../../../utils/tile-math.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=v(e),p=v(r),q=v(u);exports.useInitialBounds=function(e){var r,u=e.subjectWellCoords,v=e.hasSubjectWell,j=e.open,T=e.ghostZone,g=n.useContextOrThrow(s.ViewportStoreContext),b=o.useStore(g,(function(e){return e.bounds})),S=o.useStore(g,(function(e){return e.setBounds})),w=null!==(r=i.useFilterStore((function(e){var t;return null===(t=e.filters)||void 0===t?void 0:t.radius})))&&void 0!==r?r:f.DEFAULT_RADIUS_MILES;t.useEffect((function(){if(j&&null===b&&(!v||u)){var e,t=null!=u?u:l.MapConfig.DefaultCoords,r=T?function(e){if("radius"===e.type&&e.radius>l.MapConfig.Radius.Max)return null;var t=a.getGhostZoneBounds(e);if(!t)return null;var r=h.default(t.bounds,4),u=r[0],o=r[1],s=r[2];return{north:r[3],south:o,east:s,west:u}}(T):null;if(e=r||function(e,t){var r=[e.longitude,e.latitude],u=q.default(r,t,{units:"miles"}),o=p.default(u),s=h.default(o,4),i=s[0],n=s[1],l=s[2];return{north:s[3],south:n,east:l,west:i}}(t,w),c.getTilesForViewport(e).length>c.MAX_TILES_FOR_FETCH){var o,s=null!==(o=null==T?void 0:T.center)&&void 0!==o?o:t,i=c.pointToTile(s.longitude,s.latitude),n=d.getTileGridBounds(i),f=h.default(n,4);e={west:f[0],south:f[1],east:f[2],north:f[3]}}S(e,c.TILE_ZOOM)}}),[j,b,S,u,v,w,T])};
//# sourceMappingURL=useInitialBounds.js.map
