import { createContext as e, createElement as t, useContext as n, useMemo as r } from "react";
import { cn as i } from "@ryuzaki13/react-foundation-lib/utils";
import { GripIcon as a } from "lucide-react";
import { jsx as o } from "react/jsx-runtime";
import { useDndSortableSensors as s } from "@ryuzaki13/react-foundation-lib/hooks";
import { SortableContext as c, horizontalListSortingStrategy as l, rectSortingStrategy as u, useSortable as d, verticalListSortingStrategy as f } from "@dnd-kit/sortable";
import { CSS as p } from "@dnd-kit/utilities";
import { DndContext as m, closestCenter as h } from "@dnd-kit/core";
//#region src/sortable/sortableUtils.ts
function g(e) {
	return e?.data.current?.sortable.containerId ?? null;
}
function _(e, t) {
	return Array.isArray(t) ? t : t[String(e)] ?? null;
}
function v(e, t) {
	if (t) return t;
	switch (e) {
		case "horizontal": return l;
		case "grid": return u;
		default: return f;
	}
}
function y(e) {
	let { event: t, items: n } = e, { active: r, over: i } = t;
	if (!i || r.id === i.id) return null;
	let a = g(r), o = g(i);
	if (a == null || o == null || a !== o) return null;
	let s = _(a, n);
	if (!s) return null;
	let c = s.indexOf(r.id), l = s.indexOf(i.id);
	return c < 0 || l < 0 ? null : {
		containerId: a,
		activeId: r.id,
		overId: i.id,
		fromIndex: c,
		toIndex: l
	};
}
//#endregion
//#region src/sortable/Sortable.tsx
var b = e(null);
function x(e, t) {
	return typeof e == "function" ? e(t) : e;
}
function S(e, t) {
	return typeof e == "function" ? e(t) : e;
}
function C(e) {
	let { children: t, collisionDetection: n = h, sensors: i, onDragCancel: a, onDragEnd: c, onDragMove: l, onDragOver: u, onDragPending: d, onDragStart: f, accessibility: p, ...g } = e, _ = s(), v = typeof document > "u" ? void 0 : document.body, y = r(() => ({
		...p,
		container: p?.container ?? v
	}), [p, v]);
	return /* @__PURE__ */ o(m, {
		...g,
		accessibility: y,
		sensors: i ?? _,
		collisionDetection: n,
		onDragStart: f,
		onDragMove: l,
		onDragOver: u,
		onDragEnd: c,
		onDragCancel: a,
		onDragPending: d,
		children: t
	});
}
function w(e) {
	let { children: t, containerId: n, items: r, layout: i = "vertical", strategy: a } = e;
	return /* @__PURE__ */ o(c, {
		id: String(n),
		items: [...r],
		strategy: v(i, a),
		children: t
	});
}
function T(e) {
	let { as: n, id: a, children: s, className: c, style: l, disabled: u = !1, dragActivator: f = "handle", ...m } = e, h = n ?? "div", { attributes: g, listeners: _, setActivatorNodeRef: v, setNodeRef: y, transform: S, transition: C, isDragging: w, isOver: T, isSorting: E } = d({
		id: a,
		disabled: u
	}), D = {
		transform: p.Transform.toString(S),
		transition: C,
		zIndex: !u && w ? 2 : 1,
		opacity: !u && w ? .6 : void 0,
		...l
	}, O = r(() => ({
		attributes: g,
		listeners: f === "handle" ? _ : void 0,
		setActivatorNodeRef: v,
		disabled: u || f !== "handle",
		isDragging: w
	}), [
		g,
		_,
		v,
		u,
		f,
		w
	]), k = {
		isDragging: w,
		isOver: T,
		isSorting: E,
		disabled: u
	}, A = f === "item" && !u ? {
		...g,
		..._
	} : {};
	return /* @__PURE__ */ o(b.Provider, {
		value: O,
		children: t(h, {
			...m,
			...A,
			ref: y,
			className: i(c),
			style: D,
			"data-sortable-id": String(a),
			"data-sortable-dragging": w ? "true" : "false",
			"data-sortable-disabled": u ? "true" : "false"
		}, x(s, k))
	});
}
function E(e) {
	let { as: r, children: i, disabled: a = !1, ...o } = e, s = r ?? "div", c = n(b), l = a || !c || c.disabled, u = l ? {} : {
		...c.attributes,
		...c.listeners
	}, d = {
		disabled: l,
		isDragging: c?.isDragging ?? !1
	};
	return t(s, {
		...o,
		...u,
		ref: !l && c ? c.setActivatorNodeRef : void 0,
		"aria-disabled": l || void 0,
		"data-sortable-handle": "true",
		"data-sortable-handle-disabled": l ? "true" : "false",
		"data-sortable-handle-dragging": d.isDragging ? "true" : "false"
	}, S(i, d));
}
var D = { dragHandle: "_7rGb26" };
//#endregion
//#region src/sortable/SortableDragHandle.tsx
function O(e, t) {
	return e ?? t;
}
function k(e, t, n) {
	return e == null ? t ?? n : t;
}
function A(e) {
	if (e.as === "button") {
		let { as: t, children: n, className: r, disabled: s = !1, icon: c = /* @__PURE__ */ o(a, { "aria-hidden": "true" }), type: l = "button", ...u } = e, d = k(n, u["aria-label"], u.title);
		return /* @__PURE__ */ o(E, {
			...u,
			as: t,
			type: l,
			disabled: s,
			"aria-label": d,
			className: i(D.dragHandle, r),
			children: O(n, c)
		});
	}
	let { as: t, children: n, className: r, disabled: s = !1, icon: c = /* @__PURE__ */ o(a, { "aria-hidden": "true" }), ...l } = e, u = k(n, l["aria-label"], l.title);
	return /* @__PURE__ */ o(E, {
		...l,
		as: t,
		disabled: s,
		"aria-label": u,
		className: i(D.dragHandle, r),
		children: O(n, c)
	});
}
//#endregion
//#region src/sortable/index.ts
var j = {
	Root: C,
	Container: w,
	Item: T,
	Handle: E,
	DragHandle: A
};
//#endregion
export { T as a, E as i, A as n, C as o, w as r, y as s, j as t };

//# sourceMappingURL=sortable-DcTIAbjD.js.map