import { c as escape_html, d as attr_style, a as attr, b as attr_class, f as stringify, y as bind_props, g as derived, e as ensure_array_like } from './dev-BNpEUZI3.js';
import 'node:module';
import { C as Card, B as Badge } from './Tabs-DzG6Bn9a.js';
import { S as Spinner, C as ChipGroup, I as Input, a as Select, B as Button, M as Modal, T as Textarea, b as Chip } from './ui-DR8zOSpC.js';

//#region src/lib/components/memory/ConfidenceBadge.svelte
function ConfidenceBadge($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link ConfidenceBadge}.
		*/
		/** Confidence level — string-keyed so adapter payloads flow in unchanged. */
		/** Optional numeric confidence [0..1] — rendered after the label when present. */
		/** Size. Defaults to `sm`. */
		let { confidence, value, size = "sm" } = $$props;
		const normalized = derived(() => (confidence ?? "unknown").toString().toLowerCase());
		const tone = derived(() => {
			if (normalized() === "high") return "success";
			if (normalized() === "medium") return "warning";
			if (normalized() === "low") return "danger";
			return "neutral";
		});
		const shown = derived(() => typeof value === "number" && Number.isFinite(value) ? `${normalized()} · ${value.toFixed(2)}` : normalized());
		Badge($$renderer, {
			tone: tone(),
			size,
			children: ($$renderer) => {
				$$renderer.push(`<!---->${escape_html(shown())}`);
			}});
	});
}
//#endregion
//#region src/lib/components/memory/DecisionModal.svelte
function DecisionModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link DecisionModal}.
		*/
		/** Bindable visibility. */
		/** Called with the new decision ID on successful save. */
		/** Called with a human-readable error when the save fails. */
		let { open = false, onSuccess, onError } = $$props;
		let decision = "";
		let rationale = "";
		let alternatives = [];
		let altDraft = "";
		let taskId = "";
		let epicId = "";
		let submitting = false;
		let formError = null;
		let decisionError = null;
		let rationaleError = null;
		function addAlt() {
			const v = altDraft.trim();
			if (!v) return;
			if (alternatives.includes(v)) {
				altDraft = "";
				return;
			}
			alternatives = [...alternatives, v];
			altDraft = "";
		}
		function removeAlt(v) {
			alternatives = alternatives.filter((a) => a !== v);
		}
		function validate() {
			let ok = true;
			decisionError = null;
			rationaleError = null;
			if (decision.trim().length < 1) {
				decisionError = "Decision statement is required.";
				ok = false;
			}
			if (rationale.trim().length < 1) {
				rationaleError = "Rationale is required.";
				ok = false;
			}
			return ok;
		}
		function reset() {
			decision = "";
			rationale = "";
			alternatives = [];
			altDraft = "";
			taskId = "";
			epicId = "";
			submitting = false;
			formError = null;
			decisionError = null;
			rationaleError = null;
		}
		async function submit() {
			if (submitting) return;
			if (!validate()) return;
			submitting = true;
			formError = null;
			try {
				const res = await fetch("/api/memory/decision-store", {
					method: "POST",
					headers: { "content-type": "application/json" },
					body: JSON.stringify({
						decision: decision.trim(),
						rationale: rationale.trim(),
						alternatives: alternatives.length > 0 ? alternatives : void 0,
						taskId: taskId.trim() || void 0,
						contextEpicId: epicId.trim() || void 0
					})
				});
				const body = await res.json();
				if (!res.ok || body.success === false) {
					const msg = body.error?.message ?? `HTTP ${res.status}`;
					throw new Error(msg);
				}
				const id = body.data?.id ?? "";
				onSuccess?.(id);
				reset();
				open = false;
			} catch (e) {
				const msg = e instanceof Error ? e.message : "Save failed";
				formError = msg;
				onError?.(msg);
			} finally {
				submitting = false;
			}
		}
		function onClose() {
			if (!submitting) reset();
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: () => open = false,
						disabled: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Cancel`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "primary",
						onclick: () => {
							submit();
						},
						loading: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Store decision`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Store decision",
					onclose: onClose,
					maxWidth: 36,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<form class="decision-form svelte-1kp2dw1">`);
						Textarea($$renderer, {
							label: "Decision",
							placeholder: "We decided to…",
							rows: 2,
							autoResize: true,
							error: decisionError ?? void 0,
							required: true,
							get value() {
								return decision;
							},
							set value($$value) {
								decision = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Textarea($$renderer, {
							label: "Rationale",
							placeholder: "Why this choice — constraints, trade-offs, evidence",
							rows: 4,
							autoResize: true,
							error: rationaleError ?? void 0,
							required: true,
							get value() {
								return rationale;
							},
							set value($$value) {
								rationale = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> <div class="alt-field svelte-1kp2dw1"><span class="alt-label svelte-1kp2dw1">Alternatives considered</span> <div class="alt-row svelte-1kp2dw1">`);
						Input($$renderer, {
							value: altDraft,
							placeholder: "Add alternative and press Enter",
							oninput: (e) => altDraft = e.target.value
						});
						$$renderer.push(`<!----> `);
						Button($$renderer, {
							variant: "secondary",
							size: "sm",
							onclick: addAlt,
							children: ($$renderer) => {
								$$renderer.push(`<!---->Add`);
							}});
						$$renderer.push(`<!----></div> `);
						if (alternatives.length > 0) {
							$$renderer.push("<!--[0-->");
							ChipGroup($$renderer, {
								label: "Alternatives",
								children: ($$renderer) => {
									$$renderer.push(`<!--[-->`);
									const each_array = ensure_array_like(alternatives);
									for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
										let alt = each_array[$$index];
										Chip($$renderer, {
											mode: "action",
											active: true,
											onclick: () => removeAlt(alt),
											children: ($$renderer) => {
												$$renderer.push(`<!---->${escape_html(alt)} ✕`);
											},
											$$slots: { default: true }
										});
									}
									$$renderer.push(`<!--]-->`);
								}});
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> <input type="hidden"/></div> <div class="ctx-grid svelte-1kp2dw1">`);
						Input($$renderer, {
							label: "Task ID (optional)",
							placeholder: "T123",
							get value() {
								return taskId;
							},
							set value($$value) {
								taskId = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Input($$renderer, {
							label: "Epic ID (optional)",
							placeholder: "T100",
							get value() {
								return epicId;
							},
							set value($$value) {
								epicId = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----></div> `);
						if (formError) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<p class="form-error svelte-1kp2dw1" role="alert" aria-live="polite">${escape_html(formError)}</p>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></form>`);
					},
					$$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/memory/FilterBar.svelte
function FilterBar($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link FilterBar}.
		*/
		/** Current filter value (controlled). */
		/** Tier options offered. Omit to hide the tier row. */
		/** Type options offered. Omit to hide the type row. */
		/** Status options offered. Omit to hide the status row. */
		/** Confidence options offered. Omit to hide the confidence row. */
		/** When true, render the min-quality slider. Defaults to `true`. */
		/** When true, render the free-text search input. Defaults to `false`. */
		/** Search placeholder. */
		/** Called whenever any filter changes. */
		let { value, tiers, types, statuses, confidences, showQuality = true, showSearch = false, searchPlaceholder = "Search…", onChange } = $$props;
		function emit(patch) {
			onChange({
				...value,
				...patch
			});
		}
		function setTier(t) {
			emit({ tier: value.tier === t ? null : t });
		}
		function setType(t) {
			emit({ type: value.type === t ? null : t });
		}
		function setStatus(s) {
			emit({ status: value.status === s ? null : s });
		}
		function setConfidence(c) {
			emit({ confidence: value.confidence === c ? null : c });
		}
		const TIER_TINT = {
			short: "var(--text-faint)",
			medium: "var(--info)",
			long: "var(--success)"
		};
		const STATUS_TINT = {
			verified: "var(--success)",
			prune: "var(--warning)",
			invalidated: "var(--danger)"
		};
		const CONFIDENCE_TINT = {
			high: "var(--success)",
			medium: "var(--warning)",
			low: "var(--danger)",
			unknown: "var(--text-faint)"
		};
		const qualityValue = derived(() => value.minQuality ?? 0);
		const qualityPct = derived(() => Math.round(qualityValue() * 100));
		$$renderer.push(`<section class="filter-bar svelte-owyv35" aria-label="Memory filters">`);
		if (tiers && tiers.length > 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row svelte-owyv35"><span class="row-label svelte-owyv35">Tier</span> `);
			ChipGroup($$renderer, {
				label: "Tier",
				children: ($$renderer) => {
					$$renderer.push(`<!--[-->`);
					const each_array = ensure_array_like(tiers);
					for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
						let t = each_array[$$index];
						Chip($$renderer, {
							mode: "toggle",
							active: value.tier === t,
							tint: TIER_TINT[t],
							onclick: () => setTier(t),
							children: ($$renderer) => {
								$$renderer.push(`<!---->${escape_html(t)}`);
							},
							$$slots: { default: true }
						});
					}
					$$renderer.push(`<!--]-->`);
				}});
			$$renderer.push(`<!----></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (types && types.length > 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row svelte-owyv35"><span class="row-label svelte-owyv35">Type</span> `);
			ChipGroup($$renderer, {
				label: "Type",
				children: ($$renderer) => {
					$$renderer.push(`<!--[-->`);
					const each_array_1 = ensure_array_like(types);
					for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
						let t = each_array_1[$$index_1];
						Chip($$renderer, {
							mode: "toggle",
							active: value.type === t,
							onclick: () => setType(t),
							children: ($$renderer) => {
								$$renderer.push(`<!---->${escape_html(t)}`);
							},
							$$slots: { default: true }
						});
					}
					$$renderer.push(`<!--]-->`);
				}});
			$$renderer.push(`<!----></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (statuses && statuses.length > 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row svelte-owyv35"><span class="row-label svelte-owyv35">Status</span> `);
			ChipGroup($$renderer, {
				label: "Status",
				children: ($$renderer) => {
					$$renderer.push(`<!--[-->`);
					const each_array_2 = ensure_array_like(statuses);
					for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
						let s = each_array_2[$$index_2];
						Chip($$renderer, {
							mode: "toggle",
							active: value.status === s,
							tint: STATUS_TINT[s],
							onclick: () => setStatus(s),
							children: ($$renderer) => {
								$$renderer.push(`<!---->${escape_html(s)}`);
							},
							$$slots: { default: true }
						});
					}
					$$renderer.push(`<!--]-->`);
				}});
			$$renderer.push(`<!----></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (confidences && confidences.length > 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row svelte-owyv35"><span class="row-label svelte-owyv35">Confidence</span> `);
			ChipGroup($$renderer, {
				label: "Confidence",
				children: ($$renderer) => {
					$$renderer.push(`<!--[-->`);
					const each_array_3 = ensure_array_like(confidences);
					for (let $$index_3 = 0, $$length = each_array_3.length; $$index_3 < $$length; $$index_3++) {
						let c = each_array_3[$$index_3];
						Chip($$renderer, {
							mode: "toggle",
							active: value.confidence === c,
							tint: CONFIDENCE_TINT[c],
							onclick: () => setConfidence(c),
							children: ($$renderer) => {
								$$renderer.push(`<!---->${escape_html(c)}`);
							},
							$$slots: { default: true }
						});
					}
					$$renderer.push(`<!--]-->`);
				}});
			$$renderer.push(`<!----></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (showQuality) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row svelte-owyv35"><span class="row-label svelte-owyv35">Quality ≥</span> <div class="quality-wrap svelte-owyv35"><input class="slider svelte-owyv35" type="range" min="0" max="1" step="0.05"${attr("value", qualityValue())}${attr("aria-label", `Minimum quality: ${qualityPct()}%`)}/> <span class="slider-value svelte-owyv35">`);
			if (value.minQuality === void 0) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`any`);
			} else {
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`${escape_html(qualityValue().toFixed(2))}`);
			}
			$$renderer.push(`<!--]--></span> `);
			if (value.minQuality !== void 0) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<button type="button" class="clear-btn svelte-owyv35" aria-label="Clear quality filter">clear</button>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--></div></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		if (showSearch) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="row search-row svelte-owyv35">`);
			Input($$renderer, {
				type: "search",
				value: value.q ?? "",
				label: "Search",
				placeholder: searchPlaceholder,
				oninput: (e) => emit({ q: e.target.value })
			});
			$$renderer.push(`<!----></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></section>`);
	});
}
//#endregion
//#region src/lib/components/memory/LearningModal.svelte
function LearningModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link LearningModal}.
		*/
		/** Bindable visibility. */
		/** Called with the new learning ID on successful save. */
		/** Called with a human-readable error when the save fails. */
		let { open = false, onSuccess, onError } = $$props;
		let insight = "";
		let source = "";
		let confidence = .5;
		let actionable = false;
		let application = "";
		let tagDraft = "";
		let applicableTypes = [];
		let submitting = false;
		let formError = null;
		let insightError = null;
		let sourceError = null;
		function addTag() {
			const v = tagDraft.trim();
			if (!v) return;
			if (applicableTypes.includes(v)) {
				tagDraft = "";
				return;
			}
			applicableTypes = [...applicableTypes, v];
			tagDraft = "";
		}
		function removeTag(v) {
			applicableTypes = applicableTypes.filter((t) => t !== v);
		}
		function validate() {
			let ok = true;
			insightError = null;
			sourceError = null;
			if (insight.trim().length < 1) {
				insightError = "Insight statement is required.";
				ok = false;
			}
			if (source.trim().length < 1) {
				sourceError = "Source reference is required.";
				ok = false;
			}
			return ok;
		}
		function reset() {
			insight = "";
			source = "";
			confidence = .5;
			actionable = false;
			application = "";
			tagDraft = "";
			applicableTypes = [];
			submitting = false;
			formError = null;
			insightError = null;
			sourceError = null;
		}
		async function submit() {
			if (submitting) return;
			if (!validate()) return;
			submitting = true;
			formError = null;
			try {
				const res = await fetch("/api/memory/learning-store", {
					method: "POST",
					headers: { "content-type": "application/json" },
					body: JSON.stringify({
						insight: insight.trim(),
						source: source.trim(),
						confidence,
						actionable,
						application: application.trim() || void 0,
						applicableTypes: applicableTypes.length > 0 ? applicableTypes : void 0
					})
				});
				const body = await res.json();
				if (!res.ok || body.success === false) {
					const msg = body.error?.message ?? `HTTP ${res.status}`;
					throw new Error(msg);
				}
				const id = body.data?.id ?? "";
				onSuccess?.(id);
				reset();
				open = false;
			} catch (e) {
				const msg = e instanceof Error ? e.message : "Save failed";
				formError = msg;
				onError?.(msg);
			} finally {
				submitting = false;
			}
		}
		function onClose() {
			if (!submitting) reset();
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: () => open = false,
						disabled: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Cancel`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "primary",
						onclick: () => {
							submit();
						},
						loading: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Store learning`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Store learning",
					onclose: onClose,
					maxWidth: 36,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<form class="learning-form svelte-1l6q7v5">`);
						Textarea($$renderer, {
							label: "Insight",
							placeholder: "The key thing you learned",
							rows: 3,
							autoResize: true,
							error: insightError ?? void 0,
							required: true,
							get value() {
								return insight;
							},
							set value($$value) {
								insight = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Input($$renderer, {
							label: "Source",
							placeholder: "Where this came from — file, task, session, commit",
							error: sourceError ?? void 0,
							required: true,
							get value() {
								return source;
							},
							set value($$value) {
								source = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> <div class="confidence-field svelte-1l6q7v5"><span class="field-label svelte-1l6q7v5">Confidence · ${escape_html(confidence.toFixed(2))}</span> <input class="slider svelte-1l6q7v5" type="range" min="0" max="1" step="0.05"${attr("value", confidence)} aria-label="Confidence"/></div> <label class="checkbox-row svelte-1l6q7v5"><input type="checkbox"${attr("checked", actionable, true)} class="svelte-1l6q7v5"/> <span>Actionable — concrete steps recorded below</span></label> `);
						if (actionable) {
							$$renderer.push("<!--[0-->");
							Textarea($$renderer, {
								label: "How to apply",
								placeholder: "Concrete application of the insight",
								rows: 3,
								autoResize: true,
								get value() {
									return application;
								},
								set value($$value) {
									application = $$value;
									$$settled = false;
								}
							});
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> <div class="tag-field svelte-1l6q7v5"><span class="field-label svelte-1l6q7v5">Applicable types (optional)</span> <div class="tag-row svelte-1l6q7v5">`);
						Input($$renderer, {
							value: tagDraft,
							placeholder: "e.g. refactor, pattern — press Add",
							oninput: (e) => tagDraft = e.target.value
						});
						$$renderer.push(`<!----> `);
						Button($$renderer, {
							variant: "secondary",
							size: "sm",
							onclick: addTag,
							children: ($$renderer) => {
								$$renderer.push(`<!---->Add`);
							}});
						$$renderer.push(`<!----></div> `);
						if (applicableTypes.length > 0) {
							$$renderer.push("<!--[0-->");
							ChipGroup($$renderer, {
								label: "Tags",
								children: ($$renderer) => {
									$$renderer.push(`<!--[-->`);
									const each_array = ensure_array_like(applicableTypes);
									for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
										let t = each_array[$$index];
										Chip($$renderer, {
											mode: "action",
											active: true,
											onclick: () => removeTag(t),
											children: ($$renderer) => {
												$$renderer.push(`<!---->${escape_html(t)} ✕`);
											},
											$$slots: { default: true }
										});
									}
									$$renderer.push(`<!--]-->`);
								}});
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></div> `);
						if (formError) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<p class="form-error svelte-1l6q7v5" role="alert" aria-live="polite">${escape_html(formError)}</p>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></form>`);
					},
					$$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/memory/ObserveModal.svelte
function ObserveModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Local mirror of `MemoryObservationKind` from
		* `@cleocode/contracts/operations/memory` — the root contracts
		* package only re-exports the higher-level `Memory*` shapes, so we
		* pin the literal union here. Keep in sync with the contract file.
		*/
		/**
		* Props for {@link ObserveModal}.
		*/
		/** Bindable visibility. */
		/** Called with the new observation ID on successful save. */
		/** Called with a human-readable error when the save fails. */
		let { open = false, onSuccess, onError } = $$props;
		const TYPE_OPTIONS = [
			{
				value: "discovery",
				label: "Discovery"
			},
			{
				value: "change",
				label: "Change"
			},
			{
				value: "feature",
				label: "Feature"
			},
			{
				value: "bugfix",
				label: "Bug fix"
			},
			{
				value: "decision",
				label: "Decision"
			},
			{
				value: "refactor",
				label: "Refactor"
			}
		];
		let title = "";
		let text = "";
		let observationType = "discovery";
		let submitting = false;
		let formError = null;
		let titleError = null;
		let textError = null;
		function validate() {
			let ok = true;
			titleError = null;
			textError = null;
			if (title.trim().length < 1) {
				titleError = "Title is required.";
				ok = false;
			} else if (title.length > 200) {
				titleError = "Title must be 200 characters or fewer.";
				ok = false;
			}
			if (text.trim().length < 1) {
				textError = "Observation body is required.";
				ok = false;
			} else if (text.length > 1e4) {
				textError = "Observation body is too long (max 10 000 chars).";
				ok = false;
			}
			return ok;
		}
		function reset() {
			title = "";
			text = "";
			observationType = "discovery";
			submitting = false;
			formError = null;
			titleError = null;
			textError = null;
		}
		async function submit() {
			if (submitting) return;
			if (!validate()) return;
			submitting = true;
			formError = null;
			try {
				const res = await fetch("/api/memory/observe", {
					method: "POST",
					headers: { "content-type": "application/json" },
					body: JSON.stringify({
						title: title.trim(),
						text: text.trim(),
						type: observationType
					})
				});
				const body = await res.json();
				if (!res.ok || body.success === false) {
					const msg = body.error?.message ?? `HTTP ${res.status}`;
					throw new Error(msg);
				}
				const id = body.data?.id ?? "";
				onSuccess?.(id);
				reset();
				open = false;
			} catch (e) {
				const msg = e instanceof Error ? e.message : "Save failed";
				formError = msg;
				onError?.(msg);
			} finally {
				submitting = false;
			}
		}
		function onClose() {
			if (!submitting) reset();
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: () => open = false,
						disabled: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Cancel`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "primary",
						onclick: () => {
							submit();
						},
						loading: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Save observation`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "New observation",
					onclose: onClose,
					maxWidth: 34,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<form class="observe-form svelte-rnbbhd">`);
						Input($$renderer, {
							label: "Title",
							placeholder: "Short memorable headline",
							error: titleError ?? void 0,
							required: true,
							get value() {
								return title;
							},
							set value($$value) {
								title = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Textarea($$renderer, {
							label: "Observation",
							placeholder: "What happened? What changed? What did you learn?",
							rows: 6,
							maxlength: 1e4,
							autoResize: true,
							error: textError ?? void 0,
							required: true,
							get value() {
								return text;
							},
							set value($$value) {
								text = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Select($$renderer, {
							label: "Kind",
							options: TYPE_OPTIONS,
							get value() {
								return observationType;
							},
							set value($$value) {
								observationType = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						if (formError) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<p class="form-error svelte-rnbbhd" role="alert" aria-live="polite">${escape_html(formError)}</p>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></form>`);
					},
					$$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/memory/Pagination.svelte
function Pagination($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link Pagination}.
		*/
		/** Current zero-based offset. */
		/** Page size. */
		/** Total item count returned by the server. */
		/** Called when user clicks Prev / Next. */
		let { offset, limit, total, onChange } = $$props;
		const pageIndex = derived(() => Math.floor(offset / Math.max(1, limit)) + 1);
		const pageCount = derived(() => Math.max(1, Math.ceil(total / Math.max(1, limit))));
		const hasPrev = derived(() => offset > 0);
		const hasNext = derived(() => offset + limit < total);
		const rangeStart = derived(() => total === 0 ? 0 : offset + 1);
		const rangeEnd = derived(() => Math.min(total, offset + limit));
		function goPrev() {
			if (!hasPrev()) return;
			onChange(Math.max(0, offset - limit));
		}
		function goNext() {
			if (!hasNext()) return;
			onChange(offset + limit);
		}
		$$renderer.push(`<nav class="pager svelte-hokvew" aria-label="Pagination">`);
		Button($$renderer, {
			variant: "subtle",
			size: "sm",
			disabled: !hasPrev(),
			onclick: goPrev,
			children: ($$renderer) => {
				$$renderer.push(`<!---->← Prev`);
			}});
		$$renderer.push(`<!----> <span class="status svelte-hokvew"><span class="range svelte-hokvew">${escape_html(rangeStart())}–${escape_html(rangeEnd())}</span> <span class="divider svelte-hokvew">of</span> <span class="total svelte-hokvew">${escape_html(total)}</span> <span class="dot svelte-hokvew">·</span> <span class="page svelte-hokvew">page ${escape_html(pageIndex())} / ${escape_html(pageCount())}</span></span> `);
		Button($$renderer, {
			variant: "subtle",
			size: "sm",
			disabled: !hasNext(),
			onclick: goNext,
			children: ($$renderer) => {
				$$renderer.push(`<!---->Next →`);
			}});
		$$renderer.push(`<!----></nav>`);
	});
}
//#endregion
//#region src/lib/components/memory/PatternModal.svelte
function PatternModal($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Local mirror of contracts `MemoryPatternType`. Keep in sync with operations/memory.ts. */
		/** Local mirror of contracts `MemoryPatternImpact`. */
		/**
		* Props for {@link PatternModal}.
		*/
		/** Bindable visibility. */
		/** Called with the new pattern ID on successful save. */
		/** Called with a human-readable error when the save fails. */
		let { open = false, onSuccess, onError } = $$props;
		const TYPE_OPTIONS = [
			{
				value: "workflow",
				label: "Workflow"
			},
			{
				value: "blocker",
				label: "Blocker"
			},
			{
				value: "success",
				label: "Success"
			},
			{
				value: "failure",
				label: "Failure"
			},
			{
				value: "optimization",
				label: "Optimization"
			}
		];
		const IMPACT_OPTIONS = [
			{
				value: "low",
				label: "Low"
			},
			{
				value: "medium",
				label: "Medium"
			},
			{
				value: "high",
				label: "High"
			}
		];
		let patternText = "";
		let contextText = "";
		let patternType = "workflow";
		let impact = "medium";
		let submitting = false;
		let formError = null;
		let patternError = null;
		let contextError = null;
		function validate() {
			let ok = true;
			patternError = null;
			contextError = null;
			if (patternText.trim().length < 1) {
				patternError = "Pattern description is required.";
				ok = false;
			}
			if (contextText.trim().length < 1) {
				contextError = "Context is required — where / when does this pattern apply?";
				ok = false;
			}
			return ok;
		}
		function reset() {
			patternText = "";
			contextText = "";
			patternType = "workflow";
			impact = "medium";
			submitting = false;
			formError = null;
			patternError = null;
			contextError = null;
		}
		async function submit() {
			if (submitting) return;
			if (!validate()) return;
			submitting = true;
			formError = null;
			try {
				const res = await fetch("/api/memory/pattern-store", {
					method: "POST",
					headers: { "content-type": "application/json" },
					body: JSON.stringify({
						pattern: patternText.trim(),
						context: contextText.trim(),
						type: patternType,
						impact
					})
				});
				const body = await res.json();
				if (!res.ok || body.success === false) {
					const msg = body.error?.message ?? `HTTP ${res.status}`;
					throw new Error(msg);
				}
				const id = body.data?.id ?? "";
				onSuccess?.(id);
				reset();
				open = false;
			} catch (e) {
				const msg = e instanceof Error ? e.message : "Save failed";
				formError = msg;
				onError?.(msg);
			} finally {
				submitting = false;
			}
		}
		function onClose() {
			if (!submitting) reset();
		}
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			{
				function footer($$renderer) {
					Button($$renderer, {
						variant: "ghost",
						onclick: () => open = false,
						disabled: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Cancel`);
						}});
					$$renderer.push(`<!----> `);
					Button($$renderer, {
						variant: "primary",
						onclick: () => {
							submit();
						},
						loading: submitting,
						children: ($$renderer) => {
							$$renderer.push(`<!---->Store pattern`);
						}});
					$$renderer.push(`<!---->`);
				}
				Modal($$renderer, {
					title: "Store pattern",
					onclose: onClose,
					maxWidth: 36,
					get open() {
						return open;
					},
					set open($$value) {
						open = $$value;
						$$settled = false;
					},
					footer,
					children: ($$renderer) => {
						$$renderer.push(`<form class="pattern-form svelte-dg4797">`);
						Textarea($$renderer, {
							label: "Pattern",
							placeholder: "Describe the recurring shape — what, when, why",
							rows: 4,
							autoResize: true,
							error: patternError ?? void 0,
							required: true,
							get value() {
								return patternText;
							},
							set value($$value) {
								patternText = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Textarea($$renderer, {
							label: "Context",
							placeholder: "Where does this apply? What triggers it?",
							rows: 3,
							autoResize: true,
							error: contextError ?? void 0,
							required: true,
							get value() {
								return contextText;
							},
							set value($$value) {
								contextText = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> <div class="meta-grid svelte-dg4797">`);
						Select($$renderer, {
							label: "Type",
							options: TYPE_OPTIONS,
							get value() {
								return patternType;
							},
							set value($$value) {
								patternType = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						Select($$renderer, {
							label: "Impact",
							options: IMPACT_OPTIONS,
							get value() {
								return impact;
							},
							set value($$value) {
								impact = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----></div> `);
						if (formError) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<p class="form-error svelte-dg4797" role="alert" aria-live="polite">${escape_html(formError)}</p>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--></form>`);
					},
					$$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/memory/PromotionCountdown.svelte
function PromotionCountdown($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link PromotionCountdown}.
		*/
		/** Remaining days until eligibility (0 = now). */
		let { daysUntil } = $$props;
		const tone = derived(() => {
			if (daysUntil < .1) return "success";
			if (daysUntil < 1) return "info";
			return "neutral";
		});
		const label = derived(() => {
			if (daysUntil < .1) return "ready now";
			if (daysUntil < 1) return `${Math.round(daysUntil * 24)}h`;
			return `${daysUntil.toFixed(1)}d`;
		});
		Badge($$renderer, {
			tone: tone(),
			size: "sm",
			pill: true,
			children: ($$renderer) => {
				$$renderer.push(`<!---->${escape_html(label())}`);
			}});
	});
}
//#endregion
//#region src/lib/components/memory/QualityBar.svelte
function QualityBar($$renderer, $$props) {
	/**
	* Props for {@link QualityBar}.
	*/
	/** Quality score in [0..1]. `null` → placeholder. */
	/** When true, render the numeric label next to the bar. Defaults to `true`. */
	/** Width of the bar in px. Defaults to 80. */
	let { score, showLabel = true, width = 80 } = $$props;
	const resolved = derived(() => typeof score === "number" && Number.isFinite(score) ? score : null);
	const pct = derived(() => resolved() === null ? 0 : Math.round(Math.max(0, Math.min(1, resolved())) * 100));
	/** Semantic bucket — drives the token-driven colour. */
	const tone = derived(() => {
		if (resolved() === null) return "unknown";
		if (resolved() >= .7) return "high";
		if (resolved() >= .4) return "mid";
		return "low";
	});
	const labelText = derived(() => resolved() === null ? "—" : resolved().toFixed(2));
	$$renderer.push(`<span class="q-bar svelte-7jfl6u"${attr_style(`--q-width:${stringify(width)}px`)} role="img"${attr("aria-label", `Quality ${labelText()}`)}><span class="track svelte-7jfl6u"><span${attr_class(`fill t-${stringify(tone())}`, "svelte-7jfl6u")}${attr_style(`width:${stringify(pct())}%`)}></span></span> `);
	if (showLabel) {
		$$renderer.push("<!--[0-->");
		$$renderer.push(`<span${attr_class(`label t-${stringify(tone())}`, "svelte-7jfl6u")}>${escape_html(labelText())}</span>`);
	} else $$renderer.push("<!--[-1-->");
	$$renderer.push(`<!--]--></span>`);
}
//#endregion
//#region src/lib/components/memory/SortControl.svelte
function SortControl($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props for {@link SortControl}.
		*/
		/** Current sort key. */
		/** Emits the selected key. */
		/** When false, hide the citation option (e.g. decisions page has no citation_count). */
		let { value, onChange, allowCitation = true } = $$props;
		const options = derived(() => [
			{
				value: "created_desc",
				label: "Newest first"
			},
			{
				value: "quality_desc",
				label: "Quality · high to low"
			},
			...allowCitation ? [{
				value: "citation_desc",
				label: "Citations · most first"
			}] : []
		]);
		function handle(e) {
			const el = e.target;
			onChange(el.value);
		}
		$$renderer.push(`<div class="sort-ctrl svelte-1ta5t9b"><span class="sort-label svelte-1ta5t9b">Sort</span> `);
		Select($$renderer, {
			value,
			options: options(),
			onchange: handle
		});
		$$renderer.push(`<!----></div>`);
	});
}
//#endregion
//#region src/lib/components/memory/TierBadge.svelte
function TierBadge($$renderer, $$props) {
	/**
	* Props for {@link TierBadge}.
	*/
	/** Memory tier — null / unknown / custom renders neutral. */
	/** Size. Defaults to `sm` for dense list rows. */
	let { tier, size = "sm" } = $$props;
	const tone = derived(() => {
		if (tier === "long") return "success";
		if (tier === "medium") return "info";
		if (tier === "short") return "neutral";
		return "neutral";
	});
	const label = derived(() => tier ?? "unknown");
	Badge($$renderer, {
		tone: tone(),
		size,
		pill: true,
		children: ($$renderer) => {
			$$renderer.push(`<!---->${escape_html(label())}`);
		}});
}
//#endregion
//#region src/lib/components/memory/VerifyQueuePanel.svelte
function VerifyQueuePanel($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Pending-verify entry shape — mirrors contracts.MemoryPendingEntry. */
		/** Response shape for GET /api/memory/pending-verify. */
		/**
		* Props for {@link VerifyQueuePanel}.
		*/
		/** Minimum citations threshold; passed through. Defaults to 5. */
		/** Max items shown. Defaults to 10. */
		let { minCitations = 5, limit = 10 } = $$props;
		{
			function header($$renderer) {
				$$renderer.push(`<div class="panel-head svelte-17fm0cm"><h3 class="panel-title svelte-17fm0cm">Verify queue</h3> <span class="panel-sub svelte-17fm0cm">Unverified but frequently cited — promote to ground truth</span></div>`);
			}
			Card($$renderer, {
				header,
				children: ($$renderer) => {
					{
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<div class="state svelte-17fm0cm">`);
						Spinner($$renderer, { size: "md" });
						$$renderer.push(`<!----> <span>Loading verify queue…</span></div>`);
					}
					$$renderer.push(`<!--]-->`);
				}});
		}
	});
}

export { ConfidenceBadge as C, DecisionModal as D, FilterBar as F, LearningModal as L, ObserveModal as O, Pagination as P, QualityBar as Q, SortControl as S, TierBadge as T, VerifyQueuePanel as V, PromotionCountdown as a, PatternModal as b };
//# sourceMappingURL=memory2-Cgc_4D5q.js.map
