'use strict';

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

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

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

    controlLabelFallback() {
        return false;
    }

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