<?php
include('header.php');
?>

<!-- start main -->
<section class="inner-section single-banner">
	<div class="container">
		<h2>wishlist</h2>
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="index.php">Home</a></li>
			<li class="breadcrumb-item"><a href="shop-4column.php">shop grid</a></li>
			<li class="breadcrumb-item active" aria-current="page">wishlist</li>
		</ol>
	</div>
</section>
<section class="inner-section wishlist-part">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<div class="table-scroll">
					<table class="table-list">
						<thead>
							<tr>
								<th scope="col">Serial</th>
								<th scope="col">Product</th>
								<th scope="col">Name</th>
								<th scope="col">Price</th>
								<th scope="col">Size | Color</th>
								<th scope="col">status</th>
								<th scope="col">shopping</th>
								<th scope="col">action</th>
							</tr>
						</thead>
						<tbody id="wishlist">
						    
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</section>

<!-- end main -->

<?php
include('footer.php');
?>

<script>
function loadwishlist(){
     let Products_cart = JSON.parse(localStorage.getItem('wish_list'));
     var myObj, count, j, wishlisthtml, space = "";
     sub_total = 0;
     wishlisthtml = '';
     j = j-1;
     var count = 0;
     
     for (j in Products_cart) {
         if (j != 'undefined') {
            count++;
			var img = Products_cart[j].image;
			var p_name = Products_cart[j].cart_p_name;
			var c_price = Products_cart[j].cart_p_current_price;
			var o_price = Products_cart[j].cart_p_old_price;
			var size_id = Products_cart[j].cart_size_id;
			var size_name = Products_cart[j].cart_size_name;
			var color_id = Products_cart[j].cart_color_id;
			var color_name = Products_cart[j].cart_color_name;
			var p_id = Products_cart[j].cart_p_id;
			var p_name = Products_cart[j].cart_p_name;
			var cart_p_qty = Products_cart[j].cart_p_qty;
			var stock = Products_cart[j].stock_qty;
            //var tot +=cart_p_qty*c_price;
			var a = ((o_price - c_price) / o_price) * 100;
			var off = a.toFixed();
			
			var uniqueid = p_id+size_id+color_id;
			if(stock == null || stock == 0){
			    var stock_ = '<h6 class="stock-out">Out Of Stock</h6>';
			 //   var alertmessage = "sweetalert('warning','Out Of Stock')";
			    var add_to_cart_btn = '<button class="product-add" onclick="outofstockalert()" title="Add to Cart">out of stock</button>';
			} else if(stock != null && stock != 0){
			    var stock_ = '<h6 class="stock-in">in Stock</h6>';
			    var add_to_cart_btn = '<button class="product-add" onclick="add('+p_id+','+uniqueid+')" title="Add to Cart">add to cart</button>';
			}
			
			
            a = '<tr class="wishlist_item'+uniqueid+'">';
            b = '<td class="table-serial">';
            c = '<h6>'+count+'</h6>';
            d = '</td>';
            e = '<td class="table-image"><img src="<?php echo base_url(); ?>uploads/shop/product/' + img + '" alt="' + p_name + '">';
            f = '</td>';
            g = '<td class="table-name">';
            h = '<h6>' + p_name + '</h6>';
            i = '</td>';
            j = '<td class="table-price">';
            k = '<h6>₹' + c_price + '</h6>';
            l = '</td>';
            m = '<td class="table-size-color">';
            n = '<h6><span>'+size_name+'</span> &nbsp;&nbsp;&nbsp; <span class="badge" style="background-color: '+color_name+';">'+color_name+'</span></h6>';
            o = '</td>';
            p = '<td class="table-status">';
            q = stock_;
            r = '</td>';
            s = '<td class="table-shop">';
            t = add_to_cart_btn;
            u = '</td>';
            v = '<td class="table-action">';
            w = '<a class="view" href="<?=base_url('product_view?id=');?>'+p_id+'" title="Quick View"><i class="fas fa-eye"></i></a>';
            x = '<a class="trash" href="javascript:void(0);" onclick="remove_wish_Item('+uniqueid+')" title="Remove Wishlist"><i class="icofont-trash"></i></a>';
            y = '</td>';
            z = '</tr>';
			wishlisthtml += a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z;
	   }
	}
	
	if(wishlisthtml!=='') { document.getElementById("wishlist").innerHTML=wishlisthtml;}
	else{
	    document.getElementById("wishlist").innerHTML = '<tr><td colspan="8"><img src="<?=base_url('uploads/empty_wishlist.png');?>" class="img-fluid" /></td></tr>';
	}
    // var i = get_cart_item();
	
// 	$("#cart_quantity").html(get_cart_item());
// 	$("#cart_quantity2").html(get_cart_item());
// 	$("#cart_quantity3").html(get_cart_item());
// 	$("#cart_quantity4").html(get_cart_item());
// 	var d='<div class="col-12"><img src="<?=base_url('uploads/empty-cart.png');?>" class="img-fluid" /></div><div class="col-12 text-center"><b>Cart Is Empty</b></div>';        
//     var i = get_cart_item();
    
//     if(i==null || i=='' || i==0){
//         $("#cart_quantity").html('0');
//         $("#cart_quantity2").html('0');
//         $("#cart_quantity3").html('0');
//         $("#cart_quantity4").html('0');
//         document.getElementById("cart_view").innerHTML=d;
//     }
}
loadwishlist();
</script>
<script>
    function outofstockalert(){
        sweetalert('warning','Product is Out of Stock');
    }
</script>