<?php include app()->basePath('app/Views/partials/header.php'); ?>

<section class="panel">
    <p class="eyebrow">Administracao</p>
    <h1>Certificados</h1>
    <p>Controle certificados emitidos, codigos de validacao e reemissoes.</p>

    <form class="filterbar simple" method="get" action="/admin/certificates">
        <input name="search" placeholder="Pesquisar por aluno, curso ou codigo" value="<?= e($filters['search']) ?>">
        <button class="button" type="submit">Pesquisar</button>
    </form>

    <div class="table-wrap">
        <table>
            <thead>
                <tr>
                    <th>Numero</th>
                    <th>Aluno</th>
                    <th>Curso</th>
                    <th>Emissor</th>
                    <th>Data</th>
                    <th>Accoes</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!$certificates): ?>
                    <tr><td colspan="6">Nenhum certificado encontrado.</td></tr>
                <?php endif; ?>
                <?php foreach ($certificates as $certificate): ?>
                    <tr>
                        <td>
                            <strong><?= e($certificate['certificate_number']) ?></strong>
                            <span class="muted"><?= e($certificate['validation_code']) ?></span>
                        </td>
                        <td>
                            <?= e($certificate['student_name']) ?>
                            <span class="muted"><?= e($certificate['student_email']) ?></span>
                        </td>
                        <td><?= e($certificate['course_title']) ?></td>
                        <td><?= e($certificate['issuer_name']) ?></td>
                        <td><?= e(format_date($certificate['issued_at'])) ?></td>
                        <td>
                            <div class="row-actions">
                                <a class="mini-button" href="/certificates/show?id=<?= e((string) $certificate['id']) ?>">Ver</a>
                                <a class="mini-button" href="/certificates/pdf?id=<?= e((string) $certificate['id']) ?>">PDF</a>
                                <form method="post" action="/admin/certificates/reissue">
                                    <?= csrf_field() ?>
                                    <input type="hidden" name="id" value="<?= e((string) $certificate['id']) ?>">
                                    <button class="mini-button" type="submit">Reemitir</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>

<?php include app()->basePath('app/Views/partials/footer.php'); ?>
