import e from"@babel/runtime/helpers/asyncToGenerator";import t from"@babel/runtime/regenerator";import{useCallback as r}from"react";import{uniq as n}from"lodash";import{SEARCH_CATEGORIES as i}from"../AdvancedSearch/constants.js";import{EXCLUDE_RIG_NAME_FILTER as s,doesWellPassVisibilityAndFilters as a}from"../../../utils/doesWellPassFilters.js";import"@babel/runtime/helpers/toConsumableArray";import"@babel/runtime/helpers/defineProperty";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import"../../../../../clients/jsonApi/index.js";import"../../../../../clients/subscriptions/constants.js";import"../../../../../clients/subscriptions.v1.js";import"../../../../../clients/subscriptions/subscriptions-client.factory.js";import"../../../../../clients/api/apiCore.js";import"../../../../../clients/constants.js";import"../../../../../clients/sso/auth0.js";import"../../../../../clients/sso/oauth2.js";import"../../../../../clients/api/rateLimiter.js";import{fetchWellsByRigIds as o}from"../../../api/wells/fetchWellsByRigIds.js";import"../../../constants.js";import"../../../api/shared/dataFormatter.js";import"@babel/runtime/helpers/slicedToArray";import"../../../../../utils/index.js";import{showInfoNotification as u}from"../../../../../utils/notificationToasts.js";var l="No wells match current filters.",c=function(l){var c=l.filters,p=l.wells,f=l.maxOffsetWellNumber,m=l.includeHidden,h=l.fetchSearchedWells,b=l.setIsTableLoading,d=l.setSelectedWells,x=l.setLoadingAssetIds,g=l.setCurrentSelectionZone,j=l.markUserEdit,k=l.searchGenerationRef,v=r(function(){var r=e(t.mark((function e(r,l,v,w){var y,S,A,W,I,N,T,C,F,L,G,P,R,B,E,H,M,O;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(j(),g(null),y=k.current,S=function(){return k.current!==y},A=[],W=null==c?void 0:c.companyId,I=Array.isArray(W)&&W.length>0?W:null,N=v!==i.well.name?s:void 0,T=function(e){return a(e,c,m,N)},v!==i.well.name){e.next=13;break}A=l,e.next=40;break;case 13:if(w&&0!==w.length){e.next=15;break}return e.abrupt("return");case 15:return b(!0),e.prev=16,e.next=19,o(w,I);case 19:if(C=e.sent,!S()){e.next=22;break}return e.abrupt("return");case 22:if(!r){e.next=30;break}if(F=C.filter(T),0!==(A=F.map((function(e){return e.id}))).length){e.next=28;break}return u("No wells match current filters."),e.abrupt("return");case 28:e.next=31;break;case 30:A=C.map((function(e){return e.id}));case 31:e.next=37;break;case 33:return e.prev=33,e.t0=e.catch(16),console.error("Failed to fetch wells for rigs:",e.t0),e.abrupt("return");case 37:return e.prev=37,b(!1),e.finish(37);case 40:if(0!==A.length){e.next=42;break}return e.abrupt("return");case 42:if(L=new Set(A),G=(p||[]).filter((function(e){return L.has(e.id)&&(!r||T(e))})),P=[],!(r&&G.length<A.length)){e.next=63;break}if(R=new Set(G.map((function(e){return e.id}))),!((B=A.filter((function(e){return!R.has(e)}))).length>0)){e.next=63;break}return x((function(e){return e.concat(B)})),e.next=52,h(B);case 52:if(E=e.sent,H=new Set(B),M=function(e){var t=e.filter((function(e){return!H.has(e)}));return t.length===e.length?e:t},!S()){e.next=58;break}return x(M),e.abrupt("return");case 58:if(P=E.filter(T),x(M),0!==G.length||0!==P.length){e.next=63;break}return u("No wells match current filters."),e.abrupt("return");case 63:if(!S()){e.next=65;break}return e.abrupt("return");case 65:r?(O=G.concat(P),d((function(e){var t=new Set(e.map((function(e){return e.id}))),r=O.filter((function(e){return!t.has(e.id)})).slice(0,Math.max(0,f-e.length));return r.length>0?e.concat(r):e}))):d((function(e){return n(e.filter((function(e){var t=e.id;return!L.has(t)})))}));case 66:case"end":return e.stop()}}),e,null,[[16,33,37,40]])})));return function(e,t,n,i){return r.apply(this,arguments)}}(),[c,p,f,m,h,b,d,x,g,j,k]);return v};export{l as NO_WELLS_MATCH_FILTERS_MESSAGE,c as useAdvancedSearchHandler};
//# sourceMappingURL=useAdvancedSearchHandler.js.map
