import React from 'react';
import { Form } from 'react-bootstrap';
import { ValidatorComponent } from 'react-form-validator-core';
import translateLabel from "../../translation"

class TextArea extends ValidatorComponent {
  // constructor(props) {
  //   super(props);
  // }

  render() {

    const { id, name, label, value, rows, type, asterisk, readonly, placeholder, onChange } = this.props;
    return (
      <div>
        <Form.Group>
          <Form.Label>{label}{asterisk ? <span className='asterisk'>*</span> : ""}</Form.Label>
          <Form.Control className="textareabox"
            id={id}
            name={name}
            value={value !== null ? value : ""}
            as={type}
            rows={rows}
            placeholder={placeholder}
            readOnly={readonly === "true" ? true : false}
            onChange={onChange}
            ref={(r) => { this.input = r; }}
          />
          {this.errorText()}
        </Form.Group>
      </div>);
  }

  errorText() {
    const { isValid } = this.state;
    if (isValid) {
      return null;
    }
    return (
      <div className="errorStr">
        {translateLabel(this.getErrorMessage())}
      </div>
    );
  }
}

export default TextArea;