import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import{useState as r,useRef as n,useEffect as o,useMemo as i}from"react";import{fetchInterventionUnits as c}from"../../api/intervention-units/fetchInterventionUnits.js";function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?a(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var l=function(e){var a=r([]),u=t(a,2),l=u[0],s=u[1],f=r(!1),p=t(f,2),b=p[0],v=p[1],d=n(null),m=n(!1);return o((function(){var t,r;if(!e)return null===(r=d.current)||void 0===r||r.abort(),s([]),v(!1),void(m.current=!1);if(!(m.current&&l.length>0)){null===(t=d.current)||void 0===t||t.abort();var n=new AbortController;return d.current=n,v(!0),c(n.signal).then((function(e){n.signal.aborted||(s(e),m.current=!0,v(!1))})).catch((function(e){n.signal.aborted||(console.error("Failed to fetch intervention units:",e),s([]),v(!1))})),function(){n.abort()}}}),[e]),{wellIdToInterventionNames:i((function(){var e=new Map;return l.forEach((function(t){t.assetIds.forEach((function(r){var n=e.get(r);n?n.push(t.name):e.set(r,[t.name])}))})),e}),[l]),activeInterventionWellIds:i((function(){var e=new Set;return l.forEach((function(t){null!=t.activeWellAssetId&&e.add(t.activeWellAssetId)})),e}),[l]),isLoading:b}},s=function(e,t){return 0===t.size?e:e.map((function(e){var r=t.get(e.id);return r?u(u({},e),{},{interventionAsset:r}):e}))};export{s as enrichWellsWithInterventionData,l as useInterventionEnrichment};
//# sourceMappingURL=useInterventionEnrichment.js.map
