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