import { u as useFileNodesInSelectedDrive } from "./dist-DAY54QOk.js";
import { t as useGraphMetadata } from "./use-graph-metadata-C0FHs2qM.js";
import { useMemo } from "react";
//#region editors/knowledge-vault/hooks/use-knowledge-notes.ts
function useKnowledgeNotes() {
	const cachedFileNodes = useFileNodesInSelectedDrive();
	const { nodeMap, edges, fileNodes: serverFileNodes, allNodes: serverAllNodes, isLoading, error, refetch } = useGraphMetadata();
	const fileNodes = serverFileNodes.length > 0 ? serverFileNodes : cachedFileNodes ?? [];
	const knowledgeFileNodes = useMemo(() => fileNodes.filter((n) => n.documentType === "bai/knowledge-note"), [fileNodes]);
	const linksBySource = useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		for (const e of edges) {
			let arr = map.get(e.sourceDocumentId);
			if (!arr) {
				arr = [];
				map.set(e.sourceDocumentId, arr);
			}
			arr.push({
				id: e.id,
				targetDocumentId: e.targetDocumentId,
				targetTitle: e.targetTitle,
				linkType: e.linkType
			});
		}
		return map;
	}, [edges]);
	const notes = useMemo(() => {
		return knowledgeFileNodes.map((node) => {
			const meta = nodeMap.get(node.id);
			const links = linksBySource.get(node.id) ?? [];
			if (!meta) return {
				id: node.id,
				name: node.name,
				title: null,
				noteType: null,
				status: "DRAFT",
				description: null,
				topics: [],
				links,
				provenance: null
			};
			const topics = meta.topics.map((name, i) => ({
				id: `${node.id}-topic-${i}`,
				name
			}));
			return {
				id: node.id,
				name: node.name,
				title: meta.title,
				noteType: meta.noteType,
				status: meta.status ?? "DRAFT",
				description: meta.description,
				topics,
				links,
				provenance: meta.author || meta.sourceOrigin || meta.createdAt ? {
					author: meta.author,
					createdAt: meta.createdAt,
					updatedAt: meta.updatedAt
				} : null
			};
		});
	}, [
		knowledgeFileNodes,
		nodeMap,
		linksBySource
	]);
	return {
		notes,
		noteMap: useMemo(() => {
			const m = /* @__PURE__ */ new Map();
			for (const n of notes) m.set(n.id, n);
			return m;
		}, [notes]),
		serverFileNodes,
		serverAllNodes,
		isLoading,
		error,
		refetch
	};
}
//#endregion
export { useKnowledgeNotes as t };

//# sourceMappingURL=use-knowledge-notes-hOBUTNOF.js.map