"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require('./../../ext-esm/tslib/tslib.es6.js'),t=require("react"),s=require("../../clients/jsonApi/index.js"),a=function(t){return e.__awaiter(void 0,[t],void 0,(function(t){var a,n,r,i,l,d,u,c,o,f=t.appPad,p=t.assets,v=t.currentOffsetSetting;return e.__generator(this,(function(t){switch(t.label){case 0:return a=f&&p[0]?[]:[null===(o=p[0])||void 0===o?void 0:o.id],n=new Set(p.map((function(e){return e.asset_id}))),(r=v.filter((function(e){return!n.has(e.selectedWellId)}))).length?(i=r.reduce((function(e,t){var s=e.wellIds,a=e.assetIdsToResolve,n=t.selectedWellId,r=t.selectedWellIdNew;return{assetIdsToResolve:r?a:a.concat(n),wellIds:r?s.concat(r):s}}),{assetIdsToResolve:[],wellIds:[]}),l=i.assetIdsToResolve,d=i.wellIds,l.length?[4,s.getResolvedAssets({assets:l})]:[3,2]):[2,a];case 1:return c=t.sent(),[3,3];case 2:c={wells:[]},t.label=3;case 3:return u=c.wells,[2,a.concat.apply(a,e.__spreadArray(e.__spreadArray([],d,!1),u.map((function(e){return e.data.id})),!1))]}}))}))};exports.useOffsetPickerActions=function(n){var r=n.opened,i=n.currentOffsetSetting,l=n.appPad,d=n.assets,u=t.useState([]),c=u[0],o=u[1],f=t.useState([]),p=f[0],v=f[1];return t.useEffect((function(){r&&e.__awaiter(void 0,void 0,void 0,(function(){var t,n,r,u;return e.__generator(this,(function(c){switch(c.label){case 0:return t=i.map((function(e){return e.selectedWellId})),n=function(e){var t=e.appPad,s=e.assets;return t?[{id:t.id.toString(),name:t.name,wells:s.map((function(e){return{assetId:e.asset_id,name:e.name,status:e.status,id:e.id}}))}]:[]}({appPad:l,assets:d}),[4,a({appPad:l,assets:d,currentOffsetSetting:i})];case 1:return r=c.sent(),[4,(f=r,e.__awaiter(void 0,void 0,void 0,(function(){var t,a;return e.__generator(this,(function(e){switch(e.label){case 0:return f.length?[4,s.getWells({ids:f,fields:["well.name","well.asset_id","well.status","well.pad"]})]:[2,[]];case 1:return t=e.sent(),a=new Map(t.data.map((function(e){var t=e.id,s=e.attributes;return[t,{id:t,assetId:s.asset_id,name:s.name,status:s.status}]}))),[2,t.included.filter((function(e){return"pad"===e.type})).map((function(e){return{id:e.id,name:e.attributes.name,wells:e.relationships.wells.data.map((function(e){var t=e.id;return a.get(t)})).filter(Boolean)}}))]}}))})))];case 2:return u=c.sent(),o(n.concat(u)),v(t),[2]}var f}))}))}),[r,d,i]),{selectedPads:c,selectedWellAssetIds:p,setSelectedPads:o,setSelectedWellAssetIds:v}};
