import { Z as onDestroy, _ as derived, $ as store_get, a0 as attr_style, a1 as attr, a2 as attr_class, a3 as escape_html, a4 as ensure_array_like, a5 as spread_props, a6 as sanitize_props, a7 as slot, Y as writable, a8 as unsubscribe_stores } from './internal-B3VUlLoc.js';
import { r as resolve } from './client-CHafgYl_.js';
import { p as page } from './state-DzwmDIZC.js';
import { H as Header, P as ProjectBar, d as desktopLeftOpen, a as desktopPaneSelections, b as desktopRightOpen, I as Icon, c as activeProjectId, e as desktopPaneWidths, i as isDesktopViewport, f as disconnect } from './Header-DF-atx4l.js';
import { p as pwaState } from './pwa-CJLBSCpd.js';
import { T as Terminal, C as ChatPanel } from './ChatPanel-ndj_srn8.js';
import { F as FilesPanel } from './FilesPanel-CBLJwWpj.js';
import { S as SourcePanel } from './SourcePanel-FU3TiMKP.js';
import { T as TerminalPanel, t as terminals } from './TerminalPanel-B_T52Ad_.js';
import '@sveltejs/kit/internal';
import '@sveltejs/kit/internal/server';
import './formatting-Cq2KfAoL.js';
import './extensions-Crd97FJ_.js';
import './WorkspaceEmptyState-CpWtvgum.js';

var keyboardInset = writable(0);
//#endregion
//#region ../../node_modules/.pnpm/lucide-svelte@1.0.1_svelte@5.55.5/node_modules/lucide-svelte/dist/icons/files.svelte
function Files($$renderer, $$props) {
	Icon($$renderer, spread_props([
		{ name: "files" },
		sanitize_props($$props),
		{
			/**
			* @component @name Files
			* @description Lucide SVG icon component, renders SVG Element with children.
			*
			* @preview ![img](data:image/svg+xml;base64,PHN2ZyAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogIHdpZHRoPSIyNCIKICBoZWlnaHQ9IjI0IgogIHZpZXdCb3g9IjAgMCAyNCAyNCIKICBmaWxsPSJub25lIgogIHN0cm9rZT0iIzAwMCIgc3R5bGU9ImJhY2tncm91bmQtY29sb3I6ICNmZmY7IGJvcmRlci1yYWRpdXM6IDJweCIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNMTUgMmgtNGEyIDIgMCAwIDAtMiAydjExYTIgMiAwIDAgMCAyIDJoOGEyIDIgMCAwIDAgMi0yVjgiIC8+CiAgPHBhdGggZD0iTTE2LjcwNiAyLjcwNkEyLjQgMi40IDAgMCAwIDE1IDJ2NWExIDEgMCAwIDAgMSAxaDVhMi40IDIuNCAwIDAgMC0uNzA2LTEuNzA2eiIgLz4KICA8cGF0aCBkPSJNNSA3YTIgMiAwIDAgMC0yIDJ2MTFhMiAyIDAgMCAwIDIgMmg4YTIgMiAwIDAgMCAxLjczMi0xIiAvPgo8L3N2Zz4K) - https://lucide.dev/icons/files
			* @see https://lucide.dev/guide/packages/lucide-svelte - Documentation
			*
			* @param {Object} props - Lucide icons props and any valid SVG attribute
			* @returns {FunctionalComponent} Svelte component
			*
			*/
			iconNode: [
				["path", { "d": "M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8" }],
				["path", { "d": "M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z" }],
				["path", { "d": "M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1" }]
			],
			children: ($$renderer) => {
				$$renderer.push(`<!--[-->`);
				slot($$renderer, $$props, "default", {});
				$$renderer.push(`<!--]-->`);
			},
			$$slots: { default: true }
		}
	]));
}
//#endregion
//#region ../../node_modules/.pnpm/lucide-svelte@1.0.1_svelte@5.55.5/node_modules/lucide-svelte/dist/icons/git-branch.svelte
function Git_branch($$renderer, $$props) {
	Icon($$renderer, spread_props([
		{ name: "git-branch" },
		sanitize_props($$props),
		{
			/**
			* @component @name GitBranch
			* @description Lucide SVG icon component, renders SVG Element with children.
			*
			* @preview ![img](data:image/svg+xml;base64,PHN2ZyAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogIHdpZHRoPSIyNCIKICBoZWlnaHQ9IjI0IgogIHZpZXdCb3g9IjAgMCAyNCAyNCIKICBmaWxsPSJub25lIgogIHN0cm9rZT0iIzAwMCIgc3R5bGU9ImJhY2tncm91bmQtY29sb3I6ICNmZmY7IGJvcmRlci1yYWRpdXM6IDJweCIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNMTUgNmE5IDkgMCAwIDAtOSA5VjMiIC8+CiAgPGNpcmNsZSBjeD0iMTgiIGN5PSI2IiByPSIzIiAvPgogIDxjaXJjbGUgY3g9IjYiIGN5PSIxOCIgcj0iMyIgLz4KPC9zdmc+Cg==) - https://lucide.dev/icons/git-branch
			* @see https://lucide.dev/guide/packages/lucide-svelte - Documentation
			*
			* @param {Object} props - Lucide icons props and any valid SVG attribute
			* @returns {FunctionalComponent} Svelte component
			*
			*/
			iconNode: [
				["path", { "d": "M15 6a9 9 0 0 0-9 9V3" }],
				["circle", {
					"cx": "18",
					"cy": "6",
					"r": "3"
				}],
				["circle", {
					"cx": "6",
					"cy": "18",
					"r": "3"
				}]
			],
			children: ($$renderer) => {
				$$renderer.push(`<!--[-->`);
				slot($$renderer, $$props, "default", {});
				$$renderer.push(`<!--]-->`);
			},
			$$slots: { default: true }
		}
	]));
}
//#endregion
//#region ../../node_modules/.pnpm/lucide-svelte@1.0.1_svelte@5.55.5/node_modules/lucide-svelte/dist/icons/messages-square.svelte
function Messages_square($$renderer, $$props) {
	Icon($$renderer, spread_props([
		{ name: "messages-square" },
		sanitize_props($$props),
		{
			/**
			* @component @name MessagesSquare
			* @description Lucide SVG icon component, renders SVG Element with children.
			*
			* @preview ![img](data:image/svg+xml;base64,PHN2ZyAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogIHdpZHRoPSIyNCIKICBoZWlnaHQ9IjI0IgogIHZpZXdCb3g9IjAgMCAyNCAyNCIKICBmaWxsPSJub25lIgogIHN0cm9rZT0iIzAwMCIgc3R5bGU9ImJhY2tncm91bmQtY29sb3I6ICNmZmY7IGJvcmRlci1yYWRpdXM6IDJweCIKICBzdHJva2Utd2lkdGg9IjIiCiAgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIgogIHN0cm9rZS1saW5lam9pbj0icm91bmQiCj4KICA8cGF0aCBkPSJNMTYgMTBhMiAyIDAgMCAxLTIgMkg2LjgyOGEyIDIgMCAwIDAtMS40MTQuNTg2bC0yLjIwMiAyLjIwMkEuNzEuNzEgMCAwIDEgMiAxNC4yODZWNGEyIDIgMCAwIDEgMi0yaDEwYTIgMiAwIDAgMSAyIDJ6IiAvPgogIDxwYXRoIGQ9Ik0yMCA5YTIgMiAwIDAgMSAyIDJ2MTAuMjg2YS43MS43MSAwIDAgMS0xLjIxMi41MDJsLTIuMjAyLTIuMjAyQTIgMiAwIDAgMCAxNy4xNzIgMTlIMTBhMiAyIDAgMCAxLTItMnYtMSIgLz4KPC9zdmc+Cg==) - https://lucide.dev/icons/messages-square
			* @see https://lucide.dev/guide/packages/lucide-svelte - Documentation
			*
			* @param {Object} props - Lucide icons props and any valid SVG attribute
			* @returns {FunctionalComponent} Svelte component
			*
			*/
			iconNode: [["path", { "d": "M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z" }], ["path", { "d": "M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1" }]],
			children: ($$renderer) => {
				$$renderer.push(`<!--[-->`);
				slot($$renderer, $$props, "default", {});
				$$renderer.push(`<!--]-->`);
			},
			$$slots: { default: true }
		}
	]));
}
//#endregion
//#region src/lib/components/layout/DesktopWorkbench.svelte
function DesktopWorkbench($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		var $$store_subs;
		const PANEL_TABS = [
			{
				value: "chat",
				label: "Chat",
				icon: Messages_square
			},
			{
				value: "terminal",
				label: "Terminal",
				icon: Terminal
			},
			{
				value: "source",
				label: "Source",
				icon: Git_branch
			},
			{
				value: "files",
				label: "Files",
				icon: Files
			}
		];
		let widths = derived(() => store_get($$store_subs ??= {}, "$desktopPaneWidths", desktopPaneWidths));
		let leftOpen = derived(() => store_get($$store_subs ??= {}, "$desktopLeftOpen", desktopLeftOpen));
		let rightOpen = derived(() => store_get($$store_subs ??= {}, "$desktopRightOpen", desktopRightOpen));
		let selections = derived(() => store_get($$store_subs ??= {}, "$desktopPaneSelections", desktopPaneSelections));
		let gridStyle = derived(() => gridTemplate(widths(), leftOpen(), rightOpen()));
		let activeChatSessionId = derived(() => page.params.id ?? null);
		function gridTemplate(current, showLeft, showRight) {
			const vars = `--left-width:${current[0]}%;--right-width:${current[2]}%;`;
			if (showLeft && showRight) return `${vars}grid-template-columns:${current[0]}% ${current[1]}% ${current[2]}%`;
			if (showLeft) return `${vars}grid-template-columns:${current[0]}% ${100 - current[0]}%`;
			if (showRight) return `${vars}grid-template-columns:${100 - current[2]}% ${current[2]}%`;
			return `${vars}grid-template-columns:100%`;
		}
		function PaneChrome($$renderer, pane, selected) {
			$$renderer.push(`<div class="pane-toolbar svelte-htzcc6" role="tablist"${attr("aria-label", `${pane} pane`)}><!--[-->`);
			const each_array = ensure_array_like(PANEL_TABS);
			for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
				let tab = each_array[$$index];
				$$renderer.push(`<button type="button" role="tab"${attr_class("pane-tab svelte-htzcc6", void 0, { "active": selected === tab.value })}${attr("aria-selected", selected === tab.value)}${attr("title", tab.label)}>`);
				if (tab.icon) {
					$$renderer.push("<!--[-->");
					tab.icon($$renderer, { size: 16 });
					$$renderer.push("<!--]-->");
				} else {
					$$renderer.push("<!--[!-->");
					$$renderer.push("<!--]-->");
				}
				$$renderer.push(`</button>`);
			}
			$$renderer.push(`<!--]--></div> <div class="panel-host svelte-htzcc6">`);
			if (selected === "chat") {
				$$renderer.push("<!--[0-->");
				ChatPanel($$renderer, { sessionId: activeChatSessionId() });
			} else if (selected === "terminal") {
				$$renderer.push("<!--[1-->");
				TerminalPanel($$renderer);
			} else if (selected === "source") {
				$$renderer.push("<!--[2-->");
				SourcePanel($$renderer);
			} else {
				$$renderer.push("<!--[-1-->");
				FilesPanel($$renderer);
			}
			$$renderer.push(`<!--]--></div>`);
		}
		$$renderer.push(`<div class="workbench svelte-htzcc6"${attr_style(gridStyle())} role="application">`);
		if (leftOpen()) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<aside class="pane sidebar left svelte-htzcc6">`);
			PaneChrome($$renderer, "left", selections().left);
			$$renderer.push(`<!----></aside> <button type="button" class="resize-handle resize-left svelte-htzcc6" aria-label="Resize left sidebar"></button>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> <main class="pane center svelte-htzcc6">`);
		PaneChrome($$renderer, "center", selections().center);
		$$renderer.push(`<!----></main> `);
		if (rightOpen()) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<button type="button" class="resize-handle resize-right svelte-htzcc6" aria-label="Resize right sidebar"></button> <aside class="pane sidebar right svelte-htzcc6">`);
			PaneChrome($$renderer, "right", selections().right);
			$$renderer.push(`<!----></aside>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></div>`);
		if ($$store_subs) unsubscribe_stores($$store_subs);
	});
}
//#endregion
//#region src/lib/components/layout/MobileNav.svelte
function MobileNav($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		var $$store_subs;
		let currentPath = derived(() => page.url.pathname);
		let projectTerminalCount = derived(() => store_get($$store_subs ??= {}, "$terminals", terminals).filter((terminal) => terminal.projectId === store_get($$store_subs ??= {}, "$activeProjectId", activeProjectId) && terminal.alive).length);
		function isActive(path) {
			if (path === "/chat") return currentPath() === "/chat" || currentPath().startsWith("/chat/");
			return currentPath() === path;
		}
		$$renderer.push(`<div class="bottom-shell svelte-15ams6y">`);
		ProjectBar($$renderer, {});
		$$renderer.push(`<!----> <nav class="bottom-nav svelte-15ams6y" aria-label="Bottom tabs"><a${attr("href", resolve("/chat"))}${attr_class("svelte-15ams6y", void 0, { "active": isActive("/chat") })}>`);
		Messages_square($$renderer, {
			class: "nav-icon",
			"aria-hidden": "true"
		});
		$$renderer.push(`<!----> <span>Chat</span></a> <a${attr("href", resolve("/terminal"))}${attr_class("svelte-15ams6y", void 0, { "active": isActive("/terminal") })}>`);
		Terminal($$renderer, {
			class: "nav-icon",
			"aria-hidden": "true"
		});
		$$renderer.push(`<!----> <span>Terminal ${escape_html(projectTerminalCount())}</span></a> <a${attr("href", resolve("/source"))}${attr_class("svelte-15ams6y", void 0, { "active": isActive("/source") })}>`);
		Git_branch($$renderer, {
			class: "nav-icon",
			"aria-hidden": "true"
		});
		$$renderer.push(`<!----> <span>Source</span></a> <a${attr("href", resolve("/files"))}${attr_class("svelte-15ams6y", void 0, { "active": isActive("/files") })}>`);
		Files($$renderer, {
			class: "nav-icon",
			"aria-hidden": "true"
		});
		$$renderer.push(`<!----> <span>Files</span></a></nav></div>`);
		if ($$store_subs) unsubscribe_stores($$store_subs);
	});
}
//#endregion
//#region src/lib/components/layout/PwaPrompt.svelte
function PwaPrompt($$renderer) {
	var $$store_subs;
	let state = derived(() => store_get($$store_subs ??= {}, "$pwaState", pwaState));
	let showUpdate = derived(() => state().updateAvailable && !state().updateDismissed);
	let showOffline = derived(() => state().offlineReady && !state().offlineReadyDismissed && !showUpdate());
	if (showUpdate() || showOffline()) {
		$$renderer.push("<!--[0-->");
		$$renderer.push(`<div class="pwa-prompt svelte-9qvo1t" role="status" aria-live="polite"><div class="copy svelte-9qvo1t"><strong class="svelte-9qvo1t">${escape_html(showUpdate() ? "Update available" : "App shell ready")}</strong> <span class="svelte-9qvo1t">${escape_html(showUpdate() ? "Reload when ready to use the newest version." : "fatmux can now launch as an installed app.")}</span></div> <div class="actions svelte-9qvo1t">`);
		if (showUpdate()) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<button type="button" class="primary svelte-9qvo1t"${attr("disabled", state().updating, true)}>${escape_html(state().updating ? "Updating..." : "Update")}</button> <button type="button" class="svelte-9qvo1t">Dismiss</button>`);
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<button type="button" class="svelte-9qvo1t">OK</button>`);
		}
		$$renderer.push(`<!--]--></div></div>`);
	} else $$renderer.push("<!--[-1-->");
	$$renderer.push(`<!--]-->`);
	if ($$store_subs) unsubscribe_stores($$store_subs);
}
//#endregion
//#region src/routes/+layout.svelte
function _layout($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		var $$store_subs;
		let { children } = $$props;
		let onTerminal = derived(() => page.url.pathname.startsWith("/terminal"));
		let fullPageRoute = derived(() => page.url.pathname === "/settings");
		let kbOpen = derived(() => store_get($$store_subs ??= {}, "$keyboardInset", keyboardInset) > 80);
		let desktopViewport = derived(() => store_get($$store_subs ??= {}, "$isDesktopViewport", isDesktopViewport));
		let hideMobileNav = derived(() => fullPageRoute() || onTerminal() && kbOpen());
		onDestroy(() => {
			disconnect();
		});
		$$renderer.push(`<div class="app-shell svelte-12qhfyh">`);
		if (desktopViewport()) {
			$$renderer.push("<!--[0-->");
			if (fullPageRoute()) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<div class="app-content app-content--full-page svelte-12qhfyh">`);
				children($$renderer);
				$$renderer.push(`<!----></div>`);
			} else {
				$$renderer.push("<!--[-1-->");
				Header($$renderer, {});
				$$renderer.push(`<!----> `);
				DesktopWorkbench($$renderer);
				$$renderer.push(`<!---->`);
			}
			$$renderer.push(`<!--]-->`);
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<div class="app-content svelte-12qhfyh">`);
			children($$renderer);
			$$renderer.push(`<!----></div> `);
			if (!hideMobileNav()) {
				$$renderer.push("<!--[0-->");
				MobileNav($$renderer);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]-->`);
		}
		$$renderer.push(`<!--]--></div> `);
		PwaPrompt($$renderer);
		$$renderer.push(`<!---->`);
		if ($$store_subs) unsubscribe_stores($$store_subs);
	});
}

export { _layout as default };
//# sourceMappingURL=_layout.svelte-DBGvH04P.js.map
