/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-d4ad2ea | Cube Dev Team */
import { Portal } from "../../portal/Portal.js";
import { DialogContainer } from "../Dialog/DialogContainer.js";
import { _AlertDialog } from "./AlertDialog.js";
import { jsx } from "react/jsx-runtime";

//#region src/components/overlays/AlertDialog/AlertDialogZone.tsx
const PORTAL_KEY = "AlertDialogZone";
/**
* @internal Do not use it
*/
function AlertDialogZone(props) {
	const { openedDialog } = props;
	if (openedDialog === null) return /* @__PURE__ */ 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;
			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" ? void 0 : typeof actions.cancel === "boolean" ? actions.cancel ? { onPress: () => reject(void 0) } : false : {
				...actions.cancel,
				onPress: (e) => {
					actions.cancel.onPress?.(e);
					reject(void 0);
				}
			}
		};
	})();
	return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(DialogContainer, {
		isOpen: isVisible,
		isDismissable,
		type,
		onDismiss,
		children: /* @__PURE__ */ jsx(_AlertDialog, {
			noActions: dialogType === "form",
			actions: _actions,
			isHidden: !isVisible,
			content: typeof content === "function" ? content({
				resolve,
				reject
			}) : content,
			...options
		})
	}) }, PORTAL_KEY);
}

//#endregion
export { AlertDialogZone };
//# sourceMappingURL=AlertDialogZone.js.map