import { isJsx, isReactText } from "../utils/assertion.js";
import { random } from "../utils/number.js";
import { useIds } from "../utils/react.js";
import { cs } from "../utils/styles.js";
import "../utils/index.js";
import { useStyleConfig } from "../core/theme.js";
import { styled } from "../core/styled.js";
import { vui } from "../core/vui.js";
import "../core/index.js";
import { modalAnimation, modalJustifyContent } from "./consts.js";
import { DialogProvider } from "./context.js";
import modal_default from "../modal/modal.js";
import "../modal/index.js";
import dialogBody_default from "./dialogBody.js";
import dialogCancelButton_default from "./dialogCancelButton.js";
import dialogCloseButton_default from "./dialogCloseButton.js";
import dialogSubmitButton_default from "./dialogSubmitButton.js";
import dialogFooter_default from "./dialogFooter.js";
import dialogIcon_default from "./dialogIcon.js";
import dialogTitle_default from "./dialogTitle.js";
import dialogHeader_default from "./dialogHeader.js";
import { useRef } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";

//#region src/dialog/dialog.tsx
const DialogBase = styled.divBox`
  background-color: white;
  border-radius: 1px;
  box-shadow: modal;
  display: flex;
  flex-direction: column;
  width: 100%;
`;
/**
* Displays content in a Modal window. Includes required accessibility configuration.
*
* Dialog is built upon `Modal`.
*
* The content can include important information, like warnings or errors, simple forms or prompts for user's decision. It blocks interaction with the rest of the page, but often can be disabled by pressing Escape, clicking on the backdrop or close button.
*/
const Dialog = vui((props, ref) => {
	const { body: bodyProp, cancelButton, children, className, closeButton, disableBackdropClose, footer, header, icon, id, isOpen, modalProps: modalPropsProp, placement = "center", onClose, size, status, submitButton, title, variant, ...rest } = props;
	const styles = useStyleConfig("Dialog", props);
	const [dialogId, bodyId, titleId] = useIds(useRef(id ?? random().toString()).current, [
		"dialog",
		"dialog-body",
		"dialog-title"
	]);
	const body = isReactText(bodyProp) ? { children: bodyProp } : bodyProp;
	const showHeader = Boolean(header || closeButton || icon || title);
	const showFooter = Boolean(footer || cancelButton || submitButton);
	const ariaProps = {
		"aria-describedby": bodyId,
		"aria-labelledby": titleId
	};
	const modalProps = {
		animation: modalAnimation[placement],
		contentProps: {
			alignItems: placement === "center" ? "center" : "auto",
			justifyContent: modalJustifyContent[placement],
			...modalPropsProp?.contentProps
		},
		...modalPropsProp
	};
	return /* @__PURE__ */ jsx(DialogProvider, {
		value: {
			bodyId,
			icon,
			isOpen,
			onClose,
			size,
			status,
			titleId,
			variant
		},
		children: /* @__PURE__ */ jsx(modal_default, {
			isOpen,
			onClose,
			...modalProps,
			disableBackdropClose,
			children: /* @__PURE__ */ jsx(DialogBase, {
				className: cs("vui-dialog", className),
				id: dialogId,
				maxH: placement === "center" ? "calc(100vh - 32px)" : "100%",
				ref,
				role: "dialog",
				...ariaProps,
				...styles.container,
				...rest,
				children: children ?? /* @__PURE__ */ jsxs(Fragment$1, { children: [
					isJsx(header) ? header : showHeader && /* @__PURE__ */ jsx(dialogHeader_default, {
						closeButton,
						icon,
						title,
						...header
					}),
					isJsx(body) ? body : body && /* @__PURE__ */ jsx(dialogBody_default, { ...body }),
					isJsx(footer) ? footer : showFooter && /* @__PURE__ */ jsx(dialogFooter_default, {
						cancelButton,
						submitButton,
						...footer
					})
				] })
			})
		})
	});
});
Dialog.Body = dialogBody_default;
Dialog.CancelButton = dialogCancelButton_default;
Dialog.CloseButton = dialogCloseButton_default;
Dialog.Footer = dialogFooter_default;
Dialog.Header = dialogHeader_default;
Dialog.Icon = dialogIcon_default;
Dialog.SubmitButton = dialogSubmitButton_default;
Dialog.Title = dialogTitle_default;
Dialog.displayName = "Dialog";
var dialog_default = Dialog;

//#endregion
export { DialogBase, dialog_default as default };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=dialog.js.map