/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-f1f3d22 | Cube Dev Team */
import { chain } from "../../../utils/react/chain.js";
import { Paragraph } from "../../content/Paragraph.js";
import { _Title } from "../../content/Title.js";
import { Button } from "../../actions/Button/Button.js";
import { ButtonGroup } from "../../actions/ButtonGroup/ButtonGroup.js";
import { useDialogContext } from "../Dialog/context.js";
import { Content } from "../../content/Content.js";
import { Header } from "../../content/Header.js";
import { Dialog } from "../Dialog/Dialog.js";
import { Footer } from "../../content/Footer.js";
import { forwardRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";

//#region src/components/overlays/AlertDialog/AlertDialog.tsx
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 ?? {};
	confirmProps = confirmProps !== false ? {
		...DEFAULT_CONFIRM_PROPS,
		...typeof confirmProps === "object" ? confirmProps : null
	} : void 0;
	cancelProps = cancelProps ? {
		...DEFAULT_CANCEL_PROPS,
		...typeof cancelProps === "object" ? cancelProps : null
	} : void 0;
	return /* @__PURE__ */ jsxs(Dialog, {
		ref,
		role: "alertdialog",
		isDismissable: false,
		...otherProps,
		children: [
			title ? /* @__PURE__ */ jsx(Header, { children: /* @__PURE__ */ jsx(_Title, { children: title }) }) : null,
			content ? /* @__PURE__ */ jsx(Content, { children: typeof content === "string" ? /* @__PURE__ */ jsx(Paragraph, { children: content }) : content }) : null,
			!noActions && (confirmProps || secondaryProps || cancelProps) ? /* @__PURE__ */ jsx(Footer, { children: /* @__PURE__ */ jsxs(ButtonGroup, { children: [
				confirmProps && /* @__PURE__ */ jsx(Button, {
					autoFocus: true,
					theme: danger ? "danger" : void 0,
					...confirmProps,
					onPress: (e) => chain(confirmProps?.onPress?.(e), onClose?.("confirm"))
				}),
				secondaryProps && /* @__PURE__ */ jsx(Button, {
					...secondaryProps,
					onPress: (e) => chain(secondaryProps?.onPress?.(e), onClose?.("secondary"))
				}),
				cancelProps && /* @__PURE__ */ 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";

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