// Tag input — Enter/comma commits a chip, Backspace removes the last
document.querySelectorAll("[data-if-tags]").forEach(function (wrap) {
var input = wrap.querySelector("input");
var list = wrap.querySelector(".if-tag-list");
if (!input || !list) return;
function addChip(value) {
value = (value || "").trim();
if (!value) return;
var chip = document.createElement("span");
chip.className = "if-tag-chip";
chip.textContent = value + " ";
var x = document.createElement("button");
x.type = "button";
x.setAttribute("aria-label", "Remove tag " + value);
x.textContent = "×";
x.addEventListener("click", function () {
chip.remove();
});
chip.appendChild(x);
list.appendChild(chip);
}
input.addEventListener("keydown", function (e) {
if (e.key === "Enter" || e.key === ",") {
e.preventDefault();
addChip(input.value);
input.value = "";
} else if (e.key === "Backspace" && !input.value) {
var last = list.querySelector(".if-tag-chip:last-child");
if (last) last.remove();
}
});
});