'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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _flexboxReact = require('flexbox-react');

var _flexboxReact2 = _interopRequireDefault(_flexboxReact);

var _semanticUiReact = require('semantic-ui-react');

var _getAlertIconClassName = require('../../util/getAlertIconClassName');

var _componentFactory = require('../../util/component-factory.js');

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; }

var NotificationMessage = function NotificationMessage(props) {
  var notification = props.notification,
      onNotificationClicked = props.onNotificationClicked,
      onClearNotification = props.onClearNotification,
      rest = _objectWithoutProperties(props, ['notification', 'onNotificationClicked', 'onClearNotification']);

  var id = notification.id,
      type = notification.type,
      title = notification.title,
      description = notification.description,
      timeStamp = notification.timeStamp,
      isMsgRead = notification.isMsgRead;

  var icon = (0, _getAlertIconClassName.getAlertIconClassName)(type);
  var isReadStyle = isMsgRead ? 'normal' : 'bold';

  function handleNotificationClicked(notification) {
    onNotificationClicked(notification);
  }

  function handleClearClicked(e, notification) {
    onClearNotification(notification);
    e.stopPropagation();
  }

  return _react2.default.createElement(
    _flexboxReact2.default,
    _extends({
      id: id,
      onClick: function onClick() {
        return handleNotificationClicked(notification);
      },
      flexDirection: 'column',
      flexGrow: 1,
      className: 'column singleNotification'
    }, rest),
    _react2.default.createElement(
      _flexboxReact2.default,
      { title: title },
      _react2.default.createElement(_semanticUiReact.Icon, { className: 'text-large notificationIcon ' + type + ' ' + icon }),
      _react2.default.createElement(
        _flexboxReact2.default,
        { flexDirection: 'column', className: 'notificationContent' },
        _react2.default.createElement(
          'div',
          {
            className: 'notificationTitle',
            style: { fontWeight: isReadStyle }
          },
          title
        ),
        _react2.default.createElement(
          'div',
          { className: 'notificationDesc' },
          description
        ),
        _react2.default.createElement(
          'div',
          { className: 'notificationActions' },
          _react2.default.createElement(
            'a',
            {
              className: 'notificationClear',
              onClick: function onClick(e) {
                return handleClearClicked(e, notification);
              }
            },
            'Clear'
          )
        )
      ),
      _react2.default.createElement(
        'div',
        { className: 'notificationTime' },
        (0, _componentFactory.getRelativeTime)(timeStamp)
      )
    )
  );
};

NotificationMessage.defaultProps = {
  title: '',
  description: '',
  icon: ''
};

NotificationMessage.propTypes = {
  title: _propTypes2.default.string,
  description: _propTypes2.default.string
};

exports.default = NotificationMessage;
//# sourceMappingURL=NotificationMessage.js.map