import { ConfigService } from "../../../configService/index.mjs";
import { useUser } from "../../../utilities/auth/useUser.mjs";
import { useTenant } from "../../../utilities/tenant/useTenant.mjs";
import UserAvatar from "./UserAvatar.mjs";
import { FluentProfileMenuCard } from "./FluentProfileMenuCard.mjs";
import MenuOpener from "./MenuOpener.mjs";
import { useSingleLogout } from "../../../utilities/auth/useSingleLogout.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Button, IconButton, makeStyles } from "@material-ui/core";
import { Link as Link$1 } from "react-router-dom";
//#region src/shell/ui/profile/UserProfileMenuWrapper.tsx
const useStyles = makeStyles((theme) => ({
	root: {},
	avatar: { background: theme.palette.secondary.main }
}));
const UserProfileMenuWrapper = (t0) => {
	const $ = c(26);
	const { returnTo } = t0;
	const classes = useStyles();
	const user = useUser();
	const singleLogout = useSingleLogout();
	const tenantContext = useTenant();
	const currentTenant = tenantContext?.activeTenant ?? null;
	let t1;
	if ($[0] !== tenantContext?.filteredTenantsList || $[1] !== tenantContext?.tenantsList) {
		t1 = tenantContext?.filteredTenantsList ?? tenantContext?.tenantsList ?? [];
		$[0] = tenantContext?.filteredTenantsList;
		$[1] = tenantContext?.tenantsList;
		$[2] = t1;
	} else t1 = $[2];
	const availableTenants = t1;
	const enforcedTenantId = ConfigService.config.UNITY_TENANT_ID;
	let t2;
	if ($[3] !== availableTenants) {
		t2 = !enforcedTenantId || enforcedTenantId === "" ? availableTenants : availableTenants.filter((option) => option.tenantId === enforcedTenantId);
		$[3] = availableTenants;
		$[4] = t2;
	} else t2 = $[4];
	const profileMenuTenants = t2;
	if (!user) {
		const t3 = returnTo ?? (typeof window !== "undefined" ? window.location.pathname : "/") ?? "/";
		let t4;
		if ($[5] !== t3) {
			t4 = /* @__PURE__ */ React.createElement(Button, {
				component: Link$1,
				to: {
					pathname: "/login",
					state: { returnTo: t3 }
				},
				color: "inherit"
			}, "Sign in");
			$[5] = t3;
			$[6] = t4;
		} else t4 = $[6];
		let t5;
		if ($[7] !== classes.root || $[8] !== t4) {
			t5 = /* @__PURE__ */ React.createElement("div", { className: classes.root }, t4);
			$[7] = classes.root;
			$[8] = t4;
			$[9] = t5;
		} else t5 = $[9];
		return t5;
	}
	const t3 = user?.name;
	const t4 = user?.email;
	let t5;
	if ($[10] !== classes.avatar || $[11] !== t3 || $[12] !== t4) {
		t5 = /* @__PURE__ */ React.createElement(IconButton, null, /* @__PURE__ */ React.createElement(UserAvatar, {
			name: t3,
			email: t4,
			size: "toolbar",
			className: classes.avatar
		}));
		$[10] = classes.avatar;
		$[11] = t3;
		$[12] = t4;
		$[13] = t5;
	} else t5 = $[13];
	let t6;
	if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
		t6 = {
			keepMounted: true,
			getContentAnchorEl: null,
			variant: "menu",
			anchorOrigin: {
				vertical: "bottom",
				horizontal: "right"
			},
			transformOrigin: {
				vertical: "top",
				horizontal: "right"
			}
		};
		$[14] = t6;
	} else t6 = $[14];
	let t7;
	if ($[15] !== currentTenant || $[16] !== profileMenuTenants || $[17] !== singleLogout || $[18] !== user) {
		t7 = /* @__PURE__ */ React.createElement(FluentProfileMenuCard, {
			userTenants: profileMenuTenants,
			currentTenant,
			user,
			logout: singleLogout,
			unityUrl: ConfigService.config.UNITY_URL
		});
		$[15] = currentTenant;
		$[16] = profileMenuTenants;
		$[17] = singleLogout;
		$[18] = user;
		$[19] = t7;
	} else t7 = $[19];
	let t8;
	if ($[20] !== t5 || $[21] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(MenuOpener, {
			name: "udp-user-profile-popover",
			button: t5,
			menuProps: t6
		}, t7);
		$[20] = t5;
		$[21] = t7;
		$[22] = t8;
	} else t8 = $[22];
	let t9;
	if ($[23] !== classes.root || $[24] !== t8) {
		t9 = /* @__PURE__ */ React.createElement("div", { className: classes.root }, t8);
		$[23] = classes.root;
		$[24] = t8;
		$[25] = t9;
	} else t9 = $[25];
	return t9;
};
//#endregion
export { UserProfileMenuWrapper as default };

//# sourceMappingURL=UserProfileMenuWrapper.mjs.map