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