import { describe, expect, it } from "vitest";
import {
  homePathForLang,
  isHomePathname,
  languageForHomePathname,
  localizedHomeRoutes,
} from "./languageRoutes";

const expectedRoutes = [
  ["/chinese", "zh-CN"],
  ["/japanese", "ja"],
  ["/korean", "ko"],
  ["/vietnamese", "vi"],
  ["/indonesian", "id"],
  ["/malay", "ms"],
] as const;

describe("language home routes", () => {
  it("uses CTO-style full language path names except default English root", () => {
    expect(localizedHomeRoutes.map(({ path, lang }) => [path, lang])).toEqual(
      expectedRoutes,
    );
  });

  it("maps localized home paths to language codes", () => {
    for (const [path, lang] of expectedRoutes) {
      expect(languageForHomePathname(path)).toBe(lang);
      expect(languageForHomePathname(`${path}/`)).toBe(lang);
    }
    expect(languageForHomePathname("/english")).toBeNull();
    expect(languageForHomePathname("/unknown")).toBeNull();
  });

  it("treats root and localized language paths as home pages", () => {
    expect(isHomePathname("/")).toBe(true);
    expect(isHomePathname("/chinese")).toBe(true);
    expect(isHomePathname("/browse")).toBe(false);
  });

  it("links each active language back to its localized home", () => {
    expect(homePathForLang("en")).toBe("/");
    expect(homePathForLang("zh-CN")).toBe("/chinese");
    expect(homePathForLang("ja")).toBe("/japanese");
    expect(homePathForLang("ko")).toBe("/korean");
    expect(homePathForLang("vi")).toBe("/vietnamese");
    expect(homePathForLang("id")).toBe("/indonesian");
    expect(homePathForLang("ms")).toBe("/malay");
  });
});
