import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/regenerator";import{sortBy as n,get as a}from"lodash";import{getAssets as o}from"../../../clients/jsonApi/index.js";import{mapbox as s}from"../../../utils/index.js";function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?u(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var c=s.getAssetV2Coordinates,p=s.getDistanceByCoordinates,l=function(){var e=t(r.mark((function e(t){var n;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=null,null==t||!t.length){e.next=11;break}return e.prev=2,e.next=5,o({ids:t,fields:["asset.name","asset.top_hole","asset.settings"]});case 5:n=e.sent,e.next=11;break;case 8:e.prev=8,e.t0=e.catch(2),console.error(e.t0);case 11:return e.abrupt("return",n?n.data.map((function(e){var t;return{id:Number(e.id),name:a(e,"attributes.name"),topHole:null!==(t=a(e,"attributes.top_hole"))&&void 0!==t?t:a(e,"attributes.settings.top_hole")}})):[]);case 12:case"end":return e.stop()}}),e,null,[[2,8]])})));return function(t){return e.apply(this,arguments)}}(),f=function(){var e=t(r.mark((function e(a,o){var s,u,f,b;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,l(a);case 2:if(s=e.sent,u=s.find((function(e){return e.id===o})),f=u&&c(u,"topHole")){e.next=7;break}return e.abrupt("return",s);case 7:return e.next=9,Promise.all(s.map(function(){var e=t(r.mark((function e(t){var n,a;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,c(t,"topHole");case 3:if(!(n=e.sent)){e.next=13;break}return e.t0=parseFloat,e.next=8,p(f,n);case 8:return e.t1=e.sent,a=(0,e.t0)(e.t1),e.abrupt("return",i(i({},t),{},{distance:parseFloat(a.toFixed(2))}));case 13:return e.abrupt("return",t);case 14:e.next=19;break;case 16:return e.prev=16,e.t2=e.catch(0),e.abrupt("return",t);case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t){return e.apply(this,arguments)}}()));case 9:return b=e.sent,e.abrupt("return",n(b,"distance"));case 11:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}();export{f as getCoordinatedWells};
//# sourceMappingURL=getCoordinatedWells.js.map
