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

//# sourceMappingURL=index.js.map