<?php include 'includes/header.php'; ?>

<h2 class="section-title">محصولات شگفت‌انگیز</h2>

<div class="products">

<?php
$offers = $pdo->query("SELECT * FROM products WHERE is_special = 1")->fetchAll();

foreach ($offers as $p):

    // گرفتن تصویر
    $img = $pdo->prepare("SELECT image_path FROM product_images WHERE product_id = ? LIMIT 1");
    $img->execute([$p['id']]);
    $image = $img->fetchColumn();

    // قیمت امن و بدون خطا
    $price = isset($p['price']) && $p['price'] !== null ? (float)$p['price'] : 0;
?>

<div class="product-card special">
    <span class="badge">شگفت‌انگیز</span>

    <img src="../admin/<?php echo $image; ?>">

    <h3><?php echo $p['title']; ?></h3>

    <p class="new-price"><?php echo number_format($price); ?> تومان</p>

    <a class="btn" href="product.php?id=<?php echo $p['id']; ?>">مشاهده</a>
</div>

<?php endforeach; ?>

</div>

<?php include 'includes/footer.php'; ?>