<?php $__env->startSection('title', 'Kelola Wilayah'); ?>
<?php $__env->startSection('topbar_title', 'Kelola Wilayah'); ?>

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

<div class="page-header">
    <div class="page-header-left">
        <h1>Data Wilayah / RT</h1>
    </div>
    <a href="<?php echo e(url('/admin/wilayah/create')); ?>" class="btn-primary-green">
        <i class="bi bi-plus-lg"></i> Tambah Wilayah
    </a>
</div>

<div class="card">
    <table class="data-table">
        <thead>
            <tr>
                <th style="width:50px;">No</th>
                <th>Nama Wilayah/Alamat</th>
                <th style="width:80px;">RT</th>
                <th style="width:80px;">RW</th>
                <th>Ketua RT yang Bertugas</th>
                <th style="width:110px;">Jumlah KK</th>
                <th style="width:100px;">Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $wilayah; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $w): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
                <td style="color:var(--text-muted);"><?php echo e($i + 1); ?></td>
                <td style="font-weight:500;"><?php echo e($w->nama_wilayah); ?></td>
                <td><?php echo e(str_pad($w->rt, 2, '0', STR_PAD_LEFT)); ?></td>
                <td><?php echo e(str_pad($w->rw, 2, '0', STR_PAD_LEFT)); ?></td>
                <td>
                    <?php
                        $ketuaRT = $w->users->where('int_role', 'rt')->first();
                    ?>
                    <?php if($ketuaRT): ?>
                        <div style="display:flex; align-items:center; gap:8px;">
                            <div class="avatar-initial" style="width:28px;height:28px;font-size:10px;">
                                <?php echo e(strtoupper(substr($ketuaRT->nama_user, 0, 2))); ?>

                            </div>
                            <span><?php echo e($ketuaRT->nama_user); ?></span>
                        </div>
                    <?php else: ?>
                        <span style="color:var(--text-muted); font-style:italic; font-size:13px;">Belum di-assign</span>
                    <?php endif; ?>
                </td>
                <td>
                    <?php if($w->dataKKs->count() > 0): ?>
                        <span style="font-weight:600;"><?php echo e($w->dataKKs->count()); ?></span>
                    <?php else: ?>
                        <span style="color:var(--text-muted);">-</span>
                    <?php endif; ?>
                </td>
                <td>
                    <div style="display:flex; align-items:center; gap:4px;">
                        <a href="<?php echo e(url('/admin/wilayah/edit/' . $w->id_wilayah)); ?>" class="action-icon-btn edit" title="Edit">
                            <i class="bi bi-pencil-fill"></i>
                        </a>
                        <form action="<?php echo e(url('/admin/wilayah/destroy/' . $w->id_wilayah)); ?>" method="POST" style="display:inline;">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="action-icon-btn del" title="Hapus"
                                onclick="return confirm('Hapus wilayah <?php echo e($w->nama_wilayah); ?>?')">
                                <i class="bi bi-trash3-fill"></i>
                            </button>
                        </form>
                    </div>
                </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
                <td colspan="7" style="text-align:center; padding:40px; color:var(--text-muted);">
                    <i class="bi bi-map" style="font-size:36px; display:block; margin-bottom:10px;"></i>
                    Belum ada data wilayah. Klik "Tambah Wilayah" untuk menambahkan.
                </td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
    <div class="pagination-wrap">
        <span>Menampilkan 1 hingga <?php echo e($wilayah->count()); ?> dari <?php echo e($wilayah->count()); ?> data</span>
        <div class="pagination-btns">
            <button class="page-btn" disabled><i class="bi bi-chevron-left"></i></button>
            <button class="page-btn active">1</button>
            <button class="page-btn" disabled><i class="bi bi-chevron-right"></i></button>
        </div>
    </div>
</div>

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

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