'use client'; interface SocialLink { url: string; platform: string; } interface ProfileStatsProps { posts: number; snippets: number; repositories: number; followers: number; following: number; stars: number; links?: SocialLink[]; variant?: 'compact' | 'full'; } interface StatChipProps { label: string; value: number; onClick?: () => void; } function formatCount(n: number): string { if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`; if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`; return String(n); } function StatChip({ label, value, onClick }: StatChipProps) { const Tag = onClick ? 'button' : 'div'; return ( {formatCount(value)} {label} ); } const PLATFORM_ICONS: Record = { github: ( ), twitter: ( ), linkedin: ( ), youtube: ( ), website: ( ), }; function PlatformIcon({ platform }: { platform: string }) { const icon = PLATFORM_ICONS[platform.toLowerCase()]; if (icon) return <>{icon}>; return <>{PLATFORM_ICONS['website']}>; } function normalizePlatform(url: string, platform: string): string { if (platform && platform !== 'website') return platform.toLowerCase(); if (url.includes('github.com')) return 'github'; if (url.includes('twitter.com') || url.includes('x.com')) return 'twitter'; if (url.includes('linkedin.com')) return 'linkedin'; if (url.includes('youtube.com')) return 'youtube'; return 'website'; } export function ProfileStats({ posts, snippets, repositories, followers, following, stars, links = [], variant = 'full', }: ProfileStatsProps) { const stats: Array<{ label: string; value: number }> = [ { label: 'Posts', value: posts }, { label: 'Snippets', value: snippets }, { label: 'Repos', value: repositories }, { label: 'Followers', value: followers }, { label: 'Following', value: following }, { label: 'Stars', value: stars }, ]; const visibleStats = variant === 'compact' ? stats.slice(0, 4) : stats; return ( {/* Stat chips */} {visibleStats.map((s) => ( ))} {/* Social links */} {links.length > 0 && ( {links.map((link) => { const platform = normalizePlatform(link.url, link.platform); return ( {variant === 'full' && ( {platform} )} ); })} )} ); } export default ProfileStats;