<?php
require_once '../includes/constants.php';
require_once '../includes/session.php';
require_once '../includes/functions.php';

if (!isset($_SESSION['affiliate_id'])) {
    die("Access denied");
}

$offerId = $_GET['id'] ?? 0;
if (!$offerId) die("Invalid offer ID");

$sql = "SELECT * FROM partners_offers WHERE offer_id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$offerId]);
$offer = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$offer) die("Offer not found");
?>
<!DOCTYPE html>
<html>
<head>
    <title><?php echo SITE_TITLE . ' | Offer Preview'; ?></title>
    <link rel="stylesheet" href="css/public.css">
</head>
<body>
<div class="container">
<h2><?php echo htmlspecialchars($offer['offer_title']); ?></h2>
<p><strong>Payout:</strong> <?php echo htmlspecialchars($offer['offer_payout']) . ' ' . htmlspecialchars($offer['offer_currency']); ?></p>
<p><strong>Geo:</strong> <?php echo htmlspecialchars($offer['offer_geo']); ?></p>
<p><strong>Device:</strong> <?php echo htmlspecialchars($offer['offer_device']); ?></p>
<p><strong>Status:</strong> <?php echo htmlspecialchars($offer['offer_status']); ?></p>

<?php if ($offer['offer_status'] === 'active'): ?>
    <form method="post" action="offer_apply.php">
        <input type="hidden" name="offer_id" value="<?php echo htmlspecialchars($offer['offer_id']); ?>">
        <button type="submit">Apply for Access</button>
    </form>
<?php endif; ?>
</div>
</body>
</html>