"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/slicedToArray"),t=require("@babel/runtime/helpers/toConsumableArray"),n=require("react"),u=require("lodash/isEmpty"),a=require("lodash/isEqual"),i=require("lodash/omit"),o=require("../../constants.js"),l=require("../../stores/filter-store/useFilterStore.js");require("../../stores/company-safeguard/CompanySafeguardContext.js");var s=require("../../stores/company-safeguard/useCompanySafeguard.js"),f=require("../../stores/filter-store/types.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(e),p=c(r),m=c(t),y=c(u),b=c(a),g=c(i);function F(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 O(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?F(Object(t),!0).forEach((function(r){d.default(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):F(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var j=["hasUserConfirmedAllCompaniesLoadAll"].concat(m.default(f.SELECTION_FILTER_KEYS));exports.useFilterHandlers=function(){var e=s.useCompanySafeguard(),r=e.isSafeguardReady,t=e.targetCompanyId,u=l.useFilterStore((function(e){return e.filters})),a=l.useFilterStore((function(e){return e.defaultFilters})),i=l.useFilterStore((function(e){return e.tempFilters})),f=l.useFilterStore((function(e){return e.setFilter})),c=l.useFilterStore((function(e){return e.setFilters})),m=l.useFilterStore((function(e){return e.resetFilterCriteria})),F=n.useState({}),S=p.default(F,2),h=S[0],C=S[1],q=n.useMemo((function(){if(!r)return!0;if(!y.default(i))return!1;var e=t?O(O({},a),{},{companyId:t}):a,n=g.default(u,j),o=g.default(e,j);return b.default(n,o)}),[u,i,a,r,t]),v=n.useCallback((function(){m("manual_ui"),t&&f("companyId",t,"manual_ui")}),[m,f,t]);return{errors:h,isAtDefaultState:q,handleChangeFilter:n.useCallback((function(e,r){e===o.FilterType.sideTracks||e===o.FilterType.drillingWells||null!=r?f(e,r,"manual_ui"):c(g.default(null!=u?u:{},[e]),"manual_ui")}),[u,f,c]),handleCustomDateChange:function(e){return function(r){if(r&&r.isValid()){var t=r.unix(),n=!1;"timeRangeFrom"===e&&u.timeRangeTo?n=t>=u.timeRangeTo:"timeRangeTo"===e&&u.timeRangeFrom&&(n=t<=u.timeRangeFrom),C(n?d.default({},e,!0):{}),f(e,t,"manual_ui")}}},handleResetToDefaults:v}};
//# sourceMappingURL=useFilterHandlers.js.map
