import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["valid", "invalid", "size", "color", "fullWidth", "simple", "noPadding", "autoHeight", "value", "className", "textareaRef", "errorMessage", "as"];
import * as React from 'react';
import classnames from 'classnames';
import Text from '../text/Text';
import Flex from '../flex/Flex';
export var SIZE = {
  SHORT: 'short',
  NORMAL: 'normal',
  TALL: 'tall',
  XTALL: 'xtall'
};
export var TEXTAREA_COLOR = {
  DEFAULT: 'default',
  WHITE: 'white'
};

var Textarea = function Textarea(props) {
  var _classnames;

  var valid = props.valid,
      invalid = props.invalid,
      _props$size = props.size,
      size = _props$size === void 0 ? SIZE.NORMAL : _props$size,
      _props$color = props.color,
      color = _props$color === void 0 ? 'default' : _props$color,
      fullWidth = props.fullWidth,
      simple = props.simple,
      noPadding = props.noPadding,
      autoHeight = props.autoHeight,
      value = props.value,
      className = props.className,
      textareaRef = props.textareaRef,
      errorMessage = props.errorMessage,
      _props$as = props.as,
      Type = _props$as === void 0 ? 'textarea' : _props$as,
      additionalProps = _objectWithoutProperties(props, _excluded);

  if (valid === true && invalid === true) {
    throw {
      name: 'WrongValidation',
      message: 'Textarea can be either valid or invalid!'
    };
  }

  var textareaClass = classnames('sg-textarea', (_classnames = {}, _defineProperty(_classnames, "sg-textarea--".concat(String(size)), size !== SIZE.NORMAL), _defineProperty(_classnames, "sg-textarea--".concat(String(color)), color !== 'default'), _defineProperty(_classnames, 'sg-textarea--valid', valid), _defineProperty(_classnames, 'sg-textarea--invalid', invalid), _defineProperty(_classnames, 'sg-textarea--full-width', fullWidth), _defineProperty(_classnames, 'sg-textarea--simple', simple), _defineProperty(_classnames, 'sg-textarea--no-padding', noPadding), _defineProperty(_classnames, 'sg-textarea--auto-height', autoHeight), _classnames), className);
  var wrapperClass = classnames('sg-input__wrapper', {
    'sg-textarea__wrapper--full-width': fullWidth
  });
  var errorMessageDisplayed = invalid === true && errorMessage !== undefined && errorMessage !== '';
  return /*#__PURE__*/React.createElement("div", {
    className: wrapperClass
  }, /*#__PURE__*/React.createElement(Type, _extends({}, additionalProps, {
    className: textareaClass,
    ref: textareaRef,
    value: value
  })), errorMessageDisplayed && /*#__PURE__*/React.createElement(Flex, {
    marginTop: "xxs",
    marginLeft: "s",
    marginRight: "s"
  }, /*#__PURE__*/React.createElement(Text, {
    size: "xsmall",
    color: "text-red-60"
  }, errorMessage)));
};

export default Textarea;