'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/vc-tooltip/index.cjs');
require('../../../vue-components/transition/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var util = require('./util.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var log = require('../../../utils/log.cjs');
var firstNotUndefined = require('../../../utils/lang/firstNotUndefined.cjs');
var raf = require('../../../utils/vue/raf.cjs');
var placement = require('../../../utils/placement.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var is = require('../../../utils/is.cjs');
var _class = require('../../../utils/dom/class.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');
var Tooltip = require('../../../vue-components/vc-tooltip/src/Tooltip.cjs');

function splitObject(obj, keys) {
  const picked = {};
  const omitted = {
    ...obj
  };
  keys.forEach((key) => {
    if (obj && key in obj) {
      picked[key] = obj[key];
      delete omitted[key];
    }
  });
  return {
    picked,
    omitted
  };
}
var AToolTip = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ATooltip",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.tooltipProps(), {
    trigger: "hover",
    align: {},
    placement: "top",
    mouseEnterDelay: 0.1,
    mouseLeaveDelay: 0.1,
    arrowPointAtCenter: false,
    autoAdjustOverflow: true
  }),
  slots: Object,
  // emits: ['update:visible', 'visibleChange'],
  setup(props, {
    slots,
    emit,
    attrs,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      [["visible", "open"], ["onVisibleChange", "onOpenChange"]].forEach(([deprecatedName, newName]) => {
        log.devWarning(props[deprecatedName] === void 0, "Tooltip", `\`${deprecatedName}\` is deprecated, please use \`${newName}\` instead.`);
      });
    }
    const {
      prefixCls,
      getPopupContainer,
      direction,
      rootPrefixCls
    } = useConfigInject.default("tooltip", props);
    const mergedOpen = vue.computed(() => {
      var _a;
      return (_a = props.open) != null ? _a : props.visible;
    });
    const innerOpen = vue.ref(firstNotUndefined.firstNotUndefined([props.open, props.visible]));
    const tooltip = vue.ref();
    let rafId;
    vue.watch(mergedOpen, (val) => {
      raf.raf.cancel(rafId);
      rafId = raf.raf(() => {
        innerOpen.value = !!val;
      });
    });
    const isNoTitle = () => {
      var _a;
      const title = (_a = props.title) != null ? _a : slots.title;
      return !title && title !== 0;
    };
    const handleVisibleChange = (val) => {
      const noTitle = isNoTitle();
      if (mergedOpen.value === void 0)
        innerOpen.value = noTitle ? false : val;
      if (!noTitle) {
        emit("update:visible", val);
        emit("visibleChange", val);
        emit("update:open", val);
        emit("openChange", val);
      }
    };
    const getPopupDomNode = () => {
      return tooltip.value.getPopupDomNode();
    };
    expose({
      getPopupDomNode,
      open: innerOpen,
      forcePopupAlign: () => {
        var _a;
        return (_a = tooltip.value) == null ? void 0 : _a.forcePopupAlign();
      }
    });
    const tooltipPlacements = vue.computed(() => {
      const {
        builtinPlacements,
        arrowPointAtCenter,
        autoAdjustOverflow
      } = props;
      return builtinPlacements || placement.getPlacements({
        arrowPointAtCenter,
        autoAdjustOverflow
      });
    });
    const isTrueProps = (val) => {
      return val || val === "";
    };
    const getDisabledCompatibleChildren = (ele) => {
      const elementType = ele.type;
      if (typeof elementType === "object" && ele.props) {
        if ((elementType.__ANT_BUTTON === true || elementType === "button") && isTrueProps(ele.props.disabled) || elementType.__ANT_SWITCH === true && (isTrueProps(ele.props.disabled) || isTrueProps(ele.props.loading)) || elementType.__ANT_RADIO === true && isTrueProps(ele.props.disabled)) {
          const {
            picked,
            omitted
          } = splitObject(props$1.getStyle(ele), ["position", "left", "right", "top", "bottom", "float", "display", "zIndex"]);
          const spanStyle = {
            display: "inline-block",
            // default inline-block is important
            ...picked,
            cursor: "not-allowed",
            lineHeight: 1,
            // use the true height of child nodes
            width: ele.props && ele.props.block ? "100%" : void 0
          };
          const buttonStyle = {
            ...omitted,
            pointerEvents: "none"
          };
          const child = vnode.cloneElement(ele, {
            style: buttonStyle
          }, true);
          return vue.createVNode("span", {
            "style": spanStyle,
            "class": `${prefixCls.value}-disabled-compatible-wrapper`
          }, [child]);
        }
      }
      return ele;
    };
    const getOverlay = () => {
      var _a, _b;
      return (_b = props.title) != null ? _b : (_a = slots.title) == null ? void 0 : _a.call(slots);
    };
    const onPopupAlign = (domNode, align) => {
      const placements = tooltipPlacements.value;
      const placement = Object.keys(placements).find((key) => {
        var _a, _b;
        return placements[key].points[0] === ((_a = align.points) == null ? void 0 : _a[0]) && placements[key].points[1] === ((_b = align.points) == null ? void 0 : _b[1]);
      });
      if (placement) {
        const rect = domNode.getBoundingClientRect();
        const transformOrigin = {
          top: "50%",
          left: "50%"
        };
        if (placement.includes("top") || placement.includes("Bottom"))
          transformOrigin.top = `${rect.height - align.offset[1]}px`;
        else if (placement.includes("Top") || placement.includes("bottom"))
          transformOrigin.top = `${-align.offset[1]}px`;
        if (placement.includes("left") || placement.includes("Right"))
          transformOrigin.left = `${rect.width - align.offset[0]}px`;
        else if (placement.includes("right") || placement.includes("Left"))
          transformOrigin.left = `${-align.offset[0]}px`;
        domNode.style.transformOrigin = `${transformOrigin.left} ${transformOrigin.top}`;
      }
    };
    const colorInfo = vue.computed(() => util.parseColor(prefixCls.value, props.color));
    const injectFromPopover = vue.computed(() => attrs["data-popover-inject"]);
    const [wrapSSR, hashId] = index.default(prefixCls, vue.computed(() => !injectFromPopover.value));
    return () => {
      var _a, _b;
      const {
        openClassName,
        overlayClassName,
        overlayStyle,
        overlayInnerStyle
      } = props;
      let children = (_b = props$1.filterEmpty((_a = slots.default) == null ? void 0 : _a.call(slots))) != null ? _b : null;
      children = children.length === 1 ? children[0] : children;
      let tempVisible = innerOpen.value;
      if (mergedOpen.value === void 0 && isNoTitle())
        tempVisible = false;
      if (!children)
        return null;
      const child = getDisabledCompatibleChildren(is.isValidElement(children) && !is.isFragment(children) ? children : vue.createVNode("span", null, [children]));
      const childCls = _class.classNames({
        [openClassName || `${prefixCls.value}-open`]: true,
        [child.props && child.props.class]: child.props && child.props.class
      });
      const customOverlayClassName = _class.classNames(overlayClassName, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, colorInfo.value.className, hashId.value);
      const formattedOverlayInnerStyle = {
        ...colorInfo.value.overlayStyle,
        ...overlayInnerStyle
      };
      const arrowContentStyle = colorInfo.value.arrowStyle;
      const vcTooltipProps = {
        ...attrs,
        ...props,
        prefixCls: prefixCls.value,
        getPopupContainer: getPopupContainer == null ? void 0 : getPopupContainer.value,
        builtinPlacements: tooltipPlacements.value,
        visible: tempVisible,
        ref: tooltip,
        overlayClassName: customOverlayClassName,
        overlayStyle: {
          ...arrowContentStyle,
          ...overlayStyle
        },
        overlayInnerStyle: formattedOverlayInnerStyle,
        onVisibleChange: handleVisibleChange,
        onPopupAlign,
        transitionName: transition.getTransitionName(rootPrefixCls.value, "zoom-big-fast", props.transitionName)
      };
      return wrapSSR(vue.createVNode(Tooltip.default, vcTooltipProps, {
        default: () => [innerOpen.value ? vnode.cloneElement(child, {
          class: childCls
        }) : child],
        arrowContent: () => vue.createVNode("span", {
          "class": `${prefixCls.value}-arrow-content`
        }, null),
        overlay: getOverlay
      }));
    };
  }
});

exports.default = AToolTip;
//# sourceMappingURL=Tooltip.cjs.map
