

<?php $__env->startSection('title', 'Manajemen Kegiatan Bantuan | PRADIPA'); ?>

<?php $__env->startSection('content'); ?>
<div class="flex flex-col gap-6">
    <!-- Header Halaman -->
    <div class="bg-white p-6 rounded-xl border border-slate-200 shadow-sm flex flex-col md:flex-row justify-between md:items-center gap-4">
        <div>
            <h2 class="text-2xl font-bold text-slate-800">Manajemen Program Kegiatan</h2>
            <p class="text-sm text-slate-500 mt-1 font-medium font-sans">
                <?php if($role === 'provinsi_admin'): ?>
                    Buat, monitoring, dan atur ketersediaan alokasi program bantuan sarana produksi pertanian.
                <?php else: ?>
                    Panduan dan acuan teknis program bantuan, daftar komoditas saprodi, persyaratan berkas, serta pagu kuota kabupaten Anda.
                <?php endif; ?>
            </p>
        </div>
        <!-- Tombol Tambah Kegiatan (Hanya Tampil untuk Admin Provinsi) -->
        <?php if($role === 'provinsi_admin'): ?>
            <button onclick="bukaModalKegiatan()" class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg text-sm font-semibold shadow-sm transition-all flex items-center gap-2 self-start md:self-auto font-sans">
                <i data-lucide="plus" class="w-4 h-4"></i>
                Tambah Program Baru
            </button>
        <?php endif; ?>
    </div>

    <!-- Tampilan Error Validasi -->
    <?php if($errors->any()): ?>
        <div class="bg-rose-100 border-l-4 border-rose-600 text-rose-800 p-4 rounded-xl shadow-sm text-sm font-medium font-sans">
            <?php echo e($errors->first()); ?>

        </div>
    <?php endif; ?>

    <!-- Tampilan Toast Flash Message Sukses -->
    <?php if(session('success')): ?>
        <div class="bg-emerald-100 border-l-4 border-emerald-600 text-emerald-800 p-4 rounded-xl shadow-sm text-sm flex items-center gap-2 font-sans">
            <i data-lucide="check-circle" class="text-emerald-600"></i>
            <span class="font-medium"><?php echo e(session('success')); ?></span>
        </div>
    <?php endif; ?>

    <!-- FILTER PENCARIAN & TOMBOL SWITCH VIEW -->
    <div class="bg-white p-4 rounded-xl border border-slate-200 shadow-sm flex flex-col sm:flex-row gap-4 justify-between items-stretch sm:items-center">
        <form action="<?php echo e(route('shared.kegiatan.index')); ?>" method="GET" class="flex-1 flex gap-3">
            <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="<?php echo e(request('search')); ?>" placeholder="Cari berdasarkan nama program bantuan atau tahun..." 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>
            <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 font-sans shrink-0">
                Cari
            </button>
        </form>
        
        <!-- View Toggle Control Group -->
        <div class="flex items-center border border-slate-200 rounded-lg p-1 bg-slate-50 shrink-0 self-start sm:self-auto gap-1">
            <button type="button" id="btnGridView" onclick="switchKegiatanView('grid')" class="p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold" title="Tampilan Kartu Grid">
                <i data-lucide="layout-grid" class="w-4 h-4"></i>
                <span class="hidden sm:inline">Grid</span>
            </button>
            <button type="button" id="btnListView" onclick="switchKegiatanView('list')" class="p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold" title="Tampilan Daftar List">
                <i data-lucide="list" class="w-4 h-4"></i>
                <span class="hidden sm:inline">List</span>
            </button>
        </div>
    </div>

    <!-- ========================================================================= -->
    <!--             1. TAMPILAN MODE GRID CARDS (GRID VIEW CONTAINER)             -->
    <!-- ========================================================================= -->
    <div id="gridViewContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        <?php $__empty_1 = true; $__currentLoopData = $kegiatans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                // Hitung statistik pendukung
                $totalBarang = DB::table('barang_kegiatan')->where('kegiatan_id', $k->id)->count();
                $totalSyarat = DB::table('syarat_kegiatan')->where('kegiatan_id', $k->id)->count();
                $totalKuota = DB::table('kuota_kabupaten')->where('kegiatan_id', $k->id)->count();
                
                // Pagu total alokasi
                $totalLuasKuota = DB::table('kuota_kabupaten')->where('kegiatan_id', $k->id)->sum('kuota_luas');

                // Ambil daftar barang bantuan nyata untuk dirender
                $listBarangs = DB::table('barang_kegiatan')->where('kegiatan_id', $k->id)->get();
                // Ambil kriteria berkas nyata untuk dirender
                $listSyarats = DB::table('syarat_kegiatan')->where('kegiatan_id', $k->id)->get();

                // Kuota spesifik kabupaten login (jika operator kabupaten)
                $kuotaKabupatenSpesifik = 0;
                if($role === 'kabupaten_user') {
                    $kuotaKabupatenSpesifik = DB::table('kuota_kabupaten')
                        ->where('kegiatan_id', $k->id)
                        ->where('regency_id', $regencyId)
                        ->value('kuota_luas') ?? 0;
                }
            ?>
            <div class="bg-white border <?php echo e($k->is_active ? 'border-slate-200' : 'border-slate-100 opacity-75'); ?> rounded-2xl shadow-sm hover:shadow-md transition-all flex flex-col justify-between overflow-hidden relative">
                
                <div class="p-6 flex-1 flex flex-col">
                    <!-- Badge Tahun Anggaran & Tombol Edit Data Dasar (Hanya Provinsi) -->
                    <div class="flex justify-between items-center mb-4">
                        <span class="bg-emerald-100 text-emerald-800 text-[10px] font-extrabold px-2.5 py-1 rounded-full uppercase">TA <?php echo e($k->tahun_anggaran); ?></span>
                        
                        <div class="flex items-center gap-2">
                            <!-- TOMBOL Edit Data Dasar Program (Hanya Provinsi) -->
                            <?php if($role === 'provinsi_admin'): ?>
                                <button onclick="bukaModalEdit(<?php echo e($k->id); ?>, '<?php echo e(addslashes($k->nama_kegiatan)); ?>', '<?php echo e($k->tahun_anggaran); ?>', '<?php echo e(addslashes($k->deskripsi ?? '')); ?>')" class="p-1.5 hover:bg-slate-100 text-slate-400 hover:text-emerald-700 rounded-lg transition-all" title="Edit Data Dasar Program">
                                    <i data-lucide="edit-3" class="w-4 h-4"></i>
                                </button>
                            <?php endif; ?>

                            <?php if($k->is_active): ?>
                                <span class="flex items-center gap-1.5 text-xs text-emerald-600 font-bold font-sans">
                                    <span class="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></span> Aktif
                                </span>
                            <?php else: ?>
                                <span class="flex items-center gap-1.5 text-xs text-slate-400 font-bold font-sans">
                                    <span class="w-1.5 h-1.5 rounded-full bg-slate-400"></span> Nonaktif
                                </span>
                            <?php endif; ?>
                        </div>
                    </div>

                    <h3 class="font-extrabold text-slate-800 text-base leading-snug mb-2 font-sans"><?php echo e($k->nama_kegiatan); ?></h3>
                    <p class="text-xs text-slate-500 leading-relaxed line-clamp-3 mb-4 flex-1 font-sans"><?php echo e($k->deskripsi ?? 'Belum ada penjelasan detail mengenai program bantuan ini.'); ?></p>

                    <!-- SEKSI DETAIL NYATA (BARANG & PERSYARATAN) UNTUK DIKONSUMSI OPERATOR KABUPATEN -->
                    <div class="mt-2 space-y-3.5 border-t border-slate-100 pt-4 font-sans text-xs">
                        
                        <!-- List Rinci Barang Bantuan -->
                        <div class="flex flex-col gap-1.5">
                            <span class="font-bold text-slate-400 text-[10px] uppercase tracking-wider block">Daftar Komoditas Bantuan:</span>
                            <?php $__empty_2 = true; $__currentLoopData = $listBarangs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_2 = false; ?>
                                <div class="flex justify-between items-center bg-slate-50 border border-slate-100 px-3 py-1.5 rounded-lg text-[11px]">
                                    <span class="font-semibold text-slate-700"><?php echo e($lb->nama_barang); ?></span>
                                    <span class="font-mono text-emerald-700 font-bold bg-emerald-100/50 px-2 py-0.5 rounded"><?php echo e(floatval($lb->volume_per_hektar)); ?> <?php echo e($lb->satuan); ?>/Ha</span>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_2): ?>
                                <span class="text-slate-400 italic">Belum mendaftarkan barang alokasi.</span>
                            <?php endif; ?>
                        </div>

                        <!-- List Rinci Berkas Persyaratan -->
                        <div class="flex flex-col gap-1.5 mt-2">
                            <span class="font-bold text-slate-400 text-[10px] uppercase tracking-wider block">Persyaratan Dokumen & Spasial:</span>
                            <?php $__empty_2 = true; $__currentLoopData = $listSyarats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ls): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_2 = false; ?>
                                <div class="flex justify-between items-center bg-slate-50 border border-slate-100 px-3 py-1.5 rounded-lg text-[11px]">
                                    <span class="font-semibold text-slate-700 flex items-center gap-1">
                                        <?php echo e($ls->nama_syarat); ?>

                                        <?php if($ls->is_required): ?>
                                            <span class="text-rose-600 font-black">*</span>
                                        <?php endif; ?>
                                    </span>
                                    <span class="font-mono text-[9px] bg-slate-200 text-slate-600 px-1.5 py-0.5 rounded font-bold uppercase"><?php echo e($ls->tipe_file); ?></span>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_2): ?>
                                <span class="text-slate-400 italic">Belum menentukan berkas persyaratan.</span>
                            <?php endif; ?>
                        </div>
                    </div>

                    <!-- Info Alokasi Pagu Lahan -->
                    <div class="border-t border-slate-100 pt-4 space-y-2 text-[11px] text-slate-600 font-medium font-sans mt-4">
                        <?php if($role === 'provinsi_admin' || $role === 'provinsi_pejabat'): ?>
                            <!-- Sudut Pandang Provinsi: Total Alokasi Pagu se-Jateng -->
                            <div class="flex items-center justify-between">
                                <div class="flex items-center gap-2">
                                    <i data-lucide="map-pin" class="w-4 h-4 text-slate-400"></i>
                                    <span>Distribusi Wilayah:</span>
                                </div>
                                <span class="font-bold text-slate-800"><?php echo e($totalKuota); ?> Kab / Kota</span>
                            </div>
                            <div class="flex items-center justify-between bg-emerald-50/40 p-2.5 rounded-xl border border-emerald-100/50 mt-2">
                                <div class="flex items-center gap-2 text-emerald-800">
                                    <i data-lucide="calculator" class="w-4 h-4 text-emerald-600"></i>
                                    <span class="font-bold">Total Alokasi Pagu:</span>
                                </div>
                                <span class="font-black text-emerald-800 text-xs"><?php echo e(number_format($totalLuasKuota, 1, ',', '.')); ?> Ha</span>
                            </div>
                        <?php else: ?>
                            <!-- Sudut Pandang Kabupaten: Hanya Menampilkan Kuota Kabupatennya Sendiri -->
                            <div class="flex items-center justify-between bg-emerald-50/40 p-2.5 rounded-xl border border-emerald-100/50 mt-2">
                                <div class="flex items-center gap-2 text-emerald-800">
                                    <i data-lucide="shield-check" class="w-4 h-4 text-emerald-600"></i>
                                    <span class="font-bold">Jatah Alokasi Kuota Kabupaten Anda:</span>
                                </div>
                                <span class="font-black text-emerald-800 text-sm"><?php echo e(number_format($kuotaKabupatenSpesifik, 1, ',', '.')); ?> Ha</span>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Bagian Tombol Aksi di Bawah Card (Hanya muncul jika yang masuk Provinsi) -->
                <?php if($role === 'provinsi_admin'): ?>
                    <div class="bg-slate-50 border-t border-slate-100 px-6 py-3.5 flex justify-between items-center gap-2 font-sans">
                        <a href="<?php echo e(route('shared.kegiatan.param', $k->id)); ?>" class="px-3 py-1.5 bg-white hover:bg-slate-100 text-slate-700 font-bold text-xs rounded-lg transition-colors border border-slate-200 flex items-center gap-1.5">
                            <i data-lucide="sliders" class="w-3.5 h-3.5 text-slate-500"></i>
                            Atur Parameter
                        </a>

                        <form action="<?php echo e(route('shared.kegiatan.toggle', $k->id)); ?>" method="POST">
                            <?php echo csrf_field(); ?>
                            <?php if($k->is_active): ?>
                                <button type="submit" class="px-3 py-1.5 bg-rose-50 hover:bg-rose-100 text-rose-700 font-bold text-xs rounded-lg transition-colors border border-rose-200">
                                    Nonaktifkan
                                </button>
                            <?php else: ?>
                                <button type="submit" class="px-3 py-1.5 bg-emerald-50 hover:bg-emerald-100 text-emerald-700 font-bold text-xs rounded-lg transition-colors border border-emerald-200">
                                    Aktifkan
                                </button>
                            <?php endif; ?>
                        </form>
                    </div>
                <?php endif; ?>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="col-span-full bg-white p-12 text-center rounded-2xl border border-slate-200 shadow-sm flex flex-col items-center justify-center gap-3">
                <div class="bg-slate-50 p-4 rounded-full text-slate-400">
                    <i data-lucide="folder-open" class="w-10 h-10"></i>
                </div>
                <h4 class="font-bold text-slate-800 text-base">Belum Ada Program Bantuan</h4>
                <p class="text-xs text-slate-400">Dinas Provinsi belum mendaftarkan program bantuan dinas pertanian aktif apa pun.</p>
            </div>
        <?php endif; ?>
    </div>

    <!-- ========================================================================= -->
    <!--             2. TAMPILAN MODE AKORDION LIST (LIST VIEW CONTAINER)           -->
    <!-- ========================================================================= -->
    <div id="listViewContainer" class="hidden flex flex-col gap-4">
        <?php $__empty_1 = true; $__currentLoopData = $kegiatans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                $totalBarang = DB::table('barang_kegiatan')->where('kegiatan_id', $k->id)->count();
                $totalSyarat = DB::table('syarat_kegiatan')->where('kegiatan_id', $k->id)->count();
                $totalKuota = DB::table('kuota_kabupaten')->where('kegiatan_id', $k->id)->count();
                $totalLuasKuota = DB::table('kuota_kabupaten')->where('kegiatan_id', $k->id)->sum('kuota_luas');
                $listBarangs = DB::table('barang_kegiatan')->where('kegiatan_id', $k->id)->get();
                $listSyarats = DB::table('syarat_kegiatan')->where('kegiatan_id', $k->id)->get();

                $kuotaKabupatenSpesifik = 0;
                if($role === 'kabupaten_user') {
                    $kuotaKabupatenSpesifik = DB::table('kuota_kabupaten')
                        ->where('kegiatan_id', $k->id)
                        ->where('regency_id', $regencyId)
                        ->value('kuota_luas') ?? 0;
                }
            ?>
            <div class="bg-white border <?php echo e($k->is_active ? 'border-slate-200' : 'border-slate-100 opacity-75'); ?> rounded-xl shadow-sm hover:shadow-md transition-all overflow-hidden flex flex-col">
                <!-- Baris Utama Kegiatan -->
                <div class="p-4 flex flex-col md:flex-row md:items-center justify-between gap-4 select-none cursor-pointer hover:bg-slate-50/50" onclick="toggleDetailAccordion(<?php echo e($k->id); ?>)">
                    
                    <!-- Sektor Kiri: Nama & TA -->
                    <div class="flex items-center gap-3 min-w-0">
                        <!-- Chevron Arrow Icon -->
                        <div class="p-1 rounded bg-slate-100 text-slate-500 transition-transform duration-300" id="accordionChevron-<?php echo e($k->id); ?>">
                            <i data-lucide="chevron-down" class="w-4 h-4"></i>
                        </div>
                        <span class="bg-emerald-100 text-emerald-800 text-[9px] font-black px-2 py-0.5 rounded tracking-wide shrink-0">TA <?php echo e($k->tahun_anggaran); ?></span>
                        <h3 class="font-extrabold text-slate-800 text-sm md:text-base leading-snug truncate font-sans"><?php echo e($k->nama_kegiatan); ?></h3>
                    </div>

                    <!-- Sektor Kanan: Status & Ringkasan Pagu & Aksi Cepat -->
                    <div class="flex items-center justify-between md:justify-end gap-3 shrink-0 font-sans text-xs">
                        <!-- Indikator Kuota Ringkas -->
                        <?php if($role === 'provinsi_admin' || $role === 'provinsi_pejabat'): ?>
                            <div class="bg-emerald-50 border border-emerald-100 px-2.5 py-1 rounded-lg text-emerald-800 font-extrabold text-[11px]">
                                Pagu: <?php echo e(number_format($totalLuasKuota, 1, ',', '.')); ?> Ha
                            </div>
                        <?php else: ?>
                            <div class="bg-emerald-50 border border-emerald-100 px-2.5 py-1 rounded-lg text-emerald-800 font-extrabold text-[11px]">
                                Kuota Anda: <?php echo e(number_format($kuotaKabupatenSpesifik, 1, ',', '.')); ?> Ha
                            </div>
                        <?php endif; ?>

                        <!-- Status Aktivitas -->
                        <?php if($k->is_active): ?>
                            <span class="px-2 py-0.5 bg-emerald-100 text-emerald-800 text-[10px] font-black rounded-full uppercase">Aktif</span>
                        <?php else: ?>
                            <span class="px-2 py-0.5 bg-slate-100 text-slate-400 text-[10px] font-black rounded-full uppercase">Nonaktif</span>
                        <?php endif; ?>

                        <!-- Panel Tombol Cepat Provinsi (Hanya muncul jika yang masuk Provinsi) -->
                        <?php if($role === 'provinsi_admin'): ?>
                            <div class="flex items-center gap-1 border-l border-slate-200 pl-3" onclick="event.stopPropagation();">
                                <a href="<?php echo e(route('shared.kegiatan.param', $k->id)); ?>" class="p-1.5 hover:bg-slate-100 text-slate-500 hover:text-emerald-700 rounded-lg transition-colors border border-transparent hover:border-slate-200" title="Atur Parameter">
                                    <i data-lucide="sliders" class="w-3.5 h-3.5"></i>
                                </a>
                                <button onclick="bukaModalEdit(<?php echo e($k->id); ?>, '<?php echo e(addslashes($k->nama_kegiatan)); ?>', '<?php echo e($k->tahun_anggaran); ?>', '<?php echo e(addslashes($k->deskripsi ?? '')); ?>')" class="p-1.5 hover:bg-slate-100 text-slate-500 hover:text-emerald-700 rounded-lg transition-colors border border-transparent hover:border-slate-200" title="Edit Data Dasar">
                                    <i data-lucide="edit-3" class="w-3.5 h-3.5"></i>
                                </button>
                                <form action="<?php echo e(route('shared.kegiatan.toggle', $k->id)); ?>" method="POST" class="inline m-0">
                                    <?php echo csrf_field(); ?>
                                    <button type="submit" class="p-1.5 hover:bg-slate-100 rounded-lg transition-colors border border-transparent hover:border-slate-200 text-rose-600" title="<?php echo e($k->is_active ? 'Nonaktifkan' : 'Aktifkan'); ?>">
                                        <i data-lucide="<?php echo e($k->is_active ? 'eye-off' : 'eye'); ?>" class="w-3.5 h-3.5"></i>
                                    </button>
                                </form>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Bagian Detail Lipatan Akordion (Collapsible Detail) -->
                <div id="accordionDetail-<?php echo e($k->id); ?>" class="hidden border-t border-slate-100 p-6 bg-slate-50/50 animate-fade-in font-sans">
                    <div class="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start">
                        <!-- Kolom Detail Kiri (Teks & Komoditas) -->
                        <div class="lg:col-span-8 flex flex-col gap-4">
                            <div>
                                <span class="font-extrabold text-slate-400 text-[10px] uppercase tracking-wider block mb-1">Deskripsi & Tujuan Program:</span>
                                <p class="text-xs text-slate-600 leading-relaxed bg-white p-3 rounded-lg border border-slate-200/60"><?php echo e($k->deskripsi ?? 'Belum ada penjelasan detail mengenai program bantuan ini.'); ?></p>
                            </div>

                            <!-- List Barang Bantuan -->
                            <div>
                                <span class="font-extrabold text-slate-400 text-[10px] uppercase tracking-wider block mb-2">Daftar Komoditas Bantuan:</span>
                                <div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
                                    <?php $__empty_2 = true; $__currentLoopData = $listBarangs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_2 = false; ?>
                                        <div class="flex justify-between items-center bg-white border border-slate-200/85 px-3.5 py-2 rounded-lg text-xs shadow-sm">
                                            <span class="font-bold text-slate-700"><?php echo e($lb->nama_barang); ?></span>
                                            <span class="font-mono text-emerald-800 font-extrabold bg-emerald-50 px-2 py-0.5 rounded border border-emerald-100"><?php echo e(floatval($lb->volume_per_hektar)); ?> <?php echo e($lb->satuan); ?>/Ha</span>
                                        </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_2): ?>
                                        <span class="text-xs text-slate-400 italic">Belum mendaftarkan barang alokasi.</span>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>

                        <!-- Kolom Detail Kanan (Persyaratan & Distribusi Kuota) -->
                        <div class="lg:col-span-4 flex flex-col gap-4">
                            <!-- List Syarat Berkas -->
                            <div>
                                <span class="font-extrabold text-slate-400 text-[10px] uppercase tracking-wider block mb-2">Persyaratan Dokumen & Spasial:</span>
                                <div class="flex flex-col gap-2">
                                    <?php $__empty_2 = true; $__currentLoopData = $listSyarats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ls): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_2 = false; ?>
                                        <div class="flex justify-between items-center bg-white border border-slate-200/85 px-3 py-2 rounded-lg text-xs shadow-sm">
                                            <span class="font-bold text-slate-700 flex items-center gap-1">
                                                <?php echo e($ls->nama_syarat); ?>

                                                <?php if($ls->is_required): ?>
                                                    <span class="text-rose-600 font-black">*</span>
                                                <?php endif; ?>
                                            </span>
                                            <span class="font-mono text-[9px] bg-slate-100 text-slate-600 px-2 py-0.5 rounded font-black uppercase border border-slate-200"><?php echo e($ls->tipe_file); ?></span>
                                        </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_2): ?>
                                        <span class="text-xs text-slate-400 italic">Belum menentukan berkas persyaratan.</span>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <!-- Papan Info Alokasi Pagu Lahan -->
                            <div class="p-4 bg-white border border-slate-200 rounded-xl shadow-sm text-xs space-y-2">
                                <span class="font-extrabold text-slate-400 text-[10px] uppercase tracking-wider block mb-1">Informasi Alokasi Pagu Lahan:</span>
                                <?php if($role === 'provinsi_admin' || $role === 'provinsi_pejabat'): ?>
                                    <div class="flex items-center justify-between text-[11px] text-slate-600 font-semibold">
                                        <span>Distribusi Wilayah:</span>
                                        <span class="text-slate-800 font-bold"><?php echo e($totalKuota); ?> Kab / Kota</span>
                                    </div>
                                    <div class="flex items-center justify-between pt-1 text-emerald-800 font-bold border-t border-slate-100">
                                        <span>Total Alokasi Pagu:</span>
                                        <span class="font-black text-sm"><?php echo e(number_format($totalLuasKuota, 1, ',', '.')); ?> Ha</span>
                                    </div>
                                <?php else: ?>
                                    <div class="flex items-center justify-between pt-1 text-emerald-800 font-bold">
                                        <span>Alokasi Kabupaten Anda:</span>
                                        <span class="font-black text-sm"><?php echo e(number_format($kuotaKabupatenSpesifik, 1, ',', '.')); ?> Ha</span>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="bg-white p-12 text-center rounded-xl border border-slate-200 shadow-sm flex flex-col items-center justify-center gap-3">
                <div class="bg-slate-50 p-4 rounded-full text-slate-400">
                    <i data-lucide="folder-open" class="w-10 h-10"></i>
                </div>
                <h4 class="font-bold text-slate-800 text-base">Belum Ada Program Bantuan</h4>
                <p class="text-xs text-slate-400">Dinas Provinsi belum mendaftarkan program bantuan dinas pertanian aktif apa pun.</p>
            </div>
        <?php endif; ?>
    </div>
</div>

<!-- ================= MODAL TAMBAH KEGIATAN BARU (Hanya untuk Admin Provinsi) ================= -->
<?php if($role === 'provinsi_admin'): ?>
    <div id="modalTambahKegiatan" class="hidden fixed inset-0 z-50 bg-slate-900/60 flex items-center justify-center p-4">
        <div class="bg-white w-full max-w-md rounded-2xl shadow-2xl border border-slate-200 overflow-hidden">
            <div class="bg-slate-50 border-b border-slate-100 px-6 py-4 flex justify-between items-center">
                <h3 class="font-bold text-slate-800 text-base">Registrasi Program Bantuan Baru</h3>
                <button onclick="tutupModalKegiatan()" class="text-slate-400 hover:text-slate-600 bg-slate-100 hover:bg-slate-200 p-1.5 rounded-full transition-all">
                    <i data-lucide="x" class="w-4 h-4"></i>
                </button>
            </div>
            
            <form action="<?php echo e(route('shared.kegiatan.store')); ?>" method="POST" class="p-6 flex flex-col gap-4">
                <?php echo csrf_field(); ?>
                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Nama Program Bantuan:</label>
                    <input type="text" name="nama_kegiatan" placeholder="Contoh: Saprodi Padi Unggul Jawa Tengah" required class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500">
                </div>

                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Tahun Anggaran (TA):</label>
                    <input type="number" name="tahun_anggaran" value="<?php echo e(date('Y')); ?>" placeholder="Contoh: 2026" required class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500">
                </div>

                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Deskripsi/Tujuan Program:</label>
                    <textarea name="deskripsi" placeholder="Tuliskan petunjuk singkat juknis dari program bantuan..." rows="3" class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"></textarea>
                </div>

                <div class="flex justify-end gap-2 border-t border-slate-100 pt-4 mt-2">
                    <button type="button" onclick="tutupModalKegiatan()" class="px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-bold rounded-lg">Batal</button>
                    <button type="submit" class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold rounded-lg shadow-sm">Simpan Kegiatan</button>
                </div>
            </form>
        </div>
    </div>

    <!-- ================= MODAL EDIT DATA DASAR KEGIATAN ================= -->
    <div id="modalEditKegiatan" class="hidden fixed inset-0 z-50 bg-slate-900/60 flex items-center justify-center p-4">
        <div class="bg-white w-full max-w-md rounded-2xl shadow-2xl border border-slate-200 overflow-hidden">
            <div class="bg-slate-50 border-b border-slate-100 px-6 py-4 flex justify-between items-center">
                <h3 class="font-bold text-slate-800 text-base">Ubah Data Dasar Program</h3>
                <button onclick="tutupModalEdit()" class="text-slate-400 hover:text-slate-600 bg-slate-100 hover:bg-slate-200 p-1.5 rounded-full transition-all">
                    <i data-lucide="x" class="w-4 h-4"></i>
                </button>
            </div>
            
            <!-- Action Form ditargetkan secara dinamis via JavaScript -->
            <form id="formEditKegiatan" method="POST" class="p-6 flex flex-col gap-4">
                <?php echo csrf_field(); ?>
                
                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Nama Program Bantuan:</label>
                    <input type="text" name="nama_kegiatan" id="editNama" placeholder="Nama program bantuan..." required class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500">
                </div>

                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Tahun Anggaran (TA):</label>
                    <input type="number" name="tahun_anggaran" id="editTahun" placeholder="Tahun..." required class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500">
                </div>

                <div class="flex flex-col gap-1.5">
                    <label class="text-xs font-bold text-slate-500 uppercase tracking-wider">Deskripsi/Tujuan Program:</label>
                    <textarea name="deskripsi" id="editDeskripsi" placeholder="Tujuan singkat atau petunjuk juknis..." rows="3" class="w-full px-3.5 py-2 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"></textarea>
                </div>

                <div class="flex justify-end gap-2 border-t border-slate-100 pt-4 mt-2">
                    <button type="button" onclick="tutupModalEdit()" class="px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-bold rounded-lg">Batal</button>
                    <button type="submit" class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold rounded-lg shadow-sm">Simpan Perubahan</button>
                </div>
            </form>
        </div>
    </div>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    // --- FUNGSIONALITAS SWITCH VIEW MODE (LOCAL STORAGE INTEGRATED) ---
    function switchKegiatanView(mode) {
        const gridContainer = document.getElementById('gridViewContainer');
        const listContainer = document.getElementById('listViewContainer');
        const btnGrid = document.getElementById('btnGridView');
        const btnList = document.getElementById('btnListView');

        if (mode === 'grid') {
            gridContainer.classList.remove('hidden');
            listContainer.classList.add('hidden');
            
            // Set Style Active untuk Button Grid
            btnGrid.className = "p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold bg-white text-slate-800 shadow-sm border border-slate-200/50";
            btnList.className = "p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold text-slate-400 hover:text-slate-700";
            
            localStorage.setItem('kegiatan_view_mode', 'grid');
        } else {
            gridContainer.classList.add('hidden');
            listContainer.classList.remove('hidden');
            
            // Set Style Active untuk Button List
            btnGrid.className = "p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold text-slate-400 hover:text-slate-700";
            btnList.className = "p-1.5 rounded-md transition-all flex items-center gap-1 text-xs font-bold bg-white text-slate-800 shadow-sm border border-slate-200/50";
            
            localStorage.setItem('kegiatan_view_mode', 'list');
        }
    }

    // --- FUNGSIONALITAS TOGGLE AKORDION DETAIL LIST ---
    function toggleDetailAccordion(id) {
        const detailPanel = document.getElementById('accordionDetail-' + id);
        const chevron = document.getElementById('accordionChevron-' + id);

        if (detailPanel.classList.contains('hidden')) {
            detailPanel.classList.remove('hidden');
            chevron.classList.add('rotate-180');
        } else {
            detailPanel.classList.add('hidden');
            chevron.classList.remove('rotate-180');
        }
    }

    // Penanganan Modal Tambah (Hanya diaktifkan jika role admin)
    <?php if($role === 'provinsi_admin'): ?>
        function bukaModalKegiatan() {
            document.getElementById('modalTambahKegiatan').classList.remove('hidden');
        }
        function tutupModalKegiatan() {
            document.getElementById('modalTambahKegiatan').classList.add('hidden');
        }

        // Penanganan Modal Edit
        function bukaModalEdit(id, nama, tahun, deskripsi) {
            document.getElementById('editNama').value = nama;
            document.getElementById('editTahun').value = tahun;
            document.getElementById('editDeskripsi').value = deskripsi;

            const form = document.getElementById('formEditKegiatan');
            form.action = `<?php echo e(url('shared/kegiatan')); ?>/${id}/update`;

            document.getElementById('modalEditKegiatan').classList.remove('hidden');
        }

        function tutupModalEdit() {
            document.getElementById('modalEditKegiatan').classList.add('hidden');
        }
    <?php endif; ?>

    // Inisialisasi Tampilan Berdasarkan Pilihan Terakhir User
    document.addEventListener('DOMContentLoaded', () => {
        const savedMode = localStorage.getItem('kegiatan_view_mode') || 'grid';
        switchKegiatanView(savedMode);
    });
</script>
<?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/kegiatan/index.blade.php ENDPATH**/ ?>