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

test("settings opens notifications as a nested back-navigation layer", async () => {
  const settings = await readFile(new URL("../context/SettingsWindow.jsx", import.meta.url), "utf8");
  assert.match(settings, /const \[notificationsOpen, setNotificationsOpen\] = useState\(false\)/);
  assert.match(settings, /useBackLayer\(notificationsOpen, \(\) => setNotificationsOpen\(false\), "settings-notifications"\)/);
  assert.match(settings, /if \(notificationsOpen\) return <NotificationSettingsPage onBack=\{closeNotifications\} \/>/);
  assert.match(settings, /t\("settings\.notifications"\)/);
  assert.match(settings, /setNotificationsOpen\(true\)/);
});

test("notification detail exposes permission, master, and per-event controls", async () => {
  const [page, css] = await Promise.all([
    readFile(new URL("./NotificationSettingsPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("./notification-settings.css", import.meta.url), "utf8")
  ]);
  assert.match(page, /className="settings-page notification-settings-page"/);
  assert.match(page, /requestSystemNotificationPermission/);
  assert.match(page, /NOTIFICATION_SETTING_GROUPS\.map/);
  assert.match(page, /role="switch"/);
  assert.match(page, /t\("settings\.back"\)/);
  assert.match(css, /\.notification-setting-row\{[^}]*min-height:64px/s);
  assert.match(css, /\.notification-switch\{[^}]*min-width:52px[^}]*min-height:48px/s);
});
