'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();
    vue.provide(utils.groupToolTipInjectKey, {
      key: uniqueValue,
      instanceData
    });
    let root = null;
    let lastNode = null;
    const eventListener = (e, eventName) => {
      const node = utils.seekParent(e, uniqueValue, root);
      if (node === lastNode) {
        return;
      }
      if (node) {
        const tooltipData = instanceData.get(node);
        if (tooltipData.value.trigger !== eventName)
          return;
        lastNode = node;
        if (tooltipData.value) {
          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);
        }
      }
    };
    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
