@php
    /** @var \App\Models\Product $product */
    $favoriteIds = isset($favoriteProductIds) ? $favoriteProductIds : [];
    $isFavorited = in_array((int) $product->id, array_map('intval', $favoriteIds), true);

    $bestsellersList = isset($bestsellerProductIds) ? $bestsellerProductIds : [];
    $isBest = in_array((int) $product->id, array_map('intval', $bestsellersList), true);

    $newDays = isset($new_product_days) ? (int) $new_product_days : 30;
    $isNew = ! empty($product->created_at) && ((int) $product->created_at > (time() - ($newDays * 86400)));

    $recIds = isset($recommendedFilterOptionIds) ? (array) $recommendedFilterOptionIds : [];
    $isRec = false;
    if ($recIds && $product->relationLoaded('selectedFilterOptions')) {
        $chosen = $product->selectedFilterOptions->pluck('filter_option_id')->map('intval')->all();
        foreach ($recIds as $rid) {
            if (in_array((int) $rid, $chosen, true)) {
                $isRec = true;
                break;
            }
        }
    }

    $__summaryRaw = isset($product->summary) ? trim(strip_tags($product->summary)) : '';
    $__cardExcerpt = $__summaryRaw !== ''
        ? \Illuminate\Support\Str::limit($__summaryRaw, 92)
        : '';
@endphp

<div class="imt-product-card imt-product-card--market imt-product-card--{{ isset($variant) ? $variant : 'grid' }}">
    <div class="imt-product-card__shell">
        <div class="imt-product-card__visual position-relative">
            <div class="imt-product-card__visual-sheet" aria-hidden="true"></div>

            @if($product->getAvailability() < 1)
                <span class="imt-product-card__oos">{{ trans('update.out_of_stock') }}</span>
            @else
                @if($isNew)
                    <span class="imt-badge imt-badge--new">{{ trans('update.badge_new') }}</span>
                @elseif($isBest)
                    <span class="imt-badge imt-badge--bestseller">{{ trans('update.badge_bestseller') }}</span>
                @elseif($isRec)
                    <span class="imt-badge imt-badge--recommended">{{ trans('update.badge_recommended') }}</span>
                @endif
            @endif

            <button type="button"
                    class="imt-product-card__fav js-imt-product-favorite @if($isFavorited) is-active @endif"
                    aria-pressed="{{ $isFavorited ? 'true' : 'false' }}"
                    aria-label="{{ trans('update.catalog_wishlist_toggle') }}"
                    data-product-id="{{ $product->id }}">
                <i data-feather="heart" width="17" height="17"></i>
            </button>

            <a href="{{ $product->getUrl() }}" class="imt-product-card__thumb-link d-block overflow-hidden">
                {!! premium_picture_tag([
                    'src' => $product->thumbnail,
                    'alt' => clean($product->title, 'title'),
                    'class' => 'imt-product-card__thumb img-cover',
                    'loading' => 'lazy',
                    'sizes' => '(max-width: 768px) 50vw, 280px',
                ]) !!}
            </a>

            @if(!empty($product->category))
                <a href="{{ $product->category->getUrl() }}" class="imt-product-card__cat-chip">
                    {{ $product->category->title }}
                </a>
            @endif
        </div>

        <div class="imt-product-card__body">
            <a href="{{ $product->getUrl() }}" class="imt-product-card__title">{{ clean($product->title,'title') }}</a>

            @if($__cardExcerpt !== '')
                <p class="imt-product-card__meta">{{ $__cardExcerpt }}</p>
            @endif

            @if((int) $product->getRate() > 0)
                <div class="imt-product-card__rate-row">
                    @include('web.default.includes.webinar.rate', [
                        'rate' => $product->getRate(),
                        'className' => 'imt-product-card__rate mt-0',
                        'dontShowRate' => true,
                    ])
                </div>
            @endif

            <div class="imt-product-card__footer">
                <div class="imt-product-card__pricing">
                    @if(!empty($isRewardProducts) && ! empty($product->point))
                        <span class="imt-price imt-price--points">{{ $product->point }} {{ trans('update.points') }}</span>
                    @elseif(! empty($product->price) && $product->price > 0)
                        @if($product->getPriceWithActiveDiscountPrice() < $product->price)
                            <span class="imt-price imt-price--lg">{{ handlePrice($product->getPriceWithActiveDiscountPrice()) }}</span>
                            <span class="imt-price-off">{{ handlePrice($product->price) }}</span>
                        @else
                            <span class="imt-price imt-price--lg">{{ handlePrice($product->price) }}</span>
                        @endif
                    @else
                        <span class="imt-price imt-price--free imt-price--lg">{{ trans('public.free') }}</span>
                    @endif
                </div>

                @if(empty($isRewardProducts))
                    <div class="imt-product-card__actions-row">
                        @if($product->getAvailability() > 0)
                            <a href="{{ $product->getUrl() }}" class="btn btn-primary btn-sm imt-product-card__buy">
                                {{ trans('update.buy_product') }}
                            </a>
                            <button type="button"
                                    data-id="{{ $product->id }}"
                                    class="btn imt-product-card__cart btn-add-product-to-cart">
                                <i data-feather="shopping-cart" width="17" height="17"></i>
                                {{ trans('update.add_to_cart') }}
                            </button>
                        @endif

                        <button type="button"
                                class="btn imt-product-card__peek js-imt-open-quick-view @if($product->getAvailability() < 1) imt-product-card__peek--stretch @endif"
                                data-product-id="{{ $product->id }}"
                                aria-label="{{ trans('update.catalog_quick_view') }}">
                            <i data-feather="eye" width="17" height="17"></i>
                        </button>
                    </div>
                @else
                    <div class="imt-product-card__actions-row imt-product-card__actions-row--reward">
                        <button type="button"
                                class="btn imt-product-card__peek imt-product-card__peek--reward js-imt-open-quick-view w-100"
                                data-product-id="{{ $product->id }}"
                                aria-label="{{ trans('update.catalog_quick_view') }}">
                            <i data-feather="eye" width="17" height="17"></i>
                            <span class="imt-product-card__peek-label">{{ trans('update.catalog_quick_view') }}</span>
                        </button>
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
