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