"use client";
const require_create_event_handler = require("../../../core/utils/create-event-handler/create-event-handler.cjs");
const require_get_single_element_child = require("../../../core/utils/get-single-element-child/get-single-element-child.cjs");
const require_use_props = require("../../../core/MantineProvider/use-props/use-props.cjs");
const require_Popover = require("../../Popover/Popover.cjs");
const require_Menu_context = require("../Menu.context.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/components/Menu/MenuTarget/MenuTarget.tsx
const defaultProps = { refProp: "ref" };
function MenuTarget(props) {
	const { children, refProp, ...others } = require_use_props.useProps("MenuTarget", defaultProps, props);
	const child = require_get_single_element_child.getSingleElementChild(children);
	if (!child) throw new Error("Menu.Target component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported");
	const ctx = require_Menu_context.useMenuContext();
	const _childProps = child.props;
	const onClick = require_create_event_handler.createEventHandler(_childProps.onClick, () => {
		if (ctx.trigger === "click") ctx.toggleDropdown();
		else if (ctx.trigger === "click-hover") {
			ctx.setOpenedViaClick(true);
			if (!ctx.opened) ctx.openDropdown();
		}
	});
	const onMouseEnter = require_create_event_handler.createEventHandler(_childProps.onMouseEnter, () => (ctx.trigger === "hover" || ctx.trigger === "click-hover") && ctx.openDropdown());
	const onMouseLeave = require_create_event_handler.createEventHandler(_childProps.onMouseLeave, () => {
		if (ctx.trigger === "hover") ctx.closeDropdown();
		else if (ctx.trigger === "click-hover" && !ctx.openedViaClick) ctx.closeDropdown();
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Popover.Popover.Target, {
		refProp,
		popupType: "menu",
		...others,
		children: (0, react.cloneElement)(child, {
			onClick,
			onMouseEnter,
			onMouseLeave,
			"data-expanded": ctx.opened ? true : void 0
		})
	});
}
MenuTarget.displayName = "@mantine/core/MenuTarget";
//#endregion
exports.MenuTarget = MenuTarget;

//# sourceMappingURL=MenuTarget.cjs.map