/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

'use strict';

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

var get = require('lodash/get');
var VueCompositionAPI = require('@vue/composition-api');

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

var get__default = /*#__PURE__*/_interopDefaultLegacy(get);

const DropdownMenuName = "LDropdownMenu";
const DropdownItemName = "LDropdownItem";
const getOptionsFromChildren = menuGroup => {
  if (!menuGroup || menuGroup?.length === 0) return [];
  if (get__default["default"](menuGroup, "Ctor.extendOptions.name") === DropdownMenuName) {
    const groupChildren = menuGroup.children;
    if (Array.isArray(groupChildren)) return getOptionsFromChildren(groupChildren);
    return [];
  }
  if (Array.isArray(menuGroup)) {
    return menuGroup.map(item => {
      const groupChildren = item?.componentOptions?.children;
      if (!groupChildren) return {};
      const contentIdx = groupChildren.findIndex?.(v => typeof v.text === "string");
      const childrenContent = groupChildren.filter?.(v => typeof v.text !== "string" && [DropdownMenuName, DropdownItemName].includes(get__default["default"](v, "componentOptions.Ctor.extendOptions.name")));
      const commonProps = {
        ...item.componentOptions?.propsData,
        style: item?.data?.style,
        class: item?.data?.staticClass,
        onClick: item.componentOptions?.listeners?.click,
        content: groupChildren[contentIdx]?.text || groupChildren
      };
      if (childrenContent.length === 1) {
        return {
          ...commonProps,
          children: childrenContent.length > 0 ? getOptionsFromChildren(childrenContent[0].componentOptions) : null
        };
      }
      return {
        ...commonProps,
        children: childrenContent.length > 0 ? getOptionsFromChildren(childrenContent) : null
      };
    }).filter(v => !!v.content);
  }
  return [];
};
function useDropdownOptions(props, slots) {
  const menuSlot = slots?.default?.filter(v => get__default["default"](v, "componentOptions.Ctor.extendOptions.name") === DropdownMenuName)?.[0]?.componentOptions || slots?.dropdown?.[0]?.componentOptions;
  return VueCompositionAPI.computed(() => {
    if (props.options && props.options.length > 0) return props.options;
    return getOptionsFromChildren(menuSlot);
  });
}

exports["default"] = useDropdownOptions;
exports.getOptionsFromChildren = getOptionsFromChildren;
//# sourceMappingURL=useDropdownOptions.js.map
