"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

var _CancelButton = _interopRequireDefault(require("../navigation/CancelButton"));

var _CloseButton = _interopRequireDefault(require("../navigation/CloseButton"));

var _UnrelateButton = _interopRequireDefault(require("./UnrelateButton"));

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

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

const messages = (0, _reactIntl.defineMessages)({
  open: {
    "id": "relationButtonBar.open",
    "defaultMessage": "Open"
  }
});
const propTypes = {
  isUnrelatable: _propTypes.default.bool,
  // TODO: These uses aren't properly detected. Try updating eslint-plugin-react.

  /* eslint-disable react/no-unused-prop-types */
  object: _propTypes.default.shape({
    csid: _propTypes.default.string,
    recordType: _propTypes.default.string
  }),

  /* eslint-enable react/no-unused-prop-types */
  onCancelButtonClick: _propTypes.default.func,
  onCloseButtonClick: _propTypes.default.func,
  onUnrelateButtonClick: _propTypes.default.func
};

function RelationButtonBar(props) {
  const {
    isUnrelatable,
    object,
    onCancelButtonClick,
    onCloseButtonClick,
    onUnrelateButtonClick
  } = props;
  const objectCsid = object ? object.csid : undefined;
  const cancelButton = objectCsid ? null : /*#__PURE__*/_react.default.createElement(_CancelButton.default, {
    onClick: onCancelButtonClick
  });
  const closeButton = objectCsid ? /*#__PURE__*/_react.default.createElement(_CloseButton.default, {
    onClick: onCloseButtonClick
  }) : null;
  let unrelateButton;

  if (objectCsid) {
    unrelateButton = /*#__PURE__*/_react.default.createElement(_UnrelateButton.default, {
      isUnrelatable: isUnrelatable,
      onClick: onUnrelateButtonClick
    });
  }

  let openLink;

  if (objectCsid) {
    openLink = /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
      to: `/record/${object.recordType}/${object.csid}`
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, messages.open));
  }

  return /*#__PURE__*/_react.default.createElement("div", {
    className: _ButtonBar.default.common
  }, openLink, cancelButton, unrelateButton, closeButton);
}

RelationButtonBar.propTypes = propTypes;