/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-d1bbdd3
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef, useRef } from 'react';
import { useTextField } from 'react-aria';
import { useProviderProps } from '../../../provider.js';
import { mergeProps } from '../../../utils/react/index.js';
import { castNullableStringValue, } from '../../../utils/react/nullableValue.js';
import { useFieldProps } from '../../form/index.js';
import { TextInputBase } from './TextInputBase.js';
export { useTextField };
export const TextInput = forwardRef(function TextInput(props, ref) {
    props = castNullableStringValue(props);
    props = useProviderProps(props);
    props = useFieldProps(props, {
        defaultValidationTrigger: 'onBlur',
        valuePropsMapper: ({ value, onChange }) => ({
            onChange,
            value: value?.toString() ?? '',
        }),
    });
    let { labelProps: userLabelProps, inputRef: propsInputRef, form, ...restProps } = props;
    let localInputRef = useRef(null);
    let inputRef = propsInputRef ?? localInputRef;
    let { labelProps, inputProps } = useTextField(restProps, inputRef);
    // Merge user-provided labelProps with aria labelProps
    const mergedLabelProps = mergeProps(labelProps, userLabelProps);
    return (_jsx(TextInputBase, { ...restProps, ref: ref, labelProps: mergedLabelProps, inputProps: inputProps, inputRef: inputRef }));
});
/**
 * TextInputs are text inputs that allow users to input custom text entries
 * with a keyboard. Various decorations can be displayed around the field to
 * communicate the entry requirements.
 */
TextInput.cubeInputType = 'Text';

        