"use client";
const require_get_size = require("../../core/utils/get-size/get-size.cjs");
const require_create_vars_resolver = require("../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs");
const require_use_props = require("../../core/MantineProvider/use-props/use-props.cjs");
const require_use_styles = require("../../core/styles-api/use-styles/use-styles.cjs");
const require_factory = require("../../core/factory/factory.cjs");
const require_Box = require("../../core/Box/Box.cjs");
const require_TreeNode = require("./TreeNode.cjs");
const require_use_tree = require("./use-tree.cjs");
const require_Tree_module = require("./Tree.module.cjs");
let react = require("react");
let _mantine_hooks = require("@mantine/hooks");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/components/Tree/Tree.tsx
function getFlatValues(data) {
	return data.reduce((acc, item) => {
		acc.push(item.value);
		if (item.children) acc.push(...getFlatValues(item.children));
		return acc;
	}, []);
}
const defaultProps = {
	expandOnClick: true,
	allowRangeSelection: true,
	expandOnSpace: true
};
const varsResolver = require_create_vars_resolver.createVarsResolver((_theme, { levelOffset }) => ({ root: { "--level-offset": require_get_size.getSpacing(levelOffset) } }));
const Tree = require_factory.factory((_props) => {
	const props = require_use_props.useProps("Tree", defaultProps, _props);
	const { classNames, className, style, styles, unstyled, vars, data, expandOnClick, tree, renderNode, selectOnClick, clearSelectionOnOutsideClick, allowRangeSelection, expandOnSpace, levelOffset, checkOnSpace, keepMounted, onDragDrop, allowDrop, withDragHandle, withLines, attributes, ref, ...others } = props;
	const defaultController = require_use_tree.useTree();
	const controller = tree || defaultController;
	const dragStateRef = (0, react.useRef)({
		draggedValue: null,
		currentDropTarget: null
	});
	const getStyles = require_use_styles.useStyles({
		name: "Tree",
		classes: require_Tree_module.default,
		props,
		className,
		style,
		classNames,
		styles,
		unstyled,
		attributes,
		vars,
		varsResolver
	});
	const mergedRef = (0, _mantine_hooks.useMergedRef)(ref, (0, _mantine_hooks.useClickOutside)(() => clearSelectionOnOutsideClick && controller.clearSelected()));
	const flatValues = (0, react.useMemo)(() => getFlatValues(data), [data]);
	(0, react.useEffect)(() => {
		controller.initialize(data);
	}, [data]);
	const nodes = data.map((node, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_TreeNode.TreeNode, {
		node,
		getStyles,
		rootIndex: index,
		expandOnClick,
		selectOnClick,
		controller,
		renderNode,
		flatValues,
		allowRangeSelection,
		expandOnSpace,
		checkOnSpace,
		keepMounted,
		onDragDrop,
		allowDrop,
		withDragHandle,
		dragStateRef,
		data
	}, node.value));
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Box.Box, {
		component: "ul",
		ref: mergedRef,
		...getStyles("root"),
		...others,
		role: "tree",
		"aria-multiselectable": controller.multiple,
		"data-tree-root": true,
		"data-with-lines": withLines || void 0,
		children: nodes
	});
});
Tree.displayName = "@mantine/core/Tree";
Tree.classes = require_Tree_module.default;
Tree.varsResolver = varsResolver;
//#endregion
exports.Tree = Tree;

//# sourceMappingURL=Tree.cjs.map