import { describe, expect, it } from 'vitest';

import i18n from 'i18next';

import { buildAcceptLanguage } from '../legalApi';

describe('legalApi.buildAcceptLanguage', () => {
  function setLang(lang: string) {
    Object.defineProperty(i18n, 'language', {
      value: lang,
      configurable: true,
    });
  }

  it('非中文语言回退为 en', () => {
    setLang('en');
    expect(buildAcceptLanguage()).toBe('en');

    setLang('es');
    expect(buildAcceptLanguage()).toBe('en');
  });

  it('简中/其他中文不支持时回退为 en', () => {
    setLang('zh-CN');
    expect(buildAcceptLanguage()).toBe('en');

    setLang('zh');
    expect(buildAcceptLanguage()).toBe('en');
  });

  it('繁体中文归一为 tc', () => {
    setLang('zh-TW');
    expect(buildAcceptLanguage()).toBe('tc');
  });

  it('显式 tc / hant 等归一为 tc', () => {
    setLang('tc');
    expect(buildAcceptLanguage()).toBe('tc');

    setLang('zh-Hant');
    expect(buildAcceptLanguage()).toBe('tc');
  });
});

