(()=>{const list=document.querySelector('#slot-list'),tpl=document.querySelector('#slot-template'),add=document.querySelector('#add-slot');if(!list||!tpl||!add)return;let next=list.querySelectorAll('[data-slot]').length;const refresh=()=>{const rows=[...list.querySelectorAll('[data-slot]')];rows.forEach((row,i)=>{const title=row.querySelector('[data-slot-title]');if(title)title.textContent=`Créneau ${i+1}`;const remove=row.querySelector('[data-remove-slot]');if(remove)remove.disabled=rows.length===1;});};add.addEventListener('click',()=>{const html=tpl.innerHTML.replaceAll('__INDEX__',String(next++));list.insertAdjacentHTML('beforeend',html);refresh();list.lastElementChild?.scrollIntoView({behavior:'smooth',block:'center'});});list.addEventListener('click',e=>{const button=e.target.closest('[data-remove-slot]');if(!button)return;if(list.querySelectorAll('[data-slot]').length<=1)return;button.closest('[data-slot]')?.remove();refresh();});refresh();})();
