<?php $__env->startSection('title','Pengguna'); ?>

<?php $__env->startSection('vendor-styles'); ?>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('vendors/css/tables/datatable/datatables.min.css')); ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('css/pages/data-list-view.css')); ?>">

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

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

<!-- Column selectors with Export Options and print table -->
<section id="data-list-view" class="data-list-view-header">   
    <div class="table-responsive">
        <table class="table data-list-view" id="users-table">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>NIK</th>
                    <th>Nama</th>
                    <th>Email</th>
                    <th>Role</th>
                    <th>Status</th>
                    <th>Aksi</th>
                </tr>
            </thead>
            <tbody>
            <?php $i = 1 ?>
            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($user->roles->first()->name === 'admin'): ?>
                <?php $color = "black" ?>
                <?php elseif($user->roles->first()->name === 'lurah'): ?>
                <?php $color = "primary" ?>
                <?php elseif($user->roles->first()->name === 'staff'): ?>
                <?php $color = "warning" ?>
                <?php elseif($user->roles->first()->name === 'warga'): ?>
                <?php $color = "info" ?>
                <?php endif; ?>

                <?php if($user->status === 'Aktif'): ?>
                <?php $color1 = "success" ?>
                <?php elseif($user->status === 'Tidak Aktif'): ?>
                <?php $color1 = "danger" ?>
                <?php endif; ?>
            
                <tr>
                <td class="user-id"><?php echo e($i++); ?></td>
                <td class="user-nik"><?php echo e($user->nik); ?></td>
                <td class="user-name"><?php echo e($user->name); ?></td>
                <td class="user-email"><?php echo e($user->email); ?></td>
                <td class="user-role">
                    <span class="bullet bullet-<?php echo e($color); ?> bullet-sm"></span>
                    <small class="text-muted"><?php echo e($user->roles->first()->name); ?></small>
                </td>
                <td class="user-status">
                    <div class="badge badge-pill badge-light-<?php echo e($color1); ?>">
                        <?php echo e($user->status); ?>

                    </div>
                </td>
                <td class="user-action">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('aktivasi pengguna')): ?>
                        <?php if($user->status == 'Aktif'): ?>
                            <a type="button" href="#" name="wait" id="<?php echo e($user->id); ?>" class="wait  btn btn-icon rounded-circle btn-light-warning" title="Nonaktifkan"><i class="bx bx-x"></i></a>
                        <?php else: ?>
                            <a type="button" href="#" name="aktif" id="<?php echo e($user->id); ?>" class="aktif btn btn-icon rounded-circle btn-light-success" title="Aktifkan"><i class="bx bx-check"></i></a>
                        <?php endif; ?>    
                    <?php endif; ?>  
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit pengguna')): ?>              
                        <a type="button" href="<?php echo e(route('user.edit', [$user->id])); ?>" class="btn btn-icon rounded-circle btn-light-primary" title="Edit"><i class="bx bx-edit-alt"></i></a>
                    <?php endif; ?>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('hapus pengguna')): ?>
                        <a type="button" href="#" name="delete" id="<?php echo e($user->id); ?>" class="delete btn btn-icon rounded-circle btn-light-danger" title="Hapus"><i class="bx bx-trash"></i></a>
                    <?php endif; ?>
                </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>

        </table>
    </div>
</section>
<div id="confirmModal" class="modal fade text-left" id="danger" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel120" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-danger">              
                <h5 class="modal-title white">Konfirmasi</h5>
                <button type="button" class="close btn btn-sm" data-dismiss="modal" aria-label="Close">
                    <i class="bx bx-x"></i>
                </button>
            </div>
            <div class="modal-body">
                <h5 align="center" style="margin:0;">Apakah Anda yakin akan <span class="text-danger"> menghapus </span> data ini?</h5>
            </div>
            <div class="modal-footer">
                <button type="button" name="ok_button" id="ok_button" class="btn btn-sm btn-danger">OK</button>
                <button type="button" class="btn btn-sm btn-light-secondary" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>
<div id="modalWait" class="modal fade text-left" id="danger" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel120" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-warning">              
                <h5 class="modal-title white">Konfirmasi</h5>
                <button type="button" class="close btn btn-sm" data-dismiss="modal" aria-label="Close">
                    <i class="bx bx-x"></i>
                </button>
            </div>
            <div class="modal-body">
                <h5 align="center" style="margin:0;">Apakah Anda yakin akan <span class="text-warning"> menonaktifkan </span> data ini?</h5>
            </div>
            <div class="modal-footer">
                <button type="button" name="ok_wait" id="ok_wait" class="btn btn-sm btn-warning">OK</button>
                <button type="button" class="btn btn-sm btn-light-secondary" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>
<div id="modalAktif" class="modal fade text-left" id="danger" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel120" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header bg-success">              
                <h5 class="modal-title white">Konfirmasi</h5>
                <button type="button" class="close btn btn-sm" data-dismiss="modal" aria-label="Close">
                    <i class="bx bx-x"></i>
                </button>
            </div>
            <div class="modal-body">
                <h5 align="center" style="margin:0;">Apakah Anda yakin akan <span class="text-success"> mengaktifkan </span> data ini?</h5>
            </div>
            <div class="modal-footer">
                <button type="button" name="ok_aktif" id="ok_aktif" class="btn btn-sm btn-success">OK</button>
                <button type="button" class="btn btn-sm btn-light-secondary" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>
<!-- Column selectors with Export Options and print table -->

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

<?php $__env->startSection('vendor-scripts'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/datatables.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/dataTables.bootstrap4.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/dataTables.buttons.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/buttons.html5.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/buttons.print.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/buttons.bootstrap.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/pdfmake.min.js')); ?>"></script>
<script src="<?php echo e(asset('vendors/js/tables/datatable/vfs_fonts.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-scripts'); ?>
<script src="<?php echo e(asset('js/scripts/datatables/datatable.js')); ?>"></script>
<script>
    $(document).ready(function() {
    var user_id;

    $(document).on('click', '.delete', function(){
        user_id = $(this).attr('id');
        $('#confirmModal').modal('show');
    });

    $('#ok_button').click(function(){
        $.ajax({
        url:"user/destroy/"+user_id,
        beforeSend:function(){
        $('#ok_button').text('Menghapus data...');
        },
        success:function(data)
        {
            setTimeout(function(){
            $('#confirmModal').modal('hide');
            $('#ok_button').text('OK');
            Swal.fire('Berhasil','Data berhasil dihapus!', 'success');
            }, 1500);

            setTimeout(function(){
                window.location.href = "<?php echo e(URL::to('user')); ?>"
            } , 3000);   
        }
        })
    });
    });
</script>
<script>
    $(document).ready(function() {
    var user_id;

    $(document).on('click', '.wait', function(){
        user_id = $(this).attr('id');
        $('#modalWait').modal('show');
    });

    $('#ok_wait').click(function(){
        $.ajax({
        url:"user/deaktivasi/"+user_id,
        beforeSend:function(){
        $('#ok_wait').text('Menonaktifkan data...');
        },
        success:function(data)
        {
            setTimeout(function(){
            $('#modalWait').modal('hide');
            $('#ok_wait').text('OK');
            Swal.fire('Berhasil','Data berhasil dinonaktifkan!', 'success');
            }, 1500);

            setTimeout(function(){
                window.location.href = "<?php echo e(URL::to('user')); ?>"
            } , 3000);   
        }
        })
    });
    });
</script>
<script>
    $(document).ready(function() {
    var user_id;

    $(document).on('click', '.aktif', function(){
        user_id = $(this).attr('id');
        $('#modalAktif').modal('show');
    });

    $('#ok_aktif').click(function(){
        $.ajax({
        url:"user/aktivasi/"+user_id,
        beforeSend:function(){
        $('#ok_aktif').text('Mengaktifkan data...');
        },
        success:function(data)
        {
            setTimeout(function(){
            $('#modalAktif').modal('hide');
            $('#ok_aktif').text('OK');
            Swal.fire('Berhasil','Data berhasil diaktifkan!', 'success');
            }, 1500);

            setTimeout(function(){
                window.location.href = "<?php echo e(URL::to('user')); ?>"
            } , 3000);   
        }
        })
    });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.contentLayoutMaster', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Users/mac/laravel-projects/wagom/resources/views/users/index.blade.php ENDPATH**/ ?>