document.addEventListener('DOMContentLoaded', () => {
    const day = document.querySelector('[name="jour_semaine"]');
    const start = document.querySelector('[name="heure_debut"]');
    const end = document.querySelector('[name="heure_fin"]');
    const preview = document.getElementById('schedulePreview');

    const refresh = () => {
        if (!preview) return;

        const dayLabel =
            day?.selectedOptions?.[0]?.textContent?.trim() || 'Jour';

        preview.textContent =
            dayLabel + ' · ' +
            (start?.value || '--:--') +
            ' à ' +
            (end?.value || '--:--');
    };

    [day, start, end].forEach(element => {
        element?.addEventListener('change', refresh);
        element?.addEventListener('input', refresh);
    });

    refresh();
});
