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

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5><i class="fas fa-users me-2"></i>Kelola User</h5>
        <div>
            <a href="<?php echo e(route('users.create')); ?>" class="btn btn-success">
                <i class="fas fa-plus me-2"></i>Tambah User
            </a>
        </div>
    </div>
    <div class="card-body">
        <!-- Filter -->
        <form method="GET" action="<?php echo e(route('users.index')); ?>" class="mb-3">
            <div class="row">
                <div class="col-md-3">
                    <select class="form-select" name="role">
                        <option value="">Semua Role</option>
                        <option value="customer" <?php echo e(request('role') === 'customer' ? 'selected' : ''); ?>>Customer</option>
                        <option value="manager" <?php echo e(request('role') === 'manager' ? 'selected' : ''); ?>>Manager</option>
                        <option value="admin" <?php echo e(request('role') === 'admin' ? 'selected' : ''); ?>>Admin</option>
                        <option value="superadmin" <?php echo e(request('role') === 'superadmin' ? 'selected' : ''); ?>>Super Admin</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <select class="form-select" name="status">
                        <option value="">Semua Status</option>
                        <option value="1" <?php echo e(request('status') === '1' ? 'selected' : ''); ?>>Aktif</option>
                        <option value="0" <?php echo e(request('status') === '0' ? 'selected' : ''); ?>>Tidak Aktif</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <input type="text" class="form-control" name="search" placeholder="Cari user..." value="<?php echo e(request('search')); ?>">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-filter me-2"></i>Filter
                    </button>
                </div>
            </div>
        </form>

        <!-- Stats -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="card bg-primary text-white">
                    <div class="card-body">
                        <h5><i class="fas fa-users me-2"></i>Total User</h5>
                        <h3><?php echo e($totalUsers); ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-success text-white">
                    <div class="card-body">
                        <h5><i class="fas fa-user me-2"></i>Customer</h5>
                        <h3><?php echo e($customerCount); ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-warning text-white">
                    <div class="card-body">
                        <h5><i class="fas fa-user-tie me-2"></i>Staff</h5>
                        <h3><?php echo e($staffCount); ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-info text-white">
                    <div class="card-body">
                        <h5><i class="fas fa-user-check me-2"></i>Aktif</h5>
                        <h3><?php echo e($activeCount); ?></h3>
                    </div>
                </div>
            </div>
        </div>

        <!-- User Table -->
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>Nama</th>
                        <th>Email</th>
                        <th>Role</th>
                        <th>Phone</th>
                        <th>Status</th>
                        <th>Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($user->name); ?></td>
                            <td><?php echo e($user->email); ?></td>
                            <td>
                                <span class="badge bg-<?php echo e($user->role === 'superadmin' ? 'danger' : ($user->role === 'admin' ? 'warning' : ($user->role === 'manager' ? 'info' : 'primary'))); ?>">
                                    <?php echo e(ucfirst($user->role)); ?>

                                </span>
                            </td>
                            <td><?php echo e($user->phone ?? '-'); ?></td>
                            <td>
                                <?php if($user->is_active): ?>
                                    <span class="badge bg-success">Aktif</span>
                                <?php else: ?>
                                    <span class="badge bg-danger">Tidak Aktif</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="btn-group btn-group-sm">
                                    <a href="<?php echo e(route('users.show', $user->id)); ?>" class="btn btn-info">
                                        <i class="fas fa-eye"></i>
                                    </a>
                                    <a href="<?php echo e(route('users.edit', $user->id)); ?>" class="btn btn-warning">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <?php if(Auth::user()->isSuperAdmin()): ?>
                                        <form action="<?php echo e(route('users.updateRole', $user->id)); ?>" method="POST" style="display:inline-block" onsubmit="return confirm('Ubah role user ini?')">
                                            <?php echo csrf_field(); ?>
                                            <select name="role" class="form-select form-select-sm" onchange="this.form.submit()">
                                                <option value="customer" <?php echo e($user->role === 'customer' ? 'selected' : ''); ?>>Customer</option>
                                                <option value="manager" <?php echo e($user->role === 'manager' ? 'selected' : ''); ?>>Manager</option>
                                                <option value="admin" <?php echo e($user->role === 'admin' ? 'selected' : ''); ?>>Admin</option>
                                                <option value="superadmin" <?php echo e($user->role === 'superadmin' ? 'selected' : ''); ?>>Super Admin</option>
                                            </select>
                                        </form>
                                    <?php endif; ?>
                                    <?php if($user->id !== Auth::id()): ?>
                                        <form action="<?php echo e(route('users.toggleStatus', $user->id)); ?>" method="POST" style="display:inline-block">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="btn btn-<?php echo e($user->is_active ? 'secondary' : 'success'); ?>" onclick="return confirm('Ubah status user ini?')">
                                                <i class="fas fa-<?php echo e($user->is_active ? 'ban' : 'check'); ?>"></i>
                                            </button>
                                        </form>
                                        <form action="<?php echo e(route('users.destroy', $user->id)); ?>" method="POST" style="display:inline-block" onsubmit="return confirm('Hapus user ini?')">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" class="btn btn-danger">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </form>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="6" class="text-center">Tidak ada data user</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        <?php if($users->hasPages()): ?>
            <div class="d-flex justify-content-center mt-3">
                <?php echo e($users->links()); ?>

            </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\yukig\Downloads\Manfutsal\resources\views/users/index.blade.php ENDPATH**/ ?>