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