import {dom as $7230ffa83bc0c2cf$export$df3a06d6289f983e, Provider as $7230ffa83bc0c2cf$export$2881499e37b75b9a, useContextProps as $7230ffa83bc0c2cf$export$29f1550f4b0d4415, useRenderProps as $7230ffa83bc0c2cf$export$4d86445c2cf5e3} from "./utils.mjs";
import {OverlayTriggerStateContext as $f2ff30fde7b014be$export$d2f961adcb0afbe} from "./Dialog.mjs";
import {useModalOverlay as $gJBoF$useModalOverlay} from "react-aria/useModalOverlay";
import {Overlay as $gJBoF$Overlay, DismissButton as $gJBoF$DismissButton} from "react-aria/Overlay";
import {filterDOMProps as $gJBoF$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {isScrollable as $gJBoF$isScrollable} from "react-aria/private/utils/isScrollable";
import {mergeProps as $gJBoF$mergeProps} from "react-aria/mergeProps";
import {mergeRefs as $gJBoF$mergeRefs} from "react-aria/private/utils/mergeRefs";
import {useOverlayTriggerState as $gJBoF$useOverlayTriggerState} from "react-stately/useOverlayTriggerState";
import $gJBoF$react, {createContext as $gJBoF$createContext, forwardRef as $gJBoF$forwardRef, useContext as $gJBoF$useContext, useRef as $gJBoF$useRef, useMemo as $gJBoF$useMemo} from "react";
import {useExitAnimation as $gJBoF$useExitAnimation, useEnterAnimation as $gJBoF$useEnterAnimation} from "react-aria/private/utils/animation";
import {useIsSSR as $gJBoF$useIsSSR} from "react-aria/SSRProvider";
import {useObjectRef as $gJBoF$useObjectRef} from "react-aria/useObjectRef";
import {useViewportSize as $gJBoF$useViewportSize} from "react-aria/private/utils/useViewportSize";

/*
 * 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 $8b8d26808cb8cb53$export$ab57792b9b6974a6 = /*#__PURE__*/ (0, $gJBoF$createContext)(null);
const $8b8d26808cb8cb53$var$InternalModalContext = /*#__PURE__*/ (0, $gJBoF$createContext)(null);
const $8b8d26808cb8cb53$export$2b77a92f1a5ad772 = /*#__PURE__*/ (0, $gJBoF$forwardRef)(function Modal(props, ref) {
    let ctx = (0, $gJBoF$useContext)($8b8d26808cb8cb53$var$InternalModalContext);
    if (ctx) {
        if (process.env.NODE_ENV !== 'production' && (props.onOpenChange || props.defaultOpen !== undefined || props.isOpen !== undefined)) {
            // create a list of props that are passed in but not allowed when using an external ModalOverlay
            const invalidSet = new Set([
                'isDismissable',
                'isKeyboardDismissDisabled',
                'isOpen',
                'defaultOpen',
                'onOpenChange',
                'isEntering',
                'isExiting',
                'UNSTABLE_portalContainer',
                'shouldCloseOnInteractOutside'
            ]);
            const invalidProps = Object.keys(props).filter((key)=>invalidSet.has(key));
            console.warn(`This modal is already wrapped in a ModalOverlay, props [${invalidProps.join(', ')}] should be placed on the ModalOverlay instead.`);
        }
        return /*#__PURE__*/ (0, $gJBoF$react).createElement($8b8d26808cb8cb53$var$ModalContent, {
            ...props,
            modalRef: ref
        }, props.children);
    }
    let { isDismissable: isDismissable, isKeyboardDismissDisabled: isKeyboardDismissDisabled, isOpen: isOpen, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: children, isEntering: isEntering, isExiting: isExiting, UNSTABLE_portalContainer: UNSTABLE_portalContainer, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
    return /*#__PURE__*/ (0, $gJBoF$react).createElement($8b8d26808cb8cb53$export$8948f78d83984c69, {
        isDismissable: isDismissable,
        isKeyboardDismissDisabled: isKeyboardDismissDisabled,
        isOpen: isOpen,
        defaultOpen: defaultOpen,
        onOpenChange: onOpenChange,
        isEntering: isEntering,
        isExiting: isExiting,
        UNSTABLE_portalContainer: UNSTABLE_portalContainer,
        shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
    }, /*#__PURE__*/ (0, $gJBoF$react).createElement($8b8d26808cb8cb53$var$ModalContent, {
        ...otherProps,
        modalRef: ref
    }, children));
});
function $8b8d26808cb8cb53$var$ModalOverlayWithForwardRef(props, ref) {
    [props, ref] = (0, $7230ffa83bc0c2cf$export$29f1550f4b0d4415)(props, ref, $8b8d26808cb8cb53$export$ab57792b9b6974a6);
    let contextState = (0, $gJBoF$useContext)((0, $f2ff30fde7b014be$export$d2f961adcb0afbe));
    let localState = (0, $gJBoF$useOverlayTriggerState)(props);
    let state = props.isOpen != null || props.defaultOpen != null || !contextState ? localState : contextState;
    if (state === contextState) {
        if (process.env.NODE_ENV !== 'production' && (props.onOpenChange || props.defaultOpen !== undefined || props.isOpen !== undefined)) console.warn('This modals state is controlled by a trigger, place onOpenChange on the trigger instead.');
    }
    let objectRef = (0, $gJBoF$useObjectRef)(ref);
    let modalRef = (0, $gJBoF$useRef)(null);
    let isOverlayExiting = (0, $gJBoF$useExitAnimation)(objectRef, state.isOpen);
    let isModalExiting = (0, $gJBoF$useExitAnimation)(modalRef, state.isOpen);
    let isExiting = isOverlayExiting || isModalExiting || props.isExiting || false;
    let isSSR = (0, $gJBoF$useIsSSR)();
    if (!state.isOpen && !isExiting || isSSR) return null;
    return /*#__PURE__*/ (0, $gJBoF$react).createElement($8b8d26808cb8cb53$var$ModalOverlayInner, {
        ...props,
        state: state,
        isExiting: isExiting,
        overlayRef: objectRef,
        modalRef: modalRef
    });
}
const $8b8d26808cb8cb53$export$8948f78d83984c69 = /*#__PURE__*/ (0, $gJBoF$forwardRef)($8b8d26808cb8cb53$var$ModalOverlayWithForwardRef);
function $8b8d26808cb8cb53$var$ModalOverlayInner({ UNSTABLE_portalContainer: UNSTABLE_portalContainer, ...props }) {
    let modalRef = props.modalRef;
    let { state: state } = props;
    let { modalProps: modalProps, underlayProps: underlayProps } = (0, $gJBoF$useModalOverlay)(props, state, modalRef);
    let entering = (0, $gJBoF$useEnterAnimation)(props.overlayRef) || props.isEntering || false;
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        defaultClassName: 'react-aria-ModalOverlay',
        values: {
            isEntering: entering,
            isExiting: props.isExiting,
            state: state
        }
    });
    let viewport = (0, $gJBoF$useViewportSize)();
    let pageWidth = undefined;
    let pageHeight = undefined;
    if (typeof document !== 'undefined') {
        let scrollingElement = (0, $gJBoF$isScrollable)(document.body) ? document.body : document.scrollingElement || document.documentElement;
        // Prevent Firefox from adding scrollbars when the page has a fractional width/height.
        let fractionalWidthDifference = scrollingElement.getBoundingClientRect().width % 1;
        let fractionalHeightDifference = scrollingElement.getBoundingClientRect().height % 1;
        pageWidth = scrollingElement.scrollWidth - fractionalWidthDifference;
        pageHeight = scrollingElement.scrollHeight - fractionalHeightDifference;
    }
    let style = {
        ...renderProps.style,
        '--visual-viewport-width': viewport.width + 'px',
        '--visual-viewport-height': viewport.height + 'px',
        '--page-width': pageWidth !== undefined ? pageWidth + 'px' : undefined,
        '--page-height': pageHeight !== undefined ? pageHeight + 'px' : undefined
    };
    return /*#__PURE__*/ (0, $gJBoF$react).createElement((0, $gJBoF$Overlay), {
        isExiting: props.isExiting,
        portalContainer: UNSTABLE_portalContainer
    }, /*#__PURE__*/ (0, $gJBoF$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        ...(0, $gJBoF$mergeProps)((0, $gJBoF$filterDOMProps)(props, {
            global: true
        }), underlayProps),
        ...renderProps,
        style: style,
        ref: props.overlayRef,
        "data-entering": entering || undefined,
        "data-exiting": props.isExiting || undefined
    }, /*#__PURE__*/ (0, $gJBoF$react).createElement((0, $7230ffa83bc0c2cf$export$2881499e37b75b9a), {
        values: [
            [
                $8b8d26808cb8cb53$var$InternalModalContext,
                {
                    modalProps: modalProps,
                    modalRef: modalRef,
                    isExiting: props.isExiting,
                    isDismissable: props.isDismissable
                }
            ],
            [
                (0, $f2ff30fde7b014be$export$d2f961adcb0afbe),
                state
            ]
        ]
    }, renderProps.children)));
}
function $8b8d26808cb8cb53$var$ModalContent(props) {
    let { modalProps: modalProps, modalRef: modalRef, isExiting: isExiting, isDismissable: isDismissable } = (0, $gJBoF$useContext)($8b8d26808cb8cb53$var$InternalModalContext);
    let state = (0, $gJBoF$useContext)((0, $f2ff30fde7b014be$export$d2f961adcb0afbe));
    let mergedRefs = (0, $gJBoF$useMemo)(()=>(0, $gJBoF$mergeRefs)(props.modalRef, modalRef), [
        props.modalRef,
        modalRef
    ]);
    let ref = (0, $gJBoF$useObjectRef)(mergedRefs);
    let entering = (0, $gJBoF$useEnterAnimation)(ref);
    let renderProps = (0, $7230ffa83bc0c2cf$export$4d86445c2cf5e3)({
        ...props,
        defaultClassName: 'react-aria-Modal',
        values: {
            isEntering: entering,
            isExiting: isExiting,
            state: state
        }
    });
    return /*#__PURE__*/ (0, $gJBoF$react).createElement((0, $7230ffa83bc0c2cf$export$df3a06d6289f983e).div, {
        ...(0, $gJBoF$mergeProps)((0, $gJBoF$filterDOMProps)(props, {
            global: true
        }), modalProps),
        ...renderProps,
        ref: ref,
        "data-entering": entering || undefined,
        "data-exiting": isExiting || undefined
    }, isDismissable && /*#__PURE__*/ (0, $gJBoF$react).createElement((0, $gJBoF$DismissButton), {
        onDismiss: state.close
    }), renderProps.children);
}


export {$8b8d26808cb8cb53$export$ab57792b9b6974a6 as ModalContext, $8b8d26808cb8cb53$export$2b77a92f1a5ad772 as Modal, $8b8d26808cb8cb53$export$8948f78d83984c69 as ModalOverlay};
//# sourceMappingURL=Modal.mjs.map
