"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// 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
 */
const TextInput = props => {
  const {
    ariaLabel,
    fieldClassName,
    inversed,
    multiline,
    numeric,
    onCopyCapture,
    pattern,
    rows,
    inputRef,
    size,
    type,
    ...inputProps
  } = props;
  const classes = (0, _classnames.default)('ds-c-field', {
    'ds-c-field--error': props['aria-invalid'],
    'ds-c-field--inverse': inversed
  }, size && `ds-c-field--${size}`, fieldClassName);
  let inputType = type;
  if (numeric) {
    inputType = 'text';
  } else if (multiline) {
    inputType = undefined;
  }
  const ComponentType = multiline ? 'textarea' : 'input';
  const numberRows = typeof rows === 'string' ? parseInt(rows) : rows;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ComponentType, {
    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 = exports.default = TextInput;