"use client";
import { splitPresenceProps } from "../presence/split-presence-props.js";
import { usePresence } from "../presence/use-presence.js";
import { PresenceProvider } from "../presence/use-presence-context.js";
import { MenuProvider, useMenuContext } from "./use-menu-context.js";
import { useEffectOnce } from "../../utils/use-effect-once.js";
import { MenuMachineProvider, useMenuMachineContext } from "./use-menu-machine-context.js";
import { MenuTriggerItemProvider } from "./use-menu-trigger-item-context.js";
import { useCallback } from "react";
import { mergeProps } from "@zag-js/react";
import { jsx } from "react/jsx-runtime";
//#region src/components/menu/menu-root-provider.tsx
var MenuRootProvider = (props) => {
	const parentApi = useMenuContext();
	const parentMachine = useMenuMachineContext();
	const [presenceProps, { value: menu, children }] = splitPresenceProps(props);
	const { api, service } = menu;
	const presence = usePresence(mergeProps({ present: api.open }, presenceProps));
	useEffectOnce(() => {
		if (!parentMachine) return;
		if (!parentApi) return;
		parentApi.setChild(service);
		api.setParent(parentMachine);
	});
	return /* @__PURE__ */ jsx(MenuTriggerItemProvider, {
		value: useCallback(() => parentApi?.getTriggerItemProps(api), [api, parentApi]),
		children: /* @__PURE__ */ jsx(MenuMachineProvider, {
			value: service,
			children: /* @__PURE__ */ jsx(MenuProvider, {
				value: api,
				children: /* @__PURE__ */ jsx(PresenceProvider, {
					value: presence,
					children
				})
			})
		})
	});
};
//#endregion
export { MenuRootProvider };
