"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _excluded = ["ariaLabel", "fieldClassName", "inversed", "multiline", "numeric", "onCopyCapture", "pattern", "rows", "inputRef", "size", "type"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
// TODO: We don't want to remove these until a breaking change in case anyone
// was referencing these types directly from this file.
/**
 * `<TextInput>` is an internal component used by `<TextField>`, which wraps it and handles shared form UI like labels, error messages, etc
 * `<TextInput>` is also exported for advanced design system use cases, where the internal component can be leveraged to build custom form components
 * As an internal component, it's subject to more breaking changes. Exercise caution using `<TextInput>` outside of those special cases
 */
var TextInput = function TextInput(props) {
  var ariaLabel = props.ariaLabel,
    fieldClassName = props.fieldClassName,
    inversed = props.inversed,
    multiline = props.multiline,
    numeric = props.numeric,
    onCopyCapture = props.onCopyCapture,
    pattern = props.pattern,
    rows = props.rows,
    inputRef = props.inputRef,
    size = props.size,
    type = props.type,
    inputProps = _objectWithoutProperties(props, _excluded);
  var classes = (0, _classnames.default)('ds-c-field', {
    'ds-c-field--error': props['aria-invalid'],
    'ds-c-field--inverse': inversed
  }, size && "ds-c-field--".concat(size), fieldClassName);
  var inputType = type;
  if (numeric) {
    inputType = 'text';
  } else if (multiline) {
    inputType = undefined;
  }
  var ComponentType = multiline ? 'textarea' : 'input';
  var numberRows = typeof rows === 'string' ? parseInt(rows) : rows;
  return /*#__PURE__*/_react.default.createElement(ComponentType, _extends({
    className: classes,
    ref: inputRef,
    rows: multiline && numberRows ? numberRows : undefined,
    inputMode: numeric ? 'numeric' : undefined,
    pattern: numeric && !pattern ? '[0-9]*' : pattern,
    type: inputType
    // @ts-ignore: The ClipboardEventHandler for textareas and inputs are incompatible, and TS
    // is failing to infer which one is being used here based on ComponentType.
    ,
    onCopyCapture: onCopyCapture
  }, inputProps, {
    "aria-label": ariaLabel || props['aria-label']
  }));
};
var _default = TextInput;
exports.default = _default;