<?php
require_once '../session.php';
require_once '../db.php';

// Sécurité stricte : Vérification des droits admin
if (!isset($_SESSION['user_id']) || (isset($_SESSION['role']) && $_SESSION['role'] !== 'admin')) {
    header('Location: ../index.php');
    exit;
}

// On récupère les statistiques d'origine pour la vue d'ensemble
try {
    $countParcs = $pdo->query("SELECT COUNT(*) FROM parcs")->fetchColumn();
    $countUsers = $pdo->query("SELECT COUNT(*) FROM utilisateurs")->fetchColumn();
} catch (PDOException $e) {
    $countParcs = 0;
    $countUsers = 0;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Administration | ParcoTrip</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body>

    <!-- NAVBAR ADMIN CENTRALISÉE ET AUTONOME -->
    <?php include_once 'sidebaradmin.php'; ?>

    <main class="container" style="min-height: 70vh; padding: 60px 20px; max-width: 1200px; margin: 0 auto; box-sizing: border-box;">
        
        <div style="background: linear-gradient(135deg, #fff5f5 0%, #ffe3e3 100%); padding: 40px; border-radius: 24px; border: 1px solid #ffa8a8; margin-bottom: 40px;">
            <span style="color: #ff4757; font-weight: 700; text-transform: uppercase; font-size: 0.85rem; letter-spacing: 1px;">Console de Gestion Globale</span>
            <h1 style="font-size: 2.3rem; font-weight: 800; color: #2b2b2b; margin: 10px 0 8px 0;">Panneau d'Administration 🔐</h1>
            <p style="color: #4e4e4e; font-size: 1.05rem; margin: 0; max-width: 700px;">Bienvenue dans votre espace de contrôle. Modifiez les parcs, gérez les droits des utilisateurs et supervisez l'état global de l'application ParcoTrip.</p>
        </div>

        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 30px; margin-top: 20px;">
            
            <!-- Widget Parcs d'origine -->
            <div style="background: #ffffff; border: 1px solid #e2e8f0; padding: 35px; border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.01);">
                <div style="font-size: 2.2rem; color: #ff4757; margin-bottom: 15px;"><i class="fa-solid fa-fort-awesome"></i></div>
                <h3 style="font-size: 1.25rem; font-weight: 800; margin: 0 0 5px 0;">Gestion des parcs</h3>
                <p style="color: #64748b; font-size: 13px; margin-bottom: 20px;">Total : <strong><?php echo $countParcs; ?></strong> parcs référencés.</p>
                <a href="parcs.php" class="btn-primary" style="display: inline-block; padding: 10px 20px; font-size: 0.9rem; background-color: #111; color: #fff; border-radius: 8px; text-decoration: none; font-weight: 700;">Ouvrir la gestion</a>
            </div>

            <!-- Widget Utilisateurs d'origine -->
            <div style="background: #ffffff; border: 1px solid #e2e8f0; padding: 35px; border-radius: 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.01);">
                <div style="font-size: 2.2rem; color: #4a51ff; margin-bottom: 15px;"><i class="fa-solid fa-users-gear"></i></div>
                <h3 style="font-size: 1.25rem; font-weight: 800; margin: 0 0 5px 0;">Comptes utilisateurs</h3>
                <p style="color: #64748b; font-size: 13px; margin-bottom: 20px;">Total : <strong><?php echo $countUsers; ?></strong> membres inscrits.</p>
                <a href="users.php" class="btn-secondary" style="display: inline-block; padding: 10px 20px; font-size: 0.9rem; border: 2px solid #e2e8f0; color: #111; border-radius: 8px; font-weight: 700; text-decoration: none;">Voir les profils</a>
            </div>

        </div>

    </main>

    <footer class="main-footer" style="margin-top: 80px; border-top: 1px solid rgba(0,0,0,0.06); padding: 40px 0; text-align: center;">
        <p style="color: #94a3b8; font-size: 0.88rem;">&copy; 2026 ParcoTrip Infrastructure • Terminal Admin Sécurisé.</p>
    </footer>

</body>
</html>