/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../../_chunks/dep-2db7b3ec.mjs';
import { getCurrentInstance, computed } from 'vue';
import { i as isString_1 } from '../../_chunks/dep-876fb3ec.mjs';
import { i as isArray_1 } from '../../_chunks/dep-b57180d0.mjs';
import { useChildComponentSlots } from '../../hooks/slot.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-3da99438.mjs';

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(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 getOptionsFromChildren = function getOptionsFromChildren(menuGroup) {
  var _menuGroup$, _menuGroup$$type, _menuGroup$3, _menuGroup$4;
  if (!menuGroup) return [];
  if (((_menuGroup$ = menuGroup[0]) === null || _menuGroup$ === void 0 ? void 0 : (_menuGroup$$type = _menuGroup$.type) === null || _menuGroup$$type === void 0 ? void 0 : _menuGroup$$type.name) === "TDropdownMenu") {
    var _menuGroup$2, _menuGroup$2$children, _menuGroup$2$children2;
    var groupChildren = (_menuGroup$2 = menuGroup[0]) === null || _menuGroup$2 === void 0 ? void 0 : (_menuGroup$2$children = _menuGroup$2.children) === null || _menuGroup$2$children === void 0 ? void 0 : (_menuGroup$2$children2 = _menuGroup$2$children["default"]) === null || _menuGroup$2$children2 === void 0 ? void 0 : _menuGroup$2$children2.call(_menuGroup$2$children);
    if (isArray_1(groupChildren)) return getOptionsFromChildren(groupChildren);
  }
  if (isArray_1((_menuGroup$3 = menuGroup[0]) === null || _menuGroup$3 === void 0 ? void 0 : _menuGroup$3.children)) return getOptionsFromChildren((_menuGroup$4 = menuGroup[0]) === null || _menuGroup$4 === void 0 ? void 0 : _menuGroup$4.children);
  if (isArray_1(menuGroup)) {
    return menuGroup.map(function (item) {
      var _item$children, _item$children$defaul, _groupChildren$filter, _groupChildren$filter2;
      var groupChildren = (_item$children = item.children) === null || _item$children === void 0 ? void 0 : (_item$children$defaul = _item$children["default"]) === null || _item$children$defaul === void 0 ? void 0 : _item$children$defaul.call(_item$children);
      var contentCtx = groupChildren === null || groupChildren === void 0 ? void 0 : (_groupChildren$filter = groupChildren.filter) === null || _groupChildren$filter === void 0 ? void 0 : _groupChildren$filter.call(groupChildren, function (v) {
        var _v$type;
        return !["TDropdownMenu", "TDropdownItem"].includes((_v$type = v.type) === null || _v$type === void 0 ? void 0 : _v$type.name);
      });
      var childrenCtx = groupChildren === null || groupChildren === void 0 ? void 0 : (_groupChildren$filter2 = groupChildren.filter) === null || _groupChildren$filter2 === void 0 ? void 0 : _groupChildren$filter2.call(groupChildren, function (v) {
        var _v$type2;
        return !isString_1(v.children) && ["TDropdownMenu", "TDropdownItem"].includes((_v$type2 = v.type) === null || _v$type2 === void 0 ? void 0 : _v$type2.name);
      });
      return _objectSpread(_objectSpread({
        content: contentCtx || groupChildren
      }, item.props), {}, {
        children: (childrenCtx === null || childrenCtx === void 0 ? void 0 : childrenCtx.length) > 0 ? getOptionsFromChildren(childrenCtx) : null
      });
    }).filter(function (v) {
      return !!v.content;
    });
  }
  return [];
};
function useDropdownOptions(props) {
  var _getChildComponentSlo, _getChildComponentSlo2, _getChildComponentSlo3, _getChildComponentSlo4, _instance$slots, _instance$slots$dropd;
  var getChildComponentSlots = useChildComponentSlots();
  var instance = getCurrentInstance();
  var menuSlot = ((_getChildComponentSlo = getChildComponentSlots("DropdownMenu")) === null || _getChildComponentSlo === void 0 ? void 0 : (_getChildComponentSlo2 = _getChildComponentSlo[0]) === null || _getChildComponentSlo2 === void 0 ? void 0 : (_getChildComponentSlo3 = _getChildComponentSlo2.children) === null || _getChildComponentSlo3 === void 0 ? void 0 : (_getChildComponentSlo4 = _getChildComponentSlo3["default"]) === null || _getChildComponentSlo4 === void 0 ? void 0 : _getChildComponentSlo4.call(_getChildComponentSlo3)) || ((_instance$slots = instance.slots) === null || _instance$slots === void 0 ? void 0 : (_instance$slots$dropd = _instance$slots.dropdown) === null || _instance$slots$dropd === void 0 ? void 0 : _instance$slots$dropd.call(_instance$slots));
  var dropdownOptions = computed(function () {
    if (props.options && props.options.length > 0) return props.options;
    return getOptionsFromChildren(menuSlot);
  });
  return dropdownOptions;
}

export { useDropdownOptions as default, getOptionsFromChildren };
//# sourceMappingURL=useDropdownOptions.mjs.map
