@extends('admin.layouts.app')

@section('title', 'Fleet Management - NRT SA Admin')

@section('content')
<div class="p-6">
    <!-- Header -->
    <div class="flex items-center justify-between mb-8">
        <div>
            <h1 class="text-3xl font-bold text-white mb-2 font-display text-glow">Fleet Management</h1>
            <p class="text-gray-300 font-body">Manage your vehicle fleet</p>
        </div>
        <a href="{{ route('admin.fleet.create') }}" class="btn-primary">
            <i class="fas fa-plus"></i>
            <span>Add Vehicle</span>
        </a>
    </div>

    <!-- Fleet List -->
    <div class="glass-card p-6 rounded-xl">
        <div class="overflow-x-auto">
            <table class="w-full text-left">
                <thead>
                    <tr class="border-b border-gray-700">
                        <th class="py-3 px-4 text-gray-300 font-body">Image</th>
                        <th class="py-3 px-4 text-gray-300 font-body">Name</th>
                        <th class="py-3 px-4 text-gray-300 font-body">Model</th>
                        <th class="py-3 px-4 text-gray-300 font-body">Daily Rate</th>
                        <th class="py-3 px-4 text-gray-300 font-body">Status</th>
                        <th class="py-3 px-4 text-gray-300 font-body">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($vehicles as $vehicle)
                    <tr class="border-b border-gray-800">
                        <td class="py-3 px-4">
                            @if($vehicle->image_path)
                                <img src="{{ asset('storage/' . $vehicle->image_path) }}" alt="{{ $vehicle->name }}" class="w-16 h-12 object-cover rounded">
                            @else
                                <div class="w-16 h-12 bg-gray-200 rounded flex items-center justify-center">
                                    <i class="fas fa-car text-gray-400"></i>
                                </div>
                            @endif
                        </td>
                        <td class="py-3 px-4">
                            <div>
                                <p class="text-white font-body font-semibold">{{ $vehicle->name }}</p>
                                <p class="text-gray-400 text-sm font-body">{{ $vehicle->type }}</p>
                            </div>
                        </td>
                        <td class="py-3 px-4 text-gray-300 font-body">{{ $vehicle->model }}</td>
                        <td class="py-3 px-4 text-gray-300 font-body">R{{ number_format($vehicle->daily_rate, 2) }}</td>
                        <td class="py-3 px-4">
                            <span class="px-2 py-1 rounded-full text-xs font-body
                                @if($vehicle->is_available) bg-green-100 text-green-800
                                @else bg-red-100 text-red-800
                                @endif">
                                {{ $vehicle->is_available ? 'Available' : 'Unavailable' }}
                            </span>
                        </td>
                        <td class="py-3 px-4">
                            <div class="flex space-x-2">
                                <a href="{{ route('admin.fleet.show', $vehicle) }}" class="text-blue-400 hover:text-blue-300">
                                    <i class="fas fa-eye"></i>
                                </a>
                                <a href="{{ route('admin.fleet.edit', $vehicle) }}" class="text-green-400 hover:text-green-300">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <form method="POST" action="{{ route('admin.fleet.destroy', $vehicle) }}" class="inline" onsubmit="return confirm('Are you sure you want to delete this vehicle?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="text-red-400 hover:text-red-300">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="py-8 text-center text-gray-400 font-body">No vehicles found</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($vehicles->hasPages())
        <div class="mt-6">
            {{ $vehicles->links() }}
        </div>
        @endif
    </div>
</div>
@endsection
