import { getPathObject, getPrimaryKeyValues } from "../../../utilities/maintenanceEngine/CrudBrowserUtilities.mjs";
import { ConfigService } from "../../../configService/index.mjs";
import { CardinalityTypeEnums, EntityAttributeEnums, UdpEnums } from "../../../enums/unitySystemEnums.mjs";
import { useHandleAxiosSnackbar } from "../../../utilities/apiHelpers.mjs";
import { apiMutate } from "../../../utilities/useAxiosMutate.mjs";
import { toLowerFirstChar, toUpperFirstChar } from "../../../utilities/input/StringUtilities.mjs";
import { getSanitizedName } from "../../../utilities/entities/entityUtilities.mjs";
import { useCatalogStore } from "../../../stores/catalogStore.mjs";
import { getSearchObject } from "../../../utilities/search/SearchUtilities.mjs";
import { SideSheet } from "../../../UI/surfaces/SideSheet.mjs";
import { useAxiosGet } from "../../../utilities/useAxiosGet.mjs";
import { usePromotedMethodEntity } from "../../../hooks/usePromotedMethodEntity.mjs";
import { executeQueryAdHoc } from "../../utilities/methodUtils.mjs";
import { FluentDialog } from "../../../UI/feedback/FluentDialog.mjs";
import { TagEnums } from "../../../enums/tagEnums.mjs";
import { CrudBrowserContainer } from "../../../maintenanceEngine/crudBrowser/CrudBrowserContainer.mjs";
import { CrudTableSidePanel } from "../../../maintenanceEngine/crudBrowser/CrudTableSidePanel.mjs";
import { Inquiry } from "../../../inquiry/Inquiry.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useRef, useState } from "react";
import { useHistory, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { v4 } from "uuid";
import { Alert } from "@material-ui/lab";
//#region src/udp/pages/UdpMaintenanceEnginePage/UdpMaintenanceEnginePage.jsx
const UdpMaintenanceEnginePage = (props) => {
	const $ = c(169);
	const { catalogKey, params } = props;
	const { t } = useTranslation();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = [];
		$[0] = t0;
	} else t0 = $[0];
	const [udpFieldInfos, setUdpFieldInfos] = useState(t0);
	let t1;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = [];
		$[1] = t1;
	} else t1 = $[1];
	const [alertWarnings, setAlertWarnings] = useState(t1);
	const [showBackToTableBrowser, setShowBackToTableBrowser] = useState(false);
	const gridApiRef = useRef(null);
	let t2;
	if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
		t2 = {
			type: null,
			data: null
		};
		$[2] = t2;
	} else t2 = $[2];
	const [modalConfig, setModalConfig] = useState(t2);
	const location = useLocation();
	const state = location.state;
	const history = useHistory();
	const searchParamStr = location.search;
	let t3;
	if ($[3] !== searchParamStr || $[4] !== state) {
		const searchParams = new URLSearchParams(searchParamStr);
		t3 = state?.entityName ? state.entityName : searchParams.has("entityName") === true ? toUpperFirstChar(searchParams.get("entityName")) : "";
		$[3] = searchParamStr;
		$[4] = state;
		$[5] = t3;
	} else t3 = $[5];
	const searchParamsEntityName = t3;
	const { handleErrorSnackbar, handleSuccessSnackbar } = useHandleAxiosSnackbar();
	const handleGoToTableBrowser = () => {
		history.push({ pathname: "/tableBrowser" });
	};
	params?.entityName;
	let t4;
	bb0: {
		if (params?.entityName || catalogKey || searchParamsEntityName) {
			t4 = params?.entityName || catalogKey || searchParamsEntityName;
			break bb0;
		} else handleGoToTableBrowser();
		t4 = void 0;
	}
	const udpCatalogKey = t4;
	const udpTagId = params?.udpTagId || "";
	const [selectedEntity, setSelectedEntity] = useState(null);
	const [foreignKeyData, setForeignKeyData] = useState(null);
	const [udpFieldSearchApiId, setUdpFieldSearchApiId] = useState(null);
	const [entityUdpObjectInfo, setEntityUdpObjectInfo] = useState(null);
	const [entityName, setEntityName] = useState(null);
	const { currentApiCatalogId } = useCatalogStore();
	const { data: udpObjectInfoEntity } = usePromotedMethodEntity("udpObjectInfo", true);
	const { data: udpObjectFieldInfo } = usePromotedMethodEntity("UdpObjectFieldInfo", true);
	const { data: promotedMethodEntities } = usePromotedMethodEntity(udpCatalogKey, true);
	let t5;
	if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = (type, t6) => {
			setModalConfig({
				type,
				data: t6 === void 0 ? null : t6
			});
		};
		$[6] = t5;
	} else t5 = $[6];
	const openModal = t5;
	let t6;
	if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = () => {
			setModalConfig({
				type: null,
				data: null
			});
		};
		$[7] = t6;
	} else t6 = $[7];
	const closeModal = t6;
	let t7;
	if ($[8] !== selectedEntity?.unityBaseCreateMethod?.apiMethodId) {
		t7 = async (data_0) => apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${selectedEntity?.unityBaseCreateMethod?.apiMethodId}`, { method: "post" }, data_0);
		$[8] = selectedEntity?.unityBaseCreateMethod?.apiMethodId;
		$[9] = t7;
	} else t7 = $[9];
	const executeCreate = t7;
	let t8;
	if ($[10] !== selectedEntity?.unityBaseUpdateMethod?.apiMethodId) {
		t8 = async (data_1) => apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${selectedEntity?.unityBaseUpdateMethod?.apiMethodId}`, { method: "post" }, data_1);
		$[10] = selectedEntity?.unityBaseUpdateMethod?.apiMethodId;
		$[11] = t8;
	} else t8 = $[11];
	const executeUpdate = t8;
	let t9;
	if ($[12] !== selectedEntity?.unityBaseDeleteMethod?.apiMethodId) {
		t9 = async (data_2) => apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${selectedEntity?.unityBaseDeleteMethod?.apiMethodId}`, { method: "post" }, data_2);
		$[12] = selectedEntity?.unityBaseDeleteMethod?.apiMethodId;
		$[13] = t9;
	} else t9 = $[13];
	const executeDelete = t9;
	let t10;
	if ($[14] !== executeCreate) {
		t10 = async (data_3) => await executeCreate(data_3);
		$[14] = executeCreate;
		$[15] = t10;
	} else t10 = $[15];
	const onCreate = t10;
	let t11;
	if ($[16] !== executeUpdate) {
		t11 = async (data_4) => await executeUpdate(data_4);
		$[16] = executeUpdate;
		$[17] = t11;
	} else t11 = $[17];
	const onUpdate = t11;
	let t12;
	if ($[18] !== executeDelete) {
		t12 = async (data_5) => await executeDelete(data_5);
		$[18] = executeDelete;
		$[19] = t12;
	} else t12 = $[19];
	const onDelete = t12;
	let t13;
	if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
		t13 = {};
		$[20] = t13;
	} else t13 = $[20];
	const [t14] = useAxiosGet(ConfigService.integrationV2ApiUrl, `apiCatalog/${currentApiCatalogId}/catalogObject/${entityName}`, t13, !!!currentApiCatalogId || !!!entityName, false);
	const { data: catalogObject } = t14;
	params?.filterElements;
	let filterElements;
	if ($[21] !== params?.filterElements || $[22] !== udpTagId) {
		filterElements = [];
		if (udpTagId) filterElements.push({
			searchField: "UdpTags.UdpTagAssociationUdpTag.Id",
			searchOperator: "=",
			searchValue: udpTagId
		});
		if (params?.filterElements) params?.filterElements?.forEach((filter) => {
			filterElements.push(filter);
		});
		$[21] = params?.filterElements;
		$[22] = udpTagId;
		$[23] = filterElements;
	} else filterElements = $[23];
	const searchFilterElements = filterElements;
	let t15;
	bb1: {
		if (udpFieldInfos?.length > 0 && catalogObject && entityName) {
			let t16;
			if ($[24] !== catalogObject?.properties || $[25] !== udpFieldInfos) {
				const originalAttributes = catalogObject?.properties || [];
				const attributeMap = new Map(originalAttributes.map(_temp));
				const sortedPart = udpFieldInfos.map((field) => {
					const match = attributeMap.get(field.name.toLowerCase());
					if (match) return {
						...match,
						extendedProperties: {
							...match.extendedProperties,
							udpFieldProperties: field.properties
						}
					};
					return null;
				}).filter(Boolean);
				let t17;
				if ($[27] !== udpFieldInfos) {
					t17 = new Set(udpFieldInfos.map(_temp2));
					$[27] = udpFieldInfos;
					$[28] = t17;
				} else t17 = $[28];
				const udpFieldNames = t17;
				let t18;
				if ($[29] !== udpFieldNames) {
					t18 = (attr_0) => !udpFieldNames.has(attr_0.name.toLowerCase());
					$[29] = udpFieldNames;
					$[30] = t18;
				} else t18 = $[30];
				const unmatchedPart = originalAttributes.filter(t18);
				t16 = [...sortedPart, ...unmatchedPart];
				$[24] = catalogObject?.properties;
				$[25] = udpFieldInfos;
				$[26] = t16;
			} else t16 = $[26];
			t15 = t16;
			break bb1;
		}
		t15 = void 0;
	}
	const entityAttributes = t15;
	let t16;
	if ($[31] !== udpFieldSearchApiId) {
		t16 = async (entityName_0) => {
			let fieldInfos = [];
			if (udpFieldSearchApiId) await executeQueryAdHoc({ data: getSearchObject([{
				searchField: "ObjectInfo.SanitizedName",
				searchOperator: "=",
				searchValue: getSanitizedName(entityName_0)
			}], 1, 50, true) }, udpFieldSearchApiId).then((resp) => {
				fieldInfos = resp.data?.pageList;
			});
			return fieldInfos;
		};
		$[31] = udpFieldSearchApiId;
		$[32] = t16;
	} else t16 = $[32];
	const getMetaDataForUdpField = t16;
	let t17;
	if ($[33] !== currentApiCatalogId) {
		t17 = async (attributes) => {
			if (!attributes) return [];
			const fkMethods = [];
			for (const attr_1 of attributes) if (attr_1?.extendedProperties?.childEntity) {
				const ceFieldsArr = [];
				const childAssoc = attr_1.extendedProperties.childEntityAssoc;
				if (childAssoc && Object.keys(childAssoc).length > 0 && (childAssoc.Cardinality === CardinalityTypeEnums.Many_To_Many || childAssoc.Cardinality === CardinalityTypeEnums.One_To_Many) && !childAssoc.UdpType) childAssoc.Keys.forEach((value, i) => {
					const name = value.split(",")[0];
					if (name) ceFieldsArr.push({
						idx: i,
						name: /^[A-Z]*$/.test(name) ? name.toLowerCase() : toLowerFirstChar(name)
					});
				});
				const ceAttr = attributes.find((p) => ceFieldsArr.find((cef) => cef.name === p.name));
				if (ceAttr) await apiMutate(ConfigService.integrationV1ApiUrl, `apicatalog/${currentApiCatalogId}/promotedMethodEntities/${attr_1.reference}/product/${ConfigService.config.UNITY_PRODUCT_ID}`, { method: "get" }, {}).then((resp_0) => {
					if (resp_0 && resp_0.data) fkMethods.push({
						entityAttribute: ceAttr,
						entity: resp_0.data
					});
				});
			}
			return fkMethods;
		};
		$[33] = currentApiCatalogId;
		$[34] = t17;
	} else t17 = $[34];
	const getFKMethodEntities = t17;
	let t18;
	if ($[35] !== getMetaDataForUdpField) {
		t18 = async (entityName_1) => {
			let fieldsInfo;
			fieldsInfo = await getMetaDataForUdpField(entityName_1);
			if (fieldsInfo?.length <= 0) return "";
			return (fieldsInfo?.find(_temp3))?.name;
		};
		$[35] = getMetaDataForUdpField;
		$[36] = t18;
	} else t18 = $[36];
	const getFKAssociationLabel = t18;
	const getDataByKey = _temp4;
	let t19;
	if ($[37] !== entityAttributes || $[38] !== getFKAssociationLabel || $[39] !== getFKMethodEntities) {
		t19 = async () => {
			if (!entityAttributes?.length) return null;
			const fkMethods_0 = await getFKMethodEntities(entityAttributes);
			if (!fkMethods_0?.length) {
				setForeignKeyData([]);
				return [];
			}
			const fkData = [];
			const promises = [];
			const promiseDetails = [];
			const warnings = [];
			for (const method of fkMethods_0) if (method && method?.entity?.unityBaseGetAllMethod) {
				const associationLabel = await getFKAssociationLabel(method.entity.entityName);
				promiseDetails.push({
					url: ConfigService.integrationV1ApiUrl + `/apimethod/executeQueryWithParameters/${method?.entity?.unityBaseGetAllMethod?.apiMethodId}`,
					fieldName: method.entityAttribute.name,
					name: method.entity.entityName,
					associationLabel
				});
				promises.push(apiMutate(ConfigService.integrationV1ApiUrl, `apimethod/executeQueryWithParameters/${method?.entity?.unityBaseGetAllMethod?.apiMethodId}`, { method: "post" }, { data: {} }));
			} else warnings.push({
				id: v4(),
				message: `${method.entity.entityName}'s Get-All method needs to be promoted`
			});
			setAlertWarnings((existingWarnings) => [...existingWarnings, ...warnings]);
			Promise.all(promises).then((resp_1) => {
				resp_1.forEach((response, index) => {
					if (response.status === 200) {
						if (response?.data) {
							const respData = [];
							const promiseDetail = promiseDetails.find((p_0) => p_0.url === response?.config?.url && !fkData.find((fd) => fd.entityName === p_0.name && fd.fieldName === p_0.fieldName));
							response.data.forEach((d) => {
								const id = getDataByKey(d, promiseDetail?.fieldName && d[promiseDetail.fieldName] ? promiseDetail.fieldName : "id");
								const name_0 = getDataByKey(d, promiseDetail?.associationLabel ? toLowerFirstChar(promiseDetail.associationLabel) : "name");
								respData.push({
									id,
									name: name_0 ?? id
								});
							});
							if (!!promiseDetail) fkData.push({
								fieldName: promiseDetail.fieldName,
								entityName: promiseDetail.name,
								name: promiseDetail.fieldName,
								data: respData
							});
						}
					}
				});
				setForeignKeyData(fkData);
			});
		};
		$[37] = entityAttributes;
		$[38] = getFKAssociationLabel;
		$[39] = getFKMethodEntities;
		$[40] = t19;
	} else t19 = $[40];
	const getFKData = t19;
	let t20;
	if ($[41] !== handleErrorSnackbar || $[42] !== handleSuccessSnackbar || $[43] !== onCreate || $[44] !== selectedEntity || $[45] !== t) {
		t20 = async (values) => {
			if (selectedEntity) {
				const entityName_2 = selectedEntity?.entityName;
				if (selectedEntity?.unityBaseCreateMethod) {
					const response_0 = await onCreate({ data: { requestBody: values } }).catch((res) => {
						handleErrorSnackbar(res);
					});
					if (response_0?.status === 200) {
						handleSuccessSnackbar(entityName_2 ? t(`${entityName_2} has been created`) : t("Entity has been created"));
						gridApiRef.current.refreshServerSide();
						closeModal("create");
						return response_0;
					}
				} else handleErrorSnackbar(null, selectedEntity.entityName + "'s create method must be promoted");
			}
		};
		$[41] = handleErrorSnackbar;
		$[42] = handleSuccessSnackbar;
		$[43] = onCreate;
		$[44] = selectedEntity;
		$[45] = t;
		$[46] = t20;
	} else t20 = $[46];
	const handleOnCreate = t20;
	let t21;
	if ($[47] !== handleErrorSnackbar || $[48] !== handleSuccessSnackbar || $[49] !== onUpdate || $[50] !== selectedEntity || $[51] !== t) {
		t21 = async (values_0, primaryKeyValues) => {
			if (selectedEntity) {
				const entityName_3 = selectedEntity?.entityName;
				if (selectedEntity?.unityBaseUpdateMethod) {
					const pathObject = getPathObject(selectedEntity.unityBaseUpdateMethod.pathParameters, primaryKeyValues);
					let data_7 = { requestBody: values_0 };
					if (Array.isArray(pathObject)) pathObject.forEach((po) => {
						data_7[Object.keys(po)[0]] = po[Object.keys(po)[0]];
					});
					else data_7 = {
						...pathObject,
						requestBody: values_0
					};
					if ((await onUpdate({ data: data_7 }).catch((res_0) => {
						handleErrorSnackbar(res_0);
					}))?.status === 200) {
						handleSuccessSnackbar(entityName_3 ? t(`${entityName_3} has been updated`) : t("Entity has been updated"));
						gridApiRef.current.refreshServerSide();
						closeModal("edit");
					}
				}
			}
		};
		$[47] = handleErrorSnackbar;
		$[48] = handleSuccessSnackbar;
		$[49] = onUpdate;
		$[50] = selectedEntity;
		$[51] = t;
		$[52] = t21;
	} else t21 = $[52];
	const handleOnUpdate = t21;
	let t22;
	if ($[53] !== entityAttributes || $[54] !== handleErrorSnackbar || $[55] !== handleSuccessSnackbar || $[56] !== onDelete || $[57] !== selectedEntity || $[58] !== t) {
		t22 = async (value_0) => {
			if (selectedEntity) {
				const entityName_4 = selectedEntity?.entityName;
				if (selectedEntity?.unityBaseDeleteMethod) {
					const primaryKeyValues_0 = getPrimaryKeyValues(entityAttributes, value_0);
					const pathObject_0 = getPathObject(selectedEntity?.unityBaseDeleteMethod.pathParameters, primaryKeyValues_0);
					let data_8 = {};
					if (Array.isArray(pathObject_0)) pathObject_0.forEach((po_0) => {
						data_8[Object.keys(po_0)[0]] = po_0[Object.keys(po_0)[0]];
					});
					else data_8 = { ...pathObject_0 };
					if ((await onDelete({ data: data_8 }).catch((res_1) => {
						handleErrorSnackbar(res_1);
					}))?.status === 200) {
						handleSuccessSnackbar(entityName_4 ? t(`${entityName_4} has been deleted`) : t("Entity has been deleted"));
						gridApiRef.current.refreshServerSide();
						closeModal("delete");
					}
				}
			}
		};
		$[53] = entityAttributes;
		$[54] = handleErrorSnackbar;
		$[55] = handleSuccessSnackbar;
		$[56] = onDelete;
		$[57] = selectedEntity;
		$[58] = t;
		$[59] = t22;
	} else t22 = $[59];
	const handleOnDelete = t22;
	let t23;
	if ($[60] !== alertWarnings) {
		t23 = (id_0) => {
			setAlertWarnings(alertWarnings.filter((warning) => warning.id !== id_0));
		};
		$[60] = alertWarnings;
		$[61] = t23;
	} else t23 = $[61];
	const removeWarning = t23;
	let t24;
	if ($[62] !== entityName) {
		t24 = (value_1) => {
			const sanitizedEntityName = getSanitizedName(entityName);
			const tagTypeShouldDisableEdit = [TagEnums.TagTypeSanitizedName.toLowerCase()].includes(sanitizedEntityName?.toLowerCase()) && !value_1?.[toLowerFirstChar(EntityAttributeEnums.User_Defined)];
			const shortCutContentShouldDisableEdit = [UdpEnums.Udp_Shortcut_Content.toLowerCase()].includes(sanitizedEntityName?.toLowerCase()) && value_1?.[toLowerFirstChar(EntityAttributeEnums.Is_Product_ShortcutContent)];
			const lookupShouldDisableEdit = [UdpEnums.Udp_Lookup.toLowerCase()].includes(sanitizedEntityName?.toLowerCase()) && value_1?.[toLowerFirstChar(EntityAttributeEnums.Is_Product_Lookup)];
			return tagTypeShouldDisableEdit || shortCutContentShouldDisableEdit || lookupShouldDisableEdit;
		};
		$[62] = entityName;
		$[63] = t24;
	} else t24 = $[63];
	const shouldDisableAction = t24;
	let t25;
	if ($[64] !== params?.inquiryTreeId || $[65] !== selectedEntity || $[66] !== shouldDisableAction || $[67] !== t) {
		t25 = () => {
			if (!selectedEntity) return [];
			const actions = [{
				id: "edit",
				iconName: "edit",
				getTitle: () => selectedEntity?.unityBaseUpdateMethod ? t("Edit") : t("Edit Method Not Accessible"),
				handleOnClick: (e, params_0) => {
					openModal("edit", params_0.data);
				},
				checkDisabled: (params_1) => !!!selectedEntity?.unityBaseUpdateMethod || shouldDisableAction(params_1.data)
			}, {
				id: "delete",
				iconName: "trashCan",
				getTitle: () => selectedEntity?.unityBaseDeleteMethod ? t("Delete") : t("Delete Method Not Accessible"),
				handleOnClick: (e_0, params_2) => {
					openModal("delete", params_2.data);
				},
				checkDisabled: (params_3) => !!!selectedEntity?.unityBaseDeleteMethod || shouldDisableAction(params_3.data)
			}];
			if (params?.inquiryTreeId) actions.splice(1, 0, {
				id: "inquiry",
				iconName: "relationshipDiagram",
				title: "Detailed view",
				handleOnClick: (e_1, params_4) => {
					openModal("inquiry", params_4.data);
				}
			});
			return actions;
		};
		$[64] = params?.inquiryTreeId;
		$[65] = selectedEntity;
		$[66] = shouldDisableAction;
		$[67] = t;
		$[68] = t25;
	} else t25 = $[68];
	params?.inquiryTreeId;
	let t26;
	if ($[69] !== t25) {
		t26 = t25();
		$[69] = t25;
		$[70] = t26;
	} else t26 = $[70];
	const actionList = t26;
	let t27;
	if ($[71] !== entityName || $[72] !== udpObjectInfoEntity?.unityBaseSearchMethod) {
		t27 = () => {
			const executeSearchForEntityUdpObjectInfo = async (apiMethodId, sanitizedEntityName_0) => {
				const response_3 = await executeQueryAdHoc({ data: getSearchObject([{
					searchField: "SanitizedName",
					searchOperator: "=",
					searchValue: sanitizedEntityName_0
				}], 1, 50, false) }, apiMethodId);
				if (response_3.status === 200) {
					const data_9 = response_3?.data?.pageList[0];
					setEntityUdpObjectInfo(data_9);
				}
			};
			if (udpObjectInfoEntity?.unityBaseSearchMethod && entityName) executeSearchForEntityUdpObjectInfo(udpObjectInfoEntity?.unityBaseSearchMethod?.apiMethodId, getSanitizedName(entityName));
		};
		$[71] = entityName;
		$[72] = udpObjectInfoEntity?.unityBaseSearchMethod;
		$[73] = t27;
	} else t27 = $[73];
	let t28;
	if ($[74] !== entityName || $[75] !== udpObjectInfoEntity) {
		t28 = [udpObjectInfoEntity, entityName];
		$[74] = entityName;
		$[75] = udpObjectInfoEntity;
		$[76] = t28;
	} else t28 = $[76];
	useEffect(t27, t28);
	let t29;
	let t30;
	if ($[77] !== entityAttributes || $[78] !== getFKData || $[79] !== udpFieldSearchApiId) {
		t29 = () => {
			const setFrKeyData = async () => {
				await getFKData();
			};
			if (entityAttributes && udpFieldSearchApiId !== null) setFrKeyData();
		};
		t30 = [
			entityAttributes,
			getFKData,
			udpFieldSearchApiId
		];
		$[77] = entityAttributes;
		$[78] = getFKData;
		$[79] = udpFieldSearchApiId;
		$[80] = t29;
		$[81] = t30;
	} else {
		t29 = $[80];
		t30 = $[81];
	}
	useEffect(t29, t30);
	let t31;
	let t32;
	if ($[82] !== promotedMethodEntities) {
		t31 = () => {
			if (promotedMethodEntities) {
				setSelectedEntity(promotedMethodEntities);
				setEntityName(promotedMethodEntities?.entityName);
			}
		};
		t32 = [promotedMethodEntities];
		$[82] = promotedMethodEntities;
		$[83] = t31;
		$[84] = t32;
	} else {
		t31 = $[83];
		t32 = $[84];
	}
	useEffect(t31, t32);
	let t33;
	let t34;
	if ($[85] !== udpObjectFieldInfo) {
		t33 = () => {
			if (udpObjectFieldInfo) if (udpObjectFieldInfo?.unityBaseSearchMethod?.apiMethodId) setUdpFieldSearchApiId(udpObjectFieldInfo?.unityBaseSearchMethod?.apiMethodId);
			else {
				setUdpFieldSearchApiId("");
				const udpFieldWarning = {
					id: v4(),
					message: "UdpObjectFieldInfo method needs to be promoted"
				};
				setAlertWarnings((prevState) => [...prevState, udpFieldWarning]);
			}
		};
		t34 = [udpObjectFieldInfo];
		$[85] = udpObjectFieldInfo;
		$[86] = t33;
		$[87] = t34;
	} else {
		t33 = $[86];
		t34 = $[87];
	}
	useEffect(t33, t34);
	let t35;
	if ($[88] !== entityName || $[89] !== getMetaDataForUdpField || $[90] !== udpFieldSearchApiId) {
		t35 = () => {
			const setFieldInfos = async () => {
				setUdpFieldInfos(await getMetaDataForUdpField(entityName));
			};
			if (udpFieldSearchApiId) setFieldInfos();
		};
		$[88] = entityName;
		$[89] = getMetaDataForUdpField;
		$[90] = udpFieldSearchApiId;
		$[91] = t35;
	} else t35 = $[91];
	let t36;
	if ($[92] !== entityName || $[93] !== getMetaDataForUdpField || $[94] !== udpFieldSearchApiId || $[95] !== udpObjectFieldInfo) {
		t36 = [
			udpObjectFieldInfo,
			getMetaDataForUdpField,
			udpFieldSearchApiId,
			entityName
		];
		$[92] = entityName;
		$[93] = getMetaDataForUdpField;
		$[94] = udpFieldSearchApiId;
		$[95] = udpObjectFieldInfo;
		$[96] = t36;
	} else t36 = $[96];
	useEffect(t35, t36);
	let t37;
	if ($[97] !== location.state?.from) {
		t37 = () => {
			if (location.state?.from === "tablebrowser") setShowBackToTableBrowser(true);
		};
		$[97] = location.state?.from;
		$[98] = t37;
	} else t37 = $[98];
	let t38;
	if ($[99] !== location.state) {
		t38 = [location.state];
		$[99] = location.state;
		$[100] = t38;
	} else t38 = $[100];
	useEffect(t37, t38);
	let t39;
	if ($[101] === Symbol.for("react.memo_cache_sentinel")) {
		t39 = (api) => {
			gridApiRef.current = api;
		};
		$[101] = t39;
	} else t39 = $[101];
	const handleGridApiCallback = t39;
	const fieldName = udpFieldInfos?.find(_temp5)?.name;
	const primaryKeyFieldName = fieldName?.[0]?.toLowerCase() + fieldName?.slice(1);
	let t40;
	if ($[102] !== alertWarnings || $[103] !== removeWarning) {
		let t41;
		if ($[105] !== removeWarning) {
			t41 = (warning_0) => /* @__PURE__ */ React.createElement(Alert, {
				key: warning_0.id,
				onClose: () => removeWarning(warning_0.id),
				severity: "warning"
			}, warning_0.message || "");
			$[105] = removeWarning;
			$[106] = t41;
		} else t41 = $[106];
		t40 = alertWarnings.map(t41);
		$[102] = alertWarnings;
		$[103] = removeWarning;
		$[104] = t40;
	} else t40 = $[104];
	let t41;
	if ($[107] === Symbol.for("react.memo_cache_sentinel")) {
		t41 = () => openModal("create");
		$[107] = t41;
	} else t41 = $[107];
	let t42;
	if ($[108] !== currentApiCatalogId || $[109] !== entityName) {
		t42 = {
			currentApiCatalogId,
			entityName
		};
		$[108] = currentApiCatalogId;
		$[109] = entityName;
		$[110] = t42;
	} else t42 = $[110];
	const t43 = entityUdpObjectInfo?.properties?.displayName;
	let t44;
	if ($[111] !== actionList || $[112] !== entityAttributes || $[113] !== foreignKeyData || $[114] !== searchFilterElements || $[115] !== selectedEntity || $[116] !== showBackToTableBrowser || $[117] !== t42 || $[118] !== t43) {
		t44 = /* @__PURE__ */ React.createElement(CrudBrowserContainer, {
			actionList,
			onCreate: t41,
			entityAttributes,
			foreignKeyData,
			promotedEntity: selectedEntity,
			apiMethod: t42,
			filterElements: searchFilterElements,
			setAlertWarnings,
			gridApiCallback: handleGridApiCallback,
			showBackToTableBrowser,
			gridTitle: t43
		});
		$[111] = actionList;
		$[112] = entityAttributes;
		$[113] = foreignKeyData;
		$[114] = searchFilterElements;
		$[115] = selectedEntity;
		$[116] = showBackToTableBrowser;
		$[117] = t42;
		$[118] = t43;
		$[119] = t44;
	} else t44 = $[119];
	const t45 = modalConfig.type === "create" || modalConfig.type === "edit";
	let t46;
	if ($[120] !== entityName || $[121] !== entityUdpObjectInfo?.properties?.displayName || $[122] !== modalConfig.type) {
		t46 = modalConfig.type === "create" ? `Add New ${entityUdpObjectInfo?.properties?.displayName || getSanitizedName(entityName)}` : `Edit ${entityUdpObjectInfo?.properties?.displayName || getSanitizedName(entityName)}`;
		$[120] = entityName;
		$[121] = entityUdpObjectInfo?.properties?.displayName;
		$[122] = modalConfig.type;
		$[123] = t46;
	} else t46 = $[123];
	let t47;
	if ($[124] !== entityAttributes || $[125] !== entityName || $[126] !== foreignKeyData || $[127] !== handleOnCreate || $[128] !== handleOnUpdate || $[129] !== modalConfig.data || $[130] !== modalConfig.type || $[131] !== selectedEntity?.unityBaseCreateMethod?.pageId || $[132] !== selectedEntity?.unityBaseUpdateMethod?.pageId || $[133] !== udpFieldInfos) {
		t47 = (modalConfig.type === "create" || modalConfig.type === "edit") && /* @__PURE__ */ React.createElement(CrudTableSidePanel, {
			entityAttributes,
			udpFieldInfos,
			foreignKeyData,
			closeSideSheet: closeModal,
			isNewEntry: modalConfig.type === "create",
			entityName,
			onCreate: modalConfig.type === "create" ? handleOnCreate : void 0,
			onUpdate: modalConfig.type === "edit" ? handleOnUpdate : void 0,
			crudTableEditionData: modalConfig.type === "edit" ? modalConfig.data : null,
			pageId: modalConfig.type === "edit" ? selectedEntity?.unityBaseUpdateMethod?.pageId : selectedEntity?.unityBaseCreateMethod?.pageId
		});
		$[124] = entityAttributes;
		$[125] = entityName;
		$[126] = foreignKeyData;
		$[127] = handleOnCreate;
		$[128] = handleOnUpdate;
		$[129] = modalConfig.data;
		$[130] = modalConfig.type;
		$[131] = selectedEntity?.unityBaseCreateMethod?.pageId;
		$[132] = selectedEntity?.unityBaseUpdateMethod?.pageId;
		$[133] = udpFieldInfos;
		$[134] = t47;
	} else t47 = $[134];
	let t48;
	if ($[135] !== t45 || $[136] !== t46 || $[137] !== t47) {
		t48 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: t45,
			onClose: closeModal,
			title: t46,
			width: 600
		}, t47);
		$[135] = t45;
		$[136] = t46;
		$[137] = t47;
		$[138] = t48;
	} else t48 = $[138];
	const t49 = modalConfig.type === "inquiry";
	const t50 = params?.inquiryTreeId;
	const t51 = modalConfig?.data?.[primaryKeyFieldName];
	let t52;
	if ($[139] !== t50 || $[140] !== t51) {
		t52 = /* @__PURE__ */ React.createElement(Inquiry, {
			treeId: t50,
			autoCollapseNav: true,
			searchValue: t51
		});
		$[139] = t50;
		$[140] = t51;
		$[141] = t52;
	} else t52 = $[141];
	let t53;
	if ($[142] !== t49 || $[143] !== t52) {
		t53 = /* @__PURE__ */ React.createElement(SideSheet, {
			open: t49,
			onClose: closeModal,
			title: "Detailed view",
			width: "90%"
		}, t52);
		$[142] = t49;
		$[143] = t52;
		$[144] = t53;
	} else t53 = $[144];
	const t54 = modalConfig.type === "delete";
	let t55;
	if ($[145] !== t) {
		t55 = t("Delete");
		$[145] = t;
		$[146] = t55;
	} else t55 = $[146];
	let t56;
	if ($[147] !== t) {
		t56 = t("Are you sure you want to delete this row?");
		$[147] = t;
		$[148] = t56;
	} else t56 = $[148];
	let t57;
	if ($[149] !== t) {
		t57 = t("Cancel");
		$[149] = t;
		$[150] = t57;
	} else t57 = $[150];
	let t58;
	if ($[151] !== handleOnDelete || $[152] !== modalConfig.data) {
		t58 = () => handleOnDelete(modalConfig.data);
		$[151] = handleOnDelete;
		$[152] = modalConfig.data;
		$[153] = t58;
	} else t58 = $[153];
	let t59;
	if ($[154] !== t) {
		t59 = t("Confirm");
		$[154] = t;
		$[155] = t59;
	} else t59 = $[155];
	let t60;
	if ($[156] !== t54 || $[157] !== t55 || $[158] !== t56 || $[159] !== t57 || $[160] !== t58 || $[161] !== t59) {
		t60 = /* @__PURE__ */ React.createElement(FluentDialog, {
			open: t54,
			handleClose: closeModal,
			title: t55,
			message: t56,
			actionOne: closeModal,
			labelOne: t57,
			actionTwo: t58,
			labelTwo: t59
		});
		$[156] = t54;
		$[157] = t55;
		$[158] = t56;
		$[159] = t57;
		$[160] = t58;
		$[161] = t59;
		$[162] = t60;
	} else t60 = $[162];
	let t61;
	if ($[163] !== t40 || $[164] !== t44 || $[165] !== t48 || $[166] !== t53 || $[167] !== t60) {
		t61 = /* @__PURE__ */ React.createElement(React.Fragment, null, t40, t44, t48, t53, t60);
		$[163] = t40;
		$[164] = t44;
		$[165] = t48;
		$[166] = t53;
		$[167] = t60;
		$[168] = t61;
	} else t61 = $[168];
	return t61;
};
function _temp(attr) {
	return [attr.name.toLowerCase(), attr];
}
function _temp2(f) {
	return f.name.toLowerCase();
}
function _temp3(fi) {
	return fi.properties?.maintainenceConfig?.associationLabel === "true";
}
function _temp4(obj, k) {
	if (!obj) return null;
	let val = obj[k] ?? null;
	if (!val) {
		const key = Object.keys(obj).find((objKey) => objKey.toLowerCase().includes(k));
		if (key) val = obj[key];
	}
	return val;
}
function _temp5(field_0) {
	return field_0.isPrimaryKey;
}
//#endregion
export { UdpMaintenanceEnginePage as default };

//# sourceMappingURL=UdpMaintenanceEnginePage.mjs.map