import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as o,useRef as u,useEffect as i}from"react";import{groupBy as a,get as c}from"lodash";import{fetchMetricsData as s}from"../utils/apiCalls.js";import{ALL_SECTION_KEY as p,ColumnType as f}from"../constants.js";import{mapbox as l}from"../../../utils/index.js";function m(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?m(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}var d=l.getAssetV2Coordinates,v=l.getDistanceByCoordinates,h=function(r){return Number.isFinite(r)?parseFloat(r.toFixed(2)):null};function y(l,m,y,O,j,w){var x=o(null),g=e(x,2),P=g[0],k=g[1],F=o(null),D=e(F,2),E=D[0],C=D[1],S=o(null),A=e(S,2),H=A[0],T=A[1],B=u({});function G(){return G=t(n.mark((function r(){var e,o,u;return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=m.find((function(r){return r.id===j})),(o=e&&d(e,"topHole"))||C(m),r.next=5,Promise.all(m.map(function(){var r=t(n.mark((function r(t){var e,u;return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,d(t,"topHole");case 3:if(!(e=r.sent)){r.next=13;break}return r.t0=parseFloat,r.next=8,v(o,e);case 8:return r.t1=r.sent,u=(0,r.t0)(r.t1),r.abrupt("return",b(b({},t),{},{distance:parseFloat(u.toFixed(2))}));case 13:return r.abrupt("return",t);case 14:r.next=19;break;case 16:return r.prev=16,r.t2=r.catch(0),r.abrupt("return",t);case 19:case"end":return r.stop()}}),r,null,[[0,16]])})));return function(t){return r.apply(this,arguments)}}()));case 5:u=r.sent,C(u);case 7:case"end":return r.stop()}}),r)}))),G.apply(this,arguments)}function N(r){return V.apply(this,arguments)}function V(){return(V=t(n.mark((function t(e){var o,u,i,p;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(l,e,w);case 2:o=t.sent,u={},i=a(o,"asset_id"),e.forEach((function(t){var e,n=null===(e=i[t])||void 0===e?void 0:e.reduce((function(t,e){var n=c(e,"data.value"),o=c(e,"data.key");return b(b({},t),{},r({},o,h(n)))}),{});u[t]=n})),B.current=b(b({},B.current),u),p=[],H.forEach((function(r){p.push(b(b({},r),B.current[r.id]))})),k(p);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}return i((function(){m&&function(){G.apply(this,arguments)}()}),[m,j]),i((function(){var t,e;E&&y&&O&&(t=y.filter((function(r){return r.value!==p})),e=E.map((function(e){var n=t.filter((function(r){return(O[r.value]||[]).includes(e.id)})).map((function(r){return r.label}));return n.length>0?b(b({},e),{},r({},f.wellSection,n)):e})),T(e))}),[E,y,O]),i((function(){if(H){var r=[];H.forEach((function(t){B.current[t.id]||r.push(t.id)})),N(r)}}),[H]),i((function(){P&&N(P.map((function(r){return r.id})))}),[w]),P}export{y as useAdvancedWells};
