var $16c7f9b22cce3838$exports = require("./Button.cjs");
var $048d76b84370f141$exports = require("./utils.cjs");
var $03e8b4fd5e44cde9$exports = require("./Heading.cjs");
var $74e35a768d38d46b$exports = require("./Popover.cjs");
var $76f9e98b4261ab43$exports = require("./Menu.cjs");
var $kcsOx$reactariauseDialog = require("react-aria/useDialog");
var $kcsOx$reactariaprivateutilsfilterDOMProps = require("react-aria/private/utils/filterDOMProps");
var $kcsOx$reactariamergeProps = require("react-aria/mergeProps");
var $kcsOx$reactariaprivateinteractionsPressResponder = require("react-aria/private/interactions/PressResponder");
var $kcsOx$react = require("react");
var $kcsOx$reactariauseId = require("react-aria/useId");
var $kcsOx$reactstatelyuseMenuTriggerState = require("react-stately/useMenuTriggerState");
var $kcsOx$reactariauseOverlayTrigger = require("react-aria/useOverlayTrigger");
var $kcsOx$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, "DialogContext", function () { return $88595bf043e542ec$export$8b93a07348a7730c; });
$parcel$export(module.exports, "OverlayTriggerStateContext", function () { return $88595bf043e542ec$export$d2f961adcb0afbe; });
$parcel$export(module.exports, "DialogTrigger", function () { return $88595bf043e542ec$export$2e1e1122cf0cba88; });
$parcel$export(module.exports, "Dialog", function () { return $88595bf043e542ec$export$3ddf2d174ce01153; });
/*
 * 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 $88595bf043e542ec$export$8b93a07348a7730c = /*#__PURE__*/ (0, $kcsOx$react.createContext)(null);
const $88595bf043e542ec$export$d2f961adcb0afbe = /*#__PURE__*/ (0, $kcsOx$react.createContext)(null);
function $88595bf043e542ec$export$2e1e1122cf0cba88(props) {
    // Use useMenuTriggerState instead of useOverlayTriggerState in case a menu is embedded in the dialog.
    // This is needed to handle submenus.
    let state = (0, $kcsOx$reactstatelyuseMenuTriggerState.useMenuTriggerState)(props);
    let buttonRef = (0, $kcsOx$react.useRef)(null);
    let { triggerProps: triggerProps, overlayProps: overlayProps } = (0, $kcsOx$reactariauseOverlayTrigger.useOverlayTrigger)({
        type: 'dialog'
    }, state, buttonRef);
    // Allows popover width to match trigger element
    let [buttonWidth, setButtonWidth] = (0, $kcsOx$react.useState)(null);
    let onResize = (0, $kcsOx$react.useCallback)(()=>{
        if (buttonRef.current) setButtonWidth(buttonRef.current.offsetWidth + 'px');
    }, [
        buttonRef
    ]);
    (0, $kcsOx$reactariaprivateutilsuseResizeObserver.useResizeObserver)({
        ref: buttonRef,
        onResize: onResize
    });
    // Label dialog by the trigger as a fallback if there is no title slot.
    // This is done in RAC instead of hooks because otherwise we cannot distinguish
    // between context and props. Normally aria-labelledby overrides the title
    // but when sent by context we want the title to win.
    triggerProps.id = (0, $kcsOx$reactariauseId.useId)();
    overlayProps['aria-labelledby'] = triggerProps.id;
    return /*#__PURE__*/ (0, ($parcel$interopDefault($kcsOx$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                $88595bf043e542ec$export$d2f961adcb0afbe,
                state
            ],
            [
                (0, $76f9e98b4261ab43$exports.RootMenuTriggerStateContext),
                state
            ],
            [
                $88595bf043e542ec$export$8b93a07348a7730c,
                overlayProps
            ],
            [
                (0, $74e35a768d38d46b$exports.PopoverContext),
                {
                    trigger: 'DialogTrigger',
                    triggerRef: buttonRef,
                    'aria-labelledby': overlayProps['aria-labelledby'],
                    style: {
                        '--trigger-width': buttonWidth
                    }
                }
            ]
        ]
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($kcsOx$react))).createElement((0, $kcsOx$reactariaprivateinteractionsPressResponder.PressResponder), {
        ...triggerProps,
        ref: buttonRef,
        isPressed: state.isOpen
    }, props.children));
}
const $88595bf043e542ec$export$3ddf2d174ce01153 = /*#__PURE__*/ (0, $kcsOx$react.forwardRef)(function Dialog(props, ref) {
    let originalAriaLabelledby = props['aria-labelledby'];
    [props, ref] = (0, $048d76b84370f141$exports.useContextProps)(props, ref, $88595bf043e542ec$export$8b93a07348a7730c);
    let { dialogProps: dialogProps, titleProps: titleProps } = (0, $kcsOx$reactariauseDialog.useDialog)({
        ...props,
        // Only pass aria-labelledby from props, not context.
        // Context is used as a fallback below.
        'aria-labelledby': originalAriaLabelledby
    }, ref);
    let state = (0, $kcsOx$react.useContext)($88595bf043e542ec$export$d2f961adcb0afbe);
    if (!dialogProps['aria-label'] && !dialogProps['aria-labelledby']) {
        // If aria-labelledby exists on props, we know it came from context.
        // Use that as a fallback in case there is no title slot.
        if (props['aria-labelledby']) dialogProps['aria-labelledby'] = props['aria-labelledby'];
        else if (process.env.NODE_ENV !== 'production') console.warn('If a Dialog does not contain a <Heading slot="title">, it must have an aria-label or aria-labelledby attribute for accessibility.');
    }
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        defaultClassName: 'react-aria-Dialog',
        className: props.className,
        style: props.style,
        children: props.children,
        values: {
            close: state?.close || (()=>{})
        }
    });
    let DOMProps = (0, $kcsOx$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
        global: true
    });
    return /*#__PURE__*/ (0, ($parcel$interopDefault($kcsOx$react))).createElement((0, $048d76b84370f141$exports.dom).section, {
        ...(0, $kcsOx$reactariamergeProps.mergeProps)(DOMProps, renderProps, dialogProps),
        render: props.render,
        ref: ref,
        slot: props.slot || undefined
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($kcsOx$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                (0, $03e8b4fd5e44cde9$exports.HeadingContext),
                {
                    slots: {
                        [(0, $048d76b84370f141$exports.DEFAULT_SLOT)]: {},
                        title: {
                            ...titleProps,
                            level: 2
                        }
                    }
                }
            ],
            [
                (0, $16c7f9b22cce3838$exports.ButtonContext),
                {
                    slots: {
                        [(0, $048d76b84370f141$exports.DEFAULT_SLOT)]: {},
                        close: {
                            onPress: ()=>state?.close()
                        }
                    }
                }
            ]
        ]
    }, renderProps.children));
});


//# sourceMappingURL=Dialog.cjs.map
