import { cx as e } from "../../../theme/tools.js";
import { ChevronDownSvg as t } from "../../../icons/ChevronDownSvg.js";
import { CSS as n } from "../../../node_modules/@dnd-kit/utilities/dist/utilities.esm.js";
import { DndContext as r, DragOverlay as i, KeyboardSensor as a, PointerSensor as o, TouchSensor as s, closestCenter as ee, useSensor as c, useSensors as l } from "../../../node_modules/@dnd-kit/core/dist/core.esm.js";
import { SortableContext as u, sortableKeyboardCoordinates as d, useSortable as f, verticalListSortingStrategy as p } from "../../../node_modules/@dnd-kit/sortable/dist/sortable.esm.js";
import { SidebarNavItem as m } from "../sidebar_nav_item/SidebarNavItem.js";
import { header as h, headerButton as g, headerButtonSidebarCollapsed as te, headerSidebarCollapsed as ne, items as _, itemsNested as v, section as re, sortableItem as y, sortableItemDragging as b, title as ie, titleContent as x, titleIcon as ae, titleIconTheme as oe, titleSidebarCollapsed as se, titleTheme as ce, toggleIcon as le, toggleIconCollapsed as ue } from "./sidebarNavSection.css.js";
import { useCallback as S, useId as C, useMemo as w, useState as T } from "react";
import { jsx as E, jsxs as D } from "react/jsx-runtime";
import { useTranslation as de } from "react-i18next";
//#region src/backoffice/molecules/sidebar_nav_section/SidebarNavSection.tsx
var fe = ({ item: t, isNested: r, sidebarCollapsed: i, dragHandleLabel: a, insertionPlacement: o }) => {
	let { id: s, data: ee, ...c } = t, { attributes: l, listeners: u, setNodeRef: d, transform: p, transition: h, isDragging: g } = f({
		id: s,
		disabled: i
	});
	return /* @__PURE__ */ D("div", {
		ref: d,
		style: {
			transform: n.Transform.toString(p),
			transition: h
		},
		className: e(y, { [b]: g }),
		children: [
			o === "before" && /* @__PURE__ */ E("span", {
				className: "_1rp5mg6l _1rp5mg6k txvbqbstm txvbqbq0v txvbqbfox txvbqb2wi",
				"aria-hidden": "true"
			}),
			/* @__PURE__ */ E(m, {
				...c,
				collapsed: i,
				nested: r,
				dragHandleLabel: c.dragHandleLabel ?? a,
				dragHandleProps: {
					...l,
					...u
				},
				isDragging: g
			}),
			o === "after" && /* @__PURE__ */ E("span", {
				className: "_1rp5mg6l _1rp5mg6k txvbqbstm txvbqbq0v txvbqbfox txvbqb2wi",
				"aria-hidden": "true"
			})
		]
	});
}, O = ({ title: n, icon: f, items: y, collapsible: b = !1, isCollapsed: O, defaultCollapsed: pe = !1, onCollapsedChange: k, collapsed: A = !1, reorder: j, className: M }) => {
	let [me, he] = T(pe), N = C(), P = C(), { t: F } = de("ui", { useSuspense: !1 }), [I, L] = T(null), [R, z] = T(null), B = O ?? me, V = b, ge = S(() => {
		if (!V) return;
		let e = !B;
		O ?? he(e), k?.(e);
	}, [
		V,
		B,
		O,
		k
	]), H;
	typeof n == "string" && (H = n);
	let U = e(ie, ce, { [se]: A }), _e = e(le, { [ue]: B }), W;
	A && (W = H);
	let G = null;
	f != null && (G = /* @__PURE__ */ E("span", {
		className: e(ae, oe),
		"aria-hidden": "true",
		children: f
	}));
	let ve = j?.enabled === !0 && y.length > 1, K = w(() => y.map((e) => e.id), [y]), ye = l(c(o, { activationConstraint: { distance: 4 } }), c(s, { activationConstraint: {
		delay: 180,
		tolerance: 5
	} }), c(a, { coordinateGetter: d })), q = S(() => {
		L(null), z(null);
	}, []), be = S((e) => {
		L(e.active.id), z(e.active.id);
	}, []), xe = S((e) => {
		let t = y.find((t) => t.id === String(e.active.id)) ?? null, n = null;
		e.over != null && (n = y.find((t) => t.id === String(e.over?.id)) ?? null);
		let r = t?.data?.id ?? String(e.active.id), i = null;
		n != null && (i = n.data?.id ?? String(e.over?.id)), q(), !(i == null || r === i) && j?.onReorder(r, i);
	}, [
		y,
		j,
		q
	]), J = w(() => I == null ? null : y.find((e) => e.id === String(I)) ?? null, [I, y]), Y = null, X = "before";
	if (I != null && R != null && I !== R) {
		let e = K.indexOf(String(I)), t = K.indexOf(String(R));
		e !== -1 && t !== -1 && (Y = String(R), e < t && (X = "after"));
	}
	let Se = F("navigation.sidebar.reorder.handle"), Ce = F("navigation.sidebar.reorder.instructions"), Z = null;
	n != null && (Z = V ? /* @__PURE__ */ D("button", {
		id: P,
		type: "button",
		className: e(g, { [te]: A }),
		onClick: ge,
		"aria-expanded": !B,
		"aria-controls": N,
		"aria-label": W,
		title: W,
		children: [/* @__PURE__ */ D("span", {
			className: x,
			children: [G, /* @__PURE__ */ E("span", {
				className: U,
				children: n
			})]
		}), !A && /* @__PURE__ */ E("span", {
			className: _e,
			"aria-hidden": "true",
			children: /* @__PURE__ */ E(t, {
				width: 18,
				height: 18
			})
		})]
	}) : /* @__PURE__ */ E("div", {
		className: e(h, { [ne]: A }),
		title: W,
		children: /* @__PURE__ */ D("div", {
			className: x,
			id: P,
			children: [G, /* @__PURE__ */ E("span", {
				className: U,
				children: n
			})]
		})
	}));
	let Q = null;
	if (!B) {
		let t = n != null && !A;
		Q = /* @__PURE__ */ E("div", {
			className: e(_, { [v]: t }),
			id: N,
			role: "list",
			children: y.map((e) => {
				let { id: n, data: r, ...i } = e;
				return /* @__PURE__ */ E(m, {
					...i,
					collapsed: A,
					nested: t
				}, n);
			})
		}), ve && !A && (Q = /* @__PURE__ */ D(r, {
			accessibility: { screenReaderInstructions: { draggable: Ce } },
			collisionDetection: ee,
			sensors: ye,
			onDragStart: be,
			onDragOver: (e) => {
				z(e.over?.id ?? null);
			},
			onDragCancel: q,
			onDragEnd: xe,
			children: [/* @__PURE__ */ E(u, {
				items: K,
				strategy: p,
				children: /* @__PURE__ */ E("div", {
					className: e(_, { [v]: t }),
					id: N,
					role: "list",
					children: y.map((e) => {
						let n;
						return e.id === Y && (n = X), /* @__PURE__ */ E(fe, {
							item: e,
							isNested: t,
							sidebarCollapsed: A,
							dragHandleLabel: Se,
							insertionPlacement: n
						}, e.id);
					})
				})
			}), /* @__PURE__ */ E(i, { children: J != null && /* @__PURE__ */ D("div", {
				className: "_1rp5mg6n _1rp5mg6m txvbqb10mx txvbqb11ki txvbqb13cs txvbqbyov txvbqbfpn txvbqbey txvbqbhdl txvbqb2uc txvbqb9j txvbqbhbf txvbqb28o txvbqbegv",
				children: [J.icon != null && /* @__PURE__ */ E("span", {
					className: "_1rp5mg6o txvbqbfqq txvbqbey txvbqbls4 txvbqb19gc txvbqbjlr txvbqbh6d",
					children: J.icon
				}), /* @__PURE__ */ E("span", {
					className: "_1rp5mg6q _1rp5mg6p txvbqbv7x",
					children: J.label
				})]
			}) })]
		}));
	}
	let $;
	return n != null && ($ = P), /* @__PURE__ */ D("section", {
		className: e(re, M),
		"aria-labelledby": $,
		children: [Z, Q]
	});
};
//#endregion
export { O as SidebarNavSection, O as default };

//# sourceMappingURL=SidebarNavSection.js.map