@extends('layouts.app')

@section('content')
<div class="space-y-6">
    <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <div>
            <h1 class="text-2xl font-bold text-gray-900 dark:text-white">
                Data Kendaraan
            </h1>
            <p class="text-sm text-gray-500 dark:text-gray-400">
                Master kendaraan untuk surat jalan.
            </p>
        </div>

        <a href="{{ route('vehicles.create') }}"
   style="display:inline-flex;align-items:center;justify-content:center;background:#2563eb;color:#ffffff;padding:10px 16px;border-radius:10px;font-size:14px;font-weight:700;text-decoration:none;box-shadow:0 4px 10px rgba(37,99,235,.25);">
    + Tambah Kendaraan
</a>
    </div>

    @if(session('success'))
        <div class="rounded-lg bg-green-50 p-4 text-sm text-green-700 dark:bg-green-500/10 dark:text-green-300">
            {{ session('success') }}
        </div>
    @endif

    <form method="GET" class="rounded-xl border border-gray-200 bg-white p-4 dark:border-gray-800 dark:bg-gray-900">
        <div class="grid gap-3 md:grid-cols-3">
            <input
                name="search"
                value="{{ request('search') }}"
                placeholder="Cari kendaraan..."
                class="rounded-lg border border-gray-300 px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-800 dark:text-white"
            >

            <select
                name="status"
                class="rounded-lg border border-gray-300 px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-800 dark:text-white"
            >
                <option value="">Semua status</option>
                <option value="active" @selected(request('status') === 'active')>Aktif</option>
                <option value="inactive" @selected(request('status') === 'inactive')>Nonaktif</option>
            </select>

            <button class="rounded-lg bg-gray-900 px-4 py-2 text-sm font-semibold text-white hover:bg-gray-800">
                Filter
            </button>
        </div>
    </form>

    <div class="overflow-hidden rounded-xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-gray-900">
        <div class="overflow-x-auto">
            <table class="min-w-full text-sm">
                <thead>
                    <tr class="bg-gray-50 dark:bg-gray-800">
                        <th class="px-4 py-3 text-left">Kendaraan</th>
                        <th class="px-4 py-3 text-left">Plat</th>
                        <th class="px-4 py-3 text-left">Supir</th>
                        <th class="px-4 py-3 text-left">Status</th>
                        <th class="px-4 py-3 text-right">Aksi</th>
                    </tr>
                </thead>

                <tbody>
                    @forelse($vehicles as $vehicle)
                        <tr class="border-t border-gray-200 dark:border-gray-800">
                            <td class="px-4 py-3 font-medium text-gray-900 dark:text-white">
                                {{ $vehicle->name }}
                            </td>
                            <td class="px-4 py-3 text-gray-700 dark:text-gray-300">
                                {{ $vehicle->plate_number ?: '-' }}
                            </td>
                            <td class="px-4 py-3 text-gray-700 dark:text-gray-300">
                                {{ $vehicle->driver_name ?: '-' }}
                                @if($vehicle->driver_phone)
                                    <div class="text-xs text-gray-500">
                                        {{ $vehicle->driver_phone }}
                                    </div>
                                @endif
                            </td>
                            <td class="px-4 py-3">
                                @if($vehicle->is_active)
                                    <span class="rounded-full bg-green-100 px-2 py-1 text-xs font-semibold text-green-700">
                                        Aktif
                                    </span>
                                @else
                                    <span class="rounded-full bg-gray-100 px-2 py-1 text-xs font-semibold text-gray-700">
                                        Nonaktif
                                    </span>
                                @endif
                            </td>
                            <td class="px-4 py-3 text-right">
                                <a href="{{ route('vehicles.edit', $vehicle) }}"
                                   class="rounded border border-gray-300 px-3 py-1 text-xs text-gray-700 hover:bg-gray-50">
                                    Edit
                                </a>

                                <form method="POST"
                                      action="{{ route('vehicles.destroy', $vehicle) }}"
                                      class="inline"
                                      onsubmit="return confirm('Hapus/nonaktifkan kendaraan ini?')">
                                    @csrf
                                    @method('DELETE')
                                    <button class="rounded border border-red-300 px-3 py-1 text-xs text-red-700 hover:bg-red-50">
                                        Hapus
                                    </button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="px-4 py-8 text-center text-gray-500">
                                Belum ada data kendaraan.
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="border-t border-gray-200 p-4 dark:border-gray-800">
            {{ $vehicles->links() }}
        </div>
    </div>
</div>
@endsection