{{-- Notifiche Real-time e Quick Actions --}}
@php
    $stats = App\Helpers\SidebarStatsHelper::getStats();
    $currentUser = auth()->user();
    $ticketsUrgenti = $stats['tickets']['urgenti'] ?? 0;
    $rateScadute = $stats['contabilita']['rate_scadute'] ?? 0;
    $assembleeProssime = $stats['assemblee']['prossime'] ?? 0;
    $documentiDaRevisionare = $stats['documenti']['da_revisionare'] ?? 0;
@endphp

{{-- Notifiche Urgenti --}}
@if($ticketsUrgenti > 0 && canUserAccessMenu('tickets'))
<li class="nav-item mb-1">
    <div class="alert alert-danger alert-dismissible fade show mx-2 py-2" role="alert">
        <strong><i class="fas fa-exclamation-triangle me-1"></i>Tickets Urgenti!</strong>
        <br><small>{{ $ticketsUrgenti }} ticket{{ $ticketsUrgenti > 1 ? 's' : '' }} richiedono attenzione immediata</small>
        <a href="{{ route('admin.tickets.index', ['priorita' => 'alta']) }}" class="btn btn-sm btn-outline-danger mt-1 w-100">
            <i class="fas fa-eye me-1"></i>Visualizza Urgenti
        </a>
        <button type="button" class="btn-close btn-close-small" data-bs-dismiss="alert"></button>
    </div>
</li>
@endif

{{-- Rate Scadute --}}
@if($rateScadute > 0 && canUserAccessMenu('contabilita'))
<li class="nav-item mb-1">
    <div class="alert alert-warning alert-dismissible fade show mx-2 py-2" role="alert">
        <strong><i class="fas fa-calendar-times me-1"></i>Rate Scadute</strong>
        <br><small>{{ $rateScadute }} rata{{ $rateScadute > 1 ? 'e' : '' }} non pagate oltre la scadenza</small>
        <a href="{{ route('admin.rate.index', ['stato' => 'scadute']) }}" class="btn btn-sm btn-outline-warning mt-1 w-100">
            <i class="fas fa-money-check me-1"></i>Gestisci Incassi
        </a>
        <button type="button" class="btn-close btn-close-small" data-bs-dismiss="alert"></button>
    </div>
</li>
@endif

{{-- Assemblee in Arrivo --}}
@if($assembleeProssime > 0 && canUserAccessMenu('assemblee'))
<li class="nav-item mb-1">
    <div class="alert alert-info alert-dismissible fade show mx-2 py-2" role="alert">
        <strong><i class="fas fa-users-cog me-1"></i>Assemblee</strong>
        <br><small>{{ $assembleeProssime }} assemblea{{ $assembleeProssime > 1 ? 'e' : '' }} programmate</small>
        <a href="{{ route('admin.assemblee.index', ['filter' => 'prossime']) }}" class="btn btn-sm btn-outline-info mt-1 w-100">
            <i class="fas fa-calendar me-1"></i>Vedi Calendario
        </a>
        <button type="button" class="btn-close btn-close-small" data-bs-dismiss="alert"></button>
    </div>
</li>
@endif

{{-- Quick Actions per Amministratori --}}
@if(hasMinimumRole('amministratore'))
<li class="nav-item mb-1">
    <div class="card bg-light border-0 mx-2">
        <div class="card-header bg-primary text-white py-1">
            <small><i class="fas fa-bolt me-1"></i>Azioni Rapide</small>
        </div>
        <div class="card-body p-2">
            <div class="d-grid gap-1">
                <a href="{{ route('admin.tickets.create') }}" class="btn btn-sm btn-outline-primary" title="Crea nuovo ticket di supporto">
                    <i class="fas fa-plus me-1"></i>Nuovo Ticket
                </a>
                <a href="{{ route('admin.soggetti.create') }}" class="btn btn-sm btn-outline-success" title="Aggiungi nuovo condomino">
                    <i class="fas fa-user-plus me-1"></i>Nuovo Condomino
                </a>
                <a href="{{ route('admin.stabili.create') }}" class="btn btn-sm btn-outline-info" title="Registra nuovo stabile">
                    <i class="fas fa-building me-1"></i>Nuovo Stabile
                </a>
                @if(canUserAccessMenu('contabilita'))
                <a href="{{ route('admin.rate.index') }}" class="btn btn-sm btn-outline-warning" title="Gestisci rate condominiali">
                    <i class="fas fa-receipt me-1"></i>Gestisci Rate
                </a>
                @endif
            </div>
        </div>
    </div>
</li>
@endif

{{-- Quick Stats Tile --}}
<li class="nav-item mb-1">
    <div class="card bg-gradient border-0 mx-2" style="background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);">
        <div class="card-body p-2 text-center">
            <div class="text-white">
                <small class="fw-bold d-block">Sistema NetGesCon</small>
                <div class="row g-0 mt-1">
                    <div class="col-6">
                        <small><i class="fas fa-building"></i><br>{{ $stats['stabili']['totale'] ?? 0 }} Stabili</small>
                    </div>
                    <div class="col-6">
                        <small><i class="fas fa-users"></i><br>{{ $stats['condomini']['totale'] ?? 0 }} Condomini</small>
                    </div>
                </div>
                <small class="text-light mt-1 d-block">
                    Ultimo aggiornamento: {{ date('H:i') }}
                </small>
            </div>
        </div>
    </div>
</li>
