<?php
$file = 'admin.php';
$content = file_get_contents($file);

$js = "
        function toggleMS(id) {
            const d = document.getElementById(id);
            d.style.display = d.style.display === 'block' ? 'none' : 'block';
        }
        function updateMSLabel(containerId) {
            const container = document.getElementById(containerId);
            const checkboxes = container.querySelectorAll('input[type=\"checkbox\"]:checked');
            const display = container.querySelector('.ms-display');
            if (checkboxes.length === 0) {
                display.innerText = \"Toutes / Peu importe\";
            } else {
                const labels = Array.from(checkboxes).map(cb => cb.parentElement.innerText.trim());
                display.innerText = labels.join(', ');
            }
        }
        document.addEventListener('click', function(e) {
            if (!e.target.closest('.ms-container')) {
                document.querySelectorAll('.ms-dropdown').forEach(d => d.style.display = 'none');
            }
        });
        </script>";

$content = str_replace('    </script>', $js, $content);

file_put_contents($file, $content);
echo "JS patched";
?>
