@php
  $asportiTimeline = $asportiTimeline ?? collect();
@endphp
<div class="col-xl-3 col-md-6">
  <div class="asporto-lane h-100">
    <div class="asporto-lane__head asporto-lane__head--time">
      <div>
        <div class="fw-semibold"><i class="bx bx-time-five me-1"></i>Timeline consegne</div>
        <div class="small text-muted">Orari previsti</div>
      </div>
      <span class="badge rounded-pill bg-label-secondary" id="badge-time">{{ $asportiTimeline->count() }}</span>
    </div>
    <div class="asporto-lane__body">
      <div class="asporto-timeline" id="lane-timeline">
        @forelse($asportiTimeline as $asporto)
          @php
            $ordine = $asporto->ordine;
            $info = is_array($ordine?->info) ? $ordine->info : [];
            $cliente = $info['cliente'] ?? ($ordine->nome ?? '—');
            $codice = $ordine->codice ?? ('A-'.$asporto->ordine_id);
            $orario = $asporto->ora_ritiro
              ? \Illuminate\Support\Carbon::parse($asporto->ora_ritiro)->format('H:i')
              : ($info['ora_ritiro'] ?? '—');
            $statoLabel = str_replace('_', ' ', (string) $asporto->stato);
          @endphp
          <div class="asporto-timeline__item" data-stato="{{ $asporto->stato }}">
            <span class="asporto-timeline__dot"></span>
            <div class="d-flex justify-content-between gap-2">
              <strong>{{ $orario }}</strong>
              <span class="small text-muted">{{ $codice }}</span>
            </div>
            <div class="fw-medium">{{ $cliente }}</div>
            <div class="small text-muted text-capitalize">{{ $statoLabel }}</div>
          </div>
        @empty
          <div class="text-muted small text-center py-4">Nessuna consegna in elenco</div>
        @endforelse
      </div>
    </div>
  </div>
</div>
