'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _reactRouterDom = require('react-router-dom');

var _CancelButton = require('../navigation/CancelButton');

var _CancelButton2 = _interopRequireDefault(_CancelButton);

var _CloseButton = require('../navigation/CloseButton');

var _CloseButton2 = _interopRequireDefault(_CloseButton);

var _UnrelateButton = require('./UnrelateButton');

var _UnrelateButton2 = _interopRequireDefault(_UnrelateButton);

var _ButtonBar = require('../../../styles/cspace-ui/ButtonBar.css');

var _ButtonBar2 = _interopRequireDefault(_ButtonBar);

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

var messages = (0, _reactIntl.defineMessages)({
  open: {
    'id': 'relationButtonBar.open',
    'defaultMessage': 'Open'
  }
});

var propTypes = {
  isUnrelatable: _propTypes2.default.bool,
  // TODO: These uses aren't properly detected. Try updating eslint-plugin-react.
  /* eslint-disable react/no-unused-prop-types */
  object: _propTypes2.default.shape({
    csid: _propTypes2.default.string,
    recordType: _propTypes2.default.string
  }),
  /* eslint-enable react/no-unused-prop-types */
  onCancelButtonClick: _propTypes2.default.func,
  onCloseButtonClick: _propTypes2.default.func,
  onUnrelateButtonClick: _propTypes2.default.func
};

function RelationButtonBar(props) {
  var isUnrelatable = props.isUnrelatable,
      object = props.object,
      onCancelButtonClick = props.onCancelButtonClick,
      onCloseButtonClick = props.onCloseButtonClick,
      onUnrelateButtonClick = props.onUnrelateButtonClick;


  var objectCsid = object ? object.csid : undefined;

  var cancelButton = objectCsid ? null : _react2.default.createElement(_CancelButton2.default, { onClick: onCancelButtonClick });
  var closeButton = objectCsid ? _react2.default.createElement(_CloseButton2.default, { onClick: onCloseButtonClick }) : null;

  var unrelateButton = void 0;

  if (objectCsid) {
    unrelateButton = _react2.default.createElement(_UnrelateButton2.default, {
      isUnrelatable: isUnrelatable,
      onClick: onUnrelateButtonClick
    });
  }

  var openLink = void 0;

  if (objectCsid) {
    openLink = _react2.default.createElement(
      _reactRouterDom.Link,
      { to: '/record/' + object.recordType + '/' + object.csid },
      _react2.default.createElement(_reactIntl.FormattedMessage, messages.open)
    );
  }

  return _react2.default.createElement(
    'div',
    { className: _ButtonBar2.default.common },
    openLink,
    cancelButton,
    unrelateButton,
    closeButton
  );
}

RelationButtonBar.propTypes = propTypes;