'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; }; /* global cspaceUI */
/* The cspaceUI global variable is set by webpack (in non-test builds). See webpack.config.js. */

exports.default = Footer;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _Footer = require('../../../styles/cspace-ui/Footer.css');

var _Footer2 = _interopRequireDefault(_Footer);

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

const messages = (0, _reactIntl.defineMessages)({
  copyright: {
    'id': 'footer.copyright',
    'defaultMessage': 'Copyright \xA9 {startYear}\u2013{endYear} CollectionSpace'
  },
  about: {
    'id': 'footer.about',
    'defaultMessage': 'About CollectionSpace'
  },
  feedback: {
    'id': 'footer.feedback',
    'defaultMessage': 'Leave Feedback'
  },
  feedbackUrl: {
    'id': 'footer.feedbackUrl',
    'defaultMessage': 'http://www.collectionspace.org/contact'
  },
  release: {
    'id': 'footer.release',
    'defaultMessage': 'Release {version}'
  },
  appName: {
    'id': 'footer.appName',
    'defaultMessage': 'UI'
  },
  version: {
    'id': 'footer.version',
    'defaultMessage': '{name} version {version}'
  }
});

const propTypes = {
  config: _propTypes2.default.object,
  intl: _reactIntl.intlShape.isRequired
};

const renderPluginInfo = (config, intl) => {
  const pluginInfo = config.pluginInfo;


  if (!pluginInfo) {
    return null;
  }

  return Object.keys(pluginInfo).map(name => {
    var _pluginInfo$name = pluginInfo[name];
    const pluginMessages = _pluginInfo$name.messages,
          version = _pluginInfo$name.version;


    return _react2.default.createElement(
      'li',
      { key: name },
      _react2.default.createElement(_reactIntl.FormattedMessage, _extends({}, messages.version, {
        values: {
          version,
          name: intl.formatMessage(pluginMessages.name)
        }
      }))
    );
  });
};

function Footer(props) {
  const config = props.config,
        intl = props.intl;


  const thisYear = new Date().getFullYear().toString();

  return _react2.default.createElement(
    'footer',
    { className: _Footer2.default.common },
    _react2.default.createElement(
      'ul',
      null,
      _react2.default.createElement(
        'li',
        null,
        _react2.default.createElement(_reactIntl.FormattedMessage, _extends({}, messages.copyright, {
          values: {
            startYear: '2009',
            endYear: thisYear
          }
        }))
      ),
      _react2.default.createElement(
        'li',
        null,
        _react2.default.createElement(
          'a',
          { href: 'http://www.collectionspace.org' },
          _react2.default.createElement(_reactIntl.FormattedMessage, messages.about)
        )
      ),
      _react2.default.createElement(
        'li',
        null,
        _react2.default.createElement(
          'a',
          { href: intl.formatMessage(messages.feedbackUrl) },
          _react2.default.createElement(_reactIntl.FormattedMessage, messages.feedback)
        )
      )
    ),
    _react2.default.createElement(
      'ul',
      null,
      _react2.default.createElement(
        'li',
        null,
        _react2.default.createElement(
          'a',
          { href: 'https://wiki.collectionspace.org/display/collectionspace/Release+5.0' },
          _react2.default.createElement(_reactIntl.FormattedMessage, _extends({}, messages.release, { values: { version: '5.0' } }))
        )
      ),
      _react2.default.createElement(
        'li',
        null,
        _react2.default.createElement(_reactIntl.FormattedMessage, _extends({}, messages.version, {
          values: {
            name: intl.formatMessage(messages.appName),
            version: typeof cspaceUI === 'undefined' ? '' : cspaceUI.packageVersion
          }
        }))
      ),
      renderPluginInfo(config, intl)
    )
  );
}

Footer.propTypes = propTypes;