@extends('layouts.dashboard')
@section('title', 'My Blogs')
@section('page-title', 'My Blogs')
@section('content')
<div class="content-card">
    <div class="content-card-header">
        <h3>{{ $blogs->total() }} Blogs Published</h3>
        <a href="{{ route('reseller.blogs.create') }}" class="btn btn-primary btn-sm">+ Write New Blog</a>
    </div>
    <div class="table-responsive">
    <table class="table">
        <thead><tr><th>Title</th><th>Category</th><th>Views</th><th>Lang</th><th>Published</th><th>Actions</th></tr></thead>
        <tbody>
        @forelse($blogs as $b)
            <tr>
                <td><strong>{{ \Illuminate\Support\Str::limit($b->title, 60) }}</strong></td>
                <td class="small">{{ $b->category->name ?? '—' }}</td>
                <td>{{ number_format($b->views) }}</td>
                <td><code>{{ $b->language }}</code></td>
                <td class="small">{{ $b->published_at?->format('M d, Y') }}</td>
                <td>
                    <a href="{{ route('blogs.show', $b->slug) }}" target="_blank" class="btn btn-sm btn-outline-secondary">View</a>
                    <a href="{{ route('reseller.blogs.edit', $b) }}" class="btn btn-sm btn-outline-primary">Edit</a>
                    <form action="{{ route('reseller.blogs.destroy', $b) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete this blog? Quota will not be refunded.')">
                        @csrf @method('DELETE')
                        <button class="btn btn-sm btn-outline-danger">Del</button>
                    </form>
                </td>
            </tr>
        @empty
            <tr><td colspan="6" class="text-center text-muted py-4">No blogs yet. <a href="{{ route('reseller.blogs.create') }}">Write your first one</a>.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
    {{ $blogs->links() }}
</div>
@endsection
