// src/features/stardom/LeaderboardPanel.tsx
import { useStardomStore } from '@/stores/stardom';
import { Trophy } from 'lucide-react';
import { t } from '@/locales';

export function LeaderboardPanel() {
  const { leaderboard } = useStardomStore();

  return (
    <div>
      <div className="flex items-center gap-2 mb-3">
        <Trophy className="h-4 w-4 text-yellow-500" />
        <h3 className="font-medium text-sm">{t("stardom.leaderboard.title")}</h3>
      </div>

      {leaderboard.length === 0 ? (
        <p className="text-sm text-muted-foreground py-2 text-center">{t("stardom.leaderboard.noData")}</p>
      ) : (
        <div className="space-y-1">
          {leaderboard.slice(0, 10).map((entry, index) => {
            const medal = index === 0 ? '🥇' : index === 1 ? '🥈' : index === 2 ? '🥉' : `${index + 1}.`;
            return (
              <div
                key={entry.agentId}
                className="flex items-center justify-between py-1.5 px-2 rounded hover:bg-muted/50"
              >
                <div className="flex items-center gap-2">
                  <span className="text-sm w-6 text-center">{medal}</span>
                  <span className="text-xl">{entry.avatar}</span>
                  <span className="text-sm font-medium">{entry.name}</span>
                </div>
                <div className="flex items-center gap-2">
                  <span className="text-xs text-muted-foreground">{entry.helpCount} {t("stardom.leaderboard.helpCount")}</span>
                  <span className="text-sm font-medium">⭐ {Math.round(entry.reputation)}</span>
                </div>
              </div>
            );
          })}
        </div>
      )}
    </div>
  );
}
