var $048d76b84370f141$exports = require("./utils.cjs");
var $88595bf043e542ec$exports = require("./Dialog.cjs");
var $iQHtX$reactariauseModalOverlay = require("react-aria/useModalOverlay");
var $iQHtX$reactariaOverlay = require("react-aria/Overlay");
var $iQHtX$reactariaprivateutilsfilterDOMProps = require("react-aria/private/utils/filterDOMProps");
var $iQHtX$reactariaprivateutilsisScrollable = require("react-aria/private/utils/isScrollable");
var $iQHtX$reactariamergeProps = require("react-aria/mergeProps");
var $iQHtX$reactariaprivateutilsmergeRefs = require("react-aria/private/utils/mergeRefs");
var $iQHtX$reactstatelyuseOverlayTriggerState = require("react-stately/useOverlayTriggerState");
var $iQHtX$react = require("react");
var $iQHtX$reactariaprivateutilsanimation = require("react-aria/private/utils/animation");
var $iQHtX$reactariaSSRProvider = require("react-aria/SSRProvider");
var $iQHtX$reactariauseObjectRef = require("react-aria/useObjectRef");
var $iQHtX$reactariaprivateutilsuseViewportSize = require("react-aria/private/utils/useViewportSize");


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, "ModalContext", function () { return $ea54fd2c37e7023d$export$ab57792b9b6974a6; });
$parcel$export(module.exports, "Modal", function () { return $ea54fd2c37e7023d$export$2b77a92f1a5ad772; });
$parcel$export(module.exports, "ModalOverlay", function () { return $ea54fd2c37e7023d$export$8948f78d83984c69; });
/*
 * 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 $ea54fd2c37e7023d$export$ab57792b9b6974a6 = /*#__PURE__*/ (0, $iQHtX$react.createContext)(null);
const $ea54fd2c37e7023d$var$InternalModalContext = /*#__PURE__*/ (0, $iQHtX$react.createContext)(null);
const $ea54fd2c37e7023d$export$2b77a92f1a5ad772 = /*#__PURE__*/ (0, $iQHtX$react.forwardRef)(function Modal(props, ref) {
    let ctx = (0, $iQHtX$react.useContext)($ea54fd2c37e7023d$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, ($parcel$interopDefault($iQHtX$react))).createElement($ea54fd2c37e7023d$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, ($parcel$interopDefault($iQHtX$react))).createElement($ea54fd2c37e7023d$export$8948f78d83984c69, {
        isDismissable: isDismissable,
        isKeyboardDismissDisabled: isKeyboardDismissDisabled,
        isOpen: isOpen,
        defaultOpen: defaultOpen,
        onOpenChange: onOpenChange,
        isEntering: isEntering,
        isExiting: isExiting,
        UNSTABLE_portalContainer: UNSTABLE_portalContainer,
        shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement($ea54fd2c37e7023d$var$ModalContent, {
        ...otherProps,
        modalRef: ref
    }, children));
});
function $ea54fd2c37e7023d$var$ModalOverlayWithForwardRef(props, ref) {
    [props, ref] = (0, $048d76b84370f141$exports.useContextProps)(props, ref, $ea54fd2c37e7023d$export$ab57792b9b6974a6);
    let contextState = (0, $iQHtX$react.useContext)((0, $88595bf043e542ec$exports.OverlayTriggerStateContext));
    let localState = (0, $iQHtX$reactstatelyuseOverlayTriggerState.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, $iQHtX$reactariauseObjectRef.useObjectRef)(ref);
    let modalRef = (0, $iQHtX$react.useRef)(null);
    let isOverlayExiting = (0, $iQHtX$reactariaprivateutilsanimation.useExitAnimation)(objectRef, state.isOpen);
    let isModalExiting = (0, $iQHtX$reactariaprivateutilsanimation.useExitAnimation)(modalRef, state.isOpen);
    let isExiting = isOverlayExiting || isModalExiting || props.isExiting || false;
    let isSSR = (0, $iQHtX$reactariaSSRProvider.useIsSSR)();
    if (!state.isOpen && !isExiting || isSSR) return null;
    return /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement($ea54fd2c37e7023d$var$ModalOverlayInner, {
        ...props,
        state: state,
        isExiting: isExiting,
        overlayRef: objectRef,
        modalRef: modalRef
    });
}
const $ea54fd2c37e7023d$export$8948f78d83984c69 = /*#__PURE__*/ (0, $iQHtX$react.forwardRef)($ea54fd2c37e7023d$var$ModalOverlayWithForwardRef);
function $ea54fd2c37e7023d$var$ModalOverlayInner({ UNSTABLE_portalContainer: UNSTABLE_portalContainer, ...props }) {
    let modalRef = props.modalRef;
    let { state: state } = props;
    let { modalProps: modalProps, underlayProps: underlayProps } = (0, $iQHtX$reactariauseModalOverlay.useModalOverlay)(props, state, modalRef);
    let entering = (0, $iQHtX$reactariaprivateutilsanimation.useEnterAnimation)(props.overlayRef) || props.isEntering || false;
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        ...props,
        defaultClassName: 'react-aria-ModalOverlay',
        values: {
            isEntering: entering,
            isExiting: props.isExiting,
            state: state
        }
    });
    let viewport = (0, $iQHtX$reactariaprivateutilsuseViewportSize.useViewportSize)();
    let pageWidth = undefined;
    let pageHeight = undefined;
    if (typeof document !== 'undefined') {
        let scrollingElement = (0, $iQHtX$reactariaprivateutilsisScrollable.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, ($parcel$interopDefault($iQHtX$react))).createElement((0, $iQHtX$reactariaOverlay.Overlay), {
        isExiting: props.isExiting,
        portalContainer: UNSTABLE_portalContainer
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement((0, $048d76b84370f141$exports.dom).div, {
        ...(0, $iQHtX$reactariamergeProps.mergeProps)((0, $iQHtX$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
            global: true
        }), underlayProps),
        ...renderProps,
        style: style,
        ref: props.overlayRef,
        "data-entering": entering || undefined,
        "data-exiting": props.isExiting || undefined
    }, /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement((0, $048d76b84370f141$exports.Provider), {
        values: [
            [
                $ea54fd2c37e7023d$var$InternalModalContext,
                {
                    modalProps: modalProps,
                    modalRef: modalRef,
                    isExiting: props.isExiting,
                    isDismissable: props.isDismissable
                }
            ],
            [
                (0, $88595bf043e542ec$exports.OverlayTriggerStateContext),
                state
            ]
        ]
    }, renderProps.children)));
}
function $ea54fd2c37e7023d$var$ModalContent(props) {
    let { modalProps: modalProps, modalRef: modalRef, isExiting: isExiting, isDismissable: isDismissable } = (0, $iQHtX$react.useContext)($ea54fd2c37e7023d$var$InternalModalContext);
    let state = (0, $iQHtX$react.useContext)((0, $88595bf043e542ec$exports.OverlayTriggerStateContext));
    let mergedRefs = (0, $iQHtX$react.useMemo)(()=>(0, $iQHtX$reactariaprivateutilsmergeRefs.mergeRefs)(props.modalRef, modalRef), [
        props.modalRef,
        modalRef
    ]);
    let ref = (0, $iQHtX$reactariauseObjectRef.useObjectRef)(mergedRefs);
    let entering = (0, $iQHtX$reactariaprivateutilsanimation.useEnterAnimation)(ref);
    let renderProps = (0, $048d76b84370f141$exports.useRenderProps)({
        ...props,
        defaultClassName: 'react-aria-Modal',
        values: {
            isEntering: entering,
            isExiting: isExiting,
            state: state
        }
    });
    return /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement((0, $048d76b84370f141$exports.dom).div, {
        ...(0, $iQHtX$reactariamergeProps.mergeProps)((0, $iQHtX$reactariaprivateutilsfilterDOMProps.filterDOMProps)(props, {
            global: true
        }), modalProps),
        ...renderProps,
        ref: ref,
        "data-entering": entering || undefined,
        "data-exiting": isExiting || undefined
    }, isDismissable && /*#__PURE__*/ (0, ($parcel$interopDefault($iQHtX$react))).createElement((0, $iQHtX$reactariaOverlay.DismissButton), {
        onDismiss: state.close
    }), renderProps.children);
}


//# sourceMappingURL=Modal.cjs.map
