@extends('layouts.app')

@section('title')

Shopping Cart

@parent

@stop

{{-- page level styles --}}

@section('header_styles')

<!--page level css -->

<link href="{{ asset('assets/vendors/select2/css/select2.min.css') }}" type="text/css" rel="stylesheet">

<link href="{{ asset('assets/vendors/select2/css/select2-bootstrap.css') }}" rel="stylesheet">

<!--end of page level css-->

@stop

{{-- Page content --}}

@section('content')

<!----Banner Section Starts----> 

<style>
.btn-orange{
  color: #333;
  font-weight: 500;
  background: #f9bc43;
}
.btn-orange:hover, .btn-orange:focus{
  opacity: .9;
  color: #333;
}
</style>


<main id="cart">

  

  <section>

    <div class="container">

      @if (Session::has('message'))

      <div class="alert alert-info alert-dismissible fade show" role="alert">

      <b>Attention!</b> {{ Session::get('message') }}         

         <button type="button" class="close" data-dismiss="alert" aria-label="Close">

          <span aria-hidden="true">&times;</span>

        </button>

      </div>

      @endif

      <div class="row">

        <div class="col-md-8 mb-4 shopitems">

          <h2 class="h4 p-3 bg-dark-light text-primary-light">Items in Cart <span class="badge badge-light float-right text-primary-light">{{ count($cartlist)}}</span></h2>

         



<!-- <div class="alert alert-primary alert-dismissible fade show mt-4" role="alert">

 Attention: if you buy a second ebook, or, more than one ebook, you will get a 50% discount on the lowest price ebook

  <button type="button" class="close" data-dismiss="alert" aria-label="Close">

    <span aria-hidden="true">&times;</span>

  </button>

</div> -->

<?php

  $subtotal=0;

  $origional_subtotal=0;

?>



@if($cartlist)

@foreach($cartlist as $row)         

<div class="card bigbox-hvr-slow mt-4">

  <div class="card-body">

    {{ Form::open([ 'method'  => 'delete', 'route' => [ 'cart.destroy', Crypt::encrypt($row->cart_item_id)] ]) }}    

    <button type="submit" class="close" aria-label="Close">

      <span aria-hidden="true">&times;</span>

    </button>

    {{ Form::close() }}

    @if($row->discount!='N')

    <span class="badge badge-pill badge-info mb-2">Discounted Item</span>

    @endif

    @if($row->item_type=='article')

    <h6 class="card-title"><strong>Article:</strong> {{$row->item_title}}</h6>  

    <p><strong>Journal:</strong> {{$row->journal_ebook_title}}</p>

    <div class="row">

      <div class="col-md-3"><p><strong>Volume:</strong> {{$row->volume}}</p></div>

      <div class="col-md-3"><p><strong>Issue:</strong> {{$row->issue}}</p></div>      

      <div class="col-md-3"><p><strong>Qty:</strong> {{$row->qty}}</p></div>

    </div>  

    <span class="pricetag">$ {{$row->item_price*$row->qty}}.00</span>

    <?php

        $subtotal = round(($row->item_price*$row->qty)+$subtotal);

        $origional_subtotal = round(($row->item_cost*$row->qty)+$origional_subtotal);

    ?>

    @endif

    @if($row->item_type=='chapter')

    <h6 class="card-title"><strong>Chapter:</strong> {{$row->item_title}}</h6>  

    <p><strong>Book:</strong> {{$row->journal_ebook_title}}</p>

    <div class="row">

      <div class="col-md-3"><p><strong>Volume:</strong> {{$row->volume}}</p></div>       

      <div class="col-md-3"> <p><strong>Qty:</strong> {{$row->qty}}</p></div>

    </div>  

    <span class="pricetag">$ {{$row->item_price*$row->qty}}.00</span>

    <?php

        $subtotal = round(($row->item_price*$row->qty)+$subtotal);

        $origional_subtotal = round(($row->item_cost*$row->qty)+$origional_subtotal);

    ?>

    @endif

    @if($row->item_type=='ebook_volume')

    <h6 class="card-title"><strong>Complete Book:</strong> {{$row->journal_ebook_title}}</h6>      

    <div class="row">

      <div class="col-md-3"><p><strong>Volume:</strong> {{$row->volume}}</p></div>       

      <div class="col-md-3"> <p><strong>Qty:</strong> {{$row->qty}}</p></div>

    </div>  

    <span class="pricetag">

      @if($row->discount!='N' && session()->has('original_price'))

      <del class="text-red"><?php

            $original_price = session()->get('original_price');

      ?>

        $ {{$original_price}}.00

      </del> 

      @endif

      $ {{$row->item_price*$row->qty}}.00</span>

    <?php

        $subtotal = round(($row->item_price*$row->qty)+$subtotal);

        $origional_subtotal = round(($row->item_cost*$row->qty)+$origional_subtotal);

    ?>

    @endif

  </div>

</div>

@endforeach

@else

<p>There are no products in your shopping cart.</p>

 @endif 

        </div>

        @if($cartlist)        

        <div class="col-md-4">



          <div class="card bg-spring-green bigbox-hvr-slow mb-4">

              <div class="card-header bg-dark-light text-primary-light">

                <h4 class="m-0">Promotion</h4>

              </div>

              <ul class="list-group list-group-flush">

                <li class="list-group-item d-flex lead py-4">

                {{ Form::open([ 'method'  => 'post', 'route' => [ 'promo_code'],'class' => 'd-xl-flex d-inline' ]) }}  

                  <div class="col-xl-5 px-0 pt-1 col-12">Promo Code:</div>

                  <div class="col-xl-7 col-12 p-0">

                    <div class="input-group">

                <input type="text" name="code" id="promo_code" class="form-control" placeholder="" aria-label="Example text with button addon" aria-describedby="button-addon1">

                <div class="input-group-prepend">

                  <button class="btn btn-orange" type="submit">Apply</button>

                </div>

              </div>

              </div>

               {{ Form::close() }}

              </li>

              </ul>

            </div>

          

          <div class="card bg-spring-green bigbox-hvr-slow">

              <div class="card-header bg-dark-light text-primary-light">

                <h4 class="m-0">Order Summary</h4>

              </div>

              <ul class="list-group list-group-flush">

  <li class="list-group-item lead py-4">Subtotal <span class="badge badge-primary-light text-white float-right mt-1">$ {{$origional_subtotal}}.00</span></li>

  

@if($promodiscount && !(session()->has('original_price')))

  <li class="list-group-item lead py-4">Promotion Discount <span class="badge badge-dark float-right mt-1">{{$promodiscount}}% </li>

@endif

<?php $total = $subtotal;

      $origional_total = $origional_subtotal; ?>

  

  <li class="list-group-item lead py-4"><strong>Total <span class="float-right mt-1">$ {{$total}}.00</span></strong></li>

</ul>

              <div class="card-body">

                {{ Form::open(array('id'=>"addtocartForm",'url'=>'/cart/checkout/review','method' => 'POST')) }}

                <input type="hidden" name="agree-flag" id="agree-flag" value="1">

                <button type="submit" id="checkout" value="Checkout"  onclick="javascript:return CheckLicense();" class="btn bg-primary-light btn-block mt-4 btn-lg text-white popsubmit"> Checkout </button>

                {{ Form::close() }}       


                <a class="btn btn-orange btn-block mt-4" href="javascript:GoBack()"><i class="fas fa-angle-double-left"></i> Add more item in your cart</a>
           

              </div>

              <a id="license" href="{{route('terms')}}"  ></a>

                  <div style="text-align:left;" class="modal fade" id="TnCModal" tabindex="-1" role="dialog" aria-labelledby="TnCModalLabel" aria-hidden="true">

              <div class="modal-dialog modal-lg">

                  <div class="modal-content">

                  </div> <!-- /.modal-content -->

              </div> <!-- /.modal-dialog -->

          </div>



          </div>


        </div>

        @endif

      </div>





       







    </div>

  </section>

  

</main>



<!----Main Section Starts----> 

@endsection

@section('footer_scripts')

<script language="javascript">

 function GoBack() {

    var currentUrl = window.location.href;

  window.history.back();

  setTimeout(function(){

      // if location was not changed in 100 ms, then there is no history back

      if(currentUrl === window.location.href){

          // redirect to site root

          window.location.href = '/';

      }

  }, 100);

}

  

                

function CheckLicense() {



 if(document.getElementById("agree-flag").value == "" || document.getElementById("agree-flag").value != "Y"){

  var target = $("#license").attr("href");

  $("#TnCModal .modal-content").load(target, function() {                             

    $("#TnCModal").modal("show"); 

  });                     

    return false;

  }

  

}              

</script>

 @stop

