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