"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = require("react");

var _reactRedux = require("react-redux");

var _requests = require("../selectors/requests");

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var hasWarned = false;

var noCutout = function noCutout() {
  if (!hasWarned) {
    console.warn("useLoader hook called without cutout selector, loader will never be dispatched.");
    hasWarned = true;
  }

  return true;
};

var useLoader = function useLoader(loadActions, cutoutSelector) {
  if (cutoutSelector === void 0) {
    cutoutSelector = noCutout;
  }

  var dispatch = (0, _reactRedux.useDispatch)();
  var needLogin = (0, _reactRedux.useSelector)(_requests.logoutSelector);
  var cutout = !!(0, _reactRedux.useSelector)(cutoutSelector, _reactRedux.shallowEqual) || needLogin;
  (0, _react.useEffect)(function () {
    var actions = Array.isArray(loadActions) ? loadActions : [loadActions];

    if (!cutout) {
      actions.forEach(function (action) {
        return dispatch(action);
      });
    }
  }, [dispatch, loadActions, cutout]);
};

__signature__(useLoader, "useDispatch{dispatch}\nuseSelector{needLogin}\nuseSelector{}\nuseEffect{}", function () {
  return [_reactRedux.useDispatch, _reactRedux.useSelector, _reactRedux.useSelector];
});

__signature__(useLoader, "useDispatch{dispatch}\nuseSelector{needLogin}\nuseSelector{}\nuseEffect{}", function () {
  return [_reactRedux.useDispatch, _reactRedux.useSelector, _reactRedux.useSelector];
});

var _default = useLoader;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(hasWarned, "hasWarned", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(noCutout, "noCutout", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(useLoader, "useLoader", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/hooks/useLoader.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(hasWarned, "hasWarned", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(noCutout, "noCutout", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(useLoader, "useLoader", "/home/vsts/work/1/s/src/hooks/useLoader.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/hooks/useLoader.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();