@extends('layouts.dashboard')
@section('title', 'Reseller Dashboard')
@section('page-title', 'Welcome back, ' . auth()->user()->name)
@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">Total Blogs</div><div class="stat-card-value">{{ $stats['blogs_total'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Total Views</div><div class="stat-card-value">{{ number_format($stats['blogs_views']) }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card"><div class="stat-card-label">Quota Used</div><div class="stat-card-value">{{ $stats['blogs_used'] }}/{{ $stats['blogs_quota'] }}</div></div></div>
    <div class="col-md-3 col-6"><div class="stat-card" style="border-left-color: var(--success);"><div class="stat-card-label">Remaining</div><div class="stat-card-value">{{ $stats['blogs_remaining'] }}</div></div></div>
</div>

@if($stats['blogs_remaining'] === 0)
<div class="alert alert-warning">
    <strong>You've used all your blog quota.</strong>
    <a href="{{ route('reseller.packages.index') }}" class="alert-link">Buy more blogs</a> to keep publishing.
</div>
@endif

<div class="row g-3">
    <div class="col-md-7">
        <div class="content-card">
            <div class="content-card-header">
                <h3>My Recent Blogs</h3>
                <a href="{{ route('reseller.blogs.create') }}" class="btn btn-sm btn-primary">+ New Blog</a>
            </div>
            <table class="table">
                <thead><tr><th>Title</th><th>Views</th><th>Date</th></tr></thead>
                <tbody>
                @forelse($recent_blogs as $b)
                    <tr>
                        <td><a href="{{ route('reseller.blogs.show', $b) }}">{{ \Illuminate\Support\Str::limit($b->title, 50) }}</a></td>
                        <td>{{ $b->views }}</td>
                        <td class="small">{{ $b->created_at->diffForHumans() }}</td>
                    </tr>
                @empty
                    <tr><td colspan="3" class="text-center text-muted py-4">You haven't written any blogs yet. <a href="{{ route('reseller.blogs.create') }}">Write your first one!</a></td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
    <div class="col-md-5">
        <div class="content-card">
            <div class="content-card-header"><h3>Recent Invoices</h3><a href="{{ route('reseller.invoices.index') }}" class="small">All →</a></div>
            <table class="table">
                <tbody>
                @forelse($recent_invoices as $inv)
                    <tr>
                        <td><a href="{{ route('reseller.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>
                    </tr>
                @empty
                    <tr><td class="text-center text-muted py-3">No invoices yet</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
