function initDropdown() {
  const dropdowns = document.querySelectorAll('.dropdown');

  dropdowns.forEach(dropdown => {
    const toggle = dropdown.querySelector('.dropdown-toggle');
    const menu = dropdown.querySelector('.dropdown-menu');

    toggle.addEventListener('click', () => {
      dropdown.classList.toggle('open');
    });

    menu.querySelectorAll('a').forEach(item => {
      item.addEventListener('click', (event) => {
        event.preventDefault();
        console.log(`Selected: ${item.dataset.value}`);
        dropdown.classList.remove('open');
      });
    });

    document.addEventListener('click', (event) => {
      if (!dropdown.contains(event.target)) {
        dropdown.classList.remove('open');
      }
    });
  });
}

export default initDropdown;
