import { E as head, r as escape_html, p as ensure_array_like, d as attr, e as attr_class, a8 as stringify, o as derived } from './dev-B6xUe35c.js';

//#region src/routes/splash/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		const view = derived(() => {
			const m = data.migration;
			if (m.status === "error") return { kind: "migration-error" };
			if (m.status === "pending") return { kind: "migration-pending" };
			return {
				kind: "stack",
				state: data.launchStatus.local.state
			};
		});
		let phase = { name: "idle" };
		function remoteLabel(s) {
			return {
				accessible: "Connected",
				unreachable: "Unreachable",
				unauthorized: "Needs sign-in",
				unknown: "Unknown"
			}[s] ?? s;
		}
		const stackCard = derived(() => {
			switch (data.launchStatus.local.state) {
				case "not_installed": return {
					severity: "info",
					eyebrow: "Welcome",
					title: "Let’s get you set up",
					body: "OpenPalm isn’t installed yet. Run the quick setup to install your assistant, or connect to one running somewhere else."
				};
				case "setup_incomplete": return {
					severity: "warning",
					eyebrow: "Almost there",
					title: "Finish setting up",
					body: "Installation was started but never finished. Pick up where you left off to get your assistant running."
				};
				case "installed_offline": return {
					severity: "warning",
					eyebrow: "Stopped",
					title: "Your assistant is offline",
					body: "OpenPalm is installed but nothing is running right now. Open the dashboard to start it back up."
				};
				case "installed_broken": return {
					severity: "danger",
					eyebrow: "Needs attention",
					title: "Something needs a look",
					body: "Your stack is running but one or more services are unhealthy. The diagnostics will show you what went wrong."
				};
				case "running": return {
					severity: "success",
					eyebrow: "Ready",
					title: "You’re all set",
					body: "Everything is healthy. Open the chat to start talking to your assistant."
				};
				default: return {
					severity: "info",
					eyebrow: "Status",
					title: "OpenPalm",
					body: ""
				};
			}
		});
		const runtime = derived(() => data.launchStatus.local.runtime);
		const remotes = derived(() => data.launchStatus.remotes);
		const accessibleRemote = derived(() => remotes().find((r) => r.state === "accessible"));
		const liveMsg = derived(() => {
			if (view().kind !== "migration-pending") return "";
			switch (phase.name) {
				case "applying": return "Updating your settings folder, please wait.";
				case "done": return "Update complete. You can continue.";
				case "error": return "The update did not complete.";
				case "lowspace": return "Low disk space detected. Confirm to proceed.";
				default: return "";
			}
		});
		head("pq79rg", $$renderer, ($$renderer) => {
			$$renderer.title(($$renderer) => {
				$$renderer.push(`<title>OpenPalm</title>`);
			});
		});
		$$renderer.push(`<div class="setup-page"><header class="wiz-topbar svelte-pq79rg"><div class="wiz-wordmark"><img src="/logo-128.png" alt=""/> <b>OpenPalm</b></div></header> <main class="splash-stage svelte-pq79rg"><p class="sr-only svelte-pq79rg" role="status" aria-live="polite">${escape_html(liveMsg())}</p> <div class="splash-panel svelte-pq79rg">`);
		if (view().kind === "migration-error") {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<p class="wiz-eyebrow svelte-pq79rg"><span class="sev-dot sev-danger svelte-pq79rg" aria-hidden="true"></span>Can’t continue</p> <h1 class="wiz-title">We couldn’t read your <span class="accent">settings</span></h1> `);
			if (data.migration.status === "error") {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<p class="wiz-lede">${escape_html(data.migration.message)}</p> <p class="splash-guidance svelte-pq79rg">${escape_html(data.migration.guidance || "If this keeps happening, check the application logs or re-run setup.")}</p>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]-->`);
		} else if (view().kind === "migration-pending") {
			$$renderer.push("<!--[1-->");
			{
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`<p class="wiz-eyebrow svelte-pq79rg"><span class="sev-dot sev-warning svelte-pq79rg" aria-hidden="true"></span>One quick step</p> <h1 class="wiz-title">A small update to your <span class="accent">settings</span></h1> <p class="wiz-lede">Before you continue, OpenPalm needs to reorganize your settings folder to match this
            version. It’s safe — a full backup is taken first and your existing files are kept.</p> `);
				if (data.migration.status === "pending" && data.migration.notes.length) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<ul class="splash-notes svelte-pq79rg"><!--[-->`);
					const each_array_1 = ensure_array_like(data.migration.notes);
					for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
						let note = each_array_1[$$index_1];
						$$renderer.push(`<li class="svelte-pq79rg">${escape_html(note)}</li>`);
					}
					$$renderer.push(`<!--]--></ul>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--> <div class="splash-actions svelte-pq79rg"><button class="btn btn-primary btn-lg svelte-pq79rg"${attr("disabled", phase.name === "applying", true)}>`);
				{
					$$renderer.push("<!--[-1-->");
					$$renderer.push(`Update now`);
				}
				$$renderer.push(`<!--]--></button></div> <p class="splash-reassure svelte-pq79rg">This usually takes a few seconds. Your settings, secrets, and saved data are copied to a
            timestamped backup folder first, so you can always restore your previous state.</p>`);
			}
			$$renderer.push(`<!--]-->`);
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<p class="wiz-eyebrow svelte-pq79rg"><span${attr_class(`sev-dot sev-${stringify(stackCard().severity)}`, "svelte-pq79rg")} aria-hidden="true"></span>${escape_html(stackCard().eyebrow)}</p> <h1 class="wiz-title">${escape_html(stackCard().title)}</h1> <p class="wiz-lede">${escape_html(stackCard().body)}</p> `);
			if (view().state === "not_installed" && runtime() && !runtime().dockerPresent) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<p class="splash-guidance svelte-pq79rg">No container runtime found. Install <a href="https://www.docker.com/products/docker-desktop/" target="_blank" rel="noreferrer">Docker</a> (or OrbStack / Podman), start it, then reload this page.</p>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> `);
			if (view().state === "installed_broken") {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<p class="splash-guidance svelte-pq79rg">Unhealthy services are listed in Diagnostics; the container logs show the underlying error.</p>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--> <div class="splash-actions svelte-pq79rg">`);
			if (view().state === "not_installed") {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<a class="btn btn-primary btn-lg svelte-pq79rg" href="/setup">Run setup</a> `);
				if (accessibleRemote()) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<a class="btn btn-outline btn-lg svelte-pq79rg" href="/chat">Use ${escape_html(accessibleRemote().name)}</a>`);
				} else {
					$$renderer.push("<!--[-1-->");
					$$renderer.push(`<button class="btn btn-ghost btn-lg svelte-pq79rg">Reload</button>`);
				}
				$$renderer.push(`<!--]-->`);
			} else if (view().state === "setup_incomplete") {
				$$renderer.push("<!--[1-->");
				$$renderer.push(`<a class="btn btn-primary btn-lg svelte-pq79rg" href="/setup">Resume setup</a>`);
			} else if (view().state === "installed_offline") {
				$$renderer.push("<!--[2-->");
				$$renderer.push(`<a class="btn btn-primary btn-lg svelte-pq79rg" href="/admin">Open dashboard</a> <button class="btn btn-outline btn-lg svelte-pq79rg">Reload</button>`);
			} else if (view().state === "installed_broken") {
				$$renderer.push("<!--[3-->");
				$$renderer.push(`<a class="btn btn-primary btn-lg svelte-pq79rg" href="/admin">Open diagnostics</a> <button class="btn btn-outline btn-lg svelte-pq79rg">Retry</button>`);
			} else if (view().state === "running") {
				$$renderer.push("<!--[4-->");
				$$renderer.push(`<a class="btn btn-primary btn-lg svelte-pq79rg" href="/chat">Open chat</a> <a class="btn btn-ghost btn-lg svelte-pq79rg" href="/admin">Admin</a>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--></div> `);
			if (remotes().length) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<ul class="splash-remotes svelte-pq79rg" aria-label="Remote connections"><!--[-->`);
				const each_array_2 = ensure_array_like(remotes());
				for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
					let remote = each_array_2[$$index_2];
					$$renderer.push(`<li class="svelte-pq79rg"><span${attr_class(`dot ${remote.state === "accessible" ? "ok" : "bad"}`, "svelte-pq79rg")} aria-hidden="true"></span> <span class="rname svelte-pq79rg">${escape_html(remote.name)}</span> <span class="rstate svelte-pq79rg">${escape_html(remoteLabel(remote.state))}</span></li>`);
				}
				$$renderer.push(`<!--]--></ul>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]-->`);
		}
		$$renderer.push(`<!--]--></div></main></div>`);
	});
}

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