"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../utils/types.js");
const index$1 = require("../../../hooks/use-namespace/index.js");
const index$2 = require("../../../hooks/use-id/index.js");
const index = require("../../../hooks/use-popper-container/index.js");
const index$3 = require("../../../hooks/use-delayed-toggle/index.js");
const arrow2 = require("../../popper/src/arrow2.js");
const index$4 = require("../../popper/index.js");
const tooltip = require("./tooltip.js");
const constants = require("./constants.js");
const trigger2 = require("./trigger2.js");
const content2 = require("./content2.js");
const Vue = require("vue");
const _hoisted_1 = ["innerHTML"];
const _hoisted_2 = { key: 1 };
var tooltip_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElTooltip",
  __name: "tooltip",
  props: tooltip.useTooltipProps,
  emits: tooltip.tooltipEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    index.usePopperContainer();
    const ns = index$1.useNamespace("tooltip");
    const id = index$2.useId();
    const popperRef = Vue.ref();
    const contentRef = Vue.ref();
    const updatePopper = () => {
      var _a;
      const popperComponent = Vue.unref(popperRef);
      if (popperComponent) (_a = popperComponent.popperInstanceRef) == null ? void 0 : _a.update();
    };
    const open = Vue.ref(false);
    const toggleReason = Vue.ref();
    const { show, hide, hasUpdateHandler } = tooltip.useTooltipModelToggle({
      indicator: open,
      toggleReason
    });
    const { onOpen, onClose } = index$3.useDelayedToggle({
      showAfter: Vue.toRef(props, "showAfter"),
      hideAfter: Vue.toRef(props, "hideAfter"),
      autoClose: Vue.toRef(props, "autoClose"),
      open: show,
      close: hide
    });
    const controlled = Vue.computed(() => types.isBoolean(props.visible) && !hasUpdateHandler.value);
    const kls = Vue.computed(() => {
      return [ns.b(), props.popperClass];
    });
    Vue.provide(constants.TOOLTIP_INJECTION_KEY, {
      controlled,
      id,
      open: Vue.readonly(open),
      trigger: Vue.toRef(props, "trigger"),
      onOpen,
      onClose,
      onToggle: (event) => {
        if (Vue.unref(open)) onClose(event);
        else onOpen(event);
      },
      onShow: () => {
        emit("show", toggleReason.value);
      },
      onHide: () => {
        emit("hide", toggleReason.value);
      },
      onBeforeShow: () => {
        emit("before-show", toggleReason.value);
      },
      onBeforeHide: () => {
        emit("before-hide", toggleReason.value);
      },
      updatePopper
    });
    Vue.watch(() => props.disabled, (disabled) => {
      if (disabled && open.value) open.value = false;
      if (!disabled && types.isBoolean(props.visible)) open.value = props.visible;
    });
    const isFocusInsideContent = (event) => {
      var _a;
      return (_a = contentRef.value) == null ? void 0 : _a.isFocusInsideContent(event);
    };
    Vue.onDeactivated(() => open.value && hide());
    Vue.onBeforeUnmount(() => {
      toggleReason.value = void 0;
    });
    __expose({
      popperRef,
      contentRef,
      isFocusInsideContent,
      updatePopper,
      onOpen,
      onClose,
      hide
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createBlock(Vue.unref(index$4.ElPopper), {
        ref_key: "popperRef",
        ref: popperRef,
        role: __props.role
      }, {
        default: Vue.withCtx(() => [Vue.createVNode(trigger2.default, {
          disabled: __props.disabled,
          trigger: __props.trigger,
          "trigger-keys": __props.triggerKeys,
          "virtual-ref": __props.virtualRef,
          "virtual-triggering": __props.virtualTriggering,
          "focus-on-target": __props.focusOnTarget
        }, {
          default: Vue.withCtx(() => [_ctx.$slots.default ? Vue.renderSlot(_ctx.$slots, "default", { key: 0 }) : Vue.createCommentVNode("v-if", true)]),
          _: 3
        }, 8, [
          "disabled",
          "trigger",
          "trigger-keys",
          "virtual-ref",
          "virtual-triggering",
          "focus-on-target"
        ]), Vue.createVNode(content2.default, {
          ref_key: "contentRef",
          ref: contentRef,
          "aria-label": __props.ariaLabel,
          "boundaries-padding": __props.boundariesPadding,
          content: __props.content,
          disabled: __props.disabled,
          effect: __props.effect,
          enterable: __props.enterable,
          "fallback-placements": __props.fallbackPlacements,
          "hide-after": __props.hideAfter,
          "gpu-acceleration": __props.gpuAcceleration,
          offset: __props.offset,
          persistent: __props.persistent,
          "popper-class": kls.value,
          "popper-style": __props.popperStyle,
          placement: __props.placement,
          "popper-options": __props.popperOptions,
          "arrow-offset": __props.arrowOffset,
          pure: __props.pure,
          "raw-content": __props.rawContent,
          "reference-el": __props.referenceEl,
          "trigger-target-el": __props.triggerTargetEl,
          "show-after": __props.showAfter,
          strategy: __props.strategy,
          teleported: __props.teleported,
          transition: __props.transition,
          "virtual-triggering": __props.virtualTriggering,
          "z-index": __props.zIndex,
          "append-to": __props.appendTo,
          loop: __props.loop
        }, {
          default: Vue.withCtx(() => [Vue.renderSlot(_ctx.$slots, "content", {}, () => [__props.rawContent ? (Vue.openBlock(), Vue.createElementBlock("span", {
            key: 0,
            innerHTML: __props.content
          }, null, 8, _hoisted_1)) : (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_2, Vue.toDisplayString(__props.content), 1))]), __props.showArrow ? (Vue.openBlock(), Vue.createBlock(Vue.unref(arrow2.default), { key: 0 })) : Vue.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",
          "arrow-offset",
          "pure",
          "raw-content",
          "reference-el",
          "trigger-target-el",
          "show-after",
          "strategy",
          "teleported",
          "transition",
          "virtual-triggering",
          "z-index",
          "append-to",
          "loop"
        ])]),
        _: 3
      }, 8, ["role"]);
    };
  }
});
exports.default = tooltip_vue_vue_type_script_setup_true_lang_default;
