(()=>{const label=document.querySelector('#room-label'),code=document.querySelector('#room-code');if(!label||!code)return;let manual=code.hasAttribute('data-existing');const normalize=value=>value.normalize('NFD').replace(/[\u0300-\u036f]/g,'').toUpperCase().replace(/[^A-Z0-9]+/g,'-').replace(/^-|-$/g,'').slice(0,24);const refresh=()=>{if(manual)return;const map={musique:'MUS',theatre:'THE',dessin:'ART'};const activities=[...document.querySelectorAll('[name="room_activities[]"]:checked')].map(input=>map[input.value]);code.value=['SAL',...activities,normalize(label.value)].filter(Boolean).join('-')};label.addEventListener('input',refresh);document.querySelectorAll('[name="room_activities[]"]').forEach(input=>input.addEventListener('change',refresh));code.addEventListener('input',()=>manual=code.value.trim()!=='');refresh()})();
