import { jsx, jsxs } from 'react/jsx-runtime';
import { forwardRef, useId, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { c as cn } from './utils-DdHUxIdC.js';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from './primitives/Dialog.js';
import { B as Button } from './Button-DSvnInaL.js';

const SIZE_CLASS_MAP = {
    small: "sm:max-w-xs",
    medium: "sm:max-w-sm",
    large: "sm:max-w-md",
};
const STYLE_VARIANT_MAP = {
    danger: "destructive",
    warning: "default",
};

const Alert = forwardRef(({ size = "medium", isOpen = false, isSubmitting = false, className, closeOnEsc = true, closeButton = true, backdropClassName, closeOnOutsideClick = true, onClose = () => { }, onSubmit = () => { }, title = "", message = "", submitButtonLabel: submitButtonLabelProp, cancelButtonLabel: cancelButtonLabelProp, hideCancelButton = false, style = "danger", initialFocusRef, initialFocusElement, modal, defaultOpen, 
// Radix content handlers — we intercept and merge
onOpenAutoFocus: onOpenAutoFocusProp, onCloseAutoFocus: onCloseAutoFocusProp, ...otherProps }, ref) => {
    const { t } = useTranslation();
    const submitButtonLabel = submitButtonLabelProp ?? t("neetoatoms.alert.continue", "Continue");
    const cancelButtonLabel = cancelButtonLabelProp ?? t("neetoatoms.alert.cancel", "Cancel");
    const baseId = useId();
    const titleId = `alert-title-${baseId}`;
    const messageId = `alert-message-${baseId}`;
    const submitButtonRef = useRef(null);
    const cancelButtonRef = useRef(null);
    const handleOpenChange = (open) => {
        if (!open)
            onClose();
    };
    const handleInteractOutside = (e) => {
        if (!closeOnOutsideClick)
            e.preventDefault();
    };
    const handleEscapeKeyDown = (e) => {
        if (!closeOnEsc)
            e.preventDefault();
    };
    const handleOpenAutoFocus = (e) => {
        // Custom focus ref takes highest priority
        if (initialFocusRef?.current) {
            e.preventDefault();
            initialFocusRef.current.focus();
        }
        else if (initialFocusElement === "submit" && submitButtonRef.current) {
            e.preventDefault();
            submitButtonRef.current.focus();
        }
        else if (initialFocusElement === "cancel" && cancelButtonRef.current) {
            e.preventDefault();
            cancelButtonRef.current.focus();
        }
        onOpenAutoFocusProp?.(e);
    };
    const handleCloseAutoFocus = (e) => {
        onCloseAutoFocusProp?.(e);
    };
    return (jsx(Dialog, { open: isOpen, onOpenChange: handleOpenChange, modal: modal, defaultOpen: defaultOpen, children: jsxs(DialogContent, { ref: ref, role: "alertdialog", "aria-labelledby": title ? titleId : undefined, "aria-describedby": message ? messageId : undefined, showCloseButton: closeButton, overlayClassName: backdropClassName, onInteractOutside: handleInteractOutside, onEscapeKeyDown: handleEscapeKeyDown, onOpenAutoFocus: handleOpenAutoFocus, onCloseAutoFocus: handleCloseAutoFocus, className: cn(SIZE_CLASS_MAP[size], className), "data-testid": "alert-box", ...otherProps, children: [jsxs(DialogHeader, { children: [jsx(DialogTitle, { id: titleId, "data-testid": "alert-title", className: "text-2xl font-semibold", children: title }), message && (jsx(DialogDescription, { id: messageId, "data-testid": "alert-message", children: message }))] }), jsxs(DialogFooter, { children: [!hideCancelButton && (jsx(Button, { ref: cancelButtonRef, variant: "outline", label: cancelButtonLabel, onClick: onClose, "data-testid": "alert-cancel-button" })), jsx(Button, { ref: submitButtonRef, variant: STYLE_VARIANT_MAP[style], label: submitButtonLabel, loading: isSubmitting, disabled: isSubmitting || !isOpen, onClick: onSubmit, "data-testid": "alert-submit-button" })] })] }) }));
});
Alert.displayName = "Alert";

export { Alert as A };
//# sourceMappingURL=Alert-CayTuRLW.js.map
