document.addEventListener('DOMContentLoaded', function () {
  var smoothone_submenuToggles = document.querySelectorAll(
    '.wp-block-navigation-submenu__toggle',
  );

  smoothone_submenuToggles.forEach(function (toggle) {
    toggle.addEventListener('click', function (event) {
      event.preventDefault();

      var smoothone_li = toggle.parentElement;

      if (
        smoothone_li.classList.contains('ddl-active') ||
        smoothone_li.querySelector('.ddl-active') !== null ||
        smoothone_li.querySelector('.wp-block-navigation-submenu').style.display ===
          'block'
      ) {
        smoothone_li.classList.remove('ddl-active');
        smoothone_li.querySelectorAll('.ddl-active').forEach(function (activeLi) {
          activeLi.classList.remove('ddl-active');
        });
        smoothone_li.querySelectorAll('.wp-block-navigation-submenu').forEach(function (
          submenu,
        ) {
          submenu.style.display = 'none';
        });
      } else {
        smoothone_li.classList.add('ddl-active');
        smoothone_li.querySelector('.wp-block-navigation-submenu').style.display =
          'block';
      }
    });
  });
});
