"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

var React = _interopRequireWildcard(require("react"));

var _classnames2 = _interopRequireDefault(require("classnames"));

var _Text = _interopRequireDefault(require("../text/Text"));

var _Flex = _interopRequireDefault(require("../flex/Flex"));

var _excluded = ["valid", "invalid", "size", "color", "fullWidth", "simple", "noPadding", "autoHeight", "value", "className", "textareaRef", "errorMessage", "as"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var SIZE = {
  SHORT: 'short',
  NORMAL: 'normal',
  TALL: 'tall',
  XTALL: 'xtall'
};
exports.SIZE = SIZE;
var TEXTAREA_COLOR = {
  DEFAULT: 'default',
  WHITE: 'white'
};
exports.TEXTAREA_COLOR = TEXTAREA_COLOR;

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 = (0, _classnames2.default)('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 = (0, _classnames2.default)('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.default, {
    marginTop: "xxs",
    marginLeft: "s",
    marginRight: "s"
  }, /*#__PURE__*/React.createElement(_Text.default, {
    size: "xsmall",
    color: "text-red-60"
  }, errorMessage)));
};

var _default = Textarea;
exports.default = _default;