@extends('layouts.admin')

@section('content')

<h2 style="margin-bottom:20px;">
Status Kendaraan
</h2>

<div class="card">

<table style="
width:100%;
border-collapse:collapse;
">

<tr style="
border-bottom:1px solid #e5e7eb;
">
    <th>Kendaraan</th>
    <th>Status</th>
    <th>Info</th>
</tr>

@foreach($vehicles as $vehicle)

<tr style="
border-bottom:1px solid #e5e7eb;
">

<td>

<strong>
{{ $vehicle->vehicle_name }}
</strong>

<br>

<small style="color:gray;">
{{ $vehicle->type }}
</small>

</td>

<td>

@if($vehicle->status == 'available')

<span style="
background:#dcfce7;
color:#166534;
padding:6px 12px;
border-radius:20px;
font-size:12px;
font-weight:700;
">
Tersedia
</span>

@elseif($vehicle->status == 'in_use')

<span style="
background:#dbeafe;
color:#1d4ed8;
padding:6px 12px;
border-radius:20px;
font-size:12px;
font-weight:700;
">
Sedang Digunakan
</span>

@elseif($vehicle->status == 'maintenance')

<span style="
background:#fef3c7;
color:#92400e;
padding:6px 12px;
border-radius:20px;
font-size:12px;
font-weight:700;
">
Maintenance
</span>

@else

<span style="
background:#fed7aa;
color:#9a3412;
padding:6px 12px;
border-radius:20px;
font-size:12px;
font-weight:700;
">
Menunggu Pengembalian
</span>

@endif

</td>

<td>

@php
$trip = $activeTrips
    ->where('vehicle_id', $vehicle->id)
    ->first();
@endphp

@if($trip)

Pengendara:
<strong>
{{ $trip->user->name }}
</strong>

<br>

Awal Perjalanan:
{{ $trip->departure_time->format('d M Y H:i') }}

<br><br>

Durasi:
@php

$hours = 0;

if($trip->departure_time && $trip->return_time){

    $hours =
        \Carbon\Carbon::parse($trip->departure_time)
        ->diffInHours(
            \Carbon\Carbon::parse($trip->return_time)
        );
}

@endphp

@if($hours >= 5)

<br><br>

<span style="
background:#fee2e2;
color:#991b1b;
padding:5px 10px;
border-radius:12px;
font-size:12px;
font-weight:700;
">

⚠ Pengembalian Terlambat

</span>

@endif

@php
$hours = $trip->departure_time
    ->diffInHours(now());
@endphp

<strong>
{{ $hours }} Jam
</strong>

@else

Tidak ada Pengembalian Terlambat

@endif

</td>

</tr>

@endforeach

</table>

</div>

@endsection