@extends('layouts.app')

@section('content')
@if(session('success'))
    <div class="alert alert-success">{{ session('success') }}</div>
@endif
<div class="container">
    <h2>Data Kasus</h2>

    <!-- Tombol Tambah Kasus -->
    <a href="{{ route('admin.kasus.create') }}" class="btn btn-success mb-3">+ Tambah Kasus</a>

    <!-- Card untuk search + tabel -->
    <div class="card">
        <div class="card-body p-3">

            <!-- Form Search -->
            <form action="{{ route('admin.kasus.index') }}" method="GET" class="mb-3">
                <div class="input-group">
                    <input type="text" name="search" class="form-control" placeholder="Cari berdasarkan bulan, tahun atau jumlah kasus..." value="{{ request('search') }}">
                    <button class="btn btn-primary" type="submit">Cari</button>
                </div>
            </form>

            

            <!-- Tabel Data Kasus -->
            <table class="table table-bordered mb-0">
                <thead>
                    <tr>
                        <th>Bulan</th>
                        <th>Jumlah Kasus</th>
                        <th>Tahun</th>
                        <th>Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($kasuses as $kasus)
                    <tr>
                        <td>{{ $kasus->bulan }}</td>
                        <td>{{ $kasus->jumlah_kasus }}</td>
                        <td>{{ $kasus->tahun }}</td>
                        <td>
                            <a href="{{ route('admin.kasus.edit', $kasus->id) }}" class="btn btn-warning btn-sm">Edit</a>
                            <form action="{{ route('admin.kasus.destroy', $kasus->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Yakin hapus?')">
                                @csrf
                                @method('DELETE')
                                <button class="btn btn-danger btn-sm">Hapus</button>
                            </form>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="4">Belum ada data kasus.</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>

<!-- Pagination -->
@if ($kasuses->hasPages())
    <div class="mt-4 d-flex justify-content-center">
        <nav>
            <ul class="pagination">
                {{-- Tombol Previous --}}
                @if ($kasuses->onFirstPage())
                    <li class="page-item disabled"><span class="page-link">&laquo;</span></li>
                @else
                    <li class="page-item"><a class="page-link" href="{{ $kasuses->previousPageUrl() }}" rel="prev">&laquo;</a></li>
                @endif

                {{-- Tombol Angka --}}
                @foreach ($kasuses->getUrlRange(1, $kasuses->lastPage()) as $page => $url)
                    @if ($page == $kasuses->currentPage())
                        <li class="page-item active"><span class="page-link">{{ $page }}</span></li>
                    @else
                        <li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
                    @endif
                @endforeach

                {{-- Tombol Next --}}
                @if ($kasuses->hasMorePages())
                    <li class="page-item"><a class="page-link" href="{{ $kasuses->nextPageUrl() }}" rel="next">&raquo;</a></li>
                @else
                    <li class="page-item disabled"><span class="page-link">&raquo;</span></li>
                @endif
            </ul>
        </nav>
    </div>
@endif

        </div>
    </div>
</div>
@endsection
