import { ArrowTrendingUpIcon, BoltIcon, BuildingLibraryIcon, ChatBubbleLeftRightIcon, ChatBubbleOvalLeftIcon, CheckCircleIcon, ClipboardDocumentListIcon, EnvelopeIcon, HandRaisedIcon, PuzzlePieceIcon, QuestionMarkCircleIcon, ScaleIcon, StarIcon, UserIcon, UsersIcon, } from '@heroicons/react/24/outline' import clsx from 'clsx' import {type Stats} from 'common/stats' import {ComponentType, ReactNode, SVGProps, useEffect, useState} from 'react' import {PageBase} from 'web/components/page-base' import {SEO} from 'web/components/SEO' import ChartMembers from 'web/components/widgets/charts' import {api} from 'web/lib/api' import {useT} from 'web/lib/locale' import {getCount} from 'web/lib/supabase/users' // ─── Types ──────────────────────────────────────────────────────────────────── type IconType = ComponentType> interface StatCardProps { value: string | number | null | undefined label: string icon: IconType accent?: 'amber' | 'sage' | 'muted' large?: boolean } interface StatGroupProps { icon: IconType title: string children: ReactNode } // ─── Helpers ────────────────────────────────────────────────────────────────── function formatNumber(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 n.toLocaleString() } // ─── Stat Card ──────────────────────────────────────────────────────────────── function StatCard({value, label, icon: Icon, accent = 'amber', large}: StatCardProps) { if (value === null || value === undefined || value === 0) return null const formatted = typeof value === 'number' ? formatNumber(value) : value const accentClasses = { amber: 'text-primary-500', sage: 'text-green-500', muted: 'text-ink-500', } return (
{formatted}

{label}

) } // ─── Stat Group ─────────────────────────────────────────────────────────────── function StatGroup({icon: Icon, title, children}: StatGroupProps) { return (
{title}
{children}
) } // ─── Chart wrapper ──────────────────────────────────────────────────────────── function ChartCard() { const t = useT() return (

{t('stats.chart.title', 'Member Growth')}

{t('stats.chart.subtitle', 'Total & completed profiles over time')}

) } // ─── Highlight Row ──────────────────────────────────────────────────────────── function HighlightRow({ members, active, messages, }: { members: number | null active: number | null messages: number | null | undefined }) { const t = useT() const items: { value: number | null | undefined label: string icon: IconType accent: 'amber' | 'sage' }[] = [ { value: members, label: t('stats.highlight.members', 'Total Members'), icon: UsersIcon, accent: 'amber' as const, }, { value: active, label: t('stats.highlight.active', 'Active (last month)'), icon: BoltIcon, accent: 'sage' as const, }, { value: messages, label: t('stats.highlight.messages', 'Messages sent'), icon: EnvelopeIcon, accent: 'amber' as const, }, ].filter((i) => !!i.value) if (!items.length) return null return (
{items.map((item) => { const Icon = item.icon return (
{typeof item.value === 'number' ? formatNumber(item.value) : item.value}

{item.label}

) })}
) } // ─── Page ───────────────────────────────────────────────────────────────────── export default function Stats() { const t = useT() const [data, setData] = useState>({}) const [statsData, setStatsData] = useState(undefined) const [loading, setLoading] = useState(true) useEffect(() => { async function load() { const tables = [ 'profiles', 'active_members', 'bookmarked_searches', 'private_user_message_channels', 'profile_comments', 'compatibility_prompts', 'compatibility_answers', 'votes', 'vote_results', ] as const const [settled, statsResult] = await Promise.allSettled([ Promise.allSettled(tables.map((t) => getCount(t))), api('stats', {}), ]) const result: Record = {} if (settled.status === 'fulfilled') { settled.value.forEach((res, i) => { result[tables[i]] = res.status === 'fulfilled' ? res.value : null }) } if (statsResult.status === 'fulfilled') setStatsData(statsResult.value) setData(result) setLoading(false) } void load() }, []) const genderRatioLabel = statsData?.genderRatio ? `${statsData.genderRatio.male ?? 0} / ${statsData.genderRatio.female ?? 0}` : null return (
{/* ── Page header ── */}

{t('stats.eyebrow', 'Transparency')}

{t('stats.title', 'Growth & Stats')}

{t( 'stats.subtitle', "Real numbers. No spin. Compass is built in the open — here's exactly how we're growing.", )}

{/* ── Loading skeleton ── */} {loading && (
{Array.from({length: 6}).map((_, i) => (
))}
)} {!loading && ( <> {/* ── Hero highlight row ── */} {/* ── Growth chart ── */} {/* ── Community ── */} {/* ── Conversations ── */} {/* ── Compatibility ── */} {/* ── Democracy ── */} {/**/} )}
) }