import { useStudio } from "../providers/StudioProvider.js";
import { useWorkspace } from "../hooks/useWorkspaces.js";
import { useFetchWorkflowsByPipeline } from "../hooks/useWorkflows.js";
import MainLayout_default from "../components/layout/MainLayout.js";
import ErrorSnackbar_default from "../components/snackbars/ErrorSnackbar.js";
import { usePipeline, usePipelineConfig } from "../hooks/usePipelines.js";
import { ReactFlowProvider } from "../node_modules/@xyflow/react/dist/esm/index.js";
import { requireParam } from "../lib/requireParam.js";
import PipelineDebugHeader_default from "../features/debug/components/PipelineDebugHeader.js";
import PipelineFlowViewer_default from "../features/debug/components/PipelineFlowViewer.js";
import { c } from "react/compiler-runtime";
import React, { useMemo } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { useParams } from "react-router-dom";
import { Bug, Home, Loader2 } from "lucide-react";
var PipelineDebugPage_default = () => {
	let v = c(54), { router: y } = useStudio(), b = useParams(), x;
	v[0] === b ? x = v[1] : (x = requireParam(b, "pipelineId"), v[0] = b, v[1] = x);
	let S = x, C = usePipeline(S), w = C.data?.workspaceId, T = useWorkspace(w), E = useFetchWorkflowsByPipeline(S), D;
	v[2] === E.data ? D = v[3] : (D = E.data ?? [], v[2] = E.data, v[3] = D);
	let O = D, k = T.data?.blockName, A = C.data?.blockName, j = usePipelineConfig(k, A), M;
	v[4] === y ? M = v[5] : (M = y.getDashboard(), v[4] = y, v[5] = M);
	let N;
	v[6] === Symbol.for("react.memo_cache_sentinel") ? (N = /* @__PURE__ */ jsx(Home, { className: "h-4 w-4" }), v[6] = N) : N = v[6];
	let P;
	v[7] === M ? P = v[8] : (P = {
		label: "Dashboard",
		href: M,
		icon: N
	}, v[7] = M, v[8] = P);
	let F;
	v[9] === y ? F = v[10] : (F = y.getWorkspaces(), v[9] = y, v[10] = F);
	let I;
	v[11] === F ? I = v[12] : (I = {
		label: "Workspaces",
		href: F
	}, v[11] = F, v[12] = I);
	let L = T.data?.title ?? "...", R;
	v[13] !== y || v[14] !== w ? (R = w ? y.getWorkspace(w) : void 0, v[13] = y, v[14] = w, v[15] = R) : R = v[15];
	let z;
	v[16] !== L || v[17] !== R ? (z = {
		label: L,
		href: R
	}, v[16] = L, v[17] = R, v[18] = z) : z = v[18];
	let B = `Run #${C.data?.run ?? "..."}`, V;
	v[19] !== S || v[20] !== y ? (V = y.getPipeline(S), v[19] = S, v[20] = y, v[21] = V) : V = v[21];
	let H;
	v[22] !== B || v[23] !== V ? (H = {
		label: B,
		href: V
	}, v[22] = B, v[23] = V, v[24] = H) : H = v[24];
	let U;
	v[25] === Symbol.for("react.memo_cache_sentinel") ? (U = {
		label: "Debug Flow",
		icon: /* @__PURE__ */ jsx(Bug, { className: "h-4 w-4" })
	}, v[25] = U) : U = v[25];
	let W;
	v[26] !== H || v[27] !== P || v[28] !== I || v[29] !== z ? (W = [
		P,
		I,
		z,
		H,
		U
	], v[26] = H, v[27] = P, v[28] = I, v[29] = z, v[30] = W) : W = v[30];
	let G = W;
	if (C.isLoading || E.isLoading || T.isLoading) {
		let t;
		v[31] === Symbol.for("react.memo_cache_sentinel") ? (t = /* @__PURE__ */ jsx("div", {
			className: "flex h-[calc(100vh-8rem)] items-center justify-center",
			children: /* @__PURE__ */ jsx(Loader2, { className: "text-muted-foreground h-8 w-8 animate-spin" })
		}), v[31] = t) : t = v[31];
		let _;
		return v[32] === G ? _ = v[33] : (_ = /* @__PURE__ */ jsx(MainLayout_default, {
			breadcrumbsData: G,
			children: t
		}), v[32] = G, v[33] = _), _;
	}
	let K;
	v[34] === C.error ? K = v[35] : (K = /* @__PURE__ */ jsx(ErrorSnackbar_default, { error: C.error }), v[34] = C.error, v[35] = K);
	let q = C.data?.title ?? C.data?.blockName ?? "Pipeline", J = C.data?.run, Y;
	v[36] !== S || v[37] !== y ? (Y = () => void y.navigateToPipeline(S), v[36] = S, v[37] = y, v[38] = Y) : Y = v[38];
	let X;
	v[39] !== q || v[40] !== J || v[41] !== Y ? (X = /* @__PURE__ */ jsx(PipelineDebugHeader_default, {
		title: q,
		runNumber: J,
		onBack: Y
	}), v[39] = q, v[40] = J, v[41] = Y, v[42] = X) : X = v[42];
	let Z;
	v[43] !== j || v[44] !== S || v[45] !== O ? (Z = /* @__PURE__ */ jsx("div", {
		className: "bg-card border-border flex-1 overflow-hidden rounded-2xl border shadow-sm",
		children: O.length > 0 ? /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(PipelineFlowViewer_default, {
			pipelineId: S,
			workflows: O,
			pipelineConfig: j.data
		}) }) : /* @__PURE__ */ jsx("div", {
			className: "text-muted-foreground flex h-full items-center justify-center",
			children: /* @__PURE__ */ jsx("p", {
				className: "font-medium",
				children: "No workflows found for this pipeline"
			})
		})
	}), v[43] = j, v[44] = S, v[45] = O, v[46] = Z) : Z = v[46];
	let Q;
	v[47] !== X || v[48] !== Z ? (Q = /* @__PURE__ */ jsxs("div", {
		className: "flex h-[calc(100vh-8rem)] flex-col gap-6",
		children: [X, Z]
	}), v[47] = X, v[48] = Z, v[49] = Q) : Q = v[49];
	let $;
	return v[50] !== G || v[51] !== K || v[52] !== Q ? ($ = /* @__PURE__ */ jsxs(MainLayout_default, {
		breadcrumbsData: G,
		children: [K, Q]
	}), v[50] = G, v[51] = K, v[52] = Q, v[53] = $) : $ = v[53], $;
};
export { PipelineDebugPage_default as default };
