/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-b46ab85
 * Released under the MIT license.
 */

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useDOMRef } from '@react-spectrum/utils';
import { forwardRef } from 'react';
import { useModal, useOverlay, usePreventScroll, } from 'react-aria';
import { tasty } from '../../../tasty/index.js';
import { mergeProps } from '../../../utils/react/index.js';
import { OVERLAY_WRAPPER_STYLES } from './Modal.js';
import { Overlay } from './Overlay.js';
import { Underlay } from './Underlay.js';
const TrayWrapperElement = tasty({
    qa: 'TrayWrapper',
    styles: {
        ...OVERLAY_WRAPPER_STYLES,
        placeContent: 'end center',
        placeItems: 'end center',
    },
});
const TrayElement = tasty({
    styles: {
        display: {
            '': 'none',
            'entering | entered': 'initial',
            exiting: 'initial',
            exited: 'none',
        },
        zIndex: 10,
        height: 'max 90dvh',
        width: '$min-dialog-size 90vw',
        pointerEvents: 'auto',
        transition: 'transform .25s ease-in-out, opacity .25s linear, visibility 0ms linear',
        opacity: {
            '': 0,
            open: '.9999',
        },
    },
});
function Tray(props, ref) {
    let { qa, children, onClose, isFixedHeight, isNonModal, styles, ...otherProps } = props;
    let domRef = useDOMRef(ref);
    let { overlayProps, underlayProps } = useOverlay({ ...props, isDismissable: true }, domRef);
    return (_jsxs(Overlay, { ...otherProps, children: [_jsx(Underlay, { ...underlayProps }), _jsx(TrayWrapper, { ref: domRef, qa: qa, overlayProps: overlayProps, isFixedHeight: isFixedHeight, isNonModal: isNonModal, styles: styles, onClose: onClose, children: children })] }));
}
let TrayWrapper = forwardRef(function TrayWrapper(props, ref) {
    let { qa, children, isOpen, styles, isFixedHeight, isNonModal, overlayProps, transitionState, ...otherProps } = props;
    usePreventScroll();
    let { modalProps } = useModal({
        isDisabled: isNonModal,
    });
    let domProps = mergeProps(otherProps, overlayProps);
    return (_jsx(TrayWrapperElement, { mods: {
            open: isOpen,
        }, children: _jsx(TrayElement, { qa: qa || 'Tray', styles: styles, mods: {
                open: isOpen,
                entering: transitionState === 'entering',
                exiting: transitionState === 'exiting',
                exited: transitionState === 'exited',
                entered: transitionState === 'entered',
                'fixed-height': isFixedHeight,
            }, ...domProps, ...modalProps, ref: ref, children: children }) }));
});
let _Tray = forwardRef(Tray);
_Tray.displayName = 'Tray';
export { _Tray as Tray };

        