"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const aria = require("../../../utils/dom/aria.js");
const event = require("../../../utils/dom/event.js");
const index = require("../../../hooks/use-namespace/index.js");
const trigger2 = require("../../popper/src/trigger2.js");
const trigger = require("./trigger.js");
const constants = require("./constants.js");
const utils = require("./utils.js");
const Vue = require("vue");
var trigger_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElTooltipTrigger",
  __name: "trigger",
  props: trigger.useTooltipTriggerProps,
  setup(__props, { expose: __expose }) {
    const props = __props;
    const ns = index.useNamespace("tooltip");
    const { controlled, id, open, onOpen, onClose, onToggle } = Vue.inject(constants.TOOLTIP_INJECTION_KEY, void 0);
    const triggerRef = Vue.ref(null);
    const stopWhenControlledOrDisabled = () => {
      if (Vue.unref(controlled) || props.disabled) return true;
    };
    const trigger3 = Vue.toRef(props, "trigger");
    const onMouseenter = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "hover", (e) => {
      onOpen(e);
      if (props.focusOnTarget && e.target) Vue.nextTick(() => {
        aria.focusElement(e.target, { preventScroll: true });
      });
    }));
    const onMouseleave = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "hover", onClose));
    const onClick = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "click", (e) => {
      if (e.button === 0) onToggle(e);
    }));
    const onFocus = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "focus", onOpen));
    const onBlur = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "focus", onClose));
    const onContextMenu = event.composeEventHandlers(stopWhenControlledOrDisabled, utils.whenTrigger(trigger3, "contextmenu", (e) => {
      e.preventDefault();
      onToggle(e);
    }));
    const onKeydown = event.composeEventHandlers(stopWhenControlledOrDisabled, (e) => {
      const code = event.getEventCode(e);
      if (props.triggerKeys.includes(code)) {
        e.preventDefault();
        onToggle(e);
      }
    });
    __expose({ triggerRef });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createBlock(Vue.unref(trigger2.default), {
        id: Vue.unref(id),
        "virtual-ref": __props.virtualRef,
        open: Vue.unref(open),
        "virtual-triggering": __props.virtualTriggering,
        class: Vue.normalizeClass(Vue.unref(ns).e("trigger")),
        onBlur: Vue.unref(onBlur),
        onClick: Vue.unref(onClick),
        onContextmenu: Vue.unref(onContextMenu),
        onFocus: Vue.unref(onFocus),
        onMouseenter: Vue.unref(onMouseenter),
        onMouseleave: Vue.unref(onMouseleave),
        onKeydown: Vue.unref(onKeydown)
      }, {
        default: Vue.withCtx(() => [Vue.renderSlot(_ctx.$slots, "default")]),
        _: 3
      }, 8, [
        "id",
        "virtual-ref",
        "open",
        "virtual-triggering",
        "class",
        "onBlur",
        "onClick",
        "onContextmenu",
        "onFocus",
        "onMouseenter",
        "onMouseleave",
        "onKeydown"
      ]);
    };
  }
});
exports.default = trigger_vue_vue_type_script_setup_true_lang_default;
