<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }} - NetGesCon</title>

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.bunny.net">
    <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUa1y9lwNwQG0JI2V7B8JJwdq7YJ7ZJw3B8h9hXzpZ7E6F5v3Xp7a8rBQE4x" crossorigin="anonymous">

    <!-- FontAwesome (per icone menu) -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-papm6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q6Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-OgGKvMK4Xfd3LX2p2E9B6lQTeCHKq6k0N8jbJJLMWKXMZ4Br1RrLEjzz2ZKdG8aH" crossorigin="anonymous"></script>
</head>
<body class="bg-light">
    <div class="d-flex vh-100">
        <!-- DESKTOP: Colonna launcher (icone) - nascosta su mobile -->
        <aside class="d-none d-md-flex bg-danger shadow-sm" style="width: 4rem;">
            @include('components.menu.launcher')
        </aside>

        <!-- DESKTOP: Sidebar principale - nascosta su mobile, mostrata con toggle -->
        <aside class="d-none d-md-flex bg-warning border-end border-primary border-4 shadow position-relative" style="width: 14rem;" id="sidebar-menu">
            @include('components.menu.sidebar')
            <!-- Pulsante per ridimensionare/nascondere su desktop -->
            <button id="toggle-sidebar" class="position-absolute top-0 end-0 btn btn-primary btn-sm rounded-circle shadow" style="transform: translateX(50%); top: 0.5rem;">
                <i class="fas fa-chevron-left"></i>
            </button>
        </aside>

        <!-- DESKTOP: Colonna separatrice sottile -->
        <aside class="d-none d-md-flex bg-primary d-flex align-items-center justify-content-center" style="width: 0.75rem;">
            <button id="show-sidebar" class="btn btn-link text-white p-0" style="display:none">
                <i class="fas fa-chevron-right"></i>
            </button>
        </aside>

        <!-- MOBILE: Overlay sidebar (nascosta di default) -->
        <div class="offcanvas offcanvas-start bg-warning" tabindex="-1" id="mobile-sidebar" aria-labelledby="mobileSidebarLabel">
            <div class="offcanvas-header border-bottom border-primary">
                <h5 class="offcanvas-title" id="mobileSidebarLabel">Menu</h5>
                <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
            </div>
            <div class="offcanvas-body p-0">
                @include('components.menu.sidebar')
            </div>
        </div>

        <!-- Main Content -->
        <div class="flex-fill d-flex flex-column">
            <!-- Navigation con hamburger menu per mobile -->
            <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm border-bottom">
                <div class="container-fluid">
                    <!-- MOBILE: Hamburger menu button -->
                    <button class="btn btn-outline-primary d-md-none me-3" type="button" data-bs-toggle="offcanvas" data-bs-target="#mobile-sidebar" aria-controls="mobile-sidebar">
                        <i class="fas fa-bars"></i>
                    </button>
                    
                    <!-- Logo -->
                    <a class="navbar-brand fw-bold" href="{{ auth()->user()->hasRole('super-admin') ? route('superadmin.dashboard') : route('admin.dashboard') }}">
                        NetGesCon
                        @if(auth()->user()->hasRole('super-admin'))
                            <span class="badge bg-danger ms-1">Super</span>
                        @elseif(auth()->user()->hasRole('amministratore'))
                            <span class="badge bg-primary ms-1">Admin</span>
                        @endif
                    </a>

                    <!-- Settings Dropdown (sempre visibile) -->
                    <div class="d-flex align-items-center">
                        <!-- Dark Mode Toggle -->
                        <button id="dark-mode-toggle" class="btn btn-outline-secondary me-3" title="Modalità scura">
                            <i class="fas fa-moon" id="dark-icon"></i>
                        </button>

                        <!-- User dropdown -->
                        <div class="dropdown">
                            <button class="btn btn-outline-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-user me-1"></i>
                                {{ Auth::user()->name }}
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item" href="{{ route('profile.edit') }}">
                                    <i class="fas fa-user-edit me-2"></i>{{ __('Profile') }}
                                </a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li>
                                    <form method="POST" action="{{ route('logout') }}" class="m-0">
                                        @csrf
                                        <button type="submit" class="dropdown-item text-danger">
                                            <i class="fas fa-sign-out-alt me-2"></i>{{ __('Log Out') }}
                                        </button>
                                    </form>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </nav>

            <!-- Page Content -->
            <main class="flex-fill bg-light p-4">
                @yield('content')
            </main>
        </div>
    </div>

    <!-- JavaScript per gestione responsive e dark mode -->
    <script>
        // Dark mode toggle
        document.getElementById('dark-mode-toggle').addEventListener('click', function() {
            document.body.classList.toggle('bg-dark');
            document.body.classList.toggle('text-light');
            const icon = document.getElementById('dark-icon');
            icon.classList.toggle('fa-moon');
            icon.classList.toggle('fa-sun');
            
            // Salva preferenza
            const isDark = document.body.classList.contains('bg-dark');
            localStorage.setItem('darkMode', isDark ? 'enabled' : 'disabled');
        });

        // Carica preferenza dark mode
        if (localStorage.getItem('darkMode') === 'enabled') {
            document.body.classList.add('bg-dark', 'text-light');
            document.getElementById('dark-icon').classList.replace('fa-moon', 'fa-sun');
        }

        // Toggle desktop sidebar
        document.getElementById('toggle-sidebar').addEventListener('click', function() {
            const sidebar = document.getElementById('sidebar-menu');
            const showBtn = document.getElementById('show-sidebar');
            
            sidebar.style.display = 'none';
            showBtn.style.display = 'block';
        });

        document.getElementById('show-sidebar').addEventListener('click', function() {
            const sidebar = document.getElementById('sidebar-menu');
            const showBtn = document.getElementById('show-sidebar');
            
            sidebar.style.display = 'flex';
            showBtn.style.display = 'none';
        });
    </script>
</body>
</html>
