@extends('layouts.user')
@section('title', 'Currency Impact Dashboard')
@push('styles')
@endpush
@push('scripts')
@endpush
@section('content')
{{-- Flower Decorations --}}
{{-- Header --}}
Currency Impact Dashboard
Exchange rate trends for world currencies vs USD with interactive charts.
@php
// Build chart-ready data dari database countries dan currencies
$chartItems = collect();
foreach ($countries as $country) {
$cur = $country->currency;
if (! $cur) continue;
// Ambil exchange rates dari database
$usdCurrency = \App\Models\Currency::where('code', 'USD')->first();
if (!$usdCurrency) continue;
$rates = \App\Models\ExchangeRate::where('base_currency_id', $usdCurrency->id)
->where('target_currency_id', $cur->id)
->orderBy('recorded_at', 'desc')
->take(30)
->get(['recorded_at', 'exchange_rate', 'change_percentage']);
if ($rates->count() < 2) continue;
$chartItems->push([
'country' => $country->name,
'code' => $cur->code,
'symbol' => $cur->symbol,
'name' => $cur->name,
'labels' => $rates->reverse()->map(fn ($r) => $r->recorded_at->format('M d'))->values(),
'data' => $rates->reverse()->map(fn ($r) => $r->exchange_rate)->values(),
'latest' => $rates->first()->exchange_rate,
'change' => $rates->first()->change_percentage,
'flag_url' => $country->flag_url,
]);
}
@endphp
{{-- Stats Cards --}}
@php
// Calculate correct stats from $chartItems that's actually used in the cards
$activeRatesCount = $chartItems->where('latest', '>', 0)->count();
$gainersCount = $chartItems->where('change', '>', 0)->count();
$declinersCount = $chartItems->where('change', '<', 0)->count();
@endphp
@foreach([
['total', 'Total Currencies', $chartItems->count(), '💱', 'border-blue-200', 'text-blue-600'],
['active', 'Active Rates', $activeRatesCount, '📈', 'border-emerald-200', 'text-emerald-600'],
['gainers', 'Gainers', $gainersCount, '🔼', 'border-green-200', 'text-green-600'],
['decliners', 'Decliners', $declinersCount, '🔽', 'border-red-200', 'text-red-600'],
] as [$type, $label, $value, $icon, $border, $color])
{{ $icon }}
{{ number_format($value) }}
{{ $label }}
@endforeach
{{-- Search --}}
{{-- Search Input & Button Wrapper --}}
{{-- Input with Clear Button --}}
{{-- Search Button --}}
{{-- Filter Dropdown --}}
{{-- ── Currency Chart Cards ──────────────────────────────────── --}}
@php
$chartData = collect();
@endphp
@foreach($countries as $index => $country)
@if($country->currency)
@php
$currency = $country->currency;
$latestRate = $currency->exchangeRatesAsTarget->where('base_currency_id', $baseCur->id)->first();
if (!$latestRate) continue;
$historicalRates = $currency->exchangeRatesAsTarget
->where('base_currency_id', $baseCur->id)
->take(30)
->sortBy('recorded_at');
$change = $latestRate->change_percentage ?? 0;
$changeClass = $change > 0 ? 'text-emerald-600' : ($change < 0 ? 'text-red-600' : 'text-slate-600');
$changeIcon = $change > 0 ? '↗️' : ($change < 0 ? '↘️' : '→');
$changeBg = $change > 0 ? 'bg-emerald-50 border-emerald-200' : ($change < 0 ? 'bg-red-50 border-red-200' : 'bg-slate-50 border-slate-200');
$item = [
'id' => $currency->id,
'country' => $country->name,
'code' => $currency->code,
'symbol' => $currency->symbol ?? $currency->code,
'name' => $currency->name,
'latest' => $latestRate->exchange_rate,
'change' => $change,
'flag_url' => $country->flag_url,
'labels' => $historicalRates->map(fn($r) => $r->recorded_at->format('M d'))->values(),
'data' => $historicalRates->map(fn($r) => $r->exchange_rate)->values(),
'has_history' => $historicalRates->isNotEmpty(),
];
if ($item['has_history']) {
$chartData->push($item);
}
@endphp
@endif
@endforeach
{{-- ── Empty State ───────────────────────────────────────────── --}}
@if($chartData->isEmpty())
💱
No Currency Data
No exchange rate data available. Sync currency data to see charts and trends.
@endif
🔍
No Currencies Found
Try adjusting your search or filter criteria.
@endsection
@push('scripts')
@endpush