"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const clsx = require("clsx");
const isElement = require("../../../core/utils/is-element/is-element.cjs");
require("react/jsx-runtime");
const getRefProp = require("../../../core/utils/get-ref-prop/get-ref-prop.cjs");
const useProps = require("../../../core/MantineProvider/use-props/use-props.cjs");
const factory = require("../../../core/factory/factory.cjs");
const Popover_context = require("../Popover.context.cjs");
const useMergedRef = require("../../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-merged-ref/use-merged-ref.cjs");
const defaultProps = {
  refProp: "ref",
  popupType: "dialog"
};
const PopoverTarget = factory.factory((props, ref) => {
  const { children, refProp, popupType, ...others } = useProps.useProps(
    "PopoverTarget",
    defaultProps,
    props
  );
  if (!isElement.isElement(children)) {
    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 = Popover_context.usePopoverContext();
  const targetRef = useMergedRef.useMergedRef(ctx.reference, getRefProp.getRefProp(children), ref);
  const accessibleProps = ctx.withRoles ? {
    "aria-haspopup": popupType,
    "aria-expanded": ctx.opened,
    "aria-controls": ctx.getDropdownId(),
    id: ctx.getTargetId()
  } : {};
  return React.cloneElement(children, {
    ...forwardedProps,
    ...accessibleProps,
    ...ctx.targetProps,
    className: clsx(
      ctx.targetProps.className,
      forwardedProps.className,
      children.props.className
    ),
    [refProp]: targetRef,
    ...!ctx.controlled ? { onClick: ctx.onToggle } : null
  });
});
PopoverTarget.displayName = "@mantine/core/PopoverTarget";
exports.PopoverTarget = PopoverTarget;
