import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef } from 'react';
import FormField from '../FormField';
import { StyledFormControl } from '../FormControl';
import { createClassName, hasProp, withTestIds } from '../../utils';
import { useTestIds, useUID } from '../../hooks';
import StyledInput from './Input.styles';
import { getInputTestIds } from './Input.test-ids';
export default withTestIds(forwardRef(function Input(props, ref) {
    const uid = useUID();
    const { testId, id = uid, value, defaultValue, required = false, disabled = false, readOnly = false, label, additionalInfo, labelHidden, info, status, actions, onResolveSuggestion, className, ...restProps } = props;
    const testIds = useTestIds(testId, getInputTestIds);
    const controlProp = {};
    // Conditionally render component as controlled/uncontrolled
    if (hasProp(props, 'value')) {
        controlProp.value = value ?? '';
    }
    else if (hasProp(props, 'defaultValue')) {
        controlProp.defaultValue = defaultValue ?? '';
    }
    const Comp = (_jsx(StyledFormControl, { "data-testid": testIds.control, ref: ref, id: id, required: required, disabled: disabled, readOnly: readOnly, status: status, hasSuggestion: !!onResolveSuggestion && status === 'pending', ...controlProp, 
        // Disables browser autocomplete
        // Chrome does not respect autocomplete='off'
        // Current consensus is to workaround via random string
        autoComplete: '_off', ...restProps, as: StyledInput, className: createClassName('input', className) }));
    return label ? (_jsx(FormField, { testId: testIds, additionalInfo: additionalInfo, label: label, labelHidden: labelHidden, id: id, info: info, readOnly: readOnly, status: status, required: required, disabled: disabled, actions: actions, onResolveSuggestion: onResolveSuggestion, children: Comp })) : (Comp);
}), getInputTestIds);
//# sourceMappingURL=Input.js.map