{{-- Header demo-digital-agency-2 — Marketplace style (Shopify / MercadoLibre)
Estructura:
Top bar (fixed, dark): logo + buscador prominente + acciones (lang + auth)
Sub bar (sticky): nav menu de categorías + contacto
--}}
@php
use App\Modules\Products\Models\ProductCategory;
use App\Modules\Products\Models\Product;
// Cargar catalog.json + core labels (matching del controller buildCoresIndex)
$catalogData = [];
$catalogPath = database_path('seeders/products/catalog.json');
if (file_exists($catalogPath)) {
$catalogData = json_decode(file_get_contents($catalogPath), true) ?? [];
unset($catalogData['_comment']);
}
$coreLabels = [
'agency' => 'Agencia', 'art-design' => 'Arte y Diseño', 'bp-dinamic' => 'Sitio Dinámico',
'business-catalogue' => 'Catálogo Empresarial', 'catalogue-ai' => 'Catálogo AI',
'concierge' => 'Concierge', 'construction' => 'Construcción', 'construction-2' => 'Arquitectura',
'corporative' => 'Corporativo', 'creative-agency' => 'Agencia Creativa',
'creative-video-editor' => 'Editor de Video', 'financial-wealth' => 'Finanzas',
'foundations-ong' => 'Fundaciones y ONG', 'insurance-advisor' => 'Seguros',
'law-firm-digital' => 'Estudios Jurídicos', 'nutritionist' => 'Salud y Bienestar',
'personal-brand' => 'Marca Personal', 'petite-website' => 'Sitio Petite',
'photography' => 'Fotografía', 'real-estate' => 'Inmobiliaria',
'restaurant-bar' => 'Restaurantes y Bares', 'sitio-web-profesional' => 'Sitio Profesional',
'standard-website' => 'Sitio Standard', 'website-reseller' => 'Para Revendedores',
];
// Categorías ordenadas por count desc (todas las que tengan al menos 1 producto)
$popularCategories = collect();
$categoriesWithCores = [];
try {
$popularCategories = ProductCategory::withCount(['products'])
->get()
->sortByDesc('products_count')
->where('products_count', '>', 0)
->take(13)
->values();
// Para cada categoría, agrupar sus productos por core preset
foreach ($popularCategories as $cat) {
$products = Product::where('category_id', $cat->id)->get();
$coresInCat = [];
foreach ($products as $p) {
$core = $catalogData[$p->slug]['core'] ?? null;
if (!$core) continue;
if (!isset($coresInCat[$core])) {
$coresInCat[$core] = [
'slug' => $core,
'name' => $coreLabels[$core] ?? ucwords(str_replace('-', ' ', $core)),
'count' => 0,
'active' => 0,
];
}
$coresInCat[$core]['count']++;
if ($p->is_active) $coresInCat[$core]['active']++;
}
uasort($coresInCat, fn($a, $b) => $b['active'] <=> $a['active'] ?: $b['count'] <=> $a['count']);
$categoriesWithCores[$cat->slug] = [
'name' => $cat->name,
'slug' => $cat->slug,
'products_count' => $cat->products_count,
'cores' => array_values(array_slice($coresInCat, 0, 8)),
];
}
} catch (\Throwable $e) {}
@endphp