@php
    use App\Enums\ProofStatus;
    use App\Models\SubscriptionPayment;

    /*
     * A shop that has paid and is waiting is a shop that cannot trade. The
     * oldest item in the queue is therefore shown on every screen, not just on
     * the queue itself — an unnoticed backlog is the one failure mode this
     * panel exists to prevent.
     */
    $oldest = auth()->user()?->canVerifyPayments()
        ? SubscriptionPayment::where('status', ProofStatus::Pending)->oldest('created_at')->first()
        : null;

    $waitingHours = $oldest ? (int) $oldest->created_at->diffInHours(now()) : 0;
@endphp

@if ($oldest && ! request()->routeIs('payments.queue'))
    @php $urgent = $waitingHours >= 12; @endphp

    <div @class([
        'no-print border-b px-4 py-2.5 text-sm sm:px-6 lg:px-8',
        'border-red-200 bg-red-50 text-red-900 dark:border-red-900 dark:bg-red-950 dark:text-red-100' => $urgent,
        'border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100' => ! $urgent,
    ])>
        <div class="flex flex-wrap items-center gap-x-3 gap-y-1">
            <x-ui.icon name="alert" class="h-4 w-4 shrink-0" />

            <span>
                <strong>{{ SubscriptionPayment::where('status', ProofStatus::Pending)->count() }}</strong>
                payment(s) awaiting verification.
                The oldest has been waiting
                <strong>{{ $waitingHours < 1 ? 'less than an hour' : $waitingHours.' hour(s)' }}</strong>.
            </span>

            <a href="{{ route('payments.queue') }}" wire:navigate class="font-semibold underline underline-offset-2">
                Review now
            </a>
        </div>
    </div>
@endif
