@php
  $ordine = $asporto->ordine;
  $info = is_array($ordine?->info) ? $ordine->info : [];
  $cliente = $info['cliente'] ?? ($ordine->nome ?? '—');
  $telefono = trim((string) ($info['telefono'] ?? ''));
  $telHref = $telefono !== '' ? preg_replace('/\s+/', '', $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');
@endphp

<section
  class="asporto-prep-panel asporto-pick-panel"
  id="asportoCallPanel{{ $asporto->id }}"
  data-call-panel
  data-asporto-id="{{ $asporto->id }}"
  data-asporto-codice="{{ $codice }}"
  data-ora-ritiro="{{ $orario }}"
  data-completa-url="{{ route('asporto.postazione.chiamata.completa', $asporto) }}"
  data-timing-target
  hidden
>
  <div class="asporto-prep-detail__body asporto-pick-panel__body">
    <div class="asporto-pick-split">
      <div class="asporto-pick-split__info">
        <div class="asporto-pick-split__code-row">
          <div class="asporto-prep-panel__code">{{ $codice }}</div>
          <div class="asporto-timing-chip" data-timing-chip>
            <span class="asporto-timing-badge" data-timing-badge></span>
          </div>
        </div>

        @include('asporto._partials.ordine_facts', [
          'asporto' => $asporto,
          'showTelefono' => false,
        ])

        <div class="asporto-call-phone">
          @if($telefono !== '')
            <div class="asporto-call-phone__label">Telefono</div>
            <a class="asporto-call-phone__number" href="tel:{{ $telHref }}">
              <i class="bx bx-phone-call"></i> {{ $telefono }}
            </a>
            <div class="asporto-call-phone__hint">Tocca per chiamare dal dispositivo</div>
          @else
            <div class="asporto-call-phone__label">Telefono</div>
            <div class="asporto-call-phone__missing">Numero non disponibile</div>
          @endif
        </div>
      </div>

      <div class="asporto-pick-split__items">
        <p class="asporto-pick-split__items-title">Contenuto ordine</p>
        <div class="asporto-call-riepilogo">
          @include('asporto._partials.ordine_righe_table', ['asporto' => $asporto, 'righe' => $righe])
        </div>
      </div>
    </div>
  </div>

  <div class="asporto-prep-detail__foot asporto-pick-panel__foot">
    <button type="button" class="btn btn-primary asporto-prep-continua is-ready" data-call-continua>
      <i class="bx bx-phone-call me-1"></i>Chiamata fatta → Ritiro
    </button>
  </div>
</section>
