function switchTab(tabName, updateHash = true) {
App.activeTab = tabName;
document.querySelectorAll('.nav-tab').forEach(t => {
t.classList.toggle('active', t.getAttribute('data-tab') === tabName);
});
document.querySelectorAll('.tab-content').forEach(c => {
c.classList.toggle('active', c.id === `tab-${tabName}`);
});
if (typeof ledLoadVisible === 'function') ledLoadVisible();
if (updateHash) {
let targetHash = `#/${tabName}`;
if (tabName === 'search' && App.selectedKey) {
targetHash = `#/knowledge/${encodeURIComponent(App.selectedKey)}`;
} else if (tabName === 'services' && App.place) {
targetHash = placeHash(App.place);
}
if (window.location.hash !== targetHash) {
history.pushState(null, '', targetHash);
}
}
if (tabName === 'services') renderPlaces();
}
function filterByTag(tag) {
const searchEl = document.getElementById('globalSearch');
if (searchEl) searchEl.value = '#' + tag;
App.searchQuery = '';
App.tagFilter = tag;
App.isBackendSearchResults = false;
switchTab('search', false);
const targetHash = `#/search?tag=${encodeURIComponent(tag)}`;
if (window.location.hash !== targetHash) {
history.pushState(null, '', targetHash);
}
renderKnowledgeList();
}
function escapeHtml(str) {
if (!str) return '';
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
}
function jsArg(v) {
return escapeHtml(JSON.stringify(String(v == null ? '' : v)));
}