'use strict';

var jsxRuntime = require('../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var React = require('react');
var index = require('../../node_modules/.pnpm/@radix-ui_react-dropdown-menu@2.0.5_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@1_e7gmnqwdc4f4ybjj7qkfdho6zy/node_modules/@radix-ui/react-dropdown-menu/dist/index.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');

/*
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) {
        throw new Error("useDropdownContext must be used within a DropdownMenuProvider");
    }
    return context;
};
/*
Context to determine the level of Menu
@remarks Only for internal usage.
*/
const MenuLevelContext = React.createContext(1);
const useMenuLevel = () => React.useContext(MenuLevelContext);
function DropdownMenuRoot({ children, autocomplete = false, defaultOpen = false, open, onOpenChange, ...props }) {
    const [searchValue, setSearchValue] = React.useState("");
    const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
    const computedOpen = open ?? internalOpen;
    const setOpen = (value) => {
        if (typeof onOpenChange === "function")
            onOpenChange(value);
        else
            setInternalOpen(value);
    };
    return (jsxRuntime.jsxRuntimeExports.jsx(DropdownContext.Provider, { value: { autocomplete, searchValue }, children: jsxRuntime.jsxRuntimeExports.jsx(index.Root, { ...props, open: computedOpen, onOpenChange: setOpen, children: jsxRuntime.jsxRuntimeExports.jsx(MenuLevelContext.Provider, { value: 1, children: autocomplete ? (jsxRuntime.jsxRuntimeExports.jsx(comboboxProvider.ComboboxProvider, { open: computedOpen, setOpen: setOpen, resetValueOnHide: true, includesBaseElement: false, setValue: setSearchValue, children: children })) : (children) }) }) }));
}
const DropdownMenuSubMenu = React.forwardRef(({ children, ...props }, ref) => {
    const menuLevel = useMenuLevel();
    return (jsxRuntime.jsxRuntimeExports.jsx(index.Sub, { ...props, children: jsxRuntime.jsxRuntimeExports.jsx(MenuLevelContext.Provider, { value: menuLevel + 1, children: children }) }));
});
DropdownMenuSubMenu.displayName = index.Sub.displayName;

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