<?php $__env->startSection('title', 'إدارة الركاب'); ?>
<?php $__env->startSection('page-title', 'إدارة الركاب'); ?>
<?php $__env->startSection('page-icon', 'fas fa-user'); ?>

<meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">

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

<div class="row g-3 mb-4">
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon gold"><i class="fas fa-users"></i></div>
            <div class="stat-value"><?php echo e($stats['total']); ?></div>
            <div class="stat-label">إجمالي الركاب</div>
        </div>
    </div>
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon green"><i class="fas fa-check-circle"></i></div>
            <div class="stat-value"><?php echo e($stats['verified']); ?></div>
            <div class="stat-label">موثقين</div>
        </div>
    </div>
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon blue"><i class="fas fa-user-check"></i></div>
            <div class="stat-value"><?php echo e($stats['active']); ?></div>
            <div class="stat-label">نشطين</div>
        </div>
    </div>
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon orange"><i class="fas fa-route"></i></div>
            <div class="stat-value"><?php echo e($passengers->sum(fn($p) => $p->passenger->total_trips ?? 0)); ?></div>
            <div class="stat-label">إجمالي الرحلات</div>
        </div>
    </div>
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon blue"><i class="fas fa-taxi"></i></div>
            <div class="stat-value"><?php echo e($stats['by_service']['taxi'] ?? 0); ?></div>
            <div class="stat-label">تاكسي</div>
        </div>
    </div>
    <div class="col-6 col-lg-2">
        <div class="stat-card">
            <div class="stat-icon orange"><i class="fas fa-utensils"></i></div>
            <div class="stat-value"><?php echo e($stats['by_service']['restaurant'] ?? 0); ?></div>
            <div class="stat-label">مطاعم</div>
        </div>
    </div>
</div>


<div class="row g-3">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-2">
                <div><i class="fas fa-list"></i> قائمة الركاب</div>
                <a href="<?php echo e(route('admin.users.create')); ?>" class="btn btn-primary btn-sm">
                    <i class="fas fa-plus"></i> إضافة راكب
                </a>
            </div>
            <div class="card-body">
                <form method="GET" action="<?php echo e(route('admin.passengers')); ?>" class="row g-3 mb-4">
                    <div class="col-md-2">
                        <input type="text" class="form-control" name="name" placeholder="البحث بالاسم..." value="<?php echo e(request('name')); ?>">
                    </div>
                    <div class="col-md-2">
                        <select class="form-select" name="status">
                            <option value="">الحالة</option>
                            <option value="active" <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>نشط</option>
                            <option value="inactive" <?php echo e(request('status') == 'inactive' ? 'selected' : ''); ?>>غير نشط</option>
                            <option value="suspended" <?php echo e(request('status') == 'suspended' ? 'selected' : ''); ?>>معلق</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <select class="form-select" name="active">
                            <option value="">النشاط</option>
                            <option value="1" <?php echo e(request('active') == '1' ? 'selected' : ''); ?>>نشط</option>
                            <option value="0" <?php echo e(request('active') == '0' ? 'selected' : ''); ?>>غير نشط</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <select class="form-select" name="service">
                            <option value="">الخدمة</option>
                            <option value="taxi" <?php echo e(request('service') == 'taxi' ? 'selected' : ''); ?>>تاكسي</option>
                            <option value="restaurant" <?php echo e(request('service') == 'restaurant' ? 'selected' : ''); ?>>مطاعم</option>
                            <option value="gas" <?php echo e(request('service') == 'gas' ? 'selected' : ''); ?>>غاز</option>
                            <option value="all" <?php echo e(request('service') == 'all' ? 'selected' : ''); ?>>الكل</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <select class="form-select" name="verified">
                            <option value="">التوثيق</option>
                            <option value="1" <?php echo e(request('verified') == '1' ? 'selected' : ''); ?>>موثق</option>
                            <option value="0" <?php echo e(request('verified') == '0' ? 'selected' : ''); ?>>غير موثق</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <button type="submit" class="btn btn-primary w-100"><i class="fas fa-search"></i> بحث</button>
                    </div>
                </form>

                <?php if($passengers->count() > 0): ?>
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>الصورة</th>
                                    <th>الاسم</th>
                                    <th>الهاتف</th>
                                    <th>الحالة</th>
                                    <th>التوثيق</th>
                                    <th>الخدمة</th>
                                    <th>الرحلات</th>
                                    <th>التقييم</th>
                                    <th>الإجراءات</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $passengers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $passenger): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($loop->iteration); ?></td>
                                        <td>
                                            <?php if($passenger->profile_image): ?>
                                                <img src="<?php echo e(asset('storage/' . $passenger->profile_image)); ?>" class="rounded-circle" width="36" height="36" alt="">
                                            <?php else: ?>
                                                <div class="rounded-circle d-flex align-items-center justify-content-center" style="width: 36px; height: 36px; background: var(--dark-600);">
                                                    <i class="fas fa-user" style="color: var(--text-muted);"></i>
                                                </div>
                                            <?php endif; ?>
                                        </td>
                                        <td><strong><?php echo e($passenger->name); ?></strong></td>
                                        <td><?php echo e($passenger->phone ?? 'غير محدد'); ?></td>
                                        <td>
                                            <?php switch($passenger->status):
                                                case ('active'): ?> <span class="badge badge-success">نشط</span> <?php break; ?>
                                                <?php case ('inactive'): ?> <span class="badge badge-secondary">غير نشط</span> <?php break; ?>
                                                <?php case ('suspended'): ?> <span class="badge badge-danger">معلق</span> <?php break; ?>
                                                <?php default: ?> <span class="badge badge-secondary">-</span>
                                            <?php endswitch; ?>
                                        </td>
                                        <td>
                                            <?php if($passenger->is_verified): ?>
                                                <span class="badge badge-success">موثق</span>
                                            <?php else: ?>
                                                <span class="badge badge-warning">غير موثق</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php switch($passenger->service_type):
                                                case ('taxi'): ?> <span class="badge badge-info">تاكسي</span> <?php break; ?>
                                                <?php case ('restaurant'): ?> <span class="badge badge-warning">مطاعم</span> <?php break; ?>
                                                <?php case ('gas'): ?> <span class="badge badge-danger">غاز</span> <?php break; ?>
                                                <?php case ('all'): ?> <span class="badge badge-success">الكل</span> <?php break; ?>
                                                <?php default: ?> <span class="badge badge-secondary">-</span>
                                            <?php endswitch; ?>
                                        </td>
                                        <td><span class="badge badge-info"><?php echo e($passenger->passenger->total_trips ?? 0); ?></span></td>
                                        <td>
                                            <?php if($passenger->passenger && $passenger->passenger->rating > 0): ?>
                                                <span class="badge badge-warning"><?php echo e(number_format($passenger->passenger->rating, 1)); ?></span>
                                            <?php else: ?>
                                                <span style="color: var(--text-muted);">-</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <a href="<?php echo e(route('admin.users.show', $passenger->id)); ?>" class="btn btn-info btn-sm" title="عرض"><i class="fas fa-eye"></i></a>
                                                <a href="<?php echo e(route('admin.users.edit', $passenger->id)); ?>" class="btn btn-warning btn-sm" title="تعديل"><i class="fas fa-edit"></i></a>
                                                <button type="button" class="btn btn-success btn-sm" onclick="toggleVerification(<?php echo e($passenger->id); ?>)" title="التوثيق"><i class="fas fa-check-circle"></i></button>
                                                <button type="button" class="btn btn-danger btn-sm" onclick="deletePassenger(<?php echo e($passenger->id); ?>)" title="حذف"><i class="fas fa-trash"></i></button>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="d-flex justify-content-between align-items-center mt-4">
                        <div style="color: var(--text-muted); font-size: 13px;">
                            عرض <?php echo e($passengers->firstItem() ?? 0); ?> إلى <?php echo e($passengers->lastItem() ?? 0); ?> من أصل <?php echo e($passengers->total()); ?>

                        </div>
                        <?php echo e($passengers->appends(request()->query())->links('pagination::bootstrap-4')); ?>

                    </div>
                <?php else: ?>
                    <div class="empty-state">
                        <i class="fas fa-user d-block"></i>
                        لا يوجد ركاب
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">تأكيد الحذف</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">هل أنت متأكد من حذف هذا الراكب؟</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">إلغاء</button>
                <button type="button" class="btn btn-danger" id="confirmDelete">حذف</button>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
let passengerToDelete = null;

function toggleVerification(id) {
    fetch(`/admin/passengers/${id}/toggle-verification`, {
        method: 'PATCH',
        headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Content-Type': 'application/json' },
    })
    .then(r => r.json())
    .then(data => { if (data.success) location.reload(); else alert('حدث خطأ'); })
    .catch(() => alert('حدث خطأ'));
}

function deletePassenger(id) {
    passengerToDelete = id;
    new bootstrap.Modal(document.getElementById('deleteModal')).show();
}

document.getElementById('confirmDelete').addEventListener('click', function() {
    if (passengerToDelete) {
        fetch(`/admin/users/${passengerToDelete}`, {
            method: 'DELETE',
            headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content },
        })
        .then(r => { if (r.ok) location.reload(); else alert('حدث خطأ'); })
        .catch(() => alert('حدث خطأ'));
    }
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\taxi_app\resources\views/admin/passengers/index.blade.php ENDPATH**/ ?>