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

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

<div class="row g-3 mb-4">
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon blue"><i class="fas fa-car"></i></div>
            <div class="stat-value"><?php echo e($vehicles->total()); ?></div>
            <div class="stat-label">إجمالي المركبات</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon green"><i class="fas fa-check-circle"></i></div>
            <div class="stat-value"><?php echo e($vehicles->where('is_active', true)->count()); ?></div>
            <div class="stat-label">نشطة</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon orange"><i class="fas fa-clock"></i></div>
            <div class="stat-value"><?php echo e($vehicles->where('is_available', true)->count()); ?></div>
            <div class="stat-label">متاحة</div>
        </div>
    </div>
    <div class="col-6 col-lg-3">
        <div class="stat-card">
            <div class="stat-icon gold"><i class="fas fa-user-tie"></i></div>
            <div class="stat-value"><?php echo e($vehicles->whereNotNull('driver_id')->count()); ?></div>
            <div class="stat-label">مخصصة لسائق</div>
        </div>
    </div>
</div>


<div class="row g-3 mb-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header"><i class="fas fa-filter"></i> البحث والفلترة</div>
            <div class="card-body">
                <form method="GET" action="<?php echo e(route('admin.vehicles')); ?>" class="row g-3">
                    <div class="col-md-2">
                        <input type="text" name="brand" class="form-control" placeholder="الماركة" value="<?php echo e(request('brand')); ?>">
                    </div>
                    <div class="col-md-2">
                        <input type="text" name="model" class="form-control" placeholder="الموديل" value="<?php echo e(request('model')); ?>">
                    </div>
                    <div class="col-md-2">
                        <select name="vehicle_type" class="form-select">
                            <option value="">النوع</option>
                            <option value="sedan" <?php echo e(request('vehicle_type') == 'sedan' ? 'selected' : ''); ?>>سيدان</option>
                            <option value="suv" <?php echo e(request('vehicle_type') == 'suv' ? 'selected' : ''); ?>>SUV</option>
                            <option value="hatchback" <?php echo e(request('vehicle_type') == 'hatchback' ? 'selected' : ''); ?>>هاتشباك</option>
                            <option value="pickup" <?php echo e(request('vehicle_type') == 'pickup' ? 'selected' : ''); ?>>بيك أب</option>
                            <option value="van" <?php echo e(request('vehicle_type') == 'van' ? 'selected' : ''); ?>>فان</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <select name="status" class="form-select">
                            <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="available" <?php echo e(request('status') == 'available' ? 'selected' : ''); ?>>متاحة</option>
                            <option value="unavailable" <?php echo e(request('status') == 'unavailable' ? 'selected' : ''); ?>>غير متاحة</option>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <select name="year" class="form-select">
                            <option value="">السنة</option>
                            <?php for($year = date('Y'); $year >= 2000; $year--): ?>
                                <option value="<?php echo e($year); ?>" <?php echo e(request('year') == $year ? 'selected' : ''); ?>><?php echo e($year); ?></option>
                            <?php endfor; ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <button type="submit" class="btn btn-primary w-100"><i class="fas fa-search"></i> بحث</button>
                    </div>
                    <div class="col-12">
                        <a href="<?php echo e(route('admin.vehicles')); ?>" class="btn btn-secondary"><i class="fas fa-undo"></i> إعادة تعيين</a>
                        <a href="<?php echo e(route('admin.vehicles.create')); ?>" class="btn btn-success"><i class="fas fa-plus"></i> إضافة مركبة</a>
                    </div>
                </form>
            </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">
                <div><i class="fas fa-list"></i> قائمة المركبات</div>
                <div class="d-flex gap-2">
                    <span class="badge badge-info"><?php echo e($vehicles->total()); ?> مركبة</span>
                    <a href="<?php echo e(route('admin.vehicles.create')); ?>" class="btn btn-primary btn-sm"><i class="fas fa-plus"></i> إضافة</a>
                </div>
            </div>
            <div class="card-body p-0">
                <?php if($vehicles->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>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $vehicles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vehicle): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($vehicle->id); ?></td>
                                        <td>
                                            <?php if($vehicle->image): ?>
                                                <img src="<?php echo e(asset('storage/' . $vehicle->image)); ?>" class="rounded" width="50" height="35" alt="" style="object-fit: cover;">
                                            <?php else: ?>
                                                <div class="rounded d-flex align-items-center justify-content-center" style="width: 50px; height: 35px; background: var(--dark-600);">
                                                    <i class="fas fa-car" style="color: var(--text-muted);"></i>
                                                </div>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <strong><?php echo e($vehicle->brand); ?> <?php echo e($vehicle->model); ?></strong>
                                            <br><small style="color: var(--text-muted);"><?php echo e($vehicle->year); ?> - <?php echo e($vehicle->color); ?></small>
                                            <br><span class="badge badge-secondary"><?php echo e($vehicle->plate_number); ?></span>
                                            <?php switch($vehicle->vehicle_type):
                                                case ('sedan'): ?> <span class="badge badge-info">سيدان</span> <?php break; ?>
                                                <?php case ('suv'): ?> <span class="badge badge-success">SUV</span> <?php break; ?>
                                                <?php case ('hatchback'): ?> <span class="badge badge-info">هاتشباك</span> <?php break; ?>
                                                <?php case ('pickup'): ?> <span class="badge badge-warning">بيك أب</span> <?php break; ?>
                                                <?php case ('van'): ?> <span class="badge badge-secondary">فان</span> <?php break; ?>
                                                <?php default: ?> <span class="badge badge-secondary"><?php echo e($vehicle->vehicle_type); ?></span>
                                            <?php endswitch; ?>
                                        </td>
                                        <td>
                                            <?php if($vehicle->driver): ?>
                                                <strong><?php echo e($vehicle->driver->name); ?></strong>
                                                <br><small style="color: var(--text-muted);"><?php echo e($vehicle->driver->phone); ?></small>
                                            <?php else: ?>
                                                <span style="color: var(--text-muted);">غير محدد</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php if($vehicle->is_active): ?>
                                                <span class="badge badge-success">نشطة</span>
                                            <?php else: ?>
                                                <span class="badge badge-danger">غير نشطة</span>
                                            <?php endif; ?>
                                            <?php if($vehicle->is_available): ?>
                                                <span class="badge badge-info">متاحة</span>
                                            <?php else: ?>
                                                <span class="badge badge-warning">غير متاحة</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <small style="color: var(--text-muted);"><?php echo e($vehicle->created_at->format('Y-m-d')); ?></small>
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <a href="<?php echo e(route('admin.vehicles.show', $vehicle->id)); ?>" class="btn btn-info btn-sm" title="عرض"><i class="fas fa-eye"></i></a>
                                                <button type="button" class="btn btn-primary btn-sm" onclick="showVehicleDetails(<?php echo e($vehicle->id); ?>)" title="تفاصيل"><i class="fas fa-info-circle"></i></button>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="p-3 border-top" style="border-color: rgba(255,255,255,0.04) !important;">
                        <?php echo e($vehicles->links('pagination::bootstrap-4')); ?>

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

<div class="modal fade" id="vehicleDetailsModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <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" id="vehicleDetailsContent"></div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
function showVehicleDetails(vehicleId) {
    fetch(`/admin/vehicles/${vehicleId}/details`)
        .then(r => r.json())
        .then(data => {
            if (data.success) {
                document.getElementById('vehicleDetailsContent').innerHTML = data.html;
                new bootstrap.Modal(document.getElementById('vehicleDetailsModal')).show();
            }
        })
        .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/vehicles/index.blade.php ENDPATH**/ ?>