"use client";
const require_create_split_props = require("../../utils/create-split-props.cjs");
const require_split_presence_props = require("../presence/split-presence-props.cjs");
const require_use_presence = require("../presence/use-presence.cjs");
const require_use_presence_context = require("../presence/use-presence-context.cjs");
const require_use_menu_context = require("./use-menu-context.cjs");
const require_use_effect_once = require("../../utils/use-effect-once.cjs");
const require_use_menu = require("./use-menu.cjs");
const require_use_menu_machine_context = require("./use-menu-machine-context.cjs");
const require_use_menu_trigger_item_context = require("./use-menu-trigger-item-context.cjs");
let react = require("react");
let _zag_js_react = require("@zag-js/react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/components/menu/menu-root.tsx
var splitRootProps = require_create_split_props.createSplitProps();
var MenuRoot = (props) => {
	const [presenceProps, menuProps] = require_split_presence_props.splitPresenceProps(props);
	const [useMenuProps, localProps] = splitRootProps(menuProps, [
		"anchorPoint",
		"aria-label",
		"closeOnSelect",
		"composite",
		"defaultHighlightedValue",
		"defaultOpen",
		"highlightedValue",
		"id",
		"ids",
		"loopFocus",
		"navigate",
		"onEscapeKeyDown",
		"onFocusOutside",
		"onHighlightChange",
		"onInteractOutside",
		"onOpenChange",
		"onPointerDownOutside",
		"onRequestDismiss",
		"onSelect",
		"onTriggerValueChange",
		"open",
		"positioning",
		"triggerValue",
		"defaultTriggerValue",
		"typeahead"
	]);
	const parentApi = require_use_menu_context.useMenuContext();
	const parentMachine = require_use_menu_machine_context.useMenuMachineContext();
	const { api, service } = require_use_menu.useMenu(useMenuProps);
	const presence = require_use_presence.usePresence((0, _zag_js_react.mergeProps)({ present: api.open }, presenceProps));
	require_use_effect_once.useEffectOnce(() => {
		if (!parentMachine) return;
		if (!parentApi) return;
		parentApi.setChild(service);
		api.setParent(parentMachine);
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_menu_trigger_item_context.MenuTriggerItemProvider, {
		value: (0, react.useCallback)(() => parentApi?.getTriggerItemProps(api), [api, parentApi]),
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_menu_machine_context.MenuMachineProvider, {
			value: service,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_menu_context.MenuProvider, {
				value: api,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_presence_context.PresenceProvider, {
					value: presence,
					...localProps
				})
			})
		})
	});
};
//#endregion
exports.MenuRoot = MenuRoot;
