@php
    $cartCount = !empty($userCarts) ? count($userCarts) : 0;
    $cartUrl = auth()->check() ? '/cart/' : '/login?url=' . urlencode(url('/cart'));
@endphp
<div class="dropdown d-inline-block navbar-cart-dropdown">
    <a href="{{ $cartUrl }}" class="btn btn-transparent position-relative navbar-cart-toggle" id="navbarShopingCart" data-toggle="dropdown" data-display="static"
       aria-haspopup="true" aria-expanded="false" title="{{ trans('cart.shopping_cart') }}">
        <i data-feather="shopping-cart" width="22" height="22"></i>
        <span id="navbarCartBadge" class="badge badge-circle-primary navbar-cart-badge {{ $cartCount > 0 ? '' : 'd-none' }}">{{ $cartCount > 0 ? $cartCount : '' }}</span>
    </a>

    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarShopingCart">
        <div class="d-md-none navbar-dropdown-mobile-header border-bottom mb-20 pb-10 text-right">
            <button type="button" class="close-dropdown btn p-0 border-0 bg-transparent" aria-label="{{ trans('public.close') }}">
                <i data-feather="x" width="32" height="32"></i>
            </button>
        </div>
        <div class="h-100">
            <div class="navbar-shopping-cart h-100" data-simplebar>
                @if($cartCount > 0)
                    <div class="mb-auto">
                        @foreach($userCarts as $cart)
                            @php
                                $cartItemInfo = $cart->getItemInfo();
                            @endphp
                            @if(empty($cartItemInfo) || empty($cartItemInfo['title']))
                                @continue
                            @endif
                            <div class="navbar-cart-box d-flex align-items-center mb-15">
                                <a href="{{ $cartItemInfo['itemUrl'] ?? '#' }}" class="navbar-cart-img flex-shrink-0">
                                    <img src="{{ $cartItemInfo['imgPath'] }}" alt="" class="img-cover"/>
                                </a>
                                <div class="navbar-cart-info flex-grow-1 mr-10">
                                    <a href="{{ $cartItemInfo['itemUrl'] }}">
                                        <h4 class="font-14 font-weight-bold text-dark-blue mb-5">{{ $cartItemInfo['title'] }}</h4>
                                    </a>
                                    @if(!empty($cartItemInfo['quantity']))
                                        <span class="font-12 text-gray">({{ $cartItemInfo['quantity'] }} {{ trans('update.product') }})</span>
                                    @endif
                                    <div class="price mt-5">
                                        @php $itemCurrency = $cartItemInfo['currency'] ?? ($cartOrderCurrency ?? 'EGP'); @endphp
                                        @if(!empty($cartItemInfo['discountPrice']))
                                            <span class="text-primary font-weight-bold">{{ formatModelPrice($cartItemInfo['discountPrice'], null, $itemCurrency) }}</span>
                                            <span class="off ml-10">{{ formatModelPrice($cartItemInfo['price'], null, $itemCurrency) }}</span>
                                        @else
                                            <span class="text-primary font-weight-bold">{{ formatModelPrice($cartItemInfo['price'], null, $itemCurrency) }}</span>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        @endforeach
                    </div>
                    <div class="navbar-cart-actions">
                        <div class="navbar-cart-total mt-15 border-top pt-15 d-flex align-items-center justify-content-between">
                            <strong class="total-text">{{ trans('cart.total') }}</strong>
                            <strong class="text-primary font-weight-bold">{{ $cartTotalFormatted ?? formatPaymentPrice($totalCartsPrice ?? 0, $cartOrderCurrency ?? 'EGP') }}</strong>
                        </div>
                        <a href="{{ $cartUrl }}" class="btn btn-sm btn-primary btn-block mt-15">{{ trans('cart.go_to_cart') }}</a>
                    </div>
                @else
                    <div class="d-flex align-items-center text-center py-30 px-20">
                        <i data-feather="shopping-cart" width="20" height="20" class="mr-10"></i>
                        <span>{{ trans('cart.your_cart_empty') }}</span>
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
