/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var menu_menuItemProps = require('./menu-item-props.js');
var utils_ripple = require('../utils/ripple.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var hooks_useConfig = require('../hooks/useConfig.js');
require('../_common/js/utils/set-style.js');
require('../config.js');
require('@babel/runtime/helpers/typeof');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../config-provider/useConfig.js');

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 keepAnimationMixins = configProvider_configReceiver.getKeepAnimationMixins();
var _MenuItem = VueCompositionAPI.defineComponent({
  name: "TMenuItem",
  mixins: [keepAnimationMixins],
  props: _objectSpread({}, menu_menuItemProps["default"]),
  directives: {
    ripple: utils_ripple["default"]
  },
  setup: function setup(props2, ctx) {
    var menu = VueCompositionAPI.inject("TdMenu");
    var submenu = VueCompositionAPI.inject("TdSubmenu", null);
    var active = VueCompositionAPI.computed(function () {
      return menu.activeValue.value === props2.value;
    });
    var classPrefix = hooks_useConfig.usePrefixClass();
    var classes = VueCompositionAPI.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)];
    });

    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;
          }
        });
      }
    };

    VueCompositionAPI.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
      }
    }, [utils_renderTnode.renderTNodeJSX(this, "icon"), h("span", {
      "class": ["".concat(this.classPrefix, "-menu__content")]
    }, [utils_renderTnode.renderContent(this, "default", "content")])]);
  }
});

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