<?php $__env->startSection('title', 'مدیریت کاربران'); ?>

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">لیست کاربران</h5>
        <a href="<?php echo e(route('admin.users.create')); ?>" class="btn btn-primary">
            <i class="fas fa-plus me-2"></i>
            افزودن کاربر جدید
        </a>
    </div>

    <div class="card-body">
        <!-- Filters -->
        <form method="GET" action="<?php echo e(route('admin.users.index')); ?>" class="mb-4">
            <div class="row g-3">
                <div class="col-md-4">
                    <div class="input-group">
                        <span class="input-group-text">
                            <i class="fas fa-search"></i>
                        </span>
                        <input type="text" name="search" class="form-control" placeholder="جستجو (نام، ایمیل، موبایل)" value="<?php echo e(request('search')); ?>">
                    </div>
                </div>

                <div class="col-md-2">
                    <select name="role" class="form-select">
                        <option value="">همه نقش‌ها</option>
                        <option value="admin" <?php echo e(request('role') === 'admin' ? 'selected' : ''); ?>>مدیر</option>
                        <option value="driver" <?php echo e(request('role') === 'driver' ? 'selected' : ''); ?>>راننده</option>
                        <option value="requester" <?php echo e(request('role') === 'requester' ? 'selected' : ''); ?>>درخواست‌کننده</option>
                    </select>
                </div>

                <div class="col-md-2">
                    <select name="status" class="form-select">
                        <option value="">همه وضعیت‌ها</option>
                        <option value="1" <?php echo e(request('status') === '1' ? 'selected' : ''); ?>>فعال</option>
                        <option value="0" <?php echo e(request('status') === '0' ? 'selected' : ''); ?>>غیرفعال</option>
                    </select>
                </div>

                <div class="col-md-2">
                    <select name="per_page" class="form-select">
                        <option value="10" <?php echo e(request('per_page') == 10 ? 'selected' : ''); ?>>10 مورد</option>
                        <option value="25" <?php echo e(request('per_page') == 25 ? 'selected' : ''); ?>>25 مورد</option>
                        <option value="50" <?php echo e(request('per_page') == 50 ? 'selected' : ''); ?>>50 مورد</option>
                        <option value="100" <?php echo e(request('per_page') == 100 ? 'selected' : ''); ?>>100 مورد</option>
                    </select>
                </div>

                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-filter me-2"></i>
                        فیلتر
                    </button>
                </div>
            </div>
        </form>

        <!-- Results Summary -->
        <div class="d-flex justify-content-between align-items-center mb-3">
            <div class="text-muted">
                نمایش <?php echo e($users->firstItem() ?? 0); ?> تا <?php echo e($users->lastItem() ?? 0); ?> از <?php echo e(number_format($users->total())); ?> کاربر
            </div>
            <div>
                <a href="<?php echo e(route('admin.users.index')); ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="fas fa-redo me-1"></i>
                    حذف فیلترها
                </a>
            </div>
        </div>

        <!-- Table -->
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead>
                    <tr>
                        <th>
                            <a href="<?php echo e(route('admin.users.index', array_merge(request()->all(), ['sort' => 'id', 'order' => request('order') === 'asc' ? 'desc' : 'asc']))); ?>" class="text-decoration-none text-dark">
                                کد
                                <?php if(request('sort') === 'id'): ?>
                                    <i class="fas fa-sort-<?php echo e(request('order') === 'asc' ? 'up' : 'down'); ?>"></i>
                                <?php endif; ?>
                            </a>
                        </th>
                        <th>نام و نام خانوادگی</th>
                        <th>ایمیل</th>
                        <th>موبایل</th>
                        <th>نقش</th>
                        <th>وضعیت</th>
                        <th>
                            <a href="<?php echo e(route('admin.users.index', array_merge(request()->all(), ['sort' => 'created_at', 'order' => request('order') === 'asc' ? 'desc' : 'asc']))); ?>" class="text-decoration-none text-dark">
                                تاریخ ثبت‌نام
                                <?php if(request('sort') === 'created_at'): ?>
                                    <i class="fas fa-sort-<?php echo e(request('order') === 'asc' ? 'up' : 'down'); ?>"></i>
                                <?php endif; ?>
                            </a>
                        </th>
                        <th>عملیات</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->id); ?></td>
                        <td>
                            <div class="d-flex align-items-center">
                                <div class="rounded-circle bg-primary text-white d-flex align-items-center justify-content-center me-2" style="width: 35px; height: 35px; font-size: 0.875rem;">
                                    <?php echo e(mb_substr($user->name, 0, 1)); ?>

                                </div>
                                <strong><?php echo e($user->name); ?></strong>
                            </div>
                        </td>
                        <td><?php echo e($user->email ?? '-'); ?></td>
                        <td class="font-monospace"><?php echo e($user->phone); ?></td>
                        <td>
                            <?php if($user->role === 'admin'): ?>
                                <span class="badge bg-danger">مدیر</span>
                            <?php elseif($user->role === 'driver'): ?>
                                <span class="badge bg-info">راننده</span>
                            <?php else: ?>
                                <span class="badge bg-secondary">مشتری</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($user->status === 'active'): ?>
                                <span class="badge bg-success">فعال</span>
                            <?php elseif($user->status === 'inactive'): ?>
                                <span class="badge bg-secondary">غیرفعال</span>
                            <?php else: ?>
                                <span class="badge bg-warning">معلق</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <small class="text-muted"><?php echo e($user->created_at ? \Morilog\Jalali\Jalalian::fromDateTime($user->created_at)->format('Y/m/d') : '-'); ?></small>
                        </td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="<?php echo e(route('admin.users.show', $user->id)); ?>" class="btn btn-outline-info" title="مشاهده">
                                    <i class="fas fa-eye"></i>
                                </a>
                                <a href="<?php echo e(route('admin.users.edit', $user->id)); ?>" class="btn btn-outline-primary" title="ویرایش">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <button type="button" class="btn btn-outline-danger" onclick="confirmDelete(<?php echo e($user->id); ?>)" title="حذف">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </div>

                            <form id="delete-form-<?php echo e($user->id); ?>" action="<?php echo e(route('admin.users.destroy', $user->id)); ?>" method="POST" class="d-none">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="8" class="text-center text-muted py-5">
                            <i class="fas fa-users fa-3x mb-3"></i>
                            <p class="mb-0">هیچ کاربری یافت نشد</p>
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

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

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

<?php $__env->startPush('scripts'); ?>
<script>
    function confirmDelete(userId) {
        if (confirm('آیا از حذف این کاربر اطمینان دارید؟')) {
            document.getElementById('delete-form-' + userId).submit();
        }
    }
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH S:\wamp\www\sabok\temp-laravel\resources\views/admin/users/index.blade.php ENDPATH**/ ?>