@php
$appLogoSmall = \App\Models\AppSetting::getLogoSmallUrl();
$appName = \App\Models\AppSetting::getAppName() ?? 'Glastree';
@endphp
<!DOCTYPE html>
<html lang="it">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', e($appName))</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600;700&display=swap">
    @yield('styles')
</head>
<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <nav class="main-header navbar navbar-expand navbar-white navbar-light">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
                </li>
            </ul>
            <ul class="navbar-nav ml-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link" data-toggle="dropdown" href="#">
                        <i class="far fa-bell"></i>
                        @php $unread = Auth::user()->unreadNotificheCount() ?? 0 @endphp
                        @if($unread > 0)
                        <span class="badge badge-warning navbar-badge">{{ $unread }}</span>
                        @endif
                    </a>
                    <div class="dropdown-menu dropdown-menu-right">
                        <span class="dropdown-header">Notifiche ({{ $unread }})</span>
                        <div class="dropdown-divider"></div>
                        <a href="#" class="dropdown-item">Visualizza tutte</a>
                    </div>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link" data-toggle="dropdown" href="#">
                        <i class="fas fa-user"></i> {{ Auth::user()->name }}
                    </a>
                    <div class="dropdown-menu dropdown-menu-right">
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-user-cog mr-2"></i> Profilo
                        </a>
                        <div class="dropdown-divider"></div>
                        <form method="POST" action="{{ route('logout') }}">
                            @csrf
                            <button type="submit" class="dropdown-item">
                                <i class="fas fa-sign-out-alt mr-2"></i> Esci
                            </button>
                        </form>
                    </div>
                </li>
            </ul>
        </nav>

@php
$appLogoSmall = \App\Models\AppSetting::getLogoSmallUrl();
$appName = \App\Models\AppSetting::getAppName() ?? 'Glastree';
@endphp
        <aside class="main-sidebar sidebar-dark-primary elevation-4">
            <a href="{{ route('dashboard') }}" class="brand-link">
                @if($appLogoSmall)
                    <img src="{{ $appLogoSmall }}" alt="Logo" class="brand-image" style="max-height: 35px; max-width: 40px;">
                @else
                    <i class="fas fa-tree brand-image ml-3 mr-2"></i>
                @endif
                <span class="brand-text font-weight-light">{{ $appName }}</span>
            </a>

            <div class="sidebar">
                <nav class="mt-2">
                    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu">
                        <li class="nav-item">
                            <a href="{{ route('dashboard') }}" class="nav-link {{ request()->routeIs('dashboard') ? 'active' : '' }}">
                                <i class="nav-icon fas fa-tachometer-alt"></i>
                                <p>Dashboard</p>
                            </a>
                        </li>
                        @if(Auth::user()->canAccess('individui'))
                        <li class="nav-item">
                            <a href="{{ route('individui.index') }}" class="nav-link">
                                <i class="nav-icon fas fa-users"></i>
                                <p>Individui</p>
                            </a>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('gruppi'))
                        <li class="nav-item">
                            <a href="{{ route('gruppi.index') }}" class="nav-link">
                                <i class="nav-icon fas fa-folder"></i>
                                <p>Gruppi</p>
                            </a>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('documenti'))
                        <li class="nav-item">
                            <a href="{{ route('documenti.index') }}" class="nav-link">
                                <i class="nav-icon fas fa-file"></i>
                                <p>Documenti</p>
                            </a>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('eventi'))
                        <li class="nav-item has-treeview">
                            <a href="{{ route('eventi.calendar') }}" class="nav-link">
                                <i class="nav-icon fas fa-calendar"></i>
                                <p>Eventi <i class="right fas fa-angle-left" style="font-size: 0.8rem;"></i></p>
                            </a>
                            <ul class="nav nav-treeview">
                                <li class="nav-item">
                                    <a href="{{ route('eventi.calendar') }}" class="nav-link">
                                        <i class="nav-icon fas fa-calendar-alt"></i>
                                        <p>Calendario</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('eventi.index') }}" class="nav-link">
                                        <i class="nav-icon fas fa-list"></i>
                                        <p>Elenco</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('eventi.create') }}" class="nav-link">
                                        <i class="nav-icon fas fa-plus"></i>
                                        <p>Nuovo Evento</p>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('email') || Auth::user()->canAccess('mailing'))
                        <li class="nav-item has-treeview">
                            <a href="{{ route('email.index', 'inbox') }}" class="nav-link">
                                <i class="nav-icon fas fa-envelope"></i>
                                <p>Email <i class="right fas fa-angle-left" style="font-size: 0.8rem;"></i></p>
                            </a>
                            <ul class="nav nav-treeview">
                                @if(Auth::user()->canAccess('email'))
                                <li class="nav-item">
                                    <a href="{{ route('email.compose') }}" class="nav-link">
                                        <i class="nav-icon fas fa-plus"></i>
                                        <p>Nuova Email</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'inbox') }}" class="nav-link">
                                        <i class="nav-icon fas fa-inbox"></i>
                                        <p>In arrivo</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'starred') }}" class="nav-link">
                                        <i class="nav-icon fas fa-star"></i>
                                        <p>Preferiti</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'sent') }}" class="nav-link">
                                        <i class="nav-icon fas fa-paper-plane"></i>
                                        <p>Inviate</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'drafts') }}" class="nav-link">
                                        <i class="nav-icon fas fa-edit"></i>
                                        <p>Bozze</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'archive') }}" class="nav-link">
                                        <i class="nav-icon fas fa-archive"></i>
                                        <p>Archivio</p>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('email.index', 'trash') }}" class="nav-link">
                                        <i class="nav-icon fas fa-trash"></i>
                                        <p>Cestino</p>
                                    </a>
                                </li>
                                @endif
                            </ul>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('mailing'))
                        <li class="nav-item">
                            <a href="{{ route('mailing-liste.index') }}" class="nav-link">
                                <i class="nav-icon fas fa-list"></i>
                                <p>Mailing List</p>
                            </a>
                        </li>
                        @endif
                        @if(Auth::user()->canAccess('report'))
                        <li class="nav-item">
                            <a href="{{ route('report.index') }}" class="nav-link {{ request()->routeIs('report.*') ? 'active' : '' }}">
                                <i class="nav-icon fas fa-chart-bar"></i>
                                <p>Report</p>
                            </a>
                        </li>
                        @endif
                        @if(Auth::user()->canManage('settings'))
                        <li class="nav-item">
                            <a href="/impostazioni" class="nav-link {{ request()->is('impostazioni*') ? 'active' : '' }}">
                                <i class="nav-icon fas fa-cog"></i>
                                <p>Impostazioni</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="/admin/utenti" class="nav-link {{ request()->is('admin*') ? 'active' : '' }}">
                                <i class="nav-icon fas fa-users-cog"></i>
                                <p>Admin</p>
                            </a>
                        </li>
                        @endif
                    </ul>
                </nav>
            </div>
        </aside>

        <div class="content-wrapper" style="min-height: calc(100vh - 120px);">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0">@yield('page_title', 'Dashboard')</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                @yield('breadcrumbs')
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <div class="content">
                <div class="container-fluid">
                    {!! $slot ?? '' !!}
                    @yield('content')
                </div>
            </div>
        </div>

        <footer class="main-footer">
            <strong>{{ \App\Models\AppSetting::getFooterText() }}</strong>
            @if(\App\Models\AppSetting::shouldShowVersion() && \App\Models\AppSetting::getAppVersion())
                <span class="ml-2">v{{ \App\Models\AppSetting::getAppVersion() }}</span>
            @endif
        </footer>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>
    @yield('scripts')
</body>
</html>