<div class="container py-4">
    <h3 class="fw-bold mb-4"><i class="bi bi-heart-fill text-danger me-2"></i>รายการสินค้าที่ชอบ (Wishlist)</h3>

    <?php if (empty($products)): ?>
        <div class="card border-0 shadow-sm p-5 text-center">
            <i class="bi bi-heartbreak text-muted display-1 mb-3"></i>
            <h5>คุณยังไม่มีสินค้าในรายการที่ชอบ</h5>
            <p class="text-muted">กดหัวใจที่สินค้าที่คุณสนใจเพื่อบันทึกไว้ดูภายหลัง</p>
            <div class="mt-3">
                <a href="<?= APP_URL ?>/products" class="btn btn-primary px-4 py-2 rounded-pill fw-bold">เลือกดูสินค้า</a>
            </div>
        </div>
    <?php else: ?>
        <div class="row g-4">
            <?php foreach ($products as $prod): ?>
                <div class="col-6 col-md-4 col-lg-3">
                    <div class="card border-0 shadow-sm h-100 product-card">
                        <div class="product-img-wrapper">
                            <?php 
                                $imgSrc = !empty($prod['primary_image']) ? APP_URL . '/public/' . ltrim($prod['primary_image'], '/') : APP_URL . '/public/assets/images/sample-headphone.jpg';
                            ?>
                            <img src="<?= $imgSrc ?>" alt="<?= Security::e($prod['title']) ?>" class="card-img-top" onerror="this.src='<?= APP_URL ?>/public/assets/images/sample-headphone.jpg'">
                        </div>
                        <div class="card-body d-flex flex-column">
                            <span class="text-secondary small mb-1"><?= Security::e($prod['category_name']) ?></span>
                            <h6 class="card-title fw-bold text-truncate mb-2">
                                <a href="<?= APP_URL ?>/product/<?= $prod['slug'] ?>" class="text-decoration-none text-dark"><?= Security::e($prod['title']) ?></a>
                            </h6>
                            
                            <div class="mt-auto d-flex align-items-center justify-content-between">
                                <span class="fw-bold text-primary fs-5">฿<?= number_format($prod['price'], 2) ?></span>
                                
                                <form action="<?= APP_URL ?>/wishlist/toggle" method="POST">
                                    <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
                                    <input type="hidden" name="product_id" value="<?= $prod['id'] ?>">
                                    <button type="submit" class="btn btn-outline-danger btn-sm rounded-circle"><i class="bi bi-heart-fill"></i></button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
</div>
