import {dom as $b7b7a92703138c9b$export$df3a06d6289f983e, Provider as $b7b7a92703138c9b$export$2881499e37b75b9a, useContextProps as $b7b7a92703138c9b$export$29f1550f4b0d4415, useRenderProps as $b7b7a92703138c9b$export$4d86445c2cf5e3} from "./utils.js";
import {OverlayTriggerStateContext as $acf8e70c2f419f18$export$d2f961adcb0afbe} from "./Dialog.js";
import {useModalOverlay as $auKl7$useModalOverlay} from "react-aria/useModalOverlay";
import {Overlay as $auKl7$Overlay, DismissButton as $auKl7$DismissButton} from "react-aria/Overlay";
import {filterDOMProps as $auKl7$filterDOMProps} from "react-aria/private/utils/filterDOMProps";
import {isScrollable as $auKl7$isScrollable} from "react-aria/private/utils/isScrollable";
import {mergeProps as $auKl7$mergeProps} from "react-aria/mergeProps";
import {mergeRefs as $auKl7$mergeRefs} from "react-aria/private/utils/mergeRefs";
import {useOverlayTriggerState as $auKl7$useOverlayTriggerState} from "react-stately/useOverlayTriggerState";
import $auKl7$react, {createContext as $auKl7$createContext, forwardRef as $auKl7$forwardRef, useContext as $auKl7$useContext, useRef as $auKl7$useRef, useMemo as $auKl7$useMemo} from "react";
import {useExitAnimation as $auKl7$useExitAnimation, useEnterAnimation as $auKl7$useEnterAnimation} from "react-aria/private/utils/animation";
import {useIsSSR as $auKl7$useIsSSR} from "react-aria/SSRProvider";
import {useObjectRef as $auKl7$useObjectRef} from "react-aria/useObjectRef";
import {useViewportSize as $auKl7$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 $46ccb41fa2c44f44$export$ab57792b9b6974a6 = /*#__PURE__*/ (0, $auKl7$createContext)(null);
const $46ccb41fa2c44f44$var$InternalModalContext = /*#__PURE__*/ (0, $auKl7$createContext)(null);
const $46ccb41fa2c44f44$export$2b77a92f1a5ad772 = /*#__PURE__*/ (0, $auKl7$forwardRef)(function Modal(props, ref) {
    let ctx = (0, $auKl7$useContext)($46ccb41fa2c44f44$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, $auKl7$react).createElement($46ccb41fa2c44f44$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, $auKl7$react).createElement($46ccb41fa2c44f44$export$8948f78d83984c69, {
        isDismissable: isDismissable,
        isKeyboardDismissDisabled: isKeyboardDismissDisabled,
        isOpen: isOpen,
        defaultOpen: defaultOpen,
        onOpenChange: onOpenChange,
        isEntering: isEntering,
        isExiting: isExiting,
        UNSTABLE_portalContainer: UNSTABLE_portalContainer,
        shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
    }, /*#__PURE__*/ (0, $auKl7$react).createElement($46ccb41fa2c44f44$var$ModalContent, {
        ...otherProps,
        modalRef: ref
    }, children));
});
function $46ccb41fa2c44f44$var$ModalOverlayWithForwardRef(props, ref) {
    [props, ref] = (0, $b7b7a92703138c9b$export$29f1550f4b0d4415)(props, ref, $46ccb41fa2c44f44$export$ab57792b9b6974a6);
    let contextState = (0, $auKl7$useContext)((0, $acf8e70c2f419f18$export$d2f961adcb0afbe));
    let localState = (0, $auKl7$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, $auKl7$useObjectRef)(ref);
    let modalRef = (0, $auKl7$useRef)(null);
    let isOverlayExiting = (0, $auKl7$useExitAnimation)(objectRef, state.isOpen);
    let isModalExiting = (0, $auKl7$useExitAnimation)(modalRef, state.isOpen);
    let isExiting = isOverlayExiting || isModalExiting || props.isExiting || false;
    let isSSR = (0, $auKl7$useIsSSR)();
    if (!state.isOpen && !isExiting || isSSR) return null;
    return /*#__PURE__*/ (0, $auKl7$react).createElement($46ccb41fa2c44f44$var$ModalOverlayInner, {
        ...props,
        state: state,
        isExiting: isExiting,
        overlayRef: objectRef,
        modalRef: modalRef
    });
}
const $46ccb41fa2c44f44$export$8948f78d83984c69 = /*#__PURE__*/ (0, $auKl7$forwardRef)($46ccb41fa2c44f44$var$ModalOverlayWithForwardRef);
function $46ccb41fa2c44f44$var$ModalOverlayInner({ UNSTABLE_portalContainer: UNSTABLE_portalContainer, ...props }) {
    let modalRef = props.modalRef;
    let { state: state } = props;
    let { modalProps: modalProps, underlayProps: underlayProps } = (0, $auKl7$useModalOverlay)(props, state, modalRef);
    let entering = (0, $auKl7$useEnterAnimation)(props.overlayRef) || props.isEntering || false;
    let renderProps = (0, $b7b7a92703138c9b$export$4d86445c2cf5e3)({
        ...props,
        defaultClassName: 'react-aria-ModalOverlay',
        values: {
            isEntering: entering,
            isExiting: props.isExiting,
            state: state
        }
    });
    let viewport = (0, $auKl7$useViewportSize)();
    let pageWidth = undefined;
    let pageHeight = undefined;
    if (typeof document !== 'undefined') {
        let scrollingElement = (0, $auKl7$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, $auKl7$react).createElement((0, $auKl7$Overlay), {
        isExiting: props.isExiting,
        portalContainer: UNSTABLE_portalContainer
    }, /*#__PURE__*/ (0, $auKl7$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        ...(0, $auKl7$mergeProps)((0, $auKl7$filterDOMProps)(props, {
            global: true
        }), underlayProps),
        ...renderProps,
        style: style,
        ref: props.overlayRef,
        "data-entering": entering || undefined,
        "data-exiting": props.isExiting || undefined
    }, /*#__PURE__*/ (0, $auKl7$react).createElement((0, $b7b7a92703138c9b$export$2881499e37b75b9a), {
        values: [
            [
                $46ccb41fa2c44f44$var$InternalModalContext,
                {
                    modalProps: modalProps,
                    modalRef: modalRef,
                    isExiting: props.isExiting,
                    isDismissable: props.isDismissable
                }
            ],
            [
                (0, $acf8e70c2f419f18$export$d2f961adcb0afbe),
                state
            ]
        ]
    }, renderProps.children)));
}
function $46ccb41fa2c44f44$var$ModalContent(props) {
    let { modalProps: modalProps, modalRef: modalRef, isExiting: isExiting, isDismissable: isDismissable } = (0, $auKl7$useContext)($46ccb41fa2c44f44$var$InternalModalContext);
    let state = (0, $auKl7$useContext)((0, $acf8e70c2f419f18$export$d2f961adcb0afbe));
    let mergedRefs = (0, $auKl7$useMemo)(()=>(0, $auKl7$mergeRefs)(props.modalRef, modalRef), [
        props.modalRef,
        modalRef
    ]);
    let ref = (0, $auKl7$useObjectRef)(mergedRefs);
    let entering = (0, $auKl7$useEnterAnimation)(ref);
    let renderProps = (0, $b7b7a92703138c9b$export$4d86445c2cf5e3)({
        ...props,
        defaultClassName: 'react-aria-Modal',
        values: {
            isEntering: entering,
            isExiting: isExiting,
            state: state
        }
    });
    return /*#__PURE__*/ (0, $auKl7$react).createElement((0, $b7b7a92703138c9b$export$df3a06d6289f983e).div, {
        ...(0, $auKl7$mergeProps)((0, $auKl7$filterDOMProps)(props, {
            global: true
        }), modalProps),
        ...renderProps,
        ref: ref,
        "data-entering": entering || undefined,
        "data-exiting": isExiting || undefined
    }, isDismissable && /*#__PURE__*/ (0, $auKl7$react).createElement((0, $auKl7$DismissButton), {
        onDismiss: state.close
    }), renderProps.children);
}


export {$46ccb41fa2c44f44$export$ab57792b9b6974a6 as ModalContext, $46ccb41fa2c44f44$export$2b77a92f1a5ad772 as Modal, $46ccb41fa2c44f44$export$8948f78d83984c69 as ModalOverlay};
//# sourceMappingURL=Modal.js.map
