import React, { useEffect, useState } from 'react'; function normalizeAvatarUrl(raw?: string | null): string { const trimmed = raw?.trim() || ''; if (!trimmed) return ''; if (trimmed.startsWith('//')) return `https:${trimmed}`; return trimmed; } interface StudentAvatarProps { fullName: string; avatar?: string | null; isOnline?: boolean; size?: number; showStatusBadge?: boolean; } export const StudentOnlineBadge: React.FC<{ isOnline: boolean; size?: 'sm' | 'md'; }> = ({ isOnline, size = 'sm' }) => ( {isOnline ? 'Online' : 'Offline'} ); export const StudentAvatar: React.FC = ({ fullName, avatar, isOnline = false, size = 48, showStatusBadge = true, }) => { const [imgFailed, setImgFailed] = useState(false); const avatarUrl = normalizeAvatarUrl(avatar); const initial = fullName ? fullName.trim().charAt(0).toUpperCase() : 'S'; const showImage = !!avatarUrl && !imgFailed; useEffect(() => { setImgFailed(false); }, [avatarUrl]); return ( {showImage ? ( setImgFailed(true)} /> ) : ( initial )} {showStatusBadge && ( )} ); };