'use strict';

var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var menuProvider = require('../../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.cjs');
var comboboxProvider = require('../../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.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 = "", ...props }) => {
    const [internalSearchValue, setInternalSearchValue] = React.useState(defaultSearchValue);
    const dropdownContext = useDropdownContext();
    const searchValue = providedSearchValue ?? internalSearchValue;
    const setValue = (value) => {
        setInternalSearchValue(value);
        onSearch?.(value);
    };
    const element = jsxRuntime.jsxRuntimeExports.jsx(menuProvider.MenuProvider, { focusLoop: focusLoop, ...props });
    return (jsxRuntime.jsxRuntimeExports.jsx(DropdownContext.Provider, { value: {
            autocomplete,
            parent: dropdownContext,
            autocompleteMode,
            searchValue,
        }, children: autocomplete ? (jsxRuntime.jsxRuntimeExports.jsx(comboboxProvider.ComboboxProvider, { resetValueOnHide: true, focusLoop: focusLoop, includesBaseElement: false, value: searchValue, setValue: setValue, children: element })) : (element) }));
};

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