/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var utils_ripple = require('../../utils/ripple.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var hooks_useConfig = require('../../hooks/useConfig.js');
var components_menu_props = require('./props.js');
require('../../chunks/set-style.js');
require('../../config.js');
require('vue');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../../chunks/zh_CN.js');
require('../config-provider/useConfig.js');

const keepAnimationMixins = components_configProvider_configReceiver.getKeepAnimationMixins();
var _MenuItem = VueCompositionAPI.defineComponent({
  name: "LMenuItem",
  directives: {
    ripple: utils_ripple["default"]
  },
  mixins: [keepAnimationMixins],
  props: {
    ...components_menu_props.MenuItemProps
  },
  setup(props2, ctx) {
    const menu = VueCompositionAPI.inject("TdMenu");
    const submenu = VueCompositionAPI.inject("TdSubmenu", null);
    const active = VueCompositionAPI.computed(() => menu.activeValue.value === props2.value);
    const classPrefix = hooks_useConfig.usePrefixClass();
    const classes = VueCompositionAPI.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;
        });
      }
    };
    VueCompositionAPI.onMounted(() => {
      menu?.vMenu?.add({
        value: props2.value,
        parent: 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
      }
    }, [utils_renderNode.renderLNodeJSX(this, "icon"), h("span", {
      "class": [`${this.classPrefix}-menu__content`]
    }, [utils_renderNode.renderContent(this, "default", "content")])]);
  }
});

exports["default"] = _MenuItem;
//# sourceMappingURL=menu-item.js.map
