const body = document.querySelector("body");
const header = document.querySelector(".header");
const btnMenu = document.querySelector(".header__button-menu");
const navMenu = document.querySelector(".header__menu");

const toggleMenu = () => {
  header.classList.toggle("nav-visible");
};
btnMenu.addEventListener("click", toggleMenu);

const button = document.querySelector(".table-contents-menu__button");
const content = document.getElementById("menuContent");
const icon = button.querySelector("img");

function handleResize() {
  const isUserToggled = button.classList.contains("user-toggled");

  if (window.innerWidth <= 1000) {
    if (!isUserToggled) {
      content.classList.remove("active");
      button.classList.remove("active");
      icon.src = "wp-content/themes/roobet/assets/img/sidebar/arrow-up.png";
    }
  } else {
    content.classList.add("active");
    button.classList.add("active");
    icon.src = "wp-content/themes/roobet/assets/img/sidebar/arrow.png";
  }
}

function toggleTableMenu() {
  const isOpen = content.classList.toggle("active");
  button.classList.toggle("active");
  button.classList.add("user-toggled");
  icon.src = isOpen ? "wp-content/themes/roobet/assets/img/sidebar/arrow.png" : "wp-content/themes/roobet/assets/img/sidebar/arrow-up.png";
}

handleResize();

window.addEventListener("resize", handleResize);

button.addEventListener("click", toggleTableMenu);

const bonusDropdown = document.getElementById("bonusDropdown");
const bonusArrow = document.getElementById("bonusArrow");
bonusArrow.addEventListener("click", (e) => {
  e.preventDefault();
  e.stopPropagation();

  bonusDropdown.classList.toggle("active");

  if (bonusDropdown.classList.contains("active")) {
    bonusArrow.src = "wp-content/themes/roobet/assets/img/header/arrow-up.png";
  } else {
    bonusArrow.src = "wp-content/themes/roobet/assets/img/header/arrow-down.png";
  }
});

window.addEventListener("click", () => {
  bonusDropdown.classList.remove("active");
  bonusArrow.src = "wp-content/themes/roobet/assets/img/header/arrow-down.png";
});

