import { ConfigService } from "../../../configService/index.mjs";
import { SeverityTypeEnums } from "../../../enums/unitySystemEnums.mjs";
import { useActions } from "../../../hooks/useActions.mjs";
import { useAxiosGet } from "../../../utilities/useAxiosGet.mjs";
import { AggregateChip } from "../AggregateChip.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { CircularProgress } from "@material-ui/core";
import PropTypes from "prop-types";
//#region src/UI/utilityDisplay/alerts/UdpAlert.jsx
const UdpAlert = (props) => {
	const $ = c(11);
	const { alertId } = props;
	const [status, setStatus] = useState(null);
	const [loading] = useState(false);
	const { triggerAction } = useActions();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = {};
		$[0] = t0;
	} else t0 = $[0];
	const [t1] = useAxiosGet(ConfigService.tenantV1ApiUrl, `alert/${alertId}`, t0, !!!alertId);
	const { data: alert, loading: loadingAlert } = t1;
	let t2;
	bb0: {
		if (!alert || !status) {
			t2 = void 0;
			break bb0;
		}
		let threshold;
		bb1: switch (status) {
			case SeverityTypeEnums.Success:
				threshold = alert[`${SeverityTypeEnums.Success}Threshold`];
				break bb1;
			case SeverityTypeEnums.Error:
				threshold = alert[`${SeverityTypeEnums.Error}Threshold`];
				break bb1;
			case SeverityTypeEnums.Warning:
				threshold = alert[`${SeverityTypeEnums.Warning}Threshold`];
				break bb1;
			case SeverityTypeEnums.Info:
				threshold = alert[`${SeverityTypeEnums.Info}Threshold`];
				break bb1;
			default: threshold = alert[`${SeverityTypeEnums.Default}Threshold`];
		}
		t2 = threshold;
	}
	const threshold_0 = t2;
	let t3;
	if ($[1] !== threshold_0 || $[2] !== triggerAction) {
		t3 = () => {
			if (!threshold_0) return;
			if (threshold_0?.actionId) triggerAction(threshold_0?.actionId);
		};
		$[1] = threshold_0;
		$[2] = triggerAction;
		$[3] = t3;
	} else t3 = $[3];
	const handleAlertAction = t3;
	if (loading || loadingAlert) {
		let t4;
		if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
			t4 = /* @__PURE__ */ React.createElement(CircularProgress, { size: 18 });
			$[4] = t4;
		} else t4 = $[4];
		return t4;
	}
	const t4 = alert?.aggregateThresholdId;
	const t5 = threshold_0?.label;
	const t6 = threshold_0?.actionId || false;
	const t7 = threshold_0?.hide || false;
	let t8;
	if ($[5] !== handleAlertAction || $[6] !== t4 || $[7] !== t5 || $[8] !== t6 || $[9] !== t7) {
		t8 = /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(AggregateChip, {
			aggregateThresholdId: t4,
			label: t5,
			setStatus,
			isActionable: t6,
			onAlertClick: handleAlertAction,
			isAlert: true,
			hideAlert: t7
		}));
		$[5] = handleAlertAction;
		$[6] = t4;
		$[7] = t5;
		$[8] = t6;
		$[9] = t7;
		$[10] = t8;
	} else t8 = $[10];
	return t8;
};
UdpAlert.propTypes = { alertId: PropTypes.oneOf([
	PropTypes.string,
	void 0,
	null
]) };
//#endregion
export { UdpAlert };

//# sourceMappingURL=UdpAlert.mjs.map