import { useStudio as e } from "../providers/StudioProvider.js";
import { useWorkflow as t } from "../hooks/useWorkflows.js";
import { useWorkspace as n } from "../hooks/useWorkspaces.js";
import r from "../components/feedback/LoadingCentered.js";
import i from "../components/feedback/ErrorSnackbar.js";
import a from "../features/workbench/Workbench.js";
import "../features/workbench/index.js";
import { requireParam as o } from "../lib/requireParam.js";
import { useCallback as s, useMemo as c } from "react";
import { jsx as l, jsxs as u } from "react/jsx-runtime";
import { useParams as d } from "react-router-dom";
import { Home as f } from "lucide-react";
//#region src/pages/WorkbenchPage.tsx
function p({ previewPanelOpen: p, onPreviewPanelOpenChange: m, isDeveloperMode: h, getPreviewUrl: g, getEnvironmentPreviewUrl: _, environments: v } = {}) {
	let { router: y } = e(), b = t(o(d(), "workflowId")), x = b.data?.workspaceId, S = n(x), C = c(() => v ?? S.data?.environments, [v, S.data?.environments]), w = s((e, t) => {
		if (!e.connectionUrl) return "";
		let n = new URLSearchParams({
			url: e.connectionUrl,
			name: e.envName || e.workerId || ""
		}), r = "/embed/env/preview";
		return t ? `${r}/workflows/${t}?${n}` : `${r}?${n}`;
	}, []), T = _ ?? w, E = [
		{
			label: "Dashboard",
			href: y.getDashboard(),
			icon: /* @__PURE__ */ l(f, { className: "h-4 w-4" })
		},
		{
			label: "Workspaces",
			href: y.getWorkspaces()
		},
		{
			label: S.data?.title ?? "",
			href: x ? y.getWorkspace(x) : void 0
		},
		{ label: `Run #${b.data?.run}${b.data?.title ? ` (${b.data.title})` : ""}` }
	];
	return /* @__PURE__ */ l("div", {
		className: "flex h-svh flex-col",
		children: /* @__PURE__ */ u("div", {
			className: "flex-1 overflow-hidden",
			children: [/* @__PURE__ */ l(i, { error: b.error }), /* @__PURE__ */ l(r, {
				loading: b.isLoading,
				children: b.data ? /* @__PURE__ */ l(a, {
					workflow: b.data,
					breadcrumbData: E,
					previewPanelOpen: p,
					onPreviewPanelOpenChange: m,
					isDeveloperMode: h,
					getPreviewUrl: g,
					getEnvironmentPreviewUrl: T,
					environments: C
				}) : !b.isLoading && !b.error ? /* @__PURE__ */ l("p", {
					className: "text-muted-foreground py-8 text-center text-sm",
					children: "Workflow not found."
				}) : null
			})]
		})
	});
}
//#endregion
export { p as default };
