import { describe, expect, it } from 'vitest';
import { en } from './i18n/en';
import { ru } from './i18n/ru';
import { errorKey, translate } from './i18n/catalog';

describe('i18n catalog', () => {
  it('has identical keys in en and ru', () => {
    expect(Object.keys(ru).sort()).toEqual(Object.keys(en).sort());
  });

  it('interpolates parameters', () => {
    expect(translate('en', 'game.bag', { n: 7 })).toBe('7 in the bag');
    expect(translate('ru', 'game.bag', { n: 7 })).toBe('7 в мешке');
  });

  it('names the previous player in the cross-game your-turn toast', () => {
    expect(translate('ru', 'game.yourTurnBy', { name: 'Аня' })).toBe('Аня: Ваш ход!');
    expect(translate('en', 'game.yourTurnBy', { name: 'Ann' })).toBe('Ann: Your turn!');
  });

  it('names the nudger in the cross-game nudge toast', () => {
    expect(translate('ru', 'chat.nudgeBy', { name: 'Аня' })).toBe('Аня: Жду Вашего хода 🤭');
    expect(translate('en', 'chat.nudgeBy', { name: 'Ann' })).toBe('Ann: Waiting for your move 🤭');
  });

  it('localizes move-history action labels', () => {
    expect(translate('ru', 'move.exchange')).toBe('обмен');
    expect(translate('ru', 'move.pass')).toBe('пас');
    expect(translate('en', 'move.exchange')).toBe('exchange');
  });

  it('localizes the awaited-move (thinking) label', () => {
    expect(translate('ru', 'game.thinking')).toBe('думает…');
    expect(translate('en', 'game.thinking')).toBe('thinking…');
  });

  it('maps error codes to keys with a generic fallback', () => {
    expect(errorKey('not_your_turn')).toBe('error.not_your_turn');
    expect(errorKey('totally_unknown')).toBe('error.generic');
  });
});
