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

import { jsx as _jsx } from "react/jsx-runtime";
import { Portal } from '../../portal/index.js';
import { DialogContainer } from '../Dialog/index.js';
import { AlertDialog } from './AlertDialog.js';
const PORTAL_KEY = 'AlertDialogZone';
/**
 * @internal Do not use it
 */
export function AlertDialogZone(props) {
    const { openedDialog } = props;
    if (openedDialog === null)
        return _jsx(Portal, {}, PORTAL_KEY);
    const { type, isDismissable = true, actions, onDismiss, content, ...options } = openedDialog.props;
    const { resolve, reject, isVisible, dialogType } = openedDialog.meta;
    const _actions = (() => {
        const mergeActionProps = (action, status) => {
            if (typeof action === 'undefined') {
                return undefined;
            }
            if (typeof action === 'boolean') {
                return (action
                    ? { onPress: () => resolve(status) }
                    : false);
            }
            const onPress = action.onPress;
            return {
                ...action,
                onPress: (e) => {
                    onPress?.(e);
                    resolve(status);
                },
            };
        };
        if (typeof actions === 'undefined')
            return {};
        return {
            confirm: mergeActionProps(actions.confirm, 'confirm'),
            secondary: mergeActionProps(actions.secondary, 'secondary'),
            cancel: typeof actions.cancel === 'undefined'
                ? undefined
                : typeof actions.cancel === 'boolean'
                    ? actions.cancel
                        ? { onPress: () => reject(undefined) }
                        : false
                    : {
                        ...actions.cancel,
                        onPress: (e) => {
                            actions.cancel.onPress?.(e);
                            reject(undefined);
                        },
                    },
        };
    })();
    return (_jsx(Portal, { children: _jsx(DialogContainer, { isOpen: isVisible, isDismissable: isDismissable, type: type, onDismiss: onDismiss, children: _jsx(AlertDialog, { noActions: dialogType === 'form', actions: _actions, isHidden: !isVisible, content: typeof content === 'function'
                    ? content({ resolve, reject })
                    : content, ...options }) }) }, PORTAL_KEY));
}

        