import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025 GoodData Corporation
import { forwardRef, } from "react";
import { useMergeRefs } from "@floating-ui/react";
import cx from "classnames";
import { e } from "./comboboxBem.js";
import { useComboboxState } from "./UiComboboxContext.js";
/** @internal */
export const UiComboboxInput = forwardRef(function UiComboboxInput(props, forwardedRef) {
    const { type, className, ...htmlInputProps } = props;
    const { inputValue, onInputChange, onInputKeyDown, onInputBlur, setReferenceRef, getReferenceProps, activeOption, } = useComboboxState();
    const ref = useMergeRefs([forwardedRef, setReferenceRef]);
    const referenceProps = getReferenceProps({
        ...htmlInputProps,
        autoComplete: "off",
        autoCapitalize: "none",
        autoCorrect: "off",
        // Most of the aria attributes already come from `getReferenceProps`
        "aria-activedescendant": activeOption?.id,
        "aria-autocomplete": "list",
        onKeyDown: handleKeyDown,
        onBlur: handleBlur,
    });
    function handleChange(event) {
        onInputChange(event.target.value);
        htmlInputProps.onChange?.(event);
    }
    function handleKeyDown(event) {
        onInputKeyDown(event);
        htmlInputProps.onKeyDown?.(event);
    }
    function handleBlur(event) {
        onInputBlur();
        htmlInputProps.onBlur?.(event);
    }
    return (_jsx("input", { ...referenceProps, ref: ref, className: cx(e("input"), className), type: type ?? "text", value: inputValue, onChange: handleChange }));
});
//# sourceMappingURL=UiComboboxInput.js.map