'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _SaveButton = require('../../../styles/cspace-ui/SaveButton.css');

var _SaveButton2 = _interopRequireDefault(_SaveButton);

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

var Button = _cspaceInput.components.Button;


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

var propTypes = {
  isModified: _react.PropTypes.bool,
  isSavePending: _react.PropTypes.bool,
  save: _react.PropTypes.func
};

function SaveButton(props) {
  var isModified = props.isModified,
      isSavePending = props.isSavePending,
      save = props.save;


  var className = void 0;

  if (isSavePending) {
    className = _SaveButton2.default.pending;
  } else if (isModified) {
    className = _SaveButton2.default.normal;
  } else {
    className = _SaveButton2.default.done;
  }

  return _react2.default.createElement(
    Button,
    {
      className: className,
      disabled: isSavePending,
      icon: true,
      name: 'save',
      onClick: save
    },
    _react2.default.createElement(_reactIntl.FormattedMessage, messages.label)
  );
}

SaveButton.propTypes = propTypes;