"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),r=require("react"),n=require("../../api/intervention-units/fetchInterventionUnits.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(e),u=o(t);function c(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 a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){i.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}exports.enrichWellsWithInterventionData=function(e,t){return 0===t.size?e:e.map((function(e){var r=t.get(e.id);return r?a(a({},e),{},{interventionAsset:r}):e}))},exports.useInterventionEnrichment=function(e){var t=r.useState([]),o=u.default(t,2),i=o[0],c=o[1],a=r.useState(!1),s=u.default(a,2),l=s[0],f=s[1],v=r.useRef(null),p=r.useRef(!1);return r.useEffect((function(){var t,r;if(!e)return null===(r=v.current)||void 0===r||r.abort(),c([]),f(!1),void(p.current=!1);if(!(p.current&&i.length>0)){null===(t=v.current)||void 0===t||t.abort();var o=new AbortController;return v.current=o,f(!0),n.fetchInterventionUnits(o.signal).then((function(e){o.signal.aborted||(c(e),p.current=!0,f(!1))})).catch((function(e){o.signal.aborted||(console.error("Failed to fetch intervention units:",e),c([]),f(!1))})),function(){o.abort()}}}),[e]),{wellIdToInterventionNames:r.useMemo((function(){var e=new Map;return i.forEach((function(t){t.assetIds.forEach((function(r){var n=e.get(r);n?n.push(t.name):e.set(r,[t.name])}))})),e}),[i]),activeInterventionWellIds:r.useMemo((function(){var e=new Set;return i.forEach((function(t){null!=t.activeWellAssetId&&e.add(t.activeWellAssetId)})),e}),[i]),isLoading:l}};
//# sourceMappingURL=useInterventionEnrichment.js.map
