'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var utils = require('./utils-CTr7wn5d.js');
var primitives_Dialog = require('./primitives/Dialog.js');
var Button = require('./Button-BniJ4TT_.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 = React.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 } = reactI18next.useTranslation();
    const submitButtonLabel = submitButtonLabelProp ?? t("neetoatoms.alert.continue", "Continue");
    const cancelButtonLabel = cancelButtonLabelProp ?? t("neetoatoms.alert.cancel", "Cancel");
    const baseId = React.useId();
    const titleId = `alert-title-${baseId}`;
    const messageId = `alert-message-${baseId}`;
    const submitButtonRef = React.useRef(null);
    const cancelButtonRef = React.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 (jsxRuntime.jsx(primitives_Dialog.Dialog, { open: isOpen, onOpenChange: handleOpenChange, modal: modal, defaultOpen: defaultOpen, children: jsxRuntime.jsxs(primitives_Dialog.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: utils.cn(SIZE_CLASS_MAP[size], className), "data-testid": "alert-box", ...otherProps, children: [jsxRuntime.jsxs(primitives_Dialog.DialogHeader, { children: [jsxRuntime.jsx(primitives_Dialog.DialogTitle, { id: titleId, "data-testid": "alert-title", className: "text-2xl font-semibold", children: title }), message && (jsxRuntime.jsx(primitives_Dialog.DialogDescription, { id: messageId, "data-testid": "alert-message", children: message }))] }), jsxRuntime.jsxs(primitives_Dialog.DialogFooter, { children: [!hideCancelButton && (jsxRuntime.jsx(Button.Button, { ref: cancelButtonRef, variant: "outline", label: cancelButtonLabel, onClick: onClose, "data-testid": "alert-cancel-button" })), jsxRuntime.jsx(Button.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";

exports.Alert = Alert;
//# sourceMappingURL=Alert-DnIUdIE3.js.map
