import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/toConsumableArray";import{useMemo as n}from"react";import{uniq as r,isEmpty as s}from"lodash";import{ALL_SECTION_KEY as l,COMPANY_PROVIDERS_FOR_IDAS as i,FilterType as a}from"../../constants.js";import{isXtoIdasPicker as o}from"../../utils/isXtoIdasPicker.js";import{buildOffsetSourceLabel as c}from"./buildOffsetSourceLabel.js";function u(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}var d=function(d){var f,h=d.externalOffsets,b=d.selectedWells,p=d.selectedWellsCount,O=d.selectedWellSection,g=d.subjectWellId,m=d.rawWellsWithSubject,v=d.maxOffsetSize,W=d.companyProvider,y=d.isWDUser,I=d.isManualWellsEnabled,j=d.hasValidAssetId,S=d.isAllWellsLoaded,w=d.filters,P=d.idasWellIds,D=d.owsWellIds,R=d.wellhubWellIds,k=d.savedIdasWellIds,E=d.savedOwsWellIds,L=d.savedWellhubWellIds,x=d.savedHandpickedWellIds,T=n((function(){return o({isWDUser:y,isManualWellsEnabled:I,companyProvider:W})}),[y,I,W]),U=n((function(){var e,n,s=r([].concat(t(k),t(E),t(L),t(x))).filter((function(e){return e!==g})),i=(null!==(e=null==h?void 0:h[l])&&void 0!==e?e:[]).filter((function(e){return null!=e&&e!==g})),a=new Set([].concat(t(b.map((function(e){return e.id}))),t(null!==(n=null==m?void 0:m.map((function(e){return e.id})))&&void 0!==n?n:[]))),o=T||S?i.filter((function(e){return a.has(e)})):i,c=new Set;null!=g&&c.add(g),o.slice(0,Math.max(0,v-1)).forEach((function(e){return c.add(e)}));var u=b.map((function(e){return e.id}));return{isSynced:u.length===c.size&&u.every((function(e){return c.has(e)})),hasResetTarget:o.length>0||s.length>0}}),[h,b,g,m,v,T,S,k,E,L,x]),A=U.isSynced,M=U.hasResetTarget,X=n((function(){return!!W&&i.includes(W)}),[W]),z=n((function(){return c({isWDUser:y,isIdasProvider:X,hasIdas:P.length>0,hasOws:D.length>0,hasWellhub:R.length>0})}),[y,X,P,D,R]).label,C=n((function(){var t=k.length+E.length+L.length>0?{hasIdas:k.length>0,hasOws:E.length>0,hasWellhub:L.length>0}:{hasIdas:P.length>0,hasOws:D.length>0,hasWellhub:R.length>0};return c(function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?u(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({isWDUser:y,isIdasProvider:X},t))}),[y,X,k,E,L,P,D,R]),H=C.label,V=z?"".concat(z,"."):"",q=H?"".concat(H,"."):"",B=n((function(){return y?P.length>0||D.length>0:R.length>0}),[y,R,P,D]);f=z?"Reset to Synced Offsets in ".concat(z):M?"Reset to Synced Offsets":"Reset Selection";var F=n((function(){return!!j&&(!(A||!(M||p>0))||(!(s(w)||null==w||!w[a.sideTracks])||O!==l))}),[j,M,A,p,w,O]);return{isSynced:A,isXtoProvider:X,isXtoIdas:T,syncedOffsetLabel:V,savedOffsetLabel:q,resetTooltipLabel:f,isResetVisible:F,hasOffsetSource:B,hasSavedHandpicked:x.length>0}};export{d as useSaveResetDerivedState};
//# sourceMappingURL=useSaveResetDerivedState.js.map
