"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../utils/types.js");
const error = require("../../../utils/error.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../tooltip/index.js");
const useMenu = require("./use-menu.js");
const tokens = require("./tokens.js");
const menuItem = require("./menu-item.js");
const Vue = require("vue");
const COMPONENT_NAME = "ElMenuItem";
var menu_item_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: COMPONENT_NAME,
  __name: "menu-item",
  props: menuItem.menuItemProps,
  emits: menuItem.menuItemEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    types.isPropAbsent(props.index) && error.debugWarn(COMPONENT_NAME, 'Missing required prop: "index"');
    const instance = Vue.getCurrentInstance();
    const rootMenu = Vue.inject(tokens.MENU_INJECTION_KEY);
    const nsMenu = index.useNamespace("menu");
    const nsMenuItem = index.useNamespace("menu-item");
    if (!rootMenu) error.throwError(COMPONENT_NAME, "can not inject root menu");
    const { parentMenu, indexPath } = useMenu.default(instance, Vue.toRef(props, "index"));
    const subMenu = Vue.inject(`${tokens.SUB_MENU_INJECTION_KEY}${parentMenu.value.uid}`);
    if (!subMenu) error.throwError(COMPONENT_NAME, "can not inject sub menu");
    const active = Vue.computed(() => props.index === rootMenu.activeIndex);
    const item = Vue.reactive({
      index: props.index,
      indexPath,
      active
    });
    const handleClick = () => {
      if (!props.disabled) {
        rootMenu.handleMenuItemClick({
          index: props.index,
          indexPath: indexPath.value,
          route: props.route
        });
        emit("click", item);
      }
    };
    Vue.onMounted(() => {
      subMenu.addSubMenu(item);
      rootMenu.addMenuItem(item);
    });
    Vue.onBeforeUnmount(() => {
      subMenu.removeSubMenu(item);
      rootMenu.removeMenuItem(item);
    });
    __expose({
      parentMenu,
      rootMenu,
      active,
      nsMenu,
      nsMenuItem,
      handleClick
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("li", {
        class: Vue.normalizeClass([
          Vue.unref(nsMenuItem).b(),
          Vue.unref(nsMenuItem).is("active", active.value),
          Vue.unref(nsMenuItem).is("disabled", __props.disabled)
        ]),
        role: "menuitem",
        tabindex: "-1",
        onClick: handleClick
      }, [Vue.unref(parentMenu).type.name === "ElMenu" && Vue.unref(rootMenu).props.collapse && _ctx.$slots.title ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$1.ElTooltip), {
        key: 0,
        effect: Vue.unref(rootMenu).props.popperEffect,
        placement: "right",
        "fallback-placements": ["left"],
        "popper-class": Vue.unref(rootMenu).props.popperClass,
        "popper-style": Vue.unref(rootMenu).props.popperStyle,
        persistent: Vue.unref(rootMenu).props.persistent,
        "focus-on-target": ""
      }, {
        content: Vue.withCtx(() => [Vue.renderSlot(_ctx.$slots, "title")]),
        default: Vue.withCtx(() => [Vue.createElementVNode("div", { class: Vue.normalizeClass(Vue.unref(nsMenu).be("tooltip", "trigger")) }, [Vue.renderSlot(_ctx.$slots, "default")], 2)]),
        _: 3
      }, 8, [
        "effect",
        "popper-class",
        "popper-style",
        "persistent"
      ])) : (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 1 }, [Vue.renderSlot(_ctx.$slots, "default"), Vue.renderSlot(_ctx.$slots, "title")], 64))], 2);
    };
  }
});
exports.default = menu_item_vue_vue_type_script_setup_true_lang_default;
