import r from"@babel/runtime/helpers/slicedToArray";import{useState as e,useCallback as n,useMemo as o,useEffect as t}from"react";import{usePickerPropsStore as i}from"../stores/picker-props-store/usePickerPropsStore.js";import{useFilterStore as u}from"../stores/filter-store/useFilterStore.js";var l=function(r,e){if(0===e.length)return null;var n=void 0!==r?Number(r):void 0;return void 0!==n&&!Number.isNaN(n)&&e.some((function(r){return r.id===n}))?n:e[0].id},a=function(a){var s=a.companies,f=a.canViewCompanies,d=a.canViewCompaniesLoading,c=i((function(r){return r.isLoadAllWells})),m=i((function(r){var e;return null===(e=r.defaultSubjectWell)||void 0===e?void 0:e.companyId})),p=u((function(r){return r.filters.companyId})),v=u((function(r){return r.setFilter})),g=e(null),y=r(g,2),b=y[0],I=y[1],S=n((function(){I(null)}),[]),h=o((function(){if(!c||!f||0===s.length)return null;var r=l(m,s);return null!==r?[r]:null}),[c,f,s,m]);return t((function(){if(c){if(!d&&f&&0!==s.length&&void 0===p){var r=l(m,s);null!==r&&(v("companyId",[r]),I([r]))}}else I(null)}),[c,p,d,f,s,m,v]),{isSafeguardReady:!(d||f&&c&&void 0===p),safeguardAppliedCompanyId:b,targetCompanyId:h,resetSafeguard:S}};export{a as useLoadAllWellsCompanySafeguard};
//# sourceMappingURL=useLoadAllWellsCompanySafeguard.js.map
