@php
  $ordine = $asporto->ordine;
  $info = is_array($ordine?->info) ? $ordine->info : [];
  $cliente = $info['cliente'] ?? ($ordine->nome ?? '—');
  $telefono = $info['telefono'] ?? '';
  $codice = $ordine->codice ?? ('A-'.$asporto->ordine_id);
  $orario = $asporto->ora_ritiro
    ? \Illuminate\Support\Carbon::parse($asporto->ora_ritiro)->format('H:i')
    : ($info['ora_ritiro'] ?? '');
  $note = $ordine->note ?? ($info['note'] ?? '');
  $righe = $ordine?->righe_ordine ?? collect();
  $qta = (int) $righe->sum('quantita');

  $variante = $variante ?? 'prep'; // prep|call|pick
  $badgeClass = match ($variante) {
    'call' => 'bg-label-primary',
    'pick' => 'bg-label-success',
    default => 'bg-label-warning',
  };

  if ($variante === 'call') {
    $meta = $telefono !== '' ? $telefono : '—';
  } elseif ($variante === 'pick') {
    $meta = 'Pronto al banco';
  } else {
    $meta = $qta.' '.($qta === 1 ? 'articolo' : 'articoli');
    if ($note) {
      $meta .= ' · <span class="text-warning">'.e($note).'</span>';
    }
  }

  $modalTarget = $modalTarget ?? null;
@endphp

<div
  class="asporto-card"
  @if($modalTarget)
    role="button"
    tabindex="0"
    data-bs-toggle="modal"
    data-bs-target="{{ $modalTarget }}"
  @endif
  data-asporto-card
  data-asporto-id="{{ $asporto->id }}"
  data-variante="{{ $variante }}"
>
  <div class="d-flex justify-content-between align-items-start gap-2">
    <div>
      <div class="asporto-card__code">{{ $codice }}</div>
      <div class="fw-medium">{{ $cliente }}</div>
    </div>
    @if($orario !== '')
      <span class="badge {{ $badgeClass }}">{{ $orario }}</span>
    @endif
  </div>
  <div class="asporto-card__meta mt-1">{!! $meta !!}</div>
</div>
