

<?php $__env->startSection('title', 'Dashboard Ringkasan | PRADIPA JATENG'); ?>

<?php $__env->startSection('content'); ?>
<div class="flex flex-col gap-6">
    
    <!-- PANEL INFORMASI SIMULASI USER (NOTIFIKASI ATAS) -->
    <div class="bg-amber-50 border border-amber-200 p-4 rounded-xl shadow-sm flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
        <div class="flex items-start gap-3">
            <div class="bg-amber-100 text-amber-800 p-2 rounded-lg shrink-0 mt-0.5">
                <i data-lucide="terminal" class="w-5 h-5 text-amber-700"></i>
            </div>
            <div>
                <span class="text-xs font-bold text-amber-950 block">Mode Developer Sandbox: <span class="underline text-emerald-800"><?php echo e($user->name); ?></span></span>
                <p class="text-[11px] text-amber-800 leading-relaxed mt-0.5">Sistem navigasi dashboard reaktif mendeteksi pergantian peran Operator Kabupaten melalui dropdown Sandbox di sebelah kiri secara instan.</p>
            </div>
        </div>
    </div>

    <!-- HEADER TITLE -->
    <div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm flex flex-col md:flex-row md:items-center justify-between gap-4">
        <div>
            <h2 class="text-2xl font-bold text-slate-800">Selamat Datang di Portal PRADIPA</h2>
            <p class="text-sm text-slate-500 mt-1">Sistem informasi pengelolaan usulan bantuan sarana produksi pertanian berjenjang Provinsi Jawa Tengah.</p>
        </div>
        <span class="text-xs font-bold px-3 py-1.5 bg-slate-100 rounded-lg text-slate-600 border border-slate-200 self-start md:self-auto font-sans shrink-0">Mode: <b class="uppercase font-mono text-emerald-700"><?php echo e($role); ?></b></span>
    </div>

    <!-- ========================================================================= -->
    <!--             🆕 PANEL FILTER PROGRAM KEGIATAN DINAMIS                      -->
    <!-- ========================================================================= -->
    <div class="bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex flex-col sm:flex-row items-center justify-between gap-4">
        <div class="flex items-center gap-2.5">
            <div class="p-2 bg-slate-100 text-slate-500 rounded-lg">
                <i data-lucide="filter" class="w-4 h-4"></i>
            </div>
            <div>
                <span class="text-xs font-bold text-slate-700 block">Saring Kriteria Data</span>
                <span class="text-[10px] text-slate-400">Pilih program untuk mengalibrasi bagan kuota lahan</span>
            </div>
        </div>

        <form action="<?php echo e(route('dashboard')); ?>" method="GET" class="w-full sm:w-auto flex flex-col sm:flex-row items-stretch sm:items-center gap-3 font-sans">
            <select name="kegiatan_id" onchange="this.form.submit()" class="px-3 py-2 bg-slate-50 border border-slate-200 rounded-lg text-xs font-semibold focus:outline-none focus:ring-2 focus:ring-emerald-500 cursor-pointer min-w-[220px]">
                <option value="">-- Semua Program Bantuan --</option>
                <?php $__currentLoopData = $kegiatans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($k->id); ?>" <?php echo e($filterKegiatanId == $k->id ? 'selected' : ''); ?>>
                        <?php echo e($k->nama_kegiatan); ?> (TA <?php echo e($k->tahun_anggaran); ?>)
                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
            
            <?php if($filterKegiatanId): ?>
                <a href="<?php echo e(route('dashboard')); ?>" class="px-3 py-2 bg-slate-100 hover:bg-slate-200 text-slate-600 text-xs font-bold rounded-lg text-center transition-all flex items-center justify-center gap-1">
                    <i data-lucide="rotate-ccw" class="w-3.5 h-3.5"></i>
                    Reset Filter
                </a>
            <?php endif; ?>
        </form>
    </div>

    <?php if($role === 'kabupaten_user'): ?>
        <!-- ======================================================= -->
        <!--             TAMPILAN KHUSUS USER KABUPATEN              -->
        <!-- ======================================================= -->
        
        <!-- ROW 1: KARTU INDIKATOR UTAMA KABUPATEN -->
        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-5">
            <!-- Poktan Terdaftar -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Poktan di <?php echo e($namaWilayah); ?></span>
                    <h3 class="text-xl font-black text-slate-800 mt-1 leading-none"><?php echo e($totalPoktan); ?></h3>
                    <span class="text-[9px] text-emerald-600 font-semibold mt-1 inline-block">Kelompok</span>
                </div>
                <div class="bg-emerald-50 p-2.5 rounded-lg text-emerald-600">
                    <i data-lucide="users" class="w-5 h-5"></i>
                </div>
            </div>

            <!-- Kuota Pagu Maksimal -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Pagu Provinsi</span>
                    <h3 class="text-xl font-black text-slate-800 mt-1 leading-none"><?php echo e(number_format($kuotaMaksimal, 1, ',', '.')); ?></h3>
                    <span class="text-[9px] text-blue-600 font-semibold mt-1 inline-block">Hektar (Ha)</span>
                </div>
                <div class="bg-blue-50 p-2.5 rounded-lg text-blue-600">
                    <i data-lucide="map" class="w-5 h-5"></i>
                </div>
            </div>

            <!-- Kuota Resmi Terpakai -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Kuota Terpakai</span>
                    <h3 class="text-xl font-black text-blue-800 mt-1 leading-none"><?php echo e(number_format($kuotaTerpakai, 1, ',', '.')); ?></h3>
                    <span class="text-[9px] text-blue-600 font-semibold mt-1 inline-block">Resmi Terkirim</span>
                </div>
                <div class="bg-blue-50/50 p-2.5 rounded-lg text-blue-700">
                    <i data-lucide="send" class="w-5 h-5"></i>
                </div>
            </div>

            <!-- KUOTA TERINPUT / DRAFT -->
            <div class="bg-white p-5 rounded-xl border border-amber-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-amber-800 font-bold uppercase tracking-wider block">Terinput (Draft)</span>
                    <h3 class="text-xl font-black text-amber-700 mt-1 leading-none"><?php echo e(number_format($kuotaDraft, 1, ',', '.')); ?></h3>
                    <span class="text-[9px] text-amber-600 font-semibold mt-1 inline-block">Belum Dikirim</span>
                </div>
                <div class="bg-amber-50 p-2.5 rounded-lg text-amber-600">
                    <i data-lucide="file-edit" class="w-5 h-5"></i>
                </div>
            </div>

            <!-- Sisa Kuota Resmi Terbuka -->
            <div class="bg-white p-5 rounded-xl border border-emerald-200 shadow-md flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-emerald-800 font-extrabold uppercase tracking-wider block">Sisa Kuota Riil</span>
                    <h3 class="text-xl font-black text-emerald-700 mt-1 leading-none"><?php echo e(number_format($kuotaSisa, 1, ',', '.')); ?></h3>
                    <span class="text-[9px] text-emerald-600 font-semibold mt-1 inline-block">Ha Sisa Alokasi</span>
                </div>
                <div class="bg-emerald-600 p-2.5 rounded-lg text-white shadow-md shadow-emerald-600/20">
                    <i data-lucide="unlock" class="w-5 h-5"></i>
                </div>
            </div>
        </div>

        <!-- ROW 2: DETAIL PROGRES USULAN KABUPATEN -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            
            <!-- Grafik Distribusi Usulan Sisi Kabupaten (Kiri - 2/3) -->
            <div class="lg:col-span-2 bg-white rounded-xl border border-slate-200 shadow-sm p-6 flex flex-col justify-between">
                <div>
                    <h4 class="font-bold text-slate-800 text-base">Status Pengajuan Usulan <?php echo e($namaWilayah); ?></h4>
                    <p class="text-xs text-slate-500 mt-1">Alur verifikasi berkas usulan kelompok tani dari kabupaten Anda di tingkat Dinas Provinsi.</p>
                    
                    <div class="grid grid-cols-2 sm:grid-cols-4 gap-4 mt-6">
                        <div class="p-4 bg-amber-50 border border-amber-100 rounded-xl">
                            <span class="text-xs text-amber-800 font-bold block">Konsep Draft</span>
                            <span class="text-xl font-extrabold text-amber-700 mt-1 block leading-none"><?php echo e($totalDraft); ?> <span class="text-xs font-normal text-slate-400">Usulan</span></span>
                        </div>
                        <div class="p-4 bg-blue-50 border border-blue-100 rounded-xl">
                            <span class="text-xs text-blue-800 font-semibold block">Diajukan</span>
                            <span class="text-xl font-extrabold text-blue-700 mt-1 block leading-none"><?php echo e($totalDiajukan); ?> <span class="text-xs font-normal text-blue-400">Usulan</span></span>
                        </div>
                        <div class="p-4 bg-rose-50 border border-rose-100 rounded-xl">
                            <span class="text-xs text-rose-800 font-semibold block">Butuh Revisi</span>
                            <span class="text-xl font-extrabold text-rose-700 mt-1 block leading-none"><?php echo e($totalPerbaikan); ?> <span class="text-xs font-normal text-rose-400">Usulan</span></span>
                        </div>
                        <div class="p-4 bg-purple-50 border border-purple-100 rounded-xl">
                            <span class="text-xs text-purple-800 font-semibold block">SK Diterbitkan</span>
                            <span class="text-xl font-extrabold text-purple-700 mt-1 block leading-none"><?php echo e($totalFinal); ?> <span class="text-xs font-normal text-purple-400">Usulan</span></span>
                        </div>
                    </div>
                </div>
                
                <!-- Info Peringatan Virtual Limit -->
                <div class="mt-6 pt-4 border-t border-slate-100 flex flex-col sm:flex-row justify-between sm:items-center gap-2 text-xs font-medium">
                    <span class="text-slate-400 flex items-center gap-1.5">
                        <i data-lucide="check-circle" class="w-4 h-4 text-emerald-600 shrink-0"></i>
                        <span>Sisa Kuota Resmi tidak terpotong oleh berkas yang masih berstatus Draft.</span>
                    </span>
                    <span class="text-amber-800 bg-amber-50 border border-amber-100 px-2.5 py-1 rounded-lg">
                        Estimasi Sisa Kuota jika semua draft dikirim: <b><?php echo e(number_format($kuotaSisaVirtual, 1, ',', '.')); ?> Ha</b>
                    </span>
                </div>
            </div>

            <!-- List Usulan Terbaru Kabupaten (Kanan - 1/3) -->
            <div class="bg-white rounded-xl border border-slate-200 shadow-sm p-6 flex flex-col justify-between">
                <div>
                    <h4 class="font-bold text-slate-800 text-base">Usulan Terbaru Anda</h4>
                    <p class="text-xs text-slate-500 mt-1">Daftar 5 berkas pengusulan bantuan paling akhir.</p>
                    
                    <div class="mt-4 flex flex-col gap-2.5">
                        <?php $__empty_1 = true; $__currentLoopData = $usulanTerbaru; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ut): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <div class="flex justify-between items-center gap-2 p-2 hover:bg-slate-50 rounded-lg transition-colors border border-slate-50">
                                <div class="min-w-0">
                                    <span class="text-xs font-bold text-slate-800 truncate block"><?php echo e($ut->nama_kelompok); ?></span>
                                    <span class="text-[10px] text-slate-400 block truncate font-sans"><?php echo e($ut->nama_kegiatan); ?></span>
                                </div>
                                <span class="text-[9px] font-extrabold uppercase px-2 py-0.5 rounded <?php echo e($ut->status === 'draft' ? 'bg-amber-100 text-amber-800' : 'bg-slate-100 text-slate-600'); ?> shrink-0"><?php echo e($ut->status); ?></span>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <p class="text-xs text-slate-400 py-6 text-center">Belum ada berkas usulan yang dikirimkan.</p>
                        <?php endif; ?>
                    </div>
                </div>
                
                <a href="<?php echo e(route('shared.usulan.index')); ?>" class="text-xs font-bold text-emerald-700 hover:text-emerald-800 mt-4 block text-center font-sans">Buka Manajemen Usulan →</a>
            </div>
        </div>

    <?php else: ?>
        <!-- ======================================================= -->
        <!--              TAMPILAN KHUSUS USER PROVINSI              -->
        <!-- ======================================================= -->
        
        <!-- ROW 1: KARTU INDIKATOR UTAMA PROVINSI -->
        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-5">
            <!-- Kelompok Tani -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Total Kelompok Tani</span>
                    <h3 class="text-2xl font-bold text-slate-800 mt-1 leading-none"><?php echo e($totalPoktan); ?></h3>
                    <span class="text-[9px] text-emerald-600 font-semibold mt-1 inline-block">Terdaftar se-Jateng</span>
                </div>
                <div class="bg-emerald-50 p-3 rounded-lg text-emerald-600">
                    <i data-lucide="users" class="w-6 h-6"></i>
                </div>
            </div>

            <!-- Kabupaten -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Kabupaten Terdaftar</span>
                    <h3 class="text-2xl font-bold text-slate-800 mt-1 leading-none"><?php echo e($totalKabupaten); ?></h3>
                    <span class="text-[9px] text-blue-600 font-semibold mt-1 inline-block">Wilayah Mitra</span>
                </div>
                <div class="bg-blue-50 p-3 rounded-lg text-blue-600">
                    <i data-lucide="map" class="w-6 h-6"></i>
                </div>
            </div>

            <!-- Total Usulan -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Total Usulan Masuk</span>
                    <h3 class="text-2xl font-bold text-slate-800 mt-1 leading-none"><?php echo e($totalUsulan); ?></h3>
                    <span class="text-[9px] text-amber-600 font-semibold mt-1 inline-block">Berkas Terkirim</span>
                </div>
                <div class="bg-amber-50 p-3 rounded-lg text-amber-600">
                    <i data-lucide="file-text" class="w-6 h-6"></i>
                </div>
            </div>

            <!-- Disetujui Final -->
            <div class="bg-white p-5 rounded-xl border border-slate-200 shadow-sm flex items-center justify-between">
                <div>
                    <span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider block">Disetujui Final</span>
                    <h3 class="text-2xl font-bold text-purple-600 mt-1 leading-none"><?php echo e($totalFinal); ?></h3>
                    <span class="text-[9px] text-purple-600 font-semibold mt-1 inline-block">Siap Salurkan Barang</span>
                </div>
                <div class="bg-purple-50 p-3 rounded-lg text-purple-600">
                    <i data-lucide="award" class="w-6 h-6"></i>
                </div>
            </div>
        </div>

        <!-- ROW 2: DETAIL PROGRES USULAN PROVINSI -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
            
            <!-- Pantauan Berkas Berjenjang (Kiri - 2/3) -->
            <div class="lg:col-span-2 bg-white rounded-xl border border-slate-200 shadow-sm p-6 flex flex-col justify-between">
                <div>
                    <h4 class="font-bold text-slate-800 text-base">Alur Pengusulan Berjenjang Jawa Tengah</h4>
                    <p class="text-xs text-slate-500 mt-1">Alur verifikasi berkas usulan kelompok tani dari kabupaten hingga tingkat SK Provinsi.</p>
                    
                    <div class="grid grid-cols-1 sm:grid-cols-3 gap-4 mt-6">
                        <div class="p-4 bg-slate-50 border border-slate-100 rounded-xl">
                            <span class="text-xs text-slate-500 font-semibold block">Diajukan (Review)</span>
                            <span class="text-2xl font-extrabold text-slate-700 mt-1 block leading-none"><?php echo e($totalDiajukan); ?> <span class="text-xs font-normal text-slate-400">Berkas</span></span>
                        </div>
                        <div class="p-4 bg-emerald-50 border border-emerald-100 rounded-xl">
                            <span class="text-xs text-emerald-800 font-semibold block">Diverifikasi Admin</span>
                            <span class="text-2xl font-extrabold text-slate-700 mt-1 block leading-none"><?php echo e($totalDiverifikasi); ?> <span class="text-xs font-normal text-emerald-500">Berkas</span></span>
                        </div>
                        <div class="p-4 bg-purple-50 border border-purple-100 rounded-xl">
                            <span class="text-xs text-purple-800 font-semibold block">SK Draf Final</span>
                            <span class="text-2xl font-extrabold text-purple-700 mt-1 block leading-none"><?php echo e($totalFinal); ?> <span class="text-xs font-normal text-purple-500">Berkas</span></span>
                        </div>
                    </div>
                </div>
                
                <div class="mt-6 pt-4 border-t border-slate-100 text-xs text-slate-400 flex items-center gap-1.5 font-medium">
                    <i data-lucide="info" class="w-4 h-4 text-slate-300"></i>
                    <span>Tampilan data di atas merepresentasikan kondisi pengusulan kumulatif dari seluruh operator kabupaten.</span>
                </div>
            </div>

            <!-- List Usulan Skor Tertinggi (Kanan - 1/3) -->
            <div class="bg-white rounded-xl border border-slate-200 shadow-sm p-6 flex flex-col justify-between">
                <div>
                    <h4 class="font-bold text-slate-800 text-base">Prioritas Utama Skor Tertinggi</h4>
                    <p class="text-xs text-slate-500 mt-1">Daftar usulan dengan pemenuhan syarat spasial terbaik se-Jateng.</p>
                    
                    <div class="mt-4 flex flex-col gap-2.5">
                        <?php $__empty_1 = true; $__currentLoopData = $usulanPrioritas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $up): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <div class="flex justify-between items-center gap-2 p-2 bg-emerald-50/50 hover:bg-emerald-50 rounded-lg transition-colors border border-emerald-100/50">
                                <div class="min-w-0">
                                    <span class="text-xs font-bold text-slate-800 truncate block"><?php echo e($up->nama_kelompok); ?></span>
                                    <span class="text-[9px] text-slate-400 block truncate">Kab. <?php echo e($up->nama_kabupaten); ?> | <?php echo e($up->nama_kegiatan); ?></span>
                                </div>
                                <span class="text-xs font-extrabold text-emerald-800 shrink-0 bg-white border border-emerald-200 px-1.5 py-0.5 rounded"><?php echo e(round($up->akumulasi_skor)); ?> pts</span>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <p class="text-xs text-slate-400 py-6 text-center">Belum ada berkas usulan yang masuk ke database.</p>
                        <?php endif; ?>
                    </div>
                </div>
                
                <a href="<?php echo e(route('shared.usulan.index')); ?>" class="text-xs font-bold text-emerald-700 hover:text-emerald-800 mt-4 block text-center font-sans">Proses Verifikasi Sekarang →</a>
            </div>
        </div>
    <?php endif; ?>

</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\laragon\www\pradipa\resources\views/shared/dashboard.blade.php ENDPATH**/ ?>