import { ConfigService } from "../configService/index.mjs";
import { useAxiosGet } from "../utilities/useAxiosGet.mjs";
import { useSetLocationState } from "../hooks/useSetLocationState.mjs";
import LoadingOverlay from "../UI/loading/LoadingOverlay.mjs";
import { useIsUnityAuthenticated } from "../utilities/auth/useIsUnityAuthenticated.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect } from "react";
import { useHistory } from "react-router-dom";
import { useTranslation } from "react-i18next";
import Alert from "@material-ui/lab/Alert";
import { Report } from "powerbi-report-component";
//#region src/reports/PowerBIReport.jsx
const PowerBIReport = (props) => {
	const $ = c(22);
	const userIsAuthenticated = useIsUnityAuthenticated();
	const { id, reportParameters } = props;
	const i18n = useTranslation().t;
	const history = useHistory();
	const setLocationState = useSetLocationState();
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = { height: "calc(100vh - 51px)" };
		$[0] = t0;
	} else t0 = $[0];
	const reportStyle = t0;
	let t1;
	if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
		t1 = {};
		$[1] = t1;
	} else t1 = $[1];
	const [t2] = useAxiosGet(ConfigService.productV1ApiUrl, `UdpPBIReport/Access/${id}`, t1, !!!userIsAuthenticated || !!!id);
	const { data: reportData, loading, error } = t2;
	reportData?.embedUrl;
	let t3;
	if (reportData?.embedUrl) if (reportParameters) {
		let paramsString;
		if ($[2] !== reportParameters) {
			paramsString = "";
			Object.keys(reportParameters).forEach((key) => {
				const paramString = `&rp:${key}=${reportParameters[key]}`;
				paramsString = paramsString + paramString;
			});
			$[2] = reportParameters;
			$[3] = paramsString;
		} else paramsString = $[3];
		t3 = reportData.embedUrl + paramsString;
	} else t3 = reportData.embedUrl;
	else t3 = "";
	const urlWithParameters = t3;
	let t4;
	if ($[4] !== history?.location?.state || $[5] !== i18n || $[6] !== setLocationState) {
		t4 = () => {
			if (!history?.location?.state) setLocationState({ label: i18n("Report") });
		};
		$[4] = history?.location?.state;
		$[5] = i18n;
		$[6] = setLocationState;
		$[7] = t4;
	} else t4 = $[7];
	let t5;
	if ($[8] !== history || $[9] !== i18n || $[10] !== setLocationState) {
		t5 = [
			setLocationState,
			i18n,
			history
		];
		$[8] = history;
		$[9] = i18n;
		$[10] = setLocationState;
		$[11] = t5;
	} else t5 = $[11];
	useEffect(t4, t5);
	if (loading) {
		let t6;
		if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
			t6 = /* @__PURE__ */ React.createElement(LoadingOverlay, null);
			$[12] = t6;
		} else t6 = $[12];
		return t6;
	}
	if (error) {
		let t6;
		if ($[13] !== i18n) {
			t6 = i18n("shared.messages.error");
			$[13] = i18n;
			$[14] = t6;
		} else t6 = $[14];
		let t7;
		if ($[15] !== t6) {
			t7 = /* @__PURE__ */ React.createElement(Alert, {
				severity: "error",
				onClose: _temp
			}, t6);
			$[15] = t6;
			$[16] = t7;
		} else t7 = $[16];
		return t7;
	}
	if (!userIsAuthenticated) return null;
	if (!reportData || !reportData.embedToken || !urlWithParameters || !reportData.reportId) {
		let t6;
		if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
			t6 = /* @__PURE__ */ React.createElement("div", null);
			$[17] = t6;
		} else t6 = $[17];
		return t6;
	}
	let t6;
	if ($[18] !== reportData.embedToken || $[19] !== reportData.reportId || $[20] !== urlWithParameters) {
		t6 = /* @__PURE__ */ React.createElement(Report, {
			key: reportData.reportId,
			embedType: "report",
			tokenType: "Embed",
			accessToken: reportData.embedToken,
			embedUrl: urlWithParameters,
			embedId: reportData.reportId,
			permissions: "All",
			style: reportStyle
		});
		$[18] = reportData.embedToken;
		$[19] = reportData.reportId;
		$[20] = urlWithParameters;
		$[21] = t6;
	} else t6 = $[21];
	return t6;
};
function _temp() {}
//#endregion
export { PowerBIReport };

//# sourceMappingURL=PowerBIReport.mjs.map