'use client' import { BarChart } from '@tremor/react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' interface DiversityData { total: number byCountry: { country: string; count: number; percentage: number }[] byCategory: { category: string; count: number; percentage: number }[] byOceanIssue: { issue: string; count: number; percentage: number }[] byTag: { tag: string; count: number; percentage: number }[] } interface DiversityMetricsProps { data: DiversityData } /** Convert ISO 3166-1 alpha-2 code to full country name using Intl API */ function getCountryName(code: string): string { if (code === 'Others') return 'Others' try { const displayNames = new Intl.DisplayNames(['en'], { type: 'region' }) return displayNames.of(code.toUpperCase()) || code } catch { return code } } /** Convert SCREAMING_SNAKE_CASE to Title Case */ function formatLabel(value: string): string { if (!value) return value return value .replace(/_/g, ' ') .toLowerCase() .replace(/\b\w/g, (c) => c.toUpperCase()) } export function DiversityMetricsChart({ data }: DiversityMetricsProps) { if (!data || data.total === 0) { return (

No project data available

) } // Top countries — horizontal bar chart for readability const countryBarData = (data.byCountry || []).slice(0, 15).map((c) => ({ country: getCountryName(c.country), Projects: c.count, })) const categoryData = (data.byCategory || []).slice(0, 10).map((c) => ({ category: formatLabel(c.category), Projects: c.count, })) const oceanIssueData = (data.byOceanIssue || []).slice(0, 15).map((o) => ({ issue: formatLabel(o.issue), Projects: o.count, })) return (
{/* Summary stats row */}

{data.total}

Total Projects

{(data.byCountry || []).length}

Countries

{(data.byCategory || []).length}

Categories

{(data.byOceanIssue || []).length}

Ocean Issues

{/* Country Distribution — horizontal bars */} Geographic Distribution {countryBarData.length > 0 ? ( ) : (

No geographic data

)}
{/* Competition Categories — horizontal bars */} Competition Categories {categoryData.length > 0 ? ( categoryData.length <= 4 ? ( /* Clean stacked bars for few categories */
{categoryData.map((c) => { const maxCount = Math.max(...categoryData.map((d) => d.Projects)) const pct = maxCount > 0 ? (c.Projects / maxCount) * 100 : 0 return (
{c.category} {c.Projects}
) })}
) : ( ) ) : (

No category data

)}
{/* Ocean Issues — horizontal bars for readability */} {oceanIssueData.length > 0 && ( Ocean Issues Addressed )} {/* Tags — clean pill cloud */} {(data.byTag || []).length > 0 && ( Project Tags
{(data.byTag || []).slice(0, 30).map((tag) => ( {tag.tag} ({tag.count}) ))}
)}
) }