@extends('layouts.app')

@section('title', 'Manage Blog Posts - Admin Portal')

@section('content')
<div class="bg-slate-900 text-white py-8">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex justify-between items-center">
        <h1 class="font-heading font-extrabold text-2xl">Blog & News Articles Management</h1>
        <a href="{{ route('admin.blog.create') }}" class="px-4 py-2.5 rounded-xl bg-brand-gold text-slate-950 font-bold text-xs">
            + Publish New Article
        </a>
    </div>
</div>

<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-10">
    <div class="bg-white rounded-3xl shadow-lg border border-slate-100 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left text-sm text-slate-700">
                <thead class="bg-slate-50 text-xs font-bold text-slate-500 uppercase border-b border-slate-100">
                    <tr>
                        <th class="px-6 py-4">Article Title</th>
                        <th class="px-6 py-4">Category</th>
                        <th class="px-6 py-4">Author</th>
                        <th class="px-6 py-4">Published Date</th>
                        <th class="px-6 py-4">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @foreach($posts as $post)
                        <tr class="hover:bg-slate-50">
                            <td class="px-6 py-4 font-bold text-slate-900">{{ $post->title }}</td>
                            <td class="px-6 py-4 text-xs font-semibold text-brand-blue">{{ $post->category }}</td>
                            <td class="px-6 py-4 text-xs">{{ $post->author }}</td>
                            <td class="px-6 py-4 text-xs text-slate-500">{{ $post->published_at->format('M d, Y') }}</td>
                            <td class="px-6 py-4">
                                <form action="{{ route('admin.blog.delete', $post->id) }}" method="POST" onsubmit="return confirm('Delete this post?');">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-xs text-red-600 font-bold hover:underline">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-100">
            {{ $posts->links() }}
        </div>
    </div>
</div>
@endsection
