import { useColumn as e } from "./useColumn.js";
import { useMouse as t } from "../../../composition/useMouse.js";
import { useHover as n } from "../../../composition/useHover.js";
import { unref as r, watchEffect as i } from "vue";
import { clamp as a, identity as o, tapIf as s } from "@milaboratories/helpers";
function c(e) {
	let t = s(r(e)?.querySelectorAll(".th-cell"), (e) => [...e]) ?? [];
	return t.map((e) => {
		let { width: t, x: n } = e.getBoundingClientRect();
		return o({
			colId: e.getAttribute("data-col-id"),
			width: t,
			x: n,
			right: n + t
		});
	}).slice(0, t.length - 1);
}
function l(r, o) {
	let l = t(), u = n(o, {}), { data: d } = r, f = e((e) => {
		s(d.resizeTh, (t) => {
			let n = d.columns.find((e) => e.id === t.colId);
			n && (n.width = a(e.width + e.diff, 30, 1e4), r.adjustWidth());
		});
	}, () => {
		d.resize = !1, d.resizeTh = void 0, document.body.style.cursor = "";
	});
	return i(() => {
		if (!u.value) {
			document.body.style.cursor = "";
			return;
		}
		if (d.resize) return;
		let e = c(o).find((e) => Math.abs(l.x - e.right) < 10);
		e ? (document.body.style.cursor = "col-resize", d.resizeTh = e) : (d.resizeTh = void 0, document.body.style.cursor = "");
	}), { mouseDown: (e) => {
		d.resizeTh && (d.resize = !0, f.start({
			x: e.x,
			width: d.resizeTh.width
		}));
	} };
}
export { l as useResize };

//# sourceMappingURL=useResize.js.map