import { useRef as e } from "react";
import { cn as t } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as n, jsxs as r } from "react/jsx-runtime";
import { DEFAULT_TABLE_COLUMN_MIN_WIDTH as i, normalizeTableColumnWidth as a } from "@ryuzaki13/react-foundation-lib/table";
import { useSortable as o } from "@dnd-kit/sortable";
import { CSS as s } from "@dnd-kit/utilities";
var c = { resizeHandle: "YJUVjb" }, l = 8;
function u(e, t) {
	let n = e.closest("th")?.getBoundingClientRect().width;
	return a(typeof n == "number" && Number.isFinite(n) ? n : t, t);
}
function d({ columnId: r, className: o, minWidth: s, keyboardStep: d = l, ariaLabel: f = "Изменить ширину колонки", getStartWidth: p, onResize: m, onResizeEnd: h, onReset: g }) {
	let _ = s ?? i, v = e(0), y = e(0), b = e(0), x = e(!1), S = e(!1), C = (e) => a(p?.(r, e) ?? u(e, _), _), w = (e) => {
		e.button !== 0 && e.pointerType === "mouse" || (x.current = !0, S.current = !1, v.current = e.clientX, y.current = C(e.currentTarget), b.current = y.current, e.currentTarget.setPointerCapture(e.pointerId), e.preventDefault(), e.stopPropagation());
	}, T = (e) => {
		if (!x.current) return;
		let t = a(y.current + e.clientX - v.current, _);
		b.current = t, S.current = !0, m(r, t), e.preventDefault(), e.stopPropagation();
	}, E = (e) => {
		if (x.current) {
			x.current = !1, S.current && h?.(r, b.current);
			try {
				e.currentTarget.releasePointerCapture(e.pointerId);
			} catch {}
			e.preventDefault(), e.stopPropagation();
		}
	};
	return /* @__PURE__ */ n("div", {
		role: "separator",
		"aria-label": f,
		"aria-orientation": "vertical",
		tabIndex: 0,
		onPointerDown: w,
		onPointerMove: T,
		onPointerUp: E,
		onPointerCancel: E,
		onKeyDown: (e) => {
			if (e.key !== "ArrowLeft" && e.key !== "ArrowRight" && e.key !== "Home") return;
			if (e.preventDefault(), e.stopPropagation(), e.key === "Home") {
				g?.(r);
				return;
			}
			let t = e.key === "ArrowRight" ? 1 : -1, n = a(C(e.currentTarget) + t * d, _);
			m(r, n), h?.(r, n);
		},
		onDoubleClick: (e) => {
			e.preventDefault(), e.stopPropagation(), g?.(r);
		},
		className: t(c.resizeHandle, o)
	});
}
//#endregion
//#region src/table-column-interactions/TableHeaderInteractionCell.tsx
function f(e, t) {
	return typeof e == "function" ? e(t) : e;
}
function p({ columnId: e, children: i, dragDisabled: a = !1, draggingClassName: c, resizeHandle: l, className: u, style: p, ...m }) {
	let { attributes: h, listeners: g, setActivatorNodeRef: _, setNodeRef: v, transform: y, isDragging: b, rect: x } = o({
		id: e,
		disabled: a
	}), S = b ? x.current?.width : void 0, C = {
		transform: s.Translate.toString(y),
		zIndex: b ? "calc(var(--z-header) + 1)" : void 0,
		...S ? {
			width: S,
			minWidth: S
		} : {},
		...p
	}, w = {
		attributes: h,
		listeners: g,
		setActivatorElement: _,
		disabled: a,
		isDragging: b
	};
	return /* @__PURE__ */ r("th", {
		...m,
		ref: v,
		className: t(u, b && c),
		style: C,
		children: [f(i, w), l ? /* @__PURE__ */ n(d, { ...l }) : null]
	});
}
//#endregion
export { d as n, p as t };

//# sourceMappingURL=table-column-interactions-BGd5Lwy9.js.map