// Tab switching for main tabs
document.querySelectorAll('#jgtab .jgtab-list').forEach(tab => {
  tab.addEventListener('click', function() {
    // Tab visual state
    document.querySelectorAll('#jgtab .jgtab-list').forEach(t => t.classList.remove('jgtab-list-active'));
    this.classList.add('jgtab-list-active');
    
    // Show/hide sections
    if (this.dataset.tab === 'all-members') {
      document.getElementById('all-members-section').style.display = '';
      document.getElementById('full-disclosure-section').style.display = 'none';
    } else {
      document.getElementById('all-members-section').style.display = 'none';
      document.getElementById('full-disclosure-section').style.display = '';
    }
  });
});

// Disclosure section tab switching
document.querySelectorAll('.disclosure-tab-btn').forEach(button => {
  button.addEventListener('click', function() {
    // Update active state of buttons
    document.querySelectorAll('.disclosure-tab-btn').forEach(btn => {
      btn.classList.remove('active');
    });
    this.classList.add('active');
    
    // Show corresponding content
    const tabId = this.getAttribute('data-tab');
    document.querySelectorAll('.tab-content').forEach(content => {
      content.classList.remove('active');
    });
    document.getElementById(tabId + '-tab').classList.add('active');
  });
});

// Filter functionality
document.addEventListener('DOMContentLoaded', function() {
  // Get all filter buttons and items
  const filterButtons = document.querySelectorAll('.pilou-type li');
  const items = document.querySelectorAll('.content-pl .item');
  
  // Add click event to each filter button
  filterButtons.forEach(button => {
    button.addEventListener('click', function() {
      // Remove active class from all buttons
      filterButtons.forEach(btn => btn.classList.remove('active'));
      // Add active class to clicked button
      this.classList.add('active');
      // Get the filter value
      const filterValue = this.getAttribute('data-filter');
      // Show/hide items based on filter
      items.forEach(item => {
        if (filterValue === 'all') {
          item.style.display = '';
        } else {
          if (item.getAttribute('data-type') === filterValue) {
            item.style.display = '';
          } else {
            item.style.display = 'none';
          }
        }
      });
    });
  });
});

// Regulator list functionality
document.addEventListener('DOMContentLoaded', function() {
  const regulatorList = document.getElementById('regulatorList');
  const moreRegulators = document.getElementById('moreRegulators');
  const items = regulatorList.querySelectorAll('.custom-filter-item');
  const SHOW_COUNT = 10;

  function hideExtraItems() {
    items.forEach((item, i) => {
      if (i >= SHOW_COUNT) {
        item.classList.add('hidden');
      } else {
        item.classList.remove('hidden');
      }
    });
  }

  function showAllItems() {
    items.forEach(item => item.classList.remove('hidden'));
  }

  hideExtraItems();

  moreRegulators.addEventListener('click', function() {
    if (this.classList.contains('expanded')) {
      hideExtraItems();
      this.classList.remove('expanded');
      this.querySelector('span').textContent = 'more regulators';
    } else {
      showAllItems();
      this.classList.add('expanded');
      this.querySelector('span').textContent = 'less regulators';
    }
  });
}); 