@extends('layouts.admin')

@section('title', 'Admin Dashboard')
@section('page-title', 'Dashboard')

@section('content')
<div class="space-y-8">
    <div>
        <h1 class="text-2xl font-bold text-gray-900">Admin Dashboard</h1>
        <p class="mt-1 text-sm text-gray-500">Platform overview and management.</p>
    </div>

    <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
        <div class="rounded-xl bg-white px-5 py-6 shadow-sm border border-gray-100">
            <p class="text-sm text-gray-500">Total Users</p>
            <p class="text-2xl font-bold text-gray-900">{{ number_format($stats['total_users']) }}</p>
            <p class="text-xs text-green-950 mt-1">+{{ $stats['new_users_today'] }} today</p>
        </div>
        <div class="rounded-xl bg-white px-5 py-6 shadow-sm border border-gray-100">
            <p class="text-sm text-gray-500">Total Transactions</p>
            <p class="text-2xl font-bold text-gray-900">{{ number_format($stats['total_transactions']) }}</p>
            <p class="text-xs text-green-950 mt-1">{{ $stats['successful_transactions'] }} successful</p>
        </div>
        <div class="rounded-xl bg-white px-5 py-6 shadow-sm border border-gray-100">
            <p class="text-sm text-gray-500">Total Revenue</p>
            <p class="text-2xl font-bold text-gray-900">₦{{ number_format($stats['total_revenue'], 2) }}</p>
            <p class="text-xs text-green-950 mt-1">₦{{ number_format($stats['today_revenue'], 2) }} today</p>
        </div>
        <div class="rounded-xl bg-white px-5 py-6 shadow-sm border border-gray-100">
            <p class="text-sm text-gray-500">Total Volume</p>
            <p class="text-2xl font-bold text-gray-900">₦{{ number_format($stats['total_volume'], 2) }}</p>
            <p class="text-xs text-yellow-600 mt-1">{{ $stats['pending_transactions'] }} pending</p>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
        <div class="rounded-xl bg-white shadow-sm border border-gray-100 overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100">
                <h2 class="text-lg font-semibold text-gray-900">Recent Transactions</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-100">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">User</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Service</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Amount</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-50">
                        @forelse($recentTransactions as $tx)
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3 text-sm text-gray-900">{{ $tx->user->first_name }} {{ $tx->user->last_name }}</td>
                            <td class="px-4 py-3 text-sm text-gray-500">{{ $tx->service_name }}</td>
                            <td class="px-4 py-3 text-sm font-medium text-gray-900">₦{{ number_format($tx->total_amount, 2) }}</td>
                            <td class="px-4 py-3">
                                @if($tx->status === 'successful')
                                    <span class="inline-flex items-center rounded-full bg-green-50 px-2 py-1 text-xs font-medium text-green-700">OK</span>
                                @elseif($tx->status === 'failed')
                                    <span class="inline-flex items-center rounded-full bg-red-50 px-2 py-1 text-xs font-medium text-red-700">Failed</span>
                                @else
                                    <span class="inline-flex items-center rounded-full bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-700">{{ ucfirst($tx->status) }}</span>
                                @endif
                            </td>
                        </tr>
                        @empty
                        <tr><td colspan="4" class="px-4 py-8 text-center text-sm text-gray-500">No transactions yet.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="px-6 py-3 border-t border-gray-100">
                <a href="{{ route('admin.transactions.index') }}" class="text-sm font-medium text-green-950 hover:text-green-700">View All &rarr;</a>
            </div>
        </div>

        <div class="rounded-xl bg-white shadow-sm border border-gray-100 overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100">
                <h2 class="text-lg font-semibold text-gray-900">Recent Users</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-100">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Name</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Email</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Role</th>
                            <th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Joined</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-50">
                        @forelse($recentUsers as $u)
                        <tr class="hover:bg-gray-50">
                            <td class="px-4 py-3 text-sm font-medium text-gray-900">{{ $u->first_name }} {{ $u->last_name }}</td>
                            <td class="px-4 py-3 text-sm text-gray-500">{{ $u->email }}</td>
                            <td class="px-4 py-3">
                                <span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-1 text-xs font-medium text-gray-700">{{ ucfirst($u->role) }}</span>
                            </td>
                            <td class="px-4 py-3 text-sm text-gray-500">{{ $u->created_at->format('M d') }}</td>
                        </tr>
                        @empty
                        <tr><td colspan="4" class="px-4 py-8 text-center text-sm text-gray-500">No users yet.</td></tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="px-6 py-3 border-t border-gray-100">
                <a href="{{ route('admin.users.index') }}" class="text-sm font-medium text-green-950 hover:text-green-700">View All &rarr;</a>
            </div>
        </div>
    </div>
</div>
@endsection
