import _pick from "ramda/src/pick";
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); }
import React from 'react';
import styled, { css } from 'styled-components';
import { FormField, Typography } from '../../..';
import { placeholderNormalization } from '../Text/Text';
import NormalizedElements from '../../../common/NormalizedElements';
var hasError = function hasError(error) {
  return error && error !== '';
};
var background = css(["background-color:", ";"], function (p) {
  return p.disabled ? p.theme.color.disabledBackground : p.theme.color.inputBackground;
});
var hoverBorderStyles = css(["", ""], function (p) {
  return p.disabled ? '' : "\n      &:hover {\n        border-color: ".concat(p.theme.color.inputBorderHover, ";\n      }\n");
});
var focusBorderStyles = css(["&:focus{border-color:", ";}"], function (p) {
  return p.theme.color.borderActive;
});
var borderStyles = 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 = styled(NormalizedElements.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, placeholderNormalization);
var components = {
  StyledTextarea: StyledTextarea
};
export var 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.createElement(FormField, _extends({}, _pick(['error', 'extraInfo', 'hideLabel', 'label', 'labelTooltip', 'labelTooltipPosition', 'labelTooltipInModal', 'width'], props), {
    required: visuallyEmphasiseRequired
  }), React.createElement(Typography, {
    type: "secondary",
    color: function color(t) {
      return t.color.text;
    }
  }, React.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;