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 = ["type", "size", "color", "fullWidth", "withIcon", "value", "valid", "invalid", "className", "setInputRef", "errorMessage", "disabled"];
import * as React from 'react';
import classnames from 'classnames';
import Text from '../text/Text';
import Flex from '../flex/Flex';
export var TYPE = {
  BUTTON: 'button',
  COLOR: 'color',
  DATE: 'date',
  DATETIME_LOCAL: 'datetime-local',
  EMAIL: 'email',
  FILE: 'file',
  HIDDEN: 'hidden',
  IMAGE: 'image',
  MONTH: 'month',
  NUMBER: 'number',
  PASSWORD: 'password',
  RANGE: 'range',
  RESET: 'reset',
  SEARCH: 'search',
  SUBMIT: 'submit',
  TEL: 'tel',
  TEXT: 'text',
  TIME: 'time',
  URL: 'url',
  WEEK: 'week'
};
export var SIZE = {
  L: 'l',
  M: 'm',
  S: 's'
};
export var COLOR = {
  DEFAULT: 'default',
  WHITE: 'white'
};

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

  var _props$type = props.type,
      type = _props$type === void 0 ? 'text' : _props$type,
      _props$size = props.size,
      size = _props$size === void 0 ? SIZE.M : _props$size,
      _props$color = props.color,
      color = _props$color === void 0 ? COLOR.DEFAULT : _props$color,
      fullWidth = props.fullWidth,
      withIcon = props.withIcon,
      value = props.value,
      valid = props.valid,
      invalid = props.invalid,
      className = props.className,
      setInputRef = props.setInputRef,
      errorMessage = props.errorMessage,
      disabled = props.disabled,
      additionalProps = _objectWithoutProperties(props, _excluded);

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

  var inputClass = classnames('sg-input', (_classnames = {}, _defineProperty(_classnames, "sg-input--".concat(String(size)), size !== SIZE.M), _defineProperty(_classnames, "sg-input--".concat(String(color)), color !== COLOR.DEFAULT), _defineProperty(_classnames, 'sg-input--valid', valid), _defineProperty(_classnames, 'sg-input--invalid', invalid), _defineProperty(_classnames, 'sg-input--full-width', fullWidth), _defineProperty(_classnames, 'sg-input--with-icon', withIcon), _classnames), className);
  var wrapperClass = classnames('sg-input__wrapper', {
    'sg-input__wrapper--full-width': fullWidth,
    'sg-input__wrapper--disabled': disabled
  });
  var errorMessageDisplayed = invalid === true && errorMessage !== undefined && errorMessage !== '';
  return /*#__PURE__*/React.createElement("div", {
    className: wrapperClass
  }, /*#__PURE__*/React.createElement("input", _extends({}, additionalProps, {
    type: type,
    ref: setInputRef,
    className: inputClass,
    value: value,
    disabled: disabled
  })), errorMessageDisplayed && /*#__PURE__*/React.createElement(Flex, {
    marginTop: "xxs",
    marginLeft: size === 'l' ? 'm' : 's',
    marginRight: size === 'l' ? 'm' : 's'
  }, /*#__PURE__*/React.createElement(Text, {
    size: size === 'l' ? 'small' : 'xsmall',
    color: disabled ? 'text-gray-50' : 'text-red-60'
  }, errorMessage)));
};

export default Input;