"use client";
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
const require_get_ref_prop = require("../../../core/utils/get-ref-prop/get-ref-prop.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_factory = require("../../../core/factory/factory.cjs");
const require_Popover_context = require("../Popover.context.cjs");
let react = require("react");
let _mantine_hooks = require("@mantine/hooks");
let clsx = require("clsx");
clsx = require_runtime.__toESM(clsx);
//#region packages/@mantine/core/src/components/Popover/PopoverTarget/PopoverTarget.tsx
const defaultProps = {
	refProp: "ref",
	popupType: "dialog"
};
const PopoverTarget = require_factory.factory((props) => {
	const { children, refProp, popupType, ref, ...others } = require_use_props.useProps("PopoverTarget", defaultProps, props);
	const child = require_get_single_element_child.getSingleElementChild(children);
	if (!child) throw new Error("Popover.Target component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported");
	const forwardedProps = others;
	const ctx = require_Popover_context.usePopoverContext();
	const targetRef = (0, _mantine_hooks.useMergedRef)(ctx.reference, require_get_ref_prop.getRefProp(child), ref);
	const accessibleProps = ctx.withRoles ? {
		"aria-haspopup": popupType,
		"aria-expanded": ctx.opened,
		"aria-controls": ctx.opened ? ctx.getDropdownId() : void 0,
		id: ctx.getTargetId()
	} : {};
	const childProps = child.props;
	return (0, react.cloneElement)(child, {
		...forwardedProps,
		...accessibleProps,
		...ctx.targetProps,
		className: (0, clsx.default)(ctx.targetProps.className, forwardedProps.className, childProps.className),
		[refProp]: targetRef,
		...!ctx.controlled ? { onClick: (event) => {
			ctx.onToggle();
			childProps.onClick?.(event);
		} } : null
	});
});
PopoverTarget.displayName = "@mantine/core/PopoverTarget";
//#endregion
exports.PopoverTarget = PopoverTarget;

//# sourceMappingURL=PopoverTarget.cjs.map