@forelse($servicesByCategory as $categoryId => $serviceCards)
@php
$categoryName = $serviceCards->first()['category_name'] ?? 'More';
$categoryFilterId = (int) $categoryId;
$viewAllParams = $categoryFilterId > 0 ? ['category_id' => $categoryFilterId] : ['q' => $categoryName];
if (! empty($selectedCountry ?? null)) {
$viewAllParams['country'] = $selectedCountry;
}
@endphp
@foreach($serviceCards as $card)
@php
$palette = $cardPalettes[abs(crc32((string) $card['service_name'])) % count($cardPalettes)];
$serviceName = strtoupper((string) $card['service_name']);
$compactLogoLabel = preg_replace('/[^A-Z0-9]/', '', $serviceName) ?: 'APP';
$serviceLogoChunks = collect();
if (preg_match('/\s/', trim($serviceName))) {
$serviceLogoChunks = collect(preg_split('/[\s\-_]+/', $serviceName))
->map(fn ($chunk) => preg_replace('/[^A-Z0-9]/', '', (string) $chunk))
->filter()
->map(fn ($chunk) => substr($chunk, 0, 5))
->take(3)
->values();
}
if ($serviceLogoChunks->isEmpty()) {
$compactLogoLength = strlen($compactLogoLabel);
if ($compactLogoLength <= 5) {
$serviceLogoChunks = collect([$compactLogoLabel]);
} elseif ($compactLogoLength <= 8) {
$serviceLogoChunks = collect([substr($compactLogoLabel, 0, 3), substr($compactLogoLabel, 3)]);
} elseif ($compactLogoLength <= 10) {
$serviceLogoChunks = collect([substr($compactLogoLabel, 0, 5), substr($compactLogoLabel, 5)]);
} else {
$serviceLogoChunks = collect([
substr($compactLogoLabel, 0, 5),
substr($compactLogoLabel, 5, 5),
substr($compactLogoLabel, 10, 5),
]);
}
}
$profilesCollection = collect($card['profiles'] ?? []);
$extraProfiles = (int) ($card['extra_profiles'] ?? 0);
$extraProfilesLabel = $extraProfiles > 99 ? '99+' : (string) $extraProfiles;
@endphp
@endforeach