import { useRunWorkflow as e } from "../../../hooks/useProcessor.js";
import { useCallback as t } from "react";
//#region src/features/documents/renderers/useDocumentTransition.ts
function n(e) {
	let t = e, n = t?.widgets;
	return n?.[0]?.options?.transition ? n[0].options.transition : (t?.actions)?.map((e) => e.options?.transition).find((e) => !!e);
}
function r(r, i, a) {
	let o = e(), s = i.availableTransitions?.map((e) => e.id) ?? [], c = n(a), l = !!c && s.includes(c);
	return {
		submit: t((e) => {
			!c || !l || o.mutate({
				workflowId: r.id,
				runWorkflowPayloadDto: { transition: {
					id: c,
					workflowId: i.id,
					payload: e
				} }
			});
		}, [
			c,
			l,
			o,
			r.id,
			i.id
		]),
		canSubmit: l,
		isLoading: o.isPending
	};
}
//#endregion
export { r as useDocumentTransition };
