@extends('layout')
@section('title','Produit ')
@section('description','Voir le panier')
@section('content')

 	


   <div class="breadcrumb-area mb-50">
        <div class="container">
            <div class="row">
                <div class="col">
                    <div class="breadcrumb-container">
                        <ul>
                           <li><a href="{{route('accueil')}}"><i class="fa fa-home"></i> {{ __('messages.acc') }}</a></li>
                            
    
                            <li class="active">{{ __('messages.pan') }}</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
	


	<div class="page-section section mb-50">
		<div class="container">
		
		 @if (session('status'))
                        <div class="alert alert-success" style="font-size: 15px; background-color: #328039; color: white">
                            <i class="ti-check"></i> {{ session('status') }}
                        </div>
                    @endif

                    @if (session('error'))
                        <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white">
                            <i class="ti-na"></i> {{ session('error') }}
                        </div>
                    @endif
                    @if ($errors->any())
                        <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white" >
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li> <i class="ti-na"></i> {{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif
		
			<div class="row">
				<div class="col-12">
					<form action="#">
						<!--=======  cart table  =======-->

						<div class="cart-table table-responsive mb-40">
							<table class="table">
								<thead>
									<tr>
									    <th class="text-center">N°</th>
										<th class="pro-thumbnail">{{ __('messages.img') }}</th>
										<th class="pro-title">{{ __('messages.pro') }}</th>
										<th class="pro-price">{{ __('messages.pri') }}</th>
										<th class="pro-quantity">{{ __('messages.qte') }}</th>
										<th class="pro-subtotal">{{ __('messages.tot') }}</th>
										<th class="pro-remove">{{ __('messages.del') }}</th>
									</tr>
								</thead>
								<tbody>
								
								@foreach($cart as $carts)
								
								        @php 
										
										$lang = app()->getLocale();
		
										$prod = DB::table('produit')
											->select(
												'id',
												DB::raw("designation_$lang as designation"),
												DB::raw("description_$lang as description"),
												'image_produit',
												'categorie_id',
												'prix',
												'etat_pub',
												'etat_dispo'
											)
											->where('id',$carts->produit_id)
											
											->first();
										  
										    $img = $prod->image_produit;
											
										    $designa = $prod->designation;
											
											$pp = $prod->prix;
											
						
										  
										  @endphp
								
									<tr>
									    <td class="text-center"><span>{{$loop->iteration}}</span></td>
										<td class="pro-thumbnail"><a href="#"><img src="{{asset('storage/'.$img)}}"
												style="height: 80px"	class="img-fluid" alt="Produit"></a></td>
										<td class="pro-title"><a href="#">{{$designa}}</a></td>
										<td class="pro-price"><span>{{$pp}} USD</span></td>
										<td class="pro-quantity">
											{{$carts->qte}}
										</td>
										<td class="pro-subtotal"><span>{{$carts->somligne}} USD</span></td>
										
										<td>
										  
											<a href="#" class="btn btn-danger data-supprimer" title="Supprimer" data-original-title="Tooltip on top" data-id="{{$carts->id}}" data-tooltip="Quick view" data-toggle="modal" data-target="#quick-view-modal-container">  <i class="fa fa-trash-o"></i>  </a>
										
										</td>
										
									</tr>
									
							    @endforeach
									
								</tbody>
							</table>
						</div>

						<!--=======  End of cart table  =======-->


					</form>

					<div class="row">

						<div class="col-lg-6 col-12">
						

						</div>


						<div class="col-lg-6 col-12 d-flex">
							<!--=======  Cart summery  =======-->
							
							 @php 
							 
							    $idcli =  session('client')->id;
								
								$verif = DB::table('ligne_commande')->where('client_id', $idcli)->where('etat', 'En cours')->first();
								
								if( $verif ){
									
									 $idcmde = DB::table('ligne_commande')->where('client_id', $idcli)->where('etat', 'En cours')->first()->commande_id;
								
							         $total = DB::table('ligne_commande')->where('client_id', $idcli)->where('etat', 'En cours')->get()->sum('somligne');
									 
									 $taxe = "0";
								
								$tot = $total + $taxe ;
								
								 \Illuminate\Support\Facades\DB::table('commande')->where('id', $idcmde)->update(
										[
										 'montant' => $tot,
										]);
									
								}
								
							   
							 @endphp
							 
							 @if( $verif )

							<div class="cart-summary">
								<div class="cart-summary-wrap">
									<h4>{{ __('messages.respan') }}</h4>
									<p>{{ __('messages.sut') }} <span>{{$total}} USD</span></p>
									<p>{{ __('messages.ta') }} <span>{{$taxe}} USD</span></p>
									<h2> {{ __('messages.tot') }} <span>{{$tot}} USD</span></h2>
								</div>
								<div class="cart-summary-button">
								
								    <a type="button" style="border-color: transparent; border-radius: 50px; background-color: #c96400; color: white; font-weight: 500;font-size: 15px; padding: 7px 20px;" href="{{route('choose_payment',['id'=>$idcmde])}}"> <i class="fa fa-check"></i> {{ __('messages.paye') }}</a>
								
								</div>
							</div>
							
							
							@endif

							<!--=======  End of Cart summery  =======-->

						</div>

					</div>

				</div>
			</div>
		</div>
	</div>


  	<div class="modal fade "  id="Supprimermodal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog modal-dialog-centered" role="document">
			<div class="modal-content modal-sm">
				
				<div class="modal-body">
					{{ __('messages.msup') }}
				</div>
				 <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete" >
                 
                </div>
			</div>

		</div>
	</div>

	
   @push('scripts')
   
   <script>
        $(".data-detail").on('click', function () {
                var id=$(this).data('id');
                $.get('Produits/'+id, function (data) {
                  var html = `
				  
				  
				  	<div class="row">
						<div class="col-lg-5 col-md-6 col-xs-12">
							
							<img src="storage/`+data.produ.image_produit+`" class="img-fluid" alt="">
							
						</div>
						<div class="col-lg-7 col-md-6 col-xs-12">
							<!-- product quick view description -->
							<div class="product-feature-details">
								<h2 class="product-title mb-15">`+data.produ.designation+`</h2>
								
								
                                  
								<h2 class="product-price mb-15">
									
									<span class="discounted-price"> `+data.produ.prix+` USD</span>
								</h2>

								<p class="product-description mb-20">`+data.produ.description+` </p>

								
								<div class="social-share-buttons">
									<h3>{{ __('messages.parp') }}</h3>
									<ul>
										<li><a class="twitter" href="#"><i class="fa fa-twitter"></i></a></li>
										<li><a class="facebook" href="#"><i class="fa fa-facebook"></i></a></li>
										<li><a class="google-plus" href="#"><i class="fa fa-google-plus"></i></a></li>
										<li><a class="pinterest" href="#"><i class="fa fa-pinterest"></i></a></li>
									</ul>
								</div>
							
						</div>
					</div>
				</div>
				  
				  
                               `
            ;
            $('#voir').html('').append(html);
          })
          $('#Detailmodal').modal();
        });
    </script>
	
	
		  <script>
        $(".data-supprimer").on('click', function () {
                var id=$(this).data('id');
			    $.get(location.origin+'/Lignecommande/'+id, function (data) {
                  var html = `
            <button type="button" class="btn btn-danger" data-bs-dismiss="modal">{{ __('messages.mnoo') }}</button>
                      <form action="{{route('suppcartPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.licom.id+`" name="id" >
                      <button type="submit"  style="border-color: transparent; border-radius: 50px; background-color: #c96400; color: white; font-weight: 500;font-size: 15px; padding: 7px 20px;" class="btn btn ">{{ __('messages.mye') }}</button>

            </form>`
            ;
            $('#delete').html('').append(html);
          })
          $('#Supprimermodal').modal();
        });
    </script>
   
  
    @endpush	
	

@endsection