/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 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/use-config.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('../../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("LdMenu");
    const submenu = VueCompositionAPI.inject("LdSubmenu", 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(() => {
      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
      }
    }, [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
