import { useStudio as e } from "../../../providers/StudioProvider.js";
import { useCreateWorkflow as t } from "../../../hooks/useWorkflows.js";
import { Button as n } from "../../../components/ui/button.js";
import r from "../../../components/feedback/ErrorSnackbar.js";
import i from "../../../components/dynamic-form/Form.js";
import { useRunWorkflow as a } from "../../../hooks/useProcessor.js";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import { Loader2 as c, Play as l } from "lucide-react";
import { useForm as u } from "react-hook-form";
//#region src/features/workspaces/components/WorkspaceHomePage.tsx
var d = ({ workspace: d, action: f }) => {
	let { router: p } = e(), m = t(), h = a(), g = f.options ?? {}, _ = g.workflow, v = g.title, y = g.subtitle, b = g.schema, x = g.workflowUi, S = u({
		defaultValues: {},
		mode: "onChange"
	}), C = m.isPending || h.isPending, w = !!b, T = (e) => {
		m.mutate({ workflowCreateDto: {
			alias: _,
			title: null,
			workspaceId: d.id,
			transition: null,
			args: w ? e : void 0
		} }, { onSuccess: (e) => {
			h.mutate({
				workflowId: e.id,
				runWorkflowPayloadDto: {},
				force: !0
			}, { onSuccess: () => {
				p.navigateToWorkflow(e.id);
			} });
		} });
	};
	return /* @__PURE__ */ s("div", {
		className: "mx-auto flex min-h-[60vh] max-w-2xl flex-col items-center justify-center",
		children: [
			/* @__PURE__ */ o(r, { error: m.error }),
			/* @__PURE__ */ o(r, { error: h.error }),
			v && /* @__PURE__ */ o("h2", {
				className: "mb-2 text-center text-3xl font-bold tracking-tight",
				children: v
			}),
			y && /* @__PURE__ */ o("p", {
				className: "text-muted-foreground mb-8 text-center text-sm",
				children: y
			}),
			w ? /* @__PURE__ */ o("div", {
				className: "mb-6 w-full",
				children: /* @__PURE__ */ o(i, {
					form: S,
					schema: b,
					ui: x,
					disabled: !1,
					viewOnly: !1
				})
			}) : null,
			/* @__PURE__ */ o("div", {
				className: "flex w-full justify-end",
				children: /* @__PURE__ */ s(n, {
					variant: "default",
					disabled: C,
					onClick: () => {
						S.handleSubmit(T)();
					},
					size: "lg",
					className: "font-medium",
					children: [C ? /* @__PURE__ */ o(c, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ o(l, { className: "mr-2 h-4 w-4" }), "Run"]
				})
			})
		]
	});
};
//#endregion
export { d as default };
