"use client";
import { getChildrenNodesValues } from "../Tree/get-children-nodes-values/get-children-nodes-values.mjs";
import { getAllCheckedNodes } from "../Tree/get-all-checked-nodes/get-all-checked-nodes.mjs";
import { isNodeChecked } from "../Tree/is-node-checked/is-node-checked.mjs";
//#region packages/@mantine/core/src/components/TreeSelect/get-checked-values-by-strategy.ts
function expandToLeafChecked(value, data) {
	const leaves = /* @__PURE__ */ new Set();
	for (const v of value) for (const leaf of getChildrenNodesValues(v, data)) leaves.add(leaf);
	return Array.from(leaves);
}
function getTopmostCheckedParents(data, checkedState) {
	const result = [];
	for (const node of data) if (isNodeChecked(node.value, data, checkedState)) result.push(node.value);
	else if (Array.isArray(node.children) && node.children.length > 0) result.push(...getTopmostCheckedParents(node.children, checkedState));
	return result;
}
function checkedToValue(checkedState, data, strategy) {
	if (checkedState.length === 0) return [];
	switch (strategy) {
		case "child": return checkedState;
		case "all": return getAllCheckedNodes(data, checkedState).result.filter((n) => n.checked).map((n) => n.value);
		case "parent": return getTopmostCheckedParents(data, checkedState);
		default: return checkedState;
	}
}
//#endregion
export { checkedToValue, expandToLeafChecked };

//# sourceMappingURL=get-checked-values-by-strategy.mjs.map