"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/regenerator"),n=require("lodash"),a=require("../constants.js"),s=require("../../../clients/jsonApi/index.js"),u=require("../../../utils/index.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(e),c=o(t),p=o(r);function l(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 f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){c.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var d=u.mapbox.getAssetV2Coordinates,b=u.mapbox.getDistanceByCoordinates;function O(e){return v.apply(this,arguments)}function v(){return(v=i.default(p.default.mark((function e(t){var r;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=null,e.prev=1,e.next=4,s.getAssets({ids:t,fields:["asset.name","asset.top_hole","asset.settings"]});case 4:r=e.sent,e.next=10;break;case 7:e.prev=7,e.t0=e.catch(1),console.error(e.t0);case 10: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 11:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function y(){return y=i.default(p.default.mark((function e(t,r){var a,s,u,o;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,O(t);case 2:if(a=e.sent,s=a.find((function(e){return e.id===r})),u=s&&d(s,"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(p.default.mark((function e(t){var r,n;return p.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,d(t,"topHole");case 3:if(!(r=e.sent)){e.next=13;break}return e.t0=parseFloat,e.next=8,b(u,r);case 8:return e.t1=e.sent,n=(0,e.t0)(e.t1),e.abrupt("return",f(f({},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)}))),y.apply(this,arguments)}exports.getCoordinatedWells=function(e,t){return y.apply(this,arguments)},exports.getMobileOperatingSystem=function(){var e=navigator.userAgent||window.opera;return/windows phone/i.test(e)?a.WINDOWS_PHONE:/android/i.test(e)?a.ANDROID_DEVICE:/iPad|iPhone|iPod/.test(e)&&!window.MSStream?a.IOS_DEVICE:a.OTHER_DEVICE};
