import { SideSheet } from "../../../../UI/surfaces/SideSheet.mjs";
import UdpTransactionUiActionForm_default from "../forms/UdpTransactionUiActionForm.mjs";
import { c } from "react-compiler-runtime";
import React, { useRef } from "react";
import { useTranslation } from "react-i18next";
//#region src/udp/pages/UdpTransactionTypesPage/sidesheets/UdpTransactionUiActionCreateAndEditSidesheet.jsx
const UdpTransactionUiActionCreateAndEditSidesheet = (props) => {
	const $ = c(30);
	const { initialTransactionUiAction, isSideSheetOpen, handleSideSheet, handleCreateTransactionUiAction, handleUpdateTransactionUiAction, transactionUiActionTypes, actionApis, pages, tUiActionsList } = props;
	const isEditing = !!initialTransactionUiAction;
	const formRef = useRef();
	const { t } = useTranslation();
	const normalizeToArray = _temp;
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = (allTUATypes, transactionUiActions, t1) => {
			const currentTransactionUiActionTypeId = t1 === void 0 ? null : t1;
			const allTUATypesArray = normalizeToArray(allTUATypes);
			const transactionUiActionsArray = normalizeToArray(transactionUiActions?.pageList);
			if (!transactionUiActions) return allTUATypesArray;
			const usedTUATypeIds = transactionUiActionsArray.map(_temp2).filter((id) => id !== void 0 && id !== currentTransactionUiActionTypeId);
			return allTUATypesArray.filter((type) => !usedTUATypeIds.includes(type.transactionUiActionTypeId));
		};
		$[0] = t0;
	} else t0 = $[0];
	const filterAvailableTUATypes = t0;
	let t1;
	bb0: {
		if (!transactionUiActionTypes) {
			let t2;
			if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
				t2 = [];
				$[1] = t2;
			} else t2 = $[1];
			t1 = t2;
			break bb0;
		}
		const currentTUATypeId = initialTransactionUiAction ? initialTransactionUiAction.transactionUiActionTypeId : null;
		let t2;
		if ($[2] !== currentTUATypeId || $[3] !== tUiActionsList || $[4] !== transactionUiActionTypes) {
			t2 = filterAvailableTUATypes(transactionUiActionTypes, tUiActionsList, currentTUATypeId);
			$[2] = currentTUATypeId;
			$[3] = tUiActionsList;
			$[4] = transactionUiActionTypes;
			$[5] = t2;
		} else t2 = $[5];
		t1 = t2;
	}
	const availableTUATypeOptions = t1;
	let t2;
	if ($[6] !== handleCreateTransactionUiAction || $[7] !== handleUpdateTransactionUiAction) {
		t2 = async (values, initialData) => {
			if (initialData) await handleUpdateTransactionUiAction(values, initialData);
			else await handleCreateTransactionUiAction(values);
		};
		$[6] = handleCreateTransactionUiAction;
		$[7] = handleUpdateTransactionUiAction;
		$[8] = t2;
	} else t2 = $[8];
	const onSubmitForm = t2;
	let t3;
	if ($[9] !== isEditing || $[10] !== t) {
		t3 = isEditing ? t("Edit UI Action") : t("Create UI 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] !== actionApis || $[19] !== availableTUATypeOptions || $[20] !== initialTransactionUiAction || $[21] !== onSubmitForm || $[22] !== pages) {
		t7 = /* @__PURE__ */ React.createElement(UdpTransactionUiActionForm_default, {
			ref: formRef,
			onSubmit: onSubmitForm,
			initialData: initialTransactionUiAction,
			transactionUiActionTypeOptions: availableTUATypeOptions,
			actionApiOptions: actionApis,
			pageOptions: pages
		});
		$[18] = actionApis;
		$[19] = availableTUATypeOptions;
		$[20] = initialTransactionUiAction;
		$[21] = onSubmitForm;
		$[22] = pages;
		$[23] = t7;
	} else t7 = $[23];
	let t8;
	if ($[24] !== isSideSheetOpen || $[25] !== t3 || $[26] !== t4 || $[27] !== t5 || $[28] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: isSideSheetOpen,
			width: 600,
			title: t3,
			onClose: t4,
			buttonLabel: t5,
			onSubmit: t6
		}, t7);
		$[24] = isSideSheetOpen;
		$[25] = t3;
		$[26] = t4;
		$[27] = t5;
		$[28] = t7;
		$[29] = t8;
	} else t8 = $[29];
	return t8;
};
function _temp(source) {
	if (Array.isArray(source)) return source;
	return [];
}
function _temp2(action) {
	return action.transactionUiActionTypeId;
}
//#endregion
export { UdpTransactionUiActionCreateAndEditSidesheet as default };

//# sourceMappingURL=UdpTransactionUiActionCreateAndEditSidesheet.mjs.map