/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, inject, computed, onMounted } from '@vue/composition-api';
import { MenuItemProps } from './props.js';
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 '../../chunks/set-style.js';
import '../../config.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../config-provider/useConfig.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var keepAnimationMixins = getKeepAnimationMixins();
var _MenuItem = defineComponent({
  name: "LMenuItem",
  mixins: [keepAnimationMixins],
  props: _objectSpread({}, MenuItemProps),
  directives: {
    ripple: Ripple
  },
  setup: function setup(props2, ctx) {
    var menu = inject("LdMenu");
    var submenu = inject("LdSubmenu", null);
    var active = computed(function () {
      return menu.activeValue.value === props2.value;
    });
    var classPrefix = usePrefixClass();
    var classes = computed(function () {
      var _ref;

      return ["".concat(classPrefix.value, "-menu__item"), (_ref = {}, _defineProperty(_ref, "".concat(classPrefix.value, "-is-active"), active.value), _defineProperty(_ref, "".concat(classPrefix.value, "-is-disabled"), props2.disabled), _defineProperty(_ref, "".concat(classPrefix.value, "-menu__item--plain"), !ctx.slots.icon && !props2.icon), _defineProperty(_ref, "".concat(classPrefix.value, "-submenu__item"), !!submenu && !menu.isHead), _ref)];
    });

    var handleClick = function 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) {
        var router = props2.router || ctx.root.$router;
        var methods = props2.replace ? "replace" : "push";
        router[methods](props2.to)["catch"](function (err) {
          if (err.name !== "NavigationDuplicated" && !err.message.includes("Avoided redundant navigation to current location")) {
            throw err;
          }
        });
      }
    };

    onMounted(function () {
      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: menu,
      active: active,
      classes: classes,
      handleClick: handleClick,
      classPrefix: classPrefix
    };
  },
  render: function render() {
    var 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": ["".concat(this.classPrefix, "-menu__content")]
    }, [renderContent(this, "default", "content")])]);
  }
});

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