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

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

<div class="page-header">
    <div class="page-header-left">
        <h1>Manajemen Pengguna Masjid</h1>
    </div>
    <a href="<?php echo e(url('/admin/user/create')); ?>" class="btn-primary-green">
        <i class="bi bi-plus-lg"></i> Tambah Amil
    </a>
</div>


<div class="tab-list">
    <button class="tab-btn <?php echo e($activeTab === 'amil' ? 'active' : ''); ?>" onclick="switchTab('amil')">Amil</button>
    <button class="tab-btn <?php echo e($activeTab === 'rt' ? 'active' : ''); ?>" onclick="switchTab('rt')">Ketua RT</button>
</div>


<div id="tab-amil" class="card" style="<?php echo e($activeTab !== 'amil' ? 'display:none;' : ''); ?>">
    <table class="data-table">
        <thead>
            <tr>
                <th>No</th>
                <th>Nama</th>
                <th>Username</th>
                <th>No HP</th>
                <th>Status Aktif</th>
                <th>Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $amils; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
                <td style="color:var(--text-muted); width:50px;"><?php echo e($i + 1); ?></td>
                <td>
                    <div style="display:flex; align-items:center; gap:10px;">
                        <div class="avatar-initial"><?php echo e(strtoupper(substr($u->nama_user, 0, 2))); ?></div>
                        <span style="font-weight:500;"><?php echo e($u->nama_user); ?></span>
                    </div>
                </td>
                <td style="color:var(--text-muted);"><?php echo e($u->username); ?></td>
                <td><?php echo e($u->no_hp ?? '-'); ?></td>
                <td>
                    <form action="<?php echo e(url('/admin/user/toggle/' . $u->id_user)); ?>" method="POST" style="display:inline;">
                        <?php echo csrf_field(); ?>
                        <label class="toggle-switch">
                            <input type="checkbox" <?php echo e($u->status_aktif ? 'checked' : ''); ?> onchange="this.form.submit()">
                            <span class="toggle-slider"></span>
                        </label>
                    </form>
                </td>
                <td>
                    <div style="position:relative; display:inline-block;">
                        <button class="action-dots" onclick="toggleDrop(this)">
                            <i class="bi bi-three-dots-vertical"></i>
                        </button>
                        <div class="dropdown-menu-custom">
                            <a href="<?php echo e(url('/admin/user/edit/' . $u->id_user)); ?>">
                                <i class="bi bi-pencil-square"></i> Edit Akun
                            </a>
                            <form action="<?php echo e(url('/admin/user/destroy/' . $u->id_user)); ?>" method="POST">
                                <?php echo csrf_field(); ?>
                                <button type="submit" class="del-item"
                                    onclick="return confirm('Hapus akun <?php echo e($u->nama_user); ?>?')">
                                    <i class="bi bi-trash3"></i> Hapus Akun
                                </button>
                            </form>
                        </div>
                    </div>
                </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);">
                    <i class="bi bi-inbox" style="font-size:32px; display:block; margin-bottom:8px;"></i>
                    Belum ada Amil yang terdaftar.
                </td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
    <div class="pagination-wrap">
        <span>Menampilkan <?php echo e($amils->count()); ?> data Amil</span>
    </div>
</div>


<div id="tab-rt" class="card" style="<?php echo e($activeTab !== 'rt' ? 'display:none;' : ''); ?>">
    <table class="data-table">
        <thead>
            <tr>
                <th>No</th>
                <th>Nama</th>
                <th>Username</th>
                <th>No HP</th>
                <th>Status Aktif</th>
                <th>Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $rts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
                <td style="color:var(--text-muted); width:50px;"><?php echo e($i + 1); ?></td>
                <td>
                    <div style="display:flex; align-items:center; gap:10px;">
                        <div class="avatar-initial"><?php echo e(strtoupper(substr($u->nama_user, 0, 2))); ?></div>
                        <span style="font-weight:500;"><?php echo e($u->nama_user); ?></span>
                    </div>
                </td>
                <td style="color:var(--text-muted);"><?php echo e($u->username); ?></td>
                <td><?php echo e($u->no_hp ?? '-'); ?></td>
                <td>
                    <form action="<?php echo e(url('/admin/user/toggle/' . $u->id_user)); ?>" method="POST" style="display:inline;">
                        <?php echo csrf_field(); ?>
                        <label class="toggle-switch">
                            <input type="checkbox" <?php echo e($u->status_aktif ? 'checked' : ''); ?> onchange="this.form.submit()">
                            <span class="toggle-slider"></span>
                        </label>
                    </form>
                </td>
                <td>
                    <div style="position:relative; display:inline-block;">
                        <button class="action-dots" onclick="toggleDrop(this)">
                            <i class="bi bi-three-dots-vertical"></i>
                        </button>
                        <div class="dropdown-menu-custom">
                            <a href="<?php echo e(url('/admin/user/edit/' . $u->id_user)); ?>" class="dropdown-item-custom">
                                <i class="bi bi-pencil-square"></i> Edit Akun
                            </a>
                            <form action="<?php echo e(url('/admin/user/destroy/' . $u->id_user)); ?>" method="POST">
                                <?php echo csrf_field(); ?>
                                <button type="submit" class="del-item"
                                    onclick="return confirm('Hapus akun <?php echo e($u->nama_user); ?>?')">
                                    <i class="bi bi-trash3"></i> Hapus Akun
                                </button>
                            </form>
                        </div>
                    </div>
                </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);">
                    <i class="bi bi-inbox" style="font-size:32px; display:block; margin-bottom:8px;"></i>
                    Belum ada Ketua RT yang terdaftar.
                </td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
    <div class="pagination-wrap">
        <span>Menampilkan <?php echo e($rts->count()); ?> data Ketua RT</span>
    </div>
</div>

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

<?php $__env->startPush('scripts'); ?>
<script>
function switchTab(tab) {
    document.getElementById('tab-amil').style.display = tab === 'amil' ? 'block' : 'none';
    document.getElementById('tab-rt').style.display   = tab === 'rt'   ? 'block' : 'none';
    document.querySelectorAll('.tab-btn').forEach((btn, idx) => {
        btn.classList.toggle('active', (idx === 0 && tab === 'amil') || (idx === 1 && tab === 'rt'));
    });
}

function toggleDrop(btn) {
    const menu = btn.nextElementSibling;
    document.querySelectorAll('.dropdown-menu-custom.show').forEach(m => {
        if (m !== menu) m.classList.remove('show');
    });
    menu.classList.toggle('show');
}

document.addEventListener('click', e => {
    if (!e.target.closest('.action-dots') && !e.target.closest('.dropdown-menu-custom')) {
        document.querySelectorAll('.dropdown-menu-custom.show').forEach(m => m.classList.remove('show'));
    }
});
</script>
<?php $__env->stopPush(); ?>

<?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/user/index.blade.php ENDPATH**/ ?>