/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { defineComponent, h } from '@vue/composition-api';
import { ChevronRightIcon, ChevronLeftIcon } from '@ldesign/icons-vue';
import isFunction from 'lodash/isFunction';
import { Divider } from '../divider/index.js';
import { usePrefixClass } from '../../hooks/use-config.js';
import { useGlobalIcon } from '../../hooks/use-global-icon.js';
import _DropdownItem from './dropdown-item.js';
import { DropdownProps } from './props.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../divider/divider.js';
import '../../utils/render-node.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';
import '../../utils/mixins.js';
import '../divider/props.js';
import '../config-provider/useConfig.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/render-lnode.js';
import '../../utils/helper.js';
import '../../utils/ripple.js';
import '../../_chunks/dep-cf772670.js';

var _DropdownMenu = defineComponent({
  name: "LDropdownMenu",
  props: {
    ...DropdownProps
  },
  setup(props, _ref) {
    let {
      emit
    } = _ref;
    const dropdownClass = usePrefixClass("dropdown");
    const dropdownMenuClass = usePrefixClass("dropdown__menu");
    const handleItemClick = (optionItem, options) => {
      var _data$onClick, _props$onClick;
      if (optionItem.disabled || optionItem.children) return;
      const {
        data,
        context
      } = options;
      data === null || data === void 0 ? void 0 : (_data$onClick = data.onClick) === null || _data$onClick === void 0 ? void 0 : _data$onClick.call(data, data, context);
      (_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props, data, context);
      emit("click", data, context);
    };
    return {
      dropdownClass,
      dropdownMenuClass,
      handleItemClick
    };
  },
  methods: {
    renderOptionContent(content) {
      if (isFunction(content)) return content(h);
      return content;
    },
    renderOptions(data) {
      var _data$forEach;
      const h = this.$createElement;
      const {
        ChevronRightIcon: ChevronRightIcon$1,
        ChevronLeftIcon: ChevronLeftIcon$1
      } = useGlobalIcon({
        ChevronRightIcon: ChevronRightIcon,
        ChevronLeftIcon: ChevronLeftIcon
      });
      const arr = [];
      let renderContent;
      (_data$forEach = data.forEach) === null || _data$forEach === void 0 ? void 0 : _data$forEach.call(data, (menu, idx) => {
        const optionItem = {
          ...menu
        };
        if (optionItem.children) {
          optionItem.children = this.renderOptions(optionItem.children);
          renderContent = h("div", {
            "key": idx
          }, [h(_DropdownItem, {
            "class": [`${this.dropdownClass}__item`, `${this.dropdownClass}__item--suffix`, optionItem.class],
            "props": {
              ...{
                value: optionItem.value,
                theme: optionItem.theme,
                active: optionItem.active,
                prefixIcon: optionItem.prefixIcon,
                disabled: optionItem.disabled,
                minColumnWidth: this.minColumnWidth,
                maxColumnWidth: this.maxColumnWidth,
                isSubmenu: true
              }
            }
          }, [this.direction === "right" ? h("div", {
            "class": `${this.dropdownClass}__item-content`
          }, [h("span", {
            "class": `${this.dropdownClass}__item-text`
          }, [this.renderOptionContent(optionItem.content)]), h(ChevronRightIcon$1, {
            "class": `${this.dropdownClass}__item-direction`,
            "attrs": {
              "size": "16"
            }
          })]) : h("div", {
            "class": `${this.dropdownClass}__item-content`
          }, [h(ChevronLeftIcon$1, {
            "class": `${this.dropdownClass}__item-direction`,
            "attrs": {
              "size": "16"
            }
          }), h("span", {
            "class": `${this.dropdownClass}__item-text`
          }, [this.renderOptionContent(optionItem.content)])]), h("div", {
            "class": [`${this.dropdownClass}__submenu`, {
              [`${this.dropdownClass}__submenu--disabled`]: optionItem.disabled,
              [`${this.dropdownClass}__submenu--${this.direction}`]: this.direction
            }],
            "style": {
              top: `${idx * 30}px`
            }
          }, [h("ul", [optionItem.children])])]), optionItem.divider ? h(Divider) : null]);
        } else {
          renderContent = h("div", {
            "key": idx
          }, [h(_DropdownItem, {
            "class": [`${this.dropdownClass}__item`, optionItem.class],
            "props": {
              ...{
                value: optionItem.value,
                theme: optionItem.theme,
                active: optionItem.active,
                prefixIcon: optionItem.prefixIcon,
                disabled: optionItem.disabled,
                minColumnWidth: this.minColumnWidth,
                maxColumnWidth: this.maxColumnWidth,
                onClick: (value, context) => this.handleItemClick({
                  disabled: optionItem.disabled,
                  children: optionItem.children
                }, {
                  data: optionItem,
                  context
                })
              }
            }
          }, [h("span", {
            "class": `${this.dropdownClass}__item-text`
          }, [this.renderOptionContent(optionItem.content)])]), optionItem.divider ? h(Divider) : null]);
        }
        arr.push(renderContent);
      });
      return arr;
    }
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "class": [this.dropdownMenuClass, `${this.dropdownMenuClass}--${this.direction}`],
      "style": {
        maxHeight: `${this.maxHeight}px`
      }
    }, [this.renderOptions(this.options)]);
  }
});

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