/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
"use client";
import { closeModalEntry, removeModalEntry } from "./modalStore.js";
import { useModalConfig } from "./UDSModalConfigProvider.js";
import { ModalActions } from "./ModalActions.js";
import { ModalContent } from "./ModalContent.js";
import { ModalDescription } from "./ModalDescription.js";
import { ModalTitle } from "./ModalTitle.js";
import { Modal } from "./Modal.js";
import { useEffect } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { useReducedMotion } from "motion/react";
//#region src/components/client/Modal/ManagedModal.tsx
const ManagedModal = ({ slot }) => {
	const { animationDuration } = useModalConfig();
	const durationOut = typeof animationDuration === "number" ? animationDuration : animationDuration.out;
	const exitDuration = useReducedMotion() || slot.props.reduceMotion ? 0 : durationOut;
	useEffect(() => {
		if (!slot.closing) return;
		const ownerId = slot.ownerId;
		const timer = window.setTimeout(() => removeModalEntry(ownerId), exitDuration);
		return () => window.clearTimeout(timer);
	}, [
		slot.closing,
		slot.ownerId,
		exitDuration
	]);
	const { onClose, title, description, content, actions, ...modalProps } = slot.props;
	const { actionStartContent } = slot.options;
	return /* @__PURE__ */ jsxs(Modal, {
		...modalProps,
		open: slot.open,
		onClose: (event) => {
			onClose?.(event);
			closeModalEntry(slot.ownerId);
		},
		children: [
			title != null ? /* @__PURE__ */ jsx(ModalTitle, { children: title }) : null,
			description != null ? /* @__PURE__ */ jsx(ModalDescription, { children: description }) : null,
			content != null ? /* @__PURE__ */ jsx(ModalContent, { children: content }) : null,
			actions != null || actionStartContent != null ? /* @__PURE__ */ jsx(ModalActions, {
				startContent: actionStartContent,
				children: actions
			}) : null
		]
	});
};
ManagedModal.displayName = "ManagedModal";
//#endregion
export { ManagedModal };
