@php
  $statOrdini = $statOrdini ?? [
    'total_ordini' => 0,
    'totale_incasso_fmt' => '0,00',
    'rows' => [],
    'chart_labels' => ['Nessun ordine'],
    'chart_series' => [1],
    'chart_colors' => ['#8592a3'],
  ];
@endphp
<!-- Statistiche ordini -->
<div class="col-sm-4 col-md-4 col-lg-4 col-xxl-4 mb-4 mt-4">
  <div class="card h-100">
    <div class="card-header d-flex justify-content-between">
      <div class="card-title mb-0">
        <h5 class="mb-1 me-2">Ordini</h5>
        <p class="card-subtitle mb-0">€ {{ $statOrdini['totale_incasso_fmt'] }} totale (importi con prezzo)</p>
      </div>
      <div class="dropdown">
        <button class="btn text-muted p-0" type="button" id="orderStatisticsMenu" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          <i class="bx bx-dots-vertical-rounded bx-lg"></i>
        </button>
        <div class="dropdown-menu dropdown-menu-end" aria-labelledby="orderStatisticsMenu">
          <a class="dropdown-item" href="{{ route('ordine.index') }}">Vedi tutti gli ordini</a>
          <a class="dropdown-item" href="{{ url()->current() }}">Aggiorna</a>
        </div>
      </div>
    </div>
    <div class="card-body">
      <div class="d-flex justify-content-between align-items-center mb-6">
        <div class="d-flex flex-column align-items-center gap-1">
          <h3 class="mb-1">{{ number_format($statOrdini['total_ordini'], 0, ',', '.') }}</h3>
          <small>Ordini totali</small>
        </div>
        <div id="orderStatisticsChart"></div>
      </div>
      <ul class="p-0 m-0">
        @forelse ($statOrdini['rows'] as $r)
          <li class="d-flex align-items-center @if(!$loop->last) mb-5 @endif">
            <div class="avatar flex-shrink-0 me-3">
              <span class="avatar-initial rounded {{ $r['bg'] }}"><i class="{{ $r['icon'] }}"></i></span>
            </div>
            <div class="d-flex w-100 flex-wrap align-items-center justify-content-between gap-2">
              <div class="me-2">
                <h6 class="mb-0">{{ $r['label'] }}</h6>
                <small class="text-muted">{{ \Illuminate\Support\Str::limit($r['subtitle'], 48) }}</small>
              </div>
              <div class="user-progress">
                <h6 class="mb-0">{{ number_format($r['count'], 0, ',', '.') }}</h6>
              </div>
            </div>
          </li>
        @empty
          <li class="text-muted small">Nessun ordine nel database.</li>
        @endforelse
      </ul>
    </div>
  </div>
</div>
<!-- / Statistiche ordini -->
