'use strict';

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

type TextAreaProps = FormGroupProps & Partial<TextAreaDefaultProps> & React.HTMLProps<TextArea>;

type TextAreaDefaultProps = {
    testAutomationId: string;
};

export class TextArea extends FormGroup<TextAreaProps> {
    static propTypes: any = {
        ...FormGroup.propTypes
    };

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

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