"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("@babel/runtime/helpers/toConsumableArray"),r=require("@babel/runtime/helpers/asyncToGenerator"),n=require("@babel/runtime/regenerator"),a=require("react"),s=require("../../clients/jsonApi/index.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=u(e),l=u(t),d=u(r),c=u(n),o=["well.name","well.asset_id","well.status","well.pad"],f=function(e){var t=e.appPad,r=e.assets;return t?[{id:t.id.toString(),name:t.name,wells:r.map((function(e){return{assetId:e.asset_id,name:e.name,status:e.status,id:e.id}}))}]:[]},p=function(){var e=d.default(c.default.mark((function e(t){var r,n,a,u,i,d,o,f,p,v,b,m;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.appPad,a=t.assets,u=t.currentOffsetSetting,i=n&&a[0]?[]:[null===(r=a[0])||void 0===r?void 0:r.id],d=new Set(a.map((function(e){return e.asset_id}))),(o=u.filter((function(e){return!d.has(e.selectedWellId)}))).length){e.next=6;break}return e.abrupt("return",i);case 6:if(f=o.reduce((function(e,t){var r=e.wellIds,n=e.assetIdsToResolve,a=t.selectedWellId,s=t.selectedWellIdNew;return{assetIdsToResolve:s?n:n.concat(a),wellIds:s?r.concat(s):r}}),{assetIdsToResolve:[],wellIds:[]}),p=f.assetIdsToResolve,v=f.wellIds,!p.length){e.next=13;break}return e.next=10,s.getResolvedAssets({assets:p});case 10:e.t0=e.sent,e.next=14;break;case 13:e.t0={wells:[]};case 14:return b=e.t0,m=b.wells,e.abrupt("return",i.concat.apply(i,l.default(v).concat(l.default(m.map((function(e){return e.data.id}))))));case 17:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),v=function(){var e=d.default(c.default.mark((function e(t){var r,n,a,u,i,l,d,f;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.length){e.next=2;break}return e.abrupt("return",[]);case 2:return r=function(e){var t=e.id,r=e.attributes;return{id:t,assetId:r.asset_id,name:r.name,status:r.status}},e.next=5,s.getWells({ids:t,fields:o});case 5:if(n=e.sent,a=n.data,u=n.included,i=new Map(a.map((function(e){var t=e.id,n=e.attributes;return[t,r({id:t,attributes:n})]}))),l=u.filter((function(e){return"pad"===e.type})),!(d=l.reduce((function(e,t){var r=t.relationships.wells.data.map((function(e){return e.id})).filter((function(e){return!i.has(e)}));return e.concat(r)}),[])).length){e.next=17;break}return e.next=14,s.getWells({ids:d,fields:o});case 14:e.t0=e.sent,e.next=18;break;case 17:e.t0={data:[]};case 18:return f=e.t0,f.data.forEach((function(e){var t=e.id,n=e.attributes;return i.set(t,r({id:t,attributes:n}))})),e.abrupt("return",l.map((function(e){return{id:e.id,name:e.attributes.name,wells:e.relationships.wells.data.map((function(e){var t=e.id;return i.get(t)})).filter(Boolean)}})));case 22:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();exports.useOffsetPickerActions=function(e){var t=e.opened,r=e.currentOffsetSetting,n=e.appPad,s=e.assets,u=a.useState([]),l=i.default(u,2),o=l[0],b=l[1],m=a.useState([]),w=i.default(m,2),h=w[0],x=w[1];return a.useEffect((function(){var e=function(){var e=d.default(c.default.mark((function e(){var t,a,u,i;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.map((function(e){return e.selectedWellId})),a=f({appPad:n,assets:s}),e.next=4,p({appPad:n,assets:s,currentOffsetSetting:r});case 4:return u=e.sent,e.next=7,v(u);case 7:i=e.sent,b(a.concat(i)),x(t);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();t&&e()}),[t,s,r]),{selectedPads:o,selectedWellAssetIds:h,setSelectedPads:b,setSelectedWellAssetIds:x}};
//# sourceMappingURL=useOffsetPickerActions.js.map
