@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
{{-- ── BACK NAV ──────────────────────────────────────────────── --}}
← Back to Countries @auth
@csrf
@endauth
{{-- ── HERO HEADER ────────────────────────────────────────────── --}}
@if($country->flag_url) {{ $country->name }} flag @endif

{{ $country->name }}

{{ $country->iso2 }} / {{ $country->iso3 }} @if($risk) {{ $riskLevel }} Risk @endif
@if($country->region) 🌍 {{ $country->region }}{{ $country->subregion ? ' · ' . $country->subregion : '' }} @endif @if($country->capital) 🏛️ {{ $country->capital }} @endif @if($population !== 'N/A') 👥 {{ $population }} @endif @if($country->timezone) 🕐 {{ $country->timezone }} @endif @if($currency) 💱 {{ $currency->code }}{{ $currency->symbol ? ' (' . $currency->symbol . ')' : '' }} @endif
@if($riskScore !== null)
{{ number_format($riskScore, 1) }}
Risk Score
@endif
{{-- ── ROW 1: Weather · Economy · Risk Score ──────────────────── --}}
{{-- Weather Card --}}
🌤 Current Weather @if($weather) {{ $weather->recorded_at?->diffForHumans() }} @endif
@if($weather) {{-- Weather Banner --}}
{{ $wxEmoji }}

{{ $weather->weather_status }}

{{ $weather->city }}

🌡 Temperature
{{ number_format($weather->temperature, 1) }}°C
💧 Humidity
{{ number_format($weather->humidity, 0) }}%
🌬 Wind Speed
{{ number_format($weather->wind_speed, 1) }} km/h
🌧 Rainfall
{{ number_format($weather->rainfall, 1) }} mm
⬇ Pressure
{{ $weather->pressure ? $weather->pressure . ' hPa' : 'N/A' }}
⚡ Storm Risk
{{ $wxRisk }}%
{{-- Storm risk bar --}}
Storm Probability{{ $wxRisk }}%
@else
🌤️

No weather data available.

@endif
{{-- Economy Card --}}
💼 Economy @if($economy) {{ $economy->year }} @endif
@if($economy)
💰
GDP (USD)
${{ $economy->gdp ? number_format($economy->gdp / 1e9, 1) . 'B' : 'N/A' }}
💵
Per Capita
${{ $economy->gdp_per_capita ? number_format($economy->gdp_per_capita) : 'N/A' }}
📈
Growth
{{ $economy->economic_growth !== null ? ($economy->economic_growth >= 0 ? '+' : '') . number_format($economy->economic_growth, 1) . '%' : 'N/A' }}
📉
Inflation
{{ $economy->inflation !== null ? number_format($economy->inflation, 1) . '%' : 'N/A' }}
👥
Unemployment
{{ $economy->unemployment !== null ? number_format($economy->unemployment, 1) . '%' : 'N/A' }}
{{-- Currency info below --}} @if($currency)

{{ $currency->name }}

{{ $currency->code }}{{ $currency->symbol ? ' · ' . $currency->symbol : '' }}

@if($latestRate)

{{ number_format($latestRate->exchange_rate, 4) }}

vs USD @if($latestRate->change_percentage !== null) ({{ $latestRate->change_percentage >= 0 ? '+' : '' }}{{ number_format($latestRate->change_percentage, 2) }}%) @endif

@endif
@endif @else
💼

No economy data available.

@endif
{{-- Risk Score Card --}}
⚠️ Risk Score @if($risk) {{ $riskLevel }} @endif
@if($risk) {{-- Big Score --}}
{{ number_format($riskScore, 1) }}
/ 100 Total Risk
{{ $riskScore > 60 ? '🔴' : ($riskScore > 30 ? '🟡' : '🟢') }}
{{-- Component bars --}}
@foreach([ ['🌩', 'Weather', $risk->weather_score, 'bg-blue-400'], ['💼', 'Economy', $risk->economy_score, 'bg-amber-400'], ['📉', 'Inflation', $risk->inflation_score, 'bg-orange-400'], ['💱', 'Currency', $risk->currency_score, 'bg-emerald-400'], ['🗳', 'Political', $risk->political_score, 'bg-purple-400'], ['⚓', 'Port', $risk->port_score, 'bg-sky-400'], ] as [$icon, $label, $val, $color])
{{ $icon }} {{ $label }} {{ $val !== null ? number_format($val, 1) : '—' }}
@endforeach
@if($risk->recommendation)
💡 {{ $risk->recommendation }}
@endif @else
⚠️

No risk score calculated yet.

@endif
{{-- /row-1 --}} {{-- ── ROW 2: Overview ────────────────────────────────────────── --}}
📊 Country Overview
@php $overviewItems = [ ['🏙️', '#fef9c3', 'Capital', $country->capital ?? 'N/A'], ['👥', '#dcfce7', 'Population', $population], ['🗺️', '#e0f2fe', 'Area', $country->area ? number_format($country->area) . ' km²' : 'N/A'], ['🕐', '#f3e8ff', 'Timezone', $country->timezone ?? 'N/A'], ['🌍', '#fff7ed', 'Region', $country->region ?? 'N/A'], ['🏳️', '#f0fdf4', 'Sub-Region', $country->subregion ?? 'N/A'], ['📞', '#fef2f2', 'Calling Code', $country->phone_code ? '+' . $country->phone_code : 'N/A'], ['🌐', '#fafafa', 'ISO Code', $country->iso2 . ' / ' . $country->iso3], ]; @endphp @foreach($overviewItems as [$icon, $iconBg, $label, $value])
{{ $icon }}
{{ $label }}
{{ $value }}
@endforeach
{{-- ── ROW 3: Ports ───────────────────────────────────────────── --}}
⚓ Ports ({{ $ports->count() }}) @if($ports->count() > 0) 🗺️ View on Map @endif
@if($ports->isEmpty())
⚓

No ports recorded for this country.

@else {{-- Port status mini-stats --}}
@foreach(['Open' => ['text-emerald-600','bg-emerald-50'], 'Limited' => ['text-amber-600','bg-amber-50'], 'Congested' => ['text-orange-600','bg-orange-50'], 'Closed' => ['text-red-600','bg-red-50']] as $st => [$cls, $bg])

{{ $statusCounts[$st] ?? 0 }}

{{ $st }}

@endforeach
{{-- Port filter --}} @if($ports->count() > 10)
@endif {{-- Ports table --}}
@foreach($ports as $port) @endforeach
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
@endif
{{-- /cd-page --}} @endsection @push('scripts') @endpush