@extends('layouts.user') @section('title', $country->name . ' — Country Details') @push('styles') @endpush @section('content') @php /* ── Pre-compute commonly used values ── */ $economy = $country->latestEconomy; $weather = $country->latestWeather; $risk = $country->latestRiskScore; $currency = $country->currency; $ports = $country->ports->sortBy('port_name'); /* Population from economy table */ $population = isset($economy->population) ? number_format($economy->population) : 'N/A'; /* Risk badge colors */ $riskLevel = $risk?->risk_level ?? 'N/A'; $riskBadgeCls = match($riskLevel) { 'Critical' => 'background:#fee2e2;color:#b91c1c;', 'High' => 'background:#fff7ed;color:#c2410c;', 'Medium' => 'background:#fffbeb;color:#b45309;', 'Low' => 'background:#f0fdf4;color:#166534;', default => 'background:#f8fafc;color:#64748b;', }; $riskScore = $risk?->total_score ?? null; /* Weather category */ $wxCode = $weather?->weather_code ?? 0; $wxRisk = $weather?->storm_risk ?? 0; $wxBannerCls = 'fog'; if ($weather) { if ($wxRisk >= 60 || in_array($wxCode, [95,96,99])) $wxBannerCls = 'storm'; elseif ($wxRisk >= 25 || in_array($wxCode, [61,63,65,80,81,82])) $wxBannerCls = 'rain'; elseif (in_array($wxCode, [71,73,75,77,85,86])) $wxBannerCls = 'snow'; elseif (in_array($wxCode, [1,2,3,45,48])) $wxBannerCls = 'cloudy'; elseif ($wxCode === 0) $wxBannerCls = 'clear'; } $wxEmoji = match($wxBannerCls) { 'clear' => '☀️', 'cloudy' => '⛅', 'rain' => '🌧️', 'storm' => '⛈️', 'snow' => '❄️', default => '🌫️', }; /* Exchange rate */ $latestRate = $currency ? \App\Models\ExchangeRate::where('base_currency_id', $currency->id)->orderByDesc('recorded_at')->first() : null; /* Watchlist check */ $inWatchlist = auth()->check() ? \App\Models\Watchlist::where('user_id', auth()->id())->where('country_id', $country->id)->exists() : false; /* Port status counts */ $statusCounts = $ports->groupBy('status')->map->count(); @endphp
No weather data available.
{{ $currency->name }}
{{ $currency->code }}{{ $currency->symbol ? ' · ' . $currency->symbol : '' }}
{{ number_format($latestRate->exchange_rate, 4) }}
vs USD @if($latestRate->change_percentage !== null) ({{ $latestRate->change_percentage >= 0 ? '+' : '' }}{{ number_format($latestRate->change_percentage, 2) }}%) @endif
No economy data available.
No risk score calculated yet.
No ports recorded for this country.
{{ $statusCounts[$st] ?? 0 }}
{{ $st }}
| Port Name | Code | City | Status | Coordinates |
|---|---|---|---|---|
| {{ $port->port_name }} | {{ $port->port_code }} | {{ $port->city ?: '—' }} | @php $stColor = match($port->status) { 'Open' => 'background:#f0fdf4;color:#166534;', 'Limited' => 'background:#fffbeb;color:#92400e;', 'Congested' => 'background:#fff7ed;color:#c2410c;', 'Closed' => 'background:#fef2f2;color:#991b1b;', default => 'background:#f8fafc;color:#64748b;', }; @endphp {{ $port->status }} | @if($port->latitude !== null && $port->longitude !== null) {{ number_format($port->latitude, 4) }}, {{ number_format($port->longitude, 4) }} @else — @endif |