document.addEventListener('DOMContentLoaded', function () {
  var btn = document.getElementById('btnToggleSidebar');
  var sidebar = document.getElementById('sidebar');
  if (btn && sidebar) {
    btn.addEventListener('click', function () {
      sidebar.classList.toggle('show');
    });
  }
});

/** Configuracion comun para tablas server-side de DataTables. */
function initServerTable(selector, ajaxUrl, columns, extraParams) {
  return new DataTable(selector, {
    processing: true,
    serverSide: true,
    ajax: {
      url: ajaxUrl,
      data: function (d) {
        if (typeof extraParams === 'function') {
          Object.assign(d, extraParams());
        }
      },
    },
    columns: columns,
    language: {
      url: 'https://cdn.datatables.net/plug-ins/1.13.11/i18n/es-ES.json',
    },
    pageLength: 25,
    lengthMenu: [10, 25, 50, 100],
  });
}
