import { B as generateId } from "./dist-RakiOObV.mjs";
import { a as setSelectedNode, s as useDocumentsInSelectedDrive, w as dispatchActions } from "./dist-DFMBprYi.mjs";
import { t as DocumentToolbar } from "./connect-B9rqkBQW.mjs";
import { g as actions } from "./module-Ch5VE2Fq.mjs";
import { i as useSelectedKnowledgeNoteDocument } from "./knowledge-note-ywm1-6i3.mjs";
import { t as TOOLBAR_CLASS } from "./theme-context-DeP5ztQx.mjs";
import { t as MarkdownPreview } from "./markdown-preview-CG0iT9BF.mjs";
import { t as useKnowledgeNotes } from "./use-knowledge-notes-jOCVOoPo.mjs";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
//#region editors/knowledge-note-editor/components/status-bar.tsx
const STATUS_STYLES = {
	DRAFT: "bg-amber-500/20 text-amber-300 border-amber-500/30",
	IN_REVIEW: "bg-blue-500/20 text-blue-300 border-blue-500/30",
	CANONICAL: "bg-emerald-500/20 text-emerald-300 border-emerald-500/30",
	ARCHIVED: "bg-gray-500/20 text-gray-400 border-gray-500/30"
};
const STATUS_LABELS = {
	DRAFT: "Draft",
	IN_REVIEW: "In Review",
	CANONICAL: "Canonical",
	ARCHIVED: "Archived"
};
const FLOW_HINT = {
	DRAFT: "Draft → In Review → Canonical",
	IN_REVIEW: "In Review → Canonical or → Draft",
	CANONICAL: "Canonical → Archived",
	ARCHIVED: "Archived → Draft"
};
function StatusBar({ status, provenanceAuthor, hasProvenance, onSubmitForReview, onApprove, onReject, onArchive, onRestore }) {
	const [form, setForm] = useState(null);
	const currentStatus = status ?? "DRAFT";
	const style = STATUS_STYLES[currentStatus] ?? STATUS_STYLES.DRAFT;
	const label = STATUS_LABELS[currentStatus] ?? currentStatus;
	function openForm(action) {
		setForm({
			action,
			actor: action === "approve" || action === "reject" ? "" : provenanceAuthor ?? "",
			comment: ""
		});
	}
	function handleSubmit(e) {
		e.preventDefault();
		if (!form) return;
		const actor = form.actor.trim();
		if (!actor) return;
		const id = generateId();
		const ts = (/* @__PURE__ */ new Date()).toISOString();
		const comment = form.comment.trim();
		switch (form.action) {
			case "submit":
				onSubmitForReview(id, actor, ts, comment || void 0);
				break;
			case "approve":
				onApprove(id, actor, ts, comment || void 0);
				break;
			case "reject":
				if (!comment) return;
				onReject(id, actor, ts, comment);
				break;
			case "archive":
				if (!comment) return;
				onArchive(id, actor, ts, comment);
				break;
			case "restore":
				onRestore(id, actor, ts, comment || void 0);
				break;
		}
		setForm(null);
	}
	const needsComment = form?.action === "reject" || form?.action === "archive";
	const needsReviewer = form?.action === "approve" || form?.action === "reject";
	const ACTION_LABELS = {
		submit: "Submit for Review",
		approve: "Approve",
		reject: "Reject",
		archive: "Archive",
		restore: "Restore to Draft"
	};
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-2",
		children: [/* @__PURE__ */ jsxs("div", {
			className: "flex items-center gap-3",
			children: [
				/* @__PURE__ */ jsx("span", {
					className: `inline-flex items-center rounded-full border px-3 py-1 text-xs font-semibold ${style}`,
					children: label
				}),
				!hasProvenance && currentStatus === "DRAFT" && /* @__PURE__ */ jsx("span", {
					className: "text-[10px] text-amber-400/70",
					children: "Set provenance first \\u2192"
				}),
				hasProvenance && currentStatus === "DRAFT" && !form && /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => openForm("submit"),
					className: "rounded bg-blue-600 px-3 py-1 text-xs font-medium text-white hover:bg-blue-700",
					children: "Submit for Review"
				}),
				currentStatus === "IN_REVIEW" && !form && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => openForm("approve"),
					className: "rounded bg-emerald-600 px-3 py-1 text-xs font-medium text-white hover:bg-emerald-700",
					children: "Approve"
				}), /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => openForm("reject"),
					className: "rounded bg-red-600 px-3 py-1 text-xs font-medium text-white hover:bg-red-700",
					children: "Reject"
				})] }),
				currentStatus === "CANONICAL" && !form && /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => openForm("archive"),
					className: "rounded bg-gray-600 px-3 py-1 text-xs font-medium text-white hover:bg-gray-700",
					children: "Archive"
				}),
				currentStatus === "ARCHIVED" && !form && /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => openForm("restore"),
					className: "rounded bg-amber-600 px-3 py-1 text-xs font-medium text-white hover:bg-amber-700",
					children: "Restore to Draft"
				}),
				/* @__PURE__ */ jsx("span", {
					className: "ml-auto text-[10px] text-gray-600",
					children: FLOW_HINT[currentStatus]
				})
			]
		}), form && /* @__PURE__ */ jsxs("form", {
			onSubmit: handleSubmit,
			className: "space-y-2 rounded-lg border border-white/10 bg-[#1e1e2e] p-3",
			children: [
				/* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-2",
					children: [/* @__PURE__ */ jsx("span", {
						className: "text-xs font-medium text-gray-400",
						children: ACTION_LABELS[form.action]
					}), needsReviewer && provenanceAuthor && /* @__PURE__ */ jsxs("span", {
						className: "text-[10px] text-amber-400/70",
						children: [
							"(must differ from author: ",
							provenanceAuthor,
							")"
						]
					})]
				}),
				/* @__PURE__ */ jsx("div", {
					className: "flex gap-2",
					children: /* @__PURE__ */ jsxs("div", {
						className: "flex-1 space-y-1.5",
						children: [/* @__PURE__ */ jsx("input", {
							type: "text",
							value: form.actor,
							onChange: (e) => setForm({
								...form,
								actor: e.target.value
							}),
							placeholder: needsReviewer ? "Reviewer name..." : "Actor name...",
							autoFocus: true,
							className: "w-full rounded border border-white/10 bg-[#11111b] px-2.5 py-1.5 text-xs text-gray-300 outline-none focus:border-[#cba6f7]/50"
						}), (needsComment || form.comment) && /* @__PURE__ */ jsx("input", {
							type: "text",
							value: form.comment,
							onChange: (e) => setForm({
								...form,
								comment: e.target.value
							}),
							placeholder: needsComment ? "Reason (required)..." : "Comment (optional)...",
							className: "w-full rounded border border-white/10 bg-[#11111b] px-2.5 py-1.5 text-xs text-gray-300 outline-none focus:border-[#cba6f7]/50"
						})]
					})
				}),
				/* @__PURE__ */ jsxs("div", {
					className: "flex justify-end gap-2",
					children: [/* @__PURE__ */ jsx("button", {
						type: "button",
						onClick: () => setForm(null),
						className: "rounded px-2.5 py-1 text-xs text-gray-500 hover:bg-white/5",
						children: "Cancel"
					}), /* @__PURE__ */ jsx("button", {
						type: "submit",
						disabled: !form.actor.trim() || needsComment && !form.comment.trim(),
						className: `rounded px-3 py-1 text-xs font-medium text-white disabled:opacity-40 ${{
							submit: "bg-blue-600 hover:bg-blue-700",
							approve: "bg-emerald-600 hover:bg-emerald-700",
							reject: "bg-red-600 hover:bg-red-700",
							archive: "bg-gray-600 hover:bg-gray-700",
							restore: "bg-amber-600 hover:bg-amber-700"
						}[form.action]}`,
						children: ACTION_LABELS[form.action]
					})]
				})
			]
		})]
	});
}
//#endregion
//#region editors/knowledge-note-editor/components/topics-bar.tsx
function TopicsBar({ topics, onAddTopic, onRemoveTopic }) {
	const [input, setInput] = useState("");
	function handleAdd() {
		const name = input.trim();
		if (!name) return;
		onAddTopic(generateId(), name);
		setInput("");
	}
	return /* @__PURE__ */ jsxs("div", {
		className: "flex flex-wrap items-center gap-2",
		children: [topics.map((topic) => /* @__PURE__ */ jsxs("span", {
			className: "group inline-flex items-center gap-1 rounded-full bg-[#cba6f7]/10 px-3 py-1 text-xs font-medium text-[#cba6f7]",
			children: [topic.name, /* @__PURE__ */ jsx("button", {
				type: "button",
				onClick: () => onRemoveTopic(topic.id),
				className: "ml-0.5 text-[#cba6f7]/40 opacity-0 transition-opacity hover:text-[#cba6f7] group-hover:opacity-100",
				"aria-label": `Remove topic ${topic.name}`,
				children: "×"
			})]
		}, topic.id)), /* @__PURE__ */ jsx("form", {
			className: "inline-flex",
			onSubmit: (e) => {
				e.preventDefault();
				handleAdd();
			},
			children: /* @__PURE__ */ jsx("input", {
				type: "text",
				value: input,
				onChange: (e) => setInput(e.target.value),
				placeholder: "Add topic...",
				className: "w-24 rounded-full border border-dashed border-white/10 bg-transparent px-3 py-1 text-xs text-gray-400 outline-none placeholder:text-gray-600 focus:border-[#cba6f7]/40"
			})
		})]
	});
}
//#endregion
//#region editors/knowledge-note-editor/components/links-section.tsx
const LINK_TYPES = [
	"RELATES_TO",
	"BUILDS_ON",
	"CONTRADICTS",
	"SUPERSEDES",
	"DERIVED_FROM"
];
const LINK_TYPE_LABELS = {
	RELATES_TO: "Relates to",
	BUILDS_ON: "Builds on",
	CONTRADICTS: "Contradicts",
	SUPERSEDES: "Supersedes",
	DERIVED_FROM: "Derived from"
};
const LINK_TYPE_COLORS = {
	RELATES_TO: "bg-slate-500/20 text-slate-300",
	BUILDS_ON: "bg-sky-500/20 text-sky-300",
	CONTRADICTS: "bg-red-500/20 text-red-300",
	SUPERSEDES: "bg-purple-500/20 text-purple-300",
	DERIVED_FROM: "bg-amber-500/20 text-amber-300"
};
function LinksSection({ links, currentDocId, onAddLink, onRemoveLink, onUpdateLinkType }) {
	const [isAdding, setIsAdding] = useState(false);
	const [editingLinkId, setEditingLinkId] = useState(null);
	const allDriveDocs = useDocumentsInSelectedDrive();
	const allDocs = useMemo(() => (allDriveDocs ?? []).filter((d) => d.header.documentType === "bai/knowledge-note"), [allDriveDocs]);
	const docOptions = useMemo(() => {
		const linkedIds = new Set(links.map((l) => l.targetDocumentId));
		return allDocs.filter((d) => d.header.id !== currentDocId && !linkedIds.has(d.header.id)).map((d) => ({
			id: d.header.id,
			title: d.state.global?.title ?? d.header.name ?? d.header.id
		}));
	}, [
		allDocs,
		currentDocId,
		links
	]);
	const allDocOptions = useMemo(() => {
		return allDocs.filter((d) => d.header.id !== currentDocId).map((d) => ({
			id: d.header.id,
			title: d.state.global?.title ?? d.header.name ?? d.header.id
		}));
	}, [allDocs, currentDocId]);
	function handleAdd(targetId, targetTitle, linkType) {
		onAddLink(generateId(), targetId, targetTitle, linkType);
		setIsAdding(false);
	}
	if (links.length === 0 && !isAdding) return /* @__PURE__ */ jsxs("div", {
		className: "rounded-lg border border-dashed border-white/10 p-4 text-center",
		children: [/* @__PURE__ */ jsx("p", {
			className: "mb-2 text-sm text-gray-500",
			children: "No linked notes yet"
		}), /* @__PURE__ */ jsx("button", {
			type: "button",
			onClick: () => setIsAdding(true),
			className: "text-sm font-medium text-[#cba6f7] hover:text-[#cba6f7]/80",
			children: "+ Add link"
		})]
	});
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-2",
		children: [links.map((link) => /* @__PURE__ */ jsx(LinkCard, {
			link,
			isEditing: editingLinkId === link.id,
			allDocOptions,
			onStartEdit: () => setEditingLinkId(link.id),
			onCancelEdit: () => setEditingLinkId(null),
			onUpdateLinkType,
			onRemoveLink,
			onChangeTarget: (targetId, targetTitle) => {
				onRemoveLink(link.id);
				onAddLink(generateId(), targetId, targetTitle, link.linkType ?? "RELATES_TO");
				setEditingLinkId(null);
			}
		}, link.id)), isAdding ? /* @__PURE__ */ jsx(AddLinkForm, {
			docOptions,
			onAdd: handleAdd,
			onCancel: () => setIsAdding(false)
		}) : /* @__PURE__ */ jsx("button", {
			type: "button",
			onClick: () => setIsAdding(true),
			className: "w-full rounded-lg border border-dashed border-white/10 py-1.5 text-xs text-gray-500 hover:border-[#cba6f7]/30 hover:text-[#cba6f7]",
			children: "+ Add link"
		})]
	});
}
function LinkCard({ link, isEditing, allDocOptions, onStartEdit, onCancelEdit, onUpdateLinkType, onRemoveLink, onChangeTarget }) {
	const editRef = useRef(null);
	useEffect(() => {
		if (!isEditing) return;
		function handleClickOutside(e) {
			if (editRef.current && !editRef.current.contains(e.target)) onCancelEdit();
		}
		document.addEventListener("mousedown", handleClickOutside);
		return () => document.removeEventListener("mousedown", handleClickOutside);
	}, [isEditing, onCancelEdit]);
	if (isEditing) return /* @__PURE__ */ jsxs("div", {
		ref: editRef,
		className: "rounded-lg border border-[#cba6f7]/20 bg-[#cba6f7]/5 p-2",
		children: [/* @__PURE__ */ jsx("p", {
			className: "mb-1.5 text-[10px] font-medium uppercase text-gray-500",
			children: "Change target document"
		}), /* @__PURE__ */ jsx(DocumentSearch, {
			options: allDocOptions,
			onSelect: (doc) => onChangeTarget(doc.id, doc.title),
			onCancel: onCancelEdit,
			autoFocus: true
		})]
	});
	return /* @__PURE__ */ jsxs("div", {
		className: "group flex items-center gap-2 rounded-lg border border-white/5 bg-[#1e1e2e] px-3 py-2",
		children: [
			/* @__PURE__ */ jsx("select", {
				value: link.linkType ?? "RELATES_TO",
				onChange: (e) => onUpdateLinkType(link.id, e.target.value),
				className: `rounded-md border-0 px-2 py-0.5 text-xs font-medium ${LINK_TYPE_COLORS[link.linkType ?? "RELATES_TO"] ?? ""} bg-transparent`,
				children: LINK_TYPES.map((lt) => /* @__PURE__ */ jsx("option", {
					value: lt,
					children: LINK_TYPE_LABELS[lt]
				}, lt))
			}),
			/* @__PURE__ */ jsxs("button", {
				type: "button",
				onClick: () => {
					if (link.targetDocumentId) setSelectedNode(link.targetDocumentId);
				},
				className: "flex-1 truncate text-left text-sm text-gray-300 hover:text-[#cba6f7] hover:underline",
				title: `Open: ${link.targetTitle || link.targetDocumentId || "Untitled"}`,
				children: [link.targetTitle || link.targetDocumentId || "Untitled", /* @__PURE__ */ jsxs("svg", {
					className: "ml-1 inline-block h-3 w-3 opacity-0 group-hover:opacity-50",
					viewBox: "0 0 24 24",
					fill: "none",
					stroke: "currentColor",
					strokeWidth: "2",
					children: [
						/* @__PURE__ */ jsx("path", { d: "M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6" }),
						/* @__PURE__ */ jsx("polyline", { points: "15 3 21 3 21 9" }),
						/* @__PURE__ */ jsx("line", {
							x1: "10",
							y1: "14",
							x2: "21",
							y2: "3"
						})
					]
				})]
			}),
			/* @__PURE__ */ jsx("button", {
				type: "button",
				onClick: onStartEdit,
				className: "text-gray-600 opacity-0 transition-opacity hover:text-[#cba6f7] group-hover:opacity-100",
				"aria-label": "Change target",
				title: "Change target document",
				children: /* @__PURE__ */ jsxs("svg", {
					className: "h-3.5 w-3.5",
					viewBox: "0 0 24 24",
					fill: "none",
					stroke: "currentColor",
					strokeWidth: "2",
					children: [/* @__PURE__ */ jsx("path", { d: "M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7" }), /* @__PURE__ */ jsx("path", { d: "M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z" })]
				})
			}),
			/* @__PURE__ */ jsx("button", {
				type: "button",
				onClick: () => onRemoveLink(link.id),
				className: "text-gray-600 opacity-0 transition-opacity hover:text-red-400 group-hover:opacity-100",
				"aria-label": "Remove link",
				children: "×"
			})
		]
	});
}
function AddLinkForm({ docOptions, onAdd, onCancel }) {
	const [selectedDoc, setSelectedDoc] = useState(null);
	const [manualTitle, setManualTitle] = useState("");
	const [manualId, setManualId] = useState("");
	const [linkType, setLinkType] = useState("RELATES_TO");
	const [mode, setMode] = useState("search");
	function handleSubmit() {
		if (mode === "search" && selectedDoc) onAdd(selectedDoc.id, selectedDoc.title, linkType);
		else if (mode === "manual" && manualTitle.trim()) onAdd(manualId.trim(), manualTitle.trim(), linkType);
	}
	const hasValue = mode === "search" ? !!selectedDoc : !!manualTitle.trim();
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-2 rounded-lg border border-[#cba6f7]/20 bg-[#cba6f7]/5 p-3",
		children: [
			/* @__PURE__ */ jsxs("div", {
				className: "flex gap-1",
				children: [/* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => setMode("search"),
					className: `rounded px-2 py-0.5 text-[10px] font-medium ${mode === "search" ? "bg-[#313244] text-[#cba6f7]" : "text-gray-500"}`,
					children: "Search drive"
				}), /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => setMode("manual"),
					className: `rounded px-2 py-0.5 text-[10px] font-medium ${mode === "manual" ? "bg-[#313244] text-[#cba6f7]" : "text-gray-500"}`,
					children: "Manual entry"
				})]
			}),
			mode === "search" ? /* @__PURE__ */ jsx("div", { children: selectedDoc ? /* @__PURE__ */ jsxs("div", {
				className: "flex items-center gap-2 rounded border border-white/10 bg-[#1e1e2e] px-3 py-1.5",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "flex-1 truncate text-sm text-gray-300",
						children: selectedDoc.title
					}),
					/* @__PURE__ */ jsx("span", {
						className: "text-[10px] font-mono text-gray-600",
						children: selectedDoc.id.slice(0, 8)
					}),
					/* @__PURE__ */ jsx("button", {
						type: "button",
						onClick: () => setSelectedDoc(null),
						className: "text-gray-500 hover:text-red-400",
						children: "×"
					})
				]
			}) : /* @__PURE__ */ jsx(DocumentSearch, {
				options: docOptions,
				onSelect: setSelectedDoc,
				onCancel,
				autoFocus: true
			}) }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("input", {
				type: "text",
				value: manualTitle,
				onChange: (e) => setManualTitle(e.target.value),
				placeholder: "Link title...",
				autoFocus: true,
				className: "w-full rounded border border-white/10 bg-[#1e1e2e] px-3 py-1.5 text-sm text-gray-300 outline-none focus:border-[#cba6f7]/50"
			}), /* @__PURE__ */ jsx("input", {
				type: "text",
				value: manualId,
				onChange: (e) => setManualId(e.target.value),
				placeholder: "Document PHID (optional)",
				className: "w-full rounded border border-white/10 bg-[#1e1e2e] px-3 py-1.5 text-sm font-mono text-gray-400 outline-none focus:border-[#cba6f7]/50"
			})] }),
			/* @__PURE__ */ jsxs("div", {
				className: "flex items-center gap-2",
				children: [
					/* @__PURE__ */ jsx("select", {
						value: linkType,
						onChange: (e) => setLinkType(e.target.value),
						className: "rounded border border-white/10 bg-[#1e1e2e] px-2 py-1.5 text-sm text-gray-300",
						children: LINK_TYPES.map((lt) => /* @__PURE__ */ jsx("option", {
							value: lt,
							children: LINK_TYPE_LABELS[lt]
						}, lt))
					}),
					/* @__PURE__ */ jsx("div", { className: "flex-1" }),
					/* @__PURE__ */ jsx("button", {
						type: "button",
						onClick: onCancel,
						className: "rounded px-3 py-1 text-xs text-gray-500 hover:bg-white/5",
						children: "Cancel"
					}),
					/* @__PURE__ */ jsx("button", {
						type: "button",
						onClick: handleSubmit,
						disabled: !hasValue,
						className: "rounded bg-[#cba6f7] px-3 py-1 text-xs font-medium text-[#1e1e2e] hover:bg-[#cba6f7]/80 disabled:opacity-40",
						children: "Add"
					})
				]
			})
		]
	});
}
function DocumentSearch({ options, onSelect, onCancel, autoFocus }) {
	const [query, setQuery] = useState("");
	const [isOpen, setIsOpen] = useState(true);
	const inputRef = useRef(null);
	const containerRef = useRef(null);
	const filtered = useMemo(() => {
		if (!query.trim()) return options.slice(0, 20);
		const q = query.toLowerCase();
		return options.filter((d) => d.title.toLowerCase().includes(q) || d.id.toLowerCase().includes(q)).slice(0, 20);
	}, [options, query]);
	useEffect(() => {
		if (autoFocus) inputRef.current?.focus();
	}, [autoFocus]);
	useEffect(() => {
		function handleClickOutside(e) {
			if (containerRef.current && !containerRef.current.contains(e.target)) setIsOpen(false);
		}
		document.addEventListener("mousedown", handleClickOutside);
		return () => document.removeEventListener("mousedown", handleClickOutside);
	}, []);
	return /* @__PURE__ */ jsxs("div", {
		ref: containerRef,
		className: "relative",
		children: [
			/* @__PURE__ */ jsx("input", {
				ref: inputRef,
				type: "text",
				value: query,
				onChange: (e) => {
					setQuery(e.target.value);
					setIsOpen(true);
				},
				onFocus: () => setIsOpen(true),
				onKeyDown: (e) => {
					if (e.key === "Escape") onCancel();
				},
				placeholder: "Search notes by title...",
				className: "w-full rounded border border-white/10 bg-[#1e1e2e] px-3 py-1.5 text-sm text-gray-300 outline-none focus:border-[#cba6f7]/50"
			}),
			isOpen && filtered.length > 0 && /* @__PURE__ */ jsx("div", {
				className: "absolute z-10 mt-1 max-h-48 w-full overflow-y-auto rounded-lg border border-white/10 bg-[#181825] shadow-xl",
				children: filtered.map((doc) => /* @__PURE__ */ jsxs("button", {
					type: "button",
					onClick: () => {
						onSelect(doc);
						setIsOpen(false);
						setQuery("");
					},
					className: "flex w-full items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-[#313244]",
					children: [/* @__PURE__ */ jsx("span", {
						className: "flex-1 truncate text-sm text-gray-300",
						children: doc.title
					}), /* @__PURE__ */ jsx("span", {
						className: "shrink-0 text-[10px] font-mono text-gray-600",
						children: doc.id.slice(0, 8)
					})]
				}, doc.id))
			}),
			isOpen && query.trim() && filtered.length === 0 && /* @__PURE__ */ jsx("div", {
				className: "absolute z-10 mt-1 w-full rounded-lg border border-white/10 bg-[#181825] px-3 py-2 shadow-xl",
				children: /* @__PURE__ */ jsx("p", {
					className: "text-xs text-gray-500",
					children: "No matching notes found"
				})
			})
		]
	});
}
//#endregion
//#region editors/knowledge-note-editor/components/provenance-info.tsx
const SOURCE_OPTIONS = [
	{
		value: "MANUAL",
		label: "Manual"
	},
	{
		value: "SESSION_MINE",
		label: "Session Mine"
	},
	{
		value: "IMPORT",
		label: "Import"
	},
	{
		value: "DERIVED",
		label: "Derived"
	}
];
const SOURCE_LABELS = {
	MANUAL: "Manual",
	SESSION_MINE: "Session Mine",
	IMPORT: "Import",
	DERIVED: "Derived"
};
function ProvenanceInfo({ provenance, onSetProvenance }) {
	const [isEditing, setIsEditing] = useState(false);
	const [author, setAuthor] = useState("");
	const [sourceOrigin, setSourceOrigin] = useState("MANUAL");
	function handleSubmit(e) {
		e.preventDefault();
		const trimmed = author.trim();
		if (!trimmed) return;
		onSetProvenance(trimmed, sourceOrigin);
		setIsEditing(false);
		setAuthor("");
	}
	if (!provenance && !isEditing) return /* @__PURE__ */ jsxs("div", {
		className: "rounded-lg border border-dashed border-white/10 p-3 text-center",
		children: [/* @__PURE__ */ jsx("p", {
			className: "mb-2 text-xs text-gray-500",
			children: "No provenance set"
		}), /* @__PURE__ */ jsx("button", {
			type: "button",
			onClick: () => setIsEditing(true),
			className: "text-xs font-medium text-[#cba6f7] hover:text-[#cba6f7]/80",
			children: "Set provenance"
		})]
	});
	if (isEditing) return /* @__PURE__ */ jsxs("form", {
		onSubmit: handleSubmit,
		className: "space-y-2 rounded-lg border border-[#cba6f7]/20 bg-[#cba6f7]/5 p-3",
		children: [
			/* @__PURE__ */ jsxs("label", {
				className: "block text-xs",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-500",
					children: "Author"
				}), /* @__PURE__ */ jsx("input", {
					type: "text",
					value: author,
					onChange: (e) => setAuthor(e.target.value),
					placeholder: "Author name...",
					autoFocus: true,
					className: "mt-1 w-full rounded border border-white/10 bg-[#1e1e2e] px-2 py-1.5 text-xs text-gray-300 outline-none focus:border-[#cba6f7]/50"
				})]
			}),
			/* @__PURE__ */ jsxs("label", {
				className: "block text-xs",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-500",
					children: "Source origin"
				}), /* @__PURE__ */ jsx("select", {
					value: sourceOrigin,
					onChange: (e) => setSourceOrigin(e.target.value),
					className: "mt-1 w-full rounded border border-white/10 bg-[#1e1e2e] px-2 py-1.5 text-xs text-gray-300 outline-none focus:border-[#cba6f7]/50",
					children: SOURCE_OPTIONS.map((opt) => /* @__PURE__ */ jsx("option", {
						value: opt.value,
						children: opt.label
					}, opt.value))
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex justify-end gap-2 pt-1",
				children: [/* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => setIsEditing(false),
					className: "rounded px-2.5 py-1 text-xs text-gray-500 hover:bg-white/5",
					children: "Cancel"
				}), /* @__PURE__ */ jsx("button", {
					type: "submit",
					className: "rounded bg-[#cba6f7] px-2.5 py-1 text-xs font-medium text-[#1e1e2e] hover:bg-[#cba6f7]/80",
					children: "Save"
				})]
			})
		]
	});
	const createdDate = provenance?.createdAt ? new Date(provenance.createdAt).toLocaleDateString() : "Unknown";
	const updatedDate = provenance?.updatedAt ? new Date(provenance.updatedAt).toLocaleDateString() : "Unknown";
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-1.5 text-xs text-gray-400",
		children: [
			/* @__PURE__ */ jsxs("div", {
				className: "flex justify-between",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-600",
					children: "Author"
				}), /* @__PURE__ */ jsx("span", {
					className: "font-medium text-gray-300",
					children: provenance?.author ?? "Unknown"
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex justify-between",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-600",
					children: "Source"
				}), /* @__PURE__ */ jsx("span", { children: SOURCE_LABELS[provenance?.sourceOrigin] ?? provenance?.sourceOrigin })]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex justify-between",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-600",
					children: "Created"
				}), /* @__PURE__ */ jsx("span", { children: createdDate })]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "flex justify-between",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-600",
					children: "Updated"
				}), /* @__PURE__ */ jsx("span", { children: updatedDate })]
			}),
			provenance?.sessionId && /* @__PURE__ */ jsxs("div", {
				className: "flex justify-between",
				children: [/* @__PURE__ */ jsx("span", {
					className: "text-gray-600",
					children: "Session"
				}), /* @__PURE__ */ jsx("span", {
					className: "max-w-[120px] truncate font-mono",
					title: provenance.sessionId,
					children: provenance.sessionId
				})]
			})
		]
	});
}
//#endregion
//#region editors/knowledge-note-editor/components/lifecycle-timeline.tsx
const STATUS_DOT = {
	DRAFT: "bg-amber-400",
	IN_REVIEW: "bg-blue-400",
	CANONICAL: "bg-emerald-400",
	ARCHIVED: "bg-gray-500"
};
function LifecycleTimeline({ events }) {
	if (events.length === 0) return /* @__PURE__ */ jsx("p", {
		className: "py-2 text-center text-xs text-gray-600",
		children: "No lifecycle events yet"
	});
	return /* @__PURE__ */ jsx("div", {
		className: "space-y-0",
		children: events.map((event, i) => {
			const isLast = i === events.length - 1;
			const date = event.timestamp ? new Date(event.timestamp).toLocaleString() : "";
			return /* @__PURE__ */ jsxs("div", {
				className: "flex gap-3",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex flex-col items-center",
					children: [/* @__PURE__ */ jsx("div", { className: `mt-1 h-2.5 w-2.5 rounded-full ${STATUS_DOT[event.toStatus ?? "DRAFT"]}` }), !isLast && /* @__PURE__ */ jsx("div", { className: "w-px flex-1 bg-white/10" })]
				}), /* @__PURE__ */ jsxs("div", {
					className: "pb-3",
					children: [
						/* @__PURE__ */ jsxs("p", {
							className: "text-xs font-medium text-gray-300",
							children: [
								event.fromStatus,
								" → ",
								event.toStatus
							]
						}),
						/* @__PURE__ */ jsxs("p", {
							className: "text-xs text-gray-500",
							children: [
								event.actor,
								" · ",
								date
							]
						}),
						event.comment && /* @__PURE__ */ jsxs("p", {
							className: "mt-0.5 text-xs italic text-gray-600",
							children: [
								"“",
								event.comment,
								"”"
							]
						})
					]
				})]
			}, event.id);
		})
	});
}
//#endregion
//#region editors/knowledge-note-editor/components/metadata-panel.tsx
const STRING_FIELDS = [
	{
		key: "scope",
		label: "Scope",
		placeholder: "e.g. global, team, personal"
	},
	{
		key: "confidence",
		label: "Confidence",
		placeholder: "e.g. high, medium, low"
	},
	{
		key: "severity",
		label: "Severity",
		placeholder: "e.g. critical, warning, info"
	},
	{
		key: "context",
		label: "Context",
		placeholder: "e.g. onboarding, deployment"
	},
	{
		key: "model",
		label: "Model",
		placeholder: "e.g. reducer, hook, component"
	},
	{
		key: "modelId",
		label: "Model ID",
		placeholder: "e.g. bai/knowledge-note"
	},
	{
		key: "version",
		label: "Version",
		placeholder: "e.g. v0.1, 1.2.0"
	},
	{
		key: "filePath",
		label: "File Path",
		placeholder: "e.g. src/reducers/content.ts"
	},
	{
		key: "editor",
		label: "Editor",
		placeholder: "Who last edited this note"
	},
	{
		key: "decisionStatus",
		label: "Decision Status",
		placeholder: "e.g. proposed, accepted, rejected"
	},
	{
		key: "sourceType",
		label: "Source Type",
		placeholder: "e.g. API, hook, event"
	},
	{
		key: "targetType",
		label: "Target Type",
		placeholder: "e.g. component, service"
	},
	{
		key: "relationType",
		label: "Relation Type",
		placeholder: "e.g. depends-on, extends"
	},
	{
		key: "cardinality",
		label: "Cardinality",
		placeholder: "e.g. one-to-many, many-to-many"
	},
	{
		key: "computes",
		label: "Computes",
		placeholder: "What this note derives"
	},
	{
		key: "errorMessage",
		label: "Error Message",
		placeholder: "Error text if applicable"
	},
	{
		key: "rootCause",
		label: "Root Cause",
		placeholder: "Underlying cause of an issue"
	},
	{
		key: "correctPattern",
		label: "Correct Pattern",
		placeholder: "The right way to do it"
	}
];
const LIST_FIELDS = [
	{
		key: "models",
		label: "Models",
		placeholder: "Add model..."
	},
	{
		key: "modules",
		label: "Modules",
		placeholder: "Add module..."
	},
	{
		key: "hooksUsed",
		label: "Hooks Used",
		placeholder: "Add hook..."
	},
	{
		key: "dispatchTargets",
		label: "Dispatch Targets",
		placeholder: "Add target..."
	},
	{
		key: "inputs",
		label: "Inputs",
		placeholder: "Add input..."
	},
	{
		key: "outputs",
		label: "Outputs",
		placeholder: "Add output..."
	},
	{
		key: "consumedBy",
		label: "Consumed By",
		placeholder: "Add consumer..."
	},
	{
		key: "alternatives",
		label: "Alternatives",
		placeholder: "Add alternative..."
	},
	{
		key: "consequences",
		label: "Consequences",
		placeholder: "Add consequence..."
	}
];
function MetadataPanel({ state, onSetField, onSetListField }) {
	const [expanded, setExpanded] = useState(false);
	const populatedStringFields = STRING_FIELDS.filter((f) => state[f.key] != null);
	const populatedListFields = LIST_FIELDS.filter((f) => {
		const v = state[f.key];
		return Array.isArray(v) && v.length > 0;
	});
	return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("button", {
		type: "button",
		onClick: () => setExpanded(!expanded),
		className: "flex w-full items-center justify-between text-xs font-semibold uppercase tracking-wider text-gray-500",
		children: [/* @__PURE__ */ jsxs("span", { children: ["Metadata", (populatedStringFields.length > 0 || populatedListFields.length > 0) && /* @__PURE__ */ jsxs("span", {
			className: "font-normal text-gray-600",
			children: [
				" ",
				"(",
				populatedStringFields.length + populatedListFields.length,
				")"
			]
		})] }), /* @__PURE__ */ jsx("span", {
			className: "text-gray-600",
			children: expanded ? "▲" : "▼"
		})]
	}), expanded && /* @__PURE__ */ jsxs("div", {
		className: "mt-3 space-y-3",
		children: [
			/* @__PURE__ */ jsx("div", {
				className: "space-y-2",
				children: STRING_FIELDS.map((f) => /* @__PURE__ */ jsx(MetadataStringField, {
					label: f.label,
					placeholder: f.placeholder,
					value: state[f.key],
					onChange: (v) => onSetField(f.key, v)
				}, f.key))
			}),
			/* @__PURE__ */ jsx("hr", { className: "border-white/10" }),
			/* @__PURE__ */ jsx("div", {
				className: "space-y-2",
				children: LIST_FIELDS.map((f) => /* @__PURE__ */ jsx(MetadataListField, {
					label: f.label,
					placeholder: f.placeholder,
					values: state[f.key] ?? [],
					onChange: (v) => onSetListField(f.key, v)
				}, f.key))
			})
		]
	})] });
}
function MetadataStringField({ label, value, placeholder, onChange }) {
	return /* @__PURE__ */ jsxs("label", {
		className: "block text-xs",
		children: [/* @__PURE__ */ jsx("span", {
			className: "mb-0.5 block text-gray-600",
			children: label
		}), /* @__PURE__ */ jsx("input", {
			type: "text",
			defaultValue: value ?? "",
			placeholder,
			onBlur: (e) => onChange(e.target.value || null),
			className: "w-full rounded border border-white/10 bg-[#11111b] px-2 py-1 text-xs text-gray-300 outline-none placeholder:text-gray-700 focus:border-[#cba6f7]/50"
		})]
	});
}
function MetadataListField({ label, values, placeholder, onChange }) {
	const [input, setInput] = useState("");
	function handleAdd() {
		const t = input.trim();
		if (!t) return;
		onChange([...values, t]);
		setInput("");
	}
	function handleRemove(index) {
		onChange(values.filter((_, i) => i !== index));
	}
	return /* @__PURE__ */ jsxs("div", {
		className: "text-xs",
		children: [/* @__PURE__ */ jsx("span", {
			className: "text-gray-600",
			children: label
		}), /* @__PURE__ */ jsxs("div", {
			className: "mt-1 flex flex-wrap gap-1",
			children: [values.map((v, i) => /* @__PURE__ */ jsxs("span", {
				className: "group inline-flex items-center gap-0.5 rounded bg-[#313244] px-1.5 py-0.5 text-gray-400",
				children: [v, /* @__PURE__ */ jsx("button", {
					type: "button",
					onClick: () => handleRemove(i),
					className: "text-gray-600 opacity-0 hover:text-red-400 group-hover:opacity-100",
					children: "×"
				})]
			}, `${v}-${i}`)), /* @__PURE__ */ jsx("form", {
				className: "inline-flex",
				onSubmit: (e) => {
					e.preventDefault();
					handleAdd();
				},
				children: /* @__PURE__ */ jsx("input", {
					type: "text",
					value: input,
					onChange: (e) => setInput(e.target.value),
					placeholder,
					className: "w-28 rounded border border-dashed border-white/10 bg-transparent px-1.5 py-0.5 text-xs text-gray-400 outline-none placeholder:text-gray-700 focus:border-[#cba6f7]/40"
				})
			})]
		})]
	});
}
//#endregion
//#region editors/knowledge-note-editor/editor.tsx
const NOTE_TYPES = [
	"concept",
	"decision",
	"pattern",
	"observation",
	"procedure",
	"architecture",
	"bug-pattern",
	"integration",
	"workflow",
	"reference"
];
function timestamp() {
	return (/* @__PURE__ */ new Date()).toISOString();
}
function Editor() {
	const [document, dispatch] = useSelectedKnowledgeNoteDocument();
	const [activeTab, setActiveTab] = useState("content");
	const [contentMode, setContentMode] = useState("preview");
	const { noteMap } = useKnowledgeNotes();
	const links = useMemo(() => {
		if (!document) return [];
		return noteMap.get(document.header.id)?.links ?? [];
	}, [noteMap, document]);
	if (!document || !dispatch) return /* @__PURE__ */ jsx("div", {
		className: "flex h-full items-center justify-center",
		style: { color: "var(--bai-text-faint)" },
		children: /* @__PURE__ */ jsxs("div", {
			className: "text-center text-sm",
			children: [/* @__PURE__ */ jsx("div", { children: "Loading note…" }), /* @__PURE__ */ jsx("div", {
				className: "mt-1 text-[11px]",
				children: "If this persists, the document may not have synced from the reactor yet — try refreshing."
			})]
		})
	});
	const state = document.state.global;
	const handleSetTitle = useCallback((title) => {
		if (title && title !== state.title) dispatch(actions.setTitle({
			title,
			updatedAt: timestamp()
		}));
	}, [dispatch, state.title]);
	const handleSetDescription = useCallback((description) => {
		if (description !== (state.description ?? "")) dispatch(actions.setDescription({
			description,
			updatedAt: timestamp()
		}));
	}, [dispatch, state.description]);
	const handleSetNoteType = useCallback((noteType) => {
		dispatch(actions.setNoteType({
			noteType,
			updatedAt: timestamp()
		}));
	}, [dispatch]);
	const handleSetContent = useCallback((content) => {
		dispatch(actions.setContent({
			content,
			updatedAt: timestamp()
		}));
	}, [dispatch]);
	const handleSetMetadataField = useCallback((field, value) => {
		dispatch(actions.setMetadataField({
			field,
			value: value ?? void 0,
			updatedAt: timestamp()
		}));
	}, [dispatch]);
	const handleSetMetadataListField = useCallback((field, values) => {
		dispatch(actions.setMetadataListField({
			field,
			values,
			updatedAt: timestamp()
		}));
	}, [dispatch]);
	return /* @__PURE__ */ jsx("div", {
		className: "min-h-screen",
		style: {
			backgroundColor: "var(--bai-bg)",
			color: "var(--bai-text)"
		},
		children: /* @__PURE__ */ jsxs("div", {
			className: "mx-auto max-w-6xl",
			children: [/* @__PURE__ */ jsx(DocumentToolbar, { toolbarClassName: TOOLBAR_CLASS }), /* @__PURE__ */ jsxs("div", {
				className: "flex gap-6 p-6 pb-12",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "min-w-0 flex-1 space-y-5 rounded-xl p-6",
					style: {
						backgroundColor: "var(--bai-surface)",
						border: "1px solid var(--bai-border)"
					},
					children: [
						/* @__PURE__ */ jsxs("div", {
							className: "space-y-3",
							children: [/* @__PURE__ */ jsx(StatusBar, {
								status: state.status ?? null,
								provenanceAuthor: state.provenance?.author ?? null,
								hasProvenance: !!state.provenance,
								onSubmitForReview: (id, actor, ts, comment) => dispatch(actions.submitForReview({
									id,
									actor,
									timestamp: ts,
									comment
								})),
								onApprove: (id, actor, ts, comment) => dispatch(actions.approveNote({
									id,
									actor,
									timestamp: ts,
									comment
								})),
								onReject: (id, actor, ts, comment) => dispatch(actions.rejectNote({
									id,
									actor,
									timestamp: ts,
									comment
								})),
								onArchive: (id, actor, ts, comment) => dispatch(actions.archiveNote({
									id,
									actor,
									timestamp: ts,
									comment
								})),
								onRestore: (id, actor, ts, comment) => dispatch(actions.restoreNote({
									id,
									actor,
									timestamp: ts,
									comment
								}))
							}), /* @__PURE__ */ jsx("textarea", {
								defaultValue: state.title ?? "",
								placeholder: "Untitled Note",
								onBlur: (e) => handleSetTitle(e.target.value.trim()),
								onKeyDown: (e) => {
									if (e.key === "Enter" && !e.shiftKey) e.currentTarget.blur();
								},
								onInput: (e) => {
									const el = e.currentTarget;
									el.style.height = "auto";
									el.style.height = `${el.scrollHeight}px`;
								},
								ref: (el) => {
									if (el) {
										el.style.height = "auto";
										el.style.height = `${el.scrollHeight}px`;
									}
								},
								rows: 1,
								className: "w-full resize-y border-0 bg-transparent text-2xl font-bold leading-snug outline-none",
								style: {
									color: "var(--bai-text)",
									overflow: "hidden"
								}
							})]
						}),
						/* @__PURE__ */ jsx("textarea", {
							defaultValue: state.description ?? "",
							placeholder: "Brief description (max 200 chars)...",
							maxLength: 200,
							rows: 2,
							onBlur: (e) => handleSetDescription(e.target.value.trim()),
							className: "w-full resize-none rounded-lg px-3 py-2 text-sm outline-none placeholder:opacity-50 focus:border-[#cba6f7]/50",
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsxs("div", {
							className: "flex items-center gap-3",
							children: [
								/* @__PURE__ */ jsxs("select", {
									value: state.noteType ?? "",
									onChange: (e) => handleSetNoteType(e.target.value),
									className: "rounded-lg px-3 py-1.5 text-sm outline-none focus:border-[#cba6f7]/50",
									style: {
										backgroundColor: "var(--bai-bg)",
										color: "var(--bai-text-secondary)",
										border: "1px solid var(--bai-border)"
									},
									children: [/* @__PURE__ */ jsx("option", {
										value: "",
										disabled: true,
										children: "Note type..."
									}), NOTE_TYPES.map((t) => /* @__PURE__ */ jsx("option", {
										value: t,
										children: t
									}, t))]
								}),
								/* @__PURE__ */ jsx("div", {
									className: "h-4 w-px",
									style: { backgroundColor: "var(--bai-border)" }
								}),
								/* @__PURE__ */ jsx(TopicsBar, {
									topics: state.topics,
									onAddTopic: (id, name) => dispatch(actions.addTopic({
										id,
										name
									})),
									onRemoveTopic: (id) => dispatch(actions.removeTopic({ id }))
								})
							]
						}),
						/* @__PURE__ */ jsx("div", {
							className: "flex gap-1",
							style: { borderBottom: "1px solid var(--bai-border)" },
							children: [
								["content", "Content"],
								["links", "Links"],
								["history", "History"]
							].map(([key, label]) => /* @__PURE__ */ jsxs("button", {
								type: "button",
								onClick: () => setActiveTab(key),
								className: `border-b-2 px-4 py-2 text-sm font-medium transition-colors ${activeTab === key ? "border-[#cba6f7] text-[#cba6f7]" : "border-transparent hover:border-gray-600"}`,
								style: activeTab === key ? void 0 : { color: "var(--bai-text-muted)" },
								children: [label, key === "links" && links.length > 0 && /* @__PURE__ */ jsx("span", {
									className: "ml-1.5 rounded-full px-1.5 py-0.5 text-xs",
									style: {
										backgroundColor: "var(--bai-hover)",
										color: "var(--bai-text-tertiary)"
									},
									children: links.length
								})]
							}, key))
						}),
						activeTab === "content" && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
							className: "mb-3 flex gap-1",
							children: [/* @__PURE__ */ jsx("button", {
								type: "button",
								onClick: () => setContentMode("preview"),
								className: "rounded px-2.5 py-1 text-xs font-medium transition-colors",
								style: contentMode === "preview" ? {
									backgroundColor: "var(--bai-hover)",
									color: "var(--bai-accent)"
								} : { color: "var(--bai-text-muted)" },
								children: "Preview"
							}), /* @__PURE__ */ jsx("button", {
								type: "button",
								onClick: () => setContentMode("edit"),
								className: "rounded px-2.5 py-1 text-xs font-medium transition-colors",
								style: contentMode === "edit" ? {
									backgroundColor: "var(--bai-hover)",
									color: "var(--bai-accent)"
								} : { color: "var(--bai-text-muted)" },
								children: "Edit"
							})]
						}), contentMode === "preview" ? /* @__PURE__ */ jsx("div", {
							className: "min-h-[400px] cursor-text rounded-lg px-4 py-3",
							style: {
								backgroundColor: "var(--bai-deep)",
								border: "1px solid var(--bai-border)"
							},
							onClick: () => setContentMode("edit"),
							children: state.content ? /* @__PURE__ */ jsx(MarkdownPreview, { content: state.content }) : /* @__PURE__ */ jsx("p", {
								className: "text-sm italic",
								style: { color: "var(--bai-text-faint)" },
								children: "Click to start writing..."
							})
						}) : /* @__PURE__ */ jsx("textarea", {
							defaultValue: state.content ?? "",
							placeholder: "Write your note content here... (supports markdown)",
							rows: 20,
							autoFocus: true,
							onBlur: (e) => {
								handleSetContent(e.target.value);
								setContentMode("preview");
							},
							className: "w-full resize-y rounded-lg px-4 py-3 font-mono text-sm leading-relaxed outline-none placeholder:opacity-50 focus:border-[#cba6f7]/50",
							style: {
								backgroundColor: "var(--bai-deep)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						})] }),
						activeTab === "links" && /* @__PURE__ */ jsx(LinksSection, {
							links,
							currentDocId: document.header.id,
							onAddLink: (_id, targetDocumentId, _targetTitle, linkType) => {
								dispatchActions([{
									id: generateId(),
									type: "ADD_RELATIONSHIP",
									scope: "document",
									timestampUtcMs: timestamp(),
									input: {
										sourceId: document.header.id,
										targetId: targetDocumentId,
										relationshipType: linkType
									}
								}], document.header.id);
							},
							onRemoveLink: (id) => {
								const link = links.find((l) => l.id === id);
								if (!link?.targetDocumentId) return;
								dispatchActions([{
									id: generateId(),
									type: "REMOVE_RELATIONSHIP",
									scope: "document",
									timestampUtcMs: timestamp(),
									input: {
										sourceId: document.header.id,
										targetId: link.targetDocumentId,
										relationshipType: link.linkType ?? "RELATES_TO"
									}
								}], document.header.id);
							},
							onUpdateLinkType: (id, linkType) => {
								const link = links.find((l) => l.id === id);
								if (!link?.targetDocumentId) return;
								const now = timestamp();
								dispatchActions([{
									id: generateId(),
									type: "REMOVE_RELATIONSHIP",
									scope: "document",
									timestampUtcMs: now,
									input: {
										sourceId: document.header.id,
										targetId: link.targetDocumentId,
										relationshipType: link.linkType ?? "RELATES_TO"
									}
								}, {
									id: generateId(),
									type: "ADD_RELATIONSHIP",
									scope: "document",
									timestampUtcMs: now,
									input: {
										sourceId: document.header.id,
										targetId: link.targetDocumentId,
										relationshipType: linkType
									}
								}], document.header.id);
							}
						}),
						activeTab === "history" && /* @__PURE__ */ jsx(LifecycleTimeline, { events: state.lifecycleEvents })
					]
				}), /* @__PURE__ */ jsxs("div", {
					className: "w-64 shrink-0 space-y-6 self-start rounded-xl p-5",
					style: {
						backgroundColor: "var(--bai-surface)",
						border: "1px solid var(--bai-border)"
					},
					children: [
						/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h4", {
							className: "mb-2 text-xs font-semibold uppercase tracking-wider",
							style: { color: "var(--bai-text-muted)" },
							children: "Provenance"
						}), /* @__PURE__ */ jsx(ProvenanceInfo, {
							provenance: state.provenance ?? null,
							onSetProvenance: (author, sourceOrigin) => dispatch(actions.setProvenance({
								author,
								sourceOrigin,
								createdAt: timestamp()
							}))
						})] }),
						/* @__PURE__ */ jsx("hr", { style: { borderColor: "var(--bai-border)" } }),
						/* @__PURE__ */ jsx(MetadataPanel, {
							state,
							onSetField: handleSetMetadataField,
							onSetListField: handleSetMetadataListField
						})
					]
				})]
			})]
		})
	});
}
//#endregion
export { Editor as default };

//# sourceMappingURL=editor-CV9ZShpu.mjs.map