@props(['station', 'rank', 'isCheapest' => false]) @php // Estrazione sicura dei dati (gestisce sia Array da Cache che Oggetti Eloquent) $stationId = is_array($station) ? ($station['id'] ?? null) : $station->id; $reportedAtRaw = is_array($station) ? ($station['reported_at'] ?? null) : $station->reported_at; $address = is_array($station) ? ($station['address'] ?? '') : $station->address; $municipality = is_array($station) ? ($station['municipality'] ?? '') : $station->municipality; $price = is_array($station) ? ($station['price'] ?? 0) : $station->price; // Gestione sicura del brand/gestore (metodo dell'oggetto o chiave array) $managerLabel = ''; if (is_object($station) && method_exists($station, 'managerLabel')) { $managerLabel = $station->managerLabel(); } else { $managerLabel = is_array($station) ? ($station['name'] ?? $station['brand'] ?? $station['marche'] ?? 'Distributore') : ($station->name ?? 'Distributore'); } // TASK 3: lettura corretta del timestamp e calcolo freshness $reportedAt = null; if (!empty($reportedAtRaw)) { try { $reportedAt = $reportedAtRaw instanceof \Carbon\Carbon ? $reportedAtRaw : \Carbon\Carbon::parse($reportedAtRaw); } catch (\Exception $e) { $reportedAt = null; } } $hours = $reportedAt ? now()->diffInHours($reportedAt) : 999; $freshColor = match(true) { $hours <= 24 => 'bg-emerald-400', $hours <= 48 => 'bg-amber-400', default => 'bg-red-400', }; $freshTitle = match(true) { $hours <= 24 => 'Aggiornato nelle ultime 24h', $hours <= 48 => 'Aggiornato ieri', default => 'Non aggiornato da ' . round($hours / 24) . ' giorni', }; @endphp
{{ $rank }}
{{ $managerLabel }} @if($isCheapest) 🏆 Più economico @endif

{{ $address }}, {{ ucwords(strtolower($municipality)) }}

{{ number_format($price, 3, ',', '.') }}
€/L