import { useStudio } from "../../../../providers/StudioProvider.js";
import { useDeleteWorkflow } from "../../../../hooks/useWorkflows.js";
import { Button } from "../../../../components/ui/button.js";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "../../../../components/ui/alert-dialog.js";
import { useRunPipeline } from "../../../../hooks/useProcessor.js";
import { c } from "react/compiler-runtime";
import React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { LockOpen, Trash2 } from "lucide-react";
var WorkflowButtons_default = (b) => {
	let x = c(33), { pipeline: S, workflow: C } = b, { router: w } = useStudio(), T = useDeleteWorkflow(), E = useRunPipeline(), D;
	x[0] !== S.id || x[1] !== E ? (D = () => {
		E.mutate({
			pipelineId: S.id,
			runPipelinePayloadDto: {},
			force: !1
		});
	}, x[0] = S.id, x[1] = E, x[2] = D) : D = x[2];
	let O = D, k;
	x[3] !== S.id || x[4] !== E || x[5] !== C.id ? (k = () => {
		E.mutate({
			pipelineId: S.id,
			runPipelinePayloadDto: { transition: {
				name: "unlock",
				workflowId: C.id
			} },
			force: !1
		});
	}, x[3] = S.id, x[4] = E, x[5] = C.id, x[6] = k) : k = x[6];
	let A = k, j;
	x[7] !== T || x[8] !== O || x[9] !== S.id || x[10] !== w || x[11] !== C ? (j = () => {
		try {
			T.mutate(C), O(), w.navigateToPipeline(S.id);
		} catch (e) {
			let y = e;
			console.error("Mutation failed:", y);
		}
	}, x[7] = T, x[8] = O, x[9] = S.id, x[10] = w, x[11] = C, x[12] = j) : j = x[12];
	let M = j, N;
	x[13] === T.isPending ? N = x[14] : (N = T.isPending ? /* @__PURE__ */ jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }) : /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" }), x[13] = T.isPending, x[14] = N);
	let P;
	x[15] !== T.isPending || x[16] !== N ? (P = /* @__PURE__ */ jsx(AlertDialogTrigger, {
		asChild: !0,
		children: /* @__PURE__ */ jsxs(Button, {
			variant: "ghost",
			size: "sm",
			disabled: T.isPending,
			children: [N, "Delete and Repeat Workflow"]
		})
	}), x[15] = T.isPending, x[16] = N, x[17] = P) : P = x[17];
	let F;
	x[18] === Symbol.for("react.memo_cache_sentinel") ? (F = /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [/* @__PURE__ */ jsx(AlertDialogTitle, { children: "Are you sure?" }), /* @__PURE__ */ jsx(AlertDialogDescription, { children: "This action cannot be undone. This will permanently delete the workflow." })] }), x[18] = F) : F = x[18];
	let I;
	x[19] === Symbol.for("react.memo_cache_sentinel") ? (I = /* @__PURE__ */ jsx(AlertDialogCancel, { children: "Cancel" }), x[19] = I) : I = x[19];
	let L;
	x[20] === M ? L = x[21] : (L = /* @__PURE__ */ jsxs(AlertDialogContent, { children: [F, /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [I, /* @__PURE__ */ jsx(AlertDialogAction, {
		className: "bg-destructive hover:bg-destructive/90 text-white",
		onClick: M,
		children: "Delete"
	})] })] }), x[20] = M, x[21] = L);
	let R;
	x[22] !== P || x[23] !== L ? (R = /* @__PURE__ */ jsxs(AlertDialog, { children: [P, L] }), x[22] = P, x[23] = L, x[24] = R) : R = x[24];
	let z;
	x[25] !== A || x[26] !== E.isPending || x[27] !== C.availableTransitions || x[28] !== C.place ? (z = C.place === "end" && C.availableTransitions?.find(_temp) && /* @__PURE__ */ jsxs(AlertDialog, { children: [/* @__PURE__ */ jsx(AlertDialogTrigger, {
		asChild: !0,
		children: /* @__PURE__ */ jsxs(Button, {
			variant: "ghost",
			size: "sm",
			disabled: E.isPending,
			children: [E.isPending ? /* @__PURE__ */ jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" }) : /* @__PURE__ */ jsx(LockOpen, { className: "h-4 w-4" }), "Unlock Step"]
		})
	}), /* @__PURE__ */ jsxs(AlertDialogContent, { children: [/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [/* @__PURE__ */ jsx(AlertDialogTitle, { children: "Unlock workflow" }), /* @__PURE__ */ jsx(AlertDialogDescription, { children: "Are you sure you want to unlock this workflow?" })] }), /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [/* @__PURE__ */ jsx(AlertDialogCancel, { children: "Cancel" }), /* @__PURE__ */ jsx(AlertDialogAction, {
		onClick: A,
		children: "Unlock"
	})] })] })] }), x[25] = A, x[26] = E.isPending, x[27] = C.availableTransitions, x[28] = C.place, x[29] = z) : z = x[29];
	let B;
	return x[30] !== z || x[31] !== R ? (B = /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("div", {
		className: "flex",
		children: [R, z]
	}) }), x[30] = z, x[31] = R, x[32] = B) : B = x[32], B;
};
function _temp(e) {
	return e.id === "unlock";
}
export { WorkflowButtons_default as default };
