import React, { useState, useMemo } from 'react';
import { motion } from 'framer-motion';
import { useMockStore } from '../data/mockStore';
import {
Trophy, TrendingUp, DollarSign, Target, Crown, ShieldOff,
Users, CheckCircle2, Clock, BarChart2, MapPin
} from 'lucide-react';
import { SpotlightCard } from '../components/SpotlightCard';
import AnimatedNumber from '../components/AnimatedNumber';
import { usePermissions } from '../hooks/usePermissions';
// ── Rank badge helper ────────────────────────────────────────────────────────
const rankBadge = (i) =>
i === 0 ? 'bg-yellow-100 text-yellow-700 dark:bg-yellow-500/20 dark:text-yellow-300' :
i === 1 ? 'bg-zinc-100 text-zinc-700 dark:bg-white/10 dark:text-zinc-300' :
i === 2 ? 'bg-orange-100 text-orange-700 dark:bg-orange-500/20 dark:text-orange-300' :
'text-zinc-500';
// ── Podium tier styling (gold / silver / bronze) ───────────────────────────────
// Solid metal bars with dark, clearly-legible rank numerals. Height encodes rank:
// 1st is tallest, then 2nd, then 3rd.
const PODIUM_TIERS = {
1: {
heightPx: 200,
border: 'border-yellow-400',
avatarRing: 'border-yellow-400',
bar: 'bg-gradient-to-b from-yellow-300 to-yellow-500',
numeral: 'text-yellow-900/80',
text: 'text-yellow-600 dark:text-yellow-400',
glow: 'bg-yellow-500',
},
2: {
heightPx: 144,
border: 'border-zinc-300',
avatarRing: 'border-zinc-300',
bar: 'bg-gradient-to-b from-zinc-200 to-zinc-400',
numeral: 'text-zinc-700/80',
text: 'text-zinc-500 dark:text-zinc-300',
glow: 'bg-zinc-400',
},
3: {
heightPx: 100,
border: 'border-orange-400',
avatarRing: 'border-orange-400',
bar: 'bg-gradient-to-b from-orange-300 to-orange-500',
numeral: 'text-orange-900/80',
text: 'text-orange-600 dark:text-orange-400',
glow: 'bg-orange-500',
},
};
// ── Podium step (single column) ───────────────────────────────────────────────
// Bars grow from a shared baseline at a constant speed, so the shortest (bronze)
// finishes first, then silver, and the tallest (gold) lands last.
const PodiumStep = ({ agent, rank, metricKey, numberFormat = {} }) => {
const tier = PODIUM_TIERS[rank];
return (
{agent.name.split(' ').map(n => n[0]).join('')}
{rank === 1 && }
{agent.name}
{rank}
);
};
// ── Podium (shared) ──────────────────────────────────────────────────────────
const TopPodium = ({ data, metricKey, numberFormat = {} }) => {
if (data.length < 3) return null;
const [first, second, third] = data;
return (
// Fixed min-height reserves the full podium space so the shared baseline
// never shifts while the bars animate — they grow upward from the floor.