import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import RadioButton from './index';
import Box from '../box';
import isComponentOfType from '../utils/is-component-of-type';
import omit from 'lodash.omit';

class RadioGroup extends PureComponent {
  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    disabled: PropTypes.bool,
    onChange: PropTypes.func,
    value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
  };

  static defaultProps = {
    className: '',
    disabled: false,
  };

  constructor() {
    super(...arguments);

    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(value, event) {
    if (this.props.onChange) {
      this.props.onChange(value, event);
    }
  }

  render() {
    const { children, className, disabled, value, ...others } = this.props;
    const rest = omit(others, ['onChange']);

    return (
      <Box data-teamleader-ui="radio-group" className={className} {...rest}>
        {React.Children.map(
          children,
          child =>
            !isComponentOfType(RadioButton, child)
              ? child
              : React.cloneElement(child, {
                  checked: child.props.value === value,
                  disabled: disabled || child.props.disabled,
                  onChange: event => this.handleChange(child.props.value, event),
                }),
        )}
      </Box>
    );
  }
}

export default RadioGroup;

@@ -277,300 +277,8 @@
 t %7B%0A
-  static propTypes = %7B%0A    children: PropTypes.node,%0A    className: PropTypes.string,%0A    disabled: PropTypes.bool,%0A    onChange: PropTypes.func,%0A    value: PropTypes.oneOfType(%5BPropTypes.string, PropTypes.bool%5D),%0A  %7D;%0A%0A  static defaultProps = %7B%0A    className: '',%0A    disabled: false,%0A  %7D;%0A%0A
   co
@@ -1158,16 +1158,294 @@
 %0A  %7D%0A%7D%0A%0A
+RadioGroup.propTypes = %7B%0A  children: PropTypes.node,%0A  className: PropTypes.string,%0A  disabled: PropTypes.bool,%0A  onChange: PropTypes.func,%0A  value: PropTypes.oneOfType(%5BPropTypes.string, PropTypes.bool%5D),%0A%7D;%0A%0ARadioGroup.defaultProps = %7B%0A  className: '',%0A  disabled: false,%0A%7D;%0A%0A
 export d

move static propTypes & defaultProps outside of the component class