export function survivorInitials(name: string): string {
  const parts = name.trim().split(/\s+/).filter((p) => /[A-Za-zÀ-ÿ]/.test(p[0]));
  if (parts.length === 0) return '?';
  if (parts.length === 1) return parts[0][0].toUpperCase();
  return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
}

const SURVIVOR_AVATAR: Record<string, string> = {
  'Dwight Fairfield':  'S01_DwightFairfield_Portrait.webp',
  'Meg Thomas':        'S02_MegThomas_Portrait.webp',
  'Claudette Morel':   'S03_ClaudetteMorel_Portrait.webp',
  'Jake Park':         'S04_JakePark_Portrait.webp',
  'Nea Karlsson':      'S05_NeaKarlsson_Portrait.webp',
  'Laurie Strode':     'S06_LaurieStrode_Portrait.webp',
  'Ace Visconti':      'S07_AceVisconti_Portrait.webp',
  'Bill Overbeck':     'S08_BillOverbeck_Portrait.webp',
  'Feng Min':          'S09_FengMin_Portrait.webp',
  'David King':        'S10_DavidKing_Portrait.webp',
  'Quentin Smith':     'S11_QuentinSmith_Portrait.webp',
  'David Tapp':        'S12_DavidTapp_Portrait.webp',
  'Kate Denson':       'S13_KateDenson_Portrait.webp',
  'Adam Francis':      'S14_AdamFrancis_Portrait.webp',
  'Jeff Johansen':     'S15_JeffJohansen_Portrait.webp',
  'Jane Romero':       'S16_JaneRomero_Portrait.webp',
  'Ash Williams':      'S17_AshWilliams_Portrait.webp',
  'Nancy Wheeler':     'S18_NancyWheeler_Portrait.webp',
  'Steve Harrington':  'S19_SteveHarrington_Portrait.webp',
  'Yui Kimura':        'S20_YuiKimura_Portrait.webp',
  'Zarina Kassir':     'S21_ZarinaKassir_Portrait.webp',
  'Cheryl Mason':      'S22_CherylMason_Portrait.webp',
  'Felix Richter':     'S23_FelixRichter_Portrait.webp',
  'Élodie Rakoto':     'S24_ElodieRakoto_Portrait.webp',
  'Yun-Jin Lee':       'S25_Yun-JinLee_Portrait.webp',
  'Jill Valentine':    'S26_JillValentine_Portrait.webp',
  'Leon S. Kennedy':   'S27_LeonScottKennedy_Portrait.webp',
  'Mikaela Reid':      'S28_MikaelaReid_Portrait.webp',
  'Jonah Vasquez':     'S29_JonahVasquez_Portrait.webp',
  'Yoichi Asakawa':    'S30_YoichiAsakawa_Portrait.webp',
  'Haddie Kaur':       'S31_HaddieKaur_Portrait.webp',
  'Ada Wong':          'S32_AdaWong_Portrait.webp',
  'Rebecca Chambers':  'S33_RebeccaChambers_Portrait.webp',
  'Vittorio Toscano':  'S34_VittorioToscano_Portrait.webp',
  'Thalita Lyra':      'S35_ThalitaLyra_Portrait.webp',
  'Renato Lyra':       'S36_RenatoLyra_Portrait.webp',
  'Gabriel Soma':      'S37_GabrielSoma_Portrait.webp',
  'Nicolas Cage':      'S38_NicolasCage_Portrait.webp',
  'Ellen Ripley':      'S39_EllenRipley_Portrait.webp',
  'Alan Wake':         'S40_AlanWake_Portrait.webp',
  'Sable Ward':        'S41_SableWard_Portrait.webp',
  'Aestri Yazar':      'S42_TheTroupe_Portrait.webp',
  'Lara Croft':        'S43_LaraCroft_Portrait.webp',
  'Trevor Belmont':    'S44_TrevorBelmont_Portrait.webp',
  'Taurie Cain':       'S45_TaurieCain_Portrait.webp',
  'Rick Grimes':       'S46_RickGrimes_Portrait.webp',
  'Michonne Grimes':   'S47_MichonneGrimes_Portrait.webp',
  'Vee Boonyasak':     'S48_VeeBoonyasak_Portrait.webp',
};

export function avatarUrl(name: string): string | null {
  const file = SURVIVOR_AVATAR[name];
  return file ? `avatars/${file}` : null;
}
