import { Form } from "../../../../utilities/form/Form.mjs";
import { arrayMutators } from "../../../../utilities/form/arrayMutators.mjs";
import { UdpTransactionActionEnums } from "../../../../enums/unitySystemEnums.mjs";
import UdpTransactionTypeTransactionActionFormFields from "./UdpTransactionTypeTransactionActionFormFields.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef, useImperativeHandle, useRef } from "react";
//#region src/udp/pages/UdpTransactionTypesPage/forms/UdpTransactionTypeTransactionActionForm.jsx
const baseActionsList = [
	UdpTransactionActionEnums.Send_Email,
	UdpTransactionActionEnums.Create_Reminder,
	UdpTransactionActionEnums.Custom_Client_Action
];
const UdpTransactionTypeTransactionActionForm = (props, ref) => {
	const $ = c(40);
	const { onSubmit, initialData, transactionActionOptions, catalogObjectProperties, actionApiOptions, pageOptions, transactionTypeStatusOptions } = props;
	const handleSubmitRef = useRef();
	let t0;
	bb0: {
		let formattedData;
		if (!initialData) {
			t0 = void 0;
			break bb0;
		}
		let t1;
		if ($[0] !== initialData?.transactionActionId || $[1] !== transactionActionOptions) {
			t1 = transactionActionOptions?.find((transactionAction) => transactionAction?.transactionActionId === initialData?.transactionActionId);
			$[0] = initialData?.transactionActionId;
			$[1] = transactionActionOptions;
			$[2] = t1;
		} else t1 = $[2];
		let t2;
		if ($[3] !== initialData?.parameters?.toStatus || $[4] !== transactionTypeStatusOptions) {
			t2 = transactionTypeStatusOptions?.find((tts) => tts?.transactionTypeStatusId === initialData?.parameters?.toStatus);
			$[3] = initialData?.parameters?.toStatus;
			$[4] = transactionTypeStatusOptions;
			$[5] = t2;
		} else t2 = $[5];
		const t3 = initialData?.parameters?.mandatoryFields;
		const t4 = initialData?.parameters?.hiddenFields;
		let t5;
		if ($[6] !== actionApiOptions || $[7] !== initialData?.parameters?.actionApiId) {
			t5 = actionApiOptions?.find((actionApi) => actionApi?.actionApiId === initialData?.parameters?.actionApiId);
			$[6] = actionApiOptions;
			$[7] = initialData?.parameters?.actionApiId;
			$[8] = t5;
		} else t5 = $[8];
		let t6;
		if ($[9] !== initialData?.parameters?.pageId || $[10] !== pageOptions) {
			t6 = pageOptions?.find((page) => page?.pageId === initialData?.parameters?.pageId);
			$[9] = initialData?.parameters?.pageId;
			$[10] = pageOptions;
			$[11] = t6;
		} else t6 = $[11];
		let t7;
		if ($[12] !== initialData?.parameters?.domainDataToUpdate) {
			t7 = initialData?.parameters?.domainDataToUpdate ? Object.entries(initialData?.parameters?.domainDataToUpdate) : [[]];
			$[12] = initialData?.parameters?.domainDataToUpdate;
			$[13] = t7;
		} else t7 = $[13];
		let t8;
		if ($[14] !== initialData || $[15] !== t1 || $[16] !== t2 || $[17] !== t3 || $[18] !== t4 || $[19] !== t5 || $[20] !== t6 || $[21] !== t7) {
			t8 = {
				...initialData,
				transactionAction: t1,
				toStatus: t2,
				mandatoryFields: t3,
				hiddenFields: t4,
				actionApiId: t5,
				pageId: t6,
				domainDataToUpdate: t7
			};
			$[14] = initialData;
			$[15] = t1;
			$[16] = t2;
			$[17] = t3;
			$[18] = t4;
			$[19] = t5;
			$[20] = t6;
			$[21] = t7;
			$[22] = t8;
		} else t8 = $[22];
		formattedData = t8;
		t0 = formattedData;
	}
	const formInitialValues = t0;
	let t1;
	if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = () => ({ submit: () => {
			handleSubmitRef?.current();
		} });
		$[23] = t1;
	} else t1 = $[23];
	useImperativeHandle(ref, t1);
	let t2;
	if ($[24] !== initialData || $[25] !== onSubmit) {
		t2 = (formData) => {
			onSubmit(formData, initialData);
		};
		$[24] = initialData;
		$[25] = onSubmit;
		$[26] = t2;
	} else t2 = $[26];
	const handleSubmit = t2;
	let t3;
	if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
		t3 = { ...arrayMutators };
		$[27] = t3;
	} else t3 = $[27];
	let t4;
	if ($[28] !== formInitialValues) {
		t4 = { ...formInitialValues };
		$[28] = formInitialValues;
		$[29] = t4;
	} else t4 = $[29];
	let t5;
	if ($[30] !== actionApiOptions || $[31] !== catalogObjectProperties || $[32] !== pageOptions || $[33] !== transactionActionOptions || $[34] !== transactionTypeStatusOptions) {
		t5 = (t6) => {
			const { handleSubmit: handleSubmit_0, form } = t6;
			handleSubmitRef.current = handleSubmit_0;
			const push = form?.mutators?.push ?? _temp;
			const transactionActionName = form?.getState()?.values?.transactionAction?.name;
			const showMandatoryFields = transactionActionName === UdpTransactionActionEnums.Set_Mandatory_Fields;
			const showHiddenFields = transactionActionName === UdpTransactionActionEnums.Set_Fields_Hidden;
			const showToStatusField = [...baseActionsList, UdpTransactionActionEnums.Update_Status].includes(transactionActionName);
			const showActionApiField = [...baseActionsList, UdpTransactionActionEnums.Product_Action].includes(transactionActionName);
			const showPageField = [...baseActionsList, UdpTransactionActionEnums.Product_Action].includes(transactionActionName);
			const showDomainDataToUpdateFields = [...baseActionsList, UdpTransactionActionEnums.Update_Domain].includes(transactionActionName);
			return /* @__PURE__ */ React.createElement(UdpTransactionTypeTransactionActionFormFields, {
				transactionActionOptions,
				catalogObjectProperties,
				actionApiOptions,
				pageOptions,
				transactionTypeStatusOptions,
				showMandatoryFields,
				showHiddenFields,
				showToStatusField,
				showActionApiField,
				showPageField,
				showDomainDataToUpdateFields,
				pushToFieldArray: push
			});
		};
		$[30] = actionApiOptions;
		$[31] = catalogObjectProperties;
		$[32] = pageOptions;
		$[33] = transactionActionOptions;
		$[34] = transactionTypeStatusOptions;
		$[35] = t5;
	} else t5 = $[35];
	let t6;
	if ($[36] !== handleSubmit || $[37] !== t4 || $[38] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(Form, {
			onSubmit: handleSubmit,
			mutators: t3,
			initialValues: t4,
			render: t5
		});
		$[36] = handleSubmit;
		$[37] = t4;
		$[38] = t5;
		$[39] = t6;
	} else t6 = $[39];
	return t6;
};
var UdpTransactionTypeTransactionActionForm_default = forwardRef(UdpTransactionTypeTransactionActionForm);
function _temp() {}
//#endregion
export { UdpTransactionTypeTransactionActionForm_default as default };

//# sourceMappingURL=UdpTransactionTypeTransactionActionForm.mjs.map