import { useStudio as e } from "../../../../providers/StudioProvider.js";
import { useCreateWorkflow as t, useWorkflow as n } from "../../../../hooks/useWorkflows.js";
import { Button as r } from "../../../../components/ui/button.js";
import { AlertDialog as i, AlertDialogAction as a, AlertDialogCancel as o, AlertDialogContent as s, AlertDialogDescription as c, AlertDialogFooter as l, AlertDialogHeader as u, AlertDialogTitle as d, AlertDialogTrigger as f } from "../../../../components/ui/alert-dialog.js";
import { Tooltip as p, TooltipContent as m, TooltipTrigger as h } from "../../../../components/ui/tooltip.js";
import { useRunWorkflow as g } from "../../../../hooks/useProcessor.js";
import "react";
import { jsx as _, jsxs as v } from "react/jsx-runtime";
import { LockOpen as y, Repeat as b } from "lucide-react";
//#region src/features/workbench/components/buttons/WorkflowButtons.tsx
var x = ({ workflow: x, workflowId: S }) => {
	let { router: C } = e(), w = n(S).data, T = t(), E = g(), D = T.isPending || E.isPending;
	return w ? /* @__PURE__ */ v("div", {
		className: "flex items-center",
		onClick: (e) => e.stopPropagation(),
		children: [/* @__PURE__ */ v(i, { children: [/* @__PURE__ */ v(p, { children: [/* @__PURE__ */ _(h, {
			asChild: !0,
			children: /* @__PURE__ */ _(f, {
				asChild: !0,
				children: /* @__PURE__ */ _(r, {
					variant: "ghost",
					size: "icon",
					className: "h-7 w-7",
					disabled: D,
					children: D ? /* @__PURE__ */ _("div", { className: "h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent" }) : /* @__PURE__ */ _(b, { className: "h-3.5 w-3.5" })
				})
			})
		}), /* @__PURE__ */ _(m, { children: "Repeat" })] }), /* @__PURE__ */ v(s, { children: [/* @__PURE__ */ v(u, { children: [/* @__PURE__ */ _(d, { children: "Repeat workflow" }), /* @__PURE__ */ _(c, { children: "This will create a new run with the same arguments and redirect you to it." })] }), /* @__PURE__ */ v(l, { children: [/* @__PURE__ */ _(o, { children: "Cancel" }), /* @__PURE__ */ _(a, {
			onClick: () => {
				T.mutate({ workflowCreateDto: {
					alias: x.alias,
					title: null,
					workspaceId: x.workspaceId,
					transition: null,
					args: x.args ?? {}
				} }, { onSuccess: (e) => {
					E.mutate({
						workflowId: e.id,
						runWorkflowPayloadDto: {},
						force: !0
					}, { onSuccess: () => {
						C.navigateToWorkflow(e.id);
					} });
				} });
			},
			children: "Repeat"
		})] })] })] }), w.place === "end" && w.availableTransitions?.find((e) => e.id === "unlock") && /* @__PURE__ */ v(i, { children: [/* @__PURE__ */ v(p, { children: [/* @__PURE__ */ _(h, {
			asChild: !0,
			children: /* @__PURE__ */ _(f, {
				asChild: !0,
				children: /* @__PURE__ */ _(r, {
					variant: "ghost",
					size: "icon",
					className: "h-7 w-7",
					disabled: E.isPending,
					children: E.isPending ? /* @__PURE__ */ _("div", { className: "h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent" }) : /* @__PURE__ */ _(y, { className: "h-3.5 w-3.5" })
				})
			})
		}), /* @__PURE__ */ _(m, { children: "Unlock Step" })] }), /* @__PURE__ */ v(s, { children: [/* @__PURE__ */ v(u, { children: [/* @__PURE__ */ _(d, { children: "Unlock workflow" }), /* @__PURE__ */ _(c, { children: "Are you sure you want to unlock this workflow?" })] }), /* @__PURE__ */ v(l, { children: [/* @__PURE__ */ _(o, { children: "Cancel" }), /* @__PURE__ */ _(a, {
			onClick: () => {
				E.mutate({
					workflowId: x.id,
					runWorkflowPayloadDto: { transition: {
						name: "unlock",
						workflowId: S
					} },
					force: !1
				});
			},
			children: "Unlock"
		})] })] })] })]
	}) : null;
};
//#endregion
export { x as default };
