'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

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

var styles = {
  groupText: {
    fontSize: '0.875em',
    color: 'rgba(0, 0, 0, 0.541176)'
  }
};

var FormattedFieldname = function FormattedFieldname(_ref) {
  var fieldname = _ref.fieldname,
      children = _ref.children,
      intl = _ref.intl;

  if (!fieldname) return null;
  var parts = fieldname.split('.');
  var message = void 0;
  if (parts.length === 1) {
    message = (0, _intl_helpers.createMessage)('field_key')(fieldname);
    if (typeof children === 'function') {
      return children(intl.formatMessage(message));
    } else {
      return _react2.default.createElement(_reactIntl.FormattedMessage, message);
    }
  }
  if (typeof children === 'function') {
    return children(parts.join(' / '));
  }
  var groupText = parts.slice(0, -1).map(function (t) {
    return intl.formatMessage((0, _intl_helpers.createMessage)('field_key')(t)) + ' / ';
  }).join('');
  var fieldText = intl.formatMessage((0, _intl_helpers.createMessage)('field_key')(parts.slice(-1)[0]));
  return _react2.default.createElement(
    'span',
    { title: groupText + fieldText },
    _react2.default.createElement(
      'span',
      { style: styles.groupText },
      groupText
    ),
    _react2.default.createElement(
      'span',
      { style: styles.fieldText },
      fieldText
    )
  );
};

exports.default = (0, _reactIntl.injectIntl)(FormattedFieldname);
//# sourceMappingURL=FormattedFieldname.js.map