import classNames from "classnames";
import { useMemo } from "react";
import { base64ToBuffer, decryptData } from "@/backend/accounts/crypto";
import { Icon, Icons } from "@/components/Icon";
import { UserIcon } from "@/components/UserIcon";
import { AccountProfile } from "@/pages/parts/auth/AccountCreatePart";
import { useAuthStore } from "@/stores/auth";
export interface AvatarProps {
profile: AccountProfile["profile"];
sizeClass?: string;
iconClass?: string;
bottom?: React.ReactNode;
}
export function Avatar(props: AvatarProps) {
return (
{props.bottom ? (
{props.bottom}
) : null}
);
}
export function UserAvatar(props: {
sizeClass?: string;
iconClass?: string;
bottom?: React.ReactNode;
withName?: boolean;
}) {
const auth = useAuthStore();
const bufferSeed = useMemo(
() =>
auth.account && auth.account.seed
? base64ToBuffer(auth.account.seed)
: null,
[auth]
);
if (!auth.account || auth.account === null) return null;
const deviceName = bufferSeed
? decryptData(auth.account.deviceName, bufferSeed)
: "...";
return (
<>
{props.withName && bufferSeed ? (
{deviceName.length >= 20
? `${deviceName.slice(0, 20 - 1)}…`
: deviceName}
) : null}
>
);
}
export function NoUserAvatar(props: {
sizeClass?: string;
iconClass?: string;
}) {
return (
);
}