@extends('layouts.dashboard')
@section('title', 'Dashboard')
@section('page-title', 'Welcome, ' . auth()->user()->name)
@section('content')

<div class="alert alert-info">
    Want to publish your own blogs? Upgrade by purchasing a <a href="{{ route('user.packages.index') }}" class="alert-link">writer package</a>. Once approved, you can write unlimited posts in your quota.
</div>

<div class="row g-3 mb-4">
    <div class="col-md-4 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-4 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>

<div class="row g-3">
    <div class="col-md-6">
        <div class="content-card">
            <div class="content-card-header"><h3>My Invoices</h3><a href="{{ route('user.invoices.index') }}" class="small">View all →</a></div>
            <table class="table">
                <tbody>
                @forelse($recent_invoices as $inv)
                    <tr>
                        <td><a href="{{ route('user.invoices.show', $inv) }}">{{ $inv->invoice_number }}</a></td>
                        <td>${{ number_format($inv->amount, 2) }}</td>
                        <td><span class="badge {{ $inv->statusBadgeClass() }}">{{ ucfirst($inv->status) }}</span></td>
                        <td>
                            @if($inv->isUnpaid())<a href="{{ route('user.invoices.pay', $inv) }}" class="btn btn-sm btn-warning">Pay</a>@endif
                        </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>Latest Blogs to Read</h3><a href="{{ route('blogs.index') }}" class="small">All blogs →</a></div>
            <ul class="list-unstyled">
                @foreach($latest_blogs as $b)
                    <li class="mb-2 pb-2 border-bottom">
                        <a href="{{ route('blogs.show', $b->slug) }}" target="_blank"><strong>{{ \Illuminate\Support\Str::limit($b->title, 60) }}</strong></a>
                        <div class="small text-muted">by {{ $b->author->name }} · {{ $b->published_at?->diffForHumans() }}</div>
                    </li>
                @endforeach
            </ul>
        </div>
    </div>
</div>
@endsection
