{{-- 
========================================
SIDEBAR MENU MODULARE NETGESCON
========================================
Sidebar completamente modulare con gestione permessi,
componenti separati e stili/JS esterni.

Struttura:
- Header (logo, data, news ticker)
- Notifiche e quick actions
- Menu navigation con permessi
- Footer con info utente

Autore: NetGesCon Development Team
Data: 2024
========================================
--}}

{{-- Include helpers per gestione permessi --}}
@include('components.menu.sections.menu-helpers')

{{-- Sidebar container principale --}}
<div class="netgescon-sidebar d-flex flex-column h-100" id="netgesconSidebar">
    
    {{-- Header con Logo, Data e News --}}
    @include('components.menu.sections.header')

    {{-- Notifiche e Quick Actions --}}
    @include('components.menu.sections.notifications')

    {{-- Menu Navigation principale --}}
    <nav class="sidebar-nav flex-fill overflow-auto" role="navigation" aria-label="Menu principale NetGesCon">
        <ul class="nav nav-pills flex-column p-2">
            
            {{-- Dashboard - Sempre visibile --}}
            @if(canUserAccessMenu('dashboard'))
                @include('components.menu.sections.dashboard')
            @endif
            
            {{-- Stabili - Solo amministratori e superiori --}}
            @if(canUserAccessMenu('stabili'))
                @include('components.menu.sections.stabili')
            @endif
            
            {{-- Condomini - Solo amministratori e superiori --}}
            @if(canUserAccessMenu('condomini'))
                @include('components.menu.sections.condomini')
            @endif
            
            {{-- Contabilità - Solo ruoli economici --}}
            @if(canUserAccessMenu('contabilita'))
                @include('components.menu.sections.contabilita')
            @endif
            
            {{-- Fiscale - Solo ruoli economici --}}
            @if(canUserAccessMenu('fiscale'))
                @include('components.menu.sections.fiscale')
            @endif
            
            {{-- Menu Semplici - Comunicazioni, tickets, etc --}}
            @if(canUserAccessAnyMenu(['comunicazioni', 'tickets', 'assemblee']))
                @include('components.menu.sections.menu-semplici')
            @endif
            
        </ul>
    </nav>

    {{-- Footer con info utente e versione --}}
    @include('components.menu.sections.footer')
    
</div>

{{-- Include CSS e JS esterni per la sidebar --}}
@push('styles')
    <link rel="stylesheet" href="{{ asset('css/sidebar.css') }}">
@endpush

@push('scripts')
    <script src="{{ asset('js/sidebar.js') }}"></script>
@endpush

{{-- CSS interno temporaneo --}}
<style>
/* NetGesCon Sidebar Styles */
.netgescon-sidebar {
    background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
    border-right: 2px solid #007bff;
    box-shadow: 2px 0 10px rgba(0,123,255,0.1);
    min-height: 100vh;
    width: 280px;
}

.netgescon-sidebar .nav-link {
    border-radius: 8px;
    margin: 2px 0;
    padding: 8px 12px;
    transition: all 0.3s ease;
}

.netgescon-sidebar .nav-link:hover {
    background-color: rgba(0,123,255,0.1);
    transform: translateX(5px);
}

.netgescon-sidebar .nav-link.active {
    background-color: #007bff !important;
    color: white !important;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,123,255,0.3);
}

.netgescon-sidebar .collapse .nav-link {
    padding: 6px 12px;
    font-size: 0.9em;
}

.netgescon-sidebar .collapse .nav-link:hover {
    background-color: rgba(0,123,255,0.05);
    color: #007bff;
}

/* Header styles */
.netgescon-sidebar .border-bottom {
    border-color: #007bff !important;
}

/* Footer styles */
.netgescon-sidebar .border-top {
    border-color: #007bff !important;
}

/* Dark mode support */
.dark .netgescon-sidebar {
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    border-color: #4b5563;
}

.dark .netgescon-sidebar .nav-link {
    color: #d1d5db;
}

.dark .netgescon-sidebar .nav-link:hover {
    background-color: rgba(55, 65, 81, 0.3);
    color: #d1d5db;
}

/* Responsive */
@media (max-width: 768px) {
    .netgescon-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        z-index: 1050;
        transition: left 0.3s ease;
    }
    
    .netgescon-sidebar.show {
        left: 0;
    }
}
</style>

{{-- JavaScript per funzionalità sidebar --}}
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Gestione toggle menu collassabili
    const collapseElements = document.querySelectorAll('[data-bs-toggle="collapse"]');
    collapseElements.forEach(element => {
        element.addEventListener('click', function() {
            const icon = this.querySelector('.fa-chevron-down, .fa-chevron-up');
            if (icon) {
                icon.classList.toggle('fa-chevron-down');
                icon.classList.toggle('fa-chevron-up');
            }
        });
    });

    // Gestione menu attivo
    const navLinks = document.querySelectorAll('.netgescon-sidebar .nav-link[href]');
    const currentPath = window.location.pathname;
    
    navLinks.forEach(link => {
        if (link.getAttribute('href') === currentPath) {
            link.classList.add('active');
            // Espandi il menu parent se è collassato
            const parentCollapse = link.closest('.collapse');
            if (parentCollapse) {
                parentCollapse.classList.add('show');
                const toggleButton = document.querySelector(`[href="#${parentCollapse.id}"]`);
                if (toggleButton) {
                    toggleButton.setAttribute('aria-expanded', 'true');
                }
            }
        }
    });

    // Aggiorna data e ora ogni minuto
    function updateDateTime() {
        const now = new Date();
        const dateElement = document.getElementById('current-date');
        const timeElement = document.getElementById('current-time');
        
        if (dateElement) {
            dateElement.textContent = now.toLocaleDateString('it-IT');
        }
        if (timeElement) {
            timeElement.textContent = now.toLocaleTimeString('it-IT', { hour: '2-digit', minute: '2-digit' });
        }
    }
    
    updateDateTime();
    setInterval(updateDateTime, 60000);

    // News ticker animation
    const newsTicker = document.querySelector('.news-ticker');
    if (newsTicker) {
        newsTicker.addEventListener('animationend', function() {
            this.style.animation = 'none';
            setTimeout(() => {
                this.style.animation = 'scroll-left 30s linear infinite';
            }, 50);
        });
    }

    // Aggiorna data e ora display
    function updateDateTimeDisplay() {
        const now = new Date();
        const options = {
            weekday: 'short',
            year: 'numeric',
            month: 'short',
            day: 'numeric',
            hour: '2-digit',
            minute: '2-digit'
        };
        const dateTimeDisplay = document.getElementById('datetime-display');
        if (dateTimeDisplay) {
            dateTimeDisplay.textContent = now.toLocaleDateString('it-IT', options);
        }
    }

    // Aggiorna ogni minuto
    updateDateTimeDisplay();
    setInterval(updateDateTimeDisplay, 60000);

    // News ticker animation
    function animateNews() {
        const newsText = document.getElementById('news-text');
        if (newsText) {
            const news = [
                '🌤️ Meteo: Sereno 18°C • 📈 FTSE MIB +0.5% • 🏛️ Nuove agevolazioni fiscali 2025',
                '⚡ BREAKING: Nuovo decreto condomini • 💰 EURO/USD 1.095 • 🏠 Mercato immobiliare +2.3%',
                '🎯 Scadenza F24: 16/01 • 📊 Inflazione 0.8% • 🔧 Bonus ristrutturazioni prorogato'
            ];
            
            let index = 0;
            setInterval(() => {
                index = (index + 1) % news.length;
                newsText.textContent = news[index];
            }, 10000);
        }
    }

    // Avvia animazione news
    animateNews();

    // Funzione per aprire pagina news
    function openNewsPage() {
        window.open('https://www.ansa.it/sito/notizie/economia/economia.html', '_blank');
    }
});
</script>
