<!-- Testimonials Management -->
<div class="admin-section">
    <div class="admin-section-header">
        <span class="admin-text-muted">Review and approve student testimonials</span>
    </div>

    <!-- Testimonials Table -->
    <?php if (!empty($testimonials)): ?>
    <div class="admin-card">
        <div class="admin-card-body">
            <div class="admin-table-responsive">
                <table class="admin-table" data-search="true">
                    <thead>
                        <tr>
                            <th>Student</th>
                            <th>Course</th>
                            <th>Rating</th>
                            <th>Review</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($testimonials as $t): ?>
                        <tr>
                            <td>
                                <strong><?= htmlspecialchars($t['name'], ENT_QUOTES, 'UTF-8') ?></strong>
                            </td>
                            <td><?= htmlspecialchars($t['course_name'] ?? '—', ENT_QUOTES, 'UTF-8') ?></td>
                            <td>
                                <span class="admin-stars">
                                    <?php for ($i = 1; $i <= 5; $i++): ?>
                                    <?php if ($i <= (int) ($t['rating'] ?? 5)): ?>
                                    <span class="admin-star admin-star-filled">&#9733;</span>
                                    <?php else: ?>
                                    <span class="admin-star">&#9733;</span>
                                    <?php endif; ?>
                                    <?php endfor; ?>
                                </span>
                            </td>
                            <td>
                                <span class="admin-review-preview" title="<?= htmlspecialchars($t['review'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
                                    <?= htmlspecialchars(mb_substr($t['review'] ?? '', 0, 80) . (mb_strlen($t['review'] ?? '') > 80 ? '...' : ''), ENT_QUOTES, 'UTF-8') ?>
                                </span>
                            </td>
                            <td>
                                <?php if ($t['is_approved']): ?>
                                <span class="admin-badge admin-badge-success">Approved</span>
                                <?php else: ?>
                                <span class="admin-badge admin-badge-warning">Pending</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="admin-actions">
                                    <?php if (!$t['is_approved']): ?>
                                    <form method="POST" action="<?= url('/admin/testimonials/' . (int)$t['id'] . '/approve') ?>" style="display:inline">
                                        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">
                                        <button type="submit" class="admin-btn admin-btn-sm admin-btn-success" title="Approve">
                                            &#10003; Approve
                                        </button>
                                    </form>
                                    <?php else: ?>
                                    <form method="POST" action="<?= url('/admin/testimonials/' . (int)$t['id'] . '/reject') ?>" style="display:inline">
                                        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">
                                        <button type="submit" class="admin-btn admin-btn-sm admin-btn-warning" title="Reject">
                                            &#10007; Reject
                                        </button>
                                    </form>
                                    <?php endif; ?>
                                    <form method="POST" action="<?= url('/admin/testimonials/' . (int)$t['id'] . '/delete') ?>" style="display:inline">
                                        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">
                                        <button type="submit" class="admin-btn admin-btn-sm admin-btn-danger" title="Delete"
                                                data-confirm-delete>
                                            Delete
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php else: ?>
    <div class="admin-card">
        <div class="admin-card-body">
            <p class="admin-empty-text">No testimonials found.</p>
        </div>
    </div>
    <?php endif; ?>
</div>
