import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import n from"@babel/runtime/regenerator";import{useState as a,useRef as o,useEffect as u}from"react";import{get as c,keyBy as i,omit as s,mapValues as p,merge as f}from"lodash";import{getAppHash as d,getInitialAppsDataState as l}from"./utils.js";import{resolveAppsData as b}from"./dataResolvers.js";import{isDevCenterApp as m}from"../../../../utils/devcenter.js";import{APPS_DATA_REQUESTS as h}from"./constants.js";function O(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function g(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function y(e){var O=e.apps,y=e.dashboardAssetId,j=a({}),v=t(j,2),P=v[0],w=v[1],I=o(),A=o({}),D=o({wellsById:{},rigsById:{},fracFleetsById:{},deprecatedAssetData:{}}),E=O.reduce((function(r,e){var t=c(e,["app","ui_settings","multi_rig"]);return m(e)&&!t&&r.push(g(g({},e),{},{appHash:d(e)})),r}),[]),L=function(r){return w((function(e){return p(e,(function(e){var t=r[e.id]||{};return g(g(g({},e),t),{},{isLoading:!1})}))}))},x=function(r){D.current=f(D.current,r)};return u(r(n.mark((function r(){var e,t,a,o;return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(e=Object.values(P),E.length||e.length){r.next=3;break}return r.abrupt("return");case 3:if(!(E.length<e.length)){r.next=8;break}return t=i(E,"id"),a=e.find((function(r){return!t[r.id]})).id,w((function(r){return s(r,a)})),r.abrupt("return");case 8:return o=E.filter((function(r){return!P[r.id]||P[r.id].appHash!==r.appHash})),w((function(r){return g(g({},r),l(o))})),r.t0=L,r.next=13,b({apps:E,dashboardAssetId:y,cache:D,updateCache:x});case 13:r.t1=r.sent,(0,r.t0)(r.t1);case 15:case"end":return r.stop()}}),r)}))),[String(E.map((function(r){return r.appHash}))),y]),A.current={apps:E,dashboardAssetId:y,cache:D,updateCache:x},u((function(){return I.current=setInterval((function(){b(g(g({},A.current),{},{requests:[h.FRAC_FLEET_WELLS,h.PAD_WELLS]})).then(L)}),3e5),function(){return clearInterval(I.current)}}),[]),P}export{y as default};
