import { jsx, jsxs } from 'react/jsx-runtime';
import { forwardRef, useId, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { c as cn } from './utils-BJnb9o5c.js';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from './primitives/Dialog.js';
import { b as Button } from './Button-C4c_dj-f.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,
    ...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, eventDetails) => {
      if (open) return;
      if (eventDetails.reason === "escape-key" && !closeOnEsc || eventDetails.reason === "outside-press" && !closeOnOutsideClick) {
        eventDetails.cancel();
        return;
      }
      onClose();
    };
    const initialFocus = initialFocusRef ?? (initialFocusElement === "submit" ? submitButtonRef : initialFocusElement === "cancel" ? cancelButtonRef : void 0);
    return /* @__PURE__ */ jsx(
      Dialog,
      {
        open: isOpen,
        onOpenChange: handleOpenChange,
        modal,
        defaultOpen,
        children: /* @__PURE__ */ jsxs(
          DialogContent,
          {
            ref,
            role: "alertdialog",
            "aria-labelledby": title ? titleId : void 0,
            "aria-describedby": message ? messageId : void 0,
            showCloseButton: closeButton,
            overlayClassName: backdropClassName,
            initialFocus: initialFocus ?? void 0,
            className: cn(SIZE_CLASS_MAP[size], className),
            "data-testid": "alert-box",
            ...otherProps,
            children: [
              /* @__PURE__ */ jsxs(DialogHeader, { children: [
                /* @__PURE__ */ jsx(
                  DialogTitle,
                  {
                    id: titleId,
                    "data-testid": "alert-title",
                    className: "text-2xl font-semibold",
                    children: title
                  }
                ),
                message && /* @__PURE__ */ jsx(DialogDescription, { id: messageId, "data-testid": "alert-message", children: message })
              ] }),
              /* @__PURE__ */ jsxs(DialogFooter, { children: [
                !hideCancelButton && /* @__PURE__ */ jsx(
                  Button,
                  {
                    ref: cancelButtonRef,
                    variant: "outline",
                    label: cancelButtonLabel,
                    onClick: onClose,
                    "data-testid": "alert-cancel-button"
                  }
                ),
                /* @__PURE__ */ 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-BN00VOZx.js.map
