import { SideSheet } from "../../../../UI/surfaces/SideSheet.mjs";
import UdpTransactionTypeConfigurationTransactionActionForm_default from "../forms/UdpTransactionTypeConfigurationTransactionActionForm.mjs";
import { c } from "react-compiler-runtime";
import React, { useRef } from "react";
import { useTranslation } from "react-i18next";
//#region src/udp/pages/UdpTransactionTypesPage/sidesheets/UdpTransactionTypeConfigurationTransactionActionCreateAndEditSidesheet.jsx
const UdpTransactionTypeConfigurationTransactionActionCreateAndEditSidesheet = (props) => {
	const $ = c(29);
	const { initialTransactionTypeConfigurationTransactionAction, isSideSheetOpen, handleSideSheet, handleCreateTransactionTypeConfigurationTransactionAction, handleUpdateTransactionTypeConfigurationTransactionAction, transactionTypeTransactionActions, existingTtctaList } = props;
	const isEditing = !!initialTransactionTypeConfigurationTransactionAction;
	const formRef = useRef();
	const { t } = useTranslation();
	const normalizeToArray = _temp;
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = (allTTTActions, existingTTCTActions, t1) => {
			const currentTransactionTypeTransactionActionId = t1 === void 0 ? null : t1;
			const allTTTActionsArray = normalizeToArray(allTTTActions);
			const usedTTTActionIds = normalizeToArray(existingTTCTActions?.pageList).map(_temp2).filter((id) => id !== void 0 && id !== currentTransactionTypeTransactionActionId);
			return allTTTActionsArray.filter((type) => !usedTTTActionIds.includes(type.transactionTypeTransactionActionId));
		};
		$[0] = t0;
	} else t0 = $[0];
	const filterAvailableTTTActions = t0;
	let t1;
	bb0: {
		if (!transactionTypeTransactionActions || !existingTtctaList) {
			let t2;
			if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
				t2 = [];
				$[1] = t2;
			} else t2 = $[1];
			t1 = t2;
			break bb0;
		}
		const currentTTTActionId = initialTransactionTypeConfigurationTransactionAction ? initialTransactionTypeConfigurationTransactionAction.transactionTypeTransactionActionId : null;
		let t2;
		if ($[2] !== currentTTTActionId || $[3] !== existingTtctaList || $[4] !== transactionTypeTransactionActions) {
			t2 = filterAvailableTTTActions(transactionTypeTransactionActions, existingTtctaList, currentTTTActionId);
			$[2] = currentTTTActionId;
			$[3] = existingTtctaList;
			$[4] = transactionTypeTransactionActions;
			$[5] = t2;
		} else t2 = $[5];
		t1 = t2;
	}
	const availableTTTActionOptions = t1;
	let t2;
	if ($[6] !== handleCreateTransactionTypeConfigurationTransactionAction || $[7] !== handleUpdateTransactionTypeConfigurationTransactionAction) {
		t2 = async (values, initialData) => {
			if (initialData) await handleUpdateTransactionTypeConfigurationTransactionAction(values, initialData);
			else await handleCreateTransactionTypeConfigurationTransactionAction(values);
		};
		$[6] = handleCreateTransactionTypeConfigurationTransactionAction;
		$[7] = handleUpdateTransactionTypeConfigurationTransactionAction;
		$[8] = t2;
	} else t2 = $[8];
	const onSubmitForm = t2;
	let t3;
	if ($[9] !== isEditing || $[10] !== t) {
		t3 = isEditing ? t("Edit Linked Action") : t("Create Linked Action");
		$[9] = isEditing;
		$[10] = t;
		$[11] = t3;
	} else t3 = $[11];
	let t4;
	if ($[12] !== handleSideSheet) {
		t4 = () => handleSideSheet(false);
		$[12] = handleSideSheet;
		$[13] = t4;
	} else t4 = $[13];
	let t5;
	if ($[14] !== isEditing || $[15] !== t) {
		t5 = isEditing ? t("Save") : t("Create");
		$[14] = isEditing;
		$[15] = t;
		$[16] = t5;
	} else t5 = $[16];
	let t6;
	if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = () => {
			formRef?.current?.submit();
		};
		$[17] = t6;
	} else t6 = $[17];
	let t7;
	if ($[18] !== availableTTTActionOptions || $[19] !== initialTransactionTypeConfigurationTransactionAction || $[20] !== isEditing || $[21] !== onSubmitForm) {
		t7 = /* @__PURE__ */ React.createElement(UdpTransactionTypeConfigurationTransactionActionForm_default, {
			ref: formRef,
			onSubmit: onSubmitForm,
			initialData: initialTransactionTypeConfigurationTransactionAction,
			transactionTypeTransactionActionOptions: availableTTTActionOptions,
			isEditing
		});
		$[18] = availableTTTActionOptions;
		$[19] = initialTransactionTypeConfigurationTransactionAction;
		$[20] = isEditing;
		$[21] = onSubmitForm;
		$[22] = t7;
	} else t7 = $[22];
	let t8;
	if ($[23] !== isSideSheetOpen || $[24] !== t3 || $[25] !== t4 || $[26] !== t5 || $[27] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: isSideSheetOpen,
			width: 500,
			title: t3,
			onClose: t4,
			buttonLabel: t5,
			onSubmit: t6
		}, t7);
		$[23] = isSideSheetOpen;
		$[24] = t3;
		$[25] = t4;
		$[26] = t5;
		$[27] = t7;
		$[28] = t8;
	} else t8 = $[28];
	return t8;
};
function _temp(source) {
	if (Array.isArray(source)) return source;
	return [];
}
function _temp2(action) {
	return action.transactionTypeTransactionActionId;
}
//#endregion
export { UdpTransactionTypeConfigurationTransactionActionCreateAndEditSidesheet as default };

//# sourceMappingURL=UdpTransactionTypeConfigurationTransactionActionCreateAndEditSidesheet.mjs.map