'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _formatLocation = require('../../util/formatLocation');

var _formatLocation2 = _interopRequireDefault(_formatLocation);

var _filter_helpers = require('../../util/filter_helpers');

var _intl_helpers = require('../../util/intl_helpers');

var _constants = require('../../constants');

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

var FormattedValue = function FormattedValue(_ref) {
  var value = _ref.value,
      type = _ref.type,
      _ref$coordFormat = _ref.coordFormat,
      coordFormat = _ref$coordFormat === undefined ? _constants.FORMATS_DEG_MIN_SEC : _ref$coordFormat;

  switch (type) {
    case _constants.FIELD_TYPE_DATE:
      return _react2.default.createElement(_reactIntl.FormattedDate, {
        value: (0, _filter_helpers.parseDate)(value),
        year: 'numeric',
        month: 'long',
        day: '2-digit' });
    case _constants.FIELD_TYPE_ARRAY:
      return (value || []).map(function (v) {
        return _react2.default.createElement(_reactIntl.FormattedMessage, (0, _intl_helpers.createMessage)('field_value')(value));
      });
    case _constants.FIELD_TYPE_LOCATION:
      return _react2.default.createElement(
        'span',
        null,
        (0, _formatLocation2.default)(value, coordFormat)
      );
    case _constants.FIELD_TYPE_NUMBER:
      return _react2.default.createElement(
        'span',
        null,
        value === _constants.UNDEFINED_KEY ? '' : value + ''
      );
    case _constants.FIELD_TYPE_UUID:
    case _constants.FIELD_TYPE_FILENAME:
      return _react2.default.createElement(
        'span',
        null,
        value
      );
    case _constants.FIELD_TYPE_IMAGE:
    case _constants.FIELD_TYPE_VIDEO:
    case _constants.FIELD_TYPE_MEDIA:
    case _constants.FIELD_TYPE_AUDIO:
    case _constants.FIELD_TYPE_LINK:
      return _react2.default.createElement(
        'a',
        { href: value, target: '_blank' },
        value
      );
    default:
      return _react2.default.createElement(_reactIntl.FormattedMessage, (0, _intl_helpers.createMessage)('field_value')(value));
  }
};

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