import { defineComponent, provide, getCurrentInstance, onMounted, cloneVNode } from 'vue';
import { useTooltipProps } from './props.mjs';
import { groupToolTipInjectKey, seekParent } from './utils.mjs';
import { useTooltip } from './method.mjs';

const GroupTooltip = defineComponent({
  name: "ElGroupTooltip",
  props: useTooltipProps,
  setup(props, ctx) {
    const uniqueValue = `${Math.random()}${Date.now()}`;
    const instanceData = /* @__PURE__ */ new WeakMap();
    provide(groupToolTipInjectKey, {
      key: uniqueValue,
      instanceData
    });
    let root = null;
    let lastNode = null;
    const eventListener = (e) => {
      const node = seekParent(e, uniqueValue, root);
      if (node === lastNode) {
        return;
      }
      if (node) {
        lastNode = node;
        const tooltipData = instanceData.get(node);
        if (tooltipData.value) {
          useTooltip({
            ...tooltipData.value,
            onHide: (value) => {
              var _a, _b;
              lastNode = null;
              (_b = (_a = tooltipData.value).onHide) == null ? void 0 : _b.call(_a, value);
            }
          }, node);
        }
      }
    };
    const instance = getCurrentInstance();
    onMounted(() => {
      var _a;
      root = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.$el;
    });
    return () => {
      const eventProps = {};
      if (props.trigger === "click") {
        eventProps.onClick = eventListener;
      } else if (props.trigger === "focus") {
        eventProps.onFocus = eventListener;
      } else if (props.trigger === "hover") {
        eventProps.onMouseover = eventListener;
      }
      return cloneVNode(ctx.slots.default()[0], eventProps);
    };
  }
});

export { GroupTooltip };
//# sourceMappingURL=group-tooltip.mjs.map
