"use client";
import { jsx } from 'react/jsx-runtime';
import { MenuProvider } from '../../node_modules/.pnpm/@ariakit_react-core@0.4.16_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/@ariakit/react-core/esm/menu/menu-provider.js';
import { ComboboxProvider } from '../../node_modules/.pnpm/@ariakit_react-core@0.4.16_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js';
import { createContext, useContext, useState, useCallback } 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 = '', onOpenChange, ...props }) => {
    const [internalSearchValue, setInternalSearchValue] = useState(defaultSearchValue);
    const dropdownContext = useDropdownContext();
    const searchValue = providedSearchValue ?? internalSearchValue;
    const setValue = useCallback((value) => {
        setInternalSearchValue(value);
        onSearch?.(value);
    }, [onSearch]);
    const element = (jsx(MenuProvider, { focusLoop: focusLoop, setOpen: onOpenChange, ...props }));
    return (jsx(DropdownContext.Provider, { value: {
            autocomplete,
            parent: dropdownContext,
            autocompleteMode,
            searchValue
        }, children: autocomplete ? (jsx(ComboboxProvider, { resetValueOnHide: true, focusLoop: focusLoop, includesBaseElement: false, value: searchValue, setOpen: onOpenChange, setValue: setValue, children: element })) : (element) }));
};

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