document.addEventListener('DOMContentLoaded', () => {
  const driver = document.querySelector('[name="mail_driver"]');
  const smtpFields = document.querySelector('[data-smtp-fields]');
  const toggle = () => {
    if (!driver || !smtpFields) return;
    smtpFields.hidden = driver.value !== 'smtp';
  };
  driver?.addEventListener('change', toggle);
  toggle();

  document.querySelectorAll('[data-confirm]').forEach((el) => {
    el.addEventListener('click', (event) => {
      if (!window.confirm(el.getAttribute('data-confirm'))) event.preventDefault();
    });
  });
});
