@php
  $righe = $righe ?? ($asporto->ordine?->righe_ordine ?? collect());
@endphp

@if($righe->isEmpty())
  <div class="text-muted">Nessuna riga ordine.</div>
@else
  <table class="asporto-ordine-table">
    <thead>
      <tr>
        <th class="asporto-ordine-table__qta">Q.tà</th>
        <th>Articolo</th>
      </tr>
    </thead>
    <tbody>
      @foreach($righe as $riga)
        @php
          $variantiRiga = ($riga->has_variante ?? collect())->filter(fn ($v) => $v->variante_id !== null);
          $noteRiga = trim((string) ($riga->note ?? ''));
        @endphp
        <tr>
          <td class="asporto-ordine-table__qta">{{ (int) $riga->quantita }}×</td>
          <td>
            <span class="asporto-ordine-table__nome">{{ $riga->piatto->nome ?? ('Piatto #'.$riga->piatto_id) }}</span>

            @foreach($variantiRiga as $variante)
              <div class="asporto-ordine-table__varianti" role="status">
                <i class="bx bx-plus-circle" aria-hidden="true"></i>
                <span>
                  {{ $variante->variante_piatto->label ?? 'Variante' }}
                  @if(!empty($variante->nota))
                    <em>({{ $variante->nota }})</em>
                  @endif
                </span>
              </div>
            @endforeach

            @if($noteRiga !== '')
              <div class="asporto-ordine-table__note" role="note">
                <i class="bx bx-error-circle" aria-hidden="true"></i>
                <span>{{ $noteRiga }}</span>
              </div>
            @endif
          </td>
        </tr>
      @endforeach
    </tbody>
  </table>
@endif
