<div>
    <!-- using bootstrap 4 -->
    <?php
if (! isset($_instance)) {
    $html = \Livewire\Livewire::mount('components.admin-sidebar')->html();
} elseif ($_instance->childHasBeenRendered('JYoezWs')) {
    $componentId = $_instance->getRenderedChildComponentId('JYoezWs');
    $componentTag = $_instance->getRenderedChildComponentTagName('JYoezWs');
    $html = \Livewire\Livewire::dummyMount($componentId, $componentTag);
    $_instance->preserveRenderedChild('JYoezWs');
} else {
    $response = \Livewire\Livewire::mount('components.admin-sidebar');
    $html = $response->html();
    $_instance->logRenderedChild('JYoezWs', $response->id(), \Livewire\Livewire::getRootElementTagName($html));
}
echo $html;
?>

	 <!-- Main Content-->
    <div class="main-content side-content pt-0">

        <div class="container-fluid">
            <div class="inner-body">

                <h3 class="mt-3">All Listings</h3>

                <div>
                    <!-- Flash messages for success and error -->
                    <?php if(session()->has('message')): ?>
                        <div class="alert alert-success"><?php echo e(session('message')); ?></div>
                    <?php elseif(session()->has('error')): ?>
                        <div class="alert alert-danger"><?php echo e(session('error')); ?></div>
                    <?php endif; ?>

                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>Title</th>
                                    <th>Make</th>
                                    <th>Category</th>
                                    <th>Price</th>
                                    <th>Vehicle ID</th>
                                    <th>Image</th>
                                    <th>Created At</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $listing; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $car): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($car->title); ?></td>
                                        <td><?php echo e($car->make->name); ?></td>
                                        <td><?php echo e($car->category->name); ?></td>
                                        <td><?php echo e($car->price); ?></td>

                                        <!-- Vehicle ID from related CarDetails model -->
                                        <td>
                                            <?php if($car->car_general): ?>
                                                <?php echo e($car->car_general->vehicle_id); ?>

                                            <?php else: ?>
                                                <span>No detail available</span>
                                            <?php endif; ?>
                                        </td>

                                        <!-- Car Image -->
                                        <td>
                                            <?php if(!empty($car->images) && is_array($car->images)): ?>
                                                <img src="<?php echo e(asset($car->images[0])); ?>" alt="Car Image" width="100">
                                            <?php else: ?>
                                                <span>No image available</span>
                                            <?php endif; ?>
                                        </td>

                                        <!-- Created At Date -->
                                        <td><?php echo e($car->created_at->format('Y-m-d H:i')); ?></td>

                                        <td>
                                            <!-- Edit button -->
                                            <a href="<?php echo e(route('admin.upload', $car->id)); ?>" class="btn btn-primary btn-sm">Edit</a>

                                            <!-- Delete button -->
                                            <button type="button" class="btn btn-danger btn-sm"
                                                onclick="confirmDelete(<?php echo e($car->id); ?>)">Delete</button>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>

                    <!-- Pagination links -->
                    <div class="p-2">
                        <?php echo e($listing->links('pagination::bootstrap-4')); ?>

                    </div>
                </div>

			</div>
		</div>
	</div>

    <!-- Confirmation dialog for deleting a car -->
    <script>
        function confirmDelete(carId) {
            if (confirm("Are you sure you want to delete this car?")) {
                window.livewire.find('<?php echo e($_instance->id); ?>').deleteCar(carId); // Call the Livewire delete method
            }
        }
    </script>
</div><?php /**PATH C:\xampp\htdocs\cavg\resources\views\livewire\pages\admin\listing.blade.php ENDPATH**/ ?>