import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2020-2026 GoodData Corporation
import { memo, useMemo } from "react";
import cx from "classnames";
import { Bubble } from "../Bubble/Bubble.js";
import { BubbleHoverTrigger } from "../Bubble/BubbleHoverTrigger.js";
import { Button } from "../Button/Button.js";
import { LoadingSpinner } from "../LoadingSpinner/LoadingSpinner.js";
import { Typography } from "../Typography/Typography.js";
import { useId } from "../utils/useId.js";
import { DialogBase } from "./DialogBase.js";
import { CONFIRM_DIALOG_BASE_ID } from "./elementId.js";
/**
 * @internal
 */
export const ConfirmDialogBase = memo(function ConfirmDialogBase({ displayCloseButton = true, isSubmitDisabled = false, isCancelDisabled, isPositive, headline, cancelButtonText, submitButtonText, submitButtonTooltipText, submitButtonTooltipAlignPoints, submitButtonTooltipArrowOffsets, hideSubmitButton, warning, showProgressIndicator, headerLeftButtonRenderer, footerLeftRenderer, dialogHeaderClassName, initialFocus, returnFocusTo, returnFocusAfterClose = true, titleRightIconRenderer, ...dialogBaseProps }) {
    const dialogClasses = cx("gd-confirm", dialogBaseProps.className);
    const submitButtonClasses = cx({
        "s-dialog-submit-button": true,
        "gd-button-action": isPositive,
        "gd-button-negative": !isPositive,
    });
    const headerClassNames = cx("gd-dialog-header", dialogHeaderClassName);
    const titleElementIdWhenNotSet = useId();
    const accessibilityConfig = useMemo(() => {
        let titleElementId = dialogBaseProps.accessibilityConfig?.titleElementId;
        if (headline && !titleElementId) {
            titleElementId = titleElementIdWhenNotSet;
        }
        return {
            ...(dialogBaseProps.accessibilityConfig ?? {}),
            titleElementId,
            isModal: true,
        };
    }, [dialogBaseProps.accessibilityConfig, headline, titleElementIdWhenNotSet]);
    const guardedOnSubmit = isSubmitDisabled ? undefined : dialogBaseProps.onSubmit;
    return (_jsxs(DialogBase, { ...dialogBaseProps, onSubmit: guardedOnSubmit, className: dialogClasses, displayCloseButton: displayCloseButton, accessibilityConfig: accessibilityConfig, initialFocus: initialFocus, returnFocusTo: returnFocusTo, returnFocusAfterClose: returnFocusAfterClose, children: [
            _jsxs("div", { className: "gd-dialog-header-wrapper", children: [headerLeftButtonRenderer?.(), _jsxs("div", { className: headerClassNames, children: [headline ? (_jsx(Typography, { tagName: "h3", className: "gd-dialog-header-title", id: accessibilityConfig.titleElementId, children: headline })) : null, titleRightIconRenderer?.()] })
                ] }), !!warning && _jsx("div", { className: "gd-dialog-warning", children: warning }), _jsx("div", { className: "gd-dialog-content", children: dialogBaseProps.children }), _jsxs("div", { className: "gd-dialog-footer", children: [footerLeftRenderer?.(), showProgressIndicator ? _jsx(LoadingSpinner, { className: "gd-dialog-spinner small" }) : null, _jsx(Button, { onClick: dialogBaseProps.onCancel, className: "gd-button-secondary s-dialog-cancel-button", value: cancelButtonText, disabled: isCancelDisabled }), submitButtonText && !hideSubmitButton ? (_jsxs(BubbleHoverTrigger, { className: "gd-button", showDelay: 0, hideDelay: 0, children: [
                            _jsx(Button, { id: CONFIRM_DIALOG_BASE_ID, onClick: dialogBaseProps.onSubmit, className: submitButtonClasses, value: submitButtonText, disabled: isSubmitDisabled, describedByFromValidation: true }), submitButtonTooltipText ? (_jsx(Bubble, { className: "bubble-primary", alignPoints: submitButtonTooltipAlignPoints || [{ align: "bc tc" }], arrowOffsets: submitButtonTooltipArrowOffsets || { "bc tc": [0, 15] }, children: submitButtonTooltipText })) : null] })) : null] })
        ] }));
});
