// -----------------------
// accodion
// ====== Accordion Functionality ======
document.querySelectorAll(".accordion-header").forEach((header) => {
  header.addEventListener("click", () => {
    const item = header.parentElement;
    const isActive = item.classList.contains("active");

    // Close all accordion items
    document.querySelectorAll(".accordion-item").forEach((i) => {
      i.classList.remove("active");
      i.querySelector(".accordion-header").setAttribute(
        "aria-expanded",
        "false"
      );
    });

    // Open the clicked one if not already active
    if (!isActive) {
      item.classList.add("active");
      header.setAttribute("aria-expanded", "true");
    }
  });
});

// ====== Keyboard Accessibility ======
document.querySelectorAll(".accordion-header").forEach((header) => {
  header.addEventListener("keypress", (e) => {
    if (e.key === "Enter" || e.key === " ") {
      e.preventDefault();
      header.click();
    }
  });
});
