'use strict';

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

var _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key];
                }
            }
        }
        return target;
    };

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {'default': obj};
}

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _utilsCreateChainedFunction = require('./utils/createChainedFunction');

var _utilsCreateChainedFunction2 = _interopRequireDefault(_utilsCreateChainedFunction);

var _utilsValidComponentChildren = require('./utils/ValidComponentChildren');

var _utilsValidComponentChildren2 = _interopRequireDefault(_utilsValidComponentChildren);

var DropdownMenu = _react2['default'].createClass({
    displayName: 'DropdownMenu',

    propTypes: {
        pullRight: _react2['default'].PropTypes.bool,
        onSelect: _react2['default'].PropTypes.func
    },

    render: function render() {
        var classes = {
            'dropdown-menu': true,
            'dropdown-menu-right': this.props.pullRight
        };

        return _react2['default'].createElement(
            'ul',
            _extends({}, this.props, {
                className: (0, _classnames2['default'])(this.props.className, classes),
                role: 'menu'
            }),
            _utilsValidComponentChildren2['default'].map(this.props.children, this.renderMenuItem)
        );
    },

    renderMenuItem: function renderMenuItem(child, index) {
        return (0, _react.cloneElement)(child, {
            // Capture onSelect events
            onSelect: (0, _utilsCreateChainedFunction2['default'])(child.props.onSelect, this.props.onSelect),

            // Force special props to be transferred
            key: child.key ? child.key : index
        });
    }
});

exports['default'] = DropdownMenu;
module.exports = exports['default'];