@extends('layouts.dashboard')
@section('title', 'All Blogs')
@section('page-title', 'All Blogs')
@section('content')
<div class="content-card">
    <div class="content-card-header">
        <h3>{{ $blogs->total() }} Blogs</h3>
        <a href="{{ route('admin.blogs.create') }}" class="btn btn-primary btn-sm">+ Add Blog</a>
    </div>
    <div class="table-responsive">
    <table class="table">
        <thead><tr><th>Title</th><th>Author</th><th>Category</th><th>Lang</th><th>Views</th><th>Date</th><th></th></tr></thead>
        <tbody>
        @forelse($blogs as $b)
            <tr>
                <td><a href="{{ route('blogs.show', $b->slug) }}" target="_blank">{{ \Illuminate\Support\Str::limit($b->title, 60) }}</a></td>
                <td>{{ $b->author->name ?? '—' }}</td>
                <td class="small">{{ $b->category->name ?? '—' }}</td>
                <td><code>{{ $b->language }}</code></td>
                <td>{{ number_format($b->views) }}</td>
                <td class="small">{{ $b->created_at->format('M d, Y') }}</td>
                <td>
                    <a href="{{ route('admin.blogs.edit', $b) }}" class="btn btn-sm btn-outline-primary mb-1">Edit</a>
                    <form action="{{ route('admin.blogs.destroy', $b) }}" method="POST" onsubmit="return confirm('Delete this blog?')">
                        @csrf @method('DELETE')
                        <button class="btn btn-sm btn-outline-danger">Delete</button>
                    </form>
                </td>
            </tr>
        @empty
            <tr><td colspan="7" class="text-center text-muted py-3">No blogs yet.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
    {{ $blogs->links() }}
</div>
@endsection
