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

<section class="panel">
    <p class="eyebrow">Administracao</p>
    <h1>Avaliacoes</h1>
    <p>Modere comentarios sem bloquear publicacao inicial dos alunos.</p>

    <form class="filterbar simple" method="get" action="/admin/reviews">
        <input name="search" placeholder="Pesquisar por aluno, curso ou comentario" value="<?= e($filters['search']) ?>">
        <select name="status">
            <option value="">Todos estados</option>
            <option value="active" <?= $filters['status'] === 'active' ? 'selected' : '' ?>>Activas</option>
            <option value="hidden" <?= $filters['status'] === 'hidden' ? 'selected' : '' ?>>Ocultas</option>
        </select>
        <button class="button" type="submit">Filtrar</button>
    </form>

    <div class="table-wrap">
        <table>
            <thead>
                <tr>
                    <th>Curso</th>
                    <th>Aluno</th>
                    <th>Nota</th>
                    <th>Comentario</th>
                    <th>Estado</th>
                    <th>Accoes</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!$reviews): ?>
                    <tr><td colspan="6">Nenhuma avaliacao encontrada.</td></tr>
                <?php endif; ?>
                <?php foreach ($reviews as $review): ?>
                    <tr>
                        <td><?= e($review['course_title']) ?></td>
                        <td>
                            <?= e($review['student_name']) ?>
                            <span class="muted"><?= e($review['student_email']) ?></span>
                        </td>
                        <td><span class="stars"><?= e((string) $review['rating']) ?>/5</span></td>
                        <td><?= e($review['comment'] ?: '-') ?></td>
                        <td><span class="badge <?= e($review['status']) ?>"><?= e($review['status'] === 'active' ? 'Activa' : 'Oculta') ?></span></td>
                        <td>
                            <div class="row-actions">
                                <?php if ($review['status'] === 'active'): ?>
                                    <form method="post" action="/admin/reviews/hide">
                                        <?= csrf_field() ?>
                                        <input type="hidden" name="id" value="<?= e((string) $review['id']) ?>">
                                        <button class="mini-button danger" type="submit">Ocultar</button>
                                    </form>
                                <?php else: ?>
                                    <form method="post" action="/admin/reviews/activate">
                                        <?= csrf_field() ?>
                                        <input type="hidden" name="id" value="<?= e((string) $review['id']) ?>">
                                        <button class="mini-button good" type="submit">Reactivar</button>
                                    </form>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>

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