@forelse ($trucks as $k => $t)
@php
$trip = $t->activeTrip;
$mnt = $trip ? null : $t->activeMaintenance;
$state = $trip ? ($trip->is_overdue ? 'late' : 'loaded') : ($mnt ? 'maint' : 'empty');
$region = ($trip || $mnt) ? '' : ($t->current_region ?: 'غير محدد');
$search = strtolower($t->plate_number . ' ' . $t->truck_type . ' ' . \App\Models\truck_trip::ownershipLabel($t->ownership) . ' ' . ($trip ? $trip->driver_name . ' ' . optional($trip->driver)->phone . ' ' . $trip->from_region . ' ' . $trip->to_region . ' ' . $trip->load_type . ' ' . $trip->customer_name : $region . ' ' . optional($t->default_driver)->name . ' ' . optional($t->default_driver)->phone));
@endphp
{{ $t->truck_type ?: 'شاحنة' }}{{ $t->total_load ? ' · ' . $t->total_load : '' }}
@if ($t->insurance_status == 'expired' || $t->insurance_status == 'soon' || $t->istimara_status == 'expired' || $t->istimara_status == 'soon')
@if ($t->insurance_status == 'expired') التأمين منتهي
@elseif ($t->insurance_status == 'soon') التأمين ينتهي {{ $t->insurance_expiry->format('Y/m/d') }}@endif
@if ($t->istimara_status == 'expired') الاستمارة منتهية
@elseif ($t->istimara_status == 'soon') الاستمارة تنتهي {{ $t->istimara_expiry->format('Y/m/d') }}@endif
@endif
{{ \App\Models\truck_trip::ownershipLabel($t->ownership) }}
@if ($state == 'empty') فاضية
@elseif ($state == 'maint') في الصيانة
@elseif ($state == 'late') متأخرة
@else محمّلة @endif
@if ($mnt)
{{ $mnt->reason }}
@if ($mnt->workshop)
{{ $mnt->workshop }}
@endif
دخلت: {{ $fmt($mnt->started_at) }} ({{ $mnt->days }} يوم)
@if ($mnt->expected_end_at)
الخروج المتوقع: {{ $fmt($mnt->expected_end_at) }}{{ $mnt->is_overdue ? ' — متأخرة' : '' }}
@endif
@include('trucks._call', ['drv' => $t->default_driver, 'name' => null, 'phone' => null])
@elseif (!$trip)
{{ $region }}{{ $t->current_city ? ' - ' . $t->current_city : '' }}
@include('trucks._call', ['drv' => $t->default_driver, 'name' => null, 'phone' => null])
@else
من{{ $trip->from_region }}{{ $trip->from_city }}
إلى{{ $trip->to_region }}{{ $trip->to_city }}
@include('trucks._call', ['drv' => $trip->driver, 'name' => $trip->driver_name, 'phone' => null])
@endif