"use client";
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { useMenuContext } 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/__chunks/VIIRIBF3.js';
import { Menu } 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.js';
import { Combobox } 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.js';
import { ComboboxList } 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/__chunks/MAXQOH4L.js';
import { cx } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { forwardRef, useRef, useState, useEffect } from 'react';
import { useDropdownContext } from './dropdown-menu-root.js';
import styles from './dropdown-menu.module.css.js';
import { Root } from '../../node_modules/.pnpm/@radix-ui_react-visually-hidden@1.2.3_@types_react-dom@19.1.7_@types_react@19.1.9__@types_rea_nas2f5v5xqlignvaay23ejie7a/node_modules/@radix-ui/react-visually-hidden/dist/index.js';
import { Root as Slot } from '../../node_modules/.pnpm/@radix-ui_react-slot@1.2.3_@types_react@19.1.9_react@19.1.1/node_modules/@radix-ui/react-slot/dist/index.js';

const DropdownMenuContent = forwardRef(({ className, children, asChild, searchPlaceholder = 'Search...', ...props }, ref) => {
    const menu = useMenuContext();
    const { autocomplete } = useDropdownContext();
    const isSubMenu = !!menu?.parent;
    const comboboxRef = useRef(null);
    const visuallyHiddenRef = useRef(null);
    const [isInsideRadixDialog, setIsInsideRadixDialog] = useState(false);
    /*
     * This is a workaround to fix focus lock issue when the dropdown menu is inside a Radix Dialog.
     * TODO: Use Radix.Popover for the dropdown popover
     */
    useEffect(() => {
        setIsInsideRadixDialog(!!visuallyHiddenRef.current?.closest("[role='dialog']"));
    }, []);
    return (jsxs(Fragment, { children: [jsx(Root, { ref: visuallyHiddenRef, "aria-hidden": 'true' }), jsx(Menu, { ref: ref, modal: !isInsideRadixDialog, portal: !isInsideRadixDialog, portalElement: typeof window === 'undefined' || isInsideRadixDialog
                    ? null
                    : window?.document?.body, unmountOnHide: true, gutter: isSubMenu ? 2 : 4, className: cx(styles.content, autocomplete && styles.comboboxContainer, className), render: asChild ? jsx(Slot, {}) : undefined, ...props, children: autocomplete ? (jsxs(Fragment, { children: [jsx(Combobox, { ref: comboboxRef, placeholder: searchPlaceholder, className: styles.comboboxInput, autoSelect: true, onPointerEnter: e => {
                                if (document &&
                                    document.activeElement !== comboboxRef.current)
                                    comboboxRef.current?.focus();
                            } }), jsx(ComboboxList, { className: styles.comboboxContent, children: children })] })) : (children) })] }));
});

export { DropdownMenuContent };
//# sourceMappingURL=dropdown-menu-content.js.map
