@extends('admin.layouts.app')

@section('title', 'Blog Posts')
@section('subtitle', 'Create and manage the articles shown on the public blog page.')

@section('content')
    <div class="admin-card admin-library">
        <div class="admin-toolbar">
            <div>
                <p class="admin-section-title">Blog post library</p>
                <p class="admin-section-subtitle">{{ $blogPosts->total() }} articles currently available.</p>
            </div>
            <a href="{{ route('admin.blog-posts.create') }}" class="admin-button">New blog post</a>
        </div>

        <div class="mt-6 admin-library__stack">
            @forelse($blogPosts as $blogPost)
                <article class="admin-library__item">
                    <div class="admin-library__content">
                        <div class="admin-library__heading">
                            <p class="admin-library__title">{{ $blogPost->title }}</p>
                            @if($blogPost->is_featured)
                                <span class="admin-chip">Featured</span>
                            @endif
                            <span class="admin-chip">{{ $blogPost->is_published ? 'Published' : 'Draft' }}</span>
                            @if($blogPost->badge)
                                <span class="admin-chip">{{ $blogPost->badge }}</span>
                            @endif
                        </div>
                        <p class="admin-library__description">{{ $blogPost->resolved_excerpt }}</p>
                        <p class="admin-library__meta">
                            <span>/blog/{{ $blogPost->slug }}</span>
                            @if($blogPost->published_at)
                                <span class="admin-library__meta-divider">&middot;</span>
                                <span>{{ $blogPost->published_at->format('M d, Y') }}</span>
                            @endif
                        </p>
                    </div>
                    <div class="admin-library__actions">
                        @if($blogPost->is_published)
                            <a href="{{ route('blog.show', $blogPost->slug) }}" class="admin-button admin-button--ghost" target="_blank" rel="noopener">View</a>
                        @endif
                        <a href="{{ route('admin.blog-posts.edit', $blogPost) }}" class="admin-button admin-button--secondary">Edit</a>
                        <form method="POST" action="{{ route('admin.blog-posts.destroy', $blogPost) }}" onsubmit="return confirm('Delete this blog post?')">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="admin-button admin-button--danger">Delete</button>
                        </form>
                    </div>
                </article>
            @empty
                <div class="admin-empty">No blog posts yet. Create your first article to populate the blog page.</div>
            @endforelse
        </div>

        <div class="mt-6">
            {{ $blogPosts->links() }}
        </div>
    </div>
@endsection
