var $048d76b84370f141$exports = require("./utils.cjs");
var $f7b82bedbb70abac$exports = require("./Collection.cjs");
var $433949643203e332$exports = require("./Autocomplete.cjs");
var $749e1f015a6d7f1a$exports = require("./Header.cjs");
var $557891271067a1da$exports = require("./Keyboard.cjs");
var $88595bf043e542ec$exports = require("./Dialog.cjs");
var $74e35a768d38d46b$exports = require("./Popover.cjs");
var $61557b2a9b2862a8$exports = require("./SelectionIndicator.cjs");
var $5a1b0036f8cbf051$exports = require("./Separator.cjs");
var $9a60bd90621ebc78$exports = require("./SharedElementTransition.cjs");
var $cab7d9a238d19c33$exports = require("./Text.cjs");
var $fDx7A$reactariauseMenu = require("react-aria/useMenu");
var $fDx7A$reactariaprivatecollectionsBaseCollection = require("react-aria/private/collections/BaseCollection");
var $fDx7A$reactstatelyuseMenuTriggerState = require("react-stately/useMenuTriggerState");
var $fDx7A$reactariaprivatecollectionsCollectionBuilder = require("react-aria/private/collections/CollectionBuilder");
var $fDx7A$reactariaprivateutilsfilterDOMProps = require("react-aria/private/utils/filterDOMProps");
var $fDx7A$reactariaFocusScope = require("react-aria/FocusScope");
var $fDx7A$reactariamergeProps = require("react-aria/mergeProps");
var $fDx7A$reactariaprivateinteractionsPressResponder = require("react-aria/private/interactions/PressResponder");
var $fDx7A$react = require("react");
var $fDx7A$reactstatelyprivateselectionSelectionManager = require("react-stately/private/selection/SelectionManager");
var $fDx7A$reactstatelyuseTreeState = require("react-stately/useTreeState");
var $fDx7A$reactariauseHover = require("react-aria/useHover");
var $fDx7A$reactstatelyuseMultipleSelectionState = require("react-stately/useMultipleSelectionState");
var $fDx7A$reactariauseObjectRef = require("react-aria/useObjectRef");
var $fDx7A$reactariaprivateutilsuseResizeObserver = require("react-aria/private/utils/useResizeObserver");


function $parcel$interopDefault(a) {
  return a && a.__esModule ? a.default : a;
}

function $parcel$export(e, n, v, s) {
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}

$parcel$export(module.exports, "MenuContext", function () { return $76f9e98b4261ab43$export$c7e742effb1c51e2; });
$parcel$export(module.exports, "MenuStateContext", function () { return $76f9e98b4261ab43$export$24aad8519b95b41b; });
$parcel$export(module.exports, "RootMenuTriggerStateContext", function () { return $76f9e98b4261ab43$export$795aec4671cbae19; });
$parcel$export(module.exports, "MenuTrigger", function () { return $76f9e98b4261ab43$export$27d2ad3c5815583e; });
$parcel$export(module.exports, "SubmenuTrigger", function () { return $76f9e98b4261ab43$export$ecabc99eeffab7ca; });
$parcel$export(module.exports, "Menu", function () { return $76f9e98b4261ab43$export$d9b273488cd8ce6f; });
$parcel$export(module.exports, "MenuSection", function () { return $76f9e98b4261ab43$export$4b1545b4f2016d26; });
$parcel$export(module.exports, "MenuItem", function () { return $76f9e98b4261ab43$export$2ce376c2cc3355c8; });
/*
 * 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 $76f9e98b4261ab43$export$c7e742effb1c51e2 = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
const $76f9e98b4261ab43$export$24aad8519b95b41b = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
const $76f9e98b4261ab43$export$795aec4671cbae19 = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
const $76f9e98b4261ab43$var$SelectionManagerContext = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
function $76f9e98b4261ab43$export$27d2ad3c5815583e(props) {
    let state = (0, $fDx7A$reactstatelyuseMenuTriggerState.useMenuTriggerState)(props);
    let ref = (0, $fDx7A$react.useRef)(null);
    let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $fDx7A$reactariauseMenu.useMenuTrigger)({
        ...props,
        type: 'menu'
    }, state, ref);
    // Allows menu width to match button
    let [buttonWidth, setButtonWidth] = (0, $fDx7A$react.useState)(null);
    let onResize = (0, $fDx7A$react.useCallback)(()=>{
        if (ref.current) setButtonWidth(ref.current.offsetWidth + 'px');
    }, [
        ref
    ]);
    (0, $fDx7A$reactariaprivateutilsuseResizeObserver.useResizeObserver)({
        ref: ref,
        onResize: onResize
    });
    let scrollRef = (0, $fDx7A$react.useRef)(null);
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                $76f9e98b4261ab43$export$c7e742effb1c51e2,
                {
                    ...menuProps,
                    ref: scrollRef
                }
            ],
            [
                (0, $88595bf043e542ec$exports.OverlayTriggerStateContext),
                state
            ],
            [
                $76f9e98b4261ab43$export$795aec4671cbae19,
                state
            ],
            [
                (0, $74e35a768d38d46b$exports.PopoverContext),
                {
                    trigger: 'MenuTrigger',
                    triggerRef: ref,
                    scrollRef: scrollRef,
                    placement: 'bottom start',
                    style: {
                        '--trigger-width': buttonWidth
                    },
                    'aria-labelledby': menuProps['aria-labelledby']
                }
            ]
        ]
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $fDx7A$reactariaprivateinteractionsPressResponder.PressResponder), {
        ...menuTriggerProps,
        ref: ref,
        isPressed: state.isOpen
    }, props.children));
}
const $76f9e98b4261ab43$var$SubmenuTriggerContext = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
class $76f9e98b4261ab43$var$SubmenuTriggerNode extends (0, $fDx7A$reactariaprivatecollectionsBaseCollection.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 $76f9e98b4261ab43$export$ecabc99eeffab7ca = /*#__PURE__*/ (0, $fDx7A$reactariaprivatecollectionsCollectionBuilder.createBranchComponent)($76f9e98b4261ab43$var$SubmenuTriggerNode, (props, ref, item)=>{
    let { CollectionBranch: CollectionBranch } = (0, $fDx7A$react.useContext)((0, $f7b82bedbb70abac$exports.CollectionRendererContext));
    let state = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$export$24aad8519b95b41b);
    let rootMenuTriggerState = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$export$795aec4671cbae19);
    let submenuTriggerState = (0, $fDx7A$reactstatelyuseMenuTriggerState.useSubmenuTriggerState)({
        triggerKey: item.key
    }, rootMenuTriggerState);
    let submenuRef = (0, $fDx7A$react.useRef)(null);
    let itemRef = (0, $fDx7A$reactariauseObjectRef.useObjectRef)(ref);
    let { parentMenuRef: parentMenuRef, shouldUseVirtualFocus: shouldUseVirtualFocus } = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$var$SubmenuTriggerContext);
    let { submenuTriggerProps: submenuTriggerProps, submenuProps: submenuProps, popoverProps: popoverProps } = (0, $fDx7A$reactariauseMenu.useSubmenuTrigger)({
        parentMenuRef: parentMenuRef,
        submenuRef: submenuRef,
        delay: props.delay,
        shouldUseVirtualFocus: shouldUseVirtualFocus
    }, submenuTriggerState, itemRef);
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                $76f9e98b4261ab43$var$MenuItemContext,
                {
                    ...submenuTriggerProps,
                    onAction: undefined,
                    ref: itemRef
                }
            ],
            [
                $76f9e98b4261ab43$export$c7e742effb1c51e2,
                {
                    ref: submenuRef,
                    ...submenuProps
                }
            ],
            [
                (0, $88595bf043e542ec$exports.OverlayTriggerStateContext),
                submenuTriggerState
            ],
            [
                (0, $74e35a768d38d46b$exports.PopoverContext),
                {
                    trigger: 'SubmenuTrigger',
                    triggerRef: itemRef,
                    placement: 'end top',
                    'aria-labelledby': submenuProps['aria-labelledby'],
                    ...popoverProps
                }
            ]
        ]
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement(CollectionBranch, {
        collection: state.collection,
        parent: item
    }), props.children[1]);
}, (props)=>props.children[0]);
const $76f9e98b4261ab43$export$d9b273488cd8ce6f = /*#__PURE__*/ (0, $fDx7A$react.forwardRef)(function Menu(props, ref) {
    [props, ref] = (0, $048d76b84370f141$exports.useContextProps)(props, ref, $76f9e98b4261ab43$export$c7e742effb1c51e2);
    // Delay rendering the actual menu until we have the collection so that auto focus works properly.
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $fDx7A$reactariaprivatecollectionsCollectionBuilder.CollectionBuilder), {
        content: /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $fDx7A$reactariaprivatecollectionsCollectionBuilder.Collection), props)
    }, (collection)=>/*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement($76f9e98b4261ab43$var$MenuInner, {
            props: props,
            collection: collection,
            menuRef: ref
        }));
});
function $76f9e98b4261ab43$var$MenuInner({ props: props, collection: collection, menuRef: ref }) {
    [props, ref] = (0, $048d76b84370f141$exports.useContextProps)(props, ref, (0, $433949643203e332$exports.SelectableCollectionContext));
    let { filter: filter, ...autocompleteMenuProps } = props;
    let filteredCollection = (0, $fDx7A$react.useMemo)(()=>filter ? collection.filter(filter) : collection, [
        collection,
        filter
    ]);
    let state = (0, $fDx7A$reactstatelyuseTreeState.useTreeState)({
        ...props,
        collection: filteredCollection,
        children: undefined
    });
    let triggerState = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$export$795aec4671cbae19);
    let { isVirtualized: isVirtualized, CollectionRoot: CollectionRoot } = (0, $fDx7A$react.useContext)((0, $f7b82bedbb70abac$exports.CollectionRendererContext));
    let { menuProps: menuProps } = (0, $fDx7A$reactariauseMenu.useMenu)({
        ...props,
        isVirtualized: isVirtualized,
        onClose: props.onClose || triggerState?.close
    }, state, ref);
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        ...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, ($parcel$interopDefault($fDx7A$react))).createElement("div", {
        role: "menuitem",
        style: {
            display: 'contents'
        }
    }, props.renderEmptyState());
    let DOMProps = (0, $fDx7A$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $fDx7A$reactariaFocusScope.FocusScope), null, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.dom).div, {
        ...(0, $fDx7A$reactariamergeProps.mergeProps)(DOMProps, renderProps, menuProps),
        ref: ref,
        slot: props.slot || undefined,
        "data-empty": state.collection.size === 0 || undefined,
        onScroll: props.onScroll
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                $76f9e98b4261ab43$export$24aad8519b95b41b,
                state
            ],
            [
                (0, $5a1b0036f8cbf051$exports.SeparatorContext),
                {
                    elementType: 'div'
                }
            ],
            [
                (0, $f7b82bedbb70abac$exports.SectionContext),
                {
                    name: 'MenuSection',
                    render: $76f9e98b4261ab43$var$MenuSectionInner
                }
            ],
            [
                $76f9e98b4261ab43$var$SubmenuTriggerContext,
                {
                    parentMenuRef: ref,
                    shouldUseVirtualFocus: autocompleteMenuProps?.shouldUseVirtualFocus
                }
            ],
            [
                $76f9e98b4261ab43$var$MenuItemContext,
                {
                    shouldCloseOnSelect: props.shouldCloseOnSelect
                }
            ],
            [
                (0, $433949643203e332$exports.SelectableCollectionContext),
                null
            ],
            [
                (0, $433949643203e332$exports.FieldInputContext),
                null
            ],
            [
                $76f9e98b4261ab43$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 */ [
                $76f9e98b4261ab43$export$795aec4671cbae19,
                triggerState ?? (0, $fDx7A$reactstatelyuseMenuTriggerState.useMenuTriggerState)({})
            ]
        ]
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $9a60bd90621ebc78$exports.SharedElementTransition), null, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement(CollectionRoot, {
        collection: state.collection,
        persistedKeys: (0, $f7b82bedbb70abac$exports.usePersistedKeys)(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 $76f9e98b4261ab43$var$GroupSelectionManager extends (0, $fDx7A$reactstatelyprivateselectionSelectionManager.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 $76f9e98b4261ab43$var$MenuSectionInner(props, ref, section, className = 'react-aria-MenuSection') {
    let state = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$export$24aad8519b95b41b);
    let { CollectionBranch: CollectionBranch } = (0, $fDx7A$react.useContext)((0, $f7b82bedbb70abac$exports.CollectionRendererContext));
    let [headingRef, heading] = (0, $048d76b84370f141$exports.useSlot)();
    let { headingProps: headingProps, groupProps: groupProps } = (0, $fDx7A$reactariauseMenu.useMenuSection)({
        heading: heading,
        'aria-label': section.props['aria-label'] ?? undefined
    });
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        ...props,
        id: undefined,
        children: undefined,
        defaultClassName: className,
        className: section.props?.className,
        style: section.props?.style,
        values: undefined
    });
    let parent = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$var$SelectionManagerContext);
    let selectionState = (0, $fDx7A$reactstatelyuseMultipleSelectionState.useMultipleSelectionState)(props);
    let manager = props.selectionMode != null ? new $76f9e98b4261ab43$var$GroupSelectionManager(parent, selectionState) : parent;
    let closeOnSelect = (0, $048d76b84370f141$exports.useSlottedContext)($76f9e98b4261ab43$var$MenuItemContext)?.shouldCloseOnSelect;
    let DOMProps = (0, $fDx7A$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.dom).section, {
        ...(0, $fDx7A$reactariamergeProps.mergeProps)(DOMProps, renderProps, groupProps),
        ref: ref
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                (0, $749e1f015a6d7f1a$exports.HeaderContext),
                {
                    ...headingProps,
                    ref: headingRef
                }
            ],
            [
                $76f9e98b4261ab43$var$SelectionManagerContext,
                manager
            ],
            [
                $76f9e98b4261ab43$var$MenuItemContext,
                {
                    shouldCloseOnSelect: props.shouldCloseOnSelect ?? closeOnSelect
                }
            ]
        ]
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement(CollectionBranch, {
        collection: state.collection,
        parent: section
    })));
}
const $76f9e98b4261ab43$export$4b1545b4f2016d26 = /*#__PURE__*/ (0, $fDx7A$reactariaprivatecollectionsCollectionBuilder.createBranchComponent)((0, $fDx7A$reactariaprivatecollectionsBaseCollection.SectionNode), $76f9e98b4261ab43$var$MenuSectionInner);
const $76f9e98b4261ab43$var$MenuItemContext = /*#__PURE__*/ (0, $fDx7A$react.createContext)(null);
const $76f9e98b4261ab43$export$2ce376c2cc3355c8 = /*#__PURE__*/ (0, $fDx7A$reactariaprivatecollectionsCollectionBuilder.createLeafComponent)((0, $fDx7A$reactariaprivatecollectionsBaseCollection.ItemNode), function MenuItem(props, forwardedRef, item) {
    [props, forwardedRef] = (0, $048d76b84370f141$exports.useContextProps)(props, forwardedRef, $76f9e98b4261ab43$var$MenuItemContext);
    let id = (0, $048d76b84370f141$exports.useSlottedContext)($76f9e98b4261ab43$var$MenuItemContext)?.id;
    let state = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$export$24aad8519b95b41b);
    let ref = (0, $fDx7A$reactariauseObjectRef.useObjectRef)(forwardedRef);
    let selectionManager = (0, $fDx7A$react.useContext)($76f9e98b4261ab43$var$SelectionManagerContext);
    let { isVirtualized: isVirtualized } = (0, $fDx7A$react.useContext)((0, $f7b82bedbb70abac$exports.CollectionRendererContext));
    let { menuItemProps: menuItemProps, labelProps: labelProps, descriptionProps: descriptionProps, keyboardShortcutProps: keyboardShortcutProps, ...states } = (0, $fDx7A$reactariauseMenu.useMenuItem)({
        ...props,
        id: id,
        key: item.key,
        selectionManager: selectionManager,
        isVirtualized: isVirtualized
    }, state, ref);
    let { hoverProps: hoverProps, isHovered: isHovered } = (0, $fDx7A$reactariauseHover.useHover)({
        isDisabled: states.isDisabled
    });
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        ...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, $048d76b84370f141$exports.dom).a : (0, $048d76b84370f141$exports.dom).div;
    let DOMProps = (0, $fDx7A$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
        global: true
    });
    delete DOMProps.id;
    delete DOMProps.onClick;
    return /*#__PURE__*/ (0, ($parcel$interopDefault($fDx7A$react))).createElement(ElementType, {
        ...(0, $fDx7A$reactariamergeProps.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, ($parcel$interopDefault($fDx7A$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                (0, $cab7d9a238d19c33$exports.TextContext),
                {
                    slots: {
                        [(0, $048d76b84370f141$exports.DEFAULT_SLOT)]: labelProps,
                        label: labelProps,
                        description: descriptionProps
                    }
                }
            ],
            [
                (0, $557891271067a1da$exports.KeyboardContext),
                keyboardShortcutProps
            ],
            [
                (0, $61557b2a9b2862a8$exports.SelectionIndicatorContext),
                {
                    isSelected: states.isSelected
                }
            ]
        ]
    }, renderProps.children));
});


//# sourceMappingURL=Menu.cjs.map
