(function () {
  'use strict';

  var cfg = window.CUSTAUSU_ADMIN_RESET || {};

  function initCasReset() {
    var btn  = document.getElementById('custausu-reset-settings-btn');
    var form = document.getElementById('custausu-reset-settings-form');

    if (!btn || !form) return;

    btn.addEventListener('click', function (ev) {
      ev.preventDefault();

      var ok = window.confirm(
        cfg.confirm_text ||
        'Warning: this will delete all CAS settings currently saved in custausu_global_settings. Do you want to continue?'
      );

      if (!ok) return;
      form.submit();
    });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initCasReset);
  } else {
    initCasReset();
  }
})();