// Metadatos de personaje portados de home/views/account.py + home/zone_definitions.py.
import zoneNames from './data/zone-names.json'
import zoneNamesEn from './data/zone-names-en.json'

const ZONE_NAMES = zoneNames as Record<string, string>
const ZONE_NAMES_EN = zoneNamesEn as Record<string, string>

/** Nombre de la zona a partir de su ZoneID, según idioma (EN cae a ES si falta). */
export function getZoneName(zoneId: number, locale = 'es'): string {
  const id = String(zoneId)
  if (locale === 'en') return ZONE_NAMES_EN[id] ?? ZONE_NAMES[id] ?? 'Unknown zone'
  return ZONE_NAMES[id] ?? 'Zona desconocida'
}

const CLASS_MAP: Record<number, string> = {
  1: 'warrior',
  2: 'paladin',
  3: 'hunter',
  4: 'rogue',
  5: 'priest',
  6: 'death-knight',
  7: 'shaman',
  8: 'mage',
  9: 'warlock',
  11: 'druid',
}

/** Slug de clase (para color/estilo). */
export function getClassCss(classId: number): string {
  return CLASS_MAP[classId] ?? 'unknown'
}

// Clases compatibles por raza (validación de la imagen).
const RACE_CLASS_MAP: Record<number, number[]> = {
  10: [2, 3, 4, 5, 6, 8, 9], // Elfo de Sangre
  8: [1, 3, 4, 5, 6, 7, 8], // Trol
  6: [1, 3, 6, 7, 11], // Tauren
  5: [1, 4, 5, 6, 8, 9], // No-muerto
  2: [1, 3, 4, 6, 7, 9], // Orco
  11: [1, 2, 3, 5, 6, 7, 8], // Draenei
  7: [1, 4, 6, 8, 9], // Gnomo
  4: [1, 3, 4, 5, 6, 11], // Elfo de la Noche
  3: [1, 2, 3, 4, 5, 6], // Enano
  1: [1, 2, 4, 5, 6, 8, 9], // Humano
}

const RACE_IMAGE: Record<number, string> = {
  10: 'blood-elf',
  8: 'troll',
  6: 'tauren',
  5: 'undead',
  2: 'orc',
  11: 'draenei',
  7: 'gnome',
  4: 'night-elf',
  3: 'dwarf',
  1: 'human',
}

/**
 * Ruta pública de la imagen del personaje según raza/clase/género.
 * `gender`: 0 = hombre, 1 = mujer. Si la clase no es válida para la raza -> unknown.
 */
export function getCharacterImage(classId: number, race: number, gender: number): string {
  if (!(RACE_CLASS_MAP[race] ?? []).includes(classId)) return '/races/unknown.webp'
  const base = RACE_IMAGE[race]
  if (!base) return '/races/unknown.webp'
  const suffix = gender === 0 ? 'male' : 'female'
  return `/races/big-${base}-${suffix}.webp`
}

const RACE_NAME: Record<number, string> = {
  1: 'Humano',
  2: 'Orco',
  3: 'Enano',
  4: 'Elfo de la Noche',
  5: 'No-muerto',
  6: 'Tauren',
  7: 'Gnomo',
  8: 'Trol',
  10: 'Elfo de Sangre',
  11: 'Draenei',
}
// Nombres en inglés (FusionCMS wow_constants.php).
const RACE_NAME_EN: Record<number, string> = {
  1: 'Human',
  2: 'Orc',
  3: 'Dwarf',
  4: 'Night Elf',
  5: 'Undead',
  6: 'Tauren',
  7: 'Gnome',
  8: 'Troll',
  10: 'Blood Elf',
  11: 'Draenei',
}

const CLASS_NAME: Record<number, string> = {
  1: 'Guerrero',
  2: 'Paladín',
  3: 'Cazador',
  4: 'Pícaro',
  5: 'Sacerdote',
  6: 'Caballero de la Muerte',
  7: 'Chamán',
  8: 'Mago',
  9: 'Brujo',
  11: 'Druida',
}
const CLASS_NAME_EN: Record<number, string> = {
  1: 'Warrior',
  2: 'Paladin',
  3: 'Hunter',
  4: 'Rogue',
  5: 'Priest',
  6: 'Death Knight',
  7: 'Shaman',
  8: 'Mage',
  9: 'Warlock',
  11: 'Druid',
}

export function getRaceName(race: number, locale = 'es'): string {
  return (locale === 'en' ? RACE_NAME_EN : RACE_NAME)[race] ?? '—'
}
export function getClassName(classId: number, locale = 'es'): string {
  return (locale === 'en' ? CLASS_NAME_EN : CLASS_NAME)[classId] ?? '—'
}
