'use strict';

import React from 'react';
import Static from 'react-bootstrap/lib/FormControlStatic';
import BSFormControl from 'react-bootstrap/lib/FormControl';
import {FormControl} from './FormControl';

export class TextAreaControl extends FormControl<any> {
    static propTypes: any = {
        ...FormControl.propTypes
    };

    static defaultProps = {
        ...FormControl.defaultProps,
        maxLength: 256
    };

    render() {
        let {maxLength, ...props} = this.getPropsFromContext();

        return props.readOnly ? (
            <Static ref="input" {...this.getSafeProps(props)} data-test-automation-id="input">
                {props.value}
            </Static>
        ) : (
            <BSFormControl
                {...this.getSafeProps(props)}
                data-test-automation-id="input"
                ref="input"
                componentClass="textarea"
                maxLength={maxLength}
            />
        );
    }
}
