import { UdpEnums } from "../../../enums/unitySystemEnums.mjs";
import { SideSheet } from "../../../UI/surfaces/SideSheet.mjs";
import { executeQueryWithParameters, getBaseMethod } from "../../utilities/methodUtils.mjs";
import { AmbientCard } from "../../../UI/surfaces/cards/AmbientCard/AmbientCard.mjs";
import { LinearProgress as LinearProgress$1 } from "../../../UI/loading/LinearProgress.mjs";
import { GridRow } from "../../../layout/GridRow.mjs";
import { GridUnit } from "../../../layout/GridUnit.mjs";
import { FluentTextField } from "../../../UI/inputs/textField/FluentTextField.mjs";
import { AuditEventTypeEnums } from "../../../enums/auditEventEnums.mjs";
import { useGetLocalizedUserDateTimeString } from "../../utilities/dateLocalizationHooks.mjs";
import React, { useEffect, useMemo, useState } from "react";
import { Box, makeStyles } from "@material-ui/core";
import { useTranslation } from "react-i18next";
import ReactJsonView from "@microlink/react-json-view";
//#region src/udp/pages/UdpAuditEvents/UdpAuditEventSidesheet.jsx
const useStyles = makeStyles((theme) => ({
	textField: { marginTop: theme.spacing(0) },
	loadingBar: {
		top: theme.spacing(-2),
		marginLeft: theme.spacing(-2),
		marginRight: theme.spacing(-2)
	}
}));
const UdpAuditEventSidesheet = (props) => {
	const { auditEvent, isSideSheetOpen, handleSideSheet, promotedEntities, sheetProps } = props;
	const { t } = useTranslation();
	const classes = useStyles();
	const getLocalizedDateTimeString = useGetLocalizedUserDateTimeString();
	const [auditEventDetail, setAuditEventDetail] = React.useState({});
	const [loading, setLoading] = useState(false);
	const auditEventDetailGetApiMethod = useMemo(() => {
		return getBaseMethod(UdpEnums.Udp_Audit_Event, "unityBaseGetMethod", promotedEntities);
	}, [promotedEntities]);
	const onCloseSideSheet = () => {
		handleSideSheet(false);
	};
	useEffect(() => {
		const getAuditEventDetail = async () => {
			let auditEventDetail_0 = {};
			const data = {};
			try {
				if (auditEventDetailGetApiMethod && auditEvent) {
					setLoading(true);
					data["{id}"] = auditEvent.id;
					const response = await executeQueryWithParameters({ data }, auditEventDetailGetApiMethod.apiMethodId).catch((e) => {
						console.error(e);
						setLoading(false);
					});
					if (response?.status === 200) {
						auditEventDetail_0 = response?.data?.udpAuditEventUdpAuditEventDetail[0];
						setAuditEventDetail(auditEventDetail_0);
					}
				}
			} finally {
				setLoading(false);
			}
		};
		getAuditEventDetail();
	}, [auditEvent, auditEventDetailGetApiMethod]);
	return /* @__PURE__ */ React.createElement(SideSheet, {
		...sheetProps,
		open: isSideSheetOpen,
		onClose: onCloseSideSheet,
		title: t(`Audit Event Details`),
		width: 800,
		color: "primary"
	}, loading ? /* @__PURE__ */ React.createElement(LinearProgress$1, {
		className: classes.loadingBar,
		color: "secondary"
	}) : /* @__PURE__ */ React.createElement(GridRow, null, /* @__PURE__ */ React.createElement(GridUnit, {
		ratio: "1:1",
		width: "100%"
	}, /* @__PURE__ */ React.createElement(AmbientCard, {
		fullWidth: true,
		header: true
	}, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(FluentTextField, {
		className: classes.textField,
		id: "auditEventTypeName",
		label: t("Event Type"),
		value: auditEvent?.auditEventTypeName || "",
		disabled: true
	}), /* @__PURE__ */ React.createElement(FluentTextField, {
		className: classes.textField,
		id: "auditEventUserDisplayName",
		label: t("User"),
		value: auditEvent?.userDisplayName || "",
		disabled: true
	}), /* @__PURE__ */ React.createElement(FluentTextField, {
		className: classes.textField,
		id: "auditEventDomain",
		label: t("Description"),
		value: auditEvent?.domain || "",
		disabled: true
	}), /* @__PURE__ */ React.createElement(FluentTextField, {
		className: classes.textField,
		id: "auditEventCreatedOn",
		label: t("Created On"),
		value: getLocalizedDateTimeString(auditEvent?.createdOn ?? ""),
		disabled: true
	}), /* @__PURE__ */ React.createElement(Box, null, (auditEvent?.typeCode === AuditEventTypeEnums.Update_Domain || auditEvent?.typeCode === AuditEventTypeEnums.Delete_Domain) && /* @__PURE__ */ React.createElement(ReactJsonView, {
		src: auditEventDetail?.oldObj ? JSON.parse(auditEventDetail?.oldObj) : {},
		name: t("Old Details"),
		displayDataTypes: false,
		displayObjectSize: false
	}), (auditEvent?.typeCode === AuditEventTypeEnums.Update_Domain || auditEvent?.typeCode === AuditEventTypeEnums.Create_Domain) && /* @__PURE__ */ React.createElement(ReactJsonView, {
		src: auditEventDetail?.newObj ? JSON.parse(auditEventDetail?.newObj) : {},
		name: t("New Details"),
		displayDataTypes: false,
		displayObjectSize: false
	})))))));
};
//#endregion
export { UdpAuditEventSidesheet as default };

//# sourceMappingURL=UdpAuditEventSidesheet.mjs.map