import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { Children, isValidElement, cloneElement, Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import MenuTitle from './MenuTitle';

function getMenuItems(children) {
  var items = [];
  Children.forEach(children, function (item) {
    if (isValidElement(item)) {
      items.push(item);
    }
  });
  return items;
}
/**
 * MenuItemGroup
 */


export default function MenuItemGroup(props) {
  var children = props.children,
      prefixCls = props.prefixCls,
      className = props.className,
      title = props.title,
      prefix = props.prefix,
      disabled = props.disabled,
      mode = props.mode,
      close = props.close,
      onChange = props.onChange,
      defaultIsOpen = props.defaultIsOpen,
      level = props.level,
      compact = props.compact,
      other = _objectWithoutProperties(props, ["children", "prefixCls", "className", "title", "prefix", "disabled", "mode", "close", "onChange", "defaultIsOpen", "level", "compact"]);

  var menu = getMenuItems(children).map(function (item, key) {
    return cloneElement(item, {
      level: compact ? level : level + 1,
      key: item.props.value || "menu-group-".concat(key),
      compact: compact,
      close: close,
      disabled: disabled
    });
  });
  var classes = classNames(prefixCls, {}, className);
  var titleClasses = classNames("".concat(prefixCls, "-title"));
  return React.createElement("li", {
    className: classes
  }, React.createElement(Fragment, null, React.createElement(MenuTitle, {
    silent: true,
    prefix: prefix,
    compact: compact,
    level: level,
    disabled: disabled,
    className: titleClasses
  }, title), React.createElement("ul", _extends({}, other, {
    className: "".concat(prefixCls, "-list")
  }), menu)));
}
MenuItemGroup.displayName = 'NeatUI.MenuItemGroup';
MenuItemGroup.isMenuItemGroup = true;
MenuItemGroup.propTypes = {
  /**
   * 类前缀
   * */
  prefixCls: PropTypes.string,

  /** 子菜单标题 */
  title: PropTypes.node,

  /** 分组标题前缀 */
  prefix: PropTypes.node,

  /** 关闭父组件方法 */
  close: PropTypes.func,

  /** 组件所处层数（用于确定缩进） */
  level: PropTypes.number,

  /** 是否紧凑显示 */
  compact: PropTypes.bool
};
MenuItemGroup.defaultProps = {
  prefixCls: 'ne-menu-item-group',
  title: '',
  level: 1,
  compact: false
};