<?php ob_start(); ?>

<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
    <?php foreach ($stats as $stat): ?>
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
        <div class="flex items-center justify-between mb-4">
            <h3 class="text-lg font-semibold text-gray-800">
                <?= htmlspecialchars($stat['entreprise']['nom']) ?>
            </h3>
            <span class="px-2 py-1 text-xs rounded-full 
                <?= $stat['entreprise']['type_abonnement'] === 'enterprise' ? 'bg-purple-100 text-purple-700' : 
                   ($stat['entreprise']['type_abonnement'] === 'pro' ? 'bg-blue-100 text-blue-700' : 'bg-gray-100 text-gray-700') ?>">
                <?= ucfirst($stat['entreprise']['type_abonnement']) ?>
            </span>
        </div>
        
        <div class="grid grid-cols-2 gap-4">
            <div class="p-3 bg-gray-50 rounded-lg">
                <p class="text-sm text-gray-500">Total conversations</p>
                <p class="text-2xl font-bold text-gray-800"><?= number_format($stat['conversations']['total'] ?? 0) ?></p>
            </div>
            <div class="p-3 bg-green-50 rounded-lg">
                <p class="text-sm text-gray-500">Résolues</p>
                <p class="text-2xl font-bold text-green-600"><?= number_format($stat['conversations']['resolues'] ?? 0) ?></p>
            </div>
            <div class="p-3 bg-yellow-50 rounded-lg">
                <p class="text-sm text-gray-500">En cours</p>
                <p class="text-2xl font-bold text-yellow-600"><?= number_format($stat['conversations']['en_cours'] ?? 0) ?></p>
            </div>
            <div class="p-3 bg-red-50 rounded-lg">
                <p class="text-sm text-gray-500">Escaladées</p>
                <p class="text-2xl font-bold text-red-600"><?= number_format($stat['conversations']['escaladees'] ?? 0) ?></p>
            </div>
        </div>
        
        <?php if ($stat['conversations']['satisfaction_moyenne']): ?>
        <div class="mt-4 pt-4 border-t border-gray-100">
            <div class="flex items-center justify-between">
                <span class="text-sm text-gray-500">Satisfaction moyenne</span>
                <div class="flex items-center">
                    <?php for ($i = 1; $i <= 5; $i++): ?>
                        <i class="fas fa-star <?= $i <= round($stat['conversations']['satisfaction_moyenne']) ? 'text-yellow-400' : 'text-gray-300' ?>"></i>
                    <?php endfor; ?>
                    <span class="ml-2 text-sm font-medium"><?= number_format($stat['conversations']['satisfaction_moyenne'], 1) ?>/5</span>
                </div>
            </div>
        </div>
        <?php endif; ?>
    </div>
    <?php endforeach; ?>
</div>

<?php if (empty($stats)): ?>
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-12 text-center">
    <div class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4">
        <i class="fas fa-chart-bar text-2xl text-gray-400"></i>
    </div>
    <p class="text-gray-500">Aucune statistique disponible</p>
</div>
<?php endif; ?>

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