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-BR-YtMNM.mjs";
import { i as useSelectedMocDocument } from "./moc-BRjbfxLV.mjs";
import { t as TOOLBAR_CLASS } from "./theme-context-DeP5ztQx.mjs";
import { t as useKnowledgeMocs } from "./use-knowledge-mocs-BAjT_d7v.mjs";
import { useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region editors/moc-editor/editor.tsx
const TIERS = [
	"HUB",
	"DOMAIN",
	"TOPIC"
];
const TIER_COLORS = {
	HUB: "bg-purple-500/20 text-purple-300 border-purple-500/30",
	DOMAIN: "bg-blue-500/20 text-blue-300 border-blue-500/30",
	TOPIC: "bg-emerald-500/20 text-emerald-300 border-emerald-500/30"
};
function ts() {
	return (/* @__PURE__ */ new Date()).toISOString();
}
function Editor() {
	const [document, dispatch] = useSelectedMocDocument();
	const state = document.state.global;
	const { mocMap } = useKnowledgeMocs();
	const coreIdeas = mocMap.get(document.header.id)?.coreIdeas ?? [];
	const allDriveDocs = useDocumentsInSelectedDrive();
	const allDocs = useMemo(() => (allDriveDocs ?? []).filter((d) => d.header.documentType === "bai/knowledge-note" || d.header.documentType === "bai/moc"), [allDriveDocs]);
	const [newQuestion, setNewQuestion] = useState("");
	const [newIdeaRef, setNewIdeaRef] = useState("");
	const [newIdeaPhrase, setNewIdeaPhrase] = useState("");
	if (!!!state.title) return /* @__PURE__ */ jsx(InitForm, { 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-5xl",
			children: [/* @__PURE__ */ jsx(DocumentToolbar, { toolbarClassName: TOOLBAR_CLASS }), /* @__PURE__ */ jsxs("div", {
				className: "p-6 space-y-6",
				children: [
					/* @__PURE__ */ jsxs("div", {
						className: "rounded-xl p-6",
						style: {
							backgroundColor: "var(--bai-surface)",
							border: "1px solid var(--bai-border)"
						},
						children: [
							/* @__PURE__ */ jsxs("div", {
								className: "flex items-center gap-3 mb-3",
								children: [/* @__PURE__ */ jsx("span", {
									className: `rounded-full border px-3 py-1 text-xs font-semibold ${TIER_COLORS[state.tier ?? "TOPIC"]}`,
									children: state.tier
								}), /* @__PURE__ */ jsxs("span", {
									className: "text-xs",
									style: { color: "var(--bai-text-muted)" },
									children: [state.noteCount ?? 0, " notes"]
								})]
							}),
							/* @__PURE__ */ jsx("h1", {
								className: "text-2xl font-bold",
								style: { color: "var(--bai-text)" },
								children: state.title
							}),
							/* @__PURE__ */ jsx("textarea", {
								defaultValue: state.description ?? "",
								placeholder: "Description...",
								onBlur: (e) => dispatch(actions.updateDescription({
									description: e.target.value.trim(),
									updatedAt: ts()
								})),
								className: "mt-2 w-full resize-none rounded-lg px-3 py-2 text-sm outline-none placeholder:opacity-50 focus:border-[#cba6f7]/50",
								rows: 2,
								style: {
									backgroundColor: "var(--bai-bg)",
									color: "var(--bai-text-secondary)",
									border: "1px solid var(--bai-border)"
								}
							})
						]
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "rounded-xl p-6",
						style: {
							backgroundColor: "var(--bai-surface)",
							border: "1px solid var(--bai-border)"
						},
						children: [
							/* @__PURE__ */ jsx("h3", {
								className: "mb-2 text-xs font-semibold uppercase tracking-wider",
								style: { color: "var(--bai-text-muted)" },
								children: "Orientation"
							}),
							/* @__PURE__ */ jsx("p", {
								className: "mb-1.5 text-[10px]",
								style: { color: "var(--bai-text-faint)" },
								children: "A synthesis paragraph explaining what this topic covers, key themes, and how the core ideas relate to each other."
							}),
							/* @__PURE__ */ jsx("textarea", {
								defaultValue: state.orientation ?? "",
								placeholder: "Write a 2-3 paragraph synthesis of this topic area — what are the key themes, how do the core ideas connect, and what's the current state of understanding...",
								onBlur: (e) => dispatch(actions.updateOrientation({
									orientation: e.target.value.trim(),
									updatedAt: ts()
								})),
								className: "w-full resize-y rounded-lg px-4 py-3 text-sm leading-relaxed outline-none placeholder:opacity-50 focus:border-[#cba6f7]/50",
								rows: 10,
								style: {
									backgroundColor: "var(--bai-deep)",
									color: "var(--bai-text-secondary)",
									border: "1px solid var(--bai-border)",
									minHeight: "160px"
								}
							})
						]
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "grid grid-cols-2 gap-6",
						children: [/* @__PURE__ */ jsxs("div", {
							className: "rounded-xl p-6",
							style: {
								backgroundColor: "var(--bai-surface)",
								border: "1px solid var(--bai-border)"
							},
							children: [/* @__PURE__ */ jsxs("h3", {
								className: "mb-3 text-xs font-semibold uppercase tracking-wider",
								style: { color: "var(--bai-text-muted)" },
								children: [
									"Core Ideas (",
									coreIdeas.length,
									")"
								]
							}), /* @__PURE__ */ jsxs("div", {
								className: "space-y-2",
								children: [coreIdeas.map((idea) => {
									const linkedDoc = (allDocs ?? []).find((d) => d.header.id === idea.noteRef);
									const noteTitle = linkedDoc ? linkedDoc.state.global.title ?? linkedDoc.header.name : null;
									const ideaKey = `${document.header.id}-${idea.noteRef}`;
									return /* @__PURE__ */ jsxs("div", {
										className: "group flex items-start gap-2 rounded-lg px-3 py-2",
										style: {
											backgroundColor: "var(--bai-bg)",
											boxShadow: "0 0 0 1px var(--bai-ring)"
										},
										children: [/* @__PURE__ */ jsxs("div", {
											className: "flex-1 min-w-0",
											children: [/* @__PURE__ */ jsx("p", {
												className: "text-xs",
												style: { color: "var(--bai-text-secondary)" },
												children: idea.contextPhrase
											}), idea.noteRef && (noteTitle ? /* @__PURE__ */ jsxs("button", {
												type: "button",
												onClick: () => setSelectedNode(idea.noteRef),
												className: "mt-0.5 text-[10px] text-left truncate max-w-full transition-colors hover:underline",
												style: { color: "var(--bai-accent)" },
												title: `Open note: ${noteTitle}`,
												children: [noteTitle, /* @__PURE__ */ jsxs("svg", {
													className: "ml-1 inline h-2.5 w-2.5",
													style: { color: "var(--bai-text-faint)" },
													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("path", { d: "M15 3h6v6" }),
														/* @__PURE__ */ jsx("path", { d: "M10 14L21 3" })
													]
												})]
											}) : /* @__PURE__ */ jsxs("button", {
												type: "button",
												onClick: () => setSelectedNode(idea.noteRef),
												className: "mt-0.5 text-[10px] font-mono text-left truncate max-w-full transition-colors hover:underline",
												style: { color: "var(--bai-text-faint)" },
												title: `Open document: ${idea.noteRef}`,
												children: [idea.noteRef.slice(0, 12), "..."]
											}))]
										}), /* @__PURE__ */ jsx("button", {
											type: "button",
											onClick: () => {
												dispatchActions([{
													id: generateId(),
													type: "REMOVE_RELATIONSHIP",
													scope: "document",
													timestampUtcMs: ts(),
													input: {
														sourceId: document.header.id,
														targetId: idea.noteRef,
														relationshipType: "CORE_IDEA"
													}
												}], document.header.id);
											},
											className: "opacity-0 hover:text-red-400 group-hover:opacity-100",
											style: { color: "var(--bai-text-faint)" },
											children: "×"
										})]
									}, ideaKey);
								}), /* @__PURE__ */ jsxs("form", {
									className: "flex gap-2",
									onSubmit: (e) => {
										e.preventDefault();
										if (!newIdeaRef.trim()) return;
										dispatchActions([{
											id: generateId(),
											type: "ADD_RELATIONSHIP",
											scope: "document",
											timestampUtcMs: ts(),
											input: {
												sourceId: document.header.id,
												targetId: newIdeaRef.trim(),
												relationshipType: "CORE_IDEA"
											}
										}], document.header.id);
										setNewIdeaRef("");
										setNewIdeaPhrase("");
									},
									children: [
										/* @__PURE__ */ jsx("input", {
											type: "text",
											value: newIdeaRef,
											onChange: (e) => setNewIdeaRef(e.target.value),
											placeholder: "Note ID...",
											className: "w-24 rounded px-2 py-1 text-xs font-mono outline-none focus:border-[#cba6f7]/50",
											style: {
												backgroundColor: "var(--bai-deep)",
												color: "var(--bai-text-tertiary)",
												border: "1px solid var(--bai-border)"
											}
										}),
										/* @__PURE__ */ jsx("input", {
											type: "text",
											value: newIdeaPhrase,
											onChange: (e) => setNewIdeaPhrase(e.target.value),
											placeholder: "Why it matters here...",
											className: "flex-1 rounded px-2 py-1 text-xs outline-none focus:border-[#cba6f7]/50",
											style: {
												backgroundColor: "var(--bai-deep)",
												color: "var(--bai-text-secondary)",
												border: "1px solid var(--bai-border)"
											}
										}),
										/* @__PURE__ */ jsx("button", {
											type: "submit",
											className: "rounded px-2 py-1 text-xs font-medium",
											style: {
												backgroundColor: "var(--bai-accent)",
												color: "var(--bai-accent-text)"
											},
											children: "Add"
										})
									]
								})]
							})]
						}), /* @__PURE__ */ jsxs("div", {
							className: "space-y-6",
							children: [/* @__PURE__ */ jsxs("div", {
								className: "rounded-xl p-6",
								style: {
									backgroundColor: "var(--bai-surface)",
									border: "1px solid var(--bai-border)"
								},
								children: [/* @__PURE__ */ jsx("h3", {
									className: "mb-3 text-xs font-semibold uppercase tracking-wider",
									style: { color: "var(--bai-text-muted)" },
									children: "Tensions"
								}), (state.tensions ?? []).map((t) => /* @__PURE__ */ jsxs("div", {
									className: "group flex items-center gap-2 rounded-lg px-3 py-2 mb-1",
									style: {
										backgroundColor: "var(--bai-bg)",
										boxShadow: "0 0 0 1px var(--bai-ring)"
									},
									children: [
										/* @__PURE__ */ jsx("span", { className: "h-2 w-2 shrink-0 rounded-full bg-red-400" }),
										/* @__PURE__ */ jsx("span", {
											className: "flex-1 text-xs",
											style: { color: "var(--bai-text-secondary)" },
											children: t.description
										}),
										/* @__PURE__ */ jsx("button", {
											type: "button",
											onClick: () => dispatch(actions.removeTension({ id: t.id })),
											className: "opacity-0 hover:text-red-400 group-hover:opacity-100",
											style: { color: "var(--bai-text-faint)" },
											children: "×"
										})
									]
								}, t.id))]
							}), /* @__PURE__ */ jsxs("div", {
								className: "rounded-xl p-6",
								style: {
									backgroundColor: "var(--bai-surface)",
									border: "1px solid var(--bai-border)"
								},
								children: [
									/* @__PURE__ */ jsx("h3", {
										className: "mb-3 text-xs font-semibold uppercase tracking-wider",
										style: { color: "var(--bai-text-muted)" },
										children: "Open Questions"
									}),
									(state.openQuestions ?? []).map((q, i) => /* @__PURE__ */ jsxs("div", {
										className: "group flex items-center gap-2 rounded-lg px-3 py-2 mb-1",
										style: {
											backgroundColor: "var(--bai-bg)",
											boxShadow: "0 0 0 1px var(--bai-ring)"
										},
										children: [/* @__PURE__ */ jsx("span", {
											className: "flex-1 text-xs",
											style: { color: "var(--bai-text-secondary)" },
											children: q
										}), /* @__PURE__ */ jsx("button", {
											type: "button",
											onClick: () => dispatch(actions.removeOpenQuestion({ question: q })),
											className: "opacity-0 hover:text-red-400 group-hover:opacity-100",
											style: { color: "var(--bai-text-faint)" },
											children: "×"
										})]
									}, i)),
									/* @__PURE__ */ jsxs("form", {
										className: "flex gap-2 mt-2",
										onSubmit: (e) => {
											e.preventDefault();
											if (!newQuestion.trim()) return;
											dispatch(actions.addOpenQuestion({ question: newQuestion.trim() }));
											setNewQuestion("");
										},
										children: [/* @__PURE__ */ jsx("input", {
											type: "text",
											value: newQuestion,
											onChange: (e) => setNewQuestion(e.target.value),
											placeholder: "Add question...",
											className: "flex-1 rounded px-2 py-1 text-xs outline-none focus:border-[#cba6f7]/50",
											style: {
												backgroundColor: "var(--bai-deep)",
												color: "var(--bai-text-secondary)",
												border: "1px solid var(--bai-border)"
											}
										}), /* @__PURE__ */ jsx("button", {
											type: "submit",
											className: "rounded px-2 py-1 text-xs font-medium",
											style: {
												backgroundColor: "var(--bai-accent)",
												color: "var(--bai-accent-text)"
											},
											children: "Add"
										})]
									})
								]
							})]
						})]
					})
				]
			})]
		})
	});
}
function InitForm({ dispatch }) {
	const [title, setTitle] = useState("");
	const [desc, setDesc] = useState("");
	const [orient, setOrient] = useState("");
	const [tier, setTier] = useState("TOPIC");
	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-2xl",
			children: [/* @__PURE__ */ jsx(DocumentToolbar, { toolbarClassName: TOOLBAR_CLASS }), /* @__PURE__ */ jsx("div", {
				className: "p-6",
				children: /* @__PURE__ */ jsxs("div", {
					className: "rounded-xl p-8 space-y-4",
					style: {
						backgroundColor: "var(--bai-surface)",
						border: "1px solid var(--bai-border)"
					},
					children: [
						/* @__PURE__ */ jsx("h2", {
							className: "text-lg font-bold",
							style: { color: "var(--bai-text)" },
							children: "Create Map of Content"
						}),
						/* @__PURE__ */ jsx("input", {
							type: "text",
							value: title,
							onChange: (e) => setTitle(e.target.value),
							placeholder: "MOC Title",
							className: "w-full rounded-lg px-3 py-2 text-sm outline-none focus:border-[#cba6f7]/50",
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("input", {
							type: "text",
							value: desc,
							onChange: (e) => setDesc(e.target.value),
							placeholder: "Description",
							className: "w-full rounded-lg px-3 py-2 text-sm outline-none focus:border-[#cba6f7]/50",
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("textarea", {
							value: orient,
							onChange: (e) => setOrient(e.target.value),
							placeholder: "Orientation (2-3 sentences)",
							rows: 3,
							className: "w-full rounded-lg px-3 py-2 text-sm outline-none focus:border-[#cba6f7]/50",
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("select", {
							value: tier,
							onChange: (e) => setTier(e.target.value),
							className: "rounded-lg px-3 py-2 text-sm",
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							},
							children: TIERS.map((t) => /* @__PURE__ */ jsx("option", {
								value: t,
								children: t
							}, t))
						}),
						/* @__PURE__ */ jsx("button", {
							type: "button",
							disabled: !title.trim() || !desc.trim() || !orient.trim(),
							onClick: () => dispatch(actions.createMoc({
								title,
								description: desc,
								orientation: orient,
								tier,
								createdAt: ts()
							})),
							className: "rounded-lg px-4 py-2 text-sm font-medium hover:opacity-80 disabled:opacity-40",
							style: {
								backgroundColor: "var(--bai-accent)",
								color: "var(--bai-accent-text)"
							},
							children: "Create MOC"
						})
					]
				})
			})]
		})
	});
}
//#endregion
export { Editor as default };

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