// Wait until DOM is available
document.addEventListener("DOMContentLoaded", function () {
  // Get all high-contrast buttons
  var buttons = document.querySelectorAll(".a11y-high-contrast-toggle");

  buttons.forEach(function (btn) {
    // Ensure aria-pressed is initially set
    if (!btn.hasAttribute("aria-pressed")) {
      btn.setAttribute("aria-pressed", "false");
    }

    btn.addEventListener("click", function (e) {
      var body = document.body;
      var isOn = body.classList.toggle("high-contrast");

      // Update ARIA state
      btn.setAttribute("aria-pressed", isOn ? "true" : "false");
    });
  });
});
