"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getNotifications = exports.getModal = exports.default = void 0;

var _immutable = _interopRequireDefault(require("immutable"));

var _notificationHelpers = _interopRequireDefault(require("../helpers/notificationHelpers"));

var _actionCodes = require("../constants/actionCodes");

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

const showNotification = (state, action) => {
  const notificationDescriptor = action.payload;
  let {
    notificationID
  } = action.meta;

  if (!notificationID) {
    notificationID = (0, _notificationHelpers.default)();
  }

  return state.setIn(['notifications', notificationID], notificationDescriptor);
};

const removeNotification = (state, action) => {
  const {
    notificationID
  } = action.meta;
  return state.deleteIn(['notifications', notificationID]);
};

var _default = function _default() {
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _immutable.default.Map({
    notifications: _immutable.default.OrderedMap()
  });
  let action = arguments.length > 1 ? arguments[1] : undefined;

  switch (action.type) {
    case _actionCodes.SHOW_NOTIFICATION:
      return showNotification(state, action);

    case _actionCodes.REMOVE_NOTIFICATION:
      return removeNotification(state, action);

    case _actionCodes.OPEN_MODAL:
      return state.set('modal', action.meta.name);

    case _actionCodes.CLOSE_MODAL:
      return state.delete('modal');

    default:
      return state;
  }
};

exports.default = _default;

const getModal = state => state.get('modal');

exports.getModal = getModal;

const getNotifications = state => state.get('notifications');

exports.getNotifications = getNotifications;