@php
    $userRoles = auth()->check() ? auth()->user()->getRoleNames()->toArray() : [];
    $panelPrefix = '';
    if (in_array('super-admin', $userRoles)) {
        $panelPrefix = 'superadmin.';
    } elseif (in_array('admin', $userRoles) || in_array('amministratore', $userRoles)) {
        $panelPrefix = 'admin.';
    }
@endphp

<nav class="h-full d-flex flex-column align-items-center bg-danger text-white py-4 px-1 shadow-lg" style="width: 4rem;">
    <!-- Profilo utente -->
    <a href="{{ route('profile.edit') }}" 
       class="mb-3 d-flex flex-column align-items-center text-white text-decoration-none" 
       title="Profilo {{ auth()->user()->name }}">
        <i class="fas fa-user mb-1" style="font-size: 1.5rem;"></i>
        <small style="font-size: 0.7rem;">Profilo</small>
    </a>
    
    <!-- Ricerca globale -->
    <button class="mb-3 d-flex flex-column align-items-center text-white bg-transparent border-0" 
            title="Ricerca globale"
            data-bs-toggle="modal" 
            data-bs-target="#searchModal">
        <i class="fas fa-search mb-1" style="font-size: 1.5rem;"></i>
        <small style="font-size: 0.7rem;">Cerca</small>
    </button>
    
    <!-- Nuovo documento -->
    <div class="dropdown mb-3">
        <button class="d-flex flex-column align-items-center text-white bg-transparent border-0" 
                title="Nuovo documento" 
                data-bs-toggle="dropdown" 
                aria-expanded="false">
            <i class="fas fa-plus mb-1 text-warning" style="font-size: 1.5rem;"></i>
            <small style="font-size: 0.7rem;">Nuovo</small>
        </button>
        <ul class="dropdown-menu">
            @if(Route::has($panelPrefix . 'stabili.create'))
                <li><a class="dropdown-item" href="{{ route($panelPrefix . 'stabili.create') }}"><i class="fas fa-building me-2"></i>Stabile</a></li>
            @endif
            @if(Route::has($panelPrefix . 'soggetti.create'))
                <li><a class="dropdown-item" href="{{ route($panelPrefix . 'soggetti.create') }}"><i class="fas fa-user-plus me-2"></i>Soggetto</a></li>
            @endif
            @if(Route::has($panelPrefix . 'fornitori.create'))
                <li><a class="dropdown-item" href="{{ route($panelPrefix . 'fornitori.create') }}"><i class="fas fa-truck me-2"></i>Fornitore</a></li>
            @endif
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#"><i class="fas fa-file-invoice me-2"></i>Fattura</a></li>
            <li><a class="dropdown-item" href="#"><i class="fas fa-receipt me-2"></i>Ricevuta</a></li>
        </ul>
    </div>
    
    <!-- Notifiche -->
    <button class="mb-3 d-flex flex-column align-items-center text-white bg-transparent border-0 position-relative" 
            title="Notifiche"
            data-bs-toggle="modal" 
            data-bs-target="#notificationsModal">
        <i class="fas fa-bell mb-1" style="font-size: 1.5rem;"></i>
        <small style="font-size: 0.7rem;">Novità</small>
        <!-- Badge notifiche -->
        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning">
            3
            <span class="visually-hidden">notifiche non lette</span>
        </span>
    </button>
    
    <!-- Spacer -->
    <div class="flex-fill"></div>
    
    <!-- Impostazioni -->
    <a href="{{ Route::has($panelPrefix . 'impostazioni') ? route($panelPrefix . 'impostazioni') : '#' }}" 
       class="mb-3 d-flex flex-column align-items-center text-white text-decoration-none" 
       title="Impostazioni">
        <i class="fas fa-cog mb-1" style="font-size: 1.5rem;"></i>
        <small style="font-size: 0.7rem;">Setup</small>
    </a>
    
    <!-- Help -->
    <button class="d-flex flex-column align-items-center text-white bg-transparent border-0" 
            title="Aiuto e documentazione"
            data-bs-toggle="modal" 
            data-bs-target="#helpModal">
        <i class="fas fa-question-circle mb-1" style="font-size: 1.5rem;"></i>
        <small style="font-size: 0.7rem;">Help</small>
    </button>
</nav>

<!-- Modal Ricerca -->
<div class="modal fade" id="searchModal" tabindex="-1" aria-labelledby="searchModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="searchModalLabel">Ricerca globale</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <input type="text" class="form-control mb-3" placeholder="Cerca in tutto NetGesCon..." id="globalSearch">
                <div id="searchResults" class="list-group">
                    <div class="text-muted text-center py-3">Inizia a digitare per cercare...</div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal Notifiche -->
<div class="modal fade" id="notificationsModal" tabindex="-1" aria-labelledby="notificationsModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="notificationsModalLabel">Notifiche</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="list-group">
                    <div class="list-group-item">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">Nuovo aggiornamento disponibile</h6>
                            <small>3 giorni fa</small>
                        </div>
                        <p class="mb-1">È disponibile NetGesCon v0.7.1 con nuove funzionalità.</p>
                        <small>Sistema</small>
                    </div>
                    <div class="list-group-item">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">Scadenza rata in avvicinamento</h6>
                            <small>1 settimana fa</small>
                        </div>
                        <p class="mb-1">Condominio Roma Centro - rata di marzo in scadenza.</p>
                        <small>Amministrazione</small>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Chiudi</button>
                <button type="button" class="btn btn-primary">Segna tutto come letto</button>
            </div>
        </div>
    </div>
</div>

<!-- Modal Help -->
<div class="modal fade" id="helpModal" tabindex="-1" aria-labelledby="helpModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="helpModalLabel">Aiuto NetGesCon</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6">
                        <h6>Guide rapide</h6>
                        <ul class="list-unstyled">
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-play-circle me-2"></i>Primo accesso</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-play-circle me-2"></i>Creazione stabile</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-play-circle me-2"></i>Gestione condomini</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-play-circle me-2"></i>Fatturazione</a></li>
                        </ul>
                    </div>
                    <div class="col-md-6">
                        <h6>Supporto</h6>
                        <ul class="list-unstyled">
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-envelope me-2"></i>Contatta supporto</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-book me-2"></i>Documentazione</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-video me-2"></i>Video tutorial</a></li>
                            <li><a href="#" class="text-decoration-none"><i class="fas fa-comments me-2"></i>Community</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
