/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.108.1
 * Released under the MIT license.
 */

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { forwardRef } from 'react';
import { chain } from '../../../utils/react/index.js';
import { Button } from '../../actions/Button/Button.js';
import { ButtonGroup } from '../../actions/ButtonGroup/ButtonGroup.js';
import { Content } from '../../content/Content.js';
import { Footer } from '../../content/Footer.js';
import { Header } from '../../content/Header.js';
import { Paragraph } from '../../content/Paragraph.js';
import { Title } from '../../content/Title.js';
import { Dialog } from '../Dialog/index.js';
import { useDialogContext } from '../Dialog/context.js';
const DEFAULT_CONFIRM_PROPS = {
    label: 'Ok',
    type: 'primary',
};
const DEFAULT_CANCEL_PROPS = {
    label: 'Cancel',
};
/**
 * AlertDialogs are a specific type of Dialog. They display important information that users need to acknowledge.
 */
function AlertDialog(props, ref) {
    const { onClose } = useDialogContext();
    const { danger, actions, title, styles, noActions, content, ...otherProps } = props;
    let { confirm: confirmProps, secondary: secondaryProps, cancel: cancelProps, } = actions ?? {};
    // the confirm button is present by default
    confirmProps =
        confirmProps !== false
            ? {
                ...DEFAULT_CONFIRM_PROPS,
                ...(typeof confirmProps === 'object' ? confirmProps : null),
            }
            : undefined;
    // the cancel button is hidden by default
    cancelProps = cancelProps
        ? {
            ...DEFAULT_CANCEL_PROPS,
            ...(typeof cancelProps === 'object' ? cancelProps : null),
        }
        : undefined;
    return (_jsxs(Dialog, { ref: ref, role: "alertdialog", isDismissable: false, ...otherProps, children: [title ? (_jsx(Header, { children: _jsx(Title, { children: title }) })) : null, content ? (_jsx(Content, { children: typeof content === 'string' ? (_jsx(Paragraph, { children: content })) : (content) })) : null, !noActions && (confirmProps || secondaryProps || cancelProps) ? (_jsx(Footer, { children: _jsxs(ButtonGroup, { children: [confirmProps && (_jsx(Button, { autoFocus: true, theme: danger ? 'danger' : undefined, ...confirmProps, onPress: (e) => chain(confirmProps?.onPress?.(e), onClose?.('confirm')) })), secondaryProps && (_jsx(Button, { ...secondaryProps, onPress: (e) => chain(secondaryProps?.onPress?.(e), onClose?.('secondary')) })), cancelProps && (_jsx(Button, { ...cancelProps, onPress: (e) => chain(cancelProps?.onPress?.(e), onClose?.('cancel')) }))] }) })) : null] }));
}
/**
 * AlertDialogs are a specific type of Dialog. They display important information that users need to acknowledge.
 */
const _AlertDialog = forwardRef(AlertDialog);
_AlertDialog.displayName = 'AlertDialog';
export { _AlertDialog as AlertDialog };

        