"use strict";

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

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

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

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

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

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

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

var _LockButton = _interopRequireDefault(require("../../../styles/cspace-ui/LockButton.css"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

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

const messages = (0, _reactIntl.defineMessages)({
  title: {
    "id": "lockRecordModal.title",
    "defaultMessage": "Lock Record?"
  },
  prompt: {
    "id": "lockRecordModal.prompt",
    "defaultMessage": "This record may be locked after it is saved. This will make the record read-only, to prevent further modification."
  },
  cancel: {
    "id": "lockRecordModal.cancel",
    "defaultMessage": "Cancel"
  },
  saveLock: {
    "id": "lockRecordModal.saveLock",
    "defaultMessage": "Save and lock"
  },
  saveOnly: {
    "id": "lockRecordModal.saveOnly",
    "defaultMessage": "Save only"
  }
});
const propTypes = {
  csid: _propTypes.default.string,
  isOpen: _propTypes.default.bool,
  isSavePending: _propTypes.default.bool,
  onCancelButtonClick: _propTypes.default.func,
  onCloseButtonClick: _propTypes.default.func,
  onSaveOnlyButtonClick: _propTypes.default.func,
  onSaveLockButtonClick: _propTypes.default.func
};

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

  renderButtonBar() {
    const {
      csid,
      isSavePending,
      onCancelButtonClick,
      onSaveOnlyButtonClick,
      onSaveLockButtonClick
    } = this.props;
    return _react.default.createElement("div", null, _react.default.createElement(_CancelButton.default, {
      disabled: isSavePending,
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.cancel),
      onClick: onCancelButtonClick
    }), _react.default.createElement(_SaveButton.default, {
      csid: csid,
      isSavePending: isSavePending,
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.saveOnly),
      onClick: onSaveOnlyButtonClick
    }), _react.default.createElement(_SaveButton.default, {
      className: _LockButton.default.common,
      csid: csid,
      isSavePending: isSavePending,
      label: _react.default.createElement(_reactIntl.FormattedMessage, messages.saveLock),
      onClick: onSaveLockButtonClick
    }));
  }

  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 = LockRecordModal;
LockRecordModal.modalName = 'LockRecordModal';
LockRecordModal.propTypes = propTypes;