import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/regenerator";import{useCallback as t}from"react";import{useStore as o}from"zustand";import{ViewportStoreContext as s}from"../../stores/viewport-store/ViewportStoreContext.js";import"lodash";import"../../stores/picker-props-store/PickerPropsStoreContext.js";import"@babel/runtime/helpers/defineProperty";import"@babel/runtime/helpers/objectWithoutProperties";import"react/jsx-runtime";import"../../viewport/ViewportProvider.js";import{useContextOrThrow as i}from"../../stores/utils/useContextOrThrow.js";import"../../viewport/ViewportContext.js";import{usePickerPropsStore as n}from"../../stores/picker-props-store/usePickerPropsStore.js";import{useFilterStore as l}from"../../stores/filter-store/useFilterStore.js";import"@babel/runtime/helpers/toConsumableArray";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import"../../../../clients/jsonApi/index.js";import"../../../../clients/subscriptions/constants.js";import"../../../../clients/subscriptions.v1.js";import"../../../../clients/subscriptions/subscriptions-client.factory.js";import"../../../../clients/api/apiCore.js";import"../../../../clients/constants.js";import"../../../../clients/sso/auth0.js";import"../../../../clients/sso/oauth2.js";import"../../../../clients/api/rateLimiter.js";import{getAllAssets as a}from"../../api/shared/fetchers/getAllAssets.js";import"../../constants.js";import"../../api/shared/dataFormatter.js";import"@babel/runtime/helpers/slicedToArray";import{useAllWellsCache as p}from"../useAllWellsCache/useAllWellsCache.js";var u=function(u,c){var m=i(s),d=o(m,(function(r){return r.addWellsToTile})),f=n((function(r){return r.addWellsUsabilityInfo})),b=n((function(r){return r.setAllWellsLoadProgress})),h=n((function(r){return r.segment})),j=l((function(r){var e;return null!==(e=r.filters.companyId)&&void 0!==e?e:null})),v=l((function(r){var e;return null===(e=r.filters.drillingWells)||void 0===e||e})),g="drilling"===h&&v,x=p(),C=x.getCachedWellIds,w=x.setCachedWellIds,k=x.clearCache;return{loadAllWells:t(r(e.mark((function r(){var t,o,s,i,n,l,p;return e.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(null===(t=u.current)||void 0===t||t.abort(),u.current=new AbortController,o=u.current.signal,r.prev=3,null===(s=C())){r.next=12;break}if(i=m.getState(),(n=s.map((function(r){return i.wells.get(r)})).filter((function(r){return void 0!==r}))).length!==s.length){r.next=12;break}return b({loaded:n.length,isComplete:!0}),c.current=!0,r.abrupt("return");case 12:return b({loaded:0,isComplete:!1}),r.next=15,a(j,{signal:o,onProgress:b,drillingWells:g});case 15:if(l=r.sent,!o.aborted){r.next=18;break}return r.abrupt("return");case 18:return r.next=20,f(l);case 20:if(p=r.sent,!o.aborted){r.next=23;break}return r.abrupt("return");case 23:d("all-wells",p),w(p.map((function(r){return r.id}))),b({loaded:p.length,isComplete:!0}),c.current=!0,r.next=35;break;case 29:if(r.prev=29,r.t0=r.catch(3),"AbortError"!==(null===r.t0||void 0===r.t0?void 0:r.t0.name)){r.next=33;break}return r.abrupt("return");case 33:console.error("Failed to load all wells:",r.t0),b(null);case 35:case"end":return r.stop()}}),r,null,[[3,29]])}))),[m,u,c,d,f,j,g,C,w,b]),store:m,clearCache:k}};export{u as useLoadAllWellsCallback};
//# sourceMappingURL=useLoadAllWellsCallback.js.map
