(function () {
    "use strict";
    document.querySelectorAll("[data-h4bs-staff-directory]").forEach(function (root) {
        const search = root.querySelector("[data-h4bs-staff-search]");
        const cards = Array.from(root.querySelectorAll("[data-h4bs-staff-card]"));
        const empty = root.querySelector("[data-h4bs-staff-empty]");
        const status = root.querySelector("[data-h4bs-staff-status]");
        const apply = function () {
            const query = search ? search.value.trim().toLowerCase() : "";
            let visible = 0;
            cards.forEach(function (card) { const show = !query || String(card.dataset.search || "").includes(query); card.hidden = !show; if (show) visible += 1; });
            root.querySelectorAll("[data-tier]").forEach(function (tier) { tier.hidden = !tier.querySelector("[data-h4bs-staff-card]:not([hidden])"); });
            if (empty) empty.hidden = visible !== 0;
            if (status) status.textContent = visible + (visible === 1 ? " profile shown" : " profiles shown");
        };
        if (search) search.addEventListener("input", apply);
        apply();
    });
}());
