import { Avatar } from "antd";
import { AvatarProps } from "antd/lib/avatar";

interface CustomAvatarProps extends Omit<AvatarProps, "children"> {
	src?: string;
	name?: string;
}

export function CustomAvatar({
	src,
	name,
	className = "",
	...props
}: CustomAvatarProps) {
	// 获取名字的第一个字符，如果没有名字则显示"匿"
	const firstChar = name ? name.charAt(0) : "匿";

	return (
		<Avatar
			className={`ring-2 ring-primary/50
        bg-primary-300
        text-white
        transition-all duration-200 ease-in-out shadow-md
        hover:shadow-lg
        ${className}`}
			shape="square"
			src={src}
			size={40}
			{...props}>
			{!src && firstChar}
		</Avatar>
	);
}
