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

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1">Customer Dashboard</h1>
            <p class="text-muted mb-0">Track uploads, orders, addresses, wallet balance, and courier updates from one place.</p>
        </div>
        <a href="{{ route('orders.create') }}" class="btn btn-primary">Place New Order</a>
    </div>

    <div class="row g-4 mb-4">
        <div class="col-md-3">
            <div class="card card-soft h-100"><div class="card-body"><div class="text-muted small">Documents</div><div class="metric-number">{{ $documentCount }}</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">Orders</div><div class="metric-number">{{ $orderCount }}</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">Saved Addresses</div><div class="metric-number">{{ $addressCount }}</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">Wallet</div><div class="metric-number">Rs {{ number_format($walletBalance, 2) }}</div></div></div>
        </div>
    </div>

    <div class="alert alert-info card-soft border-0">
        <strong>{{ $pendingApprovalCount }}</strong> uploaded document(s) are waiting for admin approval before final production.
    </div>

    <div class="row g-4">
        <div class="col-lg-6">
            <div class="card card-soft">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h2 class="h5 mb-0">Recent Documents</h2>
                        <a href="{{ route('documents.index') }}">Manage</a>
                    </div>
                    @if($recentDocuments->isEmpty())
                        <p class="text-muted mb-0">No documents uploaded yet.</p>
                    @else
                        <div class="list-group list-group-flush">
                            @foreach($recentDocuments as $document)
                                <div class="list-group-item px-0">
                                    <div class="fw-semibold">{{ $document->title }}</div>
                                    <div class="small text-muted">{{ $document->document_type }} | {{ $document->page_count }} pages | {{ ucfirst($document->approval_status) }}</div>
                                </div>
                            @endforeach
                        </div>
                    @endif
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="card card-soft">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h2 class="h5 mb-0">Recent Orders</h2>
                        <a href="{{ route('orders.index') }}">View all</a>
                    </div>
                    @if($recentOrders->isEmpty())
                        <p class="text-muted mb-0">No orders placed yet.</p>
                    @else
                        <div class="list-group list-group-flush">
                            @foreach($recentOrders as $order)
                                <a href="{{ route('orders.show', $order) }}" class="list-group-item list-group-item-action px-0">
                                    <div class="d-flex justify-content-between">
                                        <span class="fw-semibold">{{ $order->order_number }}</span>
                                        <span class="status-pill">{{ ucfirst($order->status) }}</span>
                                    </div>
                                    <div class="small text-muted">Rs {{ number_format($order->total_amount, 2) }} | {{ $order->created_at->format('d M Y') }}</div>
                                </a>
                            @endforeach
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>

    <div class="card card-soft mt-4">
        <div class="card-body">
            <h2 class="h5 mb-3">Saved Addresses</h2>
            @if($savedAddresses->isEmpty())
                <p class="text-muted mb-0">Addresses will appear here after you place your first order.</p>
            @else
                <div class="row g-3">
                    @foreach($savedAddresses as $address)
                        <div class="col-md-4">
                            <div class="border rounded-4 p-3 h-100">
                                <div class="fw-semibold">{{ $address->label }}</div>
                                <div>{{ $address->recipient_name }}</div>
                                <div class="small text-muted">{{ $address->line1 }}, {{ $address->city }}, {{ $address->state }} - {{ $address->postal_code }}</div>
                            </div>
                        </div>
                    @endforeach
                </div>
            @endif
        </div>
    </div>

    <div class="card card-soft mt-4">
        <div class="card-body">
            <h2 class="h5 mb-3">Recent Notifications</h2>
            @if($notifications->isEmpty())
                <p class="text-muted mb-0">Payment, courier, and admin status notifications will appear here.</p>
            @else
                <div class="list-group list-group-flush">
                    @foreach($notifications as $notification)
                        <div class="list-group-item px-0">
                            <div class="fw-semibold">{{ $notification->subject }}</div>
                            <div class="small text-muted">{{ $notification->channel }} | {{ $notification->sent_at?->format('d M Y h:i A') }}</div>
                            <div class="small">{{ $notification->message }}</div>
                        </div>
                    @endforeach
                </div>
            @endif
        </div>
    </div>
@endsection
