"use strict";

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

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

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

var _immutable = _interopRequireDefault(require("immutable"));

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

var _cspaceLayout = require("cspace-layout");

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

var _SaveButton = _interopRequireDefault(require("../record/SaveButton"));

var _RevertButton = _interopRequireDefault(require("../record/RevertButton"));

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

const messages = (0, _reactIntl.defineMessages)({
  title: {
    "id": "confirmRecordNavigationModal.title",
    "defaultMessage": "Leave Record?"
  },
  prompt: {
    "id": "confirmRecordNavigationModal.prompt",
    "defaultMessage": "You're about to leave a record that has unsaved changes."
  },
  cancel: {
    "id": "confirmRecordNavigationModal.cancel",
    "defaultMessage": "Don't leave"
  },
  save: {
    "id": "confirmRecordNavigationModal.save",
    "defaultMessage": "Save and continue"
  },
  revert: {
    "id": "confirmRecordNavigationModal.revert",
    "defaultMessage": "Revert and continue"
  }
});
const propTypes = {
  isOpen: _propTypes.default.bool,
  isModified: _propTypes.default.bool,
  isSavePending: _propTypes.default.bool,
  validationErrors: _propTypes.default.instanceOf(_immutable.default.Map),
  onCancelButtonClick: _propTypes.default.func,
  onCloseButtonClick: _propTypes.default.func,
  onRevertButtonClick: _propTypes.default.func,
  onSaveButtonClick: _propTypes.default.func,
  onSaveButtonErrorBadgeClick: _propTypes.default.func
};

class ConfirmRecordNavigationModal extends _react.Component {
  constructor() {
    super();
    this.renderButtonBar = this.renderButtonBar.bind(this);
  }

  renderButtonBar() {
    const {
      isModified,
      isSavePending,
      validationErrors,
      onCancelButtonClick,
      onSaveButtonClick,
      onSaveButtonErrorBadgeClick,
      onRevertButtonClick
    } = this.props;
    return _react.default.createElement("div", null, _react.default.createElement(_CancelButton.default, {
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.cancel),
      onClick: onCancelButtonClick
    }), _react.default.createElement(_SaveButton.default, {
      isModified: isModified,
      isSavePending: isSavePending,
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.save),
      validationErrors: validationErrors,
      onClick: onSaveButtonClick,
      onErrorBadgeClick: onSaveButtonErrorBadgeClick
    }), _react.default.createElement(_RevertButton.default, {
      isModified: isModified,
      isSavePending: isSavePending,
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.revert),
      onClick: onRevertButtonClick
    }));
  }

  render() {
    const {
      isOpen,
      onCloseButtonClick
    } = this.props;
    return _react.default.createElement(_cspaceLayout.Modal, {
      isOpen: isOpen,
      title: _react.default.createElement("h1", null, _react.default.createElement(_reactIntl.FormattedMessage, messages.title)),
      closeButtonClassName: "material-icons",
      closeButtonLabel: "close",
      renderButtonBar: this.renderButtonBar,
      onCloseButtonClick: onCloseButtonClick
    }, _react.default.createElement(_reactIntl.FormattedMessage, messages.prompt));
  }

}

exports.default = ConfirmRecordNavigationModal;
ConfirmRecordNavigationModal.modalName = 'ConfirmRecordNavigationModal';
ConfirmRecordNavigationModal.propTypes = propTypes;