import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

test("conversation account visibility setting removes both the bar and its layout offset", async () => {
  const [app, settings, accountManagement, i18n] = await Promise.all([
    readFile(new URL("../../App.jsx", import.meta.url), "utf8"),
    readFile(new URL("../context/SettingsWindow.jsx", import.meta.url), "utf8"),
    readFile(new URL("../accounts/AccountManagementPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("../../shared/i18n.js", import.meta.url), "utf8")
  ]);

  assert.match(app, /readConversationAccountVisibilityPreference/);
  assert.match(app, /writeConversationAccountVisibilityPreference/);
  assert.match(app, /const \[conversationAccountVisible, setConversationAccountVisibleState\] = useState/);
  assert.match(app, /conversationAccountVisible \? " chat-account-offset" : ""/);
  assert.match(app, /\{conversationAccountVisible && <ConversationAccountBar/);
  assert.match(app, /conversationAccountVisible=\{conversationAccountVisible\}/);
  assert.match(app, /onConversationAccountVisibleChange=\{setConversationAccountVisible\}/);

  assert.match(settings, /conversationAccountVisible = true/);
  assert.match(settings, /onConversationAccountVisibleChange = \(\) => \{\}/);
  assert.match(settings, /<AccountManagementPage[^>]*conversationAccountVisible=\{conversationAccountVisible\}/);
  assert.match(accountManagement, /t\("settings\.conversationAccountVisible"\)/);
  assert.match(accountManagement, /aria-pressed=\{conversationAccountVisible\}/);
  assert.match(accountManagement, /onClick=\{\(\) => onConversationAccountVisibleChange\(!conversationAccountVisible\)\}/);

  assert.match(i18n, /"settings\.conversationAccountVisible": "Show last chat account"/);
  assert.match(i18n, /"settings\.conversationAccountVisible": "\\uB9C8\\uC9C0\\uB9C9 \\uCC44\\uD305 \\uACC4\\uC815 \\uD45C\\uC2DC"/);
});
