"use client";
const require_noop = require("../../utils/noop/noop.cjs");
const require_Mantine_context = require("../Mantine.context.cjs");
let react = require("react");
let _mantine_hooks = require("@mantine/hooks");
//#region packages/@mantine/core/src/core/MantineProvider/use-mantine-color-scheme/use-mantine-color-scheme.ts
function disableTransition(nonce) {
	const style = document.createElement("style");
	style.setAttribute("data-mantine-styles", "inline");
	style.innerHTML = "*, *::before, *::after {transition: none !important;}";
	style.setAttribute("data-mantine-disable-transition", "true");
	nonce && style.setAttribute("nonce", nonce);
	document.head.appendChild(style);
	const clear = () => document.querySelectorAll("[data-mantine-disable-transition]").forEach((element) => element.remove());
	return clear;
}
function useMantineColorScheme({ keepTransitions } = {}) {
	const clearStylesRef = (0, react.useRef)(require_noop.noop);
	const timeoutRef = (0, react.useRef)(-1);
	const ctx = (0, react.use)(require_Mantine_context.MantineContext);
	const nonceValue = (0, react.useRef)(require_Mantine_context.useMantineStyleNonce()?.());
	if (!ctx) throw new Error("[@mantine/core] MantineProvider was not found in tree");
	const setColorScheme = (value) => {
		ctx.setColorScheme(value);
		clearStylesRef.current = keepTransitions ? () => {} : disableTransition(nonceValue.current);
		window.clearTimeout(timeoutRef.current);
		timeoutRef.current = window.setTimeout(() => {
			clearStylesRef.current?.();
		}, 10);
	};
	const clearColorScheme = () => {
		ctx.clearColorScheme();
		clearStylesRef.current = keepTransitions ? () => {} : disableTransition(nonceValue.current);
		window.clearTimeout(timeoutRef.current);
		timeoutRef.current = window.setTimeout(() => {
			clearStylesRef.current?.();
		}, 10);
	};
	const osColorScheme = (0, _mantine_hooks.useColorScheme)("light", { getInitialValueInEffect: false });
	const computedColorScheme = ctx.colorScheme === "auto" ? osColorScheme : ctx.colorScheme;
	const toggleColorScheme = (0, react.useCallback)(() => setColorScheme(computedColorScheme === "light" ? "dark" : "light"), [setColorScheme, computedColorScheme]);
	(0, react.useEffect)(() => () => {
		clearStylesRef.current?.();
		window.clearTimeout(timeoutRef.current);
	}, []);
	return {
		colorScheme: ctx.colorScheme,
		setColorScheme,
		clearColorScheme,
		toggleColorScheme
	};
}
//#endregion
exports.useMantineColorScheme = useMantineColorScheme;

//# sourceMappingURL=use-mantine-color-scheme.cjs.map