<?php
declare(strict_types=1);
require_once __DIR__ . "/config/database.php";
require_once __DIR__ . "/includes/auth.php";
require_once __DIR__ . "/includes/helpers.php";
requireAuth();

$userId = (int) ($_SESSION["user_id"] ?? 0);
$stmt = $pdo->prepare("SELECT nom, email, role, created_at FROM utilisateurs WHERE id = :id LIMIT 1");
$stmt->execute(["id" => $userId]);
$user = $stmt->fetch();

if (!$user) {
    setFlash("error", "Profil introuvable.");
    redirect("/PIS/index.php");
}

require_once __DIR__ . "/includes/header.php";
?>
<h2>Mon profil</h2>
<div class="card">
    <p><strong>Nom:</strong> <?= htmlspecialchars($user["nom"]) ?></p>
    <p><strong>Email:</strong> <?= htmlspecialchars($user["email"]) ?></p>
    <p><strong>Role:</strong> <?= htmlspecialchars($user["role"]) ?></p>
    <p><strong>Compte cree le:</strong> <?= htmlspecialchars($user["created_at"]) ?></p>
</div>
<?php require_once __DIR__ . "/includes/footer.php"; ?>
