<?php $__env->startSection('title','Shopping Cart | Shopora'); ?>
<?php $__env->startSection('content'); ?>
<div class="bg-gray-100 py-6 min-h-[calc(100vh-200px)]">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        
        <?php if($cart->items->isEmpty()): ?>
        <div class="bg-white rounded-lg p-12 text-center shadow-sm border border-gray-200">
            <div class="w-32 h-32 bg-gray-50 rounded-full flex items-center justify-center mx-auto mb-6">
                <i class="fa-solid fa-cart-shopping text-5xl text-gray-300"></i>
            </div>
            <h2 class="text-xl font-medium text-gray-800 mb-2">There are no items in this cart</h2>
            <p class="text-sm text-gray-500 mb-6">Continue shopping to find your next favorite item</p>
            <a href="<?php echo e(route('products.index')); ?>" class="btn-outline px-8 py-2.5 rounded font-medium text-sm inline-block uppercase">Continue Shopping</a>
        </div>
        <?php else: ?>
        <div class="flex flex-col lg:flex-row gap-6">
            
            <div class="lg:flex-1">
                <div class="bg-white rounded-lg shadow-sm border border-gray-200">
                    <div class="p-4 border-b border-gray-100 flex items-center justify-between">
                        <h1 class="text-lg font-medium text-gray-800">Shopping Cart (<?php echo e($cart->item_count); ?> Items)</h1>
                    </div>
                    
                    <div class="divide-y divide-gray-100">
                        <?php $__currentLoopData = $cart->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="p-4 flex gap-4">
                            <div class="w-20 h-20 bg-gray-50 border border-gray-100 flex flex-shrink-0 items-center justify-center text-3xl overflow-hidden">
                                <?php if($item->product->images && is_array($item->product->images) && count($item->product->images) > 0): ?>
                                    <img src="<?php echo e(asset('storage/' . $item->product->images[0])); ?>" alt="<?php echo e($item->product->name); ?>" class="w-full h-full object-cover">
                                <?php else: ?>
                                    🛍️
                                <?php endif; ?>
                            </div>
                            <div class="flex-1 min-w-0 flex flex-col justify-between">
                                <div class="flex justify-between gap-4 items-start">
                                    <div>
                                        <a href="<?php echo e(route('products.show',$item->product->slug)); ?>" class="text-sm text-gray-800 hover:text-primary leading-tight line-clamp-2 mb-1"><?php echo e($item->product->name); ?></a>
                                        <p class="text-xs text-gray-500">Brand: <?php echo e($item->product->brand ?? 'No Brand'); ?></p>
                                    </div>
                                    <div class="text-right flex-shrink-0">
                                        <p class="text-primary font-medium text-lg leading-none">Rs. <?php echo e(number_format($item->price)); ?></p>
                                        <?php if($item->product->is_on_sale): ?>
                                        <div class="flex items-center gap-1 mt-1 justify-end">
                                            <span class="text-xs text-gray-400 line-through">Rs. <?php echo e(number_format($item->product->price)); ?></span>
                                            <span class="text-gray-800 text-[10px]">-<?php echo e($item->product->discount_percent); ?>%</span>
                                        </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                                <div class="flex justify-between items-end mt-4">
                                    <form action="<?php echo e(route('cart.remove',$item)); ?>" method="POST">
                                        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="text-gray-400 hover:text-red-500 text-sm flex items-center gap-1 transition"><i class="fa-regular fa-trash-can"></i> Remove</button>
                                    </form>
                                    
                                    <form action="<?php echo e(route('cart.update',$item)); ?>" method="POST" class="flex items-center">
                                        <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                                        <button name="quantity" value="<?php echo e(max(1,$item->quantity-1)); ?>" class="w-8 h-8 flex items-center justify-center bg-gray-100 text-gray-500 hover:bg-gray-200"><i class="fa-solid fa-minus text-xs"></i></button>
                                        <span class="w-10 text-center text-sm font-medium"><?php echo e($item->quantity); ?></span>
                                        <button name="quantity" value="<?php echo e($item->quantity+1); ?>" class="w-8 h-8 flex items-center justify-center bg-gray-100 text-gray-500 hover:bg-gray-200"><i class="fa-solid fa-plus text-xs"></i></button>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
            </div>

            
            <div class="lg:w-[350px]">
                <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 sticky top-20">
                    <h3 class="text-base font-medium text-gray-800 mb-4">Order Summary</h3>
                    
                    <div class="space-y-3 text-sm text-gray-600 mb-4 pb-4 border-b border-gray-100">
                        <div class="flex justify-between"><span>Subtotal (<?php echo e($cart->item_count); ?> Items)</span><span>Rs. <?php echo e(number_format($cart->subtotal)); ?></span></div>
                        <div class="flex justify-between"><span>Shipping Fee</span><span class="font-medium text-gray-800"><?php echo e($cart->subtotal >= 10000 ? 'Free' : 'Rs. 299'); ?></span></div>
                        <?php if($cart->discount>0): ?><div class="flex justify-between text-green-600"><span>Discount (<?php echo e($cart->coupon_code); ?>)</span><span>- Rs. <?php echo e(number_format($cart->discount)); ?></span></div><?php endif; ?>
                    </div>
                    
                    <div class="flex justify-between items-end mb-6">
                        <span class="text-gray-800 text-sm">Total</span>
                        <div class="text-right">
                            <span class="text-primary font-bold text-xl block leading-none">Rs. <?php echo e(number_format($cart->total + ($cart->subtotal >= 10000 ? 0 : 299))); ?></span>
                            <span class="text-xs text-gray-400">VAT included, where applicable</span>
                        </div>
                    </div>
                    
                    <?php if(auth()->guard()->check()): ?>
                    <a href="<?php echo e(route('checkout.index')); ?>" class="btn-primary w-full block text-center font-bold py-3 text-sm rounded shadow-sm">PROCEED TO CHECKOUT</a>
                    <?php else: ?>
                    <a href="<?php echo e(route('login')); ?>" class="btn-primary w-full block text-center font-bold py-3 text-sm rounded shadow-sm">LOGIN TO CHECKOUT</a>
                    <?php endif; ?>

                    <div class="mt-6 pt-4 border-t border-gray-100">
                        <?php if($cart->coupon_code): ?>
                        <div class="flex justify-between items-center bg-green-50 px-3 py-2 border border-green-100 rounded text-sm">
                            <span class="text-green-600 font-medium"><i class="fa-solid fa-tag mr-1"></i> <?php echo e($cart->coupon_code); ?></span>
                            <form action="<?php echo e(route('cart.coupon.remove')); ?>" method="POST"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                <button class="text-red-500 hover:underline text-xs">Remove</button>
                            </form>
                        </div>
                        <?php else: ?>
                        <form action="<?php echo e(route('cart.coupon.apply')); ?>" method="POST" class="flex gap-2">
                            <?php echo csrf_field(); ?>
                            <input type="text" name="coupon_code" placeholder="Enter Voucher Code" class="flex-1 border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:border-primary uppercase">
                            <button class="bg-[#2abbe8] hover:bg-[#209cbd] text-white px-4 py-2 rounded text-sm font-medium transition">APPLY</button>
                        </form>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/devlools/public_html/E-Commerce/resources/views/cart/index.blade.php ENDPATH**/ ?>