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

import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useRef, useState } from 'react';
import { ModalProvider } from 'react-aria';
import { Provider } from '../provider.js';
import { TrackingProvider } from '../providers/TrackingProvider.js';
import { BASE_STYLES, BLOCK_STYLES, extractStyles, filterBaseProps, tasty, } from '../tasty/index.js';
import { EventBusProvider } from '../utils/react/useEventBus.js';
import { VERSION } from '../version.js';
import { GlobalStyles } from './GlobalStyles.js';
import { AlertDialogApiProvider } from './overlays/AlertDialog/index.js';
import { NotificationsProvider } from './overlays/NewNotifications/NotificationsContext/NotificationsProvider.js';
import { ToastProvider } from './overlays/Toast/index.js';
import { PortalProvider } from './portal/index.js';
const RootElement = tasty({
    id: 'cube-ui-kit-root',
    styles: {
        display: 'contents',
        color: '#dark-02',
        preset: 't3',
    },
});
const STYLES = [...BASE_STYLES, ...BLOCK_STYLES];
export function Root(allProps) {
    let { children, 
    /** Raw css styles for body element */
    bodyStyles, fontDisplay = 'swap', fonts, publicUrl, navigation, font, monospaceFont, applyLegacyTokens: _applyLegacyTokens, // deprecated, ignored
    tracking, cursorStrategy = 'web', style, tokens, ...props } = allProps;
    const ref = useRef(null);
    const [rootRef, setRootRef] = useState();
    useEffect(() => {
        if (!rootRef) {
            // @ts-ignore
            setRootRef(ref?.current);
        }
    }, []);
    const styles = extractStyles(props, STYLES);
    return (_jsx(Provider, { navigation: navigation, root: rootRef, children: _jsx(TrackingProvider, { event: tracking?.event, children: _jsxs(RootElement, { ref: ref, "data-tasty": VERSION, "data-font-display": fontDisplay, ...filterBaseProps(props, { eventProps: true }), styles: styles, style: {
                    '--pointer': cursorStrategy === 'web' ? 'pointer' : 'default',
                    ...style,
                }, tokens: tokens, children: [_jsx(GlobalStyles, { bodyStyles: bodyStyles, publicUrl: publicUrl, fonts: fonts, font: font, monospaceFont: monospaceFont, fontDisplay: fontDisplay }), _jsx(ModalProvider, { children: _jsx(PortalProvider, { value: ref, children: _jsx(EventBusProvider, { children: _jsx(NotificationsProvider, { rootRef: ref, children: _jsx(ToastProvider, { children: _jsx(AlertDialogApiProvider, { children: children }) }) }) }) }) })] }) }) }));
}

        