@if(!empty($contact) && in_array($contact->type, ['customer', 'both']))
<div class="tab-pane" id="vrc_vehicles_tab">
    @php
        $vrcBid = (int) ($contact->business_id);
        $vrcVehicles = \Modules\Vrc\Entities\VrcVehicle::with(['make', 'model'])
            ->where('business_id', $vrcBid)
            ->where('erp_customer_id', $contact->id)
            ->orderByDesc('id')->get();
        $vrcOrders = \Schema::hasTable('vrc_repair_orders')
            ? \Modules\Vrc\Entities\VrcRepairOrder::where('business_id', $vrcBid)
                ->where('erp_customer_id', $contact->id)
                ->orderByDesc('created_at')->limit(20)->get()
            : collect();
    @endphp

    <div class="row">
        <div class="col-md-6">
            <h4><i class="fa fa-car"></i> @lang('vrc::lang.vehicles')
                @can('vrc.vehicle.manage')
                    <a href="{{ route('vrc.vehicles.create') }}" class="btn btn-xs btn-primary pull-right"><i class="fa fa-plus"></i> @lang('messages.add')</a>
                @endcan
            </h4>
            <table class="table table-condensed table-bordered">
                <thead><tr><th>@lang('vrc::lang.vehicle')</th><th>@lang('vrc::lang.plate_number')</th><th></th></tr></thead>
                <tbody>
                @forelse($vrcVehicles as $v)
                    <tr>
                        <td>{{ trim((optional($v->make)->name ?? '').' '.(optional($v->model)->name ?? '')) ?: '—' }} {{ $v->year ? "($v->year)" : '' }}</td>
                        <td>{{ $v->plate_number ?: '—' }}</td>
                        <td><a href="{{ route('vrc.vehicles.show', $v->id) }}" class="btn btn-xs btn-default"><i class="fa fa-eye"></i></a></td>
                    </tr>
                @empty
                    <tr><td colspan="3" class="text-muted text-center">@lang('vrc::lang.no_vehicles_yet')</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="col-md-6">
            <h4><i class="fa fa-history"></i> @lang('vrc::lang.service_history')</h4>
            <table class="table table-condensed table-bordered">
                <thead><tr><th>@lang('vrc::lang.repair_order')</th><th>@lang('vrc::lang.status')</th><th>@lang('vrc::lang.grand_total')</th></tr></thead>
                <tbody>
                @forelse($vrcOrders as $ro)
                    <tr>
                        <td><a href="{{ route('vrc.repair-orders.show', $ro->id) }}">{{ $ro->number ?: ('#'.$ro->id) }}</a></td>
                        <td>{{ __('vrc::lang.ro_status_'.$ro->status) }}</td>
                        <td>{{ $ro->grand_total }}</td>
                    </tr>
                @empty
                    <tr><td colspan="3" class="text-muted text-center">@lang('vrc::lang.no_service_history')</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endif
