import { ConfigService } from "../../configService/index.mjs";
import { UdpEnums } from "../../enums/unitySystemEnums.mjs";
import { useUser } from "../../utilities/auth/useUser.mjs";
import { LayoutUnit } from "../../layout/LayoutUnit.mjs";
import { useAxiosGet } from "../../utilities/useAxiosGet.mjs";
import { PageContainer } from "../../page/PageContainer/PageContainer.mjs";
import { CrudForm } from "../../UI/forms/CrudForm.mjs";
import { UDP_LOOKUP_ENTITY_ATTRIBUTES_TO_HIDE } from "../entityAttributeActions.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Divider, makeStyles } from "@material-ui/core";
import PropTypes from "prop-types";
import { Skeleton } from "@material-ui/lab";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
//#region src/maintenanceEngine/crudBrowser/CrudTableSidePanel.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	divider: { marginTop: theme.spacing(2) }
}));
const FIELD_NUMBER = 10;
const CrudTableSidePanel = (props) => {
	const $ = c(50);
	const { entityAttributes, udpFieldInfos, foreignKeyData, crudTableEditionData, closeSideSheet, onCreate, onUpdate, pageId, setSideSheetWidth, setSideSheetButtonLabel, setSideSheetOnSubmit, setSideSheetProps, isNewEntry, entityData, entityName } = props;
	const user = useUser();
	const classes = useStyles();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = {};
		$[0] = t0;
	} else t0 = $[0];
	const [t1] = useAxiosGet(ConfigService.tenantV1ApiUrl, `page/${pageId}`, t0, !!!pageId, false);
	const { data: page, loading: loadingPage } = t1;
	let skeletonArr;
	if ($[1] !== classes) {
		skeletonArr = [];
		for (let i = 0; i < FIELD_NUMBER; i++) skeletonArr.push(/* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Skeleton, {
			key: i,
			variant: "rect",
			className: classes.skeleton
		}), /* @__PURE__ */ React.createElement(LayoutUnit, { unit: "xxs" })));
		$[1] = classes;
		$[2] = skeletonArr;
	} else skeletonArr = $[2];
	const skeleton = skeletonArr;
	let t2;
	bb0: {
		if (entityName?.toLowerCase().includes(UdpEnums.Udp_Lookup.toLowerCase())) {
			let t3;
			if ($[3] !== entityAttributes) {
				t3 = entityAttributes?.filter(_temp);
				$[3] = entityAttributes;
				$[4] = t3;
			} else t3 = $[4];
			t2 = t3;
			break bb0;
		}
		let t3;
		if ($[5] !== entityAttributes) {
			t3 = entityAttributes?.filter(_temp2);
			$[5] = entityAttributes;
			$[6] = t3;
		} else t3 = $[6];
		t2 = t3;
	}
	const filteredEntityAttributes = t2;
	let t3;
	if (page) {
		const t4 = page?.pageId;
		let t5;
		if ($[7] !== closeSideSheet || $[8] !== crudTableEditionData || $[9] !== entityData || $[10] !== entityName || $[11] !== filteredEntityAttributes || $[12] !== foreignKeyData || $[13] !== isNewEntry || $[14] !== onCreate || $[15] !== onUpdate || $[16] !== setSideSheetButtonLabel || $[17] !== setSideSheetOnSubmit || $[18] !== setSideSheetProps || $[19] !== setSideSheetWidth || $[20] !== t4 || $[21] !== udpFieldInfos) {
			t5 = {
				pageId: t4,
				entityAttributes: filteredEntityAttributes,
				entityData,
				entityName,
				foreignKeyData,
				isNewEntry,
				udpFieldInfos,
				nodeObj: crudTableEditionData,
				setSideSheetWidth,
				setSideSheetButtonLabel,
				setSideSheetOnSubmit,
				closeSideSheet,
				setSideSheetProps,
				onCreate,
				onUpdate
			};
			$[7] = closeSideSheet;
			$[8] = crudTableEditionData;
			$[9] = entityData;
			$[10] = entityName;
			$[11] = filteredEntityAttributes;
			$[12] = foreignKeyData;
			$[13] = isNewEntry;
			$[14] = onCreate;
			$[15] = onUpdate;
			$[16] = setSideSheetButtonLabel;
			$[17] = setSideSheetOnSubmit;
			$[18] = setSideSheetProps;
			$[19] = setSideSheetWidth;
			$[20] = t4;
			$[21] = udpFieldInfos;
			$[22] = t5;
		} else t5 = $[22];
		let t6;
		if ($[23] !== page || $[24] !== pageId || $[25] !== t5 || $[26] !== user) {
			t6 = /* @__PURE__ */ React.createElement(DndProvider, { backend: HTML5Backend }, /* @__PURE__ */ React.createElement(PageContainer, {
				user,
				key: pageId,
				pageData: page,
				widgetParams: t5,
				disableMargins: true
			}));
			$[23] = page;
			$[24] = pageId;
			$[25] = t5;
			$[26] = user;
			$[27] = t6;
		} else t6 = $[27];
		t3 = t6;
	} else {
		let t4;
		if ($[28] !== closeSideSheet || $[29] !== crudTableEditionData || $[30] !== entityData || $[31] !== entityName || $[32] !== filteredEntityAttributes || $[33] !== foreignKeyData || $[34] !== isNewEntry || $[35] !== onCreate || $[36] !== onUpdate || $[37] !== udpFieldInfos) {
			t4 = /* @__PURE__ */ React.createElement(CrudForm, {
				entityAttributes: filteredEntityAttributes,
				udpFieldInfos,
				foreignKeyData,
				crudTableEditionData,
				closeSideSheet,
				onCreate,
				onUpdate,
				isNewEntry,
				entityData,
				entityName
			});
			$[28] = closeSideSheet;
			$[29] = crudTableEditionData;
			$[30] = entityData;
			$[31] = entityName;
			$[32] = filteredEntityAttributes;
			$[33] = foreignKeyData;
			$[34] = isNewEntry;
			$[35] = onCreate;
			$[36] = onUpdate;
			$[37] = udpFieldInfos;
			$[38] = t4;
		} else t4 = $[38];
		let t5;
		if ($[39] === Symbol.for("react.memo_cache_sentinel")) {
			t5 = /* @__PURE__ */ React.createElement(Divider, null);
			$[39] = t5;
		} else t5 = $[39];
		let t6;
		if ($[40] !== classes.divider) {
			t6 = /* @__PURE__ */ React.createElement("div", { className: classes.divider }, t5);
			$[40] = classes.divider;
			$[41] = t6;
		} else t6 = $[41];
		let t7;
		if ($[42] !== t4 || $[43] !== t6) {
			t7 = /* @__PURE__ */ React.createElement(React.Fragment, null, t4, t6);
			$[42] = t4;
			$[43] = t6;
			$[44] = t7;
		} else t7 = $[44];
		t3 = t7;
	}
	const sideSheetContent = t3;
	let t4;
	if ($[45] !== classes || $[46] !== loadingPage || $[47] !== sideSheetContent || $[48] !== skeleton) {
		t4 = /* @__PURE__ */ React.createElement("div", null, loadingPage ? /* @__PURE__ */ React.createElement(React.Fragment, null, skeleton.map(_temp3), /* @__PURE__ */ React.createElement(LayoutUnit, { unit: "md" }), /* @__PURE__ */ React.createElement(Skeleton, {
			variant: "rect",
			className: classes.skeletonButton
		})) : sideSheetContent);
		$[45] = classes;
		$[46] = loadingPage;
		$[47] = sideSheetContent;
		$[48] = skeleton;
		$[49] = t4;
	} else t4 = $[49];
	return t4;
};
CrudTableSidePanel.propTypes = {
	entityAttributes: PropTypes.array,
	foreignKeyData: PropTypes.array,
	crudTableEditionData: PropTypes.array,
	closeSideSheet: PropTypes.func,
	onCreate: PropTypes.func,
	onUpdate: PropTypes.func
};
function _temp(attr) {
	return !UDP_LOOKUP_ENTITY_ATTRIBUTES_TO_HIDE.includes(attr.name);
}
function _temp2(attr_0) {
	return attr_0.name !== "businessObjectKey" && attr_0.name !== "ignoreLoggingTransactions";
}
function _temp3(sk) {
	return sk;
}
//#endregion
export { CrudTableSidePanel };

//# sourceMappingURL=CrudTableSidePanel.mjs.map