﻿import React from 'react';

const propTypes = {
    children: React.PropTypes.oneOfType([
        React.PropTypes.arrayOf(React.PropTypes.node),
        React.PropTypes.node
    ])
};

var inputNameId = 0;

export default class RadioExpand extends React.Component {

    constructor(props){
        super(props);
        this.inputName = `input-name-${inputNameId++}`;
    }

    renderList() {
        const children = this.props.children;
        return (
            <div className="radio-expand">
                <ul className="radio-expand__list">
                    {React.Children.map(children, this.renderItem.bind(this))}
                </ul>
            </div>
        );
    }

    renderItem(child){
        const additionalProps = {inputName: this.inputName};
        return React.cloneElement(child, additionalProps);
    }

    render() {
        return (
            this.renderList()
        );
    }
}

RadioExpand.propTypes = propTypes;