"use strict";

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

var _react = _interopRequireWildcard(require("react"));

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

var _utils = require("../../utils");

var _toasts = require("../../actions/toasts");

var _ToastList = _interopRequireDefault(require("../ToastList"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(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 TOAST_TIMEOUT = 5; // seconds

exports.TOAST_TIMEOUT = TOAST_TIMEOUT;

var selectToasts = function selectToasts(state) {
  return state.getIn(["toasts", "queue"]).take(3);
};

var ConnectedToastList = function ConnectedToastList() {
  var dismissalTimer = (0, _react.useRef)();
  var toasts = (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(selectToasts));
  var dispatch = (0, _reactRedux.useDispatch)();
  var dismissToasts = toasts.length > 0;
  (0, _react.useEffect)(function () {
    if (dismissToasts) {
      dismissalTimer.current = window.setInterval(function () {
        return dispatch((0, _toasts.shiftToast)());
      }, TOAST_TIMEOUT * 1000);
    }

    return function () {
      window.clearInterval(dismissalTimer.current);
    };
  }, [dismissalTimer, dismissToasts, dispatch]);
  return /*#__PURE__*/_react.default.createElement(_ToastList.default, {
    toasts: toasts
  });
};

__signature__(ConnectedToastList, "useRef{dismissalTimer}\nuseSelector{}\nuseDispatch{dispatch}\nuseEffect{}", function () {
  return [_reactRedux.useSelector, _reactRedux.useDispatch];
});

__signature__(ConnectedToastList, "useRef{dismissalTimer}\nuseSelector{}\nuseDispatch{dispatch}\nuseEffect{}", function () {
  return [_reactRedux.useSelector, _reactRedux.useDispatch];
});

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

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

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(TOAST_TIMEOUT, "TOAST_TIMEOUT", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(selectToasts, "selectToasts", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(ConnectedToastList, "ConnectedToastList", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.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(TOAST_TIMEOUT, "TOAST_TIMEOUT", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(selectToasts, "selectToasts", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(ConnectedToastList, "ConnectedToastList", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/AppFrame/ConnectedToastList.js");
})();

;

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