@extends('crm::emails.layout', [
    'subject' => 'AutoTrader stock access failure',
    'colours' => $colours,
])

@section('content')
<p>
    We were unable to fetch AutoTrader stock for the following
    location{{ $locations->count() === 1 ? '' : 's' }} on <strong>{{ $site_name }}</strong>
    because we do not currently have access. This usually means the AutoTrader advertiser
    ID is incorrect, or access to the location has been revoked.
</p>

<table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;">
    <thead>
        <tr style="background-color: #f5f5f5;">
            <th style="padding: 10px; border: 1px solid #ddd; text-align: left;">Location (advertiser ID)</th>
            <th style="padding: 10px; border: 1px solid #ddd; text-align: left;">Consecutive failures</th>
            <th style="padding: 10px; border: 1px solid #ddd; text-align: left;">Last successful fetch</th>
            <th style="padding: 10px; border: 1px solid #ddd; text-align: left;">Last error</th>
        </tr>
    </thead>
    <tbody>
        @foreach($locations as $location)
        <tr>
            <td style="padding: 10px; border: 1px solid #ddd;">{{ $location->advertiser_id }}</td>
            <td style="padding: 10px; border: 1px solid #ddd;">{{ $location->consecutive_failures }}</td>
            <td style="padding: 10px; border: 1px solid #ddd;">
                {{ $location->last_success_at?->format('Y-m-d H:i') ?? 'Never' }}
            </td>
            <td style="padding: 10px; border: 1px solid #ddd;">{{ $location->last_error }}</td>
        </tr>
        @endforeach
    </tbody>
</table>

@if($isLive)
<p>Please check the AutoTrader location settings for the affected dealership(s).</p>
@else
<p>This site is still in development &mdash; verify the AutoTrader advertiser configuration before go-live.</p>
@endif
@endsection
