<?php ob_start(); ?>

<div class="mb-6 flex justify-between items-center">
    <div>
        <p class="text-gray-600">
            <?= count($agents) ?> / <?= $entreprise['max_agents'] ?> agents
        </p>
    </div>
    <a href="<?= BASE_URL ?>/admin/agents/create" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition flex items-center">
        <i class="fas fa-plus mr-2"></i>Nouvel agent
    </a>
</div>

<div class="bg-white rounded-xl shadow-sm border border-gray-100">
    <div class="p-6">
        <?php if (empty($agents)): ?>
            <div class="text-center py-12">
                <div class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-users text-2xl text-gray-400"></i>
                </div>
                <p class="text-gray-500">Aucun agent pour le moment</p>
                <a href="<?= BASE_URL ?>/admin/agents/create" class="inline-flex items-center mt-4 text-indigo-600 hover:text-indigo-800">
                    <i class="fas fa-plus mr-2"></i>Créer le premier agent
                </a>
            </div>
        <?php else: ?>
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                <?php foreach ($agents as $agent): ?>
                <div class="border border-gray-200 rounded-lg p-4 hover:border-indigo-300 transition">
                    <div class="flex items-start justify-between mb-3">
                        <div class="flex items-center">
                            <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-user text-indigo-600"></i>
                            </div>
                            <div>
                                <p class="font-medium text-gray-800"><?= htmlspecialchars($agent['prenom'] . ' ' . $agent['nom']) ?></p>
                                <p class="text-sm text-gray-500"><?= htmlspecialchars($agent['email']) ?></p>
                            </div>
                        </div>
                        <span class="w-3 h-3 rounded-full <?= $agent['is_online'] ? 'bg-green-500' : 'bg-gray-300' ?>"
                              title="<?= $agent['is_online'] ? 'En ligne' : 'Hors ligne' ?>"></span>
                    </div>
                    
                    <div class="flex items-center justify-between text-sm">
                        <span class="text-gray-500">
                            <i class="fas fa-phone mr-1"></i><?= htmlspecialchars($agent['telephone'] ?? '-') ?>
                        </span>
                        <span class="px-2 py-1 rounded-full text-xs <?= $agent['is_active'] ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' ?>">
                            <?= $agent['is_active'] ? 'Actif' : 'Inactif' ?>
                        </span>
                    </div>
                    
                    <div class="mt-4 pt-3 border-t border-gray-100 flex justify-end space-x-2">
                        <a href="<?= BASE_URL ?>/admin/agents/<?= $agent['id'] ?>" 
                           class="p-2 text-indigo-600 hover:bg-indigo-50 rounded-lg" title="Modifier">
                            <i class="fas fa-edit"></i>
                        </a>
                        <form action="<?= BASE_URL ?>/admin/agents/<?= $agent['id'] ?>/delete" method="POST" class="inline"
                              onsubmit="return confirm('Supprimer cet agent ?')">
                            <button type="submit" class="p-2 text-red-600 hover:bg-red-50 rounded-lg" title="Supprimer">
                                <i class="fas fa-trash"></i>
                            </button>
                        </form>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</div>

<?php 
$content = ob_get_clean();
$title = 'Agents - ' . APP_NAME;
$pageTitle = 'Gestion des Agents';
include VIEWS_PATH . '/layouts/main.php';
?>
