import { beforeAll, describe, expect, it } from "vitest";
import { ensureCatalog, translate } from "./i18n/messages";
import type { AppLocale } from "./i18n/types";
import { pageHelpKeys, type PageHelpId } from "./pageHelp";

/** 與 pageHelp.ts 的 PageHelpId 同步；漏一頁 = 測試紅燈 */
const ALL_IDS: PageHelpId[] = [
  "today",
  "crew",
  "studio",
  "scout",
  "radar_today",
  "radar_watches",
  "crm_board",
  "crm_followups",
  "crm_stats",
  "outbox",
  "jobs",
  "brands",
  "policy",
  "playbooks",
  "insights",
  "benchmark",
  "utm",
  "settings",
  "profile",
  "invite",
  "usage",
  "usage_plans",
  "usage_checkout",
  "admin_users",
  "generic",
];

const LOCALES: AppLocale[] = ["zh-TW", "en"];

describe("page help catalog completeness", () => {
  // 非預設語系是動態載入的；不先載入就只會驗到 zh-TW 後備字串
  beforeAll(async () => {
    await Promise.all(LOCALES.map((locale) => ensureCatalog(locale)));
  });

  for (const locale of LOCALES) {
    for (const id of ALL_IDS) {
      it(`${locale} has full copy for ${id}`, () => {
        const keys = pageHelpKeys(id);
        const all = [keys.title, keys.what, keys.tips, ...keys.steps];
        for (const key of all) {
          const text = translate(locale, key);
          expect(text, key).not.toBe(key);
          expect(text.trim().length).toBeGreaterThan(0);
        }
      });
    }
  }
});
