import { forwardRef, useContext, useRef, useImperativeHandle } from "react";
import cs from "../_util/classNames.js";
import Trigger, { EventsByTriggerNeed } from "../Trigger/index.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import pick, { pickDataAttributes } from "../_util/pick.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { isFunction } from "../_util/is.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var defaultProps = {
  position: "top",
  trigger: "hover",
  escToClose: false,
  unmountOnExit: true,
  blurToHide: true,
  popupHoverStay: true
};
function Tooltip(baseProps, ref) {
  var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, componentConfig = _a.componentConfig;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Tooltip);
  var style = props.style, className = props.className, children = props.children, trigger = props.trigger, escToClose = props.escToClose, defaultPopupVisible = props.defaultPopupVisible, position = props.position, unmountOnExit = props.unmountOnExit, popupVisible = props.popupVisible, tooltipPrefixCls = props.prefixCls, blurToHide = props.blurToHide, popupHoverStay = props.popupHoverStay, disabled = props.disabled, onVisibleChange = props.onVisibleChange, triggerProps = props.triggerProps, childrenPrefix = props.childrenPrefix, getPopupContainer = props.getPopupContainer, content = props.content, mini = props.mini, color = props.color, rest = __rest(props, ["style", "className", "children", "trigger", "escToClose", "defaultPopupVisible", "position", "unmountOnExit", "popupVisible", "prefixCls", "blurToHide", "popupHoverStay", "disabled", "onVisibleChange", "triggerProps", "childrenPrefix", "getPopupContainer", "content", "mini", "color"]);
  var refTrigger = useRef();
  var updatePopupPosition = function(delay, callback) {
    if (delay === void 0) {
      delay = 0;
    }
    refTrigger.current && refTrigger.current.updatePopupPosition(delay, callback);
  };
  useImperativeHandle(ref, function() {
    return {
      updatePopupPosition
    };
  }, []);
  var prefixCls = tooltipPrefixCls || getPrefixCls("tooltip");
  var otherProps = __assign(__assign(__assign({}, pick(rest, EventsByTriggerNeed)), pickDataAttributes(rest)), triggerProps);
  var renderedContent = isFunction(content) ? content() : content;
  var isEmpty = function(content2) {
    if (content2 === null || content2 === void 0 || content2 === false) {
      return true;
    }
    if (typeof content2 === "string" && content2.trim() === "") {
      return true;
    }
    return false;
  };
  if ("popupVisible" in props) {
    otherProps.popupVisible = popupVisible;
  } else if (isEmpty(renderedContent)) {
    otherProps.popupVisible = false;
  }
  if (otherProps.showArrow !== false || otherProps.arrowProps) {
    otherProps.arrowProps = otherProps.arrowProps || {};
    if (color) {
      otherProps.arrowProps.style = __assign({
        backgroundColor: color
      }, otherProps.arrowProps.style);
    }
  }
  return /* @__PURE__ */ jsx(Trigger, {
    ...__assign({
      style: __assign({
        maxWidth: 350
      }, style),
      className,
      ref: refTrigger,
      classNames: "zoomInFadeOut",
      duration: {
        enter: 300,
        exit: 100
      },
      popup: function() {
        var _a2;
        return /* @__PURE__ */ jsx("div", {
          style: {
            backgroundColor: color
          },
          className: cs(prefixCls + "-content", prefixCls + "-content-" + position, (_a2 = {}, _a2[prefixCls + "-mini"] = mini, _a2)),
          role: "tooltip",
          children: /* @__PURE__ */ jsx("div", {
            className: prefixCls + "-content-inner",
            children: renderedContent
          })
        });
      },
      position,
      disabled,
      trigger,
      escToClose,
      showArrow: true,
      popupAlign: {
        left: 12,
        right: 12,
        top: 12,
        bottom: 12
      },
      mouseEnterDelay: 200,
      mouseLeaveDelay: 200,
      unmountOnExit,
      popupHoverStay,
      blurToHide,
      childrenPrefix: childrenPrefix || prefixCls,
      getPopupContainer,
      onVisibleChange,
      defaultPopupVisible
    }, otherProps),
    children
  });
}
var TooltipComponent = forwardRef(Tooltip);
TooltipComponent.displayName = "Tooltip";
const Tooltip$1 = TooltipComponent;
export {
  Tooltip$1 as default
};
//# sourceMappingURL=index.js.map
