'use strict';

import React from 'react';
import {FormGroup, FormGroupDefaultProps, FormGroupProps} from './FormGroup';
import {SelectControl} from './SelectControl';
import {FormControl as ReactBootstrapFormControl} from 'react-bootstrap';

type SelectProps = ReactBootstrapFormControl.FormControlProps &
    FormGroupProps &
    Partial<SelectDefaultProps> &
    React.HTMLProps<Select>;

type SelectDefaultProps = {
    testAutomationId: string;
} & FormGroupDefaultProps;

export class Select extends FormGroup<SelectProps> {
    static propTypes: any = {
        ...FormGroup.propTypes
    };

    static defaultProps = {
        ...FormGroup.defaultProps,
        testAutomationId: 'select'
    };

    renderInput(hasError) {
        let {children, readOnly, ...props} = this.props;
        let readOnlyProp = readOnly === undefined ? {} : {readOnly};
        let ariaDescProps = this.getAriaDescProps(hasError);
        return (
            <SelectControl
                {...this.getSafeProps(props)}
                ref="control"
                {...ariaDescProps}
                hasFormGroupContainer
                {...readOnlyProp}>
                {children}
            </SelectControl>
        );
    }
}
