import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import { MenuProvider } from '../../node_modules/.pnpm/@ariakit_react-core@0.4.16_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@ariakit/react-core/esm/menu/menu-provider.js';
import { ComboboxProvider } from '../../node_modules/.pnpm/@ariakit_react-core@0.4.16_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js';
import { createContext, useContext, useState } from 'react';

/**
 Root context to manage the Dropdown control
 @remarks Only for internal usage.
 */
const DropdownContext = createContext(undefined);
const useDropdownContext = () => {
    const context = useContext(DropdownContext);
    if (!context)
        return {};
    const shouldFilter = !!(context?.autocomplete &&
        context?.autocompleteMode === "auto" &&
        context?.searchValue?.length);
    const shouldFilterParent = !!(context?.parent?.autocomplete &&
        context?.parent?.autocompleteMode === "auto" &&
        context?.parent?.searchValue?.length);
    return {
        ...context,
        shouldFilter,
        parent: context?.parent && {
            ...context.parent,
            shouldFilter: shouldFilterParent,
        },
    };
};
const DropdownMenuRoot = ({ autocomplete, autocompleteMode = "auto", searchValue: providedSearchValue, onSearch, focusLoop = true, defaultSearchValue = "", ...props }) => {
    const [internalSearchValue, setInternalSearchValue] = useState(defaultSearchValue);
    const dropdownContext = useDropdownContext();
    const searchValue = providedSearchValue ?? internalSearchValue;
    const setValue = (value) => {
        setInternalSearchValue(value);
        onSearch?.(value);
    };
    const element = jsxRuntimeExports.jsx(MenuProvider, { focusLoop: focusLoop, ...props });
    return (jsxRuntimeExports.jsx(DropdownContext.Provider, { value: {
            autocomplete,
            parent: dropdownContext,
            autocompleteMode,
            searchValue,
        }, children: autocomplete ? (jsxRuntimeExports.jsx(ComboboxProvider, { resetValueOnHide: true, focusLoop: focusLoop, includesBaseElement: false, value: searchValue, setValue: setValue, children: element })) : (element) }));
};

export { DropdownContext, DropdownMenuRoot, useDropdownContext };
//# sourceMappingURL=dropdown-menu-root.js.map
