import { __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { LoadingButton } from '@mui/lab';
import { Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@mui/material';
import Button from '@mui/material/Button';
import Card from '@mui/material/Card';
import { styled } from '@mui/material/styles';
import { FormattedMessage } from 'react-intl';
const PREFIX = 'SCConfirmDialog';
const Root = styled(Card, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(({ theme }) => ({
    maxWidth: 800,
    marginBottom: theme.spacing(2)
}));
export default function ConfirmDialog(props) {
    // PROPS
    const { open, title, content = null, btnConfirm = null, btnCancel = null, isUpdating = false, onClose = null, onConfirm = null, disableBackdropClick = false } = props, rest = __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 (_jsx(Root, { children: _jsxs(Dialog, Object.assign({ open: open, onClose: handleClose }, rest, { children: [_jsx(DialogTitle, { children: title || _jsx(FormattedMessage, { id: "ui.confirmDialog.title", defaultMessage: "ui.confirmDialog.title" }) }), content && (_jsx(DialogContent, { children: _jsx(DialogContentText, Object.assign({ component: "div" }, { children: content })) })), _jsxs(DialogActions, { children: [_jsx(Button, Object.assign({ onClick: handleClose }, { children: btnCancel || _jsx(FormattedMessage, { id: "ui.confirmDialog.btnCancel", defaultMessage: "ui.confirmDialog.btnCancel" }) })), _jsx(LoadingButton, Object.assign({ onClick: handleConfirm, variant: "contained", autoFocus: true, loading: isUpdating }, { children: btnConfirm || _jsx(FormattedMessage, { id: "ui.confirmDialog.btnConfirm", defaultMessage: "ui.confirmDialog.btnConfirm" }) }))] })] })) }));
}
