'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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 }; }

var Button = _cspaceInput.components.Button;


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

var propTypes = {
  csid: _react.PropTypes.string,
  isModified: _react.PropTypes.bool,
  isSavePending: _react.PropTypes.bool,
  revert: _react.PropTypes.func
};

function RevertButton(props) {
  var csid = props.csid,
      isModified = props.isModified,
      isSavePending = props.isSavePending,
      revert = props.revert;


  if (!csid) {
    return null;
  }

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

RevertButton.propTypes = propTypes;