import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import { createContext, forwardRef, useContext, useState } from 'react';
import { Sub as $d08ef79370b62062$export$d7a01e11500dfb6f, Root as $d08ef79370b62062$export$be92b6f5f03c0fe9 } from '../../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.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';

/*
Root context to manage the Dropdown control
@remarks Only for internal usage.
*/
const DropdownContext = createContext(undefined);
const useDropdownContext = () => {
    const context = 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 = createContext(1);
const useMenuLevel = () => useContext(MenuLevelContext);
function DropdownMenuRoot({ children, autocomplete = false, defaultOpen = false, open, onOpenChange, ...props }) {
    const [searchValue, setSearchValue] = useState("");
    const [internalOpen, setInternalOpen] = useState(defaultOpen);
    const computedOpen = open ?? internalOpen;
    const setOpen = (value) => {
        if (typeof onOpenChange === "function")
            onOpenChange(value);
        else
            setInternalOpen(value);
    };
    return (jsxRuntimeExports.jsx(DropdownContext.Provider, { value: { autocomplete, searchValue }, children: jsxRuntimeExports.jsx($d08ef79370b62062$export$be92b6f5f03c0fe9, { ...props, open: computedOpen, onOpenChange: setOpen, children: jsxRuntimeExports.jsx(MenuLevelContext.Provider, { value: 1, children: autocomplete ? (jsxRuntimeExports.jsx(ComboboxProvider, { open: computedOpen, setOpen: setOpen, resetValueOnHide: true, includesBaseElement: false, setValue: setSearchValue, children: children })) : (children) }) }) }));
}
const DropdownMenuSubMenu = forwardRef(({ children, ...props }, ref) => {
    const menuLevel = useMenuLevel();
    return (jsxRuntimeExports.jsx($d08ef79370b62062$export$d7a01e11500dfb6f, { ...props, children: jsxRuntimeExports.jsx(MenuLevelContext.Provider, { value: menuLevel + 1, children: children }) }));
});
DropdownMenuSubMenu.displayName = $d08ef79370b62062$export$d7a01e11500dfb6f.displayName;

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