<?php require_once '../app/Views/topo.php'; ?>

<div class="container mt-4">
    <h3 class="mb-4">Comprovantes Anexados</h3>

    <?php if (!empty($comprovantes)) : ?>
        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead class="thead-dark">
                    <tr>
                        <th>ID</th>
                        <th>Arquivo</th>
                        <th>Visualizar</th>
                        <th>Baixar</th>
                        <th>Data de Envio</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($comprovantes as $comp) : ?>
                        <tr>
                            <td><?= $comp->id_comprovante ?></td>
                            <td><?= htmlspecialchars($comp->arquivo) ?></td>
                            <td>
                                <?php 
                                $extensao = pathinfo($comp->arquivo, PATHINFO_EXTENSION);
                                $visualizavel = in_array(strtolower($extensao), ['jpg', 'jpeg', 'png', 'gif', 'pdf']);
                                ?>
                                <?php if ($visualizavel) : ?>
                                    <a class="btn btn-sm btn-info" target="_blank" href="<?= URL ?>/comprovantes_prestacao/<?= $comp->arquivo ?>">Abrir</a>
                                <?php else : ?>
                                    <span class="text-muted">Não visualizável</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <a class="btn btn-sm btn-primary" href="<?= URL ?>/prestacaocomprovante/baixar/<?= $comp->arquivo ?>">Download</a>
                            </td>
                            <td><?= date('d/m/Y H:i', strtotime($comp->criado_em)) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php else : ?>
        <div class="alert alert-warning">Nenhum comprovante anexado.</div>
    <?php endif; ?>

    
 <a href="<?= URL ?>/prestacao_contas/index/<?= $id_prestacao ?>" class="btn btn-secondary mt-3">
    <i class="bi bi-arrow-left"></i> Voltar
</a>

</div>

<?php require_once '../app/Views/rodape.php'; ?>
