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

$todaysChampion = getTodaysChampion($pdo);
$championId = $todaysChampion['id'];

// Get all bounties
$stmt = $pdo->query("
    SELECT *
    FROM habits
    WHERE is_bounty = 1
    ORDER BY created_at DESC
");
$bounties = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Bounty Board</title>
    <link rel="stylesheet" href="../assets/css/style.css">
    <style>
        .bounty-container {
            width: 900px;
            margin: 0 auto;
            color: #eee;
        }
        .bounty-card {
            background: #1a1a1f;
            border: 1px solid #444;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 12px;
        }
        .bounty-card h3 {
            color: #ffcc66;
            margin: 0 0 6px 0;
        }
        .bounty-meta {
            font-size: 13px;
            color: #ccc;
            margin-bottom: 6px;
        }
        .bounty-card button {
            margin-top: 8px;
            background: #7a0000;
            border: none;
            padding: 8px 12px;
            color: white;
            cursor: pointer;
            border-radius: 4px;
        }
        .bounty-card button:hover {
            background: #a00000;
        }
    </style>
</head>
<body>

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

<div class="bounty-container">
    <h1 style="color:#ffcc66; text-align:center;">Bounty Board</h1>
    <h3 style="text-align:center; margin-bottom:20px;">
        Champion: <?= $todaysChampion['name'] ?> (<?= $todaysChampion['class_name'] ?>)
    </h3>

    <?php if (empty($bounties)): ?>
        <p>No bounties yet.</p>
    <?php else: ?>
        <?php foreach ($bounties as $bounty): ?>
            <div class="bounty-card" id="bounty-<?= $bounty['id'] ?>">
                <h3><?= htmlspecialchars($bounty['title']) ?></h3>
                <div class="bounty-meta">
                    XP Reward: <strong><?= (int)$bounty['xp_reward'] ?></strong> |
                    Frequency: <?= ucfirst($bounty['frequency']) ?>
                </div>
                <?php if ($bounty['description']): ?>
                    <p><?= nl2br(htmlspecialchars($bounty['description'])) ?></p>
                <?php endif; ?>

                <button onclick="completeHabit(<?= $bounty['id'] ?>)">Complete Bounty</button>
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>

<script src="../assets/js/app.js"></script>
</body>
</html>