<?php $attributes ??= new \Illuminate\View\ComponentAttributeBag;

$__newAttributes = [];
$__propNames = \Illuminate\View\ComponentAttributeBag::extractPropNames((['reviews', 'product']));

foreach ($attributes->all() as $__key => $__value) {
    if (in_array($__key, $__propNames)) {
        $$__key = $$__key ?? $__value;
    } else {
        $__newAttributes[$__key] = $__value;
    }
}

$attributes = new \Illuminate\View\ComponentAttributeBag($__newAttributes);

unset($__propNames);
unset($__newAttributes);

foreach (array_filter((['reviews', 'product']), 'is_string', ARRAY_FILTER_USE_KEY) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
}

$__defined_vars = get_defined_vars();

foreach ($attributes->all() as $__key => $__value) {
    if (array_key_exists($__key, $__defined_vars)) unset($$__key);
}

unset($__defined_vars, $__key, $__value); ?>

<div class="reviews-list mt-4">
    <h4 class="mb-3">
        <i class="bi bi-chat-left-text"></i> Customer Reviews
        <?php if($product->rating_count > 0): ?>
            <small class="text-muted">(<?php echo e($product->rating_count); ?> <?php echo e(Str::plural('review', $product->rating_count)); ?>)</small>
        <?php endif; ?>
    </h4>

    <?php if($reviews->count() > 0): ?>
        <div class="reviews-container">
            <?php $__currentLoopData = $reviews; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $review): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="review-item card mb-3">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-start mb-2">
                            <div>
                                <h6 class="mb-1">
                                    <?php echo e($review->user ? $review->user->name : 'Anonymous'); ?>

                                    <?php if($review->order_id): ?>
                                        <span class="badge bg-success ms-2">
                                            <i class="bi bi-check-circle"></i> Verified Purchase
                                        </span>
                                    <?php endif; ?>
                                </h6>
                                <small class="text-muted">
                                    <i class="bi bi-calendar"></i> <?php echo e($review->created_at->format('M d, Y')); ?>

                                </small>
                            </div>
                            <div>
                                <?php if (isset($component)) { $__componentOriginalfa87e49ca3cdf62358bbc468aaf3394b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalfa87e49ca3cdf62358bbc468aaf3394b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.star-rating','data' => ['rating' => $review->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($review->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; ?>
                            </div>
                        </div>

                        <?php if($review->title): ?>
                            <h6 class="review-title mb-2"><?php echo e($review->title); ?></h6>
                        <?php endif; ?>

                        <?php if($review->body): ?>
                            <p class="review-body mb-2"><?php echo e($review->body); ?></p>
                        <?php endif; ?>

                        <div class="review-actions d-flex align-items-center gap-3">
                            <button class="btn btn-sm btn-outline-secondary helpful-btn" 
                                    data-review-id="<?php echo e($review->id); ?>"
                                    onclick="markHelpful(<?php echo e($review->id); ?>)">
                                <i class="bi bi-hand-thumbs-up"></i> Helpful 
                                <span class="helpful-count-<?php echo e($review->id); ?>">(<?php echo e($review->helpful_count); ?>)</span>
                            </button>
                        </div>
                    </div>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>

        <!-- Pagination - Right Aligned -->
        <div class="pagination-wrapper">
            <div class="d-flex justify-content-end align-items-center gap-3 flex-wrap">
                <div class="pagination-info-text">
                    Showing <strong><?php echo e($reviews->firstItem() ?? 0); ?></strong>–<strong><?php echo e($reviews->lastItem() ?? 0); ?></strong> 
                    of <strong><?php echo e($reviews->total()); ?></strong> reviews
                </div>
                <?php if($reviews->hasPages()): ?>
                <div class="pagination-controls">
                    <?php echo e($reviews->links('vendor.pagination.admin-categories')); ?>

                </div>
                <?php endif; ?>
            </div>
        </div>
    <?php else: ?>
        <div class="alert alert-info">
            <i class="bi bi-info-circle"></i> No reviews yet. Be the first to review this product!
        </div>
    <?php endif; ?>
</div>

<script>
function markHelpful(reviewId) {
    const btn = document.querySelector(`.helpful-btn[data-review-id="${reviewId}"]`);
    const countSpan = document.querySelector(`.helpful-count-${reviewId}`);
    
    if (btn.disabled) return;
    
    btn.disabled = true;
    
    fetch(`/api/reviews/${reviewId}/helpful`, {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content,
            'Accept': 'application/json',
        },
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            countSpan.textContent = `(${data.data.helpful_count})`;
            btn.classList.add('btn-success');
            btn.classList.remove('btn-outline-secondary');
        }
    })
    .catch(error => {
        console.error('Error:', error);
    })
    .finally(() => {
        btn.disabled = false;
    });
}
</script>

<?php /**PATH /var/www/html/sudheerkt_uat/resources/views/partials/review-list.blade.php ENDPATH**/ ?>