<section class="product"> 
<div class="text-center mb-4">
            <h2 class="section-title px-5"><span class="px-2">Our Products</span></h2>
        </div>
        <button class="pre-btn"><img src={{ asset('/storage/img/arrow.png') }} alt=""></button>
        <button class="nxt-btn"><img src={{ asset('/storage/img/arrow.png') }} alt=""></button>
        <div class="product-container">

        @foreach($product as $key => $products)

                    <div class="product-card">
                        <div class="product-card-img">
                        @if($products->current_stock >= 1)
                            <label class="stock bg-success">In Stock</label>
                         @else
                            <label class="stock bg-danger">Out of Stock</label>
                         @endif
                            <img src={{ asset('/storage/'.$products->thumbnail_img) }} height="250px" >
                        </div>
                        <div class="product-card-body">
                            <p class="product-brand"> {{ $products->category->name }} </p>
                            <h5 class="product-name">
                               <a href="{{ route('viewproduct',[$products->id]) }}">
                                  {{ $products->name }} 
                               </a>
                            </h5>
                            <div>
                            @php
                                    $prignalprice=$products->unit_price;
                                    $descount=$products->discount;
                                    $price=$prignalprice-$descount;
                             @endphp

                          @php
                                $choices = [];
                               if($products->choice_options){
                               $rawChoices = json_decode($products->choice_options, true);
                               foreach($rawChoices as $choice){
                               $choices[] = [
                               'attribute_id' => $choice['attribute_id'],
                               'attribute_name' => \App\Models\Attribute::find($choice['attribute_id'])->name ?? '',
                               'values' => $choice['values']
                               ];}}
                        @endphp

                       <div class="mt-1"><span class="selling-price">Rs:</span>   <span class="selling-price">{{ number_format($price,2) }}</span></div>
                       
                       <div class="mt-1"><span class="original-price">{{ number_format($products->unit_price,2) }}</span></div>
                            </div>
                            <div class="card-footer d-flex justify-content-between bg-light">
                                 <a href="{{ route('viewproduct',[$products->id]) }}" class="btn btn-sm text-dark p-0"><i class="fas fa-eye text-primary mr-1"></i>View Detail</a>
                                 <a href="javascript:void(0);"
               class="btn btn-sm text-dark p-0"
               onclick="show_addtocart_modal(this)"
               data-id="{{ $products->id }}"
               data-name="{{ $products->name }}"
               data-images="{{ $products->photos }}"
               data-unitprice="{{ $products->unit_price }}"
               data-discount="{{ $products->discount }}"
               data-unit="{{ $products->unit }}"
               data-choice='@json($choices)'
               data-colors='@json(json_decode($products->colors, true))'
               data-stocks='@json($products->stocks)'
               >
               <i class="fas fa-shopping-cart text-primary me-1"></i> Add To Cart
            </a>
                                </div>
                         
                        </div>
                    </div>

        @endforeach
        </div>
</section>


@section('modal')
@include('frontend.modal.addtocartmodal')
@endsection

@section('script')
<script>
 const STORAGE_URL = "{{ asset('storage') }}/";
</script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
@endsection





<script src={{ asset('/storage/assets/js/script.js') }}></script>

