"use strict";

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

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

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

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

var _cspaceInput = require("cspace-input");

var _RevertButton = _interopRequireDefault(require("../../../styles/cspace-ui/RevertButton.css"));

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

const {
  Button
} = _cspaceInput.components;
const messages = (0, _reactIntl.defineMessages)({
  label: {
    "id": "revertButton.label",
    "defaultMessage": "Revert"
  }
});
const propTypes = {
  isModified: _propTypes.default.bool,
  isSavePending: _propTypes.default.bool,
  label: _propTypes.default.node,
  readOnly: _propTypes.default.bool,
  onClick: _propTypes.default.func
};

function RevertButton(props) {
  const {
    isModified,
    isSavePending,
    readOnly,
    onClick
  } = props;

  if (readOnly) {
    return null;
  }

  let {
    label
  } = props;

  if (!label) {
    label = _react.default.createElement(_reactIntl.FormattedMessage, messages.label);
  }

  return _react.default.createElement(Button, {
    className: _RevertButton.default.common,
    disabled: !isModified || isSavePending,
    icon: true,
    name: "revert",
    onClick: onClick
  }, label);
}

RevertButton.propTypes = propTypes;