<?php
    $showDiscount = $showDiscount ?? false;
    $inWishlist = false;
    $effectiveShippingDays = $product->shipping_days ?? \App\Models\Setting::get('default_shipping_days');
    if (auth()->check()) {
        // Use cached wishlist product IDs to avoid N+1 queries
        $wishlistProductIds = \App\Helpers\ProductHelper::getWishlistProductIds();
        $inWishlist = $wishlistProductIds->contains($product->id);
    }
?>
<div class="product-card">
    <div class="product-card-inner">
        <?php if($product->discount_percentage && $showDiscount): ?>
            <span class="discount-badge">-<?php echo e(round($product->discount_percentage)); ?>%</span>
        <?php endif; ?>
        <div class="product-image-wrapper">
            <a href="<?php echo e(route('product.show', $product->slug)); ?>" class="product-image-link">
                <?php if($product->image_path || $product->image): ?>
                    <?php if (isset($component)) { $__componentOriginala58dde406db9207f2e2c58e1c4a3d690 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginala58dde406db9207f2e2c58e1c4a3d690 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.product-image','data' => ['product' => $product,'context' => 'listing','class' => 'product-image','onerror' => 'this.onerror=null; this.style.display=\'none\'; this.nextElementSibling.style.display=\'flex\';']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('product-image'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['product' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($product),'context' => 'listing','class' => 'product-image','onerror' => 'this.onerror=null; this.style.display=\'none\'; this.nextElementSibling.style.display=\'flex\';']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginala58dde406db9207f2e2c58e1c4a3d690)): ?>
<?php $attributes = $__attributesOriginala58dde406db9207f2e2c58e1c4a3d690; ?>
<?php unset($__attributesOriginala58dde406db9207f2e2c58e1c4a3d690); ?>
<?php endif; ?>
<?php if (isset($__componentOriginala58dde406db9207f2e2c58e1c4a3d690)): ?>
<?php $component = $__componentOriginala58dde406db9207f2e2c58e1c4a3d690; ?>
<?php unset($__componentOriginala58dde406db9207f2e2c58e1c4a3d690); ?>
<?php endif; ?>
                    <div class="product-placeholder" style="display: none;">
                        <i class="bi bi-image"></i>
                    </div>
                <?php else: ?>
                    <div class="product-placeholder">
                        <i class="bi bi-image"></i>
                    </div>
                <?php endif; ?>
            </a>
            <?php if(auth()->guard()->check()): ?>
                <form action="<?php echo e(route('wishlist.toggle', $product->id)); ?>" method="POST" class="d-inline wishlist-form" data-product-id="<?php echo e($product->id); ?>">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="action-btn wishlist-btn <?php echo e($inWishlist ? 'in-wishlist' : ''); ?>"
                            title="<?php echo e($inWishlist ? 'Remove from Wishlist' : 'Add to Wishlist'); ?>">
                        <i class="bi bi-heart<?php echo e($inWishlist ? '-fill' : ''); ?>"></i>
                    </button>
                </form>
            <?php else: ?>
                <a href="<?php echo e(route('login')); ?>" class="btn action-btn wishlist-form wishlist-btn" title="Login to Add to Wishlist">
                    <i class="bi bi-heart"></i>
                </a>
            <?php endif; ?>
            <?php if($product->is_out_of_stock): ?>
                <div class="stockout-badge-overlay" role="status" aria-label="<?php echo e(__('Out of stock')); ?>">
                    <span class="stockout-text">Stockout</span>
                </div>
            <?php endif; ?>
        </div>
        <div class="product-info">
            <h6 class="product-title">
                <a href="<?php echo e(route('product.show', $product->slug)); ?>"><?php echo e(strtoupper($product->name)); ?></a>
            </h6>
            <?php if($product->is_out_of_stock): ?>
                <div class="product-stockout-label text-danger fw-semibold small mb-1" role="status"><?php echo e(__('Stockout')); ?></div>
            <?php endif; ?>
            
            <!-- Rating Display -->
            <div class="product-rating mb-2">
                <div class="d-flex align-items-center gap-1">
                    <?php if($product->rating_count > 0): ?>
                        <?php if (isset($component)) { $__componentOriginalfa87e49ca3cdf62358bbc468aaf3394b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalfa87e49ca3cdf62358bbc468aaf3394b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.star-rating','data' => ['rating' => $product->avg_rating,'size' => 'sm']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('star-rating'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['rating' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($product->avg_rating),'size' => 'sm']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalfa87e49ca3cdf62358bbc468aaf3394b)): ?>
<?php $attributes = $__attributesOriginalfa87e49ca3cdf62358bbc468aaf3394b; ?>
<?php unset($__attributesOriginalfa87e49ca3cdf62358bbc468aaf3394b); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalfa87e49ca3cdf62358bbc468aaf3394b)): ?>
<?php $component = $__componentOriginalfa87e49ca3cdf62358bbc468aaf3394b; ?>
<?php unset($__componentOriginalfa87e49ca3cdf62358bbc468aaf3394b); ?>
<?php endif; ?>
                        <span class="rating-text">
                            <strong class="rating-value"><?php echo e(number_format($product->avg_rating, 1)); ?></strong>
                            <span class="rating-count">(<?php echo e($product->rating_count); ?>)</span>
                        </span>
                    <?php else: ?>
                        <div class="star-rating text-sm">
                            <?php for($i = 1; $i <= 5; $i++): ?>
                                <i class="bi bi-star" style="font-size: 0.875rem; color: #ffc107; opacity: 0.4;"></i>
                            <?php endfor; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            
            <div class="product-price">
                <?php if($product->product_type === 'variant' && $product->variants && $product->variants->isNotEmpty()): ?>
                    <?php
                        $activeVariants = $product->variants->where('is_active', true);
                        $variantPrices = $activeVariants->pluck('price')->filter();
                        $minPrice = $variantPrices->min();
                        $maxPrice = $variantPrices->max();
                        $variantMrps = $activeVariants->pluck('mrp')->filter();
                        $minMrp = $variantMrps->min();
                        $maxMrp = $variantMrps->max();
                    ?>
                    <?php if($minPrice && $maxPrice && $maxPrice === $minPrice): ?>
                        <div class="current-price">₹<?php echo e(number_format($minPrice, 0)); ?></div>
                    <?php else: ?>
                        <div class="current-price">₹<?php echo e(number_format($minPrice, 0)); ?> - ₹<?php echo e(number_format($maxPrice, 0)); ?></div>
                    <?php endif; ?>
                    <?php if($minMrp && $maxMrp && $minMrp > $minPrice): ?>
                        <!-- <div class="original-price">₹<?php echo e(number_format($minMrp, 0)); ?> - ₹<?php echo e(number_format($maxMrp, 0)); ?></div> -->
                    <?php endif; ?>
                <?php else: ?>
                    <span class="current-price">₹<?php echo e(number_format($product->price, 0)); ?></span>
                    <?php if($product->mrp && $product->mrp > $product->price): ?>
                        <span class="original-price">₹<?php echo e(number_format($product->mrp, 0)); ?></span>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
            <?php if(!is_null($effectiveShippingDays) && $effectiveShippingDays !== ''): ?>
                <div class="mt-1 text-muted" style="font-size: 12px;">
                    <i class="bi bi-truck"></i> Ships in <?php echo e($effectiveShippingDays); ?> day<?php echo e((int) $effectiveShippingDays === 1 ? '' : 's'); ?>

                </div>
            <?php endif; ?>
            <?php if($product->product_type === 'variant'): ?>
               <a href="<?php echo e(route('product.show', $product->slug)); ?>" 
                  class="add-to-cart-btn mt-2">
                  Select Options
                 </a>
            <?php else: ?>
           <form action="<?php echo e(route('cart.store')); ?>" method="POST" class="add-to-cart-form">
           <?php echo csrf_field(); ?>
             <input type="hidden" name="product_id" value="<?php echo e($product->id); ?>">
            <input type="hidden" name="qty" value="1">
            <button type="submit" class="add-to-cart-btn mt-2">
             <i class="bi bi-bag"></i> Add to Cart
           </button>
           </form>
       <?php endif; ?>
        </div>
    </div>
</div>

<?php /**PATH /var/www/html/shaa_jewels/live/resources/views/partials/product-card.blade.php ENDPATH**/ ?>