"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const isElement = require("../../../core/utils/is-element/is-element.cjs");
const getDefaultZIndex = require("../../../core/utils/get-default-z-index/get-default-z-index.cjs");
const getSize = require("../../../core/utils/get-size/get-size.cjs");
const getRefProp = require("../../../core/utils/get-ref-prop/get-ref-prop.cjs");
const createVarsResolver = require("../../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs");
require("clsx");
const getThemeColor = require("../../../core/MantineProvider/color-functions/get-theme-color/get-theme-color.cjs");
const MantineThemeProvider = require("../../../core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs");
const useProps = require("../../../core/MantineProvider/use-props/use-props.cjs");
const useStyles = require("../../../core/styles-api/use-styles/use-styles.cjs");
const getStyleObject = require("../../../core/Box/get-style-object/get-style-object.cjs");
const Box = require("../../../core/Box/Box.cjs");
const factory = require("../../../core/factory/factory.cjs");
const OptionalPortal = require("../../Portal/OptionalPortal.cjs");
const useFloatingTooltip = require("./use-floating-tooltip.cjs");
const Tooltip_module_css = require("../Tooltip.module.css.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",
  withinPortal: true,
  offset: 10,
  defaultOpened: false,
  position: "right",
  zIndex: getDefaultZIndex.getDefaultZIndex("popover")
};
const varsResolver = createVarsResolver.createVarsResolver((theme, { radius, color }) => ({
  tooltip: {
    "--tooltip-radius": radius === void 0 ? void 0 : getSize.getRadius(radius),
    "--tooltip-bg": color ? getThemeColor.getThemeColor(color, theme) : void 0,
    "--tooltip-color": color ? "var(--mantine-color-white)" : void 0
  }
}));
const TooltipFloating = factory.factory((_props, ref) => {
  const props = useProps.useProps("TooltipFloating", defaultProps, _props);
  const {
    children,
    refProp,
    withinPortal,
    style,
    className,
    classNames,
    styles,
    unstyled,
    radius,
    color,
    label,
    offset,
    position,
    multiline,
    zIndex,
    disabled,
    defaultOpened,
    variant,
    vars,
    portalProps,
    ...others
  } = props;
  const theme = MantineThemeProvider.useMantineTheme();
  const getStyles = useStyles.useStyles({
    name: "TooltipFloating",
    props,
    classes: Tooltip_module_css.default,
    className,
    style,
    classNames,
    styles,
    unstyled,
    rootSelector: "tooltip",
    vars,
    varsResolver
  });
  const { handleMouseMove, x, y, opened, boundaryRef, floating, setOpened } = useFloatingTooltip.useFloatingTooltip({
    offset,
    position,
    defaultOpened
  });
  if (!isElement.isElement(children)) {
    throw new Error(
      "[@mantine/core] Tooltip.Floating component children should be an element or a component that accepts ref, fragments, strings, numbers and other primitive values are not supported"
    );
  }
  const targetRef = useMergedRef.useMergedRef(boundaryRef, getRefProp.getRefProp(children), ref);
  const _childrenProps = children.props;
  const onMouseEnter = (event) => {
    var _a;
    (_a = _childrenProps.onMouseEnter) == null ? void 0 : _a.call(_childrenProps, event);
    handleMouseMove(event);
    setOpened(true);
  };
  const onMouseLeave = (event) => {
    var _a;
    (_a = _childrenProps.onMouseLeave) == null ? void 0 : _a.call(_childrenProps, event);
    setOpened(false);
  };
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsx(OptionalPortal.OptionalPortal, { ...portalProps, withinPortal, children: /* @__PURE__ */ jsxRuntime.jsx(
      Box.Box,
      {
        ...others,
        ...getStyles("tooltip", {
          style: {
            ...getStyleObject.getStyleObject(style, theme),
            zIndex,
            display: !disabled && opened ? "block" : "none",
            top: (y && Math.round(y)) ?? "",
            left: (x && Math.round(x)) ?? ""
          }
        }),
        variant,
        ref: floating,
        mod: { multiline },
        children: label
      }
    ) }),
    React.cloneElement(children, {
      ..._childrenProps,
      [refProp]: targetRef,
      onMouseEnter,
      onMouseLeave
    })
  ] });
});
TooltipFloating.classes = Tooltip_module_css.default;
TooltipFloating.displayName = "@mantine/core/TooltipFloating";
exports.TooltipFloating = TooltipFloating;
