@extends('layouts.admin')
@section('title', 'Berita & Pengumuman')
@section('page-title', 'Berita & Pengumuman')

@section('content')
<div class="flex items-center justify-between mb-6">
    <p class="text-gray-500 text-sm">{{ $posts->total() }} artikel</p>
    <a href="{{ route('admin.posts.create') }}" class="btn-primary">+ Tambah Artikel</a>
</div>

<div class="card-admin overflow-x-auto p-0">
    <table class="w-full">
        <thead class="bg-gray-50 border-b border-gray-200">
            <tr>
                <th class="table-header">Tipe</th>
                <th class="table-header">Judul</th>
                <th class="table-header">Tanggal</th>
                <th class="table-header">Penulis</th>
                <th class="table-header">Aksi</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-gray-100">
            @forelse($posts as $post)
            <tr class="hover:bg-gray-50 transition-colors">
                <td class="table-cell">
                    <span class="badge {{ $post->tipe === 'berita' ? 'badge-blue' : 'badge-gray' }}">
                        {{ $post->tipe === 'berita' ? 'Berita' : 'Pengumuman' }}
                    </span>
                </td>
                <td class="table-cell font-medium max-w-xs"><span class="line-clamp-1">{{ $post->judul }}</span></td>
                <td class="table-cell text-sm text-gray-500">{{ $post->tanggal->format('d/m/Y') }}</td>
                <td class="table-cell text-sm text-gray-400">{{ $post->penulis ?: '—' }}</td>
                <td class="table-cell">
                    <div class="flex items-center gap-2">
                        <a href="{{ route($post->tipe === 'berita' ? 'berita.show' : 'pengumuman.show', $post->slug) }}" target="_blank" class="text-gray-400 hover:text-primary text-xs">👁️</a>
                        <a href="{{ route('admin.posts.edit', $post->id) }}" class="text-secondary hover:text-primary text-sm font-medium">Edit</a>
                        <form method="POST" action="{{ route('admin.posts.destroy', $post->id) }}" data-confirm-delete>
                            @csrf @method('DELETE')
                            <button class="text-red-500 hover:text-red-700 text-sm">Hapus</button>
                        </form>
                    </div>
                </td>
            </tr>
            @empty
            <tr><td colspan="5" class="table-cell text-center text-gray-400 py-8">Belum ada artikel.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>
<div class="mt-4">{{ $posts->links() }}</div>
@endsection
