import { useWorkflow as e } from "../hooks/useWorkflows.js";
import t from "../components/feedback/LoadingCentered.js";
import n from "../components/feedback/ErrorSnackbar.js";
import { require_enums as r } from "../packages/contracts/dist/enums/index.js";
import i from "../features/workbench/WorkflowItem.js";
import { WorkbenchLayoutProvider as a } from "../features/workbench/providers/WorkbenchLayoutProvider.js";
import "../features/workbench/index.js";
import { requireParam as o } from "../lib/requireParam.js";
import { useEffect as s, useRef as c } from "react";
import { jsx as l, jsxs as u } from "react/jsx-runtime";
import { useParams as d } from "react-router-dom";
//#region src/pages/EmbedWorkbenchPage.tsx
var f = r(), p = "loopstack:embed:workflow-completed", m = "loopstack:embed:resize";
function h() {
	let r = o(d(), "workflowId"), h = c(null), g = e(r), _ = c(!1);
	return s(() => {
		!g.data || _.current || g.data.status === f.WorkflowState.Completed && window.parent !== window && (_.current = !0, window.parent.postMessage({
			type: p,
			workflowId: r
		}, window.location.origin));
	}, [g.data, r]), s(() => {
		if (window.parent === window || !h.current) return;
		let e = new ResizeObserver(() => {
			if (!h.current) return;
			let e = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);
			window.parent.postMessage({
				type: m,
				workflowId: r,
				height: e
			}, window.location.origin);
		});
		return e.observe(h.current), () => e.disconnect();
	}, [r]), /* @__PURE__ */ u("div", {
		ref: h,
		className: "overflow-hidden pl-3 py-4",
		children: [/* @__PURE__ */ l(n, { error: g.error }), /* @__PURE__ */ l(t, {
			loading: g.isLoading,
			children: g.data ? /* @__PURE__ */ l(a, {
				workflow: g.data,
				children: /* @__PURE__ */ l(i, {
					workflow: g.data,
					workflowId: g.data.id,
					scrollTo: () => {},
					settings: {
						enableDebugMode: !1,
						showFullMessageHistory: !1
					},
					embed: !0
				})
			}) : null
		})]
	});
}
//#endregion
export { h as default };
