import { t as e } from "../../utils-B7XIe3qq.js";
import * as t from "react";
import { jsx as n, jsxs as r } from "react/jsx-runtime";
//#region src/react/primitives/split-pane.tsx
function i({ className: i, orientation: a = "horizontal", defaultSize: o = 50, minSize: s = 0, gutterSize: c = 4, onResize: l, children: u, ...d }) {
	let [f, p] = t.useState(o), m = t.useRef(null), h = t.useRef(!1), g = t.useCallback((e) => {
		e.preventDefault(), h.current = !0;
		let t = (e) => {
			if (!h.current || !m.current) return;
			let t = m.current.getBoundingClientRect(), n;
			if (a === "horizontal") {
				let r = e.clientX - t.left;
				n = t.width > 0 ? r / t.width * 100 : 50;
			} else {
				let r = e.clientY - t.top;
				n = t.height > 0 ? r / t.height * 100 : 50;
			}
			let r = a === "horizontal" ? t.width : t.height, i = r > 0 ? s / r * 100 : 0, o = Math.max(i, Math.min(100 - i, n));
			p(o), l?.(o);
		}, n = () => {
			h.current = !1, document.removeEventListener("mousemove", t), document.removeEventListener("mouseup", n);
		};
		document.addEventListener("mousemove", t), document.addEventListener("mouseup", n);
	}, [
		a,
		s,
		l
	]), _ = a === "horizontal", [v, y] = u;
	return /* @__PURE__ */ r("div", {
		ref: m,
		"data-slot": "split-pane",
		className: e("flex h-full w-full", _ ? "flex-row" : "flex-col", i),
		...d,
		children: [
			/* @__PURE__ */ n("div", {
				"data-slot": "split-pane-panel",
				className: "overflow-auto",
				style: {
					[_ ? "width" : "height"]: `calc(${String(f)}% - ${String(c / 2)}px)`,
					flexShrink: 0
				},
				children: v
			}),
			/* @__PURE__ */ n("div", {
				"data-slot": "split-pane-gutter",
				className: e("shrink-0 bg-border-glass transition-colors hover:bg-primary/40", _ ? "cursor-col-resize" : "cursor-row-resize"),
				style: { [_ ? "width" : "height"]: `${String(c)}px` },
				onMouseDown: g,
				role: "separator",
				"aria-orientation": a,
				"aria-valuenow": Math.round(f),
				"aria-valuemin": 0,
				"aria-valuemax": 100,
				tabIndex: 0,
				onKeyDown: (e) => {
					if (_ && e.key === "ArrowLeft" || !_ && e.key === "ArrowUp") {
						e.preventDefault();
						let t = Math.max(0, f - 2);
						p(t), l?.(t);
					}
					if (_ && e.key === "ArrowRight" || !_ && e.key === "ArrowDown") {
						e.preventDefault();
						let t = Math.min(100, f + 2);
						p(t), l?.(t);
					}
				}
			}),
			/* @__PURE__ */ n("div", {
				"data-slot": "split-pane-panel",
				className: "overflow-auto",
				style: {
					[_ ? "width" : "height"]: `calc(${String(100 - f)}% - ${String(c / 2)}px)`,
					flexShrink: 0
				},
				children: y
			})
		]
	});
}
//#endregion
export { i as SplitPane };

//# sourceMappingURL=split-pane.js.map