'use client' import { cn } from 'ui' import type { LeaderboardRow } from '~/types/contribute' function getInitials(name: string | null): string { if (!name) return '?' const parts = name.trim().split(/\s+/) if (parts.length >= 2) { return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase() } return name.substring(0, 2).toUpperCase() } function getAvatarColor(name: string | null): string { if (!name) return 'bg-surface-300' const colors = [ 'bg-blue-500', 'bg-purple-500', 'bg-pink-500', 'bg-red-500', 'bg-orange-500', 'bg-yellow-500', 'bg-green-500', 'bg-teal-500', 'bg-cyan-500', 'bg-indigo-500', ] let hash = 0 for (let i = 0; i < name.length; i++) { hash = name.charCodeAt(i) + ((hash << 5) - hash) } return colors[Math.abs(hash) % colors.length] } function Avatar({ name, size = 'md' }: { name: string | null; size?: 'sm' | 'md' | 'lg' }) { const initials = getInitials(name) const sizeClasses = { sm: 'h-8 w-8 text-xs', md: 'h-12 w-12 text-base', lg: 'h-20 w-20 text-2xl', } return (
{initials}
) } function TopThreeCard({ rank, name, score, isFirst, }: { rank: number name: string | null score: number isFirst: boolean }) { return (

{name || 'Anonymous'}

{score.toLocaleString()}
Replies
) } function LeaderboardRowItem({ rank, name, score, }: { rank: number name: string | null score: number }) { return (
{rank}
{name || 'Anonymous'}
{score.toLocaleString()}
Replies
) } export function LeaderboardContent({ leaderboard }: { leaderboard: LeaderboardRow[] }) { if (!leaderboard || leaderboard.length === 0) { return (
No leaderboard data available
) } const topThree = leaderboard.slice(0, 3) const rest = leaderboard.slice(3) return (
{/* Top 3 Cards */} {topThree.length > 0 && (
{topThree.length >= 2 && ( )} {topThree.length >= 1 && ( )} {topThree.length >= 3 && ( )}
)} {/* Rest of the leaderboard */} {rest.length > 0 && (
{rest.map((entry, index) => ( ))}
)}
) }