import {DEFAULT_SLOT as $7230ffa83bc0c2cf$export$c62b8e45d58ddad9, dom as $7230ffa83bc0c2cf$export$df3a06d6289f983e, Provider as $7230ffa83bc0c2cf$export$2881499e37b75b9a, useContextProps as $7230ffa83bc0c2cf$export$29f1550f4b0d4415, useRenderProps as $7230ffa83bc0c2cf$export$4d86445c2cf5e3, useSlot as $7230ffa83bc0c2cf$export$9d4c57ee4c6ffdd8, useSlottedContext as $7230ffa83bc0c2cf$export$fabf2dc03a41866e} from "./utils.mjs";
import {CollectionRendererContext as $263ab7fc0f95ccdb$export$4feb769f8ddf26c5, SectionContext as $263ab7fc0f95ccdb$export$d40e14dec8b060a8, usePersistedKeys as $263ab7fc0f95ccdb$export$90e00781bc59d8f9} from "./Collection.mjs";
import {FieldInputContext as $4b38b5b75ecc6208$export$698f465ec27e93df, SelectableCollectionContext as $4b38b5b75ecc6208$export$b0d3ecf7112093a7} from "./Autocomplete.mjs";
import {HeaderContext as $53e61d82d8b8611d$export$e0e4026c12a8bdbb} from "./Header.mjs";
import {KeyboardContext as $650bea62ab5f5f0f$export$744d98a3b8a94e1c} from "./Keyboard.mjs";
import {OverlayTriggerStateContext as $f2ff30fde7b014be$export$d2f961adcb0afbe} from "./Dialog.mjs";
import {PopoverContext as $542a13ca2fa5b484$export$9b9a0cd73afb7ca4} from "./Popover.mjs";
import {SelectionIndicatorContext as $91fe5e721c7f36c1$export$c9549807523555e0} from "./SelectionIndicator.mjs";
import {SeparatorContext as $e28ab3efe3e87743$export$6615d83f6de245ce} from "./Separator.mjs";
import {SharedElementTransition as $792f28e438b9ad5f$export$758399f318e6385a} from "./SharedElementTransition.mjs";
import {TextContext as $efe09c6d1c304b50$export$9afb8bc826b033ea} from "./Text.mjs";
import {useMenuTrigger as $7xe5e$useMenuTrigger, useSubmenuTrigger as $7xe5e$useSubmenuTrigger, useMenu as $7xe5e$useMenu, useMenuSection as $7xe5e$useMenuSection, useMenuItem as $7xe5e$useMenuItem} from "react-aria/useMenu";
import {CollectionNode as $7xe5e$CollectionNode, SectionNode as $7xe5e$SectionNode, ItemNode as $7xe5e$ItemNode} from "react-aria/private/collections/BaseCollection";
import {useMenuTriggerState as $7xe5e$useMenuTriggerState, useSubmenuTriggerState as $7xe5e$useSubmenuTriggerState} from "react-stately/useMenuTriggerState";
import {createBranchComponent as $7xe5e$createBranchComponent, CollectionBuilder as $7xe5e$CollectionBuilder, Collection as $7xe5e$Collection, createLeafComponent as $7xe5e$createLeafComponent} from "react-aria/private/collections/CollectionBuilder";
import {filterDOMProps as $7xe5e$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {FocusScope as $7xe5e$FocusScope} from "react-aria/FocusScope";
import {mergeProps as $7xe5e$mergeProps} from "react-aria/mergeProps";
import {PressResponder as $7xe5e$PressResponder} from "react-aria/private/interactions/PressResponder";
import $7xe5e$react, {createContext as $7xe5e$createContext, useRef as $7xe5e$useRef, useState as $7xe5e$useState, useCallback as $7xe5e$useCallback, useContext as $7xe5e$useContext, forwardRef as $7xe5e$forwardRef, useMemo as $7xe5e$useMemo} from "react";
import {SelectionManager as $7xe5e$SelectionManager} from "react-stately/private/selection/SelectionManager";
import {useTreeState as $7xe5e$useTreeState} from "react-stately/useTreeState";
import {useHover as $7xe5e$useHover} from "react-aria/useHover";
import {useMultipleSelectionState as $7xe5e$useMultipleSelectionState} from "react-stately/useMultipleSelectionState";
import {useObjectRef as $7xe5e$useObjectRef} from "react-aria/useObjectRef";
import {useResizeObserver as $7xe5e$useResizeObserver} from "react-aria/private/utils/useResizeObserver";

/*
 * Copyright 2022 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 

























const $49319ee1285aa241$export$c7e742effb1c51e2 = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
const $49319ee1285aa241$export$24aad8519b95b41b = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
const $49319ee1285aa241$export$795aec4671cbae19 = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
const $49319ee1285aa241$var$SelectionManagerContext = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
function $49319ee1285aa241$export$27d2ad3c5815583e(props) {
    let state = (0, $7xe5e$useMenuTriggerState)(props);
    let ref = (0, $7xe5e$useRef)(null);
    let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $7xe5e$useMenuTrigger)({
        ...props,
        type: 'menu'
    }, state, ref);
    // Allows menu width to match button
    let [buttonWidth, setButtonWidth] = (0, $7xe5e$useState)(null);
    let onResize = (0, $7xe5e$useCallback)(()=>{
        if (ref.current) setButtonWidth(ref.current.offsetWidth + 'px');
    }, [
        ref
    ]);
    (0, $7xe5e$useResizeObserver)({
        ref: ref,
        onResize: onResize
    });
    let scrollRef = (0, $7xe5e$useRef)(null);
    return /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                $49319ee1285aa241$export$c7e742effb1c51e2,
                {
                    ...menuProps,
                    ref: scrollRef
                }
            ],
            [
                (0, $f2ff30fde7b014be$export$d2f961adcb0afbe),
                state
            ],
            [
                $49319ee1285aa241$export$795aec4671cbae19,
                state
            ],
            [
                (0, $542a13ca2fa5b484$export$9b9a0cd73afb7ca4),
                {
                    trigger: 'MenuTrigger',
                    triggerRef: ref,
                    scrollRef: scrollRef,
                    placement: 'bottom start',
                    style: {
                        '--trigger-width': buttonWidth
                    },
                    'aria-labelledby': menuProps['aria-labelledby']
                }
            ]
        ]
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7xe5e$PressResponder), {
        ...menuTriggerProps,
        ref: ref,
        isPressed: state.isOpen
    }, props.children));
}
const $49319ee1285aa241$var$SubmenuTriggerContext = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
class $49319ee1285aa241$var$SubmenuTriggerNode extends (0, $7xe5e$CollectionNode) {
    static{
        this.type = 'submenutrigger';
    }
    filter(collection, newCollection, filterFn) {
        let triggerNode = collection.getItem(this.firstChildKey);
        if (triggerNode && filterFn(triggerNode.textValue, this)) {
            let clone = this.clone();
            newCollection.addDescendants(clone, collection);
            return clone;
        }
        return null;
    }
}
const $49319ee1285aa241$export$ecabc99eeffab7ca = /*#__PURE__*/ (0, $7xe5e$createBranchComponent)($49319ee1285aa241$var$SubmenuTriggerNode, (props, ref, item)=>{
    let { CollectionBranch: CollectionBranch } = (0, $7xe5e$useContext)((0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5));
    let state = (0, $7xe5e$useContext)($49319ee1285aa241$export$24aad8519b95b41b);
    let rootMenuTriggerState = (0, $7xe5e$useContext)($49319ee1285aa241$export$795aec4671cbae19);
    let submenuTriggerState = (0, $7xe5e$useSubmenuTriggerState)({
        triggerKey: item.key
    }, rootMenuTriggerState);
    let submenuRef = (0, $7xe5e$useRef)(null);
    let itemRef = (0, $7xe5e$useObjectRef)(ref);
    let { parentMenuRef: parentMenuRef, shouldUseVirtualFocus: shouldUseVirtualFocus } = (0, $7xe5e$useContext)($49319ee1285aa241$var$SubmenuTriggerContext);
    let { submenuTriggerProps: submenuTriggerProps, submenuProps: submenuProps, popoverProps: popoverProps } = (0, $7xe5e$useSubmenuTrigger)({
        parentMenuRef: parentMenuRef,
        submenuRef: submenuRef,
        delay: props.delay,
        shouldUseVirtualFocus: shouldUseVirtualFocus
    }, submenuTriggerState, itemRef);
    return /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                $49319ee1285aa241$var$MenuItemContext,
                {
                    ...submenuTriggerProps,
                    onAction: undefined,
                    ref: itemRef
                }
            ],
            [
                $49319ee1285aa241$export$c7e742effb1c51e2,
                {
                    ref: submenuRef,
                    ...submenuProps
                }
            ],
            [
                (0, $f2ff30fde7b014be$export$d2f961adcb0afbe),
                submenuTriggerState
            ],
            [
                (0, $542a13ca2fa5b484$export$9b9a0cd73afb7ca4),
                {
                    trigger: 'SubmenuTrigger',
                    triggerRef: itemRef,
                    placement: 'end top',
                    'aria-labelledby': submenuProps['aria-labelledby'],
                    ...popoverProps
                }
            ]
        ]
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement(CollectionBranch, {
        collection: state.collection,
        parent: item
    }), props.children[1]);
}, (props)=>props.children[0]);
const $49319ee1285aa241$export$d9b273488cd8ce6f = /*#__PURE__*/ (0, $7xe5e$forwardRef)(function Menu(props, ref) {
    [props, ref] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(props, ref, $49319ee1285aa241$export$c7e742effb1c51e2);
    // Delay rendering the actual menu until we have the collection so that auto focus works properly.
    return /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7xe5e$CollectionBuilder), {
        content: /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7xe5e$Collection), props)
    }, (collection)=>/*#__PURE__*/ (0, $7xe5e$react).createElement($49319ee1285aa241$var$MenuInner, {
            props: props,
            collection: collection,
            menuRef: ref
        }));
});
function $49319ee1285aa241$var$MenuInner({ props: props, collection: collection, menuRef: ref }) {
    [props, ref] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(props, ref, (0, $4b38b5b75ecc6208$export$b0d3ecf7112093a7));
    let { filter: filter, ...autocompleteMenuProps } = props;
    let filteredCollection = (0, $7xe5e$useMemo)(()=>filter ? collection.filter(filter) : collection, [
        collection,
        filter
    ]);
    let state = (0, $7xe5e$useTreeState)({
        ...props,
        collection: filteredCollection,
        children: undefined
    });
    let triggerState = (0, $7xe5e$useContext)($49319ee1285aa241$export$795aec4671cbae19);
    let { isVirtualized: isVirtualized, CollectionRoot: CollectionRoot } = (0, $7xe5e$useContext)((0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5));
    let { menuProps: menuProps } = (0, $7xe5e$useMenu)({
        ...props,
        isVirtualized: isVirtualized,
        onClose: props.onClose || triggerState?.close
    }, state, ref);
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        children: undefined,
        defaultClassName: 'react-aria-Menu',
        values: {
            isEmpty: state.collection.size === 0
        }
    });
    let emptyState = null;
    if (state.collection.size === 0 && props.renderEmptyState) emptyState = /*#__PURE__*/ (0, $7xe5e$react).createElement("div", {
        role: "menuitem",
        style: {
            display: 'contents'
        }
    }, props.renderEmptyState());
    let DOMProps = (0, $7xe5e$filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7xe5e$FocusScope), null, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        ...(0, $7xe5e$mergeProps)(DOMProps, renderProps, menuProps),
        ref: ref,
        slot: props.slot || undefined,
        "data-empty": state.collection.size === 0 || undefined,
        onScroll: props.onScroll
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                $49319ee1285aa241$export$24aad8519b95b41b,
                state
            ],
            [
                (0, $e28ab3efe3e87743$export$6615d83f6de245ce),
                {
                    elementType: 'div'
                }
            ],
            [
                (0, $263ab7fc0f95ccdb$export$d40e14dec8b060a8),
                {
                    name: 'MenuSection',
                    render: $49319ee1285aa241$var$MenuSectionInner
                }
            ],
            [
                $49319ee1285aa241$var$SubmenuTriggerContext,
                {
                    parentMenuRef: ref,
                    shouldUseVirtualFocus: autocompleteMenuProps?.shouldUseVirtualFocus
                }
            ],
            [
                $49319ee1285aa241$var$MenuItemContext,
                {
                    shouldCloseOnSelect: props.shouldCloseOnSelect
                }
            ],
            [
                (0, $4b38b5b75ecc6208$export$b0d3ecf7112093a7),
                null
            ],
            [
                (0, $4b38b5b75ecc6208$export$698f465ec27e93df),
                null
            ],
            [
                $49319ee1285aa241$var$SelectionManagerContext,
                state.selectionManager
            ],
            /* Ensure root MenuTriggerState is defined, in case Menu is rendered outside a MenuTrigger. */ /* We assume the context can never change between defined and undefined. */ /* eslint-disable-next-line react-hooks/rules-of-hooks */ [
                $49319ee1285aa241$export$795aec4671cbae19,
                triggerState ?? (0, $7xe5e$useMenuTriggerState)({})
            ]
        ]
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $792f28e438b9ad5f$export$758399f318e6385a), null, /*#__PURE__*/ (0, $7xe5e$react).createElement(CollectionRoot, {
        collection: state.collection,
        persistedKeys: (0, $263ab7fc0f95ccdb$export$90e00781bc59d8f9)(state.selectionManager.focusedKey),
        scrollRef: ref
    }))), emptyState));
}
// A subclass of SelectionManager that forwards focus-related properties to the parent,
// but has its own local selection state.
class $49319ee1285aa241$var$GroupSelectionManager extends (0, $7xe5e$SelectionManager) {
    constructor(parent, state){
        super(parent.collection, state);
        this.parent = parent;
    }
    get focusedKey() {
        return this.parent.focusedKey;
    }
    get isFocused() {
        return this.parent.isFocused;
    }
    setFocusedKey(key, childFocusStrategy) {
        return this.parent.setFocusedKey(key, childFocusStrategy);
    }
    setFocused(isFocused) {
        this.parent.setFocused(isFocused);
    }
    get childFocusStrategy() {
        return this.parent.childFocusStrategy;
    }
}
function $49319ee1285aa241$var$MenuSectionInner(props, ref, section, className = 'react-aria-MenuSection') {
    let state = (0, $7xe5e$useContext)($49319ee1285aa241$export$24aad8519b95b41b);
    let { CollectionBranch: CollectionBranch } = (0, $7xe5e$useContext)((0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5));
    let [headingRef, heading] = (0, $7230ffa83bc0c2cf$export$9d4c57ee4c6ffdd8)();
    let { headingProps: headingProps, groupProps: groupProps } = (0, $7xe5e$useMenuSection)({
        heading: heading,
        'aria-label': section.props['aria-label'] ?? undefined
    });
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        id: undefined,
        children: undefined,
        defaultClassName: className,
        className: section.props?.className,
        style: section.props?.style,
        values: undefined
    });
    let parent = (0, $7xe5e$useContext)($49319ee1285aa241$var$SelectionManagerContext);
    let selectionState = (0, $7xe5e$useMultipleSelectionState)(props);
    let manager = props.selectionMode != null ? new $49319ee1285aa241$var$GroupSelectionManager(parent, selectionState) : parent;
    let closeOnSelect = (0, $7230ffa83bc0c2cf$export$fabf2dc03a41866e)($49319ee1285aa241$var$MenuItemContext)?.shouldCloseOnSelect;
    let DOMProps = (0, $7xe5e$filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    return /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).section, {
        ...(0, $7xe5e$mergeProps)(DOMProps, renderProps, groupProps),
        ref: ref
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                (0, $53e61d82d8b8611d$export$e0e4026c12a8bdbb),
                {
                    ...headingProps,
                    ref: headingRef
                }
            ],
            [
                $49319ee1285aa241$var$SelectionManagerContext,
                manager
            ],
            [
                $49319ee1285aa241$var$MenuItemContext,
                {
                    shouldCloseOnSelect: props.shouldCloseOnSelect ?? closeOnSelect
                }
            ]
        ]
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement(CollectionBranch, {
        collection: state.collection,
        parent: section
    })));
}
const $49319ee1285aa241$export$4b1545b4f2016d26 = /*#__PURE__*/ (0, $7xe5e$createBranchComponent)((0, $7xe5e$SectionNode), $49319ee1285aa241$var$MenuSectionInner);
const $49319ee1285aa241$var$MenuItemContext = /*#__PURE__*/ (0, $7xe5e$createContext)(null);
const $49319ee1285aa241$export$2ce376c2cc3355c8 = /*#__PURE__*/ (0, $7xe5e$createLeafComponent)((0, $7xe5e$ItemNode), function MenuItem(props, forwardedRef, item) {
    [props, forwardedRef] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(props, forwardedRef, $49319ee1285aa241$var$MenuItemContext);
    let id = (0, $7230ffa83bc0c2cf$export$fabf2dc03a41866e)($49319ee1285aa241$var$MenuItemContext)?.id;
    let state = (0, $7xe5e$useContext)($49319ee1285aa241$export$24aad8519b95b41b);
    let ref = (0, $7xe5e$useObjectRef)(forwardedRef);
    let selectionManager = (0, $7xe5e$useContext)($49319ee1285aa241$var$SelectionManagerContext);
    let { isVirtualized: isVirtualized } = (0, $7xe5e$useContext)((0, $263ab7fc0f95ccdb$export$4feb769f8ddf26c5));
    let { menuItemProps: menuItemProps, labelProps: labelProps, descriptionProps: descriptionProps, keyboardShortcutProps: keyboardShortcutProps, ...states } = (0, $7xe5e$useMenuItem)({
        ...props,
        id: id,
        key: item.key,
        selectionManager: selectionManager,
        isVirtualized: isVirtualized
    }, state, ref);
    let { hoverProps: hoverProps, isHovered: isHovered } = (0, $7xe5e$useHover)({
        isDisabled: states.isDisabled
    });
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        id: undefined,
        children: item.rendered,
        defaultClassName: 'react-aria-MenuItem',
        values: {
            ...states,
            isHovered: isHovered,
            isFocusVisible: states.isFocusVisible,
            selectionMode: selectionManager.selectionMode,
            selectionBehavior: selectionManager.selectionBehavior,
            hasSubmenu: !!props['aria-haspopup'],
            isOpen: props['aria-expanded'] === 'true'
        }
    });
    let ElementType = props.href ? (0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).a : (0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div;
    let DOMProps = (0, $7xe5e$filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    delete DOMProps.onClick;
    return /*#__PURE__*/ (0, $7xe5e$react).createElement(ElementType, {
        ...(0, $7xe5e$mergeProps)(DOMProps, renderProps, menuItemProps, hoverProps),
        ref: ref,
        "data-disabled": states.isDisabled || undefined,
        "data-hovered": isHovered || undefined,
        "data-focused": states.isFocused || undefined,
        "data-focus-visible": states.isFocusVisible || undefined,
        "data-pressed": states.isPressed || undefined,
        "data-selected": states.isSelected || undefined,
        "data-selection-mode": selectionManager.selectionMode === 'none' ? undefined : selectionManager.selectionMode,
        "data-has-submenu": !!props['aria-haspopup'] || undefined,
        "data-open": props['aria-expanded'] === 'true' || undefined
    }, /*#__PURE__*/ (0, $7xe5e$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                (0, $efe09c6d1c304b50$export$9afb8bc826b033ea),
                {
                    slots: {
                        [(0, $7230ffa83bc0c2cf$export$c62b8e45d58ddad9)]: labelProps,
                        label: labelProps,
                        description: descriptionProps
                    }
                }
            ],
            [
                (0, $650bea62ab5f5f0f$export$744d98a3b8a94e1c),
                keyboardShortcutProps
            ],
            [
                (0, $91fe5e721c7f36c1$export$c9549807523555e0),
                {
                    isSelected: states.isSelected
                }
            ]
        ]
    }, renderProps.children));
});


export {$49319ee1285aa241$export$c7e742effb1c51e2 as MenuContext, $49319ee1285aa241$export$24aad8519b95b41b as MenuStateContext, $49319ee1285aa241$export$795aec4671cbae19 as RootMenuTriggerStateContext, $49319ee1285aa241$export$27d2ad3c5815583e as MenuTrigger, $49319ee1285aa241$export$ecabc99eeffab7ca as SubmenuTrigger, $49319ee1285aa241$export$d9b273488cd8ce6f as Menu, $49319ee1285aa241$export$4b1545b4f2016d26 as MenuSection, $49319ee1285aa241$export$2ce376c2cc3355c8 as MenuItem};
//# sourceMappingURL=Menu.mjs.map
