'use strict';

import React from 'react';
import {TextInputControl} from './TextInputControl';
import {FormGroup, FormGroupProps} from './FormGroup';

export type TextInputProps = FormGroupProps &
    Partial<TextInputDefaultProps> &
    React.HTMLProps<TextInput>;

export type TextInputDefaultProps = {
    testAutomationId: string;
};

export class TextInput extends FormGroup<TextInputProps> {
    static propTypes: any = {
        ...FormGroup.propTypes
    };

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

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