<?php if (!defined('ABSPATH')) exit; ?>
<div class="flash-sale-section py-8 bg-gray-50">
    <div class="container mx-auto px-4">
        <div class="flex items-center justify-between mb-6">
            <h2 class="text-2xl font-bold text-gray-800">🔥 شگفت‌انگیز امروز</h2>
        </div>
        <div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-4">
            <?php foreach ($flash_sales as $sale): 
                $product = get_post($sale->product_id);
                if (!$product) continue;
                $original_price = Dima_Product::get_price($sale->product_id);
                $discount = round((($original_price - $sale->sale_price) / $original_price) * 100);
            ?>
            <div class="bg-white rounded-lg shadow hover:shadow-lg transition p-4 relative">
                <span class="absolute top-2 right-2 bg-red-600 text-white text-xs px-2 py-1 rounded"><?php echo $discount; ?>٪</span>
                <a href="<?php echo get_permalink($sale->product_id); ?>">
                    <div class="aspect-square mb-3">
                        <?php echo get_the_post_thumbnail($sale->product_id, 'medium', array('class' => 'w-full h-full object-contain')); ?>
                    </div>
                    <h3 class="text-sm font-medium text-gray-800 mb-2 line-clamp-2"><?php echo esc_html($product->post_title); ?></h3>
                    <div class="flex items-center gap-2">
                        <span class="text-gray-400 text-xs line-through"><?php echo number_format($original_price); ?></span>
                        <span class="text-red-600 font-bold text-sm"><?php echo number_format($sale->sale_price); ?> تومان</span>
                    </div>
                </a>
                <button class="add-to-cart-btn w-full mt-3 bg-blue-600 text-white py-2 rounded-lg text-sm hover:bg-blue-700 transition" data-product-id="<?php echo esc_attr($sale->product_id); ?>">افزودن به سبد</button>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>