<?php require_once __DIR__ . '/_sidebar.php'; ?>
<main class="flex-1 py-16 md:py-0 md:pl-64">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 md:py-16">
        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8">
            <div>
                <h1 class="text-2xl font-bold text-slate-900">Testimonials</h1>
                <p class="text-sm text-slate-500 mt-1">Manage client testimonials and reviews.</p>
            </div>
            <a href="<?= htmlspecialchars($baseUrl) ?>/admin/testimonials/create" class="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-gradient-to-r from-[#FF007A] to-[#D87AA8] text-white text-sm font-semibold shadow-lg shadow-[#FF007A]/20 hover:shadow-xl hover:shadow-[#FF007A]/40 hover:-translate-y-0.5 transition-all duration-300">
                <span class="material-symbols-outlined text-base">add</span>
                New Testimonial
            </a>
        </div>

        <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">
            <div class="overflow-x-auto">
                <table class="w-full text-left text-sm">
                    <thead class="bg-slate-50 border-b border-slate-200">
                        <tr>
                            <th class="px-6 py-4 font-semibold text-slate-900">Client</th>
                            <th class="px-6 py-4 font-semibold text-slate-900">Company</th>
                            <th class="px-6 py-4 font-semibold text-slate-900">Rating</th>
                            <th class="px-6 py-4 font-semibold text-slate-900">Status</th>
                            <th class="px-6 py-4 font-semibold text-slate-900 text-right">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-slate-100">
                        <?php if (empty($items)): ?>
                            <tr>
                                <td colspan="5" class="px-6 py-10 text-center text-slate-500">No testimonials yet. Add your first testimonial.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach ($items as $item): ?>
                            <tr class="hover:bg-slate-50/60 transition-colors">
                                <td class="px-6 py-4">
                                    <div class="font-semibold text-slate-900"><?= htmlspecialchars($item['client_name']) ?></div>
                                </td>
                                <td class="px-6 py-4 text-slate-500"><?= htmlspecialchars($item['company'] ?? '—') ?></td>
                                <td class="px-6 py-4">
                                    <div class="flex items-center gap-1 text-amber-500">
                                        <?= str_repeat('★', (int)($item['rating'] ?? 5)) ?>
                                    </div>
                                </td>
                                <td class="px-6 py-4">
                                    <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium <?= $item['status'] === 'published' ? 'bg-green-50 text-green-700' : 'bg-amber-50 text-amber-700' ?>">
                                        <?= htmlspecialchars(ucfirst($item['status'])) ?>
                                    </span>
                                </td>
                                <td class="px-6 py-4 text-right">
                                    <div class="flex items-center justify-end gap-2">
                                        <a href="<?= htmlspecialchars($baseUrl) ?>/admin/testimonials/edit?id=<?= (int)$item['id'] ?>" class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-slate-100 text-slate-700 hover:bg-slate-200 transition text-xs font-medium">
                                            <span class="material-symbols-outlined text-sm">edit</span>
                                            Edit
                                        </a>
                                        <form method="post" action="<?= htmlspecialchars($baseUrl) ?>/admin/testimonials/delete" class="inline" onsubmit="return confirm('Delete this testimonial?');">
                                            <?= CSRF::input() ?>
                                            <input type="hidden" name="id" value="<?= (int)$item['id'] ?>">
                                            <button type="submit" class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-rose-50 text-rose-700 hover:bg-rose-100 transition text-xs font-medium">
                                                <span class="material-symbols-outlined text-sm">delete</span>
                                                Delete
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</main>
</div>
