'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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

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

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

var _RevertButton2 = _interopRequireDefault(_RevertButton);

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

const Button = _cspaceInput.components.Button;


const messages = (0, _reactIntl.defineMessages)({
  label: {
    'id': 'revertButton.label',
    'defaultMessage': 'Revert'
  }
});

const propTypes = {
  isModified: _propTypes2.default.bool,
  isSavePending: _propTypes2.default.bool,
  label: _propTypes2.default.node,
  readOnly: _propTypes2.default.bool,
  onClick: _propTypes2.default.func
};

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


  if (readOnly) {
    return null;
  }

  let label = props.label;


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

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

RevertButton.propTypes = propTypes;