@forelse($results as $result)
@php
$resultType = $result['type'] ?? 'product';
$item = $result['item'];
if ($resultType === 'product') {
$imageUrl = $item->pro_img
? asset('images/product/' . $item->pro_img)
: asset('assets/img/icon/category_card_1.svg');
$title = $item->title ?? $item->description() ?? $item->pro_description_pt ?? '';
$url = $item->pro_slug ? route('packs.show', $item->category->cat_slug) : '#';
$category = $item->category?->description() ?? '';
$categoryType = $item->category?->cat_type ?? '';
$icon = 'fa-box';
$iconColor = 'var(--verde-dona)';
$badgeColor = 'var(--verde-dona)';
if ($categoryType === 'Voucher') {
$icon = 'fa-gift';
$iconColor = 'var(--laranja-cta)';
$badgeColor = 'var(--laranja-cta)';
$url = '#';
} elseif (in_array($categoryType, ['Sopa', 'Sobremesa', 'Sumo'])) {
$icon = 'fa-utensils';
$iconColor = 'var(--verde-oliva)';
$badgeColor = 'var(--verde-oliva)';
$url = '#';
}
$price = null;
$priceFormatted = null;
if ($categoryType === 'Voucher') {
if (isset($item->voucher_price) && $item->voucher_price > 0) {
$price = $item->voucher_price;
$priceFormatted = $item->voucher_price_formatted ?? number_format($price, 2, ',', ' ') . ' €';
} elseif ($item->relationLoaded('voucherPricePtm') && $item->voucherPricePtm) {
$price = $item->voucherPricePtm->ptm_price ?? null;
$priceFormatted = $price ? number_format($price, 2, ',', ' ') . ' €' : null;
}
} elseif ($item->relationLoaded('typeMeals') && $item->typeMeals->isNotEmpty()) {
$firstPivot = $item->typeMeals->first()?->pivot;
$price = $firstPivot?->ptm_price ?? null;
$priceFormatted = $price ? number_format($price, 2, ',', ' ') . ' €' : null;
}
} else {
$imageUrl = asset('assets/img/icon/category_card_1.svg');
$title = '';
$url = '#';
$category = '';
$categoryType = '';
$icon = 'fa-box';
$iconColor = 'var(--verde-dona)';
$badgeColor = 'var(--verde-dona)';
$price = null;
$priceFormatted = null;
}
@endphp
@if($categoryType === 'Voucher')
{{ __('search.voucher') }}
@elseif(in_array($categoryType, ['Sopa', 'Sobremesa', 'Sumo']))
{{ $categoryType }}
@else
{{ __('search.pack') }}
@endif
@if($category)
{{ $category }}
@endif
@if(isset($result['matches']) && !empty($result['matches']))
{{ __('search.matches') }}:
@foreach($result['matches'] as $match)
{{ $match }}
@endforeach
@endif
@if($price && $price > 0)
{{ $priceFormatted ?? number_format($price, 2, ',', ' ') . ' €' }}
@endif
{{-- Packs → abrir página --}}
@if(!in_array($categoryType, ['Voucher','Sopa','Sobremesa','Sumo']))
{{-- Outros produtos → adicionar ao carrinho --}}
@else
@endif
@empty
{{ __('search.no_results_in_tab') }}
@endforelse