@php
  $tr = $totaleRedditi ?? [];
  $year = $tr['year'] ?? (int) date('Y');
@endphp
<!-- Total Income -->
<div class="col-xl-8 mb-4 mt-4">
    <div class="card">
      <div class="row row-bordered g-0">
        <div class="col-md-8">
          <div class="card-header d-flex justify-content-between">
            <div>
              <h5 class="card-title mb-1">Incassi</h5>
              <p class="card-subtitle mb-0">Andamento mensile {{ $year }} (ordini escluso carrello / annullati)</p>
            </div>
            <div class="dropdown">
              <button class="btn p-0" type="button" id="totalIncomeDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="bx bx-dots-vertical-rounded bx-lg text-muted"></i>
              </button>
              <div class="dropdown-menu dropdown-menu-end" aria-labelledby="totalIncomeDropdown">
                <span class="dropdown-item-text small text-muted">Dati aggiornati al caricamento pagina</span>
              </div>
            </div>
          </div>
          <div class="card-body">
            <div id="totalIncomeChart"></div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="card-header d-flex justify-content-between">
            <div>
              <h5 class="card-title mb-1">Riepilogo</h5>
              <p class="card-subtitle">Media mensile: € {{ $tr['media_mensile_fmt'] ?? '0,00' }}</p>
            </div>
            <div class="dropdown">
              <button class="btn p-0" type="button" id="totalReportDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="bx bx-dots-vertical-rounded bx-lg text-muted"></i>
              </button>
              <div class="dropdown-menu dropdown-menu-end" aria-labelledby="totalReportDropdown">
                <span class="dropdown-item-text small text-muted">Confronti su incassi confermati</span>
              </div>
            </div>
          </div>
          <div class="card-body pt-2">
            <div class="report-list">
              <div class="report-list-item rounded-2 mb-4">
                <div class="d-flex align-items-center">
                  <div class="report-list-icon shadow-xs me-4">
                    <img src="{{ asset('assets/svg/icons/wallet-icon.svg') }}" width="22" height="22" alt="">
                  </div>
                  <div class="d-flex justify-content-between align-items-center w-100 flex-wrap gap-2">
                    <div class="d-flex flex-column">
                      <span>Incasso {{ $year }} (€)</span>
                      <h5 class="mb-0">€ {{ $tr['incasso_ytd_fmt'] ?? '0,00' }}</h5>
                    </div>
                    @if(isset($tr['delta_ytd_pct']))
                      <small class="{{ ($tr['delta_ytd_positive'] ?? false) ? 'text-success' : 'text-danger' }}">
                        {{ $tr['delta_ytd_fmt'] ?? '' }}
                      </small>
                    @else
                      <small class="text-muted">n/d</small>
                    @endif
                  </div>
                </div>
              </div>
              <div class="report-list-item rounded-2 mb-4">
                <div class="d-flex align-items-center">
                  <div class="report-list-icon shadow-xs me-4">
                    <img src="{{ asset('assets/svg/icons/credit-card-icon.svg') }}" width="22" height="22" alt="">
                  </div>
                  <div class="d-flex justify-content-between align-items-center w-100 flex-wrap gap-2">
                    <div class="d-flex flex-column">
                      <span>Media mensile</span>
                      <h5 class="mb-0">€ {{ $tr['media_mensile_fmt'] ?? '0,00' }}</h5>
                    </div>
                    <small class="text-muted">su {{ max(1, (int) date('n')) }} mesi</small>
                  </div>
                </div>
              </div>
              <div class="report-list-item rounded-2">
                <div class="d-flex align-items-center">
                  <div class="report-list-icon shadow-xs me-4">
                    <img src="{{ asset('assets/svg/icons/paypal-icon.svg') }}" width="22" height="22" alt="">
                  </div>
                  <div class="d-flex justify-content-between align-items-center w-100 flex-wrap gap-2">
                    <div class="d-flex flex-column">
                      <span>{{ $tr['mese_corrente_nome'] ?? 'Mese corrente' }}</span>
                      <h5 class="mb-0">€ {{ $tr['incasso_mese_corrente_fmt'] ?? '0,00' }}</h5>
                    </div>
                    <small class="{{ ($tr['delta_mese_positive'] ?? true) ? 'text-success' : 'text-danger' }}">
                      {{ $tr['delta_mese_fmt'] ?? '' }}
                    </small>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
</div>
    <!--/ Total Income -->
