function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { uniqueId } from 'lodash';
import cx from 'classnames';
import Icon from '../Icon';
import MarkdownLabel from './MarkdownLabel';

class TextArea extends PureComponent {
  constructor(props) {
    super(props);
    this.id = uniqueId('label');
  }

  render() {
    const {
      meta: {
        active,
        error,
        invalid,
        touched
      },
      label,
      placeholder,
      fieldLabel,
      className,
      type,
      autoFocus,
      hidden,
      input
    } = this.props;
    const seamlessClasses = cx(className, 'form-field-text', {
      'form-field-text--has-focus': active,
      'form-field-text--has-error': invalid && touched && error
    });
    return /*#__PURE__*/React.createElement("label", {
      htmlFor: this.id,
      className: "form-field-container",
      hidden: hidden,
      name: input.name
    }, fieldLabel || label ? /*#__PURE__*/React.createElement(MarkdownLabel, {
      label: fieldLabel || label
    }) : '', /*#__PURE__*/React.createElement("div", {
      className: seamlessClasses
    }, /*#__PURE__*/React.createElement("textarea", _extends({
      id: this.id,
      className: "form-field form-field-text form-field-text--area form-field-text__input",
      placeholder: placeholder,
      autoFocus: autoFocus // eslint-disable-line
      ,
      type: type // eslint-disable-next-line react/jsx-props-no-spreading

    }, input)), invalid && touched && /*#__PURE__*/React.createElement("div", {
      className: "form-field-text__error"
    }, /*#__PURE__*/React.createElement(Icon, {
      name: "warning"
    }), error)));
  }

}

TextArea.propTypes = {
  input: PropTypes.object,
  meta: PropTypes.object,
  type: PropTypes.string,
  label: PropTypes.string,
  autoFocus: PropTypes.bool,
  fieldLabel: PropTypes.string,
  className: PropTypes.string,
  placeholder: PropTypes.string,
  hidden: PropTypes.bool
};
TextArea.defaultProps = {
  input: {},
  meta: {},
  type: 'text',
  autoFocus: false,
  label: null,
  fieldLabel: null,
  placeholder: '',
  className: '',
  hidden: false
};
export default TextArea;