@extends('layouts.admin')

@section('title', 'Admin Dashboard | Smart Dermatology')
@section('page_title', 'Overview')
@section('page_subtitle', 'Monitor users, access levels, and recent activity.')

@section('content')
    <div class="row g-4 mb-4">
        <div class="col-md-3">
            <div class="card stat-card p-4">
                <h6 class="text-muted">Total Users</h6>
                <h2 class="fw-bold">{{ $stats['total_users'] }}</h2>
                <span class="small text-success">Registered accounts in the system</span>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card p-4">
                <h6 class="text-muted">Admin Accounts</h6>
                <h2 class="fw-bold">{{ $stats['total_admins'] }}</h2>
                <span class="small" style="color:var(--brand-pink)">Role-protected dashboard access</span>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card p-4">
                <h6 class="text-muted">User Accounts</h6>
                <h2 class="fw-bold">{{ $stats['total_members'] }}</h2>
                <span class="small text-warning">Standard member panel access</span>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card p-4">
                <h6 class="text-muted">Total Analyses</h6>
                <h2 class="fw-bold">{{ $stats['total_analyses'] }}</h2>
                <span class="small text-info">Saved prediction records</span>
            </div>
        </div>
    </div>

    <div class="row g-4">
        <div class="col-lg-6">
            <div class="card panel-card p-4 h-100">
                <h5 class="fw-bold mb-1">Recently Registered Users</h5>
                <p class="text-muted mb-4">Quick snapshot of latest accounts.</p>
                <div class="table-responsive">
                    <table class="table align-middle mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>Name</th>
                                <th>Email</th>
                                <th>User Type</th>
                                <th>Joined</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($stats['recent_users'] as $user)
                                <tr>
                                    <td>{{ $user->name }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td><span class="badge rounded-pill text-bg-light text-uppercase">{{ $user->user_type }}</span></td>
                                    <td>{{ $user->created_at?->format('d M Y') }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="4" class="text-center text-muted py-4">No users found yet.</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="card panel-card p-4 h-100">
                <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
                    <div>
                        <h5 class="fw-bold mb-1">Recent Analyses</h5>
                        <p class="text-muted mb-0">Latest AI results saved by users.</p>
                    </div>
                    <a href="{{ route('admin.analyses') }}" class="btn btn-outline-secondary btn-sm">View All</a>
                </div>
                <div class="table-responsive">
                    <table class="table align-middle mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>User</th>
                                <th>Disease</th>
                                <th>Confidence</th>
                                <th>Time</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($stats['recent_analyses'] as $analysis)
                                <tr>
                                    <td>{{ $analysis->user->name }}</td>
                                    <td class="text-capitalize">{{ str_replace('_', ' ', $analysis->disease) }}</td>
                                    <td>{{ number_format($analysis->confidence * 100, 2) }}%</td>
                                    <td>{{ $analysis->created_at?->diffForHumans() }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="4" class="text-center text-muted py-4">No analyses recorded yet.</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
