@extends('layouts.frontend')

@section('title')Korpa @endsection
@section('description')Korpa @endsection
@section('keywords')Korpa @endsection
@section('h1')Korpa @endsection
@section('breadcumbs') @endsection

@inject('prices', 'App\Lib\Prices')

@section('content')
    <section id="maincontent" class="pad">
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12">
                <h2>Korpa</h2>
                <hr>
            </div>
        </div>
        <div class="row">
            <div id="cartow">
                <div id="cartiw">
                <div class="col-md-3 col-lg-2  cart-side" id="leftcol">
                    <a href="{{locRoute('contact')}}"><img class="cart-help-v" src="/assets/img/{{app()->getLocale()}}-cart-help-v.gif" alt="{{__('frontside.cart.contactus')}}"></a>
                    <a href="{{locRoute('contact')}}"><img class="cart-help-h" src="/assets/img/{{app()->getLocale()}}-cart-help-h.gif" alt="{{__('frontside.cart.contactus')}}"></a>
                </div>
            @php
                $info = '';
                if(isset($_SESSION['cartactmsg']) && trim($_SESSION['cartactmsg']) != '') {

                    $info = trim($_SESSION['cartactmsg']);
                    $_SESSION['cartactmsg'] = NULL;
                    unset($_SESSION['cartactmsg']);
                }
            @endphp
            <div class="col-md-9 col-lg-10" id="maincol">
                <div id="cartinfo">{{$info}}</div><!--end cartinfo -->
                <div id="cartwrap">
                @if(count($products))

                    <form action="{{locRoute('cart.post')}}" method="post" name="cartForm" id="cartForm">

                        <table id="shopping-cart-table" class="data-table cart-table">
                            {{--<colgroup>
                                <col width="1">
                                <col width="1">
                                <col>
                                <col width="1">
                                <col width="1">
                                <col width="1">
                            </colgroup>--}}
                            <thead>
                            <tr class="first last">
                                <th rowspan="1">{{__('frontside.cart.remove')}}</th>
                                <th class="a-center" rowspan="1">{{__('frontside.cart.image')}}</th>
                                <th rowspan="1"><span class="nobr">{{__('frontside.cart.product')}}</span></th>
                                <th colspan="1" class="a-center"><span class="nobr">{{__('frontside.cart.price')}}</span></th>
                                <th class="a-center" rowspan="1">{{__('frontside.cart.quantity')}}</th>
                                <th colspan="1" class="a-center">{{__('frontside.cart.subtotal')}}</th>
                            </tr>
                            </thead>
                            <tbody>

                            @php $total = 0; @endphp

                    @foreach($products as $p)

                        @php
                            $prodid = $p->prod_id;
                            // Ful name
                            $fullname = strtoupper($p->brand_name).' '.ucfirst($p->prod_name);

                            // Link
                            $link = url($p->slug);

                            // Image
                            $imgpath = public_path($p->prod_timg);
                            $imgsrc = (file_exists($imgpath) && is_readable($imgpath)) ? $p->prod_timg : config('images.no_image_paths.t');

                            $price = $prices->getPrice($p); //$p->sc_price;
                            $qty = $p->sc_qty;
                            $subtotal = $price*$qty;

                            $total = $total+$subtotal;

                        @endphp




                        <tr class="cartitem first last odd">
                            <td class="a-center">
                                <a href="{{locRoute('cart.remove', ['ind' => $prodid])}}" rel="nofollow" style="color:#333; text-decoration: none;">
                                    <i class="glyphicon glyphicon-trash"></i>
                                    <span class="c-info"> {{__('frontside.cart.remove')}}</span>
                                </a>
                            </td>
                            <td class="prod-img" colspan="">
                                <a href="{{$link}}">
                                <img width="90" height="90" border="0" alt="{{$fullname}}" src="{{asset($imgsrc)}}">
                                </a>
                            </td>
                            <td>
                                <input name="pid[]" type="hidden" value="{{$prodid}}">
                                <span class="product-name">
                                  <a href="{{$link}}">{{$fullname}}</a>
                                  </span>
                                            </td>
                                            <td class="a-right">
                                  <span class="cart-price">
                                  <span class="cprice"><span class="c-info">{{__('frontside.cart.price')}}: </span>
                                  <span data-price="{{$price}}" class="item-price">{{$prices::formatPrice($price)}}</span> </span>
                                  </span>
                                            </td>
                                            <td class="a-center">
                                                <span class="c-info">{{__('frontside.cart.quantity')}}: </span>
                                                <input maxlength="12" class="input-text qty" title="Qty" size="4" value="{{$qty}}" name="pqty[]" autocomplete="off">
                                            </td>
                                            <td class="a-right last">
                                  <span class="cart-price">
                                  <span class="cprice"><span class="c-info">{{__('frontside.cart.subtotal')}}: </span><span class="item-stot">{{$prices::formatPrice($subtotal)}}</span> </span>
                                  </span>
                            </td>
                        </tr>


                    @endforeach

                            </tbody>
                        <tfoot>
                        <tr class="first">
                            <td class="a-right" colspan="5"><label>{{__('frontside.cart.total')}}</label></td>
                            <td class="a-right gt" colspan="6">
                              <span class="cart-price">
                              <span class="cprice"><span class="c-info">{{__('frontside.cart.total')}}: </span><span id="grandtotal">{{$prices::formatPrice($total)}}</span> </span>
                              </span>
                            </td>
                        </tr>
                        </tfoot>
                    </table>

                        <div class="row cartbtns">
                            <div class="col-xs-6 a-left"><a href="{{url(tr_url('/'))}}" class="btn btn-default">{{__('frontside.cart.continue_shopping')}}</a></div>
                            <div class="col-xs-6 a-right"><a href="{{url(tr_url('checkout'))}}" id="make-order" class="btn btn-default">{{__('frontside.cart.make_order')}}</a>
                            </div>
                            <br clear="all" />
                        </div>

                    </form>
                @else
                    <div class="text-center">
                        <br /><br /><br />{{__('frontside.cart.cart_empty')}}<br /><br /><a href="/">{{__('frontside.cart.go_to_homepage')}}</a>
                    </div>
                @endif
                </div>
            </div><!-- / #main -->
                </div>
            </div>
        </div><!-- / .row -->
    </div><!-- /.container-fluid -->
    </section>
@endsection

@push('css')
    <link rel="stylesheet" href="{{asset('assets/css/jquery.bootstrap-touchspin.css')}}">
    <link rel="stylesheet" href="{{asset('assets/css/cart.css')}}">
@endpush

@push('scripts')
    <script src="{{asset('assets/js/jquery.bootstrap-touchspin.js')}}"></script>
    <script src="{{asset('assets/js/jquery.number.min.js')}}"></script>
    <script src="{{asset('assets/js/cart.js')}}"></script>
@endpush
