<div class="row my-4">
    <div class="col-md-12">
        <div class="card shadow">
            <div class="card-body">
                <table class="table datatables" id="dataTable-1">
                    <thead class="thead-dark">
                        <tr>
                            <th>N°</th>
                            <th>Expediente</th>
                            <th>Procedimiento</th>
                            <th>Asunto</th>
                            <th>Folios</th>
                            <th>Fecha de Trámite</th>
                            <th>Acciones</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($resolvedProcesses as $index => $process): ?>
                        <tr>
                            <td><?= $index + 1 ?></td>
                            <td><?= htmlspecialchars($process->num_exped) ?></td>
                            <td><?= htmlspecialchars($process->procedure()->description ?? $process->custom_procedure ?? 'Sin procedimiento') ?></td>
                            <td><?= htmlspecialchars($process->subject) ?></td>
                            <td><?= htmlspecialchars($process->folios) ?></td>
                            <td><?= date('d/m/Y', strtotime($process->entry_date)) ?></td>
                            <td>
                                <?php $attachment = $process->getResolutionFile(); ?>
                                <?php if ($attachment): ?>
                                    <a href="<?= BASE_HREF . ltrim($attachment->file_path, '/') ?>" target="_blank" class="btn btn-sm btn-primary">Ver Resolución</a>
                                    <a href="<?= BASE_HREF . ltrim($attachment->file_path, '/') ?>" class="btn btn-sm btn-success" download="<?= htmlspecialchars($attachment->file_name) ?>">Descargar</a>
                                <?php else: ?>
                                    <button class="btn btn-sm btn-secondary" disabled>Sin Resolución</button>
                                <?php endif; ?>
                            </td>

                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
  $(document).ready(function() {    
    $('#dataTable-1').DataTable({
      autoWidth: true,
      "lengthMenu": [
        [10, 15, 20, -1],
        [10, 15, 20, "All"]
      ]
    });
  });
</script>