var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
import React, { forwardRef } from "react";
import { Floating } from "../../../utils/components/floating/Floating.js";
import { cl } from "../../../utils/helpers/index.js";
import { useMergeRefs } from "../../../utils/hooks/index.js";
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext.js";
import SelectedOptions from "../SelectedOptions/SelectedOptions.js";
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext.js";
import Input from "./Input.js";
import { useInputContext } from "./Input.context.js";
import ToggleListButton from "./ToggleListButton.js";
export const InputController = forwardRef((props, ref) => {
    const { 
    // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Remove when prop has been removed from ComboboxProps.
    clearButton, 
    // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Remove when prop has been removed from ComboboxProps.
    clearButtonLabel, toggleListButton = true, inputClassName, shouldShowSelectedOptions = true } = props, rest = __rest(props, ["clearButton", "clearButtonLabel", "toggleListButton", "inputClassName", "shouldShowSelectedOptions"]);
    const { focusInput, inputProps, size = "medium", inputRef, toggleOpenButtonRef, readOnly, setAnchorRef, } = useInputContext();
    const { activeDescendantId, toggleIsListOpen } = useFilteredOptionsContext();
    const { selectedOptions } = useSelectedOptionsContext();
    const mergedInputRef = useMergeRefs(inputRef, ref);
    return (React.createElement(Floating.Anchor, { asChild: true, ref: setAnchorRef },
        React.createElement("div", { className: cl("aksel-combobox__wrapper-inner aksel-text-field__input", {
                "aksel-combobox__wrapper-inner--virtually-unfocused": activeDescendantId !== undefined,
            }), onClick: () => {
                if (inputProps.disabled || readOnly) {
                    return;
                }
                toggleIsListOpen(true);
                focusInput();
            } },
            !shouldShowSelectedOptions ? (React.createElement(Input, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName, readOnly: readOnly }, rest))) : (React.createElement(SelectedOptions, { selectedOptions: selectedOptions, size: size },
                React.createElement(Input, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName, shouldShowSelectedOptions: shouldShowSelectedOptions, readOnly: readOnly }, rest)))),
            toggleListButton && React.createElement(ToggleListButton, { ref: toggleOpenButtonRef }))));
});
//# sourceMappingURL=InputController.js.map