import { useWorkspace } from "../../hooks/useWorkspaces.js";
import { SidebarInsetDiv, SidebarProvider, SidebarTrigger } from "../../components/ui/sidebar.js";
import { FileContentViewer } from "../code-explorer/components/FileContentViewer.js";
import { CodeExplorerProvider, useCodeExplorerContext } from "../code-explorer/providers/CodeExplorerProvider.js";
import { FileTabsBar } from "../code-explorer/components/FileTabsBar.js";
import { useNamespaceTree } from "../../hooks/useNamespaceTree.js";
import { WorkbenchContextProvider } from "./providers/WorkbenchContextProvider.js";
import WorkflowList_default from "./WorkflowList.js";
import { ScrollProvider } from "./providers/ScrollProvider.js";
import WorkbenchSidebar_default from "./components/WorkbenchSidebar.js";
import { c } from "react/compiler-runtime";
import { useCallback, useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
function WorkbenchContent(e) {
	let a = c(11), { pipeline: o } = e, { openFiles: s, selectedFile: u, fileContent: p, workflowConfig: m, isContentLoading: _ } = useCodeExplorerContext(), v;
	a[0] === o ? v = a[1] : (v = /* @__PURE__ */ jsx("div", {
		className: "flex-1 overflow-hidden",
		children: /* @__PURE__ */ jsx(ScrollProvider, { children: /* @__PURE__ */ jsx("div", {
			className: "flex h-full flex-col",
			children: /* @__PURE__ */ jsx("div", {
				className: "flex-1 overflow-hidden",
				children: /* @__PURE__ */ jsx(WorkflowList_default, { pipeline: o })
			})
		}) })
	}), a[0] = o, a[1] = v);
	let y;
	a[2] !== p || a[3] !== _ || a[4] !== s.length || a[5] !== u || a[6] !== m ? (y = s.length > 0 && /* @__PURE__ */ jsxs("div", {
		className: "w-full md:w-1/2 shrink-0 overflow-hidden flex flex-col",
		children: [/* @__PURE__ */ jsx(FileTabsBar, {}), /* @__PURE__ */ jsx("div", {
			className: "flex-1 overflow-hidden",
			children: /* @__PURE__ */ jsx(FileContentViewer, {
				selectedFile: u,
				content: p,
				workflowConfig: m,
				isLoading: _,
				className: "h-full"
			})
		})]
	}), a[2] = p, a[3] = _, a[4] = s.length, a[5] = u, a[6] = m, a[7] = y) : y = a[7];
	let b;
	return a[8] !== v || a[9] !== y ? (b = /* @__PURE__ */ jsx("div", {
		className: "flex h-full flex-col",
		children: /* @__PURE__ */ jsxs("div", {
			className: "flex flex-1 gap-4 overflow-hidden md:flex-row flex-col",
			children: [v, y]
		})
	}), a[8] = v, a[9] = y, a[10] = b) : b = a[10], b;
}
function Workbench(l) {
	let d = c(23), { pipeline: f } = l, h = useNamespaceTree(f?.id), g = f?.workspaceId, v = useWorkspace(g), y;
	d[0] === Symbol.for("react.memo_cache_sentinel") ? (y = { activeSectionId: null }, d[0] = y) : y = d[0];
	let [x, S] = useState(y), C;
	d[1] === Symbol.for("react.memo_cache_sentinel") ? (C = (e) => {
		S({ activeSectionId: e });
	}, d[1] = C) : C = d[1];
	let w = C, T;
	d[2] === x ? T = d[3] : (T = {
		state: x,
		setActiveSectionId: w
	}, d[2] = x, d[3] = T);
	let E = T, D = v.data?.features?.fileExplorer?.enabled ?? !1, O = f?.id, k;
	d[4] === Symbol.for("react.memo_cache_sentinel") ? (k = /* @__PURE__ */ jsx(SidebarTrigger, { className: "fixed top-0 right-0 z-40 flex h-8 w-8 items-center justify-center p-8 hover:cursor-pointer md:hidden" }), d[4] = k) : k = d[4];
	let A;
	d[5] === f ? A = d[6] : (A = /* @__PURE__ */ jsx(SidebarInsetDiv, { children: /* @__PURE__ */ jsx("div", {
		className: "flex-1",
		children: /* @__PURE__ */ jsx(WorkbenchContent, { pipeline: f })
	}) }), d[5] = f, d[6] = A);
	let j;
	d[7] === v.data ? j = d[8] : (j = v.data ? {
		volumes: v.data.volumes,
		features: v.data.features
	} : void 0, d[7] = v.data, d[8] = j);
	let M;
	d[9] !== h || d[10] !== f || d[11] !== j ? (M = /* @__PURE__ */ jsx(WorkbenchSidebar_default, {
		namespaceTree: h,
		pipeline: f,
		workspaceConfig: j
	}), d[9] = h, d[10] = f, d[11] = j, d[12] = M) : M = d[12];
	let N;
	d[13] !== A || d[14] !== M ? (N = /* @__PURE__ */ jsxs(SidebarProvider, {
		defaultOpen: !0,
		className: "workbench-sidebar min-h-0",
		children: [
			k,
			A,
			M
		]
	}), d[13] = A, d[14] = M, d[15] = N) : N = d[15];
	let P;
	d[16] !== D || d[17] !== O || d[18] !== N ? (P = /* @__PURE__ */ jsx(CodeExplorerProvider, {
		pipelineId: O,
		fileExplorerEnabled: D,
		children: N
	}), d[16] = D, d[17] = O, d[18] = N, d[19] = P) : P = d[19];
	let F;
	return d[20] !== E || d[21] !== P ? (F = /* @__PURE__ */ jsx(WorkbenchContextProvider.Provider, {
		value: E,
		children: P
	}), d[20] = E, d[21] = P, d[22] = F) : F = d[22], F;
}
export { Workbench as default };
