import Form_default from "../../../../components/dynamic-form/Form.js";
import { useRunPipeline } from "../../../../hooks/useProcessor.js";
import UiActions_default from "../../../../components/ui-widgets/UiActions.js";
import { c } from "react/compiler-runtime";
import React, { useEffect } from "react";
import { jsx } from "react/jsx-runtime";
import { useForm } from "react-hook-form";
import "zod";
var DocumentFormRenderer_default = (l) => {
	let u = c(38), { pipeline: d, workflow: f, document: p, enabled: m, viewOnly: h } = l, g = useRunPipeline(), _;
	u[0] !== p.content || u[1] !== p.schema.type ? (_ = p.schema.type === "object" ? p.content : { raw: p.content }, u[0] = p.content, u[1] = p.schema.type, u[2] = _) : _ = u[2];
	let v;
	u[3] === _ ? v = u[4] : (v = {
		defaultValues: _,
		mode: "onChange"
	}, u[3] = _, u[4] = v);
	let y = useForm(v), b, x;
	u[5] !== p.validationError || u[6] !== y ? (b = () => {
		p.validationError ? p.validationError.issues.forEach((e) => {
			let s = e.path.join(".");
			y.setError(s, {
				type: e.code,
				message: e.message
			});
		}) : y.clearErrors();
	}, x = [p.validationError, y], u[5] = p.validationError, u[6] = y, u[7] = b, u[8] = x) : (b = u[7], x = u[8]), useEffect(b, x);
	let S;
	u[9] === f.availableTransitions ? S = u[10] : (S = f.availableTransitions?.map(_temp) ?? [], u[9] = f.availableTransitions, u[10] = S);
	let C = S, w;
	u[11] !== C || u[12] !== d || u[13] !== g || u[14] !== f.id ? (w = (e, s) => {
		if (!C.includes(e)) {
			console.error(`Transition ${e} not available.`);
			return;
		}
		g.mutate({
			pipelineId: d.id,
			runPipelinePayloadDto: { transition: {
				id: e,
				workflowId: f.id,
				payload: s
			} }
		});
	}, u[11] = C, u[12] = d, u[13] = g, u[14] = f.id, u[15] = w) : w = u[15];
	let T = w, E;
	u[16] !== p.schema.type || u[17] !== T ? (E = (e) => (s) => {
		p.schema.type === "object" ? T(e, s) : T(e, s.raw);
	}, u[16] = p.schema.type, u[17] = T, u[18] = E) : E = u[18];
	let D = E, O;
	u[19] !== y || u[20] !== D ? (O = (e) => {
		y.handleSubmit(D(e))();
	}, u[19] = y, u[20] = D, u[21] = O) : O = u[21];
	let k = O, A = p.ui, j = p.schema, M = A?.form?.disabled, N = !m || M || !1, P;
	u[22] === p.ui?.actions ? P = u[23] : (P = p.ui?.actions ?? [], u[22] = p.ui?.actions, u[23] = P);
	let F = P, I = A ?? void 0, L = p.meta?.mimeType, R;
	u[24] !== F || u[25] !== C || u[26] !== N || u[27] !== k || u[28] !== g.isPending ? (R = /* @__PURE__ */ jsx(UiActions_default, {
		actions: F,
		onSubmit: k,
		availableTransitions: C,
		disabled: N,
		isLoading: g.isPending
	}), u[24] = F, u[25] = C, u[26] = N, u[27] = k, u[28] = g.isPending, u[29] = R) : R = u[29];
	let z;
	return u[30] !== N || u[31] !== y || u[32] !== j || u[33] !== I || u[34] !== L || u[35] !== R || u[36] !== h ? (z = /* @__PURE__ */ jsx("div", {
		className: "flex",
		children: /* @__PURE__ */ jsx(Form_default, {
			form: y,
			schema: j,
			ui: I,
			mimeType: L,
			disabled: N,
			viewOnly: h,
			actions: R
		})
	}), u[30] = N, u[31] = y, u[32] = j, u[33] = I, u[34] = L, u[35] = R, u[36] = h, u[37] = z) : z = u[37], z;
};
function _temp(e) {
	return e.id;
}
export { DocumentFormRenderer_default as default };
