"use client";
const require_use_tree_view_context = require("../tree-view/use-tree-view-context.cjs");
const require_tree_view_branch = require("../tree-view/tree-view-branch.cjs");
const require_tree_view_branch_content = require("../tree-view/tree-view-branch-content.cjs");
const require_tree_view_branch_control = require("../tree-view/tree-view-branch-control.cjs");
const require_tree_view_branch_indent_guide = require("../tree-view/tree-view-branch-indent-guide.cjs");
const require_tree_view_branch_indicator = require("../tree-view/tree-view-branch-indicator.cjs");
const require_tree_view_branch_text = require("../tree-view/tree-view-branch-text.cjs");
const require_tree_view_item = require("../tree-view/tree-view-item.cjs");
const require_tree_view_item_text = require("../tree-view/tree-view-item-text.cjs");
const require_tree_view_node_provider = require("../tree-view/tree-view-node-provider.cjs");
const require_json_tree_view_props_context = require("./json-tree-view-props-context.cjs");
const require_json_tree_view_key_node = require("./json-tree-view-key-node.cjs");
const require_json_tree_view_value_node = require("./json-tree-view-value-node.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
let _zag_js_json_tree_utils = require("@zag-js/json-tree-utils");
//#region src/components/json-tree-view/json-tree-view-node.tsx
var scopeProps = { "data-scope": "json-tree-view" };
function JsonTreeViewNode(props) {
	const { node, indexPath, arrow, indentGuide, renderValue } = props;
	const options = require_json_tree_view_props_context.useJsonTreeViewPropsContext();
	const nodeState = require_use_tree_view_context.useTreeViewContext().getNodeState({
		node,
		indexPath
	});
	const key = (0, _zag_js_json_tree_utils.keyPathToKey)(node.keyPath, { excludeRoot: true });
	const valueNode = (0, react.useMemo)(() => (0, _zag_js_json_tree_utils.jsonNodeToElement)(node, options), [node, options]);
	const nodeProps = (0, react.useMemo)(() => {
		const desc = (0, _zag_js_json_tree_utils.getAccessibleDescription)(node);
		const line = indexPath.reduce((acc, curr) => acc + curr, 1);
		const lineLength = indexPath.length - 1;
		return {
			...scopeProps,
			"aria-label": desc,
			"data-line": line,
			style: { ["--line-length"]: lineLength }
		};
	}, [indexPath, node]);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tree_view_node_provider.TreeViewNodeProvider, {
		node,
		indexPath,
		children: nodeState.isBranch ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tree_view_branch.TreeViewBranch, {
			...scopeProps,
			children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tree_view_branch_control.TreeViewBranchControl, {
				...nodeProps,
				children: [arrow && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tree_view_branch_indicator.TreeViewBranchIndicator, {
					...scopeProps,
					children: arrow
				}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tree_view_branch_text.TreeViewBranchText, {
					...scopeProps,
					children: [key && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_json_tree_view_key_node.JsonTreeViewKeyNode, {
						node,
						showQuotes: options.quotesOnKeys
					}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_json_tree_view_value_node.JsonTreeViewValueNode, {
						node: valueNode,
						renderValue
					})]
				})]
			}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tree_view_branch_content.TreeViewBranchContent, {
				...scopeProps,
				children: [typeof indentGuide === "boolean" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tree_view_branch_indent_guide.TreeViewBranchIndentGuide, {}) : indentGuide, node.children?.map((child, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(JsonTreeViewNode, {
					...props,
					node: child,
					indexPath: [...indexPath, index]
				}, index))]
			})]
		}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tree_view_item.TreeViewItem, {
			...nodeProps,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tree_view_item_text.TreeViewItemText, {
				...scopeProps,
				children: [key && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_json_tree_view_key_node.JsonTreeViewKeyNode, {
					node,
					showQuotes: options.quotesOnKeys
				}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_json_tree_view_value_node.JsonTreeViewValueNode, {
					node: valueNode,
					renderValue
				})]
			})
		})
	});
}
//#endregion
exports.JsonTreeViewNode = JsonTreeViewNode;
