import assert from "node:assert/strict";
import test from "node:test";
import { renderToStaticMarkup } from "react-dom/server";
import { AppLanguageProvider } from "@/components/providers/app-language-provider";
import { CdcGpsfDashboardSummaryCards } from "@/features/cdc-gpsf/dashboard/components/cdc-gpsf-dashboard-summary-cards";
import { MeasureCategoryCard } from "@/features/cdc-gpsf/plenary/dashboard/components/charts/measure-category-card";
import { FilterPanelGrouped } from "@/components/ui/filter-panel";
import {
  PlenaryLabelsProvider,
  usePlenaryTranslations,
} from "./plenary-translation-provider";
import { resolvePlenaryLabels } from "./plenary-translations";

function SharedContent() {
  const text = usePlenaryTranslations();
  return (
    <>
      <h1>{text.dashboard}</h1>
      <CdcGpsfDashboardSummaryCards />
      <FilterPanelGrouped fields={[]} onChange={() => {}} labels={text} />
      <MeasureCategoryCard
        rows={[]}
        title={text.measureCategory}
        labels={text}
      />
    </>
  );
}
test("shared Plenary cards, filter and chart use owner labels without a Working Group/CDC query", () => {
  for (const owner of ["pswg", "ministry", "cdc", "cefp", "cdcgpsf"]) {
    for (const language of ["en", "kh"]) {
      const labels = [
        "page_title",
        "total_issues",
        "filter",
        "measure_category",
        "solved",
        "export_chart",
      ];
      const dictionary = Object.fromEntries(
        labels.map((key) => [key, owner + ":" + key]),
      );
      const html = renderToStaticMarkup(
        <AppLanguageProvider>
          <PlenaryLabelsProvider
            text={resolvePlenaryLabels(language, dictionary)}
          >
            <SharedContent />
          </PlenaryLabelsProvider>
        </AppLanguageProvider>,
      );
      for (const key of labels)
        assert.ok(html.includes(owner + ":" + key), key);
    }
  }
});
