@extends('layouts.user') @section('title', 'Country Comparison Engine') @push('styles') @endpush @section('content') @php $countryFlags = []; foreach ($countries ?? [] as $c) { $countryFlags[$c->iso2] = $c->flag_url; } $popularPairs = [ ['c1' => 'US', 'c2' => 'CN', 'name1' => 'United States', 'name2' => 'China'], ['c1' => 'JP', 'c2' => 'KR', 'name1' => 'Japan', 'name2' => 'South Korea'], ['c1' => 'SG', 'c2' => 'ID', 'name1' => 'Singapore', 'name2' => 'Indonesia'], ['c1' => 'DE', 'c2' => 'FR', 'name1' => 'Germany', 'name2' => 'France'], ]; @endphp {{-- Flower Decorations --}}
Decorative Flower
Decorative Flower
{{-- ── Header ─────────────────────────────────────────────────── --}}

Country Comparison Engine

Compare economic, weather, and risk indicators side-by-side.

{{-- ── Selection Form ──────────────────────────────────────────── --}}
{{-- ── Popular Comparisons Section ─────────────────────────────────── --}}

Popular Comparisons

Quickly compare countries that are frequently analyzed in global supply chain.

@foreach($popularPairs as $pair) @php $isActive = request('country1') == $pair['c1'] && request('country2') == $pair['c2']; $flag1 = $countryFlags[$pair['c1']] ?? null; $flag2 = $countryFlags[$pair['c2']] ?? null; @endphp @endforeach
{{-- Wraps the comparison results in a static container to handle AJAX updates smoothly --}} {{-- Wraps the comparison results in a static container to handle AJAX updates smoothly --}}
@if($country1 && $country2) @php $risk1 = $country1->riskScores->sortByDesc('calculated_at')->first(); $risk2 = $country2->riskScores->sortByDesc('calculated_at')->first(); $eco1 = $country1->economies->sortByDesc('year')->first(); $eco2 = $country2->economies->sortByDesc('year')->first(); $weather1 = $country1->weatherRecords->sortByDesc('recorded_at')->first(); $weather2 = $country2->weatherRecords->sortByDesc('recorded_at')->first(); @endphp
{{-- ── Side-by-side cards ── --}}
@foreach([ ['current' => $country1, 'other' => $country2, 'index' => 1], ['current' => $country2, 'other' => $country1, 'index' => 2] ] as $item) @php $country = $item['current']; $other = $item['other']; $idx = $item['index']; $risk = $idx === 1 ? $risk1 : $risk2; $otherRisk = $idx === 1 ? $risk2 : $risk1; $eco = $idx === 1 ? $eco1 : $eco2; $otherEco = $idx === 1 ? $eco2 : $eco1; $weather = $idx === 1 ? $weather1 : $weather2; $otherWeather = $idx === 1 ? $weather2 : $weather1; $cur = $country->currency; $rate = $cur ? \App\Models\ExchangeRate::where('base_currency_id', $cur->id) ->orderByDesc('recorded_at')->first() : null; // Helper to check if a value is better $rsBetter = false; $rsWorse = false; if (isset($risk1->total_score) && isset($risk2->total_score)) { if ($risk1->total_score != $risk2->total_score) { $rsBetter = $idx === 1 ? ($risk1->total_score < $risk2->total_score) : ($risk2->total_score < $risk1->total_score); $rsWorse = !$rsBetter; } } $gdpBetter = false; $gdpWorse = false; if (isset($eco1->gdp) && isset($eco2->gdp)) { if ($eco1->gdp != $eco2->gdp) { $gdpBetter = $idx === 1 ? ($eco1->gdp > $eco2->gdp) : ($eco2->gdp > $eco1->gdp); $gdpWorse = !$gdpBetter; } } $infBetter = false; $infWorse = false; if (isset($eco1->inflation) && isset($eco2->inflation)) { if ($eco1->inflation != $eco2->inflation) { $infBetter = $idx === 1 ? ($eco1->inflation < $eco2->inflation) : ($eco2->inflation < $eco1->inflation); $infWorse = !$infBetter; } } $groBetter = false; $groWorse = false; if (isset($eco1->economic_growth) && isset($eco2->economic_growth)) { if ($eco1->economic_growth != $eco2->economic_growth) { $groBetter = $idx === 1 ? ($eco1->economic_growth > $eco2->economic_growth) : ($eco2->economic_growth > $eco1->economic_growth); $groWorse = !$groBetter; } } $stBetter = false; $stWorse = false; if (isset($weather1->storm_risk) && isset($weather2->storm_risk)) { if ($weather1->storm_risk != $weather2->storm_risk) { $stBetter = $idx === 1 ? ($weather1->storm_risk < $weather2->storm_risk) : ($weather2->storm_risk < $weather1->storm_risk); $stWorse = !$stBetter; } } // Define the list of indicators $indicators = [ [ 'label' => 'GDP', 'icon' => '', 'hasData' => $eco && $eco->gdp !== null, 'value' => $eco && $eco->gdp ? '$' . number_format($eco->gdp / 1e9, 1) . 'B' : '', 'isBetter' => $gdpBetter, 'isWorse' => $gdpWorse ], [ 'label' => 'Economic Growth', 'icon' => '', 'hasData' => $eco && $eco->economic_growth !== null, 'value' => $eco && $eco->economic_growth !== null ? number_format($eco->economic_growth, 1) . '%' : '', 'isBetter' => $groBetter, 'isWorse' => $groWorse ], [ 'label' => 'Inflation', 'icon' => '', 'hasData' => $eco && $eco->inflation !== null, 'value' => $eco && $eco->inflation !== null ? number_format($eco->inflation, 1) . '%' : '', 'isBetter' => $infBetter, 'isWorse' => $infWorse ], [ 'label' => 'Storm Risk', 'icon' => '', 'hasData' => $weather && $weather->storm_risk !== null, 'value' => $weather ? $weather->storm_risk . '%' : '', 'isBetter' => $stBetter, 'isWorse' => $stWorse ], [ 'label' => 'Temperature', 'icon' => '', 'hasData' => $weather && $weather->temperature !== null, 'value' => $weather ? number_format($weather->temperature, 1) . ' °C' : '', 'isBetter' => false, 'isWorse' => false ], [ 'label' => 'Currency', 'icon' => '', 'hasData' => $cur !== null, 'value' => $cur ? $cur->code . ($cur->symbol ? ' (' . $cur->symbol . ')' : '') : '', 'isBetter' => false, 'isWorse' => false ], [ 'label' => 'Rate vs USD', 'icon' => '', 'hasData' => $rate !== null, 'value' => $rate ? number_format($rate->exchange_rate, 4) : '', 'isBetter' => false, 'isWorse' => false ], [ 'label' => 'Population', 'icon' => '', 'hasData' => isset($country->latestEconomy->population), 'value' => isset($country->latestEconomy->population) ? number_format($country->latestEconomy->population) : '', 'isBetter' => false, 'isWorse' => false ] ]; @endphp
{{-- Header --}}
@if($country->flag_url) @endif

{{ $country->name }}

{{ $country->region }}

@if($risk) @php $badgeCls = match ($risk->risk_level) { 'Critical', 'High' => 'bg-red-50 text-red-700 border-red-200', 'Medium' => 'bg-amber-50 text-amber-700 border-amber-200', default => 'bg-emerald-50 text-emerald-700 border-emerald-200' }; @endphp {{ $risk->risk_level }} @endif
{{-- Risk Score Progress Bar --}}
Risk Score @if($risk && $risk->total_score !== null) {{ number_format($risk->total_score, 1) }} / 100 @if($rsBetter) Better @endif @else Data belum tersedia @endif
@if($risk && $risk->total_score !== null) @php $barColor = match (true) { $risk->total_score >= 60 => 'bg-red-500', $risk->total_score >= 30 => 'bg-amber-500', default => 'bg-emerald-500' }; @endphp
@endif
{{-- Grid of Indicators --}}
@foreach($indicators as $ind)
{!! $ind['icon'] !!} {{ $ind['label'] }} @if($ind['isBetter']) @if($ind['label'] === 'Storm Risk') Better @else Better @endif @endif
@if($ind['hasData'])

{{ $ind['value'] }}

@else

Data belum tersedia

@endif
@endforeach
{{-- Footer Link --}}
@endforeach
@elseif(request('country1') || request('country2'))
Please select two valid countries to compare.
@endif
{{-- Modern backdrop blur loading overlay --}} @push('scripts') @endpush @endsection