import * as e from "react";
import { jsx as t } from "react/jsx-runtime";
//#region src/react/primitives/direction.tsx
var n = e.createContext({
	direction: "ltr",
	setDirection: () => {}
});
function r({ direction: r = "ltr", children: i, onChange: a }) {
	let [o, s] = e.useState(r);
	e.useEffect(() => {
		s(r);
	}, [r]), e.useEffect(() => {
		let e = document.documentElement, t = new MutationObserver(() => {
			let t = e.getAttribute("dir");
			(t === "ltr" || t === "rtl" || t === "auto") && (s(t), a?.(t));
		});
		return t.observe(e, {
			attributes: !0,
			attributeFilter: ["dir"]
		}), () => t.disconnect();
	}, [a]);
	let c = e.useCallback((e) => {
		s(e), a?.(e);
	}, [a]), l = e.useMemo(() => ({
		direction: o,
		setDirection: c
	}), [o, c]);
	return /* @__PURE__ */ t(n.Provider, {
		value: l,
		children: /* @__PURE__ */ t("div", {
			"data-slot": "direction-provider",
			dir: o,
			children: i
		})
	});
}
function i() {
	return e.useContext(n);
}
//#endregion
export { n as DirectionContext, r as DirectionProvider, i as useDirection };

//# sourceMappingURL=direction.js.map