import e from"@babel/runtime/helpers/toConsumableArray";import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import n from"@babel/runtime/helpers/slicedToArray";import o from"@babel/runtime/regenerator";import{useState as a,useEffect as c}from"react";import{isEmpty as u,uniq as l,intersection as i,get as s}from"lodash";import{fetchOffsetWellSelections as p,fetchWellhubWells as f}from"../utils/apiCalls.js";import{WellSectionColors as b,ALL_SECTION_KEY as m,ALL_SECTION_LABEL as v}from"../constants.js";function O(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 y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}var d=function(O,d,h){var j=a(null),w=n(j,2),k=w[0],x=w[1],P=a(null),g=n(P,2),D=g[0],S=g[1];return c((function(){var n,a,c=(n=t(o.mark((function t(){var n,a,c,s,f,O,j;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,!d){t.next=7;break}return t.next=4,p(d);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=[];case 8:n=t.t0,a=!u(n)&&JSON.parse(n[0].data.filters),c=!u(n)&&n[0].data.result&&JSON.parse(n[0].data.result),a&&c?(s=a.filterTabs.map((function(e,r){return{value:e.value,label:e.name,color:b[r]}})),f=[],O=s.reduce((function(e,t){var n=t.value,o=(null==c?void 0:c[n])||[],a=l(o.concat(d));return f=f.concat(a),y(y({},e),{},r({},n,a))}),{}),O=y(y({},O),{},r({},m,l(f))),j=h.map((function(e){return e.id})),O=Object.keys(O).reduce((function(e,t){return y(y({},e),{},r({},t,i(O[t],j)))}),{}),x([{value:m,label:v}].concat(e(s))),S(O)):(x([{value:m,label:v}]),S(r({},m,[d]))),t.next=19;break;case 14:t.prev=14,t.t1=t.catch(0),console.error("offetwell selection fetch error: ",t.t1),x([]),S([]);case 19:case"end":return t.stop()}}),t,null,[[0,14]])}))),function(){return n.apply(this,arguments)}),j=(a=t(o.mark((function e(){var t,n,a,c;return o.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f(d);case 3:t=e.sent,n=s(t[0],"data.offset_wells")||[],a=r({},m,l(n.map((function(e){return e.id})).concat(d))),x([{value:m,label:v}]),c=h.map((function(e){return e.id})),a=Object.keys(a).reduce((function(e,t){return y(y({},e),{},r({},t,i(a[t],c)))}),{}),S(a),e.next=17;break;case 12:e.prev=12,e.t0=e.catch(0),console.error("wellhub fetch error: ",e.t0),x([]),S([]);case 17:case"end":return e.stop()}}),e,null,[[0,12]])}))),function(){return a.apply(this,arguments)});d&&h&&(O?c():j())}),[O,d,h]),[k,x,D,S]};export{d as useBicWells};
