"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// Style

/* istanbul ignore next */
if (typeof window !== 'undefined') {}

var TextArea = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(TextArea, _React$Component);

  var _super = _createSuper(TextArea);

  function TextArea(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, TextArea);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (event) {
      _this.setState({
        value: event.target.value
      });
      /* istanbul ignore else */


      if (typeof _this.props.onChange === 'function') _this.props.onChange(event);
    });
    _this.state = {
      value: props.value
    };
    return _this;
  }

  (0, _createClass2["default"])(TextArea, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate(_ref) {
      var stateVal = _ref.value;
      var value = this.props.value;
      if (stateVal !== value) this.setState({
        value: value
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          resize = _this$props.resize,
          onChange = _this$props.onChange,
          size = _this$props.size,
          value = _this$props.value,
          attributes = (0, _objectWithoutProperties2["default"])(_this$props, ["className", "resize", "onChange", "size", "value"]);
      var TextAreaClasses = ['TextArea', "TextArea_".concat(size), "TextArea_".concat(resize), className].filter(function (e) {
        return e;
      }).join(' ');
      return /*#__PURE__*/_react["default"].createElement("textarea", (0, _extends2["default"])({}, attributes, {
        className: TextAreaClasses,
        onChange: this.onChange,
        value: this.state.value
      }));
    }
  }]);
  return TextArea;
}(_react["default"].Component);

exports["default"] = TextArea;
(0, _defineProperty2["default"])(TextArea, "propTypes", {
  onChange: _propTypes["default"].func,
  resize: _propTypes["default"].oneOf(['both', 'horizontal', 'none', 'vertical']),
  size: _propTypes["default"].oneOf(['lg', 'md', 'sm']),
  value: _propTypes["default"].string
});
(0, _defineProperty2["default"])(TextArea, "defaultProps", {
  resize: 'vertical',
  size: 'md'
});