import { expect, test } from "bun:test";
import { resolveTheme, themePreference, themePalette } from "./theme";
test("system default follows the OS, while saved explicit choices take precedence", () => {
  for (const value of [null, "invalid", "system"]) expect(themePreference(value)).toBe("system");
  expect(resolveTheme(themePreference(null), true)).toBe("dark");
  expect(resolveTheme("system", false)).toBe("light");
  expect(resolveTheme("light", true)).toBe("light");
  expect(resolveTheme("dark", false)).toBe("dark");
});
const luminance = (hex: string) => {
  const rgb = hex.slice(1).match(/../g)!.map(value => parseInt(value, 16) / 255).map(value => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
  return rgb[0]! * .2126 + rgb[1]! * .7152 + rgb[2]! * .0722;
};
test("both export palettes provide AA contrast for primary and secondary text", () => {
  for (const palette of Object.values(themePalette)) for (const foreground of [palette.ink, palette.muted]) {
    const values = [luminance(foreground), luminance(palette.paper)].sort((a, b) => a - b);
    expect((values[1]! + .05) / (values[0]! + .05)).toBeGreaterThanOrEqual(4.5);
  }
});
