import { createEnvironmentInjector } from '@angular/core';
import { TranslateService, provideTranslateService } from '@ngx-translate/core';

import { AppI18nService } from './app-i18n.service';

describe('AppI18nService', () => {
  let injector: ReturnType<typeof createEnvironmentInjector>;
  let service: AppI18nService;
  let translate: TranslateService;

  beforeEach(() => {
    injector = createEnvironmentInjector([
      provideTranslateService({
        fallbackLang: 'en',
        lang: 'en'
      }),
      AppI18nService
    ]);

    service = injector.get(AppI18nService);
    translate = injector.get(TranslateService);
  });

  afterEach(() => {
    injector.destroy();
  });

  it('loads bundled English translations on initialize', () => {
    service.initialize();

    expect(translate.getCurrentLang()).toBe('en');
    expect(translate.instant('common.brand')).toBe('Toju');
  });

  it('falls back to English for unsupported locale requests', () => {
    service.initialize('fr');

    expect(translate.getCurrentLang()).toBe('en');
  });
});
