@section('content')

<h2>Log Control Perjalanan</h2>

<table>
<tr>
    <th>Karyawan</th>
    <th>Kendaraan</th>
    <th>Tindakan</th>
</tr>

@foreach($requests as $req)

@php
$active = \App\Models\TripLog::where('request_id', $req->id)
    ->whereNull('return_time')
    ->first();
@endphp

<tr>
<td>{{ $req->user->name }}</td>
<td>{{ $req->vehicle->vehicle_name }}</td>

<td>

@if(!$active)

<form method="POST" action="/security/start-trip/{{ $req->id }}">
@csrf
<button type="submit">Mulai Perjalanan</button>
</form>

@else

<form method="POST" action="/security/end-trip/{{ $req->id }}">
@csrf
<button type="submit">Akhiri Perjalanan</button>
</form>

@endif

</td>
</tr>

@endforeach

</table>

<br><br>

<h2>History Perjalanan</h2>

<table>
<tr>
    <th>Kendaraan</th>
    <th>Keberangkatan</th>
    <th>Kembali</th>
</tr>

@foreach($logs as $log)
<tr>
<td>{{ $log->request->vehicle->vehicle_name ?? '-' }}</td>
<td>{{ $log->departure_time }}</td>
<td>{{ $log->return_time ?? '-' }}</td>
</tr>
@endforeach

</table>

@endsection