<?php
require_once "includes/auth.php";
require_once "config/db.php";

$adherents = $pdo->query("SELECT COUNT(*) FROM Adherent")->fetchColumn();
$seances   = $pdo->query("SELECT COUNT(*) FROM Seance")->fetchColumn();
$resas    = $pdo->query("SELECT COUNT(*) FROM Reservation")->fetchColumn();
$abos     = $pdo->query("SELECT COUNT(*) FROM Abonnement WHERE etat='Valide'")->fetchColumn();
$ca       = $pdo->query("SELECT SUM(prix_paye) FROM Abonnement WHERE etat='Valide'")->fetchColumn();
$abosexpire = $pdo->query("SELECT COUNT(*) FROM Abonnement WHERE etat='Expiré' AND date_fin < CURDATE()")->fetchColumn();

include "includes/header.php";
include "includes/menu.php";
?>
<style>
.hero-dashboard{
    background:url("assets/img/colvert_sport.jpg") center/cover no-repeat;
    border-radius:20px;
    color:white;
    padding:40px;
    position:relative;
}
.hero-dashboard::after{
    content:"";
    position:absolute;
    inset:0;
    background:rgba(0,0,0,0.55);
    border-radius:20px;
}
.hero-content{position:relative;z-index:2;}
.stat-card{border-radius:16px;}
</style>

<div class="hero-dashboard mb-4">
    <div class="hero-content">
        <h2>🏋️ Bienvenue <?= $_SESSION['user']['login'] ?></h2>
        <p>Tableau de bord – Salle de Sport Marc Colvert</p>
    </div>
</div>

<div class="row">
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Adhérents</h6><h2><?= $adherents ?></h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Séances</h6><h2><?= $seances ?></h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Réservations</h6><h2><?= $resas ?></h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Abonnements actifs</h6><h2><?= $abos ?></h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Chiffre d'affaires</h6><h2><?= number_format($ca, 2) ?> €</h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Panier Moyen</h6><h2><?= number_format($ca / max($abos, 1), 2) ?> €</h2></div></div>
<div class="col-md-3 mb-3"><div class="card stat-card shadow p-3 text-center"><h6>Abonnements Expirés</h6><h2><?= $abosexpire ?></h2></div></div>
</div>
<div class="hero-banner">
    <div class="hero-banner-content">
        <div>
            <h1>🏋️ Salle de Sport Marc Colvert</h1>
            <p>
                Motivation • Performance • Bonne humeur
            </p>
        </div>
    </div>
</div>

<?php include "includes/footer.php"; ?>
