@extends('admin.layouts.app')

@section('content')
    <div class="flex items-center justify-between mb-8">
        <h1 class="text-3xl font-bold">Manajemen Agenda</h1>
        <a href="{{ route('admin.agendas.create') }}"
           class="bg-blue-900 hover:bg-blue-800 text-white px-5 py-3 rounded-xl font-semibold">
            + Tambah Agenda
        </a>
    </div>

    <div class="bg-white rounded-2xl shadow p-6 overflow-x-auto">
        <table class="w-full text-left">
            <thead>
                <tr class="border-b">
                    <th class="py-3">Judul</th>
                    <th class="py-3">Tanggal</th>
                    <th class="py-3">Waktu</th>
                    <th class="py-3">Lokasi</th>
                    <th class="py-3">Status</th>
                    <th class="py-3">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @forelse($agendas as $agenda)
                    <tr class="border-b align-top">
                        <td class="py-3 font-medium">{{ $agenda->title }}</td>
                        <td class="py-3">{{ $agenda->event_date->format('d M Y') }}</td>
                        <td class="py-3">{{ $agenda->event_time ?: '-' }}</td>
                        <td class="py-3">{{ $agenda->location ?: '-' }}</td>
                        <td class="py-3">
                            @if($agenda->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">
                            <div class="flex gap-2">
                                <a href="{{ route('admin.agendas.edit', $agenda) }}"
                                   class="bg-amber-500 hover:bg-amber-600 text-white px-4 py-2 rounded-lg text-sm">
                                    Edit
                                </a>

                                <form action="{{ route('admin.agendas.destroy', $agenda) }}" method="POST"
                                      onsubmit="return confirm('Yakin hapus agenda ini?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit"
                                            class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg text-sm">
                                        Hapus
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" class="py-4 text-slate-500">Belum ada agenda.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>

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