"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/helpers/slicedToArray"),n=require("@babel/runtime/regenerator"),u=require("react"),a=require("lodash"),i=require("../utils/apiCalls.js"),c=require("../constants.js"),o=require("../../../utils/index.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=s(e),l=s(t),p=s(r),d=s(n);function b(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 v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?b(Object(r),!0).forEach((function(t){f.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):b(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var y=o.mapbox.getAssetV2Coordinates,h=o.mapbox.getDistanceByCoordinates,m=function(e){return Number.isFinite(e)?parseFloat(e.toFixed(2)):null};exports.useAdvancedWells=function(e,t,r,n,o,s){var b=u.useState(null),O=p.default(b,2),j=O[0],x=O[1],g=u.useState(null),w=p.default(g,2),E=w[0],P=w[1],q=u.useState(null),k=p.default(q,2),S=k[0],D=k[1],F=u.useRef({});function C(){return C=l.default(d.default.mark((function e(){var r,n,u;return d.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.find((function(e){return e.id===o})),(n=r&&y(r,"topHole"))||P(t),e.next=5,Promise.all(t.map(function(){var e=l.default(d.default.mark((function e(t){var r,u;return d.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,y(t,"topHole");case 3:if(!(r=e.sent)){e.next=13;break}return e.t0=parseFloat,e.next=8,h(n,r);case 8:return e.t1=e.sent,u=(0,e.t0)(e.t1),e.abrupt("return",v(v({},t),{},{distance:parseFloat(u.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 5:u=e.sent,P(u);case 7:case"end":return e.stop()}}),e)}))),C.apply(this,arguments)}function _(e){return A.apply(this,arguments)}function A(){return(A=l.default(d.default.mark((function t(r){var n,u,c,o;return d.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,i.fetchMetricsData(e,r,s);case 2:n=t.sent,u={},c=a.groupBy(n,"asset_id"),r.forEach((function(e){var t,r=null===(t=c[e])||void 0===t?void 0:t.reduce((function(e,t){var r=a.get(t,"data.value"),n=a.get(t,"data.key");return v(v({},e),{},f.default({},n,m(r)))}),{});u[e]=r})),F.current=v(v({},F.current),u),o=[],S.forEach((function(e){o.push(v(v({},e),F.current[e.id]))})),x(o);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}return u.useEffect((function(){t&&function(){C.apply(this,arguments)}()}),[t,o]),u.useEffect((function(){var e,t;E&&r&&n&&(e=r.filter((function(e){return e.value!==c.ALL_SECTION_KEY})),t=E.map((function(t){var r=e.filter((function(e){return(n[e.value]||[]).includes(t.id)})).map((function(e){return e.label}));return r.length>0?v(v({},t),{},f.default({},c.ColumnType.wellSection,r)):t})),D(t))}),[E,r,n]),u.useEffect((function(){if(S){var e=[];S.forEach((function(t){F.current[t.id]||e.push(t.id)})),_(e)}}),[S]),u.useEffect((function(){j&&_(j.map((function(e){return e.id})))}),[s]),j};
