import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import PropTypes from 'prop-types';
import * as React from 'react';
import styled from 'styled-components';
import injectE2E from '../../Tools/injectE2E';
import { fontSize, prop, theme } from '../../Tools/interpolation';
import Checkbox from './Checkbox';
import Radio from './Radio';
var Container =
/*#__PURE__*/
styled.div.withConfig({
  componentId: "sc-1c3roxu-0"
})(["\n  display: flex;\n  flex-direction: column;\n  width: ", ";\n  position: relative;\n"], prop('width'));
var InputWrapper =
/*#__PURE__*/
styled.input.attrs(injectE2E).withConfig({
  componentId: "sc-1c3roxu-1"
})(["\n  display: block;\n  height: 2.7rem;\n  width: ", ";\n  padding: 0 1rem;\n  box-sizing: border-box;\n  font-family: ", ";\n  font-size: ", ";\n  color: ", ";\n  border-width: 1px;\n  border-color: ", ";\n  border-style: solid;\n  border-radius: ", ";\n  background-color: ", ";\n  background-image: none;\n  outline-width: 0;\n  user-select: text;\n  transition: box-shadow 0.25s ease-out;\n\n  &:disabled {\n    color: ", ";\n    border-color: ", ";\n    background: ", ";\n    cursor: not-allowed;\n  }\n\n  &:active:not(:disabled),\n  &:focus:not(:disabled) {\n    box-shadow: 0 0 0 1px\n      ", ";\n  }\n\n  &::placeholder {\n    color: ", ";\n    font-size: ", ";\n  }\n"], prop('width'), theme('fontPrimary'), fontSize('md'), theme('inputColor'), function (props) {
  return props.error != null ? theme('dangerColor')(props) : theme('inputBorderColor')(props);
}, theme('inputBorderRadius'), theme('inputBackgroundColor'), theme('inputColor'), theme('inputBorderColor'), theme('inputBackgroundColorDisabled'), function (props) {
  return props.error != null ? 'transparent' : theme('inputActiveColor');
}, theme('inputPlaceholderColor'), fontSize('sm'));
export var InputLabel =
/*#__PURE__*/
styled.label.withConfig({
  componentId: "sc-1c3roxu-2"
})(["\n  font-family: ", ";\n  font-size: ", ";\n  padding-bottom: 0.5rem;\n  color: ", ";\n  ", ";\n"], theme('fontPrimary'), fontSize('sm'), function (props) {
  return props.error === true && props.disabled !== true ? props.theme.dangerColor : props.theme.inputLabelColor;
}, function (props) {
  return props.disabled === true ? 'cursor: not-allowed' : '';
});

var Input = function Input(_ref) {
  var _ref$className = _ref.className,
      className = _ref$className === void 0 ? '' : _ref$className,
      input = _ref.input,
      type = _ref.type,
      renderSuffix = _ref.renderSuffix,
      rest = _objectWithoutProperties(_ref, ["className", "input", "type", "renderSuffix"]);

  var hasLabel = rest.label != null;
  var hasError = rest.error != null;

  if (type === 'checkbox') {
    return React.createElement(Checkbox, _extends({
      className: className,
      input: input,
      type: "checkbox"
    }, rest));
  }

  if (type === 'radio') {
    return React.createElement(Radio, _extends({
      className: className,
      input: input,
      type: "radio"
    }, rest));
  }

  if (hasLabel || hasError) {
    return React.createElement(Container, {
      className: className,
      width: rest.width
    }, React.createElement(InputLabel, {
      disabled: rest.disabled,
      error: hasError,
      htmlFor: rest.name
    }, "".concat(rest.label || '').concat(hasLabel && hasError ? ' - ' : '').concat(rest.error || '')), React.createElement(InputWrapper, _extends({}, input, rest, {
      type: type
    })), renderSuffix && renderSuffix(rest.disabled));
  }

  return React.createElement(Container, {
    className: className,
    width: rest.width
  }, React.createElement(InputWrapper, _extends({}, input, rest, {
    type: type
  })), renderSuffix && renderSuffix(rest.disabled));
};

Input.propTypes = process.env.NODE_ENV !== "production" ? {
  className: PropTypes.string,
  disabled: PropTypes.bool,
  e2e: PropTypes.string,
  error: PropTypes.string,
  input: PropTypes.object,
  label: PropTypes.string,
  name: PropTypes.string,
  renderSuffix: PropTypes.func,
  type: PropTypes.oneOf(['checkbox', 'date', 'number', 'password', 'radio', 'search', 'text']),
  value: PropTypes.string,
  width: PropTypes.string
} : {};
Input.defaultProps = {
  disabled: false,
  e2e: 'defaultInput',
  type: 'text',
  width: '100%'
};
export default Input;