@extends('layouts.app', ['title' => 'Admin Dashboard | Print Cards'])

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1">Admin Dashboard</h1>
            <p class="text-muted mb-0">Monitor orders, users, uploads, payments, and courier operations from one screen.</p>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ route('admin.orders.index') }}" class="btn btn-primary">Manage Orders</a>
            <a href="{{ route('admin.settings.edit') }}" class="btn btn-outline-secondary">Settings</a>
        </div>
    </div>

    <div class="row g-4 mb-4">
        <div class="col-md-2"><div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Orders</div><div class="metric-number">{{ $metrics['orders'] }}</div></div></div></div>
        <div class="col-md-2"><div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Users</div><div class="metric-number">{{ $metrics['users'] }}</div></div></div></div>
        <div class="col-md-2"><div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Documents</div><div class="metric-number">{{ $metrics['documents'] }}</div></div></div></div>
        <div class="col-md-3"><div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Revenue</div><div class="metric-number">Rs {{ number_format($metrics['revenue'], 2) }}</div></div></div></div>
        <div class="col-md-3"><div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Pending / Delivered</div><div class="metric-number">{{ $metrics['pending_orders'] }} / {{ $metrics['delivered_orders'] }}</div></div></div></div>
    </div>

    <div class="row g-4 mb-4">
        <div class="col-lg-4"><a class="card card-soft text-decoration-none text-reset h-100" href="{{ route('admin.documents.index') }}"><div class="card-body"><h2 class="h5">Upload Approval</h2><p class="text-muted mb-0">Approve or reject customer files before production.</p></div></a></div>
        <div class="col-lg-4"><a class="card card-soft text-decoration-none text-reset h-100" href="{{ route('admin.users.index') }}"><div class="card-body"><h2 class="h5">User Control</h2><p class="text-muted mb-0">Block, reactivate, and inspect customer or agent accounts.</p></div></a></div>
        <div class="col-lg-4"><a class="card card-soft text-decoration-none text-reset h-100" href="{{ route('admin.reports.index') }}"><div class="card-body"><h2 class="h5">Reports</h2><p class="text-muted mb-0">Review status counts, revenue, and notification activity.</p></div></a></div>
    </div>

    <div class="row g-4">
        <div class="col-lg-7">
            <div class="card card-soft">
                <div class="card-body">
                    <h2 class="h5 mb-3">Recent Orders</h2>
                    <div class="table-responsive">
                        <table class="table align-middle">
                            <thead><tr><th>Order</th><th>User</th><th>Status</th><th>Total</th></tr></thead>
                            <tbody>
                                @foreach($recentOrders as $order)
                                    <tr>
                                        <td><a href="{{ route('admin.orders.show', $order) }}">{{ $order->order_number }}</a></td>
                                        <td>{{ $order->user?->name }}</td>
                                        <td>{{ ucfirst($order->status) }}</td>
                                        <td>Rs {{ number_format($order->total_amount, 2) }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-5">
            <div class="card card-soft mb-4">
                <div class="card-body">
                    <h2 class="h5 mb-3">Status Breakdown</h2>
                    @foreach($statusCounts as $status => $count)
                        <div class="d-flex justify-content-between py-2 border-bottom">
                            <span>{{ ucfirst($status) }}</span>
                            <strong>{{ $count }}</strong>
                        </div>
                    @endforeach
                </div>
            </div>
            <div class="card card-soft">
                <div class="card-body">
                    <h2 class="h5 mb-3">Newest Users</h2>
                    <div class="list-group list-group-flush">
                        @foreach($recentUsers as $user)
                            <div class="list-group-item px-0">
                                <div class="fw-semibold">{{ $user->name }}</div>
                                <div class="small text-muted">{{ $user->email }} | {{ $user->role?->name }}</div>
                            </div>
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
