'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

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

var _TitleBar = require('../sections/TitleBar');

var _TitleBar2 = _interopRequireDefault(_TitleBar);

var _recordDataHelpers = require('../../helpers/recordDataHelpers');

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

// import styles from '../../../styles/cspace-ui/RecordTitleBar.css';

var propTypes = {
  data: _react.PropTypes.instanceOf(_immutable2.default.Map),
  // isReadPending: PropTypes.bool,
  recordType: _react.PropTypes.string
};

var contextTypes = {
  config: _react.PropTypes.object
};

function RecordTitleBar(props, context) {
  var data = props.data,
      recordType = props.recordType;
  var config = context.config;


  var recordTypeConfig = config.recordTypes[recordType];

  if (!recordTypeConfig) {
    return null;
  }

  var cspaceDocument = data ? data.get(_recordDataHelpers.DOCUMENT_PROPERTY_NAME) : undefined;

  var title = recordTypeConfig.title(cspaceDocument);
  var subtitle = _react2.default.createElement(_reactIntl.FormattedMessage, recordTypeConfig.messages.record.name);

  return _react2.default.createElement(_TitleBar2.default, {
    title: title,
    subtitle: subtitle
  });
}

RecordTitleBar.propTypes = propTypes;
RecordTitleBar.contextTypes = contextTypes;