import { c } from "react-compiler-runtime";
import { useEffect, useState } from "react";
import * as gravatar from "gravatar";
import loadImages from "image-promise";
//#region src/utilities/useGravatar.ts
/**
* Provides the url to a Gravatar image for an email
*
* - Returns null until the image has preloaded so letter avatars can be displayed while loading
* - Returns null if the email does not have a Gravatar (the loaded image is a 404)
*/
function useGravatar(email, t0) {
	const $ = c(7);
	const { size } = t0;
	const [loaded, setLoaded] = useState(false);
	let t1;
	if ($[0] !== email || $[1] !== size) {
		t1 = email && gravatar.url(email, {
			s: String(size),
			protocol: "https",
			d: "404"
		});
		$[0] = email;
		$[1] = size;
		$[2] = t1;
	} else t1 = $[2];
	const url = t1;
	let t2;
	let t3;
	if ($[3] !== loaded || $[4] !== url) {
		t2 = () => {
			loadImages(url).then(() => {
				setLoaded(loaded);
			}).catch(_temp);
		};
		t3 = [loaded, url];
		$[3] = loaded;
		$[4] = url;
		$[5] = t2;
		$[6] = t3;
	} else {
		t2 = $[5];
		t3 = $[6];
	}
	useEffect(t2, t3);
	return url || null;
}
function _temp(err) {}
//#endregion
export { useGravatar as default };

//# sourceMappingURL=useGravatar.mjs.map