@extends('layouts.dashboard')
@section('title', 'Admin Dashboard')
@section('page-title', 'Admin Dashboard')
@section('content')
<div class="row g-3 mb-4">
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Users</div><div class="stat-card-value">{{ $stats['users'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Resellers</div><div class="stat-card-value">{{ $stats['resellers'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Total Blogs</div><div class="stat-card-value">{{ $stats['blogs'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Categories</div><div class="stat-card-value">{{ $stats['categories'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Packages</div><div class="stat-card-value">{{ $stats['packages'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Unpaid Invoices</div><div class="stat-card-value">{{ $stats['invoices_unpaid'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Paid Invoices</div><div class="stat-card-value">{{ $stats['invoices_paid'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Total Revenue</div><div class="stat-card-value">${{ number_format($stats['revenue'], 2) }}</div></div></div>
</div>

<div class="row g-3">
    <div class="col-md-6">
        <div class="content-card">
            <div class="content-card-header"><h3>Recent Invoices</h3><a href="{{ route('admin.invoices.index') }}" class="small">View all →</a></div>
            <table class="table">
                <thead><tr><th>#</th><th>User</th><th>Amount</th><th>Status</th></tr></thead>
                <tbody>
                @forelse($recent_invoices as $inv)
                    <tr>
                        <td><a href="{{ route('admin.invoices.show', $inv) }}">{{ $inv->invoice_number }}</a></td>
                        <td>{{ $inv->user->name ?? '—' }}</td>
                        <td>${{ number_format($inv->amount, 2) }}</td>
                        <td><span class="badge {{ $inv->statusBadgeClass() }}">{{ ucfirst($inv->status) }}</span></td>
                    </tr>
                @empty
                    <tr><td colspan="4" class="text-center text-muted py-3">No invoices yet</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
    <div class="col-md-6">
        <div class="content-card">
            <div class="content-card-header"><h3>Recent Blogs</h3><a href="{{ route('admin.blogs.index') }}" class="small">View all →</a></div>
            <table class="table">
                <thead><tr><th>Title</th><th>Author</th><th>Date</th></tr></thead>
                <tbody>
                @forelse($recent_blogs as $b)
                    <tr>
                        <td>{{ \Illuminate\Support\Str::limit($b->title, 50) }}</td>
                        <td>{{ $b->author->name ?? '—' }}</td>
                        <td class="small">{{ $b->created_at->diffForHumans() }}</td>
                    </tr>
                @empty
                    <tr><td colspan="3" class="text-center text-muted py-3">No blogs yet</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>

    <div class="col-12">
        <div class="content-card">
            <div class="content-card-header"><h3>Recent User Signups</h3><a href="{{ route('admin.users.index') }}" class="small">View all →</a></div>
            <table class="table">
                <thead><tr><th>Name</th><th>Username</th><th>Email</th><th>Role</th><th>Joined</th></tr></thead>
                <tbody>
                @foreach($recent_users as $u)
                    <tr>
                        <td><a href="{{ route('admin.users.edit', $u) }}">{{ $u->name }}</a></td>
                        <td>@{{ $u->username }}</td>
                        <td>{{ $u->email }}</td>
                        <td><span class="user-role-badge role-{{ $u->role }}">{{ $u->role }}</span></td>
                        <td class="small">{{ $u->created_at->diffForHumans() }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
