"use strict";

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

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

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

var _Dialog = require("../Dialog");

var _Button = require("../Button");

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

var IdleTimeoutDialog = function IdleTimeoutDialog(_ref) {
  var closeButtonText = _ref.closeButtonText,
      continueSessionText = _ref.continueSessionText,
      heading = _ref.heading,
      endSessionButtonText = _ref.endSessionButtonText,
      endSessionUrl = _ref.endSessionUrl,
      message = _ref.message,
      onClose = _ref.onClose,
      onSessionContinue = _ref.onSessionContinue,
      onSessionForcedEnd = _ref.onSessionForcedEnd,
      showSessionEndButton = _ref.showSessionEndButton;

  var renderDialogActions = function renderDialogActions() {
    var continueSessionButtonClasses = showSessionEndButton ? 'ds-u-margin-right--2' : null;
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Button.Button, {
      variation: "solid",
      className: continueSessionButtonClasses,
      onClick: onSessionContinue
    }, continueSessionText), showSessionEndButton ? /*#__PURE__*/_react.default.createElement(_Button.Button, {
      href: endSessionUrl,
      onClick: onSessionForcedEnd
    }, endSessionButtonText) : null);
  };

  return /*#__PURE__*/_react.default.createElement(_Dialog.Dialog, {
    alert: true,
    dialogId: "session-timeout-dialog",
    escapeExits: false,
    heading: heading,
    actions: renderDialogActions(),
    onExit: onClose,
    closeButtonText: closeButtonText
  }, message);
};

exports.IdleTimeoutDialog = IdleTimeoutDialog;
IdleTimeoutDialog.propTypes = {
  /**
     *  The text for the dialog's 'close' button
     */
  closeButtonText: _propTypes.default.string,

  /**
     * The text for the 'continue session' button in warning dialog.
     */
  continueSessionText: _propTypes.default.string.isRequired,

  /**
     * The heading text for the warning dialog.
     */
  heading: _propTypes.default.string,

  /**
     * The text for the button that ends the session in warning dialog.
     */
  endSessionButtonText: _propTypes.default.string,

  /**
     *
     */
  endSessionUrl: _propTypes.default.string,

  /**
     * The message text for the warning dialog.
     * Note that using the token `<timeToTimeout>` will be replaced in the message text with the number of minutes until timeout.
     */
  message: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]).isRequired,

  /**
     * Function that is called when the user select the 'close' button for the dialog
     */
  onClose: _propTypes.default.func.isRequired,

  /**
     * Function that is called when the user chooses to keep the session alive.
     * The IdleTimeout component will reset the countdown internally.
     */
  onSessionContinue: _propTypes.default.func.isRequired,

  /**
     * Optional function that is called when the session is manually ended by user.
     * If not provided, the behavior of `onTimeout` will be used.
     */
  onSessionForcedEnd: _propTypes.default.func,

  /**
     * Describes if the button to manually end session should be shown
     */
  showSessionEndButton: _propTypes.default.bool
};
var _default = IdleTimeoutDialog;
exports.default = _default;