{{-- product-list.blade.php --}}

@if($products->count())

    @foreach($products as $product)

                        @php
                       
                    $without_extra_price = $product->without_extra_price ?? 0;
                    $extra_charge = $product->extra_charge ?? 0;
                    $price = $without_extra_price + $extra_charge;
                        $markupValue = Auth::user()->markup_value ?? 0;

                        $markupType = Auth::user()->markup_type ?? '';

                        // FINAL PRICE
                        if($markupType == 'percent'){

                            $finalPrice = $price + (($price * $markupValue) / 100);

                        }
                        elseif($markupType == 'fixed'){

                            $finalPrice = $price + $markupValue;

                        }
                        else{

                            $finalPrice = $price;

                        }

                    @endphp


        <div class="col-lg-3 col-md-4 col-sm-6">
            <div class="product-card">
                <input
                type="checkbox"
                class="shareProduct"
                value="{{ $product->id }}"
                data-name="{{ $product->collection }}"
                data-sku="{{ $product->new_triple_sku }}"
                data-type="{{ $product->product_type }}"
                data-description="{{ $product->description }}"
                data-net_weight="{{ $product->net_weight }}"
                data-metal_kt="{{ $product->metal_kt }}"
                data-metal_color="{{ $product->metal_color }}"
                data-price="{{ round($finalPrice) }}"
                data-url="{{ route('product.detail',$product->id) }}">
                <img src="{{ asset($product->image ?? 'public/img/no_image.jpg') }}" class="product-image  product-image-{{ $product->id }}" onerror="this.src='{{ asset('public/img/no_image.jpg') }}'">
                
                <div class="product-content">
                    
                    <a href="{{ route('product.detail', $product->id) }}" class="">
                    <div class="product-name product-name-{{ $product->id }}">

                        {{ $product->collection }}

                    </div>

                    <div class="product-category product-sku-{{ $product->id }}">

                        {{ $product->new_triple_sku }}

                    </div>

                    <div class="product-category product-type-{{ $product->id }}">

                        {{ $product->product_type }}

                    </div>

                    <div class="product-price product-price-{{ $product->id }}">


                    <!-- <div class="product-price">

                        ${{ number_format($finalPrice,2) }}

                    </div> -->

                        ${{ number_format($finalPrice,2) }}

                        <!-- ${{ number_format($product->final_price ?? 0) }} -->
                        <!-- {{ Auth::user()->markup_value }} -->

                    </div>

                    </a>
                 <div class="variation-colors mb-3">

                <span class="variation-circle yellow active"
                    data-metal="Y">
                </span>

                <span class="variation-circle white"
                    data-metal="W">
                </span>

                <span class="variation-circle rose"
                    data-metal="R">
                </span>

            </div>

        <button
            class="buy-btn addToCartBtn"
            data-id="{{ $product->id }}"
            data-metal="Y">
            Add To Cart
        </button>

                </div>

                </div>
            </div>

        </div>

    @endforeach

    <div class="col-12 product-pagi">

        {{ $products->onEachSide(1)->links('pagination::bootstrap-5') }}

    </div>

@else

    <div class="col-12 text-center">

        No Products Found

    </div>

@endif