import { HTMLProps, useState } from "react";
import classNames from "classnames";
import { getPlaceholder } from "@/utils";
import { UserMetadata } from "@snort/system";
import useImgProxy from "@/hooks/img-proxy";
type AvatarProps = HTMLProps & { size?: number; pubkey: string; user?: UserMetadata };
export function Avatar({ pubkey, size, user, ...props }: AvatarProps) {
const [failed, setFailed] = useState(false);
const { proxy } = useImgProxy();
const src = user?.picture && !failed ? proxy(user.picture, size ?? 40) : getPlaceholder(pubkey);
return (
setFailed(true)}
style={{
width: `${size ?? 40}px`,
minWidth: `${size ?? 40}px`,
height: `${size ?? 40}px`,
}}
/>
);
}