@extends('layouts.app')
@section('title',$trip->trip_number)
@section('page_title','Trip '.$trip->trip_number)
@section('content')
<div class="page-head"><div><h1>{{ $trip->trip_number }}</h1><p><a href="{{ route('jobs.show',$trip->job) }}">{{ $trip->job?->job_number }}</a> · {{ $trip->job?->customer?->legal_name }}</p></div><div class="actions"><a class="btn btn-secondary" href="{{ route('trips.edit',$trip) }}">Edit</a><a class="btn btn-secondary" href="{{ route('trips.index') }}">Back</a></div></div>
<div class="grid grid-4"><div class="card metric"><div class="metric-label">Customer Revenue</div><div class="metric-value">AED {{ number_format((float)$trip->customer_rate+(float)$trip->additional_revenue,2) }}</div></div><div class="card metric"><div class="metric-label">Vendor / Trip Cost</div><div class="metric-value">AED {{ number_format((float)$trip->vendor_rate+(float)$trip->additional_cost,2) }}</div></div><div class="card metric"><div class="metric-label">Trip Margin</div><div class="metric-value">AED {{ number_format(((float)$trip->customer_rate+(float)$trip->additional_revenue)-((float)$trip->vendor_rate+(float)$trip->additional_cost),2) }}</div></div><div class="card metric"><div class="metric-label">Status</div><div class="metric-value" style="font-size:18px">{{ ucwords(str_replace('_',' ',$trip->status)) }}</div></div></div>
<div class="card" style="margin-top:18px"><div class="card-body"><div class="detail-grid"><div class="detail"><div class="detail-label">Vehicle</div><div class="detail-value">{{ $trip->vehicle?->plate_number ?? 'External / unassigned' }}</div></div><div class="detail"><div class="detail-label">Driver</div><div class="detail-value">{{ $trip->driver?->name ?? 'Unassigned' }}</div></div><div class="detail"><div class="detail-label">Vendor</div><div class="detail-value">{{ $trip->vendor?->legal_name ?? 'Own transport' }}</div></div><div class="detail"><div class="detail-label">Pickup</div><div class="detail-value">{{ optional($trip->pickup_at)->format('d M Y H:i') }}<br>{{ $trip->pickup_location }}</div></div><div class="detail"><div class="detail-label">Delivery</div><div class="detail-value">{{ optional($trip->delivery_at)->format('d M Y H:i') }}<br>{{ $trip->delivery_location }}</div></div><div class="detail"><div class="detail-label">Odometer</div><div class="detail-value">{{ $trip->start_odometer }} → {{ $trip->end_odometer }}</div></div></div><div class="divider"></div><form class="actions" method="post" action="{{ route('trips.status',$trip) }}">@csrf<select class="control" name="status" style="max-width:230px">@foreach(['scheduled','vehicle_assigned','driver_assigned','in_transit','reached_destination','delivered','cancelled'] as $s)<option value="{{ $s }}" @selected($trip->status===$s)>{{ ucwords(str_replace('_',' ',$s)) }}</option>@endforeach</select><input type="hidden" name="pickup_at" value="{{ optional($trip->pickup_at)->toIso8601String() }}"><input type="hidden" name="delivery_at" value="{{ optional($trip->delivery_at)->toIso8601String() }}"><button class="btn btn-primary">Update Trip Status</button></form></div></div>
@endsection
