/** Display helpers for player names. Bot accounts follow the server-side
 *  convention "bot:<kind>-<n>" (see api/bots.py) — render them as a short
 *  friendly label instead of the raw username. */

const BOT_PREFIX = 'bot:';

export function isBotName(name?: string | null): boolean {
  return !!name && name.startsWith(BOT_PREFIX);
}

/** "bot:heuristic-2" -> "Bot 2", "bot:neural-1" -> "AI bot 1"; other kinds
 *  keep a suffix ("Bot 1 (random)"); non-bot names pass through unchanged. */
export function displayName(name?: string | null): string {
  if (!name || !isBotName(name)) return name ?? '';
  const body = name.slice(BOT_PREFIX.length);
  const dash = body.lastIndexOf('-');
  const kind = dash > 0 ? body.slice(0, dash) : body;
  const num = dash > 0 ? body.slice(dash + 1) : '';
  if (kind === 'neural') return num ? `AI bot ${num}` : 'AI bot';
  const label = num ? `Bot ${num}` : 'Bot';
  return kind === 'heuristic' ? label : `${label} (${kind})`;
}
