/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var utils_renderTnode = require('../utils/render-tnode.js');
var utils_event = require('../utils/event.js');
var hooks_useRipple = require('../hooks/useRipple.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var menu_menuItemProps = require('./menu-item-props.js');
require('lodash/isEmpty');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isUndefined');
require('lodash/isNull');
require('lodash/isArray');
require('lodash/isNumber');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 _MenuItem = vue.defineComponent({
  name: "TMenuItem",
  props: _objectSpread({}, menu_menuItemProps["default"]),
  emits: ["click"],
  setup: function setup(props2, ctx) {
    var _toRefs = vue.toRefs(props2),
      href = _toRefs.href,
      _toRefs$target = _toRefs.target,
      target = _toRefs$target === void 0 ? "_self" : _toRefs$target;
    var classPrefix = hooks_useConfig.usePrefixClass();
    var menu = vue.inject("TdMenu");
    var itemRef = vue.ref();
    hooks_useRipple["default"](itemRef);
    var submenu = vue.inject("TdSubmenu", null);
    var active = vue.computed(function () {
      return menu.activeValue.value === props2.value;
    });
    var classes = vue.computed(function () {
      var _ref;
      return ["".concat(classPrefix.value, "-menu__item"), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-active"), active.value), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-disabled"), props2.disabled), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-menu__item--plain"), !ctx.slots.icon && !props2.icon), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-submenu__item"), !!submenu && !menu.isHead), _ref)];
    });
    vue.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"]
      });
    });
    return {
      classPrefix: classPrefix,
      menu: menu,
      active: active,
      classes: classes,
      itemRef: itemRef,
      href: href,
      target: target
    };
  },
  methods: {
    handleClick: function handleClick(e) {
      e.stopPropagation();
      if (this.disabled) return;
      this.menu.select(this.value);
      utils_event.emitEvent(this, "click");
      if (this.to) {
        var router = this.router || this.$router;
        var methods = this.replace ? "replace" : "push";
        router[methods](this.to)["catch"](function (err) {
          if (err.name !== "NavigationDuplicated" && !err.message.includes("Avoided redundant navigation to current location")) throw err;
        });
      }
    }
  },
  render: function render() {
    return vue.createVNode("li", {
      "ref": "itemRef",
      "class": this.classes,
      "onClick": this.handleClick
    }, [utils_renderTnode.renderTNodeJSX(this, "icon"), this.href ? vue.createVNode("a", {
      "href": this.href,
      "target": this.target,
      "class": "".concat(this.classPrefix, "-menu__item-link")
    }, [vue.createVNode("span", {
      "class": "".concat(this.classPrefix, "-menu__content")
    }, [utils_renderTnode.renderContent(this, "default", "content")])]) : vue.createVNode("span", {
      "class": ["".concat(this.classPrefix, "-menu__content")]
    }, [utils_renderTnode.renderContent(this, "default", "content")])]);
  }
});

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