</div>
    </div>
    </div>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
  
  <script src="js/alerts.js"></script>

  <script type="text/javascript">
    $(document).ready(function() {
      // Initialize DataTable with improved settings
      if ($('#Dtable').length) {
        $('#Dtable').DataTable({
          "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Todos"]],
          "searching": true,
          "paging": true,
          "ordering": true, // Enabled ordering for better UX
          "responsive": true,
          "language": {
            "search": "Pesquisar:",
            "lengthMenu": "Mostrar _MENU_ registros",
            "zeroRecords": "Nenhum registro encontrado",
            "info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
            "infoEmpty": "Mostrando 0 a 0 de 0 registros",
            "infoFiltered": "(filtrado de _MAX_ registros no total)",
            "emptyTable": "Nenhum dado disponível na tabela",
            "loadingRecords": "Carregando...",
            "processing": "Processando...",
            "paginate": {
              "first": "Primeiro",
              "last": "Último",
              "next": "Próximo",
              "previous": "Anterior"
            }
          }
        });
      }

      // Sidebar Toggle
      $("#menu-toggle").on('click', function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("toggled");
      });

      // Auto-dismiss Alerts (Standard Bootstrap alerts)
      $(".alert-dismissible").fadeTo(3000, 500).slideUp(500, function() {
        $(this).alert('close');
      });

      // Delete Confirmation Modal Logic
      $('#confirm-delete').on('show.bs.modal', function(e) {
        var link = $(e.relatedTarget).data('href');
        $(this).find('.btn-ok').attr('href', link);
      });
    });
  </script>

  <?php
  /**
   * Status Alert Mapping
   * 1 = Success, 2 = Deleted/Danger, 3 = Info, 4 = Warning
   */
  if (isset($_GET['status'])) {
      $statusMap = [
          '1' => ['title' => 'Sucesso!', 'msg' => 'Alterações salvas com sucesso.', 'type' => 'success'],
          '2' => ['title' => 'Excluído!', 'msg' => 'Registro removido do sistema.', 'type' => 'danger'],
          '3' => ['title' => 'Aviso',    'msg' => 'Bem-vindo ao painel.', 'type' => 'info'],
          '4' => ['title' => 'Atenção!',  'msg' => 'Verifique todos os campos obrigatórios.', 'type' => 'warning']
      ];

      $status = $_GET['status'];
      if (isset($statusMap[$status])) {
          $alert = $statusMap[$status];
          echo "<script>
              $(document).ready(function() {
                  createAlert('" . $alert['title'] . "', '" . $alert['msg'] . "', '', '" . $alert['type'] . "', true, true, 'pageMessages');
              });
          </script>";
      }
  }
  ?>
</body>
</html>