'use strict';

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

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _notificationHelpers = require('../helpers/notificationHelpers');

var _notificationHelpers2 = _interopRequireDefault(_notificationHelpers);

var _notification = require('../actions/notification');

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

const showNotification = (state, action) => {
  const notificationDescriptor = action.payload;

  let notificationID = action.meta.notificationID;


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

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

const removeNotification = (state, action) => {
  const notificationID = action.meta.notificationID;


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

exports.default = (state = _immutable2.default.Map({ notifications: _immutable2.default.OrderedMap() }), action) => {
  switch (action.type) {
    case _notification.SHOW_NOTIFICATION:
      return showNotification(state, action);
    case _notification.REMOVE_NOTIFICATION:
      return removeNotification(state, action);
    case _notification.OPEN_MODAL:
      return state.set('modal', action.meta.name);
    case _notification.CLOSE_MODAL:
      return state.delete('modal');
    default:
      return state;
  }
};

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