"use client";
import { createEventHandler } from "../../../core/utils/create-event-handler/create-event-handler.mjs";
import { getSingleElementChild } from "../../../core/utils/get-single-element-child/get-single-element-child.mjs";
import { useProps } from "../../../core/MantineProvider/use-props/use-props.mjs";
import { Popover } from "../../Popover/Popover.mjs";
import { useHoverCardContext } from "../HoverCard.context.mjs";
import { HoverCardGroupContext } from "../HoverCardGroup/HoverCardGroup.mjs";
import { cloneElement, use } from "react";
import { jsx } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/HoverCard/HoverCardTarget/HoverCardTarget.tsx
const defaultProps = { refProp: "ref" };
function HoverCardTarget(props) {
	const { children, refProp, eventPropsWrapperName, ...others } = useProps("HoverCardTarget", defaultProps, props);
	const child = getSingleElementChild(children);
	if (!child) throw new Error("HoverCard.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 = useHoverCardContext();
	if (use(HoverCardGroupContext).withinGroup && ctx.getReferenceProps && ctx.reference) {
		const referenceProps = ctx.getReferenceProps();
		return /* @__PURE__ */ jsx(Popover.Target, {
			refProp,
			...others,
			children: cloneElement(child, eventPropsWrapperName ? { [eventPropsWrapperName]: {
				...referenceProps,
				ref: ctx.reference
			} } : {
				...referenceProps,
				ref: ctx.reference
			})
		});
	}
	const eventListeners = {
		onMouseEnter: createEventHandler(child.props.onMouseEnter, ctx.openDropdown),
		onMouseLeave: createEventHandler(child.props.onMouseLeave, ctx.closeDropdown)
	};
	return /* @__PURE__ */ jsx(Popover.Target, {
		refProp,
		...others,
		children: cloneElement(child, eventPropsWrapperName ? { [eventPropsWrapperName]: eventListeners } : eventListeners)
	});
}
HoverCardTarget.displayName = "@mantine/core/HoverCardTarget";
//#endregion
export { HoverCardTarget };

//# sourceMappingURL=HoverCardTarget.mjs.map