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