import useDevicePixelRatio from "../../../utilities/useDevicePixelRatio.mjs";
import useGravatar from "../../../utilities/useGravatar.mjs";
import { c } from "react-compiler-runtime";
import React from "react";
import { Avatar, makeStyles } from "@material-ui/core";
import clsx from "clsx";
//#region src/shell/ui/profile/UserAvatar.jsx
const useStyles = makeStyles((theme) => ({
	root: {},
	default: {},
	toolbar: {
		width: 32,
		height: 32
	},
	large: {
		width: 80,
		height: 80
	}
}), { name: "UserAvatar" });
/**
* Inteligent user Avatar element
*
* - Loads a Gravatar based on the email if one exists
* - Falls back to a text avatar while loading and when a Gravatar does not exist
* - Automatically chooses image size based on size prop and device pixel density (and updates if device pixel density changes)
*/
const UserAvatar = (props) => {
	const $ = c(22);
	const classes = useStyles(props);
	let className;
	let email;
	let name;
	let other;
	let t0;
	if ($[0] !== props) {
		({name, email, size: t0, className, ...other} = props);
		$[0] = props;
		$[1] = className;
		$[2] = email;
		$[3] = name;
		$[4] = other;
		$[5] = t0;
	} else {
		className = $[1];
		email = $[2];
		name = $[3];
		other = $[4];
		t0 = $[5];
	}
	const size = t0 === void 0 ? "default" : t0;
	const dppx = useDevicePixelRatio();
	let t1;
	if ($[6] !== size) {
		t1 = {
			toolbar: 32,
			large: 80
		}[size] || 40;
		$[6] = size;
		$[7] = t1;
	} else t1 = $[7];
	const t2 = t1 * dppx;
	let t3;
	if ($[8] !== t2) {
		t3 = { size: t2 };
		$[8] = t2;
		$[9] = t3;
	} else t3 = $[9];
	const avatar = useGravatar(email, t3);
	const t4 = `${name}'s avatar`;
	const t5 = classes[size];
	let t6;
	if ($[10] !== className || $[11] !== t5) {
		t6 = clsx(className, t5);
		$[10] = className;
		$[11] = t5;
		$[12] = t6;
	} else t6 = $[12];
	let t7;
	if ($[13] !== name) {
		t7 = name?.trim()?.charAt(0) || "?";
		$[13] = name;
		$[14] = t7;
	} else t7 = $[14];
	let t8;
	if ($[15] !== avatar || $[16] !== name || $[17] !== other || $[18] !== t4 || $[19] !== t6 || $[20] !== t7) {
		t8 = /* @__PURE__ */ React.createElement(Avatar, {
			alt: name,
			"aria-label": t4,
			...other,
			className: t6,
			src: avatar
		}, t7);
		$[15] = avatar;
		$[16] = name;
		$[17] = other;
		$[18] = t4;
		$[19] = t6;
		$[20] = t7;
		$[21] = t8;
	} else t8 = $[21];
	return t8;
};
//#endregion
export { UserAvatar as default };

//# sourceMappingURL=UserAvatar.mjs.map