<?php
require_once 'header.php';

$db = getDB();

$stmt = $db->query("SELECT * FROM bounties WHERE completed = FALSE ORDER BY created_at DESC");
$activeBounties = $stmt->fetchAll();

$stmt = $db->query("SELECT * FROM bounties WHERE completed = TRUE ORDER BY completed_date DESC");
$completedBounties = $stmt->fetchAll();
?>

<h2 class="text-center mb-20" style="color: var(--gold);">💰 Bounty Board</h2>

<div class="quest-category">
    <div class="category-header">
        <span class="category-icon">📜</span>
        <span class="category-title">Available Bounties</span>
    </div>
    <div class="quest-list">
        <?php if (empty($activeBounties)): ?>
            <p style="color: #666; text-align: center;">No available bounties</p>
        <?php else: ?>
            <?php foreach ($activeBounties as $bounty): ?>
                <div class="quest-item" onclick="completeBounty(<?php echo $bounty['id']; ?>)">
                    <div class="quest-info">
                        <?php if ($bounty['image_path']): ?>
                            <img src="<?php echo $bounty['image_path']; ?>" alt="" class="quest-img">
                        <?php endif; ?>
                        <div>
                            <div class="quest-name"><?php echo $bounty['name']; ?></div>
                            <div class="quest-desc"><?php echo $bounty['description']; ?></div>
                        </div>
                    </div>
                    <span class="quest-xp">+<?php echo $bounty['xp_reward']; ?> XP</span>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>

<div class="quest-category mt-20">
    <div class="category-header">
        <span class="category-icon">✅</span>
        <span class="category-title">Completed Bounties</span>
    </div>
    <div class="quest-list">
        <?php if (empty($completedBounties)): ?>
            <p style="color: #666; text-align: center;">No completed bounties yet</p>
        <?php else: ?>
            <?php foreach ($completedBounties as $bounty): ?>
                <div class="quest-item quest-complete">
                    <div class="quest-info">
                        <?php if ($bounty['image_path']): ?>
                            <img src="<?php echo $bounty['image_path']; ?>" alt="" class="quest-img">
                        <?php endif; ?>
                        <div>
                            <div class="quest-name"><?php echo $bounty['name']; ?></div>
                            <div class="quest-desc">Completed on <?php echo $bounty['completed_date']; ?></div>
                        </div>
                    </div>
                    <span class="quest-xp">✓</span>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>

<?php require_once 'footer.php'; ?>


