"use client";
let react = require("react");
let _mantine_hooks = require("@mantine/hooks");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/core/DirectionProvider/DirectionProvider.tsx
const DirectionContext = (0, react.createContext)({
	dir: "ltr",
	toggleDirection: () => {},
	setDirection: () => {}
});
function useDirection() {
	return (0, react.use)(DirectionContext);
}
function DirectionProvider({ children, initialDirection = "ltr", detectDirection = true }) {
	const [dir, setDir] = (0, react.useState)(initialDirection);
	const setDirection = (0, react.useCallback)((direction) => {
		setDir(direction);
		if (document.documentElement.getAttribute("dir") !== direction) document.documentElement.setAttribute("dir", direction);
	}, []);
	const toggleDirection = () => setDirection(dir === "ltr" ? "rtl" : "ltr");
	(0, _mantine_hooks.useIsomorphicEffect)(() => {
		if (detectDirection) {
			const direction = document.documentElement.getAttribute("dir");
			if (direction === "rtl" || direction === "ltr") setDir(direction);
		}
	}, []);
	(0, _mantine_hooks.useMutationObserverTarget)((0, react.useCallback)(() => {
		if (typeof document === "undefined") return;
		const direction = document.documentElement.getAttribute("dir");
		if (direction === "rtl" || direction === "ltr") setDir((prev) => prev !== direction ? direction : prev);
	}, []), detectDirection ? {
		attributes: true,
		attributeFilter: ["dir"]
	} : {}, typeof document !== "undefined" && detectDirection ? document.documentElement : null);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DirectionContext, {
		value: {
			dir,
			toggleDirection,
			setDirection
		},
		children
	});
}
//#endregion
exports.DirectionContext = DirectionContext;
exports.DirectionProvider = DirectionProvider;
exports.useDirection = useDirection;

//# sourceMappingURL=DirectionProvider.cjs.map