import { x as head, e as ensure_array_like, c as escape_html, a as attr, b as attr_class, f as stringify, y as bind_props, g as derived } from './dev-BNpEUZI3.js';
import './client-CW9E6S_J.js';
import { H as HeroHeader } from './HeroHeader-v4Q9vaGr.js';
import { C as Card, B as Badge } from './Tabs-DzG6Bn9a.js';
import { B as Button, M as Modal, I as Input } from './ui-DR8zOSpC.js';
import './internal-DYSVC9SL.js';
import 'node:module';
import '@sveltejs/kit/internal';
import './index-server-DocJvixA.js';
import './chunk-DDP5xfzh.js';
import '@sveltejs/kit/internal/server';

//#region src/lib/components/admin/AuditLogPanel.svelte
function AuditLogPanel($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Initial entries from server load. Optional. */
		/** Extra class names. */
		let { initial = [], class: extraClass = "" } = $$props;
		let entries = initial;
		let loading = false;
		let errorMsg = null;
		let expandedIdx = null;
		async function refresh() {
			loading = true;
			errorMsg = null;
			try {
				const env = await (await fetch("/api/project/audit")).json();
				if (env.success && env.data) entries = env.data.entries ?? [];
				else errorMsg = env.error?.message ?? "Unable to read audit log";
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		function resultTone(r) {
			if (r === "success") return "success";
			if (r === "failure") return "danger";
			if (r === "dry-run") return "warning";
			return "info";
		}
		function formatTime(iso) {
			try {
				return new Date(iso).toLocaleString(void 0, {
					month: "short",
					day: "numeric",
					hour: "2-digit",
					minute: "2-digit",
					second: "2-digit"
				});
			} catch {
				return iso;
			}
		}
		function hasDetails(entry) {
			return Boolean(entry.detail) || Boolean(entry.meta && Object.keys(entry.meta).length > 0);
		}
		$$renderer.push(`<section${attr_class(`audit-panel ${stringify(extraClass)}`, "svelte-1fyimgn")} aria-label="Admin action audit log"><header class="panel-head svelte-1fyimgn"><h3 class="panel-title svelte-1fyimgn">Audit log `);
		if (entries.length > 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<span class="panel-count svelte-1fyimgn">${escape_html(entries.length)}</span>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></h3> `);
		Button($$renderer, {
			variant: "ghost",
			size: "sm",
			onclick: refresh,
			loading,
			children: ($$renderer) => {
				$$renderer.push(`<!---->Refresh`);
			}});
		$$renderer.push(`<!----></header> `);
		if (errorMsg) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="alert svelte-1fyimgn" role="alert">${escape_html(errorMsg)}</div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (entries.length === 0 && !loading) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<p class="empty svelte-1fyimgn">No recorded admin actions yet.</p>`);
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<ol class="log-list svelte-1fyimgn"><!--[-->`);
			const each_array = ensure_array_like(entries);
			for (let i = 0, $$length = each_array.length; i < $$length; i++) {
				let entry = each_array[i];
				const expandable = hasDetails(entry);
				$$renderer.push(`<li class="log-item svelte-1fyimgn"><div class="row svelte-1fyimgn"><time class="ts svelte-1fyimgn">${escape_html(formatTime(entry.timestamp))}</time> <code class="action svelte-1fyimgn">${escape_html(entry.action)}</code> `);
				Badge($$renderer, {
					tone: resultTone(entry.result),
					size: "sm",
					children: ($$renderer) => {
						$$renderer.push(`<!---->${escape_html(entry.result)}`);
					}});
				$$renderer.push(`<!----> `);
				if (entry.target) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<span class="target svelte-1fyimgn">${escape_html(entry.target)}</span>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--> <span class="actor svelte-1fyimgn">${escape_html(entry.actor)}</span> `);
				if (expandable) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<button type="button" class="expand-btn svelte-1fyimgn"${attr("aria-expanded", expandedIdx === i)}${attr("aria-label", expandedIdx === i ? "Collapse entry" : "Expand entry")}>${escape_html(expandedIdx === i ? "▾" : "▸")}</button>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--></div> `);
				if (expandedIdx === i && expandable) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<div class="details svelte-1fyimgn">`);
					if (entry.detail) {
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<p class="detail-text svelte-1fyimgn">${escape_html(entry.detail)}</p>`);
					} else $$renderer.push("<!--[-1-->");
					$$renderer.push(`<!--]--> `);
					if (entry.meta) {
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<pre class="meta svelte-1fyimgn">${escape_html(JSON.stringify(entry.meta, null, 2))}</pre>`);
					} else $$renderer.push("<!--[-1-->");
					$$renderer.push(`<!--]--></div>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--></li>`);
			}
			$$renderer.push(`<!--]--></ol>`);
		}
		$$renderer.push(`<!--]--></section>`);
	});
}
//#endregion
//#region src/lib/components/admin/BackupModal.svelte
function BackupModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { open = true, onClose } = $$props;
		let files = [];
		let loading = false;
		let creating = false;
		let note = "";
		let errorMsg = null;
		let successMsg = null;
		let dir = "";
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function loadList() {
			loading = true;
			errorMsg = null;
			try {
				const env = await (await fetch("/api/project/backup")).json();
				if (env.success && env.data) {
					files = env.data.backups ?? [];
					dir = env.data.dir ?? "";
				} else errorMsg = env.error?.message ?? "Unable to list backups";
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		async function createSnapshot() {
			creating = true;
			errorMsg = null;
			successMsg = null;
			try {
				const env = await (await fetch("/api/project/backup", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify({ note: note.trim() || void 0 })
				})).json();
				if (env.success) {
					successMsg = "Snapshot created";
					note = "";
					await loadList();
				} else errorMsg = env.error?.message ?? "Snapshot failed";
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				creating = false;
			}
		}
		function formatSize(bytes) {
			if (bytes < 1024) return `${bytes} B`;
			if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} kB`;
			if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
			return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
		}
		function formatTime(iso) {
			try {
				return new Date(iso).toLocaleString(void 0, {
					month: "short",
					day: "numeric",
					hour: "2-digit",
					minute: "2-digit"
				});
			} catch {
				return iso;
			}
		}
		function kindTone(kind) {
			if (kind === "tasks") return "accent";
			if (kind === "brain") return "info";
			if (kind === "config" || kind === "project-info") return "warning";
			return "neutral";
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						onclick: loadList,
						loading,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Refresh`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Project Backups",
					maxWidth: 44,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="body svelte-bv3qg3"><section class="create"><h3 class="section-title svelte-bv3qg3">New snapshot</h3> <p class="description svelte-bv3qg3">Captures <code class="svelte-bv3qg3">tasks.db</code>, <code class="svelte-bv3qg3">brain.db</code>, <code class="svelte-bv3qg3">config.json</code>, and <code class="svelte-bv3qg3">project-info.json</code> via <code class="svelte-bv3qg3">cleo backup add</code>. Vacuums into a
        timestamped <code class="svelte-bv3qg3">.cleo/backups/sqlite/</code> file.</p> <div class="create-row svelte-bv3qg3">`);
						Input($$renderer, {
							label: "Note",
							placeholder: "e.g. pre-migration checkpoint",
							get value() {
								return note;
							},
							set value($$value) {
								note = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Button($$renderer, {
							variant: "primary",
							onclick: createSnapshot,
							loading: creating,
							children: ($$renderer) => {
								$$renderer.push(`<!---->${escape_html(creating ? "Creating" : "Create snapshot")}`);
							}});
						$$renderer.push(`<!----></div> `);
						if (successMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="success svelte-bv3qg3" role="status">${escape_html(successMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-bv3qg3" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></section> <section class="list-section"><div class="list-head svelte-bv3qg3"><h3 class="section-title svelte-bv3qg3">Existing snapshots</h3> `);
						if (dir) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<code class="list-dir svelte-bv3qg3">${escape_html(dir)}</code>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div> `);
						if (loading) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<p class="hint svelte-bv3qg3">Loading…</p>`);
						} else if (files.length === 0) {
							$$renderer.push("<!--[1-->");
							$$renderer.push(`<p class="hint svelte-bv3qg3">No snapshots yet. Create one above.</p>`);
						} else {
							$$renderer.push("<!--[-1-->");
							$$renderer.push(`<ul class="list svelte-bv3qg3"><!--[-->`);
							const each_array = ensure_array_like(files);
							for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
								let file = each_array[$$index];
								$$renderer.push(`<li class="list-item svelte-bv3qg3">`);
								Badge($$renderer, {
									tone: kindTone(file.kind),
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->${escape_html(file.kind)}`);
									}});
								$$renderer.push(`<!----> <code class="list-name svelte-bv3qg3">${escape_html(file.filename)}</code> <span class="list-size svelte-bv3qg3">${escape_html(formatSize(file.sizeBytes))}</span> <time class="list-time svelte-bv3qg3">${escape_html(formatTime(file.createdAt))}</time></li>`);
							}
							$$renderer.push(`<!--]--></ul>`);
						}
						$$renderer.push(`<!--]--> <p class="restore-hint svelte-bv3qg3">Restore via CLI: <code class="svelte-bv3qg3">cleo restore backup --file &lt;filename></code>.</p></section></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/CleanModal.svelte
function CleanModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { open = true, onClose, onSuccess } = $$props;
		let includeTemp = true;
		let includeTests = false;
		let includeUnhealthy = false;
		let includeNeverIndexed = false;
		let pattern = "";
		let purgeInput = "";
		const purgeConfirmed = derived(() => purgeInput === "PURGE");
		let loading = false;
		let result = null;
		let errorMsg = null;
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function runClean(dryRun) {
			loading = true;
			result = null;
			errorMsg = null;
			try {
				const envelope = await (await fetch("/api/project/clean", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify({
						includeTemp,
						includeTests,
						includeUnhealthy,
						includeNeverIndexed,
						pattern: pattern.trim() || void 0,
						dryRun
					})
				})).json();
				if (!envelope.success) errorMsg = envelope.error?.message ?? "Clean failed";
				else {
					const data = envelope.data ?? {};
					result = {
						removed: typeof data["removed"] === "number" ? data["removed"] : void 0,
						dryRun: typeof data["dryRun"] === "boolean" ? data["dryRun"] : dryRun,
						paths: Array.isArray(data["paths"]) ? data["paths"].slice(0, 50) : void 0
					};
					if (!dryRun) onSuccess?.();
				}
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						loading,
						onclick: () => runClean(true),
						children: ($$renderer) => {
							$$renderer.push(`<!---->Preview`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "danger",
						disabled: !purgeConfirmed() || loading,
						loading,
						onclick: () => runClean(false),
						children: ($$renderer) => {
							$$renderer.push(`<!---->Purge`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Clean Project Registry",
					maxWidth: 34,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="clean-body svelte-1bkgyl6"><fieldset class="filters svelte-1bkgyl6"><legend class="legend svelte-1bkgyl6">Target filters</legend> <label class="row svelte-1bkgyl6"><input type="checkbox"${attr("checked", includeTemp, true)} class="check svelte-1bkgyl6"/> <span>Include <code class="svelte-1bkgyl6">.temp</code> paths</span></label> <label class="row svelte-1bkgyl6"><input type="checkbox"${attr("checked", includeTests, true)} class="check svelte-1bkgyl6"/> <span>Include test / tmp / fixture / scratch / sandbox paths</span></label> <label class="row svelte-1bkgyl6"><input type="checkbox"${attr("checked", includeUnhealthy, true)} class="check svelte-1bkgyl6"/> <span>Include unhealthy projects</span></label> <label class="row svelte-1bkgyl6"><input type="checkbox"${attr("checked", includeNeverIndexed, true)} class="check svelte-1bkgyl6"/> <span>Include never-indexed projects</span></label></fieldset> `);
						Input($$renderer, {
							label: "Pattern filter",
							description: "Optional regex applied to project paths.",
							placeholder: "e.g. /tmp/",
							get value() {
								return pattern;
							},
							set value($$value) {
								pattern = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> <div class="purge-section svelte-1bkgyl6"><p class="purge-label svelte-1bkgyl6">Confirm destructive purge</p> <p class="purge-hint svelte-1bkgyl6">Type <strong class="purge-keyword svelte-1bkgyl6">PURGE</strong> to enable the red button.</p> <input type="text" class="purge-input svelte-1bkgyl6" placeholder="PURGE" autocomplete="off" spellcheck="false"${attr("value", purgeInput)}/></div> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-1bkgyl6" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (result !== null) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div${attr_class("result svelte-1bkgyl6", void 0, { "is-dry-run": result.dryRun })}><div class="result-head svelte-1bkgyl6">`);
							if (result.dryRun) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="tag tag-dry svelte-1bkgyl6">DRY RUN</span>`);
							} else {
								$$renderer.push("<!--[-1-->");
								$$renderer.push(`<span class="tag tag-live svelte-1bkgyl6">PURGED</span>`);
							}
							$$renderer.push(`<!--]--> `);
							if (result.removed !== void 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="result-summary svelte-1bkgyl6">${escape_html(result.removed)} project${escape_html(result.removed === 1 ? "" : "s")}
              ${escape_html(result.dryRun ? "would be" : "")} removed</span>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div> `);
							if (result.paths && result.paths.length > 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<ul class="paths svelte-1bkgyl6"><!--[-->`);
								const each_array = ensure_array_like(result.paths);
								for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
									let p = each_array[$$index];
									$$renderer.push(`<li class="path svelte-1bkgyl6">${escape_html(p)}</li>`);
								}
								$$renderer.push(`<!--]--></ul>`);
							} else {
								$$renderer.push("<!--[-1-->");
								$$renderer.push(`<p class="empty svelte-1bkgyl6">No matching projects.</p>`);
							}
							$$renderer.push(`<!--]--></div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/DeleteConfirmModal.svelte
function DeleteConfirmModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Display name of the project to delete. */
		/** Called when the user confirms. */
		/** Called when dismissed without action. */
		let { open = true, projectName, onConfirm, onClose } = $$props;
		let inputValue = "";
		const confirmed = derived(() => inputValue === projectName);
		function handleClose() {
			open = false;
			onClose?.();
		}
		function handleConfirm() {
			if (!confirmed()) return;
			onConfirm();
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Cancel`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "danger",
						disabled: !confirmed(),
						onclick: handleConfirm,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Delete`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Delete project",
					maxWidth: 28,
					closeOnBackdrop: false,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="body svelte-15ygpq"><p class="warning svelte-15ygpq">This removes the project from the nexus registry. Files on disk are not touched.</p> <p class="hint svelte-15ygpq">Type <strong class="keyword svelte-15ygpq">${escape_html(projectName)}</strong> to confirm:</p> <input type="text" class="confirm-input svelte-15ygpq"${attr("placeholder", projectName)}${attr("value", inputValue)} autocomplete="off" spellcheck="false"/></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/DoctorModal.svelte
function DoctorModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Optional project id to scope the doctor call. */
		let { open = true, projectId = null, onClose } = $$props;
		let loading = false;
		let errorMsg = null;
		let data = null;
		let ranAt = null;
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function runDoctor() {
			loading = true;
			errorMsg = null;
			data = null;
			try {
				const envelope = await (await fetch("/api/project/doctor", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify(projectId ? { projectId } : {})
				})).json();
				if (!envelope.success) errorMsg = envelope.error?.message ?? "Doctor failed";
				else {
					data = envelope.data ?? {};
					ranAt = (/* @__PURE__ */ new Date()).toLocaleTimeString();
				}
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		function formatValue(value) {
			if (value === null) return "null";
			if (typeof value === "string") return value;
			if (typeof value === "number" || typeof value === "boolean") return String(value);
			try {
				return JSON.stringify(value, null, 2);
			} catch {
				return String(value);
			}
		}
		function getHealthTone(issues) {
			if (!Array.isArray(issues)) return "neutral";
			if (issues.length === 0) return "success";
			if (issues.length < 5) return "warning";
			return "danger";
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						onclick: runDoctor,
						loading,
						children: ($$renderer) => {
							$$renderer.push(`<!---->${escape_html(loading ? "Running" : "Re-run")}`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Project Doctor",
					maxWidth: 48,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="body svelte-ef4fmo"><p class="description svelte-ef4fmo">Runs <code class="svelte-ef4fmo">cleo nexus doctor</code> against the active project. Reports schema versions, row
      counts, orphaned references, and broken links.</p> `);
						if (loading) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="state svelte-ef4fmo"><span class="spinner svelte-ef4fmo" aria-hidden="true"></span> <span>Running diagnostics…</span></div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-ef4fmo" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (data) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="result svelte-ef4fmo"><div class="result-head svelte-ef4fmo">`);
							Badge($$renderer, {
								tone: getHealthTone(data["issues"]),
								children: ($$renderer) => {
									$$renderer.push(`<!---->${escape_html(Array.isArray(data["issues"]) && data["issues"].length === 0 ? "healthy" : "issues")}`);
								}});
							$$renderer.push(`<!----> `);
							if (ranAt) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="result-time svelte-ef4fmo">checked at ${escape_html(ranAt)}</span>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div> <div class="fields svelte-ef4fmo"><!--[-->`);
							const each_array = ensure_array_like(Object.entries(data));
							for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
								let [key, value] = each_array[$$index];
								$$renderer.push(`<div class="field svelte-ef4fmo"><span class="field-key svelte-ef4fmo">${escape_html(key)}</span> <pre class="field-value svelte-ef4fmo">${escape_html(formatValue(value))}</pre></div>`);
							}
							$$renderer.push(`<!--]--></div></div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/GcModal.svelte
function GcModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { open = true, onClose, onSuccess } = $$props;
		let confirmText = "";
		const liveConfirmed = derived(() => confirmText === "CLEAN");
		let loading = false;
		let result = null;
		let errorMsg = null;
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function runGc(dryRun) {
			loading = true;
			errorMsg = null;
			result = null;
			try {
				const env = await (await fetch("/api/project/gc", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify({ dryRun })
				})).json();
				if (!env.success) errorMsg = env.error?.message ?? "GC failed";
				else {
					result = {
						...env.data ?? {},
						dryRun
					};
					if (!dryRun) onSuccess?.();
				}
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						onclick: () => runGc(true),
						loading,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Preview`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "danger",
						disabled: !liveConfirmed() || loading,
						loading,
						onclick: () => runGc(false),
						children: ($$renderer) => {
							$$renderer.push(`<!---->Run GC`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Garbage Collect",
					maxWidth: 36,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="body svelte-1o64xpr"><p class="description svelte-1o64xpr">Removes orphaned nexus rows (dead edges, unreferenced symbols).
      Preview first; live run requires typing <strong class="kw svelte-1o64xpr">CLEAN</strong>.</p> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-1o64xpr" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (result) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div${attr_class("result svelte-1o64xpr", void 0, { "is-dry": result.dryRun })}><div class="result-head svelte-1o64xpr">`);
							if (result.dryRun) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="tag tag-dry svelte-1o64xpr">DRY RUN</span>`);
							} else {
								$$renderer.push("<!--[-1-->");
								$$renderer.push(`<span class="tag tag-live svelte-1o64xpr">REMOVED</span>`);
							}
							$$renderer.push(`<!--]--> `);
							if (typeof result.removed === "number") {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="result-summary svelte-1o64xpr">${escape_html(result.removed)} row${escape_html(result.removed === 1 ? "" : "s")}
              ${escape_html(result.dryRun ? "would be removed" : "removed")}</span>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div></div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> <div class="confirm svelte-1o64xpr"><label class="confirm-label svelte-1o64xpr" for="gc-confirm-input">Type <strong class="kw svelte-1o64xpr">CLEAN</strong> to enable live run:</label> <input id="gc-confirm-input" type="text" class="confirm-input svelte-1o64xpr" placeholder="CLEAN" autocomplete="off" spellcheck="false"${attr("value", confirmText)}/></div></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/MigrationModal.svelte
function MigrationModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { open = true, onClose } = $$props;
		let data = null;
		let loading = false;
		let errorMsg = null;
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function load() {
			loading = true;
			errorMsg = null;
			try {
				const env = await (await fetch("/api/project/migrate")).json();
				if (env.success && env.data) data = env.data;
				else errorMsg = env.error?.message ?? "Unable to read migration status";
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		function statusTone(report) {
			if (report.migrationPending === true) return "warning";
			if (report.migrationPending === false) return "success";
			if (report.schemaVersion === null) return "neutral";
			return "neutral";
		}
		function statusLabel(report) {
			if (report.migrationPending === true) return "pending";
			if (report.migrationPending === false) return "current";
			if (report.schemaVersion === null) return "unknown";
			return "unknown";
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						onclick: load,
						loading,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Refresh`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Schema Migrations",
					maxWidth: 38,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="body svelte-i18k6r"><p class="description svelte-i18k6r">Read-only status for every database. Schema version is <code class="svelte-i18k6r">PRAGMA user_version</code>. Pending is reported when the CLI cannot confirm
      the schema is current.</p> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-i18k6r" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (data) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<table class="migration-table svelte-i18k6r"><thead><tr><th scope="col" class="svelte-i18k6r">DB</th><th scope="col" class="svelte-i18k6r">Schema</th><th scope="col" class="svelte-i18k6r">Status</th><th scope="col" class="svelte-i18k6r">Message</th></tr></thead><tbody class="svelte-i18k6r"><!--[-->`);
							const each_array = ensure_array_like(Object.entries(data.databases));
							for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
								let [name, report] = each_array[$$index];
								$$renderer.push(`<tr class="svelte-i18k6r"><td class="svelte-i18k6r"><code class="svelte-i18k6r">${escape_html(name)}</code></td><td class="cell-mono svelte-i18k6r">${escape_html(report.schemaVersion ?? "—")}</td><td class="svelte-i18k6r">`);
								Badge($$renderer, {
									tone: statusTone(report),
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->${escape_html(statusLabel(report))}`);
									}});
								$$renderer.push(`<!----></td><td class="cell-msg svelte-i18k6r">${escape_html(report.message)}</td></tr>`);
							}
							$$renderer.push(`<!--]--></tbody></table> <div class="note svelte-i18k6r"><span class="note-label svelte-i18k6r">NOTE</span> ${escape_html(data.note)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/lib/components/admin/ScanModal.svelte
function ScanModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Bindable open state. */
		/** Close callback — fires after user dismisses. */
		/** Callback fired when a scan completes successfully (refresh list). */
		let { open = true, onClose, onSuccess } = $$props;
		let roots = "~/code,~/projects,/mnt/projects";
		let maxDepth = "4";
		let autoRegister = false;
		let loading = false;
		let result = null;
		let errorMsg = null;
		function handleClose() {
			open = false;
			onClose?.();
		}
		async function runScan() {
			loading = true;
			result = null;
			errorMsg = null;
			const depth = Number.parseInt(maxDepth, 10);
			try {
				const envelope = await (await fetch("/api/project/scan", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify({
						roots,
						maxDepth: Number.isFinite(depth) ? depth : void 0,
						autoRegister
					})
				})).json();
				if (!envelope.success) errorMsg = envelope.error?.message ?? "Scan failed";
				else {
					const data = envelope.data ?? {};
					result = {
						registered: typeof data["registered"] === "number" ? data["registered"] : void 0,
						unregistered: typeof data["unregistered"] === "number" ? data["unregistered"] : void 0,
						total: typeof data["total"] === "number" ? data["total"] : void 0,
						paths: Array.isArray(data["paths"]) ? data["paths"].slice(0, 50) : void 0
					};
					onSuccess?.();
				}
			} catch (err) {
				errorMsg = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				loading = false;
			}
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: handleClose,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Close`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "primary",
						loading,
						onclick: runScan,
						children: ($$renderer) => {
							$$renderer.push(`<!---->${escape_html(loading ? "Scanning" : "Run scan")}`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Scan for Projects",
					maxWidth: 34,
					onclose: handleClose,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<div class="scan-body svelte-1y7f472">`);
						Input($$renderer, {
							label: "Root paths (comma-separated)",
							description: "Absolute or home-relative directories to crawl. `~` is expanded server-side.",
							placeholder: "~/code,~/projects,/mnt/projects",
							get value() {
								return roots;
							},
							set value($$value) {
								roots = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Input($$renderer, {
							type: "number",
							label: "Max depth",
							description: "Directory levels to descend before stopping.",
							placeholder: "4",
							get value() {
								return maxDepth;
							},
							set value($$value) {
								maxDepth = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> <label class="auto-row svelte-1y7f472"><input type="checkbox"${attr("checked", autoRegister, true)} class="auto-check svelte-1y7f472"/> <span class="auto-label svelte-1y7f472">Auto-register discovered projects</span></label> `);
						if (errorMsg) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="alert svelte-1y7f472" role="alert">${escape_html(errorMsg)}</div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> `);
						if (result) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="result-panel svelte-1y7f472" role="status"><div class="counts svelte-1y7f472">`);
							if (result.total !== void 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<div class="count-chip svelte-1y7f472"><span class="count-num svelte-1y7f472">${escape_html(result.total)}</span> <span class="count-lbl svelte-1y7f472">Found</span></div>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--> `);
							if (result.registered !== void 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<div class="count-chip t-success svelte-1y7f472"><span class="count-num svelte-1y7f472">${escape_html(result.registered)}</span> <span class="count-lbl svelte-1y7f472">Registered</span></div>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--> `);
							if (result.unregistered !== void 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<div class="count-chip t-warning svelte-1y7f472"><span class="count-num svelte-1y7f472">${escape_html(result.unregistered)}</span> <span class="count-lbl svelte-1y7f472">Unregistered</span></div>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div> `);
							if (result.paths && result.paths.length > 0) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<ul class="paths svelte-1y7f472"><!--[-->`);
								const each_array = ensure_array_like(result.paths);
								for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
									let p = each_array[$$index];
									$$renderer.push(`<li class="path svelte-1y7f472">${escape_html(p)}</li>`);
								}
								$$renderer.push(`<!--]--></ul>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div>`);
					},
					$$slots: {
						footer: true,
						default: true
					}
				});
			}
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
		bind_props($$props, { open });
	});
}
//#endregion
//#region src/routes/projects/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		let showScan = false;
		let showClean = false;
		let showBackup = false;
		let showDoctor = false;
		let showMigration = false;
		let showGc = false;
		let deleteTarget = null;
		let projects = [...data.projects];
		const rowStates = {};
		const rowErrors = {};
		let bulkRunning = false;
		let bulkSummary = null;
		let bulkError = null;
		function formatCount(n) {
			if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
			return String(n);
		}
		/**
		* Relative-time formatter with ISO tooltip. Audit item #1 — "Last
		* Indexed" now shows full precision rather than date-only.
		*/
		function formatRelative(iso) {
			if (!iso) return "never";
			try {
				const t = new Date(iso).getTime();
				const delta = Date.now() - t;
				if (delta < 6e4) return "just now";
				if (delta < 36e5) return `${Math.floor(delta / 6e4)}m ago`;
				if (delta < 864e5) return `${Math.floor(delta / 36e5)}h ago`;
				const days = Math.floor(delta / 864e5);
				if (days < 30) return `${days}d ago`;
				if (days < 365) return `${Math.floor(days / 30)}mo ago`;
				return `${Math.floor(days / 365)}y ago`;
			} catch {
				return iso;
			}
		}
		function formatIso(iso) {
			if (!iso) return "";
			try {
				return new Date(iso).toISOString();
			} catch {
				return iso;
			}
		}
		const SEVEN_DAYS_MS = 10080 * 60 * 1e3;
		function isStale(lastIndexed) {
			if (!lastIndexed) return false;
			return Date.now() - new Date(lastIndexed).getTime() > SEVEN_DAYS_MS;
		}
		function healthTone(status, stale) {
			if (status === "unhealthy") return "danger";
			if (stale) return "warning";
			if (status === "healthy") return "success";
			return "neutral";
		}
		function healthLabel(status, stale, neverIndexed) {
			if (status === "unhealthy") return "unhealthy";
			if (neverIndexed) return "unindexed";
			if (stale) return "stale";
			if (status === "healthy") return "healthy";
			return status;
		}
		async function handleIndex(projectId, action) {
			rowStates[projectId] = "loading";
			rowErrors[projectId] = "";
			try {
				const envelope = await (await fetch(`/api/project/${encodeURIComponent(projectId)}/${action}`, { method: "POST" })).json();
				if (envelope.success) {
					rowStates[projectId] = "success";
					const idx = projects.findIndex((p) => p.projectId === projectId);
					if (idx >= 0) projects[idx] = {
						...projects[idx],
						lastIndexed: (/* @__PURE__ */ new Date()).toISOString()
					};
				} else {
					rowStates[projectId] = "error";
					rowErrors[projectId] = envelope.error?.message ?? "Index failed";
				}
			} catch (err) {
				rowStates[projectId] = "error";
				rowErrors[projectId] = err instanceof Error ? err.message : "Unexpected error";
			}
			if (rowStates[projectId] === "success") setTimeout(() => {
				rowStates[projectId] = "idle";
			}, 3e3);
		}
		async function confirmDelete() {
			if (!deleteTarget) return;
			const { projectId } = deleteTarget;
			deleteTarget = null;
			rowStates[projectId] = "loading";
			rowErrors[projectId] = "";
			try {
				const envelope = await (await fetch(`/api/project/${encodeURIComponent(projectId)}`, { method: "DELETE" })).json();
				if (envelope.success) projects = projects.filter((p) => p.projectId !== projectId);
				else {
					rowStates[projectId] = "error";
					rowErrors[projectId] = envelope.error?.message ?? "Delete failed";
				}
			} catch (err) {
				rowStates[projectId] = "error";
				rowErrors[projectId] = err instanceof Error ? err.message : "Unexpected error";
			}
		}
		async function runBulkReindex() {
			if (!confirm("Re-index every registered project serially? This can take a while.")) return;
			bulkRunning = true;
			bulkError = null;
			bulkSummary = null;
			try {
				const env = await (await fetch("/api/project/reindex-all", {
					method: "POST",
					headers: { "Content-Type": "application/json" },
					body: JSON.stringify({})
				})).json();
				if (env.success && env.data) bulkSummary = {
					total: env.data.total,
					succeeded: env.data.succeeded,
					failed: env.data.failed,
					skipped: env.data.skipped
				};
				else bulkError = env.error?.message ?? "Bulk reindex failed";
			} catch (err) {
				bulkError = err instanceof Error ? err.message : "Unexpected error";
			} finally {
				bulkRunning = false;
			}
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			head("rqn88j", $$renderer, ($$renderer) => {
				$$renderer.title(($$renderer) => {
					$$renderer.push(`<title>Admin — CLEO Studio</title>`);
				});
			});
			if (showScan) {
				$$renderer.push("<!--[0-->");
				ScanModal($$renderer, {
					onClose: () => showScan = false,
					get open() {
						return showScan;
					},
					set open($$value) {
						showScan = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (showClean) {
				$$renderer.push("<!--[0-->");
				CleanModal($$renderer, {
					onClose: () => showClean = false,
					get open() {
						return showClean;
					},
					set open($$value) {
						showClean = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (showBackup) {
				$$renderer.push("<!--[0-->");
				BackupModal($$renderer, {
					onClose: () => showBackup = false,
					get open() {
						return showBackup;
					},
					set open($$value) {
						showBackup = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (showDoctor) {
				$$renderer.push("<!--[0-->");
				DoctorModal($$renderer, {
					onClose: () => showDoctor = false,
					get open() {
						return showDoctor;
					},
					set open($$value) {
						showDoctor = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (showMigration) {
				$$renderer.push("<!--[0-->");
				MigrationModal($$renderer, {
					onClose: () => showMigration = false,
					get open() {
						return showMigration;
					},
					set open($$value) {
						showMigration = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (showGc) {
				$$renderer.push("<!--[0-->");
				GcModal($$renderer, {
					onClose: () => showGc = false,
					get open() {
						return showGc;
					},
					set open($$value) {
						showGc = $$value;
						$$settled = false;
					}
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (deleteTarget) {
				$$renderer.push("<!--[0-->");
				DeleteConfirmModal($$renderer, {
					projectName: deleteTarget.name,
					onConfirm: confirmDelete,
					onClose: () => deleteTarget = null
				});
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> <div class="admin-view svelte-rqn88j">`);
			{
				function actions($$renderer) {
					Button($$renderer, {
						variant: "secondary",
						size: "sm",
						onclick: () => showScan = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Scan`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						size: "sm",
						onclick: () => showBackup = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Backup`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						size: "sm",
						onclick: () => showDoctor = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Doctor`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						size: "sm",
						onclick: () => showMigration = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Schema`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "secondary",
						size: "sm",
						onclick: () => showGc = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->GC`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "ghost",
						size: "sm",
						onclick: runBulkReindex,
						loading: bulkRunning,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Reindex all`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "danger",
						size: "sm",
						onclick: () => showClean = true,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Clean`);
						}});
					$$renderer.push(`<!---->`);
				}
				HeroHeader($$renderer, {
					eyebrow: "PROJECT REGISTRY",
					title: "Admin",
					subtitle: "Scan · index · doctor · backup. Every mutation is audited.",
					meta: data.activeProjectName,
					actions});
			}
			$$renderer.push(`<!----> `);
			if (bulkError) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<div class="bulk-alert svelte-rqn88j" role="alert">Bulk reindex failed: ${escape_html(bulkError)}</div>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (bulkSummary) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<div class="bulk-summary svelte-rqn88j" role="status">`);
				Badge($$renderer, {
					tone: bulkSummary.failed === 0 ? "success" : "warning",
					size: "md",
					children: ($$renderer) => {
						$$renderer.push(`<!---->${escape_html(bulkSummary.succeeded)}/${escape_html(bulkSummary.total)} reindexed`);
					}});
				$$renderer.push(`<!----> `);
				if (bulkSummary.failed > 0) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<span class="bulk-failed svelte-rqn88j">${escape_html(bulkSummary.failed)} failed</span>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--> `);
				if (bulkSummary.skipped > 0) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<span class="bulk-skipped svelte-rqn88j">${escape_html(bulkSummary.skipped)} skipped</span>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--></div>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> <div class="admin-layout svelte-rqn88j"><section class="admin-main svelte-rqn88j">`);
			if (projects.length === 0) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<div class="empty-state svelte-rqn88j"><p class="empty-title svelte-rqn88j">No projects registered</p> <p class="empty-detail svelte-rqn88j">Run <code class="svelte-rqn88j">cleo nexus projects register</code> or use the <strong>Scan</strong> button
            above.</p></div>`);
			} else {
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`<div class="project-grid svelte-rqn88j"><!--[-->`);
				const each_array = ensure_array_like(projects);
				for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
					let project = each_array[$$index];
					const isActive = data.activeProjectId === project.projectId;
					const rowState = rowStates[project.projectId] ?? "idle";
					const rowError = rowErrors[project.projectId] ?? "";
					const neverIndexed = project.lastIndexed === null;
					const stale = isStale(project.lastIndexed);
					{
						function header($$renderer) {
							$$renderer.push(`<div class="card-head svelte-rqn88j"><div class="card-identity svelte-rqn88j"><span class="card-name svelte-rqn88j">${escape_html(project.name)}</span> `);
							if (isActive) {
								$$renderer.push("<!--[0-->");
								Badge($$renderer, {
									tone: "success",
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->ACTIVE`);
									}});
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--> `);
							Badge($$renderer, {
								tone: healthTone(project.healthStatus, stale),
								size: "sm",
								children: ($$renderer) => {
									$$renderer.push(`<!---->${escape_html(healthLabel(project.healthStatus, stale, neverIndexed))}`);
								}});
							$$renderer.push(`<!----></div> <code class="card-path svelte-rqn88j">${escape_html(project.projectPath)}</code></div>`);
						}
						function footer($$renderer) {
							$$renderer.push(`<div class="card-actions svelte-rqn88j">`);
							if (!isActive) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<form method="POST" action="?/switchProject"><input type="hidden" name="projectId"${attr("value", project.projectId)}/> `);
								Button($$renderer, {
									type: "submit",
									variant: "primary",
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->Switch`);
									}});
								$$renderer.push(`<!----></form>`);
							} else {
								$$renderer.push("<!--[-1-->");
								$$renderer.push(`<form method="POST" action="?/clearProject">`);
								Button($$renderer, {
									type: "submit",
									variant: "ghost",
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->Clear`);
									}});
								$$renderer.push(`<!----></form>`);
							}
							$$renderer.push(`<!--]--> `);
							Button($$renderer, {
								variant: "secondary",
								size: "sm",
								disabled: rowState === "loading",
								loading: rowState === "loading",
								onclick: () => handleIndex(project.projectId, neverIndexed ? "index" : "reindex"),
								children: ($$renderer) => {
									$$renderer.push(`<!---->${escape_html(neverIndexed ? "Index" : "Re-index")}`);
								}});
							$$renderer.push(`<!----> `);
							Button($$renderer, {
								variant: "ghost",
								size: "sm",
								onclick: () => {
									showDoctor = true;
								},
								children: ($$renderer) => {
									$$renderer.push(`<!---->Doctor`);
								}});
							$$renderer.push(`<!----> <div class="card-actions-right svelte-rqn88j">`);
							Button($$renderer, {
								variant: "danger",
								size: "sm",
								disabled: rowState === "loading",
								onclick: () => deleteTarget = {
									projectId: project.projectId,
									name: project.name
								},
								children: ($$renderer) => {
									$$renderer.push(`<!---->Delete`);
								}});
							$$renderer.push(`<!----> `);
							if (rowState === "success") {
								$$renderer.push("<!--[0-->");
								Badge($$renderer, {
									tone: "success",
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<!---->done`);
									}});
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--> `);
							if (rowState === "error" && rowError) {
								$$renderer.push("<!--[0-->");
								Badge($$renderer, {
									tone: "danger",
									size: "sm",
									children: ($$renderer) => {
										$$renderer.push(`<span${attr("title", rowError)}>error</span>`);
									}});
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></div></div>`);
						}
						Card($$renderer, {
							padding: "cozy",
							class: isActive ? "project-card is-active" : "project-card",
							header,
							footer,
							children: ($$renderer) => {
								$$renderer.push(`<div class="card-stats svelte-rqn88j"><div class="card-stat svelte-rqn88j"><span class="card-stat-value svelte-rqn88j">${escape_html(formatCount(project.taskCount))}</span> <span class="card-stat-label svelte-rqn88j">Tasks</span></div> <div class="card-stat svelte-rqn88j"><span class="card-stat-value svelte-rqn88j">${escape_html(formatCount(project.nodeCount))}</span> <span class="card-stat-label svelte-rqn88j">Symbols</span></div> <div class="card-stat svelte-rqn88j"><span class="card-stat-value svelte-rqn88j">${escape_html(formatCount(project.relationCount))}</span> <span class="card-stat-label svelte-rqn88j">Relations</span></div> <div class="card-stat svelte-rqn88j"><span class="card-stat-value svelte-rqn88j"${attr("title", formatIso(project.lastIndexed))}>${escape_html(formatRelative(project.lastIndexed))}</span> <span class="card-stat-label svelte-rqn88j">Last indexed</span></div></div>`);
							}});
					}
				}
				$$renderer.push(`<!--]--></div>`);
			}
			$$renderer.push(`<!--]--></section> <aside class="admin-rail svelte-rqn88j" aria-label="Audit trail">`);
			AuditLogPanel($$renderer, { initial: data.auditEntries });
			$$renderer.push(`<!----></aside></div></div>`);
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
	});
}

export { _page as default };
//# sourceMappingURL=_page.svelte-DtGADbrV.js.map
