import { clearStoredTenant, storeTenant } from "../../../utilities/storage/UnitySessionStorage.mjs";
import { clearStoredPath } from "../../../utilities/redirect/LocalRedirectUrlStorage.mjs";
import { TenantSelect } from "../../../utilities/tenant/TenantSelect.mjs";
import UserAvatar from "./UserAvatar.mjs";
import { clearStoredExternalPath } from "../../../utilities/redirect/ExternalRedirectUrlStorage.mjs";
import { useUserActions } from "../../../utilities/auth/users.mjs";
import { c } from "react-compiler-runtime";
import React, { forwardRef } from "react";
import { Button, CardContent, Typography, makeStyles } from "@material-ui/core";
import { useHistory } from "react-router-dom";
import { useTranslation } from "react-i18next";
//#region src/shell/ui/profile/FluentProfileMenuCard.tsx
const useHistory$1 = useHistory;
const useStyles = makeStyles((theme) => ({
	root: {
		"& > *": { margin: theme.spacing(1) },
		"&:last-child": { paddingBottom: theme.spacing(2) }
	},
	cardHeader: {
		display: "flex",
		marginBottom: theme.spacing(3)
	},
	currentTenant: {
		margin: "auto",
		width: "85%",
		marginBottom: theme.spacing(4)
	},
	buttonGroup: {
		display: "flex",
		flexDirection: "row",
		alignItems: "center"
	},
	basicInfoContainer: { marginLeft: theme.spacing(1) },
	basicInfo: { paddingLeft: theme.spacing(1) },
	divider: { height: theme.spacing(3) },
	avatar: { fontSize: 40 }
}));
const FluentProfileMenuCard = forwardRef((props, ref) => {
	const $ = c(44);
	const classes = useStyles();
	const { userTenants, currentTenant, user, logout, unityUrl: t0 } = props;
	const history = useHistory$1();
	let t1;
	if ($[0] !== history) {
		t1 = () => history.push("/");
		$[0] = history;
		$[1] = t1;
	} else t1 = $[1];
	const redirectToHome = t1;
	const { t } = useTranslation();
	const { changeTenant } = useUserActions();
	let t2;
	if ($[2] !== changeTenant || $[3] !== redirectToHome) {
		t2 = (tenant) => {
			storeTenant(tenant.tenantId);
			changeTenant(tenant.tenantId);
			redirectToHome();
		};
		$[2] = changeTenant;
		$[3] = redirectToHome;
		$[4] = t2;
	} else t2 = $[4];
	const handleTenantChange = t2;
	if (!user) return null;
	const t3 = classes.root;
	const t4 = user?.name;
	const t5 = user?.email;
	let t6;
	if ($[5] !== classes.avatar || $[6] !== t4 || $[7] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(UserAvatar, {
			name: t4,
			email: t5,
			size: "large",
			className: classes.avatar
		});
		$[5] = classes.avatar;
		$[6] = t4;
		$[7] = t5;
		$[8] = t6;
	} else t6 = $[8];
	const t7 = user?.name;
	let t8;
	if ($[9] !== classes.basicInfo || $[10] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(Typography, {
			className: classes.basicInfo,
			variant: "subtitle2"
		}, t7);
		$[9] = classes.basicInfo;
		$[10] = t7;
		$[11] = t8;
	} else t8 = $[11];
	const t9 = user?.email;
	let t10;
	if ($[12] !== classes.basicInfo || $[13] !== t9) {
		t10 = /* @__PURE__ */ React.createElement(Typography, {
			className: classes.basicInfo,
			variant: "body2"
		}, t9);
		$[12] = classes.basicInfo;
		$[13] = t9;
		$[14] = t10;
	} else t10 = $[14];
	let t11;
	if ($[15] !== classes.basicInfoContainer || $[16] !== t10 || $[17] !== t8) {
		t11 = /* @__PURE__ */ React.createElement("div", { className: classes.basicInfoContainer }, t8, t10);
		$[15] = classes.basicInfoContainer;
		$[16] = t10;
		$[17] = t8;
		$[18] = t11;
	} else t11 = $[18];
	let t12;
	if ($[19] !== classes.cardHeader || $[20] !== t11 || $[21] !== t6) {
		t12 = /* @__PURE__ */ React.createElement("div", { className: classes.cardHeader }, t6, t11);
		$[19] = classes.cardHeader;
		$[20] = t11;
		$[21] = t6;
		$[22] = t12;
	} else t12 = $[22];
	let t13;
	if ($[23] !== changeTenant || $[24] !== classes.currentTenant || $[25] !== currentTenant || $[26] !== handleTenantChange || $[27] !== t || $[28] !== user || $[29] !== userTenants) {
		t13 = userTenants && user && changeTenant && /* @__PURE__ */ React.createElement(TenantSelect, {
			className: classes.currentTenant,
			id: "current-tenant",
			tenants: userTenants,
			value: currentTenant,
			onTenantChange: handleTenantChange,
			label: t("Current Tenant"),
			recordIdPrefix: "udpRecord-FluentProfileMenuCard"
		});
		$[23] = changeTenant;
		$[24] = classes.currentTenant;
		$[25] = currentTenant;
		$[26] = handleTenantChange;
		$[27] = t;
		$[28] = user;
		$[29] = userTenants;
		$[30] = t13;
	} else t13 = $[30];
	let t14;
	if ($[31] !== logout) {
		t14 = () => {
			clearStoredPath();
			clearStoredExternalPath();
			clearStoredTenant();
			logout();
		};
		$[31] = logout;
		$[32] = t14;
	} else t14 = $[32];
	let t15;
	if ($[33] !== t) {
		t15 = t("Sign out");
		$[33] = t;
		$[34] = t15;
	} else t15 = $[34];
	let t16;
	if ($[35] !== t14 || $[36] !== t15) {
		t16 = /* @__PURE__ */ React.createElement(Button, {
			id: "udpRecord-FluentProfileMenuCard-SignOut",
			udprecordid: "udpRecord-FluentProfileMenuCard-SignOut",
			onClick: t14,
			variant: "outlined",
			color: "secondary"
		}, t15);
		$[35] = t14;
		$[36] = t15;
		$[37] = t16;
	} else t16 = $[37];
	let t17;
	if ($[38] !== classes.root || $[39] !== ref || $[40] !== t12 || $[41] !== t13 || $[42] !== t16) {
		t17 = /* @__PURE__ */ React.createElement(CardContent, {
			ref,
			className: t3
		}, t12, t13, t16);
		$[38] = classes.root;
		$[39] = ref;
		$[40] = t12;
		$[41] = t13;
		$[42] = t16;
		$[43] = t17;
	} else t17 = $[43];
	return t17;
});
FluentProfileMenuCard.displayName = "FluentProfileMenuCard";
//#endregion
export { FluentProfileMenuCard };

//# sourceMappingURL=FluentProfileMenuCard.mjs.map