<?php $__env->startSection('title', 'Data KK & Mustahik'); ?>
<?php $__env->startSection('topbar_title', 'Data Warga — ' . (Auth::user()->wilayah ? 'RT ' . str_pad(Auth::user()->wilayah->rt, 2, '0', STR_PAD_LEFT) . ' / RW ' . str_pad(Auth::user()->wilayah->rw, 2, '0', STR_PAD_LEFT) : 'Wilayah Belum Diatur')); ?>

<?php $__env->startSection('content'); ?>


<div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:16px;">
    <div style="display:flex; align-items:center; gap:12px;">
        <div style="width:36px; height:36px; background:var(--green-light); border-radius:8px; display:flex; align-items:center; justify-content:center; color:var(--green-primary); font-size:18px;">
            <i class="bi bi-file-earmark-person-fill"></i>
        </div>
        <h2 style="font-size:18px; font-weight:700; color:var(--text-dark); margin:0;">Data Kartu Keluarga (KK)</h2>
    </div>
    <button class="btn-primary-green" onclick="document.getElementById('modalKk').style.display='flex'">
        <i class="bi bi-plus-lg"></i> Tambah KK Baru
    </button>
</div>

<div class="card" style="margin-bottom:40px;">
    <table class="data-table">
        <thead>
            <tr>
                <th style="width:50px;">No</th>
                <th>NIK Kepala KK</th>
                <th>Nama Kepala KK</th>
                <th>Alamat Rumah</th>
                <th>Tanggungan</th>
                <th style="text-align:right;">Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $dataKk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $kk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
                <td style="color:var(--text-muted);"><?php echo e($dataKk->firstItem() + $i); ?></td>
                <td style="font-size:13px; color:var(--text-muted); font-weight:500;"><?php echo e($kk->nik_kepala_kk); ?></td>
                <td style="font-weight:600; font-size:13.5px;"><?php echo e($kk->nama_kepala_kk); ?></td>
                <td style="font-size:13px; color:var(--text-muted);"><?php echo e(Str::limit($kk->alamat_rumah, 40)); ?></td>
                <td style="font-size:13px; font-weight:600;"><?php echo e($kk->jumlah_tanggungan); ?></td>
                <td style="text-align:right;">
                    <button class="action-icon-btn" onclick='openEditKkModal(<?php echo json_encode($kk, 15, 512) ?>)'><i class="bi bi-pencil"></i></button>
                    <button class="action-icon-btn del" style="color:#ef4444;"><i class="bi bi-trash"></i></button>
                </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
                <td colspan="6" style="text-align:center; padding:32px; color:var(--text-muted);">
                    Belum ada data Kartu Keluarga (KK) terdaftar.
                </td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
    
    <?php if($dataKk->hasPages()): ?>
    <div class="pagination-wrap">
        <span>Menampilkan <?php echo e($dataKk->firstItem() ?? 0); ?>-<?php echo e($dataKk->lastItem() ?? 0); ?> dari <?php echo e($dataKk->total()); ?> data KK</span>
        <div class="pagination-btns">
            <?php if($dataKk->onFirstPage()): ?>
                <button class="page-btn" disabled><i class="bi bi-chevron-left"></i></button>
            <?php else: ?>
                <a href="<?php echo e($dataKk->appends(request()->except('kk_page'))->previousPageUrl()); ?>" class="page-btn"><i class="bi bi-chevron-left"></i></a>
            <?php endif; ?>
            <?php if($dataKk->hasMorePages()): ?>
                <a href="<?php echo e($dataKk->appends(request()->except('kk_page'))->nextPageUrl()); ?>" class="page-btn"><i class="bi bi-chevron-right"></i></a>
            <?php else: ?>
                <button class="page-btn" disabled><i class="bi bi-chevron-right"></i></button>
            <?php endif; ?>
        </div>
    </div>
    <?php endif; ?>
</div>



<div style="text-align:center; position:relative; margin-bottom:40px;">
    <div style="position:absolute; left:0; top:50%; width:100%; height:1px; background:var(--border-color); z-index:1;"></div>
    <span style="background:var(--bg-page); padding:0 20px; font-size:16px; font-weight:700; color:var(--green-primary); position:relative; z-index:2;">
        Daftar Mustahik (Penerima Zakat)
    </span>
</div>



<div style="background:linear-gradient(to bottom, #e8f5ee 0%, #ffffff 100%); padding:20px; border-radius:var(--radius); border:1px solid var(--border-color); margin-bottom:20px;">
    
    <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:16px;">
        <div style="display:flex; align-items:center; gap:12px;">
            <div style="width:36px; height:36px; background:var(--green-primary); border-radius:8px; display:flex; align-items:center; justify-content:center; color:white; font-size:16px;">
                <i class="bi bi-people-fill"></i>
            </div>
            <h2 style="font-size:16px; font-weight:700; color:var(--green-primary); margin:0;">Data Mustahik</h2>
        </div>
        
        <div style="display:flex; gap:12px; align-items:center;">
            <form method="GET" action="<?php echo e(url('/rt/data-warga')); ?>" style="display:flex; align-items:center; gap:8px;">
                <span style="font-size:12px; font-weight:600; color:var(--text-muted);">Filter KK:</span>
                <div class="select-wrap" style="width:200px;">
                    <select name="filter_kk" class="form-ctrl" onchange="this.form.submit()" style="padding:8px 12px; font-size:13px; background:white;">
                        <option value="">Semua KK</option>
                        <?php $__currentLoopData = $listKk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($kk->id_kk); ?>" <?php echo e(request('filter_kk') == $kk->id_kk ? 'selected' : ''); ?>>
                                <?php echo e($kk->nama_kepala_kk); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            </form>
            <button class="btn-primary-green" onclick="document.getElementById('modalMustahik').style.display='flex'">
                <i class="bi bi-person-plus-fill"></i> Tambah Mustahik
            </button>
        </div>
    </div>

    <div class="card">
        <table class="data-table">
            <thead>
                <tr>
                    <th style="width:50px;">No</th>
                    <th>Nama Mustahik</th>
                    <th>NIK KK</th>
                    <th>Hubungan</th>
                    <th>Kategori Asnaf</th>
                    <th>Status</th>
                    <th style="text-align:right;">Aksi</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $dataMustahik; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $m): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td style="color:var(--text-muted);"><?php echo e($dataMustahik->firstItem() + $i); ?></td>
                    <td style="font-weight:600; font-size:13.5px;"><?php echo e($m->nama_mustahik); ?></td>
                    <td style="font-size:13px; color:var(--text-muted); font-weight:500;">
                        <?php echo e($m->kk->nik_kepala_kk ?? '-'); ?>

                    </td>
                    <td style="font-size:13px; color:var(--text-dark);"><?php echo e($m->hub_dengan_kk ?: 'Kepala Keluarga'); ?></td>
                    <td style="font-size:13px;"><?php echo e($m->kategori_asnaf); ?></td>
                    <td>
                        <?php if($m->status == 'Disetujui'): ?>
                            <span class="badge-pill" style="border:1px solid #86efac; color:#16a34a; padding:4px 12px; border-radius:20px; font-size:11px;">Disetujui</span>
                        <?php elseif($m->status == 'Ditolak'): ?>
                            <span class="badge-pill" style="background:#fee2e2; color:#b91c1c; padding:4px 12px; border-radius:20px; font-size:11px;">Ditolak</span>
                        <?php else: ?>
                            <span class="badge-pill" style="background:#ffedd5; color:#c2410c; padding:4px 12px; border-radius:20px; font-size:11px;">Pending</span>
                        <?php endif; ?>
                    </td>
                    <td style="text-align:right;">
                        <?php if($m->status == 'Ditolak'): ?>
                            <button class="btn-outline" style="font-size:11.5px; padding:6px 10px;">Ajukan Ulang</button>
                        <?php elseif($m->status == 'Pending'): ?>
                            <button class="action-icon-btn edit" style="font-size:12px; color:var(--text-muted);" onclick='openEditMustahikModal(<?php echo json_encode($m, 15, 512) ?>)'><i class="bi bi-pencil"></i> Edit</button>
                        <?php else: ?>
                            <button class="btn-outline-green" style="font-size:11.5px; padding:6px 10px;">Lihat Detail</button>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr>
                    <td colspan="7" style="text-align:center; padding:32px; color:var(--text-muted);">
                        Belum ada pengajuan mustahik untuk wilayah ini.
                    </td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
        
        <?php if($dataMustahik->hasPages()): ?>
        <div class="pagination-wrap">
            <span>Menampilkan <?php echo e($dataMustahik->firstItem() ?? 0); ?>-<?php echo e($dataMustahik->lastItem() ?? 0); ?> dari <?php echo e($dataMustahik->total()); ?> data Mustahik</span>
            <div class="pagination-btns">
                <?php if($dataMustahik->onFirstPage()): ?>
                    <button class="page-btn" disabled><i class="bi bi-chevron-left"></i></button>
                <?php else: ?>
                    <a href="<?php echo e($dataMustahik->appends(request()->except('mustahik_page'))->previousPageUrl()); ?>" class="page-btn"><i class="bi bi-chevron-left"></i></a>
                <?php endif; ?>
                <?php if($dataMustahik->hasMorePages()): ?>
                    <a href="<?php echo e($dataMustahik->appends(request()->except('mustahik_page'))->nextPageUrl()); ?>" class="page-btn"><i class="bi bi-chevron-right"></i></a>
                <?php else: ?>
                    <button class="page-btn" disabled><i class="bi bi-chevron-right"></i></button>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>


<div id="modalKk" class="modal-overlay">
    <div class="modal-content">
        <div class="modal-header">
            <h3 style="font-size:18px; font-weight:700;">Tambah Data KK Baru</h3>
            <button type="button" class="btn-close-modal" onclick="document.getElementById('modalKk').style.display='none'"><i class="bi bi-x-lg"></i></button>
        </div>
        <form action="<?php echo e(url('/rt/kk/store')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">NIK Kepala Keluarga</label>
                    <input type="text" name="nik_kepala_kk" class="form-ctrl" required>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Nama Kepala Keluarga</label>
                    <input type="text" name="nama_kepala_kk" class="form-ctrl" required>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Alamat Rumah Lengkap</label>
                    <textarea name="alamat_rumah" class="form-ctrl" rows="3" required></textarea>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Jumlah Tanggungan</label>
                    <input type="number" name="jumlah_tanggungan" class="form-ctrl" min="0" value="0" required>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn-outline" onclick="document.getElementById('modalKk').style.display='none'">Batal</button>
                <button type="submit" class="btn-primary-green">Simpan Data KK</button>
            </div>
        </form>
    </div>
</div>


<div id="modalMustahik" class="modal-overlay">
    <div class="modal-content">
        <div class="modal-header">
            <h3 style="font-size:18px; font-weight:700;">Ajukan Mustahik Baru</h3>
            <button type="button" class="btn-close-modal" onclick="document.getElementById('modalMustahik').style.display='none'"><i class="bi bi-x-lg"></i></button>
        </div>
        <form action="<?php echo e(url('/rt/mustahik/store')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Pilih Kartu Keluarga (KK)</label>
                    <div class="select-wrap">
                        <select name="id_kk" class="form-ctrl" required>
                            <option value="">-- Pilih KK --</option>
                            <?php $__currentLoopData = $listKk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $kk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($kk->id_kk); ?>"><?php echo e($kk->nama_kepala_kk); ?> (<?php echo e($kk->nik_kepala_kk); ?>)</option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Nama Mustahik</label>
                        <input type="text" name="nama_mustahik" class="form-ctrl" required>
                    </div>
                    <div>
                        <label class="form-label-styled">NIK Mustahik</label>
                        <input type="text" name="nik_kepala_kk" class="form-ctrl" required>
                    </div>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Hubungan dengan KK</label>
                        <input type="text" name="hub_dengan_kk" class="form-ctrl" placeholder="Misal: Kepala Keluarga, Istri, Anak" required>
                    </div>
                    <div>
                        <label class="form-label-styled">Pekerjaan</label>
                        <input type="text" name="pekerjaan" class="form-ctrl" required>
                    </div>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Pendapatan Bulanan (Rp)</label>
                    <input type="text" name="pendapatan_bulanan" id="pendapatan_bulanan_modal" class="form-ctrl" placeholder="Rp. 0" required>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Kondisi Warga</label>
                        <div class="select-wrap">
                            <select name="status_kondisi_warga" class="form-ctrl" required>
                                <option value="Tidak Mampu">Tidak Mampu</option>
                                <option value="Mampu">Mampu</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="form-label-styled">Status Rumah</label>
                        <div class="select-wrap">
                            <select name="status_kepemilikan_rumah" class="form-ctrl" required>
                                <option value="Sewa">Sewa</option>
                                <option value="Milik Sendiri">Milik Sendiri</option>
                                <option value="Menumpang">Menumpang</option>
                                <option value="Lainnya">Lainnya</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="form-label-styled">Kategori Asnaf</label>
                        <div class="select-wrap">
                            <select name="kategori_asnaf" class="form-ctrl" required>
                                <option value="Fakir">Fakir</option>
                                <option value="Miskin">Miskin</option>
                                <option value="Gharim">Gharim</option>
                                <option value="Ibnu Sabil">Ibnu Sabil</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn-outline" onclick="document.getElementById('modalMustahik').style.display='none'">Batal</button>
                <button type="submit" class="btn-primary-green">Kirim Pengajuan ke Amil</button>
            </div>
        </form>
    </div>
</div>


<div id="modalEditKk" class="modal-overlay">
    <div class="modal-content">
        <div class="modal-header">
            <h3 style="font-size:18px; font-weight:700;">Edit Data KK</h3>
            <button type="button" class="btn-close-modal" onclick="document.getElementById('modalEditKk').style.display='none'"><i class="bi bi-x-lg"></i></button>
        </div>
        <form id="formEditKk" method="POST">
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">NIK Kepala Keluarga</label>
                    <input type="text" name="nik_kepala_kk" id="edit_kk_nik" class="form-ctrl" required>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Nama Kepala Keluarga</label>
                    <input type="text" name="nama_kepala_kk" id="edit_kk_nama" class="form-ctrl" required>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Alamat Rumah Lengkap</label>
                    <textarea name="alamat_rumah" id="edit_kk_alamat" class="form-ctrl" rows="3" required></textarea>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Jumlah Tanggungan</label>
                    <input type="number" name="jumlah_tanggungan" id="edit_kk_tanggungan" class="form-ctrl" min="0" required>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn-outline" onclick="document.getElementById('modalEditKk').style.display='none'">Batal</button>
                <button type="submit" class="btn-primary-green">Simpan Perubahan</button>
            </div>
        </form>
    </div>
</div>


<div id="modalEditMustahik" class="modal-overlay">
    <div class="modal-content">
        <div class="modal-header">
            <h3 style="font-size:18px; font-weight:700;">Edit Pengajuan Mustahik</h3>
            <button type="button" class="btn-close-modal" onclick="document.getElementById('modalEditMustahik').style.display='none'"><i class="bi bi-x-lg"></i></button>
        </div>
        <form id="formEditMustahik" method="POST">
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div style="display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Nama Mustahik</label>
                        <input type="text" name="nama_mustahik" id="edit_m_nama" class="form-ctrl" required>
                    </div>
                    <div>
                        <label class="form-label-styled">NIK Mustahik</label>
                        <input type="text" name="nik_kepala_kk" id="edit_m_nik" class="form-ctrl" required>
                    </div>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Hubungan dengan KK</label>
                        <input type="text" name="hub_dengan_kk" id="edit_m_hub" class="form-ctrl" required>
                    </div>
                    <div>
                        <label class="form-label-styled">Pekerjaan</label>
                        <input type="text" name="pekerjaan" id="edit_m_pekerjaan" class="form-ctrl" required>
                    </div>
                </div>
                <div style="margin-bottom:14px;">
                    <label class="form-label-styled">Pendapatan Bulanan (Rp)</label>
                    <input type="text" name="pendapatan_bulanan" id="edit_m_pendapatan" class="form-ctrl" required>
                </div>
                <div style="display:grid; grid-template-columns:1fr 1fr 1fr; gap:14px; margin-bottom:14px;">
                    <div>
                        <label class="form-label-styled">Kondisi Warga</label>
                        <div class="select-wrap">
                            <select name="status_kondisi_warga" id="edit_m_kondisi" class="form-ctrl" required>
                                <option value="Tidak Mampu">Tidak Mampu</option>
                                <option value="Mampu">Mampu</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="form-label-styled">Status Rumah</label>
                        <div class="select-wrap">
                            <select name="status_kepemilikan_rumah" id="edit_m_rumah" class="form-ctrl" required>
                                <option value="Sewa">Sewa</option>
                                <option value="Milik Sendiri">Milik Sendiri</option>
                                <option value="Menumpang">Menumpang</option>
                                <option value="Lainnya">Lainnya</option>
                            </select>
                        </div>
                    </div>
                    <div>
                        <label class="form-label-styled">Kategori Asnaf</label>
                        <div class="select-wrap">
                            <select name="kategori_asnaf" id="edit_m_asnaf" class="form-ctrl" required>
                                <option value="Fakir">Fakir</option>
                                <option value="Miskin">Miskin</option>
                                <option value="Gharim">Gharim</option>
                                <option value="Ibnu Sabil">Ibnu Sabil</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn-outline" onclick="document.getElementById('modalEditMustahik').style.display='none'">Batal</button>
                <button type="submit" class="btn-primary-green">Simpan Perubahan</button>
            </div>
        </form>
    </div>
</div>

<style>
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 999;
    display: none; align-items: center; justify-content: center;
}
.modal-content {
    background: white; width: 100%; max-width: 600px;
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
    padding: 18px 24px; border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between;
}
.btn-close-modal {
    background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer;
}
.btn-close-modal:hover { color: #ef4444; }
.modal-body {
    padding: 24px; overflow-y: auto;
}
.modal-footer {
    padding: 16px 24px; border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 12px; background: var(--bg-page);
    border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius);
}

.action-icon-btn {
    background: none; border: none; cursor: pointer;
    font-size: 14px; color: var(--text-muted); transition: color .15s;
    padding: 4px 6px; display: inline-flex; align-items: center; justify-content: center;
}
.action-icon-btn:hover { color: var(--text-dark); }
.action-icon-btn.edit:hover { color: var(--green-primary); }
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
    var rupiah = document.getElementById('pendapatan_bulanan_modal');
    if (rupiah) {
        rupiah.addEventListener('keyup', function(e){
            rupiah.value = formatRupiah(this.value, 'Rp. ');
        });
    }

    function formatRupiah(angka, prefix){
        var number_string = angka.replace(/[^,\d]/g, '').toString(),
        split           = number_string.split(','),
        sisa            = split[0].length % 3,
        rupiah          = split[0].substr(0, sisa),
        ribuan          = split[0].substr(sisa).match(/\d{3}/gi);

        if(ribuan){
            separator = sisa ? '.' : '';
            rupiah += separator + ribuan.join('.');
        }

        rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
        return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
    }

    // Handle Format Rupiah for Edit Mustahik Modal
    var rupiahEdit = document.getElementById('edit_m_pendapatan');
    if (rupiahEdit) {
        rupiahEdit.addEventListener('keyup', function(e){
            rupiahEdit.value = formatRupiah(this.value, 'Rp. ');
        });
    }
});

function openEditKkModal(data) {
    document.getElementById('formEditKk').action = '/rt/kk/update/' + data.id_kk;
    document.getElementById('edit_kk_nik').value = data.nik_kepala_kk;
    document.getElementById('edit_kk_nama').value = data.nama_kepala_kk;
    document.getElementById('edit_kk_alamat').value = data.alamat_rumah;
    document.getElementById('edit_kk_tanggungan').value = data.jumlah_tanggungan;
    document.getElementById('modalEditKk').style.display = 'flex';
}

function openEditMustahikModal(data) {
    document.getElementById('formEditMustahik').action = '/rt/mustahik/update/' + data.id_mustahik;
    document.getElementById('edit_m_nama').value = data.nama_mustahik;
    document.getElementById('edit_m_nik').value = data.nik_kepala_kk;
    document.getElementById('edit_m_hub').value = data.hub_dengan_kk;
    document.getElementById('edit_m_pekerjaan').value = data.pekerjaan;
    
    // Format Rupiah manually for initial value
    var valStr = data.pendapatan_bulanan.toString().replace(/\.00$/, ''); // remove .00 if exists
    document.getElementById('edit_m_pendapatan').value = 'Rp. ' + valStr.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
    
    document.getElementById('edit_m_kondisi').value = data.status_kondisi_warga;
    document.getElementById('edit_m_rumah').value = data.status_kepemilikan_rumah;
    document.getElementById('edit_m_asnaf').value = data.kategori_asnaf;
    document.getElementById('modalEditMustahik').style.display = 'flex';
}
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make(Auth::user()->int_role == 'superadmin' ? 'layouts.superadmin' : 'layouts.rt', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\Skripsi\zakat-masjid\resources\views/rt/data_warga.blade.php ENDPATH**/ ?>