"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Textarea = void 0;
var _pick2 = _interopRequireDefault(require("ramda/src/pick"));
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _ = require("../../..");
var _Text = require("../Text/Text");
var _NormalizedElements = _interopRequireDefault(require("../../../common/NormalizedElements"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
var hasError = function hasError(error) {
  return error && error !== '';
};
var background = (0, _styledComponents.css)(["background-color:", ";"], function (p) {
  return p.disabled ? p.theme.color.disabledBackground : p.theme.color.inputBackground;
});
var hoverBorderStyles = (0, _styledComponents.css)(["", ""], function (p) {
  return p.disabled ? '' : "\n      &:hover {\n        border-color: ".concat(p.theme.color.inputBorderHover, ";\n      }\n");
});
var focusBorderStyles = (0, _styledComponents.css)(["&:focus{border-color:", ";}"], function (p) {
  return p.theme.color.borderActive;
});
var borderStyles = (0, _styledComponents.css)(["border:1px solid ", ";position:relative;", " ", ""], function (p) {
  if (hasError(p.error)) return p.theme.color.inputBorderError;
  if (p.success) return p.theme.color.inputBorderSuccess;
  return p.theme.color.inputBorder;
}, hoverBorderStyles, focusBorderStyles);
var StyledTextarea = (0, _styledComponents.default)(_NormalizedElements.default.Textarea).withConfig({
  displayName: "Textarea__StyledTextarea",
  componentId: "sc-74ur6l-0"
})(["border:0;width:100%;padding:", "px;margin:0;vertical-align:top;box-sizing:border-box;resize:", ";color:", ";border-radius:", ";", " ", " ", ""], function (p) {
  return p.theme.spacing.unit(2);
}, function (p) {
  return p.noResize && 'none';
}, function (p) {
  return p.theme.color.text;
}, function (p) {
  return p.theme.borderRadius4;
}, borderStyles, background, _Text.placeholderNormalization);
var components = {
  StyledTextarea: StyledTextarea
};
var Textarea = exports.Textarea = function Textarea(props) {
  var autoFocus = props.autoFocus,
    defaultValue = props.defaultValue,
    disabled = props.disabled,
    error = props.error,
    maxLength = props.maxLength,
    name = props.name,
    noResize = props.noResize,
    onBlur = props.onBlur,
    onChange = props.onChange,
    onClick = props.onClick,
    onFocus = props.onFocus,
    onKeyDown = props.onKeyDown,
    onKeyPress = props.onKeyPress,
    onKeyUp = props.onKeyUp,
    placeholder = props.placeholder,
    required = props.required,
    _props$rows = props.rows,
    rows = _props$rows === void 0 ? 3 : _props$rows,
    success = props.success,
    value = props.value,
    visuallyEmphasiseRequired = props.visuallyEmphasiseRequired;
  return _react.default.createElement(_.FormField, _extends({}, (0, _pick2.default)(['error', 'extraInfo', 'hideLabel', 'label', 'labelTooltip', 'labelTooltipPosition', 'labelTooltipInModal', 'width'], props), {
    required: visuallyEmphasiseRequired
  }), _react.default.createElement(_.Typography, {
    type: "secondary",
    color: function color(t) {
      return t.color.text;
    }
  }, _react.default.createElement(StyledTextarea, _extends({
    autoFocus: autoFocus,
    defaultValue: defaultValue,
    disabled: disabled,
    error: error,
    maxLength: maxLength,
    name: name,
    onBlur: onBlur,
    onChange: onChange,
    onClick: onClick,
    onFocus: onFocus,
    onKeyDown: onKeyDown,
    onKeyPress: onKeyPress,
    onKeyUp: onKeyUp,
    placeholder: placeholder,
    required: required,
    rows: rows,
    success: success,
    value: value,
    noResize: noResize
  }, hasError(error) ? {
    'aria-invalid': true
  } : {}))));
};
Textarea.components = components;