// === TREE VIEW === function renderTree() { const el = document.getElementById("tree-view"); const filtered = filterTags(); if (!filtered.length) { el.innerHTML = '
Sin datos
'; return; } // Group tags by set_hst const groups = new Map(); filtered.forEach(t => { const g = t.set_hst || "other"; if (!groups.has(g)) groups.set(g, []); groups.get(g).push(t); }); el.innerHTML = [...groups.entries()].map(([gid, tags]) => { const info = state.groups.find(g => g.mrf === gid); const name = info ? (info.name_es || info.ref) : gid === "other" ? "Sin grupo" : gid.slice(0, 10); return `
+ ${name} (${tags.length})
${tags.map(t => { const sel = state.selected.has(t.mrf); const img = getImg(t); return `
${img ? `` : ""} ${t.ref} - ${getName(t)}
`; }).join("")}
`; }).join(""); // Bind expand/collapse el.querySelectorAll(".tree-item[data-expand]").forEach(i => { i.onclick = () => { const ch = document.getElementById(`tree-${i.dataset.expand}`); if (ch) { ch.classList.toggle("open"); i.querySelector(".tree-toggle").textContent = ch.classList.contains("open") ? "-" : "+"; } }; }); // Bind tag click el.querySelectorAll(".tree-item[data-mrf]").forEach(i => { i.onclick = e => { e.stopPropagation(); state.selectionMode ? toggleSel(i.dataset.mrf) : showDetail(i.dataset.mrf); }; }); }