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