'use strict';

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

var vue = require('vue');
require('../../../utils/index.js');
var props = require('./props.js');
var utils = require('./utils.js');
var method = require('./method.js');
var rand = require('../../../utils/rand.js');

const GroupTooltip = vue.defineComponent({
  name: "ElGroupTooltip",
  props: props.useTooltipProps,
  setup(props, ctx) {
    const uniqueValue = `el-group-tooltip__${rand.genRandomKey()}`;
    const instanceData = /* @__PURE__ */ new WeakMap();
    const destructionTooltipData = /* @__PURE__ */ new WeakMap();
    vue.provide(utils.groupToolTipInjectKey, {
      key: uniqueValue,
      instanceData,
      destructionTooltipFn
    });
    let root = null;
    let lastNode = null;
    function destructionTooltipFn(node) {
      var _a;
      (_a = destructionTooltipData.get(node)) == null ? void 0 : _a();
    }
    const eventListener = (e, eventName, parent) => {
      const node = utils.seekParent(e, uniqueValue, root, parent);
      if (node === lastNode) {
        return;
      }
      if (node) {
        const tooltipData = instanceData.get(node);
        if (tooltipData.value.trigger !== eventName)
          return;
        lastNode = node;
        if (tooltipData.value) {
          if (tooltipData.value.disabled) {
            e.stopPropagation();
            e.preventDefault();
            node.parentNode && eventListener(e, eventName, true);
            return;
          }
          const unUseTooltip = method.useTooltip({
            ...tooltipData.value,
            onHide: (value) => {
              var _a, _b;
              lastNode = null;
              (_b = (_a = tooltipData.value).onHide) == null ? void 0 : _b.call(_a, value);
            },
            closeUseTooltip: () => {
              lastNode = null;
            }
          }, node);
          vue.nextTick(() => {
            tooltipData.value.__tooltipRef__.value = unUseTooltip == null ? void 0 : unUseTooltip.ref;
          });
          destructionTooltipData.set(node, unUseTooltip);
        }
      }
    };
    const instance = vue.getCurrentInstance();
    vue.onMounted(() => {
      var _a;
      root = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.$el;
    });
    return () => {
      const eventProps = {
        onClick: (e) => eventListener(e, "click"),
        onFocus: (e) => eventListener(e, "focus"),
        onMouseover: (e) => eventListener(e, "hover")
      };
      return vue.cloneVNode(ctx.slots.default()[0], eventProps);
    };
  }
});

exports.GroupTooltip = GroupTooltip;
//# sourceMappingURL=group-tooltip.js.map
