/**
 * Custom JS for theme elements
 */

/**
 * Wocommerce active class for category list
 */
let signifyBlocksUrl = window.location.href;
const signifyBlocksCatLink = document.querySelectorAll(
  ".wc-block-product-categories-list li a"
);
signifyBlocksCatLink.forEach((item) => {
  if (item.href === signifyBlocksUrl) {
    item.classList.add("active");
  }
});

// Function to Add/remove class for mobile Woocommerce sidebar Widgets/filters
const toggleFunc = (targetElem) => {
  let filterButtons = document.querySelectorAll(targetElem);

  filterButtons.forEach((filterButton) => {
    if (filterButton !== null) {
      filterButton.addEventListener("click", () => {
        if (filterButton.classList.contains("toggled-on")) {
          // if has 'toggled-on' class remove class
          filterButton.classList.remove("toggled-on");
        } else {
          // otherwise add 'toggled-on' class
          filterButton.classList.add("toggled-on");
        }
      });
    }
  });
};

toggleFunc(".btn-mobile-filters");
