/**
 * Dashboard filter functionality
 * Part of Valserv Analytics for SentinelPro plugin
 */
document.addEventListener("DOMContentLoaded", function() {
    // Referrer filter controls
    var referrerSelectAllBtn = document.querySelector(".sentinelpro-referrer-select-all");
    var referrerDeselectAllBtn = document.querySelector(".sentinelpro-referrer-deselect-all");
    var referrerCheckboxes = document.querySelectorAll(".sentinelpro-referrer-checkboxes input[type=checkbox]");
    
    if (referrerSelectAllBtn) {
        referrerSelectAllBtn.onclick = function() { 
            referrerCheckboxes.forEach(cb => cb.checked = true); 
        };
    }
    if (referrerDeselectAllBtn) {
        referrerDeselectAllBtn.onclick = function() { 
            referrerCheckboxes.forEach(cb => cb.checked = false); 
        };
    }

    // OS filter controls
    var osSelectAllBtn = document.querySelector(".sentinelpro-os-select-all");
    var osDeselectAllBtn = document.querySelector(".sentinelpro-os-deselect-all");
    var osCheckboxes = document.querySelectorAll(".sentinelpro-os-checkboxes input[type=checkbox]");
    
    if (osSelectAllBtn) {
        osSelectAllBtn.onclick = function() { 
            osCheckboxes.forEach(cb => cb.checked = true); 
        };
    }
    if (osDeselectAllBtn) {
        osDeselectAllBtn.onclick = function() { 
            osCheckboxes.forEach(cb => cb.checked = false); 
        };
    }

    // Browser filter controls
    var browserSelectAllBtn = document.querySelector(".sentinelpro-browser-select-all");
    var browserDeselectAllBtn = document.querySelector(".sentinelpro-browser-deselect-all");
    var browserCheckboxes = document.querySelectorAll(".sentinelpro-browser-checkboxes input[type=checkbox]");
    
    if (browserSelectAllBtn) {
        browserSelectAllBtn.onclick = function() { 
            browserCheckboxes.forEach(cb => cb.checked = true); 
        };
    }
    if (browserDeselectAllBtn) {
        browserDeselectAllBtn.onclick = function() { 
            browserCheckboxes.forEach(cb => cb.checked = false); 
        };
    }
});
