/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import classNames from "classnames";
import * as React from "react";
import { Classes, DISPLAYNAME_PREFIX } from "../../common";
import { ALERT_WARN_CANCEL_ESCAPE_KEY, ALERT_WARN_CANCEL_OUTSIDE_CLICK, ALERT_WARN_CANCEL_PROPS, } from "../../common/errors";
import { useValidateProps } from "../../hooks/useValidateProps";
import { Button } from "../button/buttons";
import { Dialog } from "../dialog/dialog";
import { Icon } from "../icon/icon";
/**
 * Alert component.
 *
 * @see https://blueprintjs.com/docs/#core/components/alert
 */
export const Alert = props => {
    const { cancelButtonText, canEscapeKeyCancel = false, canOutsideClickCancel = false, children, className, confirmButtonText = "OK", icon, intent, isOpen = false, loading = false, onCancel, onClose, onConfirm, ...overlayProps } = props;
    useValidateProps(() => {
        if (onClose == null && (cancelButtonText == null) !== (onCancel == null)) {
            console.warn(ALERT_WARN_CANCEL_PROPS);
        }
        const hasCancelHandler = onCancel != null || onClose != null;
        if (canEscapeKeyCancel && !hasCancelHandler) {
            console.warn(ALERT_WARN_CANCEL_ESCAPE_KEY);
        }
        if (canOutsideClickCancel && !hasCancelHandler) {
            console.warn(ALERT_WARN_CANCEL_OUTSIDE_CLICK);
        }
    }, [canEscapeKeyCancel, canOutsideClickCancel, cancelButtonText, onCancel, onClose]);
    const internalHandleCallbacks = React.useCallback((confirmed, event) => {
        (confirmed ? onConfirm : onCancel)?.(event);
        onClose?.(confirmed, event);
    }, [onCancel, onClose, onConfirm]);
    const handleCancel = React.useCallback((event) => internalHandleCallbacks(false, event), [internalHandleCallbacks]);
    const handleConfirm = React.useCallback((event) => internalHandleCallbacks(true, event), [internalHandleCallbacks]);
    return (React.createElement(Dialog, { ...overlayProps, role: "alertdialog", className: classNames(Classes.ALERT, className), canEscapeKeyClose: canEscapeKeyCancel, canOutsideClickClose: canOutsideClickCancel, isOpen: isOpen, onClose: handleCancel },
        React.createElement("div", { className: Classes.ALERT_BODY },
            React.createElement(Icon, { icon: icon, size: 40, intent: intent }),
            React.createElement("div", { className: Classes.ALERT_CONTENTS }, children)),
        React.createElement("div", { className: Classes.ALERT_FOOTER },
            React.createElement(Button, { loading: loading, intent: intent, text: confirmButtonText, onClick: handleConfirm }),
            cancelButtonText && React.createElement(Button, { text: cancelButtonText, disabled: loading, onClick: handleCancel }))));
};
Alert.displayName = `${DISPLAYNAME_PREFIX}.Alert`;
//# sourceMappingURL=alert.js.map