

<?php $__env->startSection('title', 'Product - ' . $product->name); ?>

<?php $__env->startSection('content'); ?>
<div class="grid gap-8 xl:grid-cols-[1.2fr_0.8fr]">
    <div class="rounded-3xl bg-white p-8 shadow-sm">
        <img src="<?php echo e($product->image); ?>" alt="<?php echo e($product->name); ?>" class="w-full rounded-3xl object-cover h-[480px]">
        <div class="mt-8 space-y-4">
            <div class="flex flex-wrap items-center gap-3 text-sm text-slate-500">
                <span><?php echo e($product->category->name); ?></span>
                <span class="h-1 w-1 rounded-full bg-slate-400"></span>
                <span><?php echo e(number_format($product->rating, 1)); ?> ★ rating</span>
            </div>
            <h1 class="text-3xl font-semibold text-slate-900"><?php echo e($product->name); ?></h1>
            <p class="text-slate-600 leading-7"><?php echo e($product->description); ?></p>
            <div class="flex items-end gap-4">
                <div>
                    <p class="text-3xl font-bold text-slate-900">₹<?php echo e(number_format($product->display_price, 2)); ?></p>
                    <?php if($product->sale_price): ?>
                        <p class="text-sm text-slate-500 line-through">₹<?php echo e(number_format($product->price, 2)); ?></p>
                    <?php endif; ?>
                </div>
                <?php if($product->discount_percent): ?>
                    <span class="rounded-full bg-emerald-50 px-3 py-1 text-sm font-semibold text-emerald-700"><?php echo e($product->discount_percent); ?>% OFF</span>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <aside class="space-y-6">
        <div class="rounded-3xl bg-white p-6 shadow-sm">
            <h2 class="text-xl font-semibold mb-4">Purchase Options</h2>
            <form method="POST" action="<?php echo e(route('cart.add', $product->id)); ?>">
                <?php echo csrf_field(); ?>
                <button type="submit" class="w-full rounded-full bg-slate-900 py-3 text-white font-semibold hover:bg-slate-800">Add to Cart</button>
            </form>
            <form method="POST" action="<?php echo e(route('wishlist.add', $product->id)); ?>" class="mt-3">
                <?php echo csrf_field(); ?>
                <button type="submit" class="w-full rounded-full border border-slate-300 py-3 text-slate-700 font-semibold hover:bg-slate-50">Add to Wishlist</button>
            </form>
            <form method="POST" action="<?php echo e(route('compare.add', $product->id)); ?>" class="mt-3">
                <?php echo csrf_field(); ?>
                <button type="submit" class="w-full rounded-full border border-slate-300 py-3 text-slate-700 font-semibold hover:bg-slate-50">Add to Compare</button>
            </form>
        </div>

        <div class="rounded-3xl bg-white p-6 shadow-sm">
            <h3 class="text-lg font-semibold mb-3">Delivery & Payment</h3>
            <ul class="space-y-3 text-slate-600 text-sm">
                <li>Free shipping over ₹1000</li>
                <li>30-day return policy</li>
                <li>Secure SSL payment</li>
            </ul>
        </div>
    </aside>
</div>

<!-- Reviews Section -->
<section class="mt-12 space-y-6">
    <h2 class="text-2xl font-semibold">Customer Reviews</h2>

    <?php if(auth()->guard()->check()): ?>
        <!-- Add Review -->
        <div class="rounded-3xl bg-white p-6 shadow-sm">
            <h3 class="text-lg font-semibold mb-4">Share Your Review</h3>
            <form action="<?php echo e(route('review.store', $product)); ?>" method="POST" class="space-y-4">
                <?php echo csrf_field(); ?>
                
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">Rating</label>
                    <div class="flex gap-2">
                        <?php for($i = 1; $i <= 5; $i++): ?>
                            <input type="radio" name="rating" value="<?php echo e($i); ?>" id="star<?php echo e($i); ?>" class="hidden" <?php echo e($userReview && $userReview->rating == $i ? 'checked' : ''); ?>>
                            <label for="star<?php echo e($i); ?>" class="cursor-pointer text-2xl text-slate-300 hover:text-yellow-400">★</label>
                        <?php endfor; ?>
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">Title</label>
                    <input type="text" name="title" required class="w-full rounded-3xl border border-slate-200 px-4 py-2 focus:border-slate-900 focus:outline-none" value="<?php echo e($userReview?->title ?? ''); ?>">
                </div>

                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-2">Comment</label>
                    <textarea name="comment" rows="4" required class="w-full rounded-3xl border border-slate-200 px-4 py-2 focus:border-slate-900 focus:outline-none"><?php echo e($userReview?->comment ?? ''); ?></textarea>
                </div>

                <button type="submit" class="rounded-full bg-slate-900 px-6 py-2 text-white hover:bg-slate-800">
                    <?php echo e($userReview ? 'Update Review' : 'Submit Review'); ?>

                </button>
            </form>
        </div>
    <?php else: ?>
        <div class="rounded-3xl bg-slate-50 p-6 border border-slate-200">
            <p class="text-slate-600">
                <a href="<?php echo e(route('login')); ?>" class="font-semibold text-slate-900 hover:underline">Log in</a> to share your review
            </p>
        </div>
    <?php endif; ?>

    <!-- Reviews List -->
    <?php if($reviews->isNotEmpty()): ?>
        <div class="space-y-4">
            <?php $__currentLoopData = $reviews; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $review): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="rounded-3xl bg-white p-6 shadow-sm">
                    <div class="flex justify-between items-start mb-3">
                        <div>
                            <p class="font-semibold"><?php echo e($review->user->name); ?></p>
                            <div class="flex gap-1 text-yellow-400">
                                <?php for($i = 0; $i < $review->rating; $i++): ?>
                                    <span>★</span>
                                <?php endfor; ?>
                            </div>
                        </div>
                        <p class="text-sm text-slate-500"><?php echo e($review->created_at->diffForHumans()); ?></p>
                    </div>
                    <h4 class="font-semibold mb-2"><?php echo e($review->title); ?></h4>
                    <p class="text-slate-600"><?php echo e($review->comment); ?></p>
                    <?php if(auth()->guard()->check()): ?>
                        <?php if(auth()->id() === $review->user_id || auth()->user()->isAdmin()): ?>
                            <form action="<?php echo e(route('review.delete', $review)); ?>" method="POST" class="mt-3 inline">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="text-sm text-red-600 hover:text-red-800" onclick="return confirm('Are you sure?')">Delete</button>
                            </form>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>

        <?php echo e($reviews->links()); ?>

    <?php else: ?>
        <p class="text-slate-600">No reviews yet. Be the first to review this product!</p>
    <?php endif; ?>
</section>

<?php if($related->isNotEmpty()): ?>
<section class="mt-12">
    <div class="flex items-center justify-between mb-6">
        <div>
            <h2 class="text-2xl font-semibold">Related Products</h2>
            <p class="text-slate-500">Other items from the same category.</p>
        </div>
    </div>
    <div class="grid gap-6 md:grid-cols-2 xl:grid-cols-4">
        <?php $__currentLoopData = $related; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <article class="rounded-3xl bg-white p-5 shadow-sm hover:shadow-md transition">
                <img src="<?php echo e($item->image); ?>" alt="<?php echo e($item->name); ?>" class="h-40 w-full rounded-3xl object-cover">
                <div class="mt-4">
                    <h3 class="text-lg font-semibold"><a href="<?php echo e(route('product.show', $item->slug)); ?>"><?php echo e($item->name); ?></a></h3>
                    <div class="mt-2 flex items-center justify-between">
                        <p class="font-bold">₹<?php echo e(number_format($item->display_price, 2)); ?></p>
                        <span class="text-sm text-slate-500"><?php echo e(number_format($item->rating, 1)); ?> ★</span>
                    </div>
                </div>
            </article>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
</section>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\phunt\resources\views/product/show.blade.php ENDPATH**/ ?>