import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _jsxFileName = 'src/menu/MenuItemGroup.jsx';
import React, { Component, Children, isValidElement, cloneElement, Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import MenuTitle from './MenuTitle';

/**
 * MenuItemGroup
 */

var MenuItemGroup = function (_Component) {
    _inherits(MenuItemGroup, _Component);

    function MenuItemGroup() {
        _classCallCheck(this, MenuItemGroup);

        return _possibleConstructorReturn(this, (MenuItemGroup.__proto__ || Object.getPrototypeOf(MenuItemGroup)).apply(this, arguments));
    }

    _createClass(MenuItemGroup, [{
        key: 'getMenuItems',
        value: function getMenuItems(children) {
            var items = [];
            Children.forEach(children, function (item) {
                if (isValidElement(item)) {
                    items.push(item);
                }
            });
            return items;
        }
    }, {
        key: 'render',
        value: function render() {
            var _props = this.props,
                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 = this.getMenuItems(children).map(function (item, key) {
                return cloneElement(item, {
                    level: compact ? level : level + 1,
                    key: item.props.value || 'menu-group-' + key,
                    compact: compact,
                    close: close
                });
            });
            var classes = classNames(prefixCls, {}, className);
            var titleClasses = classNames(prefixCls + '-title');
            return React.createElement(
                'li',
                { className: classes, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 69
                    },
                    __self: this
                },
                React.createElement(
                    Fragment,
                    {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 70
                        },
                        __self: this
                    },
                    React.createElement(
                        MenuTitle,
                        { prefix: prefix, compact: compact, level: level, className: titleClasses, __source: {
                                fileName: _jsxFileName,
                                lineNumber: 71
                            },
                            __self: this
                        },
                        title
                    ),
                    React.createElement(
                        'ul',
                        Object.assign({}, other, { className: prefixCls + '-list', __source: {
                                fileName: _jsxFileName,
                                lineNumber: 74
                            },
                            __self: this
                        }),
                        menu
                    )
                )
            );
        }
    }]);

    return MenuItemGroup;
}(Component);

MenuItemGroup.propTypes = {
    prefixCls: PropTypes.string,
    className: 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
};
MenuItemGroup.displayName = 'NeatUI.MenuItemGroup';
export default MenuItemGroup;