import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/regenerator";import{sortBy as n,get as o}from"lodash";import{WINDOWS_PHONE as a,ANDROID_DEVICE as s,IOS_DEVICE as i,OTHER_DEVICE as u}from"../constants.js";import{getAssets as c}from"../../../clients/jsonApi/index.js";import{mapbox as p}from"../../../utils/index.js";function f(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 r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?f(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var b=p.getAssetV2Coordinates,m=p.getDistanceByCoordinates;function d(){var e=navigator.userAgent||window.opera;return/windows phone/i.test(e)?a:/android/i.test(e)?s:/iPad|iPhone|iPod/.test(e)&&!window.MSStream?i:u}function h(e){return v.apply(this,arguments)}function v(){return(v=e(r.mark((function e(t){var n;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.prev=1,e.next=4,c({ids:t,fields:["asset.name","asset.top_hole","asset.settings"]});case 4:n=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",n?n.data.map((function(e){var t;return{id:Number(e.id),name:o(e,"attributes.name"),topHole:null!==(t=o(e,"attributes.top_hole"))&&void 0!==t?t:o(e,"attributes.settings.top_hole")}})):[]);case 11:case"end":return e.stop()}}),e,null,[[1,7]])})))).apply(this,arguments)}function y(e,t){return w.apply(this,arguments)}function w(){return w=e(r.mark((function t(o,a){var s,i,u,c;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h(o);case 2:if(s=t.sent,i=s.find((function(e){return e.id===a})),u=i&&b(i,"topHole")){t.next=7;break}return t.abrupt("return",s);case 7:return t.next=9,Promise.all(s.map(function(){var t=e(r.mark((function e(t){var n,o;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b(t,"topHole");case 3:if(!(n=e.sent)){e.next=13;break}return e.t0=parseFloat,e.next=8,m(u,n);case 8:return e.t1=e.sent,o=(0,e.t0)(e.t1),e.abrupt("return",l(l({},t),{},{distance:parseFloat(o.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(e){return t.apply(this,arguments)}}()));case 9:return c=t.sent,t.abrupt("return",n(c,"distance"));case 11:case"end":return t.stop()}}),t)}))),w.apply(this,arguments)}export{y as getCoordinatedWells,d as getMobileOperatingSystem};
