(() => { const editorSelector = '[data-be-event-editor]'; function showFields(group, visible) { group.hidden = !visible; for (const control of group.querySelectorAll('input, select')) { control.disabled = !visible; } } function updateSchedule(editor) { const allDay = editor.querySelector('[name="be[all_day]"]').checked; for (const time of editor.querySelectorAll('[data-be-time]')) { showFields(time, !allDay); } const repeat = editor.querySelector('[name="be[repeat]"]'); for (const group of editor.querySelectorAll('[data-be-repeat]')) { const mode = group.dataset.beRepeat; showFields(group, mode === repeat.value || (mode === 'enabled' && repeat.value !== 'none')); } editor.querySelector('[data-be-frequency]').textContent = repeat.selectedOptions[0].textContent; } function updateSelection(picker) { const summary = picker.querySelector('[data-be-picker-selection]'); const labels = [...picker.querySelectorAll('[data-be-picker-option] input:checked')] .map(input => input.nextElementSibling.textContent); summary.textContent = labels.join(', ') || summary.dataset.beEmpty; } function initialize() { for (const editor of document.querySelectorAll(editorSelector)) updateSchedule(editor); } document.addEventListener('change', event => { const editor = event.target.closest(editorSelector); if (!editor) return; if (event.target.name === 'be[all_day]' || event.target.name === 'be[repeat]') { updateSchedule(editor); } else if (event.target.closest('[data-be-picker-option]')) { updateSelection(event.target.closest('[data-be-picker]')); } }); document.addEventListener('input', event => { if (!event.target.matches('[data-be-picker-search]')) return; const picker = event.target.closest('[data-be-picker]'); const search = event.target.value.trim().toLocaleLowerCase(); let found = false; for (const option of picker.querySelectorAll('[data-be-picker-option]')) { option.hidden = !option.textContent.toLocaleLowerCase().includes(search); found = found || !option.hidden; } picker.querySelector('[data-be-no-options]').hidden = found; }); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initialize, {once: true}); } else { initialize(); } })();