"use strict";

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

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

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

var _styles = require("@vincent_za/styles");

var _constants = require("../constants");

var _component = _interopRequireWildcard(require("../Placeholder/component"));

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

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _templateObject4() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  border: 0;\n  padding: 0 0 0 1px;\n  flex-grow: 1;\n  width: 100%;\n  height: 4rem;\n  background-color: transparent;\n  box-shadow: inset -1px -1px 0 ", ";\n  color: ", ";\n  outline: none;\n\n  &:focus {\n    box-shadow: 0 1px 0 ", ";\n    ", ";\n  };\n\n  ", ";\n  ", ";\n\n  ", ";\n\n  &:focus + ", " {\n    ", ";\n  };\n  ", ";\n"]);

  _templateObject4 = function _templateObject4() {
    return data;
  };

  return data;
}

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  top: 2rem;\n  ", ";\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  position: absolute;\n  top: 100%;\n  right: 0;\n  margin-top: ", ";\n  font-size: ", ";\n  color: ", ";\n"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  position: relative;\n  align-items: center;\n  width: 100%;\n\n  &::after {\n    content: '';\n    position: absolute;\n    right: 0;\n    bottom: 0;\n    width: 0;\n    height: 0;\n    border-style: solid;\n    border-width: 0 0 1rem 1rem;\n    border-color: transparent transparent ", " transparent;\n    pointer-events: none;\n  };\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var Wrap = _styledComponents.default.div(_templateObject(), _styles.COLOR_FORM_FIELD_BORDER_OPAQUE);

var Error = _styledComponents.default.div(_templateObject2(), _styles.REM_UNIT_XSM, _styles.REM_FONT_SIZE___SM, _styles.RED_ORANGE);

var errorStyles = "\n  color: ".concat(_styles.RED_ORANGE, " !important;\n  box-shadow: 0 1px 0 ").concat(_styles.RED_ORANGE, " !important;\n\n  &:focus {\n    box-shadow: 0 1px 0 ").concat(_styles.RED_ORANGE, " !important;\n  }\n");
var activeStylesTextArea = "\n  padding: ".concat(_styles.REM_UNIT_MD, " 0 ").concat(_styles.REM_UNIT_XSM, " 1px;\n");
var PlaceholderStyled = (0, _styledComponents.default)(_component.default)(_templateObject3(), function (props) {
  return props.hasValue && _component.STYLES_PLACEHOLDER_ACTIVE;
});

var TextAreaInput = _styledComponents.default.textarea(_templateObject4(), _styles.COLOR_FORM_FIELD_BORDER, _styles.GRAY_X11, _styles.ISABELLINE, activeStylesTextArea, function (props) {
  return props.touched && props.error && errorStyles;
}, function (props) {
  return props.hasValue && activeStylesTextArea;
}, function (props) {
  return props.isDisabled && "\n    pointer-events: none;\n    color: rgba(255, 255, 255, 0.2);\n  ";
}, PlaceholderStyled, _component.STYLES_PLACEHOLDER_ACTIVE, function (props) {
  return props.isHidden && 'display: none';
});

var TextArea =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(TextArea, _React$PureComponent);

  function TextArea() {
    _classCallCheck(this, TextArea);

    return _possibleConstructorReturn(this, _getPrototypeOf(TextArea).apply(this, arguments));
  }

  _createClass(TextArea, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          isHidden = _this$props.isHidden,
          isDisabled = _this$props.isDisabled,
          input = _this$props.input,
          placeholder = _this$props.placeholder,
          _this$props$meta = _this$props.meta,
          touched = _this$props$meta.touched,
          error = _this$props$meta.error,
          className = _this$props.className,
          id = _this$props.id;
      var isError = touched && error;
      var hasValue = input.value !== '';
      return _react.default.createElement(Wrap, {
        isDisabled: isDisabled
      }, _react.default.createElement(TextAreaInput, _extends({}, input, {
        isHidden: isHidden,
        isDisabled: isDisabled,
        hasValue: hasValue,
        touched: touched,
        error: error,
        className: (0, _classnames2.default)(className, _defineProperty({}, _constants.CLASSNAME_HAS_VALUE, hasValue)),
        id: id,
        tabIndex: isDisabled ? -1 : 0,
        onChange: input.onChange
      })), placeholder && _react.default.createElement(PlaceholderStyled, {
        hasValue: hasValue,
        isError: isError,
        isDisabled: isDisabled,
        className: _constants.CLASSNAME_PLACEHOLDER
      }, placeholder), isError && _react.default.createElement(Error, null, error));
    }
  }]);

  return TextArea;
}(_react.default.PureComponent);

TextArea.propTypes = {
  isHidden: _propTypes.bool,
  isDisabled: _propTypes.bool,
  className: _propTypes.string,
  input: _propTypes.object.isRequired,
  placeholder: _propTypes.string,
  meta: _propTypes.object.isRequired,
  id: _propTypes.string
};
TextArea.defaultProps = {
  isHidden: false,
  isDisabled: false,
  className: '',
  placeholder: '',
  id: undefined
};
var _default = TextArea;
exports.default = _default;