/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { defineComponent, inject, computed, onMounted } from '@vue/composition-api';
import Ripple from '../../utils/ripple.js';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import { getKeepAnimationMixins } from '../config-provider/config-receiver.js';
import { usePrefixClass } from '../../hooks/use-config.js';
import { MenuItemProps } from './props.js';
import '../../chunks/set-style.js';
import '../../config.js';
import 'vue';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../config-provider/useConfig.js';

const keepAnimationMixins = getKeepAnimationMixins();
var _MenuItem = defineComponent({
  name: "LMenuItem",
  directives: {
    ripple: Ripple
  },
  mixins: [keepAnimationMixins],
  props: {
    ...MenuItemProps
  },
  setup(props2, ctx) {
    const menu = inject("LdMenu");
    const submenu = inject("LdSubmenu", null);
    const active = computed(() => menu.activeValue.value === props2.value);
    const classPrefix = usePrefixClass();
    const classes = computed(() => [`${classPrefix.value}-menu__item`, {
      [`${classPrefix.value}-is-active`]: active.value,
      [`${classPrefix.value}-is-disabled`]: props2.disabled,
      [`${classPrefix.value}-menu__item--plain`]: !ctx.slots.icon && !props2.icon,
      [`${classPrefix.value}-submenu__item`]: !!submenu && !menu.isHead
    }]);
    const handleClick = () => {
      if (props2.disabled) return;
      menu.select(props2.value);
      ctx.emit("click");
      if (props2.href) {
        window.open(props2.href, props2.target);
      } else if (props2.to) {
        const router = props2.router || ctx.root.$router;
        const methods = props2.replace ? "replace" : "push";
        router[methods](props2.to).catch(err => {
          if (err.name !== "NavigationDuplicated" && !err.message.includes("Avoided redundant navigation to current location")) throw err;
        });
      }
    };
    onMounted(() => {
      var _menu$vMenu;
      menu === null || menu === void 0 ? void 0 : (_menu$vMenu = menu.vMenu) === null || _menu$vMenu === void 0 ? void 0 : _menu$vMenu.add({
        value: props2.value,
        parent: submenu === null || submenu === void 0 ? void 0 : submenu.value,
        vnode: ctx.slots.default && ctx.slots.default()
      });
    });
    return {
      menu,
      active,
      classes,
      handleClick,
      classPrefix
    };
  },
  render() {
    const h = arguments[0];
    return h("li", {
      "directives": [{
        name: "ripple",
        value: this.keepAnimation.ripple
      }],
      "class": this.classes,
      "on": {
        "click": this.handleClick
      }
    }, [renderLNodeJSX(this, "icon"), h("span", {
      "class": [`${this.classPrefix}-menu__content`]
    }, [renderContent(this, "default", "content")])]);
  }
});

export { _MenuItem as default };
//# sourceMappingURL=menu-item.js.map
