import { emoji } from '../../../core/theme.js';

// Rank tier system
export const TIERS = [
  { name: 'برونزي', nameEn: 'Bronze', min: 0, max: 999, color: '#CD7F32', get icon() { return emoji('medal_bronze', '🥉', 16); } },
  { name: 'فضي', nameEn: 'Silver', min: 1000, max: 1199, color: '#C0C0C0', get icon() { return emoji('medal_silver', '🥈', 16); } },
  { name: 'ذهبي', nameEn: 'Gold', min: 1200, max: 1399, color: '#FFD700', get icon() { return emoji('medal_gold', '🥇', 16); } },
  { name: 'بلاتيني', nameEn: 'Platinum', min: 1400, max: 1599, color: '#00CED1', get icon() { return emoji('gem', '💎', 16); } },
  { name: 'ماسي', nameEn: 'Diamond', min: 1600, max: 1799, color: '#B9F2FF', icon: '💠' },
  { name: 'أسطوري', nameEn: 'Master', min: 1800, max: 2000, color: '#FF4500', icon: '👑' },
  { name: 'جراند ماستر', nameEn: 'Grandmaster', min: 2000, max: 9999, color: '#8B008B', icon: '🏅' },
];

export function getTier(rating) {
  for (let i = TIERS.length - 1; i >= 0; i--) {
    if (rating >= TIERS[i].min) return TIERS[i];
  }
  return TIERS[0];
}

export function getTierProgress(rating) {
  const tier = getTier(rating);
  const range = tier.max - tier.min;
  if (range <= 0) return 1;
  return Math.min(1, (rating - tier.min) / range);
}

export function getNextTier(rating) {
  const current = getTier(rating);
  const idx = TIERS.indexOf(current);
  return idx < TIERS.length - 1 ? TIERS[idx + 1] : null;
}
