/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-e634e55 | Cube Dev Team */
import { injectRawCSS } from "../injector/index.js";
import { useInsertionEffect, useMemo, useRef } from "react";

//#region src/tasty/hooks/useRawCSS.ts
function useRawCSS(cssOrFactory, depsOrOptions, options) {
	const isFactory = typeof cssOrFactory === "function";
	const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
	const opts = isFactory ? options : depsOrOptions;
	const css = useMemo(() => isFactory ? cssOrFactory() : cssOrFactory, isFactory ? deps ?? [] : [cssOrFactory]);
	const disposeRef = useRef(null);
	useInsertionEffect(() => {
		disposeRef.current?.();
		if (!css.trim()) {
			disposeRef.current = null;
			return;
		}
		const { dispose } = injectRawCSS(css, opts);
		disposeRef.current = dispose;
		return () => {
			disposeRef.current?.();
			disposeRef.current = null;
		};
	}, [css, opts?.root]);
}

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