import { LookupTypeIdEnums, UdpEnums } from "../../enums/unitySystemEnums.mjs";
import { toTitleCase } from "../../utilities/input/StringUtilities.mjs";
import { getSanitizedName } from "../../utilities/entities/entityUtilities.mjs";
import { CrudTableColumnDefs } from "./CrudTableColumnDefs.mjs";
import { SearchMethodUdpGrid } from "../../UI/templates/newGrid/SearchMethodUdpGrid.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect } from "react";
import { useHistory } from "react-router-dom";
import { LookupEntitiesIcon } from "@fluentui/react-icons";
import { useTranslation } from "react-i18next";
import { v4 } from "uuid";
//#region src/maintenanceEngine/crudBrowser/CrudBrowserContainer.jsx
const GRID_ID = "4be3be45-1930-4ab9-b7b7-0c0fa3e30490";
const CrudBrowserContainer = (props) => {
	const $ = c(65);
	let actionList;
	let entityAttributes;
	let filterElements;
	let foreignKeyData;
	let gridApiCallback;
	let gridTitle;
	let onCreate;
	let other;
	let promotedEntity;
	let setAlertWarnings;
	let showBackToTableBrowser;
	if ($[0] !== props) {
		const { actionList: t0, onCreate: t1, entityAttributes: t2, foreignKeyData: t3, promotedEntity: t4, apiMethod, filterElements: t5, setAlertWarnings: t6, gridApiCallback: t7, showBackToTableBrowser: t8, gridTitle: t9, ...t10 } = props;
		actionList = t0;
		onCreate = t1;
		entityAttributes = t2;
		foreignKeyData = t3;
		promotedEntity = t4;
		filterElements = t5;
		setAlertWarnings = t6;
		gridApiCallback = t7;
		showBackToTableBrowser = t8;
		gridTitle = t9;
		other = t10;
		$[0] = props;
		$[1] = actionList;
		$[2] = entityAttributes;
		$[3] = filterElements;
		$[4] = foreignKeyData;
		$[5] = gridApiCallback;
		$[6] = gridTitle;
		$[7] = onCreate;
		$[8] = other;
		$[9] = promotedEntity;
		$[10] = setAlertWarnings;
		$[11] = showBackToTableBrowser;
	} else {
		actionList = $[1];
		entityAttributes = $[2];
		filterElements = $[3];
		foreignKeyData = $[4];
		gridApiCallback = $[5];
		gridTitle = $[6];
		onCreate = $[7];
		other = $[8];
		promotedEntity = $[9];
		setAlertWarnings = $[10];
		showBackToTableBrowser = $[11];
	}
	const { t } = useTranslation();
	const history = useHistory();
	const entityName = promotedEntity?.entityName;
	let t0;
	bb0: {
		if (!entityName) {
			t0 = "";
			break bb0;
		}
		let t1;
		if ($[12] !== entityName) {
			t1 = toTitleCase(getSanitizedName(entityName));
			$[12] = entityName;
			$[13] = t1;
		} else t1 = $[13];
		t0 = t1;
	}
	const commonEntityName = t0;
	let t1;
	if ($[14] !== history) {
		t1 = () => {
			history.push({ pathname: "/tableBrowser" });
		};
		$[14] = history;
		$[15] = t1;
	} else t1 = $[15];
	const handleGoToTableBrowser = t1;
	let t2;
	if (showBackToTableBrowser) {
		let t3;
		if ($[16] !== t) {
			t3 = t("Table Browser");
			$[16] = t;
			$[17] = t3;
		} else t3 = $[17];
		let t4;
		if ($[18] !== handleGoToTableBrowser || $[19] !== t3) {
			t4 = [{
				label: t3,
				iconName: "arrowLeft16",
				onClick: handleGoToTableBrowser
			}];
			$[18] = handleGoToTableBrowser;
			$[19] = t3;
			$[20] = t4;
		} else t4 = $[20];
		t2 = t4;
	} else {
		let t3;
		if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
			t3 = [];
			$[21] = t3;
		} else t3 = $[21];
		t2 = t3;
	}
	const secondaryActionButtons = t2;
	let t3;
	if ($[22] !== t) {
		t3 = t("Open Virtual Table");
		$[22] = t;
		$[23] = t3;
	} else t3 = $[23];
	const t4 = !!!foreignKeyData;
	let t5;
	if ($[24] !== entityName || $[25] !== history || $[26] !== promotedEntity) {
		t5 = (value) => {
			history.push({
				pathname: `/virtual/${value.id}`,
				search: `?entityName=${entityName}`,
				state: {
					value,
					promotedEntity,
					label: value.name
				}
			});
		};
		$[24] = entityName;
		$[25] = history;
		$[26] = promotedEntity;
		$[27] = t5;
	} else t5 = $[27];
	let t6;
	if ($[28] !== t3 || $[29] !== t4 || $[30] !== t5) {
		t6 = [{
			id: 3,
			title: t3,
			icon: LookupEntitiesIcon,
			loading: t4,
			onClick: t5,
			checkDisabled: _temp
		}];
		$[28] = t3;
		$[29] = t4;
		$[30] = t5;
		$[31] = t6;
	} else t6 = $[31];
	const virtualActions = t6;
	let t7;
	bb1: {
		if (!actionList || actionList?.length === 0) {
			t7 = null;
			break bb1;
		}
		if (getSanitizedName(entityName?.toLowerCase()) === UdpEnums.Udp_Lookup.toLowerCase()) {
			let t8;
			if ($[32] !== actionList || $[33] !== virtualActions) {
				t8 = [...actionList, ...virtualActions];
				$[32] = actionList;
				$[33] = virtualActions;
				$[34] = t8;
			} else t8 = $[34];
			t7 = t8;
			break bb1;
		}
		let t8;
		if ($[35] !== actionList) {
			t8 = [...actionList];
			$[35] = actionList;
			$[36] = t8;
		} else t8 = $[36];
		t7 = t8;
	}
	const jointActionList = t7;
	let t8;
	bb2: {
		if (entityAttributes && jointActionList) {
			let t9;
			if ($[37] !== entityAttributes || $[38] !== jointActionList) {
				t9 = CrudTableColumnDefs(entityAttributes, jointActionList);
				$[37] = entityAttributes;
				$[38] = jointActionList;
				$[39] = t9;
			} else t9 = $[39];
			t8 = t9;
			break bb2;
		}
		t8 = void 0;
	}
	const columnDefs = t8;
	let t10;
	let t9;
	if ($[40] !== promotedEntity || $[41] !== setAlertWarnings) {
		t9 = () => {
			if (promotedEntity) {
				if (!promotedEntity?.unityBaseSearchMethod?.apiMethodId) {
					const searchMethodWarning = {
						id: v4(),
						message: `${promotedEntity.entityName}'s Search method needs to be promoted`
					};
					setAlertWarnings && setAlertWarnings((prevState) => [...prevState, searchMethodWarning]);
				}
			}
		};
		t10 = [promotedEntity, setAlertWarnings];
		$[40] = promotedEntity;
		$[41] = setAlertWarnings;
		$[42] = t10;
		$[43] = t9;
	} else {
		t10 = $[42];
		t9 = $[43];
	}
	useEffect(t9, t10);
	let t11;
	if ($[44] !== filterElements || $[45] !== promotedEntity?.unityBaseSearchMethod?.apiMethodId) {
		t11 = () => ({
			apiMethodId: promotedEntity?.unityBaseSearchMethod?.apiMethodId,
			customSearchObject: { filterElements }
		});
		$[44] = filterElements;
		$[45] = promotedEntity?.unityBaseSearchMethod?.apiMethodId;
		$[46] = t11;
	} else t11 = $[46];
	promotedEntity?.unityBaseSearchMethod?.apiMethodId;
	let t12;
	if ($[47] !== t11) {
		t12 = t11();
		$[47] = t11;
		$[48] = t12;
	} else t12 = $[48];
	const searchMethodConfig = t12;
	let t13;
	if ($[49] === Symbol.for("react.memo_cache_sentinel")) {
		t13 = [
			{ name: "openSavedViews" },
			{ name: "agGridSizeColumnsToFit" },
			{ name: "agGridAutoSizeColumns" },
			{ name: "agGridResetColumns" },
			{ name: "agGridHideShowColumns" },
			{ name: "agGridRefreshData" }
		];
		$[49] = t13;
	} else t13 = $[49];
	const gridFunctions = t13;
	const t14 = gridTitle ?? commonEntityName;
	let t15;
	if ($[50] !== onCreate) {
		t15 = {
			label: "Add",
			iconName: "add",
			onClick: onCreate
		};
		$[50] = onCreate;
		$[51] = t15;
	} else t15 = $[51];
	let t16;
	if ($[52] !== secondaryActionButtons || $[53] !== t14 || $[54] !== t15) {
		t16 = {
			title: t14,
			primaryActionButton: t15,
			secondaryActionButtons
		};
		$[52] = secondaryActionButtons;
		$[53] = t14;
		$[54] = t15;
		$[55] = t16;
	} else t16 = $[55];
	let t17;
	if ($[56] !== other) {
		t17 = {
			pagination: true,
			...other
		};
		$[56] = other;
		$[57] = t17;
	} else t17 = $[57];
	let t18;
	if ($[58] !== columnDefs || $[59] !== commonEntityName || $[60] !== gridApiCallback || $[61] !== searchMethodConfig || $[62] !== t16 || $[63] !== t17) {
		t18 = /* @__PURE__ */ React.createElement(SearchMethodUdpGrid, {
			columnDefs,
			searchMethodConfig,
			gridHeaderConfig: t16,
			gridId: GRID_ID,
			entityName: commonEntityName,
			gridOptions: t17,
			gridApiCallback,
			gridFunctions
		});
		$[58] = columnDefs;
		$[59] = commonEntityName;
		$[60] = gridApiCallback;
		$[61] = searchMethodConfig;
		$[62] = t16;
		$[63] = t17;
		$[64] = t18;
	} else t18 = $[64];
	return t18;
};
function _temp(value_0) {
	return value_0.typeId !== LookupTypeIdEnums.Lookup;
}
//#endregion
export { CrudBrowserContainer };

//# sourceMappingURL=CrudBrowserContainer.mjs.map