import r from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as o,useRef as i,useMemo as c,useEffect as s}from"react";import{isEqual as u,groupBy as a,get as p}from"lodash";import"@babel/runtime/helpers/toConsumableArray";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import"../../../../clients/jsonApi/index.js";import"../../../../clients/subscriptions/constants.js";import"../../../../clients/subscriptions.v1.js";import"../../../../clients/subscriptions/subscriptions-client.factory.js";import"../../../../clients/api/apiCore.js";import"../../../../clients/constants.js";import"../../../../clients/sso/auth0.js";import"../../../../clients/sso/oauth2.js";import"../../../../clients/api/rateLimiter.js";import{NonConvertableMetrics as l}from"../../constants.js";import"../../api/shared/dataFormatter.js";import{fetchMetricsData as m}from"../../api/metrics/fetchMetricsData.js";import{usePickerPropsStore as f}from"../../stores/picker-props-store/usePickerPropsStore.js";import{getSegmentConfig as b}from"../../segment-config/index.js";import{transformWells as d}from"./wellTransformations.js";function j(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 h(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?j(Object(n),!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}var v=function(r){return Number.isFinite(r)?parseFloat(r.toFixed(2)):null},y=function(j,y,g,w,O,P){var x=f((function(r){return r.segment})),k=b(x).metricsCollection,S=o(null),A=e(S,2),D=A[0],C=A[1],E=o(!1),F=e(E,2),T=F[0],I=F[1],M=o(new Set),N=e(M,2),G=N[0],L=N[1],_=i({}),q=i(O),z=i(k),B=i(null),H=c((function(){return P&&j?d(j,w,y,g):null}),[j,w,y,g,P]);return s((function(){if(!H||!P)return I(!1),void L(new Set);var o=H.map((function(r){return h(h({},r),_.current[r.id]||{})}));C(o),I(!0),B.current&&B.current.abort();var i=new AbortController;B.current=i;var c=function(){var o=r(n.mark((function o(){var c,s,f,b,d,j,y,g,w,P,x;return n.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(o.prev=0,c=[],s=!u(q.current,O),f=z.current!==k,s||f?(c=H.map((function(r){return r.id})),_.current={},q.current=O,z.current=k):c=H.filter((function(r){return!_.current[r.id]})).map((function(r){return r.id})),c.length>0&&L(new Set(c)),!(c.length>0&&O.length>0)){o.next=20;break}return b=new Map(H.filter((function(r){return c.includes(r.id)})).map((function(r){return[r.id,r]}))),d=a(Array.from(b.values()).filter((function(r){return r.companyId})),"companyId"),j=Object.entries(d).map(function(){var t=r(n.mark((function r(t){var o,c,s,u;return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=e(t,2),c=o[0],s=o[1],u=s.map((function(r){return r.id})),r.abrupt("return",m(Number(c),u,O,i.signal,k));case 3:case"end":return r.stop()}}),r)})));return function(r){return t.apply(this,arguments)}}()),o.next=12,Promise.all(j);case 12:if(y=o.sent,!i.signal.aborted){o.next=15;break}return o.abrupt("return");case 15:g=y.flat(),w={},P=a(g,"asset_id"),c.forEach((function(r){var e,n=null===(e=P[r])||void 0===e?void 0:e.reduce((function(r,e){var n=p(e,"data.value"),o=p(e,"data.key");return h(h({},r),{},t({},o,l.includes(o)?n:v(n)))}),{});w[r]=n||{}})),_.current=h(h({},_.current),w);case 20:x=H.map((function(r){return h(h({},r),_.current[r.id]||{})})),C((function(r){return u(x,r)?r:x})),I(!1),L(new Set),o.next=29;break;case 26:o.prev=26,o.t0=o.catch(0),i.signal.aborted||(console.error("Error fetching metrics data:",o.t0),C(H),I(!1),L(new Set));case 29:case"end":return o.stop()}}),o,null,[[0,26]])})));return function(){return o.apply(this,arguments)}}();return c(),function(){B.current&&(B.current.abort(),B.current=null)}}),[H,O,P,k]),[D,T,H,G]};export{y as useAdvancedWells};
//# sourceMappingURL=useAdvancedWells.js.map
