import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["component", "className", "label", "id", "endAdornment", "startAdornment", "error", "success", "warning", "helperText"];
import React from "react";
import cx from "classnames";
import { useId } from "../../hooks";
import getStyles from "./styles";
var TextfieldBase = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _cx, _cx2;

  var _props$component = props.component,
      Component = _props$component === void 0 ? "input" : _props$component,
      className = props.className,
      label = props.label,
      propId = props.id,
      endAdornment = props.endAdornment,
      startAdornment = props.startAdornment,
      error = props.error,
      success = props.success,
      warning = props.warning,
      helperText = props.helperText,
      htmlProps = _objectWithoutProperties(props, _excluded);

  var helperTextId = useId(null, "helper-text");
  var id = useId(propId, "textfield");
  var classes = getStyles();
  var inputClasses = cx(classes.input, (_cx = {}, _defineProperty(_cx, classes.endAdornmentSpace, endAdornment), _defineProperty(_cx, classes.startAdornmentSpace, startAdornment), _cx));
  var rootClasses = cx(classes.root, (_cx2 = {}, _defineProperty(_cx2, classes.error, error), _defineProperty(_cx2, classes.warning, warning), _defineProperty(_cx2, classes.success, success), _cx2));
  return /*#__PURE__*/React.createElement("div", {
    className: className
  }, label && /*#__PURE__*/React.createElement("label", {
    className: classes.label,
    htmlFor: id
  }, label), /*#__PURE__*/React.createElement("div", {
    className: rootClasses
  }, startAdornment, /*#__PURE__*/React.createElement(Component, _extends({
    id: id,
    ref: ref,
    className: inputClasses,
    "aria-describedby": helperText && helperTextId,
    "aria-invalid": error
  }, htmlProps)), endAdornment), helperText && /*#__PURE__*/React.createElement("div", {
    className: classes.helperText,
    id: helperTextId
  }, helperText));
});

if (process.env.NODE_ENV !== "production") {
  TextfieldBase.displayName = "TextfieldBase";
}

export default TextfieldBase;