import e from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import n from"@babel/runtime/regenerator";import{useState as i,useEffect as u}from"react";import{uniq as s}from"lodash";import{isAssetVisibleToUser as o}from"../../../../utils/isAssetVisibleToUser.js";import{useIsAdmin as a}from"../../../../hooks/useIsAdmin.js";import{countFilteredItems as c,isFiniteNumber as f,hasActiveWellFilters as l,groupByType as p,computeRigCheckedState as m,fetchWellDataMap as b,fetchRigWellsMap as d}from"./useAssetsData.utils.js";import{doesWellPassFilters as h,EXCLUDE_RIG_NAME_FILTER as y}from"../../../../utils/doesWellPassFilters.js";function g(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function v(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}var w=function(e,r){return"well"!==e.type||o(e,r)},O=function(){var e=t(n.mark((function e(r,t,i,u,o){var a,c,g,w,O,j,k,x,A;return n.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=r.filter((function(e){return"well"===e.type&&f(e.redirectAssetId)})),c=s(t.map((function(e){return Number(e.asset_id)}))),e.next=4,d(c,o);case 4:if(g=e.sent,w=r.map((function(e){if("rig"!==e.type)return e;var r=g.get(Number(e.asset_id))||[];return m(e,r,u)})),l(i)){e.next=8;break}return e.abrupt("return",p(w));case 8:return O=s(a.map((function(e){return Number(e.redirectAssetId)}))),e.next=11,b(O);case 11:return j=e.sent,k=new Set(O.filter((function(e){var r=j.get(e);return r&&h(r,i)}))),x=new Set(c.filter((function(e){return(g.get(e)||[]).some((function(e){return h(e,i,y)}))}))),A=r.filter((function(e){return"well"!==e.type||k.has(Number(e.redirectAssetId))})).map((function(e){if("rig"!==e.type)return e;var r=Number(e.asset_id),t=g.get(r)||[];if(!x.has(r)){var n=0===t.length?"This rig has no wells":"No wells match current filters";return v(v({},e),{},{checked:!1,disabledReason:n})}var s=t.filter((function(e){return h(e,i,y)}));return m(e,s,u)})),e.abrupt("return",p(A));case 16:case"end":return e.stop()}}),e)})));return function(r,t,n,i,u){return e.apply(this,arguments)}}(),j=function(r,s,o,m,b,d){var h,y=i([]),g=e(y,2),j=g[0],k=g[1],x=i(!1),A=e(x,2),P=A[0],N=A[1],D=a()&&null!==(h=null==m?void 0:m.showHiddenWells)&&void 0!==h&&h;return u((function(){var e=!1,i=function(){var i=t(n.mark((function t(){var i,u,a,h,y,g,j;return n.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=r.map((function(e){return v(v({},e),{},{checked:"rig"!==e.type&&o.includes(e.redirectAssetId)})})),u=null==m?void 0:m.rigName,a=Array.isArray(u)&&u.length>0,0!==(h=i.filter((function(e){return(!s||e.type===s)&&(!("rig"===e.type&&a&&!u.includes(e.name))&&!!w(e,D))}))).length){t.next=7;break}return e||(k([]),N(!1),d(0)),t.abrupt("return");case 7:if(0!==(y=h.filter((function(e){return"rig"===e.type&&f(e.asset_id)}))).length||l(m)){t.next=11;break}return e||(g=p(h),k(g),N(!1),d(c(g))),t.abrupt("return");case 11:return N(!0),t.prev=12,t.next=15,O(h,y,m,o,b);case 15:j=t.sent,e||(k(j),d(c(j))),t.next=23;break;case 19:t.prev=19,t.t0=t.catch(12),console.error(t.t0),e||k([]);case 23:return t.prev=23,e||N(!1),t.finish(23);case 26:case"end":return t.stop()}}),t,null,[[12,19,23,26]])})));return function(){return i.apply(this,arguments)}}();return i(),function(){e=!0}}),[r,s,o,m,b,d,D]),{searchResult:j,isFiltering:P}};export{j as useAssetsFilter};
//# sourceMappingURL=useAssetsFilter.js.map
