<!-- Navbar Header -->
@php
    $karyawan = Auth::user()->karyawan;
@endphp


<nav class="app-header navbar navbar-expand bg-body">
    <div class="container-fluid">
        <!-- Left Navbar Links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-lte-toggle="sidebar" href="#" role="button">
                    <i class="bi bi-list fs-4"></i>
                </a>
            </li>
        </ul>

        <!-- Right Navbar Links -->
        <ul class="navbar-nav ms-auto">
            <!-- User Menu Dropdown -->
            <li class="nav-item dropdown user-menu">
                <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                    <img src="{{ Auth::user()->karyawan?->foto ? asset('storage/' . Auth::user()->karyawan->foto) : asset('default-user.png') }}"
                        class="user-image rounded-circle shadow" alt="User Image" />
                    <span class="d-none d-md-inline">{{ Auth::user()->karyawan?->nama ?? '-' }}</span>
                </a>

                <ul class="dropdown-menu dropdown-menu-lg dropdown-menu-end border-0 shadow rounded-4 overflow-hidden">
                    <!-- User Header -->
                    <li class="user-header text-center px-4 py-4 bg-light">
                        <img src="{{ $karyawan?->foto ? asset('storage/' . $karyawan->foto) : asset('default-user.png') }}"
                            class="rounded-circle shadow-sm border mb-3"
                            style="width: 90px; height: 90px; object-fit: cover;" alt="User Image" />
                        <p class="mb-0 fw-semibold fs-6">
                            {{ Auth::user()->name }}
                        </p>
                        <small class="text-muted">
                            {{ Auth::user()->karyawan->jabatan?->jabatan ?? '-' }}
                        </small>
                    </li>

                    <!-- Menu Body Links -->
                    <li>
                        <a href="{{ route('profile.edit') }}"
                            class="dropdown-item d-flex align-items-center gap-2 py-2">
                            <i class="bi bi-person-circle text-primary"></i>
                            <span>Edit Profile</span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ route('password.edit') }}"
                            class="dropdown-item d-flex align-items-center gap-2 py-2">
                            <i class="bi bi-shield-lock text-warning"></i>
                            <span>Reset Password</span>
                        </a>
                    </li>
                    <li>
                        <hr class="dropdown-divider my-1">
                    </li>

                    <!-- Logout Button -->
                    <li class="px-3 py-2">
                        <form method="POST" action="{{ route('logout') }}">
                            @csrf
                            <button type="submit" class="btn btn-danger w-100 rounded-3 fw-semibold">
                                <i class="bi bi-box-arrow-right me-1"></i> Logout
                            </button>
                        </form>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</nav>

<!-- Main Sidebar Container -->
<aside class="app-sidebar bg-body-secondary shadow" data-bs-theme="dark">
    <!-- Brand Logo -->
    <div class="sidebar-brand">
        <img src="/assets/img/pst.png" alt="GL Asuh Logo" class="brand-image "
            style="opacity: .9; max-height: 35px; width: auto;">
        <span class="brand-text fw-semibold ms-2">GL Asuh</span>
    </div>

    <!-- Sidebar Menu Wrapper -->
    <div class="sidebar-wrapper">
        <nav class="mt-2">
            <ul class="nav sidebar-menu flex-column" data-lte-toggle="treeview" role="navigation"
                aria-label="Main navigation" data-accordion="false" id="navigation">

                <li class="nav-item">
                    <a href="{{ Auth::user()->role == 'administrator'
                        ? route('administrator.dashboard')
                        : (Auth::user()->role == 'atasan'
                            ? route('dashboard.index')
                            : route('hasilPenilaian.index')) }}"
                        class="nav-link">
                        <i class="nav-icon bi bi-speedometer2"></i>
                        <p>Dashboard</p>
                    </a>
                </li>

                @if (auth()->user()->role === 'administrator' || auth()->user()->role === 'atasan')
                    <li
                        class="nav-item {{ request()->routeIs('laporan.index', 'hasilPenilaian.*') ? 'menu-open' : '' }}">
                        <a href="#"
                            class="nav-link {{ request()->routeIs('laporan.index', 'hasilPenilaian.*') ? 'active' : '' }}">
                            <i class="nav-icon bi bi-file-earmark-text"></i>
                            <p>
                                Laporan
                                <i class="nav-arrow bi bi-chevron-right"></i>
                            </p>
                        </a>

                        <ul class="nav nav-treeview">

                            <li class="nav-item">
                                <a href="{{ route('laporan.index') }}"
                                    class="nav-link {{ request()->routeIs('laporan.index') ? 'active' : '' }}">
                                    <p>Data Laporan Anak Asuh</p>
                                </a>
                            </li>

                            <li class="nav-item">
                                <a href="{{ route('hasilPenilaian.index') }}"
                                    class="nav-link {{ request()->routeIs('hasilPenilaian.*') ? 'active' : '' }}">
                                    <p>Hasil Penilaian</p>
                                </a>
                            </li>

                            @if (auth()->user()->role === 'atasan')
                                <li class="nav-item">
                                    <a href="{{ route('laporan.create') }}"
                                        class="nav-link {{ request()->routeIs('laporan.create') ? 'active' : '' }}">
                                        <p>Tambah Laporan</p>
                                    </a>
                                </li>
                            @endif

                        </ul>
                    </li>
                @endif

                @if (auth()->user()->role === 'administrator')
                    <li
                        class="nav-item {{ request()->routeIs('laporanv2.create', 'laporan.create') ? 'menu-open' : '' }}">
                        <a href="#"
                            class="nav-link {{ request()->routeIs('laporanv2.create', 'laporan.create') ? 'active' : '' }}">
                            <i class="nav-icon bi bi-plus-circle"></i>
                            <p>
                                Tambah Laporan
                                <i class="nav-arrow bi bi-chevron-right"></i>
                            </p>
                        </a>

                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="{{ route('laporan.create') }}"
                                    class="nav-link {{ request()->routeIs('laporan.create') ? 'active' : '' }}">
                                    <p>Laporan</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('laporanv2.create') }}"
                                    class="nav-link {{ request()->routeIs('laporanv2.create') ? 'active' : '' }}">
                                    <p>Laporan V2</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                @endif

                @if (auth()->user()->role === 'administrator')
                    <li
                        class="nav-item {{ request()->routeIs('karyawan.*', 'user.*', 'jabatan.*', 'departemen.*') ? 'menu-open' : '' }}">
                        <a href="#"
                            class="nav-link {{ request()->routeIs('karyawan.*', 'user.*', 'jabatan.*', 'departemen.*') ? 'active' : '' }}">
                            <i class="nav-icon bi bi-people"></i>
                            <p>
                                Manajemen
                                <i class="nav-arrow bi bi-chevron-right"></i>
                            </p>
                        </a>

                        <ul class="nav nav-treeview">

                            <li class="nav-item">
                                <a href="{{ route('karyawan.index') }}"
                                    class="nav-link {{ request()->routeIs('karyawan.*') ? 'active' : '' }}">
                                    <p>Karyawan</p>
                                </a>
                            </li>

                            <li class="nav-item">
                                <a href="{{ route('user.index') }}"
                                    class="nav-link {{ request()->routeIs('user.*') ? 'active' : '' }}">
                                    <p>User</p>
                                </a>
                            </li>

                            <li class="nav-item">
                                <a href="{{ route('jabatan.index') }}"
                                    class="nav-link {{ request()->routeIs('jabatan.*') ? 'active' : '' }}">
                                    <p>Jabatan</p>
                                </a>
                            </li>

                            <li class="nav-item">
                                <a href="{{ route('departemen.index') }}"
                                    class="nav-link {{ request()->routeIs('departemen.*') ? 'active' : '' }}">
                                    <p>Departemen</p>
                                </a>
                            </li>

                        </ul>
                    </li>
                @endif

                <li class="nav-item {{ request()->routeIs('flow.index', 'tutor.index') ? 'menu-open' : '' }}">
                    <a href="#"
                        class="nav-link {{ request()->routeIs('flow.index', 'tutor.index') ? 'active' : '' }}">
                        <i class="nav-icon bi bi-info-circle"></i>
                        <p>
                            Information
                            <i class="nav-arrow bi bi-chevron-right"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="{{ route('flow.index') }}"
                                class="nav-link {{ request()->routeIs('flow.index') ? 'active' : '' }}">
                                <p>Sistem Penilaian</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="{{ route('tutor.index') }}"
                                class="nav-link {{ request()->routeIs('tutor.index') ? 'active' : '' }}">
                                <p>Tutorial Aplikasi</p>
                            </a>
                        </li>
                    </ul>
                </li>

            </ul>
        </nav>
    </div>


    <div class="sidebar-footer text-center ">
        <img src="{{ asset('assets/img/pst_hebat.png') }}" class="rounded " style="width: 230px;" alt="Logo PST">

    </div>


</aside>
