import { getTranslations, setRequestLocale } from 'next-intl/server'; import Link from 'next/link'; import { Header } from '@/components/Header'; import { Footer } from '@/components/Footer'; import { createDb, skillReviewQueries } from '@skillhub/db'; import { getPageAlternates } from '@/lib/seo'; import { getOrSetCache, cacheKeys, cacheTTL } from '@/lib/cache'; import { BarChart3, ShieldAlert, AlertTriangle, CheckCircle } from 'lucide-react'; export const dynamic = 'force-dynamic'; interface StatsData { pipeline: Record; totalReviews: number; scoreDistribution: Record; securityStats: Record; malwareCount: number; } async function getPublicReviewStats(): Promise { try { return await getOrSetCache(cacheKeys.reviewStatsPublic(), cacheTTL.reviewStatsPublic, async () => { const db = createDb(); const [pipeline, totalReviews, scoreDistribution, securityStats, malwareCount] = await Promise.all([ skillReviewQueries.getPublicPipelineStats(db), skillReviewQueries.countTotalReviews(db), skillReviewQueries.getScoreDistribution(db), skillReviewQueries.getSecurityStats(db), skillReviewQueries.countMaliciousSkills(db), ]); return { pipeline, totalReviews, scoreDistribution, securityStats, malwareCount }; }); } catch (error) { console.error('Error fetching review stats:', error); return null; } } export async function generateMetadata({ params, }: { params: Promise<{ locale: string }>; }) { const { locale } = await params; return { alternates: getPageAlternates(locale, '/reviewed/stats'), }; } function StatCard({ icon: Icon, label, value, color, href, }: { icon: React.ElementType; label: string; value: number; color: string; href?: string; }) { const content = (

{value.toLocaleString()}

{label}

); if (href) { return {content}; } return content; } function BarRow({ label, value, total, color, }: { label: string; value: number; total: number; color: string; }) { const pct = total > 0 ? (value / total) * 100 : 0; return (
{label} {value.toLocaleString()} ({pct.toFixed(1)}%)
); } export default async function ReviewStatsPage({ params, }: { params: Promise<{ locale: string }>; }) { const { locale } = await params; setRequestLocale(locale); const t = await getTranslations('reviewStats'); const data = await getPublicReviewStats(); if (!data) { return (

Failed to load stats.

); } // Total = all browse-ready SKILL.md skills (for meaningful percentages) const pipelineTotal = Object.values(data.pipeline).reduce((sum, n) => sum + n, 0); const scoreTotal = data.scoreDistribution.high + data.scoreDistribution.mid + data.scoreDistribution.low; return (
{/* Header Section */}

{t('title')}

{t('subtitle')}

{/* Review Pipeline */}

{t('pipelineTitle')}

{t('pipelineDescription')}

{t('totalReviews')} {data.totalReviews.toLocaleString()}
{/* Score Distribution */}

{t('scoreTitle')}

{t('scoreDescription')}

{/* Security & Malware */}
{/* Security Scan */}

{t('securityTitle')}

{t('securityDescription')}

{/* Malware Detection */}

{t('malwareTitle')}

{t('malwareDescription')}

{data.malwareCount > 0 && ( {t('malwareViewAll')} → )}
); }