@extends('admin.layouts.app')

@section('content')
    <h1 class="text-3xl font-bold mb-8">Dashboard Admin</h1>

    <div class="grid md:grid-cols-3 gap-6 mb-10">
        <div class="bg-white rounded-2xl shadow p-6">
            <p class="text-slate-500">Total Berita</p>
            <h2 class="text-3xl font-bold text-blue-900 mt-2">{{ $totalPosts }}</h2>
        </div>
        <div class="bg-white rounded-2xl shadow p-6">
            <p class="text-slate-500">Total Galeri</p>
            <h2 class="text-3xl font-bold text-purple-700 mt-2">{{ $totalGalleries }}</h2>
            <div class="bg-white rounded-2xl shadow p-6">
                <p class="text-slate-500">Total Agenda</p>
                <h2 class="text-3xl font-bold text-pink-700 mt-2">{{ $totalAgendas }}</h2>
            </div>
        </div>
        <div class="bg-white rounded-2xl shadow p-6">
            <p class="text-slate-500">Berita Publish</p>
            <h2 class="text-3xl font-bold text-green-700 mt-2">{{ $publishedPosts }}</h2>
        </div>

        <div class="bg-white rounded-2xl shadow p-6">
            <p class="text-slate-500">Draft</p>
            <h2 class="text-3xl font-bold text-yellow-600 mt-2">{{ $draftPosts }}</h2>
        </div>
    </div>

    <div class="bg-white rounded-2xl shadow p-6">
        <h3 class="text-xl font-bold mb-4">Berita Terbaru</h3>

        <div class="overflow-x-auto">
            <table class="w-full text-left">
                <thead>
                    <tr class="border-b">
                        <th class="py-3">Judul</th>
                        <th class="py-3">Status</th>
                        <th class="py-3">Tanggal</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($latestPosts as $post)
                        <tr class="border-b">
                            <td class="py-3">{{ $post->title }}</td>
                            <td class="py-3">
                                @if($post->is_published)
                                    <span class="px-3 py-1 rounded-full bg-green-100 text-green-700 text-sm">Publish</span>
                                @else
                                    <span class="px-3 py-1 rounded-full bg-yellow-100 text-yellow-700 text-sm">Draft</span>
                                @endif
                            </td>
                            <td class="py-3">{{ $post->created_at->format('d M Y') }}</td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="3" class="py-4 text-slate-500">Belum ada data berita.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
@endsection