'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

exports.default = NotificationBar;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _Notification = require('./Notification');

var _Notification2 = _interopRequireDefault(_Notification);

var _ValidationErrorNotificationContainer = require('../../containers/notification/ValidationErrorNotificationContainer');

var _ValidationErrorNotificationContainer2 = _interopRequireDefault(_ValidationErrorNotificationContainer);

var _NotificationBar = require('../../../styles/cspace-ui/NotificationBar.css');

var _NotificationBar2 = _interopRequireDefault(_NotificationBar);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

const propTypes = {
  close: _propTypes2.default.func,
  notifications: _propTypes2.default.instanceOf(_immutable2.default.OrderedMap)
};

function NotificationBar(props) {
  const close = props.close,
        notifications = props.notifications;


  const children = notifications.entrySeq().reverse().map(entry => {
    var _entry = _slicedToArray(entry, 2);

    const id = _entry[0],
          descriptor = _entry[1];

    const type = descriptor.type,
          remainingProps = _objectWithoutProperties(descriptor, ['type']);

    const NotificationComponent = type === 'validation' ? _ValidationErrorNotificationContainer2.default : _Notification2.default;

    return _react2.default.createElement(NotificationComponent, _extends({
      key: id,
      id: id,
      close: close
    }, remainingProps));
  }).toJS();

  return _react2.default.createElement(
    'div',
    { className: _NotificationBar2.default.common },
    children
  );
}

NotificationBar.propTypes = propTypes;