'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _constants = require('../../constants');

var _alerts = require('../actions/alerts');

var alertTimerMiddleware = function alertTimerMiddleware(store) {
  return function (next) {
    return function (action) {
      var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : setTimeout;

      if (action && action.type === _constants.ADD_ALERT && action.payload.removeIn) {
        var remove = function remove() {
          store.dispatch((0, _alerts.removeAlert)(action.payload.uuid));
        };

        // injected for testing
        delay(remove, action.payload.removeIn);
      }

      return next(action);
    };
  };
};

exports.default = alertTimerMiddleware;