@extends('layouts.app')

@section('title', 'Database Kelompok Tani | PRADIPA')

@section('content')
<div class="flex flex-col gap-6">
    <!-- Header Halaman -->
    <div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm">
        <h2 class="text-2xl font-bold text-slate-800">Master Database Kelompok Tani</h2>
        <p class="text-sm text-slate-500 mt-1 font-medium">Informasi data pokok instansi kelompok tani (Poktan) resmi terverifikasi se-Jawa Tengah.</p>
    </div>

    <!-- FILTER PENCARIAN & WILAYAH -->
    <form action="{{ route('shared.poktan.index') }}" method="GET" class="bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex flex-col md:flex-row gap-4">
        <!-- Input Cari -->
        <div class="flex-1 relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-3 text-slate-400">
                <i data-lucide="search" class="w-5 h-5"></i>
            </span>
            <input type="text" name="search" value="{{ request('search') }}" placeholder="Cari berdasarkan nama kelompok, nomor induk, atau nama ketua..." class="w-full pl-10 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all">
        </div>
        <!-- Filter Kabupaten -->
        <div class="w-full md:w-64">
            <select name="kabupaten" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500 cursor-pointer">
                <option value="">Semua Kabupaten</option>
                @foreach($kabupatens as $kab)
                    <option value="{{ $kab->id }}" {{ request('kabupaten') == $kab->id ? 'selected' : '' }}>{{ $kab->nama_kabupaten }}</option>
                @endforeach
            </select>
        </div>
        <!-- Tombol Cari -->
        <button type="submit" class="px-5 py-2 bg-slate-800 hover:bg-slate-900 text-white rounded-lg text-sm font-semibold transition-all">
            Filter Data
        </button>
    </form>

    <!-- TABEL MASTER DATA POKTAN -->
    <div class="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-left text-sm divide-y divide-slate-100">
                <thead class="bg-slate-50">
                    <tr class="text-slate-500 uppercase text-[11px] font-bold tracking-wider">
                        <th class="py-4 px-6">Identitas Kelompok Tani</th>
                        <th class="py-4 px-6">Nomor Induk Poktan</th>
                        <th class="py-4 px-6">Ketua Kelompok & NIK</th>
                        <th class="py-4 px-6">Lokasi Geografis Administrasi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @forelse($poktans as $p)
                        <tr class="hover:bg-slate-50/50 transition-colors">
                            <td class="py-4 px-6">
                                <div class="font-extrabold text-slate-800 text-sm flex items-center gap-1.5">
                                    <i data-lucide="users-2" class="w-4 h-4 text-emerald-600"></i>
                                    {{ $p->nama_kelompok }}
                                </div>
                            </td>
                            <td class="py-4 px-6">
                                <span class="px-2 py-1 bg-slate-100 text-slate-700 font-mono text-[11px] font-bold rounded border border-slate-200">
                                    {{ $p->nomor_induk }}
                                </span>
                            </td>
                            <td class="py-4 px-6">
                                <div class="font-bold text-slate-700">{{ $p->nama_ketua }}</div>
                                <div class="text-[10px] text-slate-400 font-mono mt-0.5">NIK: {{ $p->nik_ketua }}</div>
                            </td>
                            <td class="py-4 px-6 text-xs font-semibold text-slate-600 leading-relaxed">
                                Desa {{ $p->nama_desa }}, Kecamatan {{ $p->nama_kecamatan }}<br>
                                <span class="text-slate-400 font-normal">Kabupaten:</span> <b>{{ $p->nama_kabupaten }}</b>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="4" class="py-8 text-center text-slate-400 font-medium">Tidak ada data Kelompok Tani yang sesuai dengan filter pencarian Anda.</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <!-- Panel Paginasi -->
        @if($poktans->hasPages())
            <div class="bg-slate-50 border-t border-slate-100 px-6 py-4">
                {{ $poktans->links() }}
            </div>
        @endif
    </div>
</div>
@endsection