"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../utils/dom/event.js");
const rovingFocusItem = require("../../roving-focus-group/src/roving-focus-item.js");
const dropdown = require("./dropdown.js");
const tokens = require("./tokens.js");
const dropdownItemImpl = require("./dropdown-item-impl.js");
const useDropdown = require("./useDropdown.js");
const vue = require("vue");
var dropdown_item_vue_vue_type_script_lang_default = vue.defineComponent({
  name: "ElDropdownItem",
  components: {
    ElRovingFocusItem: rovingFocusItem.default,
    ElDropdownItemImpl: dropdownItemImpl.default
  },
  inheritAttrs: false,
  props: dropdown.dropdownItemProps,
  emits: [
    "pointermove",
    "pointerleave",
    "click"
  ],
  setup(props, { emit, attrs }) {
    const { elDropdown } = useDropdown.useDropdown();
    const _instance = vue.getCurrentInstance();
    const { onItemEnter, onItemLeave } = vue.inject(tokens.DROPDOWN_INJECTION_KEY, void 0);
    const handlePointerMove = event.composeEventHandlers((e) => {
      emit("pointermove", e);
      return e.defaultPrevented;
    }, event.whenMouse((e) => {
      if (props.disabled) {
        onItemLeave(e);
        return;
      }
      const target = e.currentTarget;
      if (target === document.activeElement || target.contains(document.activeElement)) return;
      onItemEnter(e);
      if (!e.defaultPrevented) target == null ? void 0 : target.focus({ preventScroll: true });
    }));
    const handlePointerLeave = event.composeEventHandlers((e) => {
      emit("pointerleave", e);
      return e.defaultPrevented;
    }, event.whenMouse(onItemLeave));
    return {
      handleClick: event.composeEventHandlers((e) => {
        if (props.disabled) return;
        emit("click", e);
        return e.type !== "keydown" && e.defaultPrevented;
      }, (e) => {
        var _a, _b, _c;
        if (props.disabled) {
          e.stopImmediatePropagation();
          return;
        }
        if ((_a = elDropdown == null ? void 0 : elDropdown.hideOnClick) == null ? void 0 : _a.value) (_b = elDropdown.handleClick) == null ? void 0 : _b.call(elDropdown);
        (_c = elDropdown.commandHandler) == null ? void 0 : _c.call(elDropdown, props.command, _instance, e);
      }),
      handlePointerMove,
      handlePointerLeave,
      propsAndAttrs: vue.computed(() => ({
        ...props,
        ...attrs
      }))
    };
  }
});
exports.default = dropdown_item_vue_vue_type_script_lang_default;
