
<?php $__env->startSection('content'); ?>

<div class="container-fluid">

  <div class="row">

        <div class="col-xl-12 col-lg-12">
             <div class="card shadow mb-4">
                                <!-- Card Header - Dropdown -->
                               
                                <div class="card-body">
                                    <div class=" pb-2">
                                     <div class="inner-bg table-responsive">
                    <div class="element-title mb-2">
                      <h4 class="mb-4">Favorite Products</h4>
                    </div>
                    <table class="cart-table table border" width="100%">
                      <thead>
                        <tr>
                          <th>Item Image</th>
                          <th>Item Name</th>
                          <th>Item Price</th>
                          <th>Details</th>
                          <th>Cart</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php if(!empty($favorites)): ?>
                          <?php $__currentLoopData = $favorites; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $favorite): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                              <td><img class="img-fluid my-auto align-self-center mr-2 mr-md-4 pl-0 p-0 m-0" src="<?php echo e(asset('storage/'.$favorite->item->image)); ?>" width="100" height="80" /></td>
                              <td><?php echo e($favorite->item->name); ?></a></td>
                              <td>Rs.<?php echo e($favorite->item->price); ?></td>
                              <td><a href="<?php echo e(route('item.show', $favorite->item)); ?>" class="btn btn-warning">View Details</a></td>
                               <td>
                                  <?php if(auth()->check()): ?>
                                    <?php if(!\Cart::session(auth()->user()->id)->get($favorite->item->id)): ?>
                                    
                                      <button id="add-<?php echo e($favorite->item->id); ?>" class="bttn" type="button" style=" border: 0; background: transparent;" onclick="add_cart(<?php echo e($favorite->item->id); ?>)"><i class="fas fa-cart-arrow-down" style=" color: #ae0151; font-size: 20px; "></i></button>
                                      
                                      <button id="added-<?php echo e($favorite->item->id); ?>" type="button" disabled class="bttn d-none" style=" border: 0; background: transparent;" ><i class="fas fa-cart-arrow-down" style=" color: #ccc; font-size: 20px; "></i></button>
                                      
                                  <?php else: ?>
                                      <button type="button" disabled class="bttn" style=" border: 0; background: transparent;" ><i class="fas fa-cart-arrow-down" style=" color: #ccc; font-size: 20px; "></i></button>
                                    <?php endif; ?>
                                  <?php else: ?>
                                    <a href="<?php echo e(route('login')); ?>" class="bttn"><i class="fas fa-cart-arrow-down" style=" color: #ae0151; font-size: 20px; "></i></a>
                                  <?php endif; ?>
                               </td>
                            
                            </tr>
                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                      </tbody>
                    </table>
                  </div>    
                               
                            </div>
                        </div>
                        <!-- Area -->
                       
                    </div>
</div>
                       
                    </div>

                    <!-- Content Row -->
                </div>

<?php $__env->stopSection(); ?>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

<script>

function add_cart(id){

     var cart_no = document.getElementById('cart_no').textContent;

            $.ajax({
                    type: "Post",
                    url: '<?php echo e(route('add.to.cart')); ?>',
                    datatype: 'json',
                    data: {
                      "_token": "<?php echo e(csrf_token()); ?>",
                        'item_id' : id,
                    },
                    success: function (data) {
                        const obj = JSON.parse(data);
                         
                           document.getElementById('add-'+id).classList.add('d-none');
                           document.getElementById('added-'+id).classList.remove('d-none');
                           document.getElementById('cart_no').textContent = parseInt(cart_no) + 1;

                      },
                    complete: function () {
                    },
                    error: function () {
                    }
                });

    }

</script>
<?php echo $__env->make('layouts.userdashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\chittar\resources\views/user/favorite.blade.php ENDPATH**/ ?>