'use strict';

import React from 'react';
import PropTypes from 'prop-types';
import {FormGroup} from './FormGroup';
import {RadioControl} from './RadioControl';

export class Radio extends FormGroup {
    static propTypes = {
        ...FormGroup.propTypes,
        hiddenLabel: PropTypes.bool,
        removeName: PropTypes.bool
    };

    static defaultProps = {
        ...FormGroup.defaultProps,
        testAutomationId: 'radio',
        hiddenLabel: false,
        removeName: false
    };

    controlLabelFallback() {
        return false;
    }

    renderInput(hasError) {
        let {label, children, hiddenLabel, removeName, ...props} = this.props;
        let ariaDescProps = this.getAriaDescProps(hasError);
        return (
            <RadioControl
                {...this.getSafeProps(props)}
                ref="control"
                hiddenLabel={hiddenLabel}
                removeName={removeName}
                {...ariaDescProps}
                hasFormGroupContainer>
                {children || label}
            </RadioControl>
        );
    }
}
