/**
 * ClosureA file-level audit regressions (8 Nov 2026).
 */
import { describe, test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { pickLocalized } from "@/features/shared/types/cms";

const src = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");

describe("F-CLA-1 community post body falls back to the language it was written in", () => {
  test("a post stored only in Arabic still shows in English, and vice versa", () => {
    assert.equal(pickLocalized(null, "نص المنشور #تطوع", "en"), "نص المنشور #تطوع");
    assert.equal(pickLocalized("Post body", null, "ar"), "Post body");
    assert.equal(pickLocalized("Post body", "نص", "ar"), "نص");
  });

  test("the card and the detail body both use the fallback", () => {
    for (const file of [
      "features/community/components/InnerPostCard.tsx",
      "features/community/components/CommunityPostBody.tsx",
    ]) {
      assert.match(src(file), /pickLocalized\(\s*\w+\??\.idea_text_en,\s*\w+\??\.idea_text_ar/);
    }
  });
});

describe("F-CLA-2 an avatar/logo upload no longer locks the account form's Save", () => {
  test("neither Save button is gated on the sticky picture-changed flag", () => {
    for (const file of [
      "features/profile/components/AccountFormActions.tsx",
      "features/profile/components/OrganizerFormActions.tsx",
      "features/profile/components/VolunteerAccountInformation.tsx",
      "features/profile/components/OrganizerAccountForm.tsx",
    ]) {
      assert.doesNotMatch(src(file), /isOnlyProfilePicChanged/, file);
    }
  });
});

describe("F-CLA-3 RTL-safe volunteer-list select alignment", () => {
  test("the unfocused control uses a logical value like the focused one", () => {
    const css = src("app/globals.css");
    assert.doesNotMatch(css, /\.voulnteerlist \.css-13cymwt-control \{\s*justify-content: left;/);
  });
});

describe("F-CLA-4 root error boundary defaults to Arabic", () => {
  test("document is Arabic/RTL with the English copy marked as such", () => {
    const file = src("app/global-error.tsx");
    assert.match(file, /<html lang="ar" dir="rtl">/);
    assert.match(file, /lang="en"/);
  });
});
