import "./dist-DZj99xX4.js";
import { a as setSelectedNode, s as useDocumentsInSelectedDrive } from "./dist-DAY54QOk.js";
import { t as DocumentToolbar } from "./connect-DwcZHh7Q.js";
import { g as actions } from "./module-Dv-oA2vt.js";
import { t as useSelectedTensionDocument } from "./tension-CbAHJ7h-.js";
import { t as TOOLBAR_CLASS } from "./theme-context-DsfdY07T.js";
import { useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region editors/tension-editor/editor.tsx
const STATUS_COLORS = {
	OPEN: "bg-red-500/20 text-red-300 border-red-500/30",
	RESOLVED: "bg-emerald-500/20 text-emerald-300 border-emerald-500/30",
	DISSOLVED: "bg-blue-500/20 text-blue-300 border-blue-500/30"
};
function ts() {
	return (/* @__PURE__ */ new Date()).toISOString();
}
function Editor() {
	const [document, dispatch] = useSelectedTensionDocument();
	const state = document.state.global;
	const allDriveDocs = useDocumentsInSelectedDrive();
	const allDocs = useMemo(() => (allDriveDocs ?? []).filter((d) => d.header.documentType === "bai/knowledge-note" || d.header.documentType === "bai/moc"), [allDriveDocs]);
	if (!!!state.title) return /* @__PURE__ */ jsx(CreateForm, { dispatch });
	const involvedNotes = (state.involvedRefs ?? []).map((ref) => {
		const doc = (allDocs ?? []).find((d) => d.header.id === ref);
		return {
			ref,
			title: doc ? doc.state.global.title ?? doc.header.name : ref.slice(0, 12),
			exists: !!doc
		};
	});
	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-3xl",
			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 ${STATUS_COLORS[state.status ?? "OPEN"]}`,
										children: state.status
									}),
									state.observedBy && /* @__PURE__ */ jsxs("span", {
										className: "text-xs",
										style: { color: "var(--bai-text-faint)" },
										children: ["by ", state.observedBy]
									}),
									state.observedAt && /* @__PURE__ */ jsx("span", {
										className: "text-xs",
										style: { color: "var(--bai-text-faint)" },
										children: new Date(state.observedAt).toLocaleDateString()
									})
								]
							}),
							/* @__PURE__ */ jsx("h1", {
								className: "text-xl font-bold",
								style: { color: "var(--bai-text)" },
								children: state.title
							}),
							state.description && /* @__PURE__ */ jsx("p", {
								className: "mt-2 text-sm",
								style: { color: "var(--bai-text-tertiary)" },
								children: state.description
							})
						]
					}),
					state.content && /* @__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: "Analysis"
						}), /* @__PURE__ */ jsx("div", {
							className: "rounded-lg px-4 py-3",
							style: {
								backgroundColor: "var(--bai-deep)",
								border: "1px solid var(--bai-border)"
							},
							children: /* @__PURE__ */ jsx("pre", {
								className: "whitespace-pre-wrap text-sm leading-relaxed",
								style: { color: "var(--bai-text-secondary)" },
								children: state.content
							})
						})]
					}),
					/* @__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: [
								"Involved Notes (",
								involvedNotes.length,
								")"
							]
						}), /* @__PURE__ */ jsx("div", {
							className: "space-y-2",
							children: involvedNotes.map((note) => /* @__PURE__ */ jsxs("div", {
								className: "flex items-center gap-3 rounded-lg px-4 py-3",
								style: {
									backgroundColor: "var(--bai-bg)",
									border: "1px solid var(--bai-border)"
								},
								children: [/* @__PURE__ */ jsx("span", { className: "h-2 w-2 shrink-0 rounded-full bg-red-400" }), note.exists ? /* @__PURE__ */ jsx("button", {
									type: "button",
									onClick: () => setSelectedNode(note.ref),
									className: "flex-1 text-left text-xs transition-colors truncate",
									style: { color: "var(--bai-accent)" },
									children: note.title
								}) : /* @__PURE__ */ jsx("span", {
									className: "flex-1 text-xs font-mono truncate",
									style: { color: "var(--bai-text-faint)" },
									children: note.ref
								})]
							}, note.ref))
						})]
					}),
					state.resolution && /* @__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: "Resolution"
							}),
							/* @__PURE__ */ jsx("p", {
								className: "text-sm leading-relaxed",
								style: { color: "var(--bai-text-secondary)" },
								children: state.resolution
							}),
							state.resolvedAt && /* @__PURE__ */ jsxs("p", {
								className: "mt-2 text-[10px]",
								style: { color: "var(--bai-text-faint)" },
								children: ["Resolved ", new Date(state.resolvedAt).toLocaleString()]
							})
						]
					}),
					state.status === "OPEN" && /* @__PURE__ */ jsxs("div", {
						className: "flex gap-3",
						children: [/* @__PURE__ */ jsx("button", {
							type: "button",
							onClick: () => {
								const resolution = prompt("How was this resolved? (one side is correct)");
								if (resolution) dispatch(actions.resolveTension({
									resolution,
									resolvedAt: ts()
								}));
							},
							className: "rounded-lg px-4 py-2 text-sm font-medium",
							style: {
								backgroundColor: "var(--bai-accent)",
								color: "var(--bai-accent-text)"
							},
							children: "Resolve"
						}), /* @__PURE__ */ jsx("button", {
							type: "button",
							onClick: () => {
								const resolution = prompt("Why is this tension apparent, not real?");
								if (resolution) dispatch(actions.dissolveTension({
									resolution,
									resolvedAt: ts()
								}));
							},
							className: "rounded-lg px-4 py-2 text-sm font-medium",
							style: {
								backgroundColor: "var(--bai-hover)",
								color: "var(--bai-text-secondary)"
							},
							children: "Dissolve"
						})]
					})
				]
			})]
		})
	});
}
function CreateForm({ dispatch }) {
	const [title, setTitle] = useState("");
	const [desc, setDesc] = useState("");
	const [content, setContent] = useState("");
	const [observer, setObserver] = useState("");
	const INPUT = "w-full rounded-lg px-3 py-2 text-sm outline-none focus:border-[#cba6f7]/50";
	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: "Identify Tension"
						}),
						/* @__PURE__ */ jsx("p", {
							className: "text-xs",
							style: { color: "var(--bai-text-muted)" },
							children: "Record a contradiction between two or more claims in the vault"
						}),
						/* @__PURE__ */ jsx("input", {
							type: "text",
							value: title,
							onChange: (e) => setTitle(e.target.value),
							placeholder: "What's the contradiction? (e.g., 'vault as tool vs vault as cognitive infrastructure')",
							className: INPUT,
							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: "Brief summary of the conflict",
							className: INPUT,
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("textarea", {
							value: content,
							onChange: (e) => setContent(e.target.value),
							placeholder: "Full analysis of the contradiction — why it matters, what's at stake...",
							rows: 6,
							className: INPUT,
							style: {
								backgroundColor: "var(--bai-deep)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("input", {
							type: "text",
							value: observer,
							onChange: (e) => setObserver(e.target.value),
							placeholder: "Observed by (optional)",
							className: INPUT,
							style: {
								backgroundColor: "var(--bai-bg)",
								color: "var(--bai-text-secondary)",
								border: "1px solid var(--bai-border)"
							}
						}),
						/* @__PURE__ */ jsx("button", {
							type: "button",
							disabled: !title.trim() || !desc.trim(),
							onClick: () => dispatch(actions.createTension({
								title,
								description: desc,
								content: content || void 0,
								involvedRefs: [],
								observedAt: ts(),
								observedBy: observer || void 0
							})),
							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 Tension"
						})
					]
				})
			})]
		})
	});
}
//#endregion
export { Editor as default };

//# sourceMappingURL=editor-BOUH5TTG.js.map