"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require('./../../../ext-esm/tslib/tslib.es6.js'),e=require("react"),i=require("../../../clients/index.js"),a=require("./useWellStreamsData.js"),s=require("../utils/initialDataFetcher.js"),r={provider:"corva",collection:"completion.wits",event:"",params:{fields:"timestamp,collection,asset_id",limit:1,sort:"{ timestamp: -1 }"}},n={provider:"corva",collection:"wireline.wits",event:"",params:{fields:"timestamp,collection,asset_id,data.state",limit:1,sort:"{ timestamp: -1 }"}};exports.useWellStreamActivityTypeSubscription=function(c){var o=c.currentWellId,u=c.isStatusShown,l=c.withSubscription,m=e.useState({timestamp:0}),p=m[0],f=m[1],d=e.useState({timestamp:0}),_=d[0],v=d[1],h=e.useRef([]),S=a({isStatusShown:u,currentWellId:o,wirelineData:p,fracData:_}),b=function(e){var i=e.data[0]||{},a=i.collection,s=i.timestamp,c=i.data,o=i.stage_number;s&&(a===n.collection?f((function(e){return t.__assign(t.__assign({},e),{timestamp:s,stageNumber:o,data:c})})):a===r.collection&&v((function(e){return t.__assign(t.__assign({},e),{timestamp:s})})))},g=function(e,a){var s=t.__assign(t.__assign({},a),{assetId:e}),r=i.socketClient.subscribe(s,{onDataReceive:b});h.current.push(r)};return e.useLayoutEffect((function(){if(o){var t=s.initialDataFetcher(r),e=s.initialDataFetcher(n),i=[t(o),e(o)];return l&&(g(o,r),g(o,n)),Promise.all(i).then((function(t){t.forEach((function(t){b({data:t})}))})),function(){h.current.forEach((function(t){return t()})),h.current=[],f({timestamp:0}),v({timestamp:0})}}}),[o]),S};
