'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactIntl = require('react-intl');

var _deprecated = require('../../../images/deprecated.svg');

var _deprecated2 = _interopRequireDefault(_deprecated);

var _locked = require('../../../images/locked.svg');

var _locked2 = _interopRequireDefault(_locked);

var _replicated = require('../../../images/replicated.svg');

var _replicated2 = _interopRequireDefault(_replicated);

var _WorkflowStateIcon = require('../../../styles/cspace-ui/WorkflowStateIcon.css');

var _WorkflowStateIcon2 = _interopRequireDefault(_WorkflowStateIcon);

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

var messages = (0, _reactIntl.defineMessages)({
  deprecated: {
    'id': 'workflowStateIcon.deprecated',
    'defaultMessage': 'Deprecated'
  },
  locked: {
    'id': 'workflowStateIcon.locked',
    'defaultMessage': 'Locked'
  },
  replicated: {
    'id': 'workflowStateIcon.replicated',
    'defaultMessage': 'Replicated'
  }
});

var images = {
  replicated: _replicated2.default,
  deprecated: _deprecated2.default,
  locked: _locked2.default
};

var propTypes = {
  intl: _reactIntl.intlShape,
  value: _propTypes2.default.string
};

function WorkflowStateIcon(props) {
  var intl = props.intl,
      value = props.value;


  if (!value) {
    return null;
  }

  var icons = [];

  Object.keys(images).forEach(function (state) {
    if (value.includes(state)) {
      var src = images[state];
      var message = messages[state];
      var desc = message ? intl.formatMessage(message) : state;

      icons.push(_react2.default.createElement('img', { key: state, alt: desc, src: src, title: desc }));
    }
  });

  if (icons.length === 0) {
    return null;
  }

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

WorkflowStateIcon.propTypes = propTypes;

exports.default = (0, _reactIntl.injectIntl)(WorkflowStateIcon);