"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const index$1 = require("../../../../../@vueuse/core/index.js");
const constants = require("./constants.js");
const trigger = require("./trigger.js");
const pluginVue_exportHelper = require("../../../_virtual/plugin-vue_export-helper.js");
const index = require("../../../hooks/use-forward-ref/index.js");
const types = require("../../../utils/types.js");
const onlyChild = require("../../slot/src/only-child.js");
const isNil = require("../../../../../lodash-es/isNil.js");
const I = Vue.defineComponent({
  name: "ElPopperTrigger",
  inheritAttrs: false
}), K = /* @__PURE__ */ Vue.defineComponent({
  ...I,
  props: trigger.popperTriggerProps,
  setup(h, { expose: _ }) {
    const o = h, { role: n, triggerRef: s } = Vue.inject(constants.POPPER_INJECTION_KEY, void 0);
    index.useForwardRef(s);
    const c = Vue.computed(() => u.value ? o.id : void 0), f = Vue.computed(() => {
      if (n && n.value === "tooltip")
        return o.open && o.id ? o.id : void 0;
    }), u = Vue.computed(() => {
      if (n && n.value !== "tooltip")
        return n.value;
    }), v = Vue.computed(() => u.value ? `${o.open}` : void 0);
    let i;
    return Vue.onMounted(() => {
      Vue.watch(() => o.virtualRef, (r) => {
        r && (s.value = index$1.unrefElement(r));
      }, {
        immediate: true
      }), Vue.watch(s, (r, t) => {
        i == null || i(), i = void 0, types.isElement(r) && ([
          "onMouseenter",
          "onMouseleave",
          "onClick",
          "onKeydown",
          "onFocus",
          "onBlur",
          "onContextmenu"
        ].forEach((e) => {
          var d;
          const a = o[e];
          a && (r.addEventListener(e.slice(2).toLowerCase(), a), (d = t == null ? void 0 : t.removeEventListener) == null || d.call(t, e.slice(2).toLowerCase(), a));
        }), i = Vue.watch([c, f, u, v], (e) => {
          [
            "aria-controls",
            "aria-describedby",
            "aria-haspopup",
            "aria-expanded"
          ].forEach((d, a) => {
            isNil.default(e[a]) ? r.removeAttribute(d) : r.setAttribute(d, e[a]);
          });
        }, { immediate: true })), types.isElement(t) && [
          "aria-controls",
          "aria-describedby",
          "aria-haspopup",
          "aria-expanded"
        ].forEach((e) => t.removeAttribute(e));
      }, {
        immediate: true
      });
    }), Vue.onBeforeUnmount(() => {
      i == null || i(), i = void 0;
    }), _({
      triggerRef: s
    }), (r, t) => r.virtualTriggering ? Vue.createCommentVNode("v-if", true) : (Vue.openBlock(), Vue.createBlock(Vue.unref(onlyChild.OnlyChild), Vue.mergeProps({ key: 0 }, r.$attrs, {
      "aria-controls": Vue.unref(c),
      "aria-describedby": Vue.unref(f),
      "aria-expanded": Vue.unref(v),
      "aria-haspopup": Vue.unref(u)
    }), {
      default: Vue.withCtx(() => [
        Vue.renderSlot(r.$slots, "default")
      ]),
      _: 3
    }, 16, ["aria-controls", "aria-describedby", "aria-expanded", "aria-haspopup"]));
  }
});
var Y = /* @__PURE__ */ pluginVue_exportHelper.default(K, [["__file", "trigger.vue"]]);
exports.default = Y;
