/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-b859c78 | Cube Dev Team */
import { extractStyles } from "../tasty/utils/styles.js";
import { BASE_STYLES, BLOCK_STYLES } from "../tasty/styles/list.js";
import { tasty } from "../tasty/tasty.js";
import { filterBaseProps } from "../tasty/utils/filter-base-props.js";
import { EventBusProvider } from "../utils/react/useEventBus.js";
import { PortalProvider } from "./portal/PortalProvider.js";
import { VERSION } from "../version.js";
import { Provider } from "../provider.js";
import { TrackingProvider } from "../providers/TrackingProvider.js";
import { GlobalStyles } from "./GlobalStyles.js";
import { AlertDialogApiProvider } from "./overlays/AlertDialog/AlertDialogApiProvider.js";
import { OverlayProvider } from "./overlays/Notifications/OverlayProvider.js";
import { useEffect, useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { ModalProvider } from "react-aria";

//#region src/components/Root.tsx
const RootElement = tasty({
	id: "cube-ui-kit-root",
	styles: {
		display: "contents",
		color: "#dark-02",
		preset: "t3"
	}
});
const STYLES = [...BASE_STYLES, ...BLOCK_STYLES];
function Root(allProps) {
	let { children, bodyStyles, fontDisplay = "swap", fonts, publicUrl, navigation, font, monospaceFont, applyLegacyTokens: _applyLegacyTokens, tracking, cursorStrategy = "web", style, tokens, ...props } = allProps;
	const ref = useRef(null);
	const [rootRef, setRootRef] = useState();
	useEffect(() => {
		if (!rootRef) setRootRef(ref?.current);
	}, []);
	const styles = extractStyles(props, STYLES);
	return /* @__PURE__ */ jsx(Provider, {
		navigation,
		root: rootRef,
		children: /* @__PURE__ */ jsx(TrackingProvider, {
			event: tracking?.event,
			children: /* @__PURE__ */ jsxs(RootElement, {
				ref,
				"data-tasty": VERSION,
				"data-font-display": fontDisplay,
				...filterBaseProps(props, { eventProps: true }),
				styles,
				style: {
					"--pointer": cursorStrategy === "web" ? "pointer" : "default",
					...style
				},
				tokens,
				children: [/* @__PURE__ */ jsx(GlobalStyles, {
					bodyStyles,
					publicUrl,
					fonts,
					font,
					monospaceFont,
					fontDisplay
				}), /* @__PURE__ */ jsx(ModalProvider, { children: /* @__PURE__ */ jsx(PortalProvider, {
					value: ref,
					children: /* @__PURE__ */ jsx(EventBusProvider, { children: /* @__PURE__ */ jsx(OverlayProvider, { children: /* @__PURE__ */ jsx(AlertDialogApiProvider, { children }) }) })
				}) })]
			})
		})
	});
}

//#endregion
export { Root };
//# sourceMappingURL=Root.js.map