(() => {
    const select=document.getElementById('communication-template');
    const subject=document.getElementById('communication-subject');
    const html=document.getElementById('communication-html');
    const text=document.getElementById('communication-text');

    if(!select){
        return;
    }

    select.addEventListener('change',() => {
        const option=select.selectedOptions[0];

        if(!option || !option.value){
            return;
        }

        subject.value=option.dataset.object || '';
        html.value=option.dataset.html || '';
        text.value=option.dataset.text || '';
    });
})();
