"use client";
'use strict';

var jsxRuntime = require('react/jsx-runtime');
var menuProvider = require('../../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.cjs');
var comboboxProvider = require('../../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.cjs');
var React = require('react');

/**
 Root context to manage the Dropdown control
 @remarks Only for internal usage.
 */
const DropdownContext = React.createContext(undefined);
const useDropdownContext = () => {
    const context = React.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] = React.useState(defaultSearchValue);
    const dropdownContext = useDropdownContext();
    const searchValue = providedSearchValue ?? internalSearchValue;
    const setValue = React.useCallback((value) => {
        setInternalSearchValue(value);
        onSearch?.(value);
    }, [onSearch]);
    const element = (jsxRuntime.jsx(menuProvider.MenuProvider, { focusLoop: focusLoop, setOpen: onOpenChange, ...props }));
    return (jsxRuntime.jsx(DropdownContext.Provider, { value: {
            autocomplete,
            parent: dropdownContext,
            autocompleteMode,
            searchValue
        }, children: autocomplete ? (jsxRuntime.jsx(comboboxProvider.ComboboxProvider, { resetValueOnHide: true, focusLoop: focusLoop, includesBaseElement: false, value: searchValue, setOpen: onOpenChange, setValue: setValue, children: element })) : (element) }));
};

exports.DropdownContext = DropdownContext;
exports.DropdownMenuRoot = DropdownMenuRoot;
exports.useDropdownContext = useDropdownContext;
//# sourceMappingURL=dropdown-menu-root.cjs.map
