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

'use strict';

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

var Vue = require('vue');
var dropdown_dropdownItem = require('./dropdown-item.js');
var config = require('../config.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var utils_helper = require('../utils/helper.js');
require('@babel/runtime/helpers/defineProperty');
require('tdesign-icons-vue');
require('../divider/index.js');
require('../divider/divider.js');
require('../divider/props.js');
require('@babel/runtime/helpers/typeof');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('./dropdown-item-props.js');
require('../utils/classnames.js');
require('../utils/event.js');
require('../utils/ripple.js');
require('../_common/js/utils/set-style.js');
require('../utils/mixins.js');
require('../config-provider/config-receiver.js');
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('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

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

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

var name = "".concat(config.prefix, "-dropdown__menu");
var _DropdownMenu = Vue__default["default"].extend({
  name: "TDropdownMenu",
  inject: {
    dropdown: {
      "default": void 0
    }
  },
  data: function data() {
    return {
      path: ""
    };
  },
  methods: {
    isActive: function isActive(item, pathPrefix) {
      var excludeSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
      var itemPath = "".concat(pathPrefix, "/").concat(item.value);

      if (excludeSelf && this.path === itemPath) {
        return false;
      }

      return this.path.indexOf(itemPath) === 0;
    },
    handleHoverItem: function handleHoverItem(path) {
      this.path = path;
    },
    handleItemClick: function handleItemClick(data, context, idx) {
      var _this$dropdown$option, _this$dropdown$option2;

      (_this$dropdown$option = (_this$dropdown$option2 = this.dropdown.options[idx]).onClick) === null || _this$dropdown$option === void 0 ? void 0 : _this$dropdown$option.call(_this$dropdown$option2, data, context);
    },
    renderMenuColumn: function renderMenuColumn(children, showSubmenu, pathPrefix) {
      var _this = this;

      var h = this.$createElement;
      var menuClass = ["".concat(name, "-column"), "narrow-scrollbar", {
        submenu__visible: showSubmenu
      }];
      var _this$dropdown = this.dropdown,
          maxHeight = _this$dropdown.maxHeight,
          maxColumnWidth = _this$dropdown.maxColumnWidth,
          minColumnWidth = _this$dropdown.minColumnWidth;
      return h("div", {
        "class": menuClass,
        "style": {
          maxHeight: "".concat(maxHeight, "px"),
          maxWidth: utils_helper.pxCompat(maxColumnWidth),
          minWidth: utils_helper.pxCompat(minColumnWidth)
        }
      }, [children.map(function (item, idx) {
        return h(dropdown_dropdownItem["default"], {
          "key": idx,
          "attrs": {
            "disabled": item.disabled,
            "active": _this.isActive(item, pathPrefix) || item.active,
            "value": item.value,
            "content": item.content,
            "divider": item.divider,
            "hasChildren": item.children && item.children.length > 0,
            "path": "".concat(pathPrefix, "/").concat(item.value)
          },
          "on": {
            "click": function click(data, context) {
              return _this.handleItemClick(data, context, idx);
            },
            "hover": _this.handleHoverItem
          }
        });
      })]);
    }
  },
  render: function render() {
    var _this2 = this;

    var h = arguments[0];
    var columns = [];
    var menuItems = this.dropdown.options;
    var pathPrefix = "";

    if (this.$scopedSlots["default"]) {
      return h("div", {
        "class": name
      }, [h("div", {
        "class": ["".concat(name, "-column"), "narrow-scrollbar"],
        "style": {
          maxHeight: "".concat(this.dropdown.maxHeight, "px"),
          maxWidth: "".concat(this.dropdown.maxColumnWidth, "px"),
          minWidth: "".concat(this.dropdown.minColumnWidth, "px")
        }
      }, [utils_renderTnode.renderTNodeJSX(this, "default")])]);
    }

    while (menuItems && menuItems.length) {
      var activeItem = menuItems.find(function (item) {
        return _this2.isActive(item, pathPrefix, false);
      });
      columns.push(this.renderMenuColumn(menuItems, !!activeItem, pathPrefix));

      if (activeItem) {
        pathPrefix = "".concat(pathPrefix, "/").concat(activeItem.value);
        menuItems = activeItem.children || [];
      } else {
        menuItems = [];
      }
    }

    return h("div", {
      "class": name
    }, [columns]);
  }
});

exports["default"] = _DropdownMenu;
//# sourceMappingURL=dropdown-menu.js.map
