"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ConfirmDialog = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = require("../Button/Button");
var _Dialog = require("../Dialog");
var _Body = require("../Typography/Variants/Body2");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var ConfirmDialog = exports.ConfirmDialog = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var _ref$open = _ref.open,
    open = _ref$open === void 0 ? false : _ref$open,
    onCancel = _ref.onCancel,
    onConfirm = _ref.onConfirm,
    className = _ref.className,
    _ref$dialogTitle = _ref.dialogTitle,
    dialogTitle = _ref$dialogTitle === void 0 ? "Discard changes?" : _ref$dialogTitle,
    _ref$dialogContent = _ref.dialogContent,
    dialogContent = _ref$dialogContent === void 0 ? "All unsaved changes will be lost." : _ref$dialogContent,
    _ref$confirmBtnText = _ref.confirmBtnText,
    confirmBtnText = _ref$confirmBtnText === void 0 ? "OK" : _ref$confirmBtnText,
    _ref$cancelBtnText = _ref.cancelBtnText,
    cancelBtnText = _ref$cancelBtnText === void 0 ? "Cancel" : _ref$cancelBtnText,
    _ref$shouldShowCancel = _ref.shouldShowCancelButton,
    shouldShowCancelButton = _ref$shouldShowCancel === void 0 ? true : _ref$shouldShowCancel,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading;
  (0, _react.useEffect)(function () {
    var handleKeyDown = function handleKeyDown(event) {
      if (event.key === "Enter" && onConfirm) {
        event.preventDefault();
        onConfirm();
      }
    };
    if (open) {
      window.addEventListener("keydown", handleKeyDown);
    }
    return function () {
      window.removeEventListener("keydown", handleKeyDown);
    };
  }, [open, onConfirm]);
  return /*#__PURE__*/_react.default.createElement(_Dialog.Dialog, {
    ref: ref,
    open: open,
    onClose: onCancel,
    className: (0, _classnames.default)("c-confirm-dialog", className),
    disableCloseOnEsc: isLoading
  }, /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Title, null, dialogTitle), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.ContentDivider, null), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Content, null, /*#__PURE__*/_react.default.createElement(_Body.Body2, {
    lineHeight: "loose",
    color: "secondary",
    whitespace: "pre-line"
  }, dialogContent)), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.ContentDivider, null), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Actions, null, /*#__PURE__*/_react.default.createElement(_Button.Button, {
    variant: "primary",
    style: {
      marginRight: "12px"
    },
    onClick: onConfirm,
    disabled: isLoading
  }, confirmBtnText), shouldShowCancelButton ? /*#__PURE__*/_react.default.createElement(_Button.Button, {
    variant: "secondary",
    "data-action": "cancel",
    onClick: onCancel,
    type: "button",
    disabled: isLoading
  }, cancelBtnText) : null));
});
ConfirmDialog.displayName = "ConfirmDialog";
//# sourceMappingURL=ConfirmDialog.js.map