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

import Vue from 'vue';
import _DropdownItem from './dropdown-item.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import { pxCompat } from '../../utils/helper.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import '@babel/runtime/helpers/defineProperty';
import '@ldesign/icons-vue';
import '../divider/index.js';
import '../divider/divider.js';
import '../divider/props.js';
import '@babel/runtime/helpers/typeof';
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 '../../utils/with-install.js';
import '../../config.js';
import '../divider/style/css.js';
import '../divider/type.js';
import './props.js';
import '../../utils/event.js';
import '../../utils/ripple.js';
import '../../chunks/set-style.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';

var classPrefixMixins = getClassPrefixMixins("dropdown");
var _DropdownMenu = mixins(Vue, classPrefixMixins).extend({
  name: "LDropdownMenu",
  inject: {
    dropdown: {
      "default": void 0
    }
  },
  components: {
    LDropdownItem: _DropdownItem
  },
  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(this.componentName, "__menu-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: pxCompat(maxColumnWidth),
          minWidth: pxCompat(minColumnWidth)
        }
      }, [children.map(function (item, idx) {
        return h("l-dropdown-item", {
          "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": "".concat(this.componentName, "__menu")
      }, [h("div", {
        "class": ["".concat(this.componentName, "__menu-column"), "narrow-scrollbar"],
        "style": {
          maxHeight: "".concat(this.dropdown.maxHeight, "px"),
          maxWidth: "".concat(this.dropdown.maxColumnWidth, "px"),
          minWidth: "".concat(this.dropdown.minColumnWidth, "px")
        }
      }, [renderLNodeJSX(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": "".concat(this.componentName, "__menu")
    }, [columns]);
  }
});

export { _DropdownMenu as default };
//# sourceMappingURL=dropdown-menu.js.map
