import { defineComponent, inject, ref, provide, createElementBlock, onMounted, watch, unref, onBeforeUnmount, openBlock, mergeProps, createVNode, withCtx, renderSlot } from "vue";
import { NOOP as n } from "../../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import { POPPER_CONTENT_INJECTION_KEY as p } from "./constants.mjs";
import { popperContentEmits as s, popperContentProps as u } from "./content2.mjs";
import c from "../../../_virtual/plugin-vue_export-helper.mjs";
import { usePopperContentFocusTrap as d } from "./composables/use-focus-trap.mjs";
import { usePopperContent as B } from "./composables/use-content.mjs";
import { usePopperContentDOM as w } from "./composables/use-content-dom.mjs";
import { formItemContextKey as t } from "../../form/src/constants.mjs";
import { isElement as s$1 } from "../../../utils/types.mjs";
import ve from "../../focus-trap/src/focus-trap.mjs";
import n$1 from "../../../../../lodash-es/isNil.mjs";
const ie = defineComponent({
  name: "ElPopperContent"
}), ue = /* @__PURE__ */ defineComponent({
  ...ie,
  props: u,
  emits: s,
  setup(A, { expose: b, emit: T }) {
    const t$1 = A, {
      focusStartRef: _,
      trapped: u2,
      onFocusAfterReleased: g,
      onFocusAfterTrapped: O,
      onFocusInTrap: N,
      onFocusoutPrevented: S,
      onReleaseRequested: w$1
    } = d(t$1, T), { attributes: y, arrowRef: M, contentRef: a, styles: x, instanceRef: q, role: m, update: B$1 } = B(t$1), {
      ariaModal: $,
      arrowStyle: h,
      contentAttrs: k,
      contentClass: K,
      contentStyle: d$1,
      updateZIndex: j
    } = w(t$1, {
      styles: x,
      attributes: y,
      role: m
    }), p$1 = inject(t, void 0), D = ref();
    provide(p, {
      arrowStyle: h,
      arrowRef: M,
      arrowOffset: D
    }), p$1 && (p$1.addInputId || p$1.removeInputId) && provide(t, {
      ...p$1,
      addInputId: n,
      removeInputId: n
    });
    let r;
    const c2 = (n2 = true) => {
      B$1(), n2 && j();
    }, J = () => {
      c2(false), t$1.visible && t$1.focusOnShow ? u2.value = true : t$1.visible === false && (u2.value = false);
    };
    return onMounted(() => {
      watch(() => t$1.triggerTargetEl, (n2, s2) => {
        r == null || r(), r = void 0;
        const o = unref(n2 || a.value), l = unref(s2 || a.value);
        s$1(o) && (r = watch([m, () => t$1.ariaLabel, $, () => t$1.id], (i) => {
          ["role", "aria-label", "aria-modal", "id"].forEach((v, R) => {
            n$1(i[R]) ? o.removeAttribute(v) : o.setAttribute(v, i[R]);
          });
        }, { immediate: true })), l !== o && s$1(l) && ["role", "aria-label", "aria-modal", "id"].forEach((i) => {
          l.removeAttribute(i);
        });
      }, { immediate: true }), watch(() => t$1.visible, J, { immediate: true });
    }), onBeforeUnmount(() => {
      r == null || r(), r = void 0;
    }), b({
      popperContentRef: a,
      popperInstanceRef: q,
      updatePopper: c2,
      contentStyle: d$1
    }), (n2, s2) => (openBlock(), createElementBlock("div", mergeProps({
      ref_key: "contentRef",
      ref: a
    }, unref(k), {
      style: unref(d$1),
      class: unref(K),
      tabindex: "-1",
      onMouseenter: s2[0] || (s2[0] = (o) => n2.$emit("mouseenter", o)),
      onMouseleave: s2[1] || (s2[1] = (o) => n2.$emit("mouseleave", o))
    }), [
      createVNode(unref(ve), {
        trapped: unref(u2),
        "trap-on-focus-in": true,
        "focus-trap-el": unref(a),
        "focus-start-el": unref(_),
        onFocusAfterTrapped: unref(O),
        onFocusAfterReleased: unref(g),
        onFocusin: unref(N),
        onFocusoutPrevented: unref(S),
        onReleaseRequested: unref(w$1)
      }, {
        default: withCtx(() => [
          renderSlot(n2.$slots, "default")
        ]),
        _: 3
      }, 8, ["trapped", "focus-trap-el", "focus-start-el", "onFocusAfterTrapped", "onFocusAfterReleased", "onFocusin", "onFocusoutPrevented", "onReleaseRequested"])
    ], 16));
  }
});
var Ae = /* @__PURE__ */ c(ue, [["__file", "content.vue"]]);
export {
  Ae as default
};
