"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const lab_1 = require("@mui/lab");
const material_1 = require("@mui/material");
const Button_1 = tslib_1.__importDefault(require("@mui/material/Button"));
const Card_1 = tslib_1.__importDefault(require("@mui/material/Card"));
const styles_1 = require("@mui/material/styles");
const react_intl_1 = require("react-intl");
const PREFIX = 'SCConfirmDialog';
const Root = (0, styles_1.styled)(Card_1.default, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(({ theme }) => ({
    maxWidth: 800,
    marginBottom: theme.spacing(2)
}));
function ConfirmDialog(props) {
    // PROPS
    const { open, title, content = null, btnConfirm = null, btnCancel = null, isUpdating = false, onClose = null, onConfirm = null, disableBackdropClick = false } = props, rest = tslib_1.__rest(props, ["open", "title", "content", "btnConfirm", "btnCancel", "isUpdating", "onClose", "onConfirm", "disableBackdropClick"]);
    /**
     * Handles dialog closing
     * @param reason
     */
    function handleClose(reason) {
        if (disableBackdropClick && (reason === 'backdropClick' || reason === 'escapeKeyDown')) {
            return false;
        }
        if (!isUpdating) {
            onClose === null || onClose === void 0 ? void 0 : onClose();
        }
    }
    /**
     * Handles action confirm
     */
    function handleConfirm() {
        onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm();
    }
    /**
     * Renders root object
     */
    return ((0, jsx_runtime_1.jsx)(Root, { children: (0, jsx_runtime_1.jsxs)(material_1.Dialog, Object.assign({ open: open, onClose: handleClose }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: title || (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.confirmDialog.title", defaultMessage: "ui.confirmDialog.title" }) }), content && ((0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, Object.assign({ component: "div" }, { children: content })) })), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(Button_1.default, Object.assign({ onClick: handleClose }, { children: btnCancel || (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.confirmDialog.btnCancel", defaultMessage: "ui.confirmDialog.btnCancel" }) })), (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ onClick: handleConfirm, variant: "contained", autoFocus: true, loading: isUpdating }, { children: btnConfirm || (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.confirmDialog.btnConfirm", defaultMessage: "ui.confirmDialog.btnConfirm" }) }))] })] })) }));
}
exports.default = ConfirmDialog;
