"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/asyncToGenerator"),r=require("@babel/runtime/regenerator"),n=require("lodash"),a=require("../../../clients/jsonApi/index.js"),u=require("../../../utils/index.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(e),i=s(t),c=s(r);function p(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 l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){o.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var f=u.mapbox.getAssetV2Coordinates,b=u.mapbox.getDistanceByCoordinates,d=function(){var e=i.default(c.default.mark((function e(t){var r;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=null,null==t||!t.length){e.next=11;break}return e.prev=2,e.next=5,a.getAssets({ids:t,fields:["asset.name","asset.top_hole","asset.settings"]});case 5:r=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",r?r.data.map((function(e){var t;return{id:Number(e.id),name:n.get(e,"attributes.name"),topHole:null!==(t=n.get(e,"attributes.top_hole"))&&void 0!==t?t:n.get(e,"attributes.settings.top_hole")}})):[]);case 12:case"end":return e.stop()}}),e,null,[[2,8]])})));return function(t){return e.apply(this,arguments)}}(),v=function(){var e=i.default(c.default.mark((function e(t,r){var a,u,s,o;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,d(t);case 2:if(a=e.sent,u=a.find((function(e){return e.id===r})),s=u&&f(u,"topHole")){e.next=7;break}return e.abrupt("return",a);case 7:return e.next=9,Promise.all(a.map(function(){var e=i.default(c.default.mark((function e(t){var r,n;return c.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f(t,"topHole");case 3:if(!(r=e.sent)){e.next=13;break}return e.t0=parseFloat,e.next=8,b(s,r);case 8:return e.t1=e.sent,n=(0,e.t0)(e.t1),e.abrupt("return",l(l({},t),{},{distance:parseFloat(n.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 o=e.sent,e.abrupt("return",n.sortBy(o,"distance"));case 11:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}();exports.getCoordinatedWells=v;
//# sourceMappingURL=getCoordinatedWells.js.map
