"use client";
import { createSplitProps } from "../../utils/create-split-props.js";
import { createTreeCollection } from "../collection/tree-collection.js";
import { useTreeView } from "../tree-view/use-tree-view.js";
import { getBranchValues } from "./get-branch-value.js";
import { useMemo } from "react";
import { getRootNode, nodeToString, nodeToValue } from "@zag-js/json-tree-utils";
//#region src/components/json-tree-view/use-json-tree-view.ts
var splitJsonTreeViewProps = createSplitProps();
var useJsonTreeView = (props) => {
	const [jsonTreeProps, localProps] = splitJsonTreeViewProps(props, [
		"maxPreviewItems",
		"collapseStringsAfterLength",
		"quotesOnKeys",
		"groupArraysAfterLength",
		"showNonenumerable"
	]);
	const { data, defaultExpandedDepth = 1, ...restProps } = localProps;
	const collection = useMemo(() => {
		return createTreeCollection({
			nodeToValue,
			nodeToString,
			rootNode: getRootNode(data)
		});
	}, [data]);
	return {
		...useTreeView({
			defaultExpandedValue: useMemo(() => {
				return defaultExpandedDepth != null ? getBranchValues(collection, defaultExpandedDepth) : void 0;
			}, [collection, defaultExpandedDepth]),
			...restProps,
			collection,
			typeahead: false
		}),
		options: jsonTreeProps
	};
};
//#endregion
export { useJsonTreeView };
