/** @license MIT | @cube-dev/ui-kit v0.142.7 | Cube Dev Team */
import { extractStyles } from "../utils/styles.js";
import { EventBusProvider } from "../utils/react/useEventBus.js";
import { PortalProvider } from "./portal/PortalProvider.js";
import { TASTY_VERSION, 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 { BASE_STYLES, BLOCK_STYLES, configure, filterBaseProps, setGlobalPredefinedStates, tasty } from "@tenphi/tasty";
import { useEffect, useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { ModalProvider } from "react-aria";

//#region src/components/Root.tsx
setGlobalPredefinedStates({
	"@dark": "@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))",
	"@hc": "@root(contrast=high) | (!@root(contrast) & @media(prefers-contrast: more))"
});
configure({
	colorSpace: "rgb",
	units: {
		x: "var(--gap)",
		r: "var(--radius)",
		cr: "var(--card-radius)",
		bw: "var(--border-width)",
		ow: "var(--outline-width)"
	},
	recipes: {
		reset: {
			margin: 0,
			padding: 0,
			border: 0,
			outline: 0,
			boxSizing: "border-box"
		},
		button: {
			appearance: "none",
			touchAction: "manipulation",
			textDecoration: "none",
			"-webkit-tap-highlight-color": "transparent",
			fill: "#clear",
			color: "inherit",
			cursor: {
				"": "default",
				":is(a)": "pointer",
				":is(button)": "$pointer",
				disabled: "not-allowed"
			}
		},
		input: {
			appearance: "none",
			wordSpacing: "initial",
			color: "inherit",
			fill: "#clear"
		},
		"input-autofill": {
			"@autofill": ":-webkit-autofill | :autofill",
			appearance: { "@autofill": "none" },
			"-webkit-text-fill-color": {
				"": "currentColor",
				"@autofill": "#primary-text"
			},
			caretColor: { "@autofill": "#primary-text" },
			shadow: { "@autofill": "0 0 0 9999rem #surface inset" },
			preset: { "@autofill": "inherit" },
			"-webkit-opacity": {
				"": false,
				"[disabled]": "1"
			}
		},
		"input-placeholder": {
			"-webkit-text-fill-color": "#placeholder",
			color: "#placeholder"
		},
		"input-search-cancel-button": {
			hide: true,
			appearance: "none"
		}
	}
});
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-uikit": VERSION,
				"data-tasty": 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