import { t as e } from "../chunks/ui.module-BisoTevy.js";
import { o as t } from "../chunks/input-Bp6_Ucgr.js";
import { t as n } from "../chunks/check-box-Dd3YFuxd.js";
import { c as r, d as i, f as a, i as o, l as s, n as c, p as l, r as u, t as d, u as f } from "../chunks/picker-e6IsrMUG.js";
import { r as p } from "../chunks/useODataSelectBase-CKe1AVMI.js";
import { o as m } from "../chunks/multi-select-COEkc8Qc.js";
import { useCallback as h, useEffect as g, useLayoutEffect as _, useMemo as v, useRef as y, useState as ee } from "react";
import { flattenODataDependentServices as b, sortODataDependentSegmentItemsByChains as x, useODataCollection as S, useODataCollectionChains as te, useODataCollectionModel as C } from "@ryuzaki13/react-foundation-api/odata";
import { cn as w } from "@ryuzaki13/react-foundation-lib/utils";
import { CheckIcon as T, ChevronRightIcon as E, MinusIcon as ne, XIcon as re } from "lucide-react";
import { Fragment as ie, jsx as D, jsxs as O } from "react/jsx-runtime";
import { compareStrings as ae } from "@ryuzaki13/react-foundation-lib/string-comparison";
//#region src/tree-select/helpers.ts
function k(e) {
	return e ? { [e.codeKey]: [e.value] } : {};
}
//#endregion
//#region src/tree-select/model/buildODataTreeNodes.ts
function A(e, t, n) {
	return e ? `${e}/${t}:${n}` : `${t}:${n}`;
}
function j(e, t, n) {
	let r = n[t];
	return r && e[r] || e[t];
}
function M(e) {
	return [...new Set(e.filter(Boolean))].join(" ");
}
function oe(e) {
	return {
		id: A(e.parentId, e.codeKey, e.value),
		codeKey: e.codeKey,
		value: e.value,
		label: e.label,
		code: e.code,
		searchText: M([
			e.value,
			e.label,
			e.code
		]),
		sortCode: e.sortCode,
		children: [],
		childByBranchKey: /* @__PURE__ */ new Map()
	};
}
function se(e, t) {
	e.sort((e, n) => {
		let r = t ? e.sortCode : e.label, i = t ? n.sortCode : n.label;
		return ae(r, i) || ae(e.sortCode, n.sortCode);
	});
	for (let n of e) se(n.children, t);
}
function ce(e) {
	return {
		id: e.id,
		codeKey: e.codeKey,
		value: e.value,
		label: e.label,
		code: e.code,
		searchText: e.searchText,
		children: e.children.length > 0 ? e.children.map(ce) : void 0
	};
}
function le({ items: e, orderedCodeKeys: t, keyPairsMap: n, hiddenCodeKeys: r, textValueCodeKeys: i, sortByCode: a = !0 }) {
	if (t.length === 0 || e.length === 0) return [];
	let o = [], s = /* @__PURE__ */ new Map();
	for (let a of e) {
		let e;
		for (let c of t) {
			let t = String(a[c] ?? "");
			if (!t) break;
			let l = String(j(a, c, n) ?? ""), u = i?.has(c) ? l : t, d = `${c}:${u}`, f = e ? e.childByBranchKey : s, p = f.get(d);
			p || (p = oe({
				parentId: e?.id,
				codeKey: c,
				value: u,
				label: l,
				code: r.has(c) ? void 0 : t,
				sortCode: t
			}), f.set(d, p), e ? e.children.push(p) : o.push(p)), e = p;
		}
	}
	return se(o, a), o.map(ce);
}
//#endregion
//#region src/tree-select/model/resolveOrderedTreeSegmentItems.ts
function ue(e, t) {
	return x(e, t);
}
//#endregion
//#region src/tree-select/model/useODataTreeData.ts
function N(e, t, n) {
	return b([{
		odata: e,
		segments: t,
		model: n
	}]);
}
function de(e) {
	return e[0]?.id;
}
function P({ odata: e, segments: t, model: n }) {
	let r = `${e.service}.${e.target}`, i = v(() => N(e, t, n), [
		e,
		t,
		n
	]), a = te([e]), o = v(() => ue(i, a), [i, a]), s = v(() => o.map((e) => e.id), [o]), c = de(o) ?? Object.keys(t)[0], l = C({
		codeKey: c,
		...n
	}), u = S({
		odata: e,
		model: l
	}), { hiddenCodeKeys: d, textValueCodeKeys: f } = v(() => {
		let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
		for (let r of o) (r.segment.hideCode ?? e.hideCode) && t.add(r.id), r.segment.selectText && n.add(r.id);
		return {
			hiddenCodeKeys: t,
			textValueCodeKeys: n
		};
	}, [e.hideCode, o]), p = v(() => le({
		items: u.data?.items ?? [],
		orderedCodeKeys: s,
		keyPairsMap: u.data?.keyPairsMap ?? {},
		hiddenCodeKeys: d,
		textValueCodeKeys: f,
		sortByCode: e.sortByCode
	}), [
		u.data?.items,
		u.data?.keyPairsMap,
		d,
		e.sortByCode,
		s,
		f
	]), m = o[0]?.segment.placeholder ?? "Выберите значение", h = !!a[r]?.length;
	return {
		nodes: p,
		orderedSegmentItems: o,
		orderedCodeKeys: s,
		isLoading: u.isLoading,
		isError: u.isError,
		placeholder: m,
		hasResolvedChain: h
	};
}
//#endregion
//#region src/tree-select/model/treeUtils.ts
function F(e, t) {
	return `${e}::${t}`;
}
function fe(e) {
	let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = 0, s = (e, c) => {
		t.set(e.id, e), n.set(e.id, c), i.set(e.id, o++), a.set(F(e.codeKey, e.value), e.id);
		let l = (e.children ?? []).map((e) => e.id);
		r.set(e.id, l);
		for (let t of e.children ?? []) s(t, e.id);
	};
	for (let t of e) s(t);
	return {
		rootIds: e.map((e) => e.id),
		nodeById: t,
		parentById: n,
		childrenById: r,
		preorderIndexById: i,
		nodeIdByCodeValue: a
	};
}
function pe(e, t) {
	if (e) return t.nodeIdByCodeValue.get(F(e.codeKey, e.value));
}
function I(e, t) {
	let n = /* @__PURE__ */ new Set();
	if (!e) return n;
	for (let [r, i] of Object.entries(e)) for (let e of i) {
		let i = t.nodeIdByCodeValue.get(F(r, e));
		i && n.add(i);
	}
	return B(n, t);
}
function me(e, t) {
	let n = [...e].sort((e, n) => (t.preorderIndexById.get(e) ?? 2 ** 53 - 1) - (t.preorderIndexById.get(n) ?? 2 ** 53 - 1)), r = {};
	for (let e of n) {
		let n = t.nodeById.get(e);
		n && (r[n.codeKey] = r[n.codeKey] ?? [], r[n.codeKey].push(n.value));
	}
	return r;
}
function L(e, t) {
	let n = [], r = t.parentById.get(e);
	for (; r;) n.push(r), r = t.parentById.get(r);
	return n;
}
function R(e, t, n) {
	let r = n.parentById.get(e);
	for (; r;) {
		if (r === t) return !0;
		r = n.parentById.get(r);
	}
	return !1;
}
function he(e, t, n) {
	for (let r of [...e]) R(r, t, n) && e.delete(r);
}
function z(e, t, n) {
	if (t.has(e)) return !0;
	if (n.nodeById.get(e)?.disabled) return !1;
	let r = n.childrenById.get(e) ?? [];
	return r.length !== 0 && r.every((e) => z(e, t, n));
}
function B(e, t) {
	let n = new Set(e);
	for (let e of [...n]) L(e, t).some((e) => n.has(e)) && n.delete(e);
	let r = [...t.nodeById.keys()].sort((e, n) => (t.preorderIndexById.get(n) ?? 0) - (t.preorderIndexById.get(e) ?? 0));
	for (let e of r) {
		let r = t.childrenById.get(e) ?? [];
		r.length === 0 || n.has(e) || t.nodeById.get(e)?.disabled || r.every((e) => z(e, n, t)) && (he(n, e, t), n.add(e));
	}
	return n;
}
function V(e, t, n) {
	let r = n.parentById.get(t);
	for (; r;) {
		if (e.has(r)) {
			e.delete(r);
			for (let t of W(n, n.childrenById.get(r) ?? [])) e.add(t);
			return !0;
		}
		r = n.parentById.get(r);
	}
	return !1;
}
function H(e, t, n) {
	return t.has(e) ? !0 : L(e, n).some((e) => t.has(e));
}
function U(e, t, n, r) {
	let i = n.childrenById.get(e) ?? [];
	if (t.has(e)) return r.selectedIds.add(e), {
		selected: !0,
		partial: !1
	};
	if (i.length === 0) return {
		selected: !1,
		partial: !1
	};
	let a = i.map((e) => U(e, t, n, r)), o = a.every((e) => e.selected && !e.partial), s = a.some((e) => e.selected || e.partial);
	return o ? (r.selectedIds.add(e), {
		selected: !0,
		partial: !1
	}) : s ? (r.partialIds.add(e), {
		selected: !1,
		partial: !0
	}) : {
		selected: !1,
		partial: !1
	};
}
function ge(e, t) {
	let n = {
		selectedIds: /* @__PURE__ */ new Set(),
		partialIds: /* @__PURE__ */ new Set()
	};
	for (let r of t.rootIds) U(r, e, t, n);
	return n;
}
function W(e, t = e.rootIds) {
	let n = (t) => {
		let r = e.nodeById.get(t), i = (e.childrenById.get(t) ?? []).map(n), a = i.flatMap((e) => e.selectedIds), o = r?.disabled === !0 || i.some((e) => e.containsDisabled);
		return !r || r.disabled || o ? {
			containsDisabled: !0,
			selectedIds: a
		} : {
			containsDisabled: !1,
			selectedIds: [t]
		};
	};
	return new Set(t.flatMap((e) => n(e).selectedIds));
}
function _e(e, t, n) {
	let r = I(e, n), i = (e) => {
		if (H(e, r, n)) {
			if (r.has(e)) {
				r.delete(e);
				return;
			}
			V(r, e, n) && i(e);
			return;
		}
		he(r, e, n), r.add(e);
	}, a = [...W(n, [t])], o = a.length > 0 && a.every((e) => H(e, r, n));
	for (let e of a) {
		let t = H(e, r, n);
		(o && t || !o && !t) && i(e);
	}
	return me(B(r, n), n);
}
function ve(e, t, n) {
	let r = t.parentById.get(e);
	for (; r;) n.add(r), r = t.parentById.get(r);
}
function ye(e, t) {
	let n = /* @__PURE__ */ new Set();
	for (let r of e) ve(r, t, n);
	return n;
}
function be(e, t, n) {
	let r = /* @__PURE__ */ new Set();
	for (let [i, a] of e.childrenById) {
		if (a.length === 0) continue;
		let o = e.nodeById.get(i);
		o && (n.get(i) ?? t.has(o.codeKey)) && r.add(i);
	}
	return r;
}
function G(e, t, n) {
	let r = (e.children ?? []).map((e) => G(e, t, n)).filter((e) => !!e);
	return !e.searchText.toLowerCase().includes(t) && r.length === 0 ? null : (r.length > 0 && n.add(e.id), r.length === 0 ? e : {
		...e,
		children: r
	});
}
function xe(e, t) {
	let n = t.trim().toLowerCase();
	if (!n) return {
		nodes: [...e],
		expandedIds: /* @__PURE__ */ new Set()
	};
	let r = /* @__PURE__ */ new Set();
	return {
		nodes: e.map((e) => G(e, n, r)).filter((e) => !!e),
		expandedIds: r
	};
}
function Se(e, t) {
	let n = [], r = (e, i, a) => {
		let o = (e.children?.length ?? 0) > 0, s = o && t.has(e.id);
		if (n.push({
			node: e,
			level: i,
			parentId: a,
			hasChildren: o,
			isExpanded: s,
			isLeaf: !o
		}), s) for (let t of e.children ?? []) r(t, i + 1, e.id);
	};
	for (let t of e) r(t, 0);
	return n;
}
//#endregion
//#region src/tree-select/model/buildTreeColumnsLayoutDescriptor.ts
function Ce(e) {
	let t = [], n = 0;
	for (; n < e.length;) {
		let r = n + 1;
		for (; r < e.length && e[r]?.level !== 0;) r += 1;
		t.push({
			startIndex: n,
			endIndexExclusive: r
		}), n = r;
	}
	let r = t.map(({ startIndex: e, endIndexExclusive: t }) => `${e}:${t}`).join("|");
	return {
		itemCount: e.length,
		groups: t,
		signature: `${e.length}|${r}`
	};
}
//#endregion
//#region src/tree-select/model/resolveBalancedTreeColumnsLayout.ts
var K = 16, we = 48, q = 224, Te = 10, J = 32, Y = 6, Ee = 3;
function X(e, t) {
	return Number.isFinite(e) && e > 0 ? e : t;
}
function De(e) {
	let t = e.endIndexExclusive - e.startIndex;
	return Math.min(Ee, t);
}
function Z(e, t) {
	let n = Math.max(1, t), r = [], i = 1, a = 1, o = 0;
	for (let t of e.groups) {
		let e = De(t), s = n - a + 1;
		a > 1 && e > s && (o += s, i += 1, a = 1);
		for (let e = t.startIndex; e < t.endIndexExclusive; e += 1) r[e] = {
			column: i,
			row: a
		}, a += 1, a > n && (i += 1, a = 1);
	}
	return {
		placements: r,
		usedColumnCount: r.length ? Math.max(...r.map((e) => e.column)) : 1,
		intentionalGapCount: o
	};
}
function Oe({ descriptor: e, availableWidth: t, availableHeight: n, viewportWidth: r, viewportHeight: i, referenceWidth: a }) {
	let o = Math.max(0, Math.floor(Number.isFinite(e.itemCount) ? e.itemCount : 0)), s = X(t, 240), c = X(n, 80), l = X(r, s + 16), u = X(i, c), d = Math.max(1, Math.min(s, Math.max(1, l - 16))), f = Math.max(1, Math.min(c, u - 16)), p = Math.max(1, X(a, 1)), m = Math.min(d, p), h = Math.max(1, Math.floor((d - K + Te) / 234)), g = Math.max(1, Math.min(Y, h, o || 1)), _ = e.groups.reduce((e, t) => Math.max(e, De(t)), 1);
	if (o === 0) return {
		columnCount: 1,
		rowCount: 1,
		width: m,
		minWidth: m,
		maxHeight: f,
		placements: []
	};
	let v, y = Infinity;
	for (let t = 1; t <= g; t += 1) {
		let n = Math.max(_, Math.ceil(o / t)), r = Z(e, n);
		for (; r.usedColumnCount > t && n < o;) n += 1, r = Z(e, n);
		let i = r.usedColumnCount, a = Math.max(m, K + i * q + (i - 1) * Te), s = we + n * J, c = a / d, l = s / f, u = (i * n - o) / o, p = r.intentionalGapCount / o, h = Math.max(c, l) + .25 * Math.abs(c - l) + .01 * u + .02 * p + .04 * (i - 1);
		h < y && (y = h, v = {
			columnCount: i,
			rowCount: n,
			width: Math.min(d, a),
			minWidth: m,
			maxHeight: f,
			placements: r.placements
		});
	}
	return v ?? {
		columnCount: 1,
		rowCount: o,
		width: m,
		minWidth: m,
		maxHeight: f,
		placements: Z(e, o).placements
	};
}
var Q = {
	treeRow: "eMqOwq",
	treeRowSelected: "JKstO-",
	treeRowActive: "hKgr8e",
	treeRowDisabled: "KjPZjd",
	treeNodeButton: "_6EH37F",
	treePopupHeader: "UBll8Q",
	treeColumns: "-y3RZP",
	treeColumnRow: "ayLJ50",
	treeColumnsPopupLayout: "_430vL2",
	treeColumnRootLabel: "FkzTJI",
	treeColumnRootCode: "e8fE4t",
	treeColumnCheckBox: "_2MFkGF",
	treeNodeOptionContent: "SWQUvb",
	treeIndent: "o5NWnX",
	treeExpander: "ibSd-S",
	treeExpanderPlaceholder: "lXezvv",
	treeExpanderIcon: "FMlLGX",
	treeExpanderIconExpanded: "d2Zt7U",
	treeSelection: "_8PN4hs",
	treeSelectionChecked: "_4JEoen",
	treeSelectionPartial: "GS8eEC",
	treeSelectionIcon: "T8gVno",
	treeSummary: "o6stdX",
	inputWithOverlay: "I5zvhe",
	valueOverlay: "KQ0PBI",
	treeActions: "_7hAQQA",
	treeClearButton: "XeUHNc"
};
//#endregion
//#region src/tree-select/TreeNodeContent.tsx
function ke({ node: e, level: t, highlight: r, hasChildren: i, isExpanded: a, selected: o, partial: s, selectionMode: c, optionsLayout: l = "tree", onToggleExpand: u, onToggleSelection: d }) {
	let f = l === "tree", m = l === "columns" && t === 0;
	return /* @__PURE__ */ O(ie, { children: [
		/* @__PURE__ */ D("span", {
			className: Q.treeIndent,
			style: { "--tree-level": t },
			"aria-hidden": "true"
		}),
		f && i ? /* @__PURE__ */ D("button", {
			type: "button",
			className: Q.treeExpander,
			onClick: (e) => {
				e.stopPropagation(), u?.();
			},
			"aria-label": a ? "Свернуть ветку" : "Развернуть ветку",
			"data-ui": "tree-select-expander",
			"data-action": a ? "collapse-tree-select-node" : "expand-tree-select-node",
			children: /* @__PURE__ */ D(E, { className: w(Q.treeExpanderIcon, a && Q.treeExpanderIconExpanded) })
		}) : f ? /* @__PURE__ */ D("span", {
			className: Q.treeExpanderPlaceholder,
			"aria-hidden": "true"
		}) : null,
		c === "multi" && l === "columns" ? /* @__PURE__ */ D("span", {
			className: Q.treeColumnCheckBox,
			onMouseDown: (e) => e.stopPropagation(),
			onClick: (e) => e.stopPropagation(),
			children: /* @__PURE__ */ D(n, {
				value: o,
				indeterminate: s,
				disabled: e.disabled,
				"aria-label": `Выбрать ${e.label}`,
				onChange: () => d?.()
			})
		}) : c === "multi" ? /* @__PURE__ */ D("span", {
			className: w(Q.treeSelection, o && Q.treeSelectionChecked, s && Q.treeSelectionPartial),
			"aria-hidden": "true",
			children: o ? /* @__PURE__ */ D(T, { className: Q.treeSelectionIcon }) : s ? /* @__PURE__ */ D(ne, { className: Q.treeSelectionIcon }) : null
		}) : null,
		/* @__PURE__ */ D("div", {
			className: Q.treeNodeOptionContent,
			children: /* @__PURE__ */ D(p, {
				label: e.label,
				code: e.code,
				highlight: r,
				labelClassName: m ? Q.treeColumnRootLabel : void 0,
				codeClassName: m ? Q.treeColumnRootCode : void 0
			})
		})
	] });
}
//#endregion
//#region src/tree-select/TreePickerBase.tsx
function Ae({ label: n, description: c, disabled: p, placeholder: m, size: b, nodes: x, selectedIds: S, partialIds: te, selectionMode: C, optionsLayout: T = "tree", defaultExpandedCodeKeys: E, open: ne, onOpenChange: ae, bulkActions: k, triggerMode: A = "display", selectedSummary: j, selectedSummaryText: M, query: oe, defaultQuery: se, onQuery: ce, onNodeActivate: le, onClearSelection: ue, isLoading: N, error: de }) {
	let P = y(null), F = y(null), pe = y(!1), [I, me] = ee(() => /* @__PURE__ */ new Map()), L = A === "search" ? C === "multi" ? "search-multi" : "search-single" : "display", R = v(() => fe(x), [x]), he = v(() => `${m} <${R.nodeById.size}>`, [m, R]), z = v(() => new Set(E), [E]), { query: B, setQuery: V } = u({
		open: !0,
		query: oe,
		defaultQuery: se,
		onQuery: ce,
		triggerMode: "display"
	}), { nodes: U, expandedIds: ge } = v(() => xe(x, B), [x, B]), W = v(() => ye(S, R), [S, R]), _e = v(() => be(R, z, I), [
		z,
		I,
		R
	]), ve = v(() => new Set([...R.childrenById].filter(([, e]) => e.length > 0).map(([e]) => e)), [R]), G = v(() => T === "columns" ? ve : /* @__PURE__ */ new Set([
		..._e,
		...ge,
		...W
	]), [
		ve,
		_e,
		T,
		ge,
		W
	]), K = v(() => Se(U, G), [U, G]), we = v(() => K.findIndex((e) => S.has(e.node.id)), [S, K]), q = v(() => Ce(K), [K]), Te = h((e) => {
		let t = Oe({
			...e,
			descriptor: q
		}), n = {};
		return t.placements.forEach((e, t) => {
			n[`--tree-option-${t}-column`] = String(e.column), n[`--tree-option-${t}-row`] = String(e.row);
		}), {
			width: `${t.width}px`,
			minWidth: `${t.minWidth}px`,
			maxWidth: `${t.width}px`,
			maxHeight: `${t.maxHeight}px`,
			"--tree-column-count": String(t.columnCount),
			"--tree-row-count": String(t.rowCount),
			...n
		};
	}, [q]), { open: J, activeIndex: Y, context: Ee, floatingStyles: X, getFloatingProps: De, setReference: Z, setFloating: Ae, setOptionRef: je, close: Me, openList: Ne, toggleOpen: Pe, selectOption: Fe, handleReferenceKeyDown: Ie, handleFloatingKeyDown: Le, getOptionId: Re, getActiveOptionId: ze } = o({
		options: K,
		selectedIndex: we,
		open: ne,
		onOpenChange: ae,
		onSelect: (e) => le(e.node),
		getOptionDisabled: (e) => e.node.disabled === !0,
		disabled: p || N,
		closeOnSelect: C === "single",
		allowOpenWithoutOptions: !0,
		triggerMode: L,
		placementStrategy: T === "columns" ? "auto" : "flip",
		resolveFloatingSize: T === "columns" ? Te : void 0
	}), Be = Ee.update, Ve = S.size > 0, He = A === "search" && (J || B.length > 0), Ue = He ? B : M ?? "", We = A === "display" && !!j, Ge = L === "search-multi" && !!j, Ke = L === "search-multi" && !Ve || L === "search-single" && (!M || He) || L === "display" && !Ve, $ = d({
		mode: L,
		open: J,
		currentQuery: B,
		hasDisplayValue: !!M,
		inputRef: P,
		setQuery: V,
		openList: Ne,
		close: Me,
		toggleOpen: Pe
	}), qe = T === "columns" && C === "multi" && k, Je = A === "display", Ye = qe || Je ? /* @__PURE__ */ O("div", {
		className: Q.treePopupHeader,
		children: [qe ? /* @__PURE__ */ D(i, {
			onSelectAll: k.onSelectAll,
			onDeselectAll: k.onDeselectAll,
			selectAllButtonRef: F
		}) : null, Je ? /* @__PURE__ */ D(t, {
			value: B,
			onChange: V,
			onClear: () => V(""),
			placeholder: "Поиск по дереву",
			onKeyDown: (e) => {
				e.key !== "Escape" && e.key !== "Tab" && e.stopPropagation();
			},
			onClick: (e) => {
				e.stopPropagation();
			}
		}) : null]
	}) : void 0;
	g(() => {
		pe.current && !J && $.policy.resetQueryOnClose && V(""), pe.current = J;
	}, [
		J,
		V,
		$.policy.resetQueryOnClose
	]), _(() => {
		J && T === "columns" && Be();
	}, [
		q.signature,
		J,
		T,
		Be
	]);
	let Xe = (e) => {
		P.current = e;
	}, Ze = () => {
		ue?.(), V(""), C === "single" && Me();
	}, Qe = (e) => {
		e.hasChildren && me((t) => {
			let n = new Map(t), r = t.get(e.node.id) ?? z.has(e.node.codeKey);
			return n.set(e.node.id, !r), n;
		});
	};
	return /* @__PURE__ */ D(l, {
		label: n,
		description: c,
		disabled: p,
		size: b,
		children: ({ controlId: t, labelId: i, describedBy: o }) => {
			let c = `${t}-listbox`, l = typeof n == "string" ? n : m;
			return /* @__PURE__ */ O(ie, { children: [/* @__PURE__ */ D(r, {
				ref: Xe,
				rootRef: Z,
				id: t,
				type: "text",
				role: "combobox",
				autoComplete: "off",
				disabled: p || N,
				readOnly: A !== "search",
				value: A === "display" && We ? "" : Ue,
				placeholder: Ke ? he : void 0,
				"aria-labelledby": i,
				"aria-label": i ? void 0 : m,
				"aria-describedby": o,
				"aria-haspopup": T === "columns" ? "dialog" : "listbox",
				"aria-expanded": J,
				"aria-controls": J ? c : void 0,
				"aria-autocomplete": T !== "columns" && A === "search" ? "list" : "none",
				"aria-activedescendant": T !== "columns" && J && K.length > 0 ? ze(c) : void 0,
				inputClassName: w(Ve && Q.treeSummary, We && Q.inputWithOverlay),
				overlay: We ? /* @__PURE__ */ D("div", {
					className: Q.valueOverlay,
					children: j
				}) : void 0,
				endAdornment: /* @__PURE__ */ O(s, {
					open: J,
					disabled: p || N,
					onToggleMouseDown: $.handleToggleMouseDown,
					onToggleClick: $.handleToggleClick,
					children: [Ge ? j : null, Ve && ue ? /* @__PURE__ */ D("button", {
						type: "button",
						className: Q.treeClearButton,
						onMouseDown: (e) => {
							e.preventDefault(), e.stopPropagation();
						},
						onClick: (e) => {
							e.preventDefault(), e.stopPropagation(), Ze();
						},
						"aria-label": "Очистить выбор",
						children: /* @__PURE__ */ D(re, {})
					}) : null]
				}),
				onChange: (e) => {
					A === "search" && $.handleTriggerInputChange(e.target.value);
				},
				onClick: $.handleTriggerClick,
				onFocus: (e) => {
					$.handleTriggerFocus(e.currentTarget);
				},
				onKeyDown: (e) => {
					if (T === "columns" && J && e.key === "Tab" && !e.shiftKey && F.current) {
						e.preventDefault(), F.current.focus();
						return;
					}
					Ie(e), !e.defaultPrevented && $.handleTriggerKeyDown({
						event: e,
						onActivateWhenOpen: () => {
							let e = Y >= 0 ? K[Y] : void 0;
							e && Fe(e);
						},
						enableSpaceActivation: A === "display"
					});
				}
			}), /* @__PURE__ */ D(a, {
				open: J,
				context: Ee,
				floatingStyles: X,
				listId: c,
				labelId: i,
				popupAriaLabel: l,
				descriptionId: o,
				activeOptionId: T !== "columns" && K.length > 0 ? ze(c) : void 0,
				ariaMultiselectable: T !== "columns" && C === "multi",
				popupRole: T === "columns" ? "dialog" : "listbox",
				setFloating: Ae,
				getFloatingProps: De,
				onKeyDown: Le,
				className: e.uiPopupOptions,
				layoutClassName: T === "columns" ? Q.treeColumnsPopupLayout : void 0,
				bodyClassName: "scrollable",
				header: Ye,
				children: /* @__PURE__ */ D("div", {
					className: w(T === "columns" && Q.treeColumns),
					children: K.length === 0 ? /* @__PURE__ */ D(f, {
						errorState: de,
						loadingState: N ? "Загрузка..." : void 0,
						emptyState: !de && !N ? "Нет данных" : void 0
					}) : K.map((e, t) => {
						let n = C === "multi" ? H(e.node.id, S, R) : S.has(e.node.id), r = C === "multi" && !n && te.has(e.node.id), i = t === Y, a = e.node.disabled === !0;
						return /* @__PURE__ */ D("div", {
							"data-ui": "tree-select-option",
							id: Re(c, t),
							ref: (e) => je(t, e),
							role: T === "columns" ? void 0 : "option",
							"aria-selected": T === "columns" ? void 0 : n,
							"aria-disabled": a || void 0,
							className: w(Q.treeRow, T === "columns" && Q.treeColumnRow, a && Q.treeRowDisabled, i && Q.treeRowActive, n && Q.treeRowSelected),
							style: T === "columns" ? {
								"--tree-option-column": `var(--tree-option-${t}-column, auto)`,
								"--tree-option-row": `var(--tree-option-${t}-row, auto)`
							} : void 0,
							onMouseDown: (e) => {
								e.preventDefault();
							},
							onClick: () => Fe(e),
							children: /* @__PURE__ */ D("div", {
								className: Q.treeNodeButton,
								children: /* @__PURE__ */ D(ke, {
									node: e.node,
									level: e.level,
									highlight: B,
									hasChildren: e.hasChildren,
									isExpanded: e.isExpanded,
									selected: n,
									partial: r,
									selectionMode: C,
									optionsLayout: T,
									onToggleExpand: () => Qe(e),
									onToggleSelection: () => Fe(e)
								})
							})
						}, e.node.id);
					})
				})
			})] });
		}
	});
}
//#endregion
//#region src/tree-select/TreeMultiSelect.tsx
function je(e, t) {
	if (e.size !== 0) {
		if (e.size === 1) {
			let n = t.nodeById.get([...e][0]);
			return n ? n.label : void 0;
		}
		return `${e.size} элементов`;
	}
}
function Me(e, t, n) {
	let r = I(e, n), i = I(t, n);
	return r.size === i.size && [...r].every((e) => i.has(e));
}
function Ne({ label: e, description: t, disabled: n, placeholder: r = "Выберите значения", size: i, nodes: a, value: o, onChange: s, query: l, defaultQuery: u, onQuery: d, isLoading: f, error: p, optionsLayout: h = "tree", defaultExpandedCodeKeys: g }) {
	let [_, y] = ee(!1), b = v(() => fe(a), [a]), { draftValue: x, setDraftValue: S, prepareOpen: te } = c({
		value: o,
		open: _,
		onCommit: s,
		isEqual: (e, t) => Me(e, t, b)
	}), C = _ ? x : o, w = v(() => I(C, b), [C, b]), T = v(() => ge(w, b), [w, b]), E = v(() => je(w, b), [w, b]);
	return /* @__PURE__ */ D(Ae, {
		label: e,
		description: t,
		disabled: n,
		placeholder: r,
		size: i,
		nodes: a,
		selectedIds: T.selectedIds,
		partialIds: T.partialIds,
		selectionMode: "multi",
		optionsLayout: h,
		defaultExpandedCodeKeys: g,
		open: _,
		onOpenChange: (e) => {
			e && !_ && te(), y(e);
		},
		bulkActions: {
			onSelectAll: () => {
				S(me(W(b), b));
			},
			onDeselectAll: () => S({})
		},
		triggerMode: "search",
		selectedSummary: E ? /* @__PURE__ */ D(m, { value: E }) : void 0,
		query: l,
		defaultQuery: u,
		onQuery: d,
		onNodeActivate: (e) => {
			S((t) => _e(t, e.id, b));
		},
		onClearSelection: () => {
			S({}), _ || s({});
		},
		isLoading: f,
		error: p
	});
}
//#endregion
//#region src/tree-select/ODataTreeMultiSelect.tsx
function Pe({ label: e, description: t, disabled: n, size: r, placeholder: i, query: a, defaultQuery: o, onQuery: s, optionsLayout: c, value: l, onChange: u, odata: d, segments: f, model: p, defaultExpandedCodeKeys: m }) {
	let h = P({
		odata: d,
		segments: f,
		model: p
	});
	return /* @__PURE__ */ D(Ne, {
		label: e,
		description: t,
		disabled: n || h.isLoading,
		size: r,
		placeholder: i ?? h.placeholder,
		nodes: h.nodes,
		value: l,
		onChange: u,
		query: a,
		defaultQuery: o,
		onQuery: s,
		optionsLayout: c,
		defaultExpandedCodeKeys: m,
		isLoading: h.isLoading,
		error: h.isError ? "Ошибка загрузки" : void 0
	});
}
//#endregion
//#region src/tree-select/TreeSelect.tsx
function Fe(e) {
	if (e) return e.code && e.code !== e.label ? `${e.label} · ${e.code}` : e.label;
}
function Ie({ label: e, description: t, disabled: n, placeholder: r = "Выберите значение", size: i, nodes: a, value: o, onChange: s, query: c, defaultQuery: l, onQuery: u, isLoading: d, error: f, clearable: p = !1, defaultExpandedCodeKeys: m }) {
	let h = v(() => fe(a), [a]), g = pe(o, h), _ = g ? h.nodeById.get(g) : void 0;
	return /* @__PURE__ */ D(Ae, {
		label: e,
		description: t,
		disabled: n,
		placeholder: r,
		size: i,
		nodes: a,
		selectedIds: g ? /* @__PURE__ */ new Set([g]) : /* @__PURE__ */ new Set(),
		partialIds: /* @__PURE__ */ new Set(),
		selectionMode: "single",
		defaultExpandedCodeKeys: m,
		triggerMode: "search",
		selectedSummaryText: Fe(_),
		query: c,
		defaultQuery: l,
		onQuery: u,
		onNodeActivate: (e) => s({
			codeKey: e.codeKey,
			value: e.value
		}),
		onClearSelection: p ? () => s(void 0) : void 0,
		isLoading: d,
		error: f
	});
}
//#endregion
//#region src/tree-select/ODataTreeSelect.tsx
function Le({ label: e, description: t, disabled: n, size: r, placeholder: i, query: a, defaultQuery: o, onQuery: s, value: c, onChange: l, odata: u, segments: d, model: f, clearable: p, defaultExpandedCodeKeys: m }) {
	let h = P({
		odata: u,
		segments: d,
		model: f
	});
	return /* @__PURE__ */ D(Ie, {
		label: e,
		description: t,
		disabled: n || h.isLoading,
		size: r,
		placeholder: i ?? h.placeholder,
		nodes: h.nodes,
		value: c,
		onChange: l,
		query: a,
		defaultQuery: o,
		onQuery: s,
		defaultExpandedCodeKeys: m,
		isLoading: h.isLoading,
		error: h.isError ? "Ошибка загрузки" : void 0,
		clearable: p
	});
}
//#endregion
export { Pe as ODataTreeMultiSelect, Le as ODataTreeSelect, Ne as TreeMultiSelect, Ie as TreeSelect, k as treeSelectValueToSelectedFilters };

//# sourceMappingURL=index.js.map