"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),r=require("react"),i=require("../utils/initialDataFetcher.js"),a=require("./useWellStreamsData.js"),n=require("../../../clients/index.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=o(e),s=o(t);function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){c.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var p={provider:"corva",collection:"completion.wits",event:"",params:{fields:"timestamp,collection,asset_id",limit:1,sort:"{ timestamp: -1 }"}},m={provider:"corva",collection:"wireline.wits",event:"",params:{fields:"timestamp,collection,asset_id,data.state",limit:1,sort:"{ timestamp: -1 }"}};exports.useWellStreamActivityTypeSubscription=function(e){var t=e.currentWellId,o=e.isStatusShown,c=e.withSubscription,u=r.useState({timestamp:0}),f=s.default(u,2),d=f[0],b=f[1],v=r.useState({timestamp:0}),y=s.default(v,2),O=y[0],h=y[1],j=r.useRef([]),w=a({isStatusShown:o,currentWellId:t,wirelineData:d,fracData:O}),S=function(e){var t=e.data[0]||{},r=t.collection,i=t.timestamp,a=t.data,n=t.stage_number;if(!i)return b({timestamp:0}),void h({timestamp:0});r===m.collection?b((function(e){return l(l({},e),{},{timestamp:i,stageNumber:n,data:a})})):r===p.collection&&h((function(e){return l(l({},e),{},{timestamp:i})}))},D=function(e,t){var r={provider:t.provider,collection:t.collection,event:t.event,params:t.params,assetId:e},i=n.socketClient.subscribe(r,{onDataReceive:S});j.current.push(i)};return r.useLayoutEffect((function(){if(t){var e=i.initialDataFetcher(p),r=i.initialDataFetcher(m),a=[e(t),r(t)];return c&&(D(t,p),D(t,m)),Promise.all(a).then((function(e){e.forEach((function(e){e&&S({data:e})}))})),function(){j.current.forEach((function(e){return e()})),j.current=[],b({timestamp:0}),h({timestamp:0})}}}),[t]),w};
//# sourceMappingURL=useWellStreamActivityTypeSubscription.js.map
