import { defineComponent, ref, toRef, computed, provide, readonly, unref, watch, createBlock, onDeactivated, openBlock, withCtx, createVNode, renderSlot, createCommentVNode, createElementBlock, toDisplayString } from "vue";
import { ElPopper as e } from "../../popper/index.mjs";
import { TOOLTIP_INJECTION_KEY as o$1 } from "./constants.mjs";
import { tooltipEmits as M, useTooltipProps as n, useTooltipModelToggle as P } from "./tooltip.mjs";
import Q from "./trigger2.mjs";
import he from "./content2.mjs";
import c from "../../../_virtual/plugin-vue_export-helper.mjs";
import { usePopperContainer as C } from "../../../hooks/use-popper-container/index.mjs";
import { useId as b } from "../../../hooks/use-id/index.mjs";
import { useDelayedToggle as N } from "../../../hooks/use-delayed-toggle/index.mjs";
import { isBoolean as o } from "../../../utils/types.mjs";
import R from "../../popper/src/arrow2.mjs";
const _ = ["innerHTML"], x = { key: 1 }, ee = defineComponent({
  name: "ElTooltip"
}), oe = /* @__PURE__ */ defineComponent({
  ...ee,
  props: n,
  emits: M,
  setup(R$1, { expose: A, emit: a }) {
    const o$2 = R$1;
    C();
    const P$1 = b(), f = ref(), d = ref(), v = () => {
      var e2;
      const t = unref(f);
      t && ((e2 = t.popperInstanceRef) == null || e2.update());
    }, r = ref(false), n2 = ref(), { show: I, hide: g, hasUpdateHandler: O } = P({
      indicator: r,
      toggleReason: n2
    }), { onOpen: u, onClose: m } = N({
      showAfter: toRef(o$2, "showAfter"),
      hideAfter: toRef(o$2, "hideAfter"),
      autoClose: toRef(o$2, "autoClose"),
      open: I,
      close: g
    }), B = computed(() => o(o$2.visible) && !O.value);
    provide(o$1, {
      controlled: B,
      id: P$1,
      open: readonly(r),
      trigger: toRef(o$2, "trigger"),
      onOpen: (e2) => {
        u(e2);
      },
      onClose: (e2) => {
        m(e2);
      },
      onToggle: (e2) => {
        unref(r) ? m(e2) : u(e2);
      },
      onShow: () => {
        a("show", n2.value);
      },
      onHide: () => {
        a("hide", n2.value);
      },
      onBeforeShow: () => {
        a("before-show", n2.value);
      },
      onBeforeHide: () => {
        a("before-hide", n2.value);
      },
      updatePopper: v
    }), watch(() => o$2.disabled, (e2) => {
      e2 && r.value && (r.value = false);
    });
    const H = (e2) => {
      var t, h;
      const b2 = (h = (t = d.value) == null ? void 0 : t.contentRef) == null ? void 0 : h.popperContentRef, S = (e2 == null ? void 0 : e2.relatedTarget) || document.activeElement;
      return b2 && b2.contains(S);
    };
    return onDeactivated(() => r.value && g()), A({
      popperRef: f,
      contentRef: d,
      isFocusInsideContent: H,
      updatePopper: v,
      onOpen: u,
      onClose: m,
      hide: g
    }), (e$1, t) => (openBlock(), createBlock(unref(e), {
      ref_key: "popperRef",
      ref: f,
      role: e$1.role
    }, {
      default: withCtx(() => [
        createVNode(Q, {
          disabled: e$1.disabled,
          trigger: e$1.trigger,
          "trigger-keys": e$1.triggerKeys,
          "virtual-ref": e$1.virtualRef,
          "virtual-triggering": e$1.virtualTriggering
        }, {
          default: withCtx(() => [
            e$1.$slots.default ? renderSlot(e$1.$slots, "default", { key: 0 }) : createCommentVNode("v-if", true)
          ]),
          _: 3
        }, 8, ["disabled", "trigger", "trigger-keys", "virtual-ref", "virtual-triggering"]),
        createVNode(he, {
          ref_key: "contentRef",
          ref: d,
          "aria-label": e$1.ariaLabel,
          "boundaries-padding": e$1.boundariesPadding,
          content: e$1.content,
          disabled: e$1.disabled,
          effect: e$1.effect,
          enterable: e$1.enterable,
          "fallback-placements": e$1.fallbackPlacements,
          "hide-after": e$1.hideAfter,
          "gpu-acceleration": e$1.gpuAcceleration,
          offset: e$1.offset,
          persistent: e$1.persistent,
          "popper-class": e$1.popperClass,
          "popper-style": e$1.popperStyle,
          placement: e$1.placement,
          "popper-options": e$1.popperOptions,
          pure: e$1.pure,
          "raw-content": e$1.rawContent,
          "reference-el": e$1.referenceEl,
          "trigger-target-el": e$1.triggerTargetEl,
          "show-after": e$1.showAfter,
          strategy: e$1.strategy,
          teleported: e$1.teleported,
          transition: e$1.transition,
          "virtual-triggering": e$1.virtualTriggering,
          "z-index": e$1.zIndex,
          "append-to": e$1.appendTo
        }, {
          default: withCtx(() => [
            renderSlot(e$1.$slots, "content", {}, () => [
              e$1.rawContent ? (openBlock(), createElementBlock("span", {
                key: 0,
                innerHTML: e$1.content
              }, null, 8, _)) : (openBlock(), createElementBlock("span", x, toDisplayString(e$1.content), 1))
            ]),
            e$1.showArrow ? (openBlock(), createBlock(unref(R), {
              key: 0,
              "arrow-offset": e$1.arrowOffset
            }, null, 8, ["arrow-offset"])) : createCommentVNode("v-if", true)
          ]),
          _: 3
        }, 8, ["aria-label", "boundaries-padding", "content", "disabled", "effect", "enterable", "fallback-placements", "hide-after", "gpu-acceleration", "offset", "persistent", "popper-class", "popper-style", "placement", "popper-options", "pure", "raw-content", "reference-el", "trigger-target-el", "show-after", "strategy", "teleported", "transition", "virtual-triggering", "z-index", "append-to"])
      ]),
      _: 3
    }, 8, ["role"]));
  }
});
var me = /* @__PURE__ */ c(oe, [["__file", "tooltip.vue"]]);
export {
  me as default
};
