import { getPathObject, getPrimaryKeyValues } from "../../utilities/maintenanceEngine/CrudBrowserUtilities.mjs";
import { ConfigService } from "../../configService/index.mjs";
import { toLowerFirstChar, toTitleCase } from "../../utilities/input/StringUtilities.mjs";
import { useAxiosGet } from "../../utilities/useAxiosGet.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { Typography, makeStyles } from "@material-ui/core";
import { useSnackbar } from "notistack";
import { useTranslation } from "react-i18next";
//#region src/actions/sidebar/EntitySideBarContent.jsx
const useStyles = makeStyles((theme) => ({ dataRoot: { marginTop: theme.spacing(2) } }));
const EntitySideBarContent = (props) => {
	const $ = c(29);
	const { action, executeAction, entityAttributes, selectedNodeObj, apiCatalogId, entityName, sidebarEntity } = props;
	const classes = useStyles(props);
	const [data, setData] = useState(null);
	const { enqueueSnackbar } = useSnackbar();
	const { t } = useTranslation();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = {};
		$[0] = t0;
	} else t0 = $[0];
	const [t1] = useAxiosGet(ConfigService.integrationV1ApiUrl, `apicatalog/${apiCatalogId}/promotedMethodEntities/${entityName}/product/${ConfigService.config.UNITY_PRODUCT_ID}`, t0, !!!apiCatalogId || !!!entityName || !!sidebarEntity, false);
	const { data: selectedEntity } = t1;
	const entity = selectedEntity || sidebarEntity;
	let t2;
	if ($[1] !== enqueueSnackbar || $[2] !== t) {
		t2 = () => {
			enqueueSnackbar(t("Invalid action value."), {
				variant: "error",
				anchorOrigin: {
					vertical: "top",
					horizontal: "center"
				}
			});
		};
		$[1] = enqueueSnackbar;
		$[2] = t;
		$[3] = t2;
	} else t2 = $[3];
	const showError = t2;
	let t3;
	if ($[4] !== action || $[5] !== entity || $[6] !== executeAction || $[7] !== showError) {
		t3 = async (data_0) => {
			if (entity?.unityBaseGetMethod && action?.value) if (entity.unityBaseGetMethod.apiMethodId === action.value) return await executeAction(data_0, action.value);
			else showError();
		};
		$[4] = action;
		$[5] = entity;
		$[6] = executeAction;
		$[7] = showError;
		$[8] = t3;
	} else t3 = $[8];
	const onGet = t3;
	let t4;
	if ($[9] !== enqueueSnackbar || $[10] !== entity?.unityBaseGetMethod || $[11] !== entityAttributes || $[12] !== onGet) {
		t4 = async (value) => {
			if (entity?.unityBaseGetMethod) {
				const primaryKeyValues = getPrimaryKeyValues(entityAttributes, value);
				const response = await onGet({ data: { ...getPathObject(entity?.unityBaseGetMethod?.pathParameters, primaryKeyValues) } }).catch((res) => {
					enqueueSnackbar(res.message, {
						variant: "error",
						anchorOrigin: {
							vertical: "top",
							horizontal: "center"
						}
					});
				});
				if (response?.status === 200) setData(response.data);
			}
		};
		$[9] = enqueueSnackbar;
		$[10] = entity?.unityBaseGetMethod;
		$[11] = entityAttributes;
		$[12] = onGet;
		$[13] = t4;
	} else t4 = $[13];
	const handleOnGet = t4;
	let t5;
	if ($[14] !== classes || $[15] !== data) {
		t5 = (schemaAttribute) => {
			if (!data || schemaAttribute?.extendedProperties?.childEntity) return null;
			return /* @__PURE__ */ React.createElement("div", { className: classes.dataRoot }, /* @__PURE__ */ React.createElement(Typography, {
				variant: "subtitle2",
				style: { marginTop: 8 }
			}, toTitleCase(schemaAttribute?.name)), /* @__PURE__ */ React.createElement(Typography, null, data[toLowerFirstChar(schemaAttribute.name)]));
		};
		$[14] = classes;
		$[15] = data;
		$[16] = t5;
	} else t5 = $[16];
	const renderData = t5;
	let t6;
	if ($[17] !== entityAttributes || $[18] !== renderData) {
		t6 = entityAttributes?.map((schemaAttribute_0, index) => !schemaAttribute_0?.extendedProperties?.identifier && /* @__PURE__ */ React.createElement(React.Fragment, { key: `${schemaAttribute_0.name}-${index}` }, renderData(schemaAttribute_0)));
		$[17] = entityAttributes;
		$[18] = renderData;
		$[19] = t6;
	} else t6 = $[19];
	let t7;
	if ($[20] !== t6) {
		t7 = /* @__PURE__ */ React.createElement("div", null, t6);
		$[20] = t6;
		$[21] = t7;
	} else t7 = $[21];
	const cardContent = t7;
	let t8;
	let t9;
	if ($[22] !== data || $[23] !== handleOnGet || $[24] !== selectedNodeObj) {
		t8 = () => {
			if (!data) handleOnGet(selectedNodeObj);
		};
		t9 = [
			handleOnGet,
			selectedNodeObj,
			data
		];
		$[22] = data;
		$[23] = handleOnGet;
		$[24] = selectedNodeObj;
		$[25] = t8;
		$[26] = t9;
	} else {
		t8 = $[25];
		t9 = $[26];
	}
	useEffect(t8, t9);
	let t10;
	if ($[27] !== cardContent) {
		t10 = /* @__PURE__ */ React.createElement("div", null, cardContent);
		$[27] = cardContent;
		$[28] = t10;
	} else t10 = $[28];
	return t10;
};
//#endregion
export { EntitySideBarContent };

//# sourceMappingURL=EntitySideBarContent.mjs.map