@extends('layouts.security')

@section('content')

<style>

.hover-card{
    transition:.25s;
}

.hover-card:hover{
    transform:translateY(-4px);
    box-shadow:0 12px 25px rgba(0,0,0,.10) !important;
}

.btn-green{
    background:#16a34a;
    color:white;
    border:none;
    padding:8px 14px;
    border-radius:8px;
    font-weight:700;
    cursor:pointer;
}

.btn-blue{
    background:#2563eb;
    color:white;
    border:none;
    padding:8px 14px;
    border-radius:8px;
    font-weight:700;
    cursor:pointer;
}

</style>

<div style="margin-bottom:25px;">

    <p style="
    color:#64748b;
    font-size:14px;
    margin-bottom:8px;
    ">
        Home / Log Kontrol Pengguna
    </p>

    <h2 style="
    font-size:34px;
    font-weight:700;
    margin:0;
    ">
        Log Kontrol Pengguna
    </h2>

    <hr style="
    margin-top:20px;
    border:none;
    border-top:4px solid #e5e7eb;
    ">

</div>

<!-- ACTIVE REQUESTS -->

<div class="hover-card" style="
padding:20px;
border-radius:18px;
background:white;
box-shadow:0 4px 16px rgba(0,0,0,.05);
margin-bottom:25px;
">

<h3 style="margin-bottom:20px;">
Kontrol Perjalanan
</h3>

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

<tr>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Karyawan
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Kendaraan
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Tindakan
</th>

</tr>

@foreach($requests as $req)

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

<td style="padding:18px 16px;">
{{ $req->user->name }}
</td>

<td style="padding:18px 16px;">
{{ $req->vehicle->vehicle_name }}
</td>

<td style="padding:18px 16px;">

@if(!in_array($req->vehicle_id, $activeTrips))

<form method="POST"
    action="/security/start-trip/{{ $req->id }}">

    @csrf

    <button type="submit"
            class="btn-green">
        Mulai Perjalanan
    </button>

</form>

@else

<span style="
background:#dbeafe;
color:#1d4ed8;
padding:8px 12px;
border-radius:999px;
font-size:12px;
font-weight:700;
">

Menunggu Pengembalian Karyawan

</span>

@endif

</td>

</tr>

@endforeach

</table>

</div>

<!-- HISTORY -->

<div class="hover-card" style="
padding:20px;
border-radius:18px;
background:white;
box-shadow:0 4px 16px rgba(0,0,0,.05);
">

<h3 style="margin-bottom:20px;">
Riwayat Penggunaan Kendaraan
</h3>

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

<tr>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Kendaraan
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Keberangkatan
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Kembali
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
BBM
</th>

<th style="
padding:16px;
text-align:left;
border-bottom:1px solid #e5e7eb;
">
Status
</th>

</tr>

@foreach($logs as $log)

@php
$fuel = $log->fuelLogs->first() ?? null;
@endphp

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

<td style="padding:18px 16px;">
{{ $log->vehicle->vehicle_name ?? '-' }}
</td>

<td style="padding:18px 16px;">
{{ $log->departure_time }}
</td>

<td style="padding:18px 16px;">
{{ $log->return_time ?? '-' }}
</td>

<td style="padding:18px 16px;">

@if($fuel)

{{ $fuel->fuel_used }} L

@else

<span style="
color:#92400e;
font-weight:600;
">
Tidak Diinput
</span>

@endif

</td>

<td style="padding:18px 16px;">

@if(!$log->return_time)

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

@elseif($fuel && $fuel->fuel_used > 20)

<span style="
background:#fee2e2;
color:#b91c1c;
padding:6px 12px;
border-radius:999px;
font-size:12px;
font-weight:700;
">
BBM Tinggi
</span>

@else

<span style="
background:#dcfce7;
color:#15803d;
padding:6px 12px;
border-radius:999px;
font-size:12px;
font-weight:700;
">
Selesai
</span>

@endif

</td>

</tr>

@endforeach

@if($logs->isEmpty())

<tr>

<td colspan="5"
style="
padding:25px;
text-align:center;
color:#64748b;
">

Tidak ada riwayat penggunaan kendaraan.

</td>

</tr>

@endif

</table>

</div>

@endsection