<?php
require_once "../includes/config.php";
require_once "../includes/functions.php";

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Get today's champion
$todaysChampion = getTodaysChampion($pdo);
$championId = $todaysChampion['id'];

// Get champion stats
$stmt = $pdo->prepare("SELECT total_xp, level FROM champion_stats WHERE champion_id = ?");
$stmt->execute([$championId]);
$stats = $stmt->fetch();

$totalXP = $stats ? $stats['total_xp'] : 0;
$level   = $stats ? $stats['level'] : 1;

// Get today's habits
$habits = getHabitsForToday($pdo);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Dashboard</title>
    <link rel="stylesheet" href="../assets/css/style.css">
</head>
<body>

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

<h1>Today's Champion: <?= htmlspecialchars($todaysChampion['name']) ?></h1>
<p>Level: <?= $level ?></p>
<p>XP: <?= $totalXP ?> / <?= getXPForNextLevel($level) ?></p>

<h2>Today's Habits</h2>
<?php if (empty($habits)): ?>
    <p>No habits today.</p>
<?php else: ?>
    <ul>
        <?php foreach ($habits as $habit): ?>
            <li><?= htmlspecialchars($habit['title']) ?> (<?= $habit['xp_reward'] ?> XP)</li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

</body>
</html>