  </div><!-- /.dfp-main -->
</div><!-- /.dfp-container -->

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.8/css/jquery.dataTables.min.css">

<script>
// ---- Hamburger toggle ----
document.addEventListener('click', function (e) {
  if (e.target && e.target.id === 'dfpHamburgerBtn') {
    document.getElementById('dfpSidebar').classList.toggle('open');
  } else if (!e.target.closest('.dfp-sidebar') && !e.target.closest('#dfpHamburgerBtn')) {
    document.getElementById('dfpSidebar').classList.remove('open');
  }
});

// ---- Center-screen toast helper ----
// Usage: dfpToast('Saved successfully', 'success'); dfpToast('Something went wrong', 'error');
var dfpToastTimer = null;
function dfpToast(message, type) {
  type = type || 'info';
  var box = document.getElementById('dfpToastBox');
  var wrap = document.getElementById('dfpToastWrap');
  box.className = 'dfp-toast ' + type;
  box.innerText = message;
  wrap.style.display = 'block';
  if (dfpToastTimer) { clearTimeout(dfpToastTimer); }
  dfpToastTimer = setTimeout(function () {
    wrap.style.display = 'none';
    box.innerText = '';
  }, 2500);
}

// ---- Prevent double-click submits on any .btn / [type=submit] ----
document.addEventListener('click', function (e) {
  var el = e.target.closest('.btn, button[type=submit], input[type=submit]');
  if (el) {
    if (el.dataset.dfpLock === '1') {
      e.preventDefault();
      return;
    }
    el.dataset.dfpLock = '1';
    setTimeout(function () { el.dataset.dfpLock = '0'; }, 1200);
  }
});

// ---- Common column-filter wiring for DataTables (event delegation) ----
// Call dfpEnableColumnFilters('#mytable') after initializing DataTable with a filter-row in <thead>.
function dfpEnableColumnFilters(tableSelector) {
  $(document).on('keyup change', tableSelector + ' thead tr.filterrow input, ' + tableSelector + ' thead tr.filterrow select', function () {
    var table = $(tableSelector).DataTable();
    var colIndex = $(this).closest('th').index();
    table.column(colIndex).search(this.value).draw();
  });
}

// ---- Common periodic dashboard stats loader (requirement #41) ----
// Usage on a dashboard page:
//   dfpStartAutoRefresh('ajax_admin_dashboardstats.php', function(data){ ...update DOM... }, 60000);
function dfpStartAutoRefresh(ajaxurl, onData, intervalms) {
  intervalms = intervalms || 60000;
  function load() {
    $.getJSON(ajaxurl, function (resp) {
      if (resp && resp.success) {
        onData(resp.data);
      }
    });
  }
  load(); // initial load on page open
  return setInterval(load, intervalms);
}
</script>

<!-- Page-specific JS goes below this line, then footer2.php closes the document -->
