// Drives settings.html against /api/config/* (see api/routers/config.py).
// Every mutation re-fetches its own section from the server afterward
// rather than guessing the new state locally -- the server is the one
// source of truth for what's actually in the YAML/txt files.
const KINDS_EDITABLE_HERE = new Set(["presidio_builtin", "regex"]);
document.querySelectorAll(".tab").forEach((tab) => {
tab.addEventListener("click", () => {
document.querySelectorAll(".tab").forEach((t) => t.classList.remove("active"));
document.querySelectorAll(".panel").forEach((p) => (p.hidden = true));
tab.classList.add("active");
document.getElementById(tab.dataset.panel).hidden = false;
});
});
init();
async function init() {
await Promise.all([loadCategories(), loadColumns(), loadExcludeList()]);
document.getElementById("category-form").addEventListener("submit", onAddCategory);
document.getElementById("column-form").addEventListener("submit", onAddColumn);
document.getElementById("exclude-form").addEventListener("submit", onAddExcludeTerm);
}
// ------------------------------------------------------------- categories
async function loadCategories() {
const categories = await getJSON("/api/config/categories");
const tbody = document.querySelector("#categories-table tbody");
tbody.innerHTML = "";
for (const c of categories) {
const editable = KINDS_EDITABLE_HERE.has(c.kind);
const row = document.createElement("tr");
row.innerHTML = `