<?php $__env->startSection('header', 'Edit Penerima Manfaat'); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-4xl mx-auto">
    <div class="mb-6">
        <a href="<?php echo e(route('beneficiaries.index')); ?>" class="text-gray-500 hover:text-primary transition flex items-center text-sm font-medium">
            <i class="fas fa-arrow-left mr-2"></i> Kembali ke Daftar
        </a>
    </div>

    <form action="<?php echo e(route('beneficiaries.update', $beneficiary->id)); ?>" method="POST" class="space-y-6">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>
        
        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Informasi Pribadi</h3>
                <p class="text-sm text-gray-500 mt-1">Data dasar penerima manfaat program POM500.</p>
            </div>
            
            <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="space-y-2">
                    <label for="name" class="text-sm font-semibold text-gray-700">Nama Lengkap <span class="text-red-500">*</span></label>
                    <input type="text" name="name" id="name" value="<?php echo e(old('name', $beneficiary->name)); ?>" required
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                        placeholder="Masukkan nama lengkap">
                    <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-xs text-red-500"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <div class="space-y-2">
                    <label for="nik" class="text-sm font-semibold text-gray-700">NIK <span class="text-red-500">*</span></label>
                    <input type="text" name="nik" id="nik" value="<?php echo e(old('nik', $beneficiary->nik)); ?>" required
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition <?php $__errorArgs = ['nik'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> border-red-500 <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                        placeholder="16 digit NIK">
                    <?php $__errorArgs = ['nik'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <p class="text-xs text-red-500"><?php echo e($message); ?></p> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>

                <div class="md:col-span-2 space-y-2">
                    <label for="address" class="text-sm font-semibold text-gray-700">Alamat</label>
                    <textarea name="address" id="address" rows="3"
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="Alamat lengkap (Dusun/RT/RW)"><?php echo e(old('address', $beneficiary->address)); ?></textarea>
                </div>

                <div class="space-y-2">
                    <label for="district" class="text-sm font-semibold text-gray-700">Kecamatan <span class="text-red-500">*</span></label>
                    <select name="district" id="district" required
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition">
                        <option value="">Pilih Kecamatan</option>
                        <option value="Mamboro" <?php echo e(old('district', $beneficiary->district) == 'Mamboro' ? 'selected' : ''); ?>>Mamboro</option>
                        <option value="Katiku Tana" <?php echo e(old('district', $beneficiary->district) == 'Katiku Tana' ? 'selected' : ''); ?>>Katiku Tana</option>
                        <option value="Katiku Tana Selatan" <?php echo e(old('district', $beneficiary->district) == 'Katiku Tana Selatan' ? 'selected' : ''); ?>>Katiku Tana Selatan</option>
                        <option value="Umbu Ratu Nggay" <?php echo e(old('district', $beneficiary->district) == 'Umbu Ratu Nggay' ? 'selected' : ''); ?>>Umbu Ratu Nggay</option>
                        <option value="Umbu Ratu Nggay Barat" <?php echo e(old('district', $beneficiary->district) == 'Umbu Ratu Nggay Barat' ? 'selected' : ''); ?>>Umbu Ratu Nggay Barat</option>
                    </select>
                </div>

                <div class="space-y-2">
                    <label for="village" class="text-sm font-semibold text-gray-700">Desa <span class="text-red-500">*</span></label>
                    <input type="text" name="village" id="village" value="<?php echo e(old('village', $beneficiary->village)); ?>" required
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="Nama desa">
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Orang Tua Asuh</h3>
                <p class="text-sm text-gray-500 mt-1">Pejabat pendamping untuk penerima ini.</p>
            </div>
            
            <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="space-y-2">
                    <label for="foster_parent_name" class="text-sm font-semibold text-gray-700">Nama Pejabat</label>
                    <input type="text" name="foster_parent_name" id="foster_parent_name" value="<?php echo e(old('foster_parent_name', $beneficiary->foster_parent_name)); ?>"
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="Nama lengkap pejabat">
                </div>

                <div class="space-y-2">
                    <label for="foster_parent_role" class="text-sm font-semibold text-gray-700">Jabatan</label>
                    <input type="text" name="foster_parent_role" id="foster_parent_role" value="<?php echo e(old('foster_parent_role', $beneficiary->foster_parent_role)); ?>"
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="Contoh: Kadis Pertanian">
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Komponen Program - Hortikultura</h3>
                <p class="text-sm text-gray-500 mt-1">Detail bantuan hortikultura yang diterima penerima manfaat.</p>
            </div>
            
            <div id="horticulture-container" class="p-6 space-y-4">
                <!-- Horticulture items will be added here -->
                <?php $__currentLoopData = $beneficiary->horticultures; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $horticulture): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php echo $__env->make('beneficiaries.partials.horticulture_input', ['index' => $index, 'horticulture' => $horticulture], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php if(old('horticultures')): ?>
                    <?php $__currentLoopData = old('horticultures'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $horticulture): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if(!isset($horticulture['id'])): ?> 
                            <?php echo $__env->make('beneficiaries.partials.horticulture_input', ['index' => $index, 'horticulture' => $horticulture], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            </div>
            <div class="p-4 border-t border-gray-100">
                <button type="button" id="add-horticulture" class="w-full bg-gray-50 text-gray-600 py-2 rounded-lg text-sm font-medium hover:bg-gray-100 transition flex items-center justify-center">
                    <i class="fas fa-plus mr-2"></i> Tambah Hortikultura
                </button>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Komponen Program - Ternak</h3>
                <p class="text-sm text-gray-500 mt-1">Detail bantuan ternak yang diterima penerima manfaat.</p>
            </div>
            
            <div id="livestock-container" class="p-6 space-y-4">
                <!-- Livestock items will be added here -->
                <?php $__currentLoopData = $beneficiary->livestocks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $livestock): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php echo $__env->make('beneficiaries.partials.livestock_input', ['index' => $index, 'livestock' => $livestock], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php if(old('livestocks')): ?>
                    <?php $__currentLoopData = old('livestocks'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $livestock): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if(!isset($livestock['id'])): ?> 
                            <?php echo $__env->make('beneficiaries.partials.livestock_input', ['index' => $index, 'livestock' => $livestock], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            </div>
            <div class="p-4 border-t border-gray-100">
                <button type="button" id="add-livestock" class="w-full bg-gray-50 text-gray-600 py-2 rounded-lg text-sm font-medium hover:bg-gray-100 transition flex items-center justify-center">
                    <i class="fas fa-plus mr-2"></i> Tambah Ternak
                </button>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Komponen Program - Unggas</h3>
                <p class="text-sm text-gray-500 mt-1">Detail bantuan unggas yang diterima penerima manfaat.</p>
            </div>
            
            <div id="poultry-container" class="p-6 space-y-4">
                <!-- Poultry items will be added here -->
                <?php $__currentLoopData = $beneficiary->poultries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $poultry): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php echo $__env->make('beneficiaries.partials.poultry_input', ['index' => $index, 'poultry' => $poultry], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php if(old('poultries')): ?>
                    <?php $__currentLoopData = old('poultries'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $poultry): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if(!isset($poultry['id'])): ?> 
                            <?php echo $__env->make('beneficiaries.partials.poultry_input', ['index' => $index, 'poultry' => $poultry], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            </div>
            <div class="p-4 border-t border-gray-100">
                <button type="button" id="add-poultry" class="w-full bg-gray-50 text-gray-600 py-2 rounded-lg text-sm font-medium hover:bg-gray-100 transition flex items-center justify-center">
                    <i class="fas fa-plus mr-2"></i> Tambah Unggas
                </button>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Komponen Program - Perikanan</h3>
                <p class="text-sm text-gray-500 mt-1">Detail bantuan perikanan yang diterima penerima manfaat.</p>
            </div>
            
            <div id="fish-container" class="p-6 space-y-4">
                <!-- Fish items will be added here -->
                <?php $__currentLoopData = $beneficiary->fish; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $fish_item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php echo $__env->make('beneficiaries.partials.fish_input', ['index' => $index, 'fish_item' => $fish_item], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php if(old('fish')): ?>
                    <?php $__currentLoopData = old('fish'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $fish_item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if(!isset($fish_item['id'])): ?> 
                            <?php echo $__env->make('beneficiaries.partials.fish_input', ['index' => $index, 'fish_item' => $fish_item], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            </div>
            <div class="p-4 border-t border-gray-100">
                <button type="button" id="add-fish" class="w-full bg-gray-50 text-gray-600 py-2 rounded-lg text-sm font-medium hover:bg-gray-100 transition flex items-center justify-center">
                    <i class="fas fa-plus mr-2"></i> Tambah Perikanan
                </button>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
            <div class="p-6 border-b border-gray-100">
                <h3 class="text-lg font-semibold text-gray-800">Lokasi & Status</h3>
                <p class="text-sm text-gray-500 mt-1">Koordinat GPS dan status kepesertaan.</p>
            </div>
            
            <div class="p-6 grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="space-y-2">
                    <label for="latitude" class="text-sm font-semibold text-gray-700">Latitude</label>
                    <input type="number" step="any" name="latitude" id="latitude" value="<?php echo e(old('latitude', $beneficiary->latitude)); ?>"
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="-9.xxxxxx">
                </div>

                <div class="space-y-2">
                    <label for="longitude" class="text-sm font-semibold text-gray-700">Longitude</label>
                    <input type="number" step="any" name="longitude" id="longitude" value="<?php echo e(old('longitude', $beneficiary->longitude)); ?>"
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                        placeholder="119.xxxxxx">
                </div>

                <div class="space-y-2">
                    <label for="status" class="text-sm font-semibold text-gray-700">Status Program <span class="text-red-500">*</span></label>
                    <select name="status" id="status" required
                        class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition">
                        <option value="active" <?php echo e(old('status', $beneficiary->status) == 'active' ? 'selected' : ''); ?>>Aktif</option>
                        <option value="inactive" <?php echo e(old('status', $beneficiary->status) == 'inactive' ? 'selected' : ''); ?>>Tidak Aktif</option>
                        <option value="graduated" <?php echo e(old('status', $beneficiary->status) == 'graduated' ? 'selected' : ''); ?>>Mandiri (Graduated)</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="flex justify-end space-x-3">
            <button type="reset" class="px-6 py-2.5 border border-gray-200 text-gray-600 rounded-lg text-sm font-bold hover:bg-gray-50 transition">
                Reset
            </button>
            <button type="submit" class="px-8 py-2.5 bg-primary text-white rounded-lg text-sm font-bold hover:bg-sky-600 transition shadow-md shadow-blue-100">
                Simpan Perubahan
            </button>
        </div>
    </form>
</div>

<?php $__env->startSection('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        let horticultureIndex = <?php echo e(max($beneficiary->horticultures->count(), count(old('horticultures', [])))); ?>;
        let livestockIndex = <?php echo e(max($beneficiary->livestocks->count(), count(old('livestocks', [])))); ?>;
        let poultryIndex = <?php echo e(max($beneficiary->poultries->count(), count(old('poultries', [])))); ?>;
        let fishIndex = <?php echo e(max($beneficiary->fish->count(), count(old('fish', [])))); ?>;

        document.getElementById('add-horticulture').addEventListener('click', () => {
            addHorticulture(horticultureIndex++);
        });

        document.getElementById('add-livestock').addEventListener('click', () => {
            addLivestock(livestockIndex++);
        });

        document.getElementById('add-poultry').addEventListener('click', () => {
            addPoultry(poultryIndex++);
        });

        document.getElementById('add-fish').addEventListener('click', () => {
            addFish(fishIndex++);
        });

        function addHorticulture(index, horticulture = {}) {
            const container = document.getElementById('horticulture-container');
            const template = `
                <div class="horticulture-item p-4 border border-gray-200 rounded-lg relative">
                    <button type="button" class="remove-horticulture absolute top-2 right-2 text-gray-400 hover:text-red-500">
                        <i class="fas fa-times-circle"></i>
                    </button>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="space-y-2">
                            <label for="horticultures_${index}_type" class="text-sm font-semibold text-gray-700">Tipe Budidaya</label>
                            <input type="text" name="horticultures[${index}][type]" id="horticultures_${index}_type" value="${horticulture.type || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: Sayuran, Buah">
                        </div>
                        <div class="space-y-2">
                            <label for="horticultures_${index}_commodity" class="text-sm font-semibold text-gray-700">Komoditas</label>
                            <input type="text" name="horticultures[${index}][commodity]" id="horticultures_${index}_commodity" value="${horticulture.commodity || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: Cabe, Tomat">
                        </div>
                        <div class="space-y-2">
                            <label for="horticultures_${index}_quantity" class="text-sm font-semibold text-gray-700">Jumlah/Luas (Are)</label>
                            <input type="text" name="horticultures[${index}][quantity]" id="horticultures_${index}_quantity" value="${horticulture.quantity || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: 50 (polybag), 0.5 (are)">
                        </div>
                    </div>
                    <input type="hidden" name="horticultures[${index}][id]" value="${horticulture.id || ''}">
                </div>
            `;
            container.insertAdjacentHTML('beforeend', template);
            container.lastElementChild.querySelector('.remove-horticulture').addEventListener('click', function() {
                this.closest('.horticulture-item').remove();
            });
        }

        function addLivestock(index, livestock = {}) {
            const container = document.getElementById('livestock-container');
            const template = `
                <div class="livestock-item p-4 border border-gray-200 rounded-lg relative">
                    <button type="button" class="remove-livestock absolute top-2 right-2 text-gray-400 hover:text-red-500">
                        <i class="fas fa-times-circle"></i>
                    </button>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="space-y-2">
                            <label for="livestocks_${index}_type" class="text-sm font-semibold text-gray-700">Jenis Ternak</label>
                            <input type="text" name="livestocks[${index}][type]" id="livestocks_${index}_type" value="${livestock.type || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: Kambing, Sapi">
                        </div>
                        <div class="space-y-2">
                            <label for="livestocks_${index}_male_count" class="text-sm font-semibold text-gray-700">Jumlah Jantan</label>
                            <input type="number" name="livestocks[${index}][male_count]" id="livestocks_${index}_male_count" value="${livestock.male_count || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Jumlah ternak jantan">
                        </div>
                        <div class="space-y-2">
                            <label for="livestocks_${index}_female_count" class="text-sm font-semibold text-gray-700">Jumlah Betina</label>
                            <input type="number" name="livestocks[${index}][female_count]" id="livestocks_${index}_female_count" value="${livestock.female_count || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Jumlah ternak betina">
                        </div>
                    </div>
                    <input type="hidden" name="livestocks[${index}][id]" value="${livestock.id || ''}">
                </div>
            `;
            container.insertAdjacentHTML('beforeend', template);
            container.lastElementChild.querySelector('.remove-livestock').addEventListener('click', function() {
                this.closest('.livestock-item').remove();
            });
        }

        function addPoultry(index, poultry = {}) {
            const container = document.getElementById('poultry-container');
            const template = `
                <div class="poultry-item p-4 border border-gray-200 rounded-lg relative">
                    <button type="button" class="remove-poultry absolute top-2 right-2 text-gray-400 hover:text-red-500">
                        <i class="fas fa-times-circle"></i>
                    </button>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="space-y-2">
                            <label for="poultries_${index}_type" class="text-sm font-semibold text-gray-700">Jenis Unggas</label>
                            <input type="text" name="poultries[${index}][type]" id="poultries_${index}_type" value="${poultry.type || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: Ayam, Bebek">
                        </div>
                        <div class="space-y-2">
                            <label for="poultries_${index}_quantity" class="text-sm font-semibold text-gray-700">Jumlah</label>
                            <input type="text" name="poultries[${index}][quantity]" id="poultries_${index}_quantity" value="${poultry.quantity || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Jumlah unggas">
                        </div>
                        <div class="space-y-2">
                            <label for="poultries_${index}_distribution_date" class="text-sm font-semibold text-gray-700">Tanggal Distribusi</label>
                            <input type="date" name="poultries[${index}][distribution_date]" id="poultries_${index}_distribution_date" value="${poultry.distribution_date || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition">
                        </div>
                    </div>
                    <input type="hidden" name="poultries[${index}][id]" value="${poultry.id || ''}">
                </div>
            `;
            container.insertAdjacentHTML('beforeend', template);
            container.lastElementChild.querySelector('.remove-poultry').addEventListener('click', function() {
                this.closest('.poultry-item').remove();
            });
        }

        function addFish(index, fish_item = {}) {
            const container = document.getElementById('fish-container');
            const template = `
                <div class="fish-item p-4 border border-gray-200 rounded-lg relative">
                    <button type="button" class="remove-fish absolute top-2 right-2 text-gray-400 hover:text-red-500">
                        <i class="fas fa-times-circle"></i>
                    </button>
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div class="space-y-2">
                            <label for="fish_${index}_type" class="text-sm font-semibold text-gray-700">Jenis Ikan</label>
                            <input type="text" name="fish[${index}][type]" id="fish_${index}_type" value="${fish_item.type || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Contoh: Lele, Nila">
                        </div>
                        <div class="space-y-2">
                            <label for="fish_${index}_quantity" class="text-sm font-semibold text-gray-700">Jumlah</label>
                            <input type="text" name="fish[${index}][quantity]" id="fish_${index}_quantity" value="${fish_item.quantity || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition"
                                placeholder="Jumlah ikan">
                        </div>
                        <div class="space-y-2">
                            <label for="fish_${index}_distribution_date" class="text-sm font-semibold text-gray-700">Tanggal Distribusi</label>
                            <input type="date" name="fish[${index}][distribution_date]" id="fish_${index}_distribution_date" value="${fish_item.distribution_date || ''}"
                                class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:ring-2 focus:ring-primary/20 focus:border-primary outline-none transition">
                        </div>
                    </div>
                    <input type="hidden" name="fish[${index}][id]" value="${fish_item.id || ''}">
                </div>
            `;
            container.insertAdjacentHTML('beforeend', template);
            container.lastElementChild.querySelector('.remove-fish').addEventListener('click', function() {
                this.closest('.fish-item').remove();
            });
        }

        // Attach event listeners to existing remove buttons
        document.querySelectorAll('.remove-horticulture').forEach(button => {
            button.addEventListener('click', function() {
                this.closest('.horticulture-item').remove();
            });
        });
        document.querySelectorAll('.remove-livestock').forEach(button => {
            button.addEventListener('click', function() {
                this.closest('.livestock-item').remove();
            });
        });
        document.querySelectorAll('.remove-poultry').forEach(button => {
            button.addEventListener('click', function() {
                this.closest('.poultry-item').remove();
            });
        });
        document.querySelectorAll('.remove-fish').forEach(button => {
            button.addEventListener('click', function() {
                this.closest('.fish-item').remove();
            });
        });
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/sumba001/public_html/pom500.sumbatengahkab.go.id/resources/views/beneficiaries/edit.blade.php ENDPATH**/ ?>