const allCards = document.querySelectorAll('.team-card'); function filterTeams(query) { const q = query.toLowerCase().trim(); const grid = document.getElementById('teamsGrid'); const empty = document.getElementById('emptyState'); const clearBtn = document.getElementById('searchClear'); let visible = 0; clearBtn.style.display = q ? 'block' : 'none'; if (grid) { allCards.forEach(function(card) { const name = card.dataset.name || ''; const desc = card.dataset.desc || ''; const match = !q || name.includes(q) || desc.includes(q); card.style.display = match ? '' : 'none'; if (match) visible++; }); if (visible === 0) { if (!empty) { const container = document.getElementById('teamsContainer'); const div = document.createElement('div'); div.className = 'empty-state'; div.id = 'emptyState'; div.innerHTML = '
No teams match your search.
'; container.appendChild(div); } else { empty.querySelector('p').textContent = 'No teams match your search.'; empty.style.display = ''; } } else { if (empty) empty.style.display = 'none'; } } const url = q ? '?search=' + encodeURIComponent(query) : window.location.pathname; window.history.replaceState({}, '', url); } document.getElementById('teamSearch')?.addEventListener('input', function() { filterTeams(this.value); }); document.addEventListener('DOMContentLoaded', function() { const searchInput = document.getElementById('teamSearch'); if (searchInput && searchInput.value) { filterTeams(searchInput.value); } }); function deleteTeam(id, name) { if (confirm('Delete team "' + name + '"?\nThis will remove access for all members.')) { const form = document.getElementById('deleteForm'); form.action = '/teams/' + id + '/delete'; form.submit(); } }