import { SubHeaderAction } from "../../utilities/utilityBar/SubHeaderAction.mjs";
import { AmbientAlert } from "../../UI/feedback/AmbientAlert.mjs";
import { ensureOutlookStatusLoaded, getOutlookStatus, subscribeOutlookStatus } from "./outlookIntegrationStatus.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
//#region src/integrations/outlook/OutlookIntegrationBanner.jsx
/**
* Global warning banner shown when Outlook integration is disconnected.
* Defaults to enabled so apps get the disconnected warning behavior out of the box.
*/
const OutlookIntegrationBanner = (t0) => {
	const $ = c(24);
	const { onConfigure, enabled: t1, hideOnPaths: t2, title, message, actionLabel, dismissible: t3, renderInSubHeaderAction: t4 } = t0;
	const enabled = t1 === void 0 ? true : t1;
	const hideOnPaths = t2 === void 0 ? [] : t2;
	const dismissible = t3 === void 0 ? true : t3;
	const renderInSubHeaderAction = t4 === void 0 ? false : t4;
	const { t } = useTranslation();
	const location = useLocation();
	const [status, setStatus] = useState(_temp);
	const [show, setShow] = useState(true);
	location?.pathname;
	const pathname = location?.pathname || "";
	const shouldHideForPath = hideOnPaths.some((path) => path && pathname.includes(path));
	let t5;
	let t6;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t5 = () => {
			const unsub = subscribeOutlookStatus((next) => {
				setStatus(next);
				if (next.connected) setShow(false);
				else setShow(true);
			});
			ensureOutlookStatusLoaded().catch(_temp2);
			return () => unsub();
		};
		t6 = [];
		$[0] = t5;
		$[1] = t6;
	} else {
		t5 = $[0];
		t6 = $[1];
	}
	useEffect(t5, t6);
	if (!enabled || shouldHideForPath || !show || !status.loaded || status.connected) return null;
	let t7;
	if ($[2] !== t || $[3] !== title) {
		t7 = title || t("outlook.banner.title", "Outlook Integration Required");
		$[2] = t;
		$[3] = title;
		$[4] = t7;
	} else t7 = $[4];
	let t8;
	if ($[5] !== message || $[6] !== status.error || $[7] !== t) {
		t8 = status.error || message || t("outlook.banner.message", "Setup Outlook integration to enable email functionality.");
		$[5] = message;
		$[6] = status.error;
		$[7] = t;
		$[8] = t8;
	} else t8 = $[8];
	const t9 = status.error ? "error" : "warning";
	const t10 = typeof onConfigure === "function";
	let t11;
	if ($[9] !== actionLabel || $[10] !== t) {
		t11 = actionLabel || t("outlook.banner.action", "Setup Outlook integration");
		$[9] = actionLabel;
		$[10] = t;
		$[11] = t11;
	} else t11 = $[11];
	let t12;
	if ($[12] !== dismissible) {
		t12 = dismissible ? () => setShow(false) : void 0;
		$[12] = dismissible;
		$[13] = t12;
	} else t12 = $[13];
	let t13;
	if ($[14] !== onConfigure || $[15] !== t10 || $[16] !== t11 || $[17] !== t12 || $[18] !== t7 || $[19] !== t8 || $[20] !== t9) {
		t13 = /* @__PURE__ */ React.createElement(AmbientAlert, {
			alertTitle: t7,
			alertMessage: t8,
			showAlert: true,
			alertSeverity: t9,
			alertAction: t10,
			alertActionButton: t11,
			alertHandleAction: onConfigure,
			closeAlert: t12
		});
		$[14] = onConfigure;
		$[15] = t10;
		$[16] = t11;
		$[17] = t12;
		$[18] = t7;
		$[19] = t8;
		$[20] = t9;
		$[21] = t13;
	} else t13 = $[21];
	const alert = t13;
	if (renderInSubHeaderAction) {
		let t14;
		if ($[22] !== alert) {
			t14 = /* @__PURE__ */ React.createElement(SubHeaderAction, null, alert);
			$[22] = alert;
			$[23] = t14;
		} else t14 = $[23];
		return t14;
	}
	return alert;
};
function _temp() {
	return getOutlookStatus();
}
function _temp2() {}
//#endregion
export { OutlookIntegrationBanner as default };

//# sourceMappingURL=OutlookIntegrationBanner.mjs.map