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