import { SideSheet } from "../../../../UI/surfaces/SideSheet.mjs";
import UdpTransactionAttachmentTypeForm_default from "../forms/UdpTransactionAttachmentTypeForm.mjs";
import { c } from "react-compiler-runtime";
import React, { useRef } from "react";
import { useTranslation } from "react-i18next";
//#region src/udp/pages/UdpTransactionTypesPage/sidesheets/UdpTransactionAttachmentTypeCreateAndEditSidesheet.jsx
const UdpTransactionAttachmentTypeCreateAndEditSidesheet = (props) => {
	const $ = c(21);
	const { initialTransactionAttachmentType, isSideSheetOpen, handleCreateTransactionAttachmentType, handleUpdateTransactionAttachmentType, handleSideSheet } = props;
	const isEditing = !!initialTransactionAttachmentType;
	const formRef = useRef();
	const { t } = useTranslation();
	let t0;
	if ($[0] !== handleCreateTransactionAttachmentType || $[1] !== handleUpdateTransactionAttachmentType) {
		t0 = async (values, initialData) => {
			if (initialData) await handleUpdateTransactionAttachmentType(values, initialData);
			else await handleCreateTransactionAttachmentType(values);
		};
		$[0] = handleCreateTransactionAttachmentType;
		$[1] = handleUpdateTransactionAttachmentType;
		$[2] = t0;
	} else t0 = $[2];
	const onSubmitForm = t0;
	let t1;
	if ($[3] !== isEditing || $[4] !== t) {
		t1 = isEditing ? t("Edit Attachment Type") : t("Create Attachment Type");
		$[3] = isEditing;
		$[4] = t;
		$[5] = t1;
	} else t1 = $[5];
	let t2;
	if ($[6] !== handleSideSheet) {
		t2 = () => handleSideSheet(false);
		$[6] = handleSideSheet;
		$[7] = t2;
	} else t2 = $[7];
	let t3;
	if ($[8] !== isEditing || $[9] !== t) {
		t3 = isEditing ? t("Save") : t("Create");
		$[8] = isEditing;
		$[9] = t;
		$[10] = t3;
	} else t3 = $[10];
	let t4;
	if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
		t4 = () => {
			formRef?.current?.submit();
		};
		$[11] = t4;
	} else t4 = $[11];
	let t5;
	if ($[12] !== initialTransactionAttachmentType || $[13] !== onSubmitForm) {
		t5 = /* @__PURE__ */ React.createElement(UdpTransactionAttachmentTypeForm_default, {
			ref: formRef,
			onSubmit: onSubmitForm,
			initialData: initialTransactionAttachmentType
		});
		$[12] = initialTransactionAttachmentType;
		$[13] = onSubmitForm;
		$[14] = t5;
	} else t5 = $[14];
	let t6;
	if ($[15] !== isSideSheetOpen || $[16] !== t1 || $[17] !== t2 || $[18] !== t3 || $[19] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: isSideSheetOpen,
			width: 500,
			title: t1,
			onClose: t2,
			buttonLabel: t3,
			onSubmit: t4
		}, t5);
		$[15] = isSideSheetOpen;
		$[16] = t1;
		$[17] = t2;
		$[18] = t3;
		$[19] = t5;
		$[20] = t6;
	} else t6 = $[20];
	return t6;
};
//#endregion
export { UdpTransactionAttachmentTypeCreateAndEditSidesheet as default };

//# sourceMappingURL=UdpTransactionAttachmentTypeCreateAndEditSidesheet.mjs.map