{{-- <style>
    .sidebar-nav,
    .sidebar-nav *:not(ul, li) {
        overflow: auto !important;
    }
</style> --}}

<aside class="position-fixed bg-white topBar w-100 bg-light pt-4 px-4 shadow-lg" id="top-bar"
    style=";min-height: 70px;z-index:9;left:0;user-select: none;">
    <nav class="sidebar-nav scroll-sidebar " id="top-bar-content">
        <ul id="sidebarnav" class="d-flex flex-nowrap gap-4 justify-content-xl-center ">
            <li class="sidebar-item">
                <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                    href="{{ route('dashboard') }}" aria-expanded="false">
                    <span><i class="ti ti-dashboard"></i></span>
                    <span class="hide-menu">DASHBOARD</span>
                </a>
            </li>

            {{-- master data --}}
            @php
                $hasMasterDataAccess =
                    request()->routeIs('users.*') ||
                    request()->routeIs('roles.*') ||
                    request()->routeIs('actions.*') ||
                    request()->routeIs('locations.*') ||
                    request()->routeIs('manufactures.*') ||
                    PermissionHelper::hasPermission('users')->read ||
                    PermissionHelper::hasPermission('roles')->read ||
                    PermissionHelper::hasPermission('actions')->read ||
                    PermissionHelper::hasPermission('locations')->read ||
                    PermissionHelper::hasPermission('manufactures')->read;
            @endphp

            <li class="dropdown sidebar-item">
                <div class="dropdown">
                    @if ($hasMasterDataAccess)
                        @php
                            // cek apakah salah satu route master data sedang aktif
                            $isMasterActive =
                                request()->routeIs('users.*') ||
                                request()->routeIs('roles.*') ||
                                request()->routeIs('actions.*') ||
                                request()->routeIs('locations.*') ||
                                request()->routeIs('manufactures.*');
                        @endphp

                        <button
                            class="btn btn-outline-primary border-0 dropdown-toggle {{ $isMasterActive ? 'active' : '' }}"
                            type="button" data-bs-toggle="dropdown" aria-expanded="false">
                            MASTER DATA
                        </button>
                    @endif
                    <ul class="dropdown-menu overflow-auto" style="max-height: calc(100vh - 155px)">
                        @if (PermissionHelper::hasPermission('users')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('users.index') }}" aria-expanded="false">
                                    <span><i class="ti ti-user"></i></span>
                                    <span class="hide-menu">User</span>
                                </a>
                            </li>
                        @endif
                        {{-- @if (PermissionHelper::hasPermission('aprrove')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('aprrove.index') }}" aria-expanded="false">
                                    <span><i class="fas fa-clock"></i></span>
                                    <span class="hide-menu">Approve</span>
                                </a>
                            </li>
                        @endif --}}
                        @if (PermissionHelper::hasPermission('roles')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('roles.index') }}" aria-expanded="false">
                                    <span><i class="ti ti-settings"></i></span>
                                    <span class="hide-menu">Role</span>
                                </a>
                            </li>
                        @endif
                        @if (PermissionHelper::hasPermission('actions')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('actions.index') }}" aria-expanded="false">
                                    <span><i class="ti ti-settings"></i></span>
                                    <span class="hide-menu">Action</span>
                                </a>
                            </li>
                        @endif
                        @if (PermissionHelper::hasPermission('locations')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('locations.index') }}" aria-expanded="false">
                                    <span><i class="ti ti-map-pin"></i></span>
                                    <span class="hide-menu">Location</span>
                                </a>
                            </li>
                        @endif
                        @if (PermissionHelper::hasPermission('status-checklist')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('status-checklist.index') }}" aria-expanded="false">
                                    <span><i class="ti ti-map-pin"></i></span>
                                    <span class="hide-menu">Status Checklist</span>
                                </a>
                            </li>
                        @endif
                        @if (PermissionHelper::hasPermission('shift')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('shift.index') }}" aria-expanded="false">
                                    <i class="fas fa-clock"></i>
                                    <span class="hide-menu">Shift</span>
                                </a>
                            </li>
                        @endif

                        @if (PermissionHelper::hasPermission('manufactures')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('manufactures.index') }}" aria-expanded="false">
                                    <span><i class="fa-solid fa-industry"></i></span>
                                    <span class="hide-menu">Manufacture</span>
                                </a>
                            </li>
                        @endif
                    </ul>
                </div>
            </li>

            @if (PermissionHelper::hasPermission('unit-type')->read)
                <li class="sidebar-item">
                    <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                        href="{{ route('unit-type.index') }}" aria-expanded="false">
                        <span><i class="fa-solid fa-clipboard-list"></i></span>
                        <span class="hide-menu">Unit Type</span>
                    </a>
                </li>
            @endif
            @if (PermissionHelper::hasPermission('units')->read)
                <li class="sidebar-item">
                    <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                        href="{{ route('units.index') }}" aria-expanded="false">
                        <span><i class="fa-solid fa-clipboard-list"></i></span>
                        <span class="hide-menu">Unit List</span>
                    </a>
                </li>
            @endif
            @if (PermissionHelper::hasPermission('checklist')->read)
                <li class="sidebar-item">
                    <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                        href="{{ route('checklist.index') }}" aria-expanded="false">
                        <span><i class="fas fa-clipboard"></i></span>
                        <span class="hide-menu">Data Checklist</span>
                    </a>
                </li>
            @endif

            @php
                $reportAccess =
                    request()->routeIs('daily-report.*') || PermissionHelper::hasPermission('daily-report')->read;

            @endphp

            <li class="dropdown sidebar-item">
                <div class="dropdown">
                    @if ($reportAccess)
                        @php
                            $isReportActive = request()->routeIs('daily-report.*');
                        @endphp

                        <button
                            class="btn btn-outline-primary border-0 dropdown-toggle {{ $isReportActive ? 'active' : '' }}"
                            type="button" data-bs-toggle="dropdown" aria-expanded="false">
                            Isi Checklist
                        </button>
                    @endif
                    <ul class="dropdown-menu overflow-auto" style="max-height: calc(100vh - 155px)">
                        @if (PermissionHelper::hasPermission('daily-report')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('daily-report.index') }}" aria-expanded="false">
                                    <span><i class="fas fa-sticky-note"></i></span>
                                    <span class="hide-menu">Isi Checklist Harian</span>
                                </a>
                            </li>
                        @endif
                        @if (PermissionHelper::hasPermission('monthly-report')->read)
                            <li class="dropdown-item sidebar-item">
                                <a class="sidebar-link" href="{{ route('monthly-report.index') }}" aria-expanded="false">
                                    <span><i class="fas fa-sticky-note"></i></span>
                                    <span class="hide-menu">Laporan Checklist Bulanan</span>
                                </a>
                            </li>
                        @endif
                    </ul>
                </div>
            </li>
            @if (PermissionHelper::hasPermission('swp')->read)
                <li class="sidebar-item">
                    <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                        href="{{ route('swp.index') }}" aria-expanded="false">
                        <span><i class="fas fa-hard-hat"></i></span>
                        <span class="hide-menu">SWP</span>
                    </a>
                </li>
            @endif
            @if (PermissionHelper::hasPermission('stbm')->read)
                <li class="sidebar-item">
                    <a class="sidebar-link btn btn-outline-primary border-0" style="padding-block: 5px"
                        href="{{ route('stbm.index') }}" aria-expanded="false">
                        <span><i class="fas fa-hard-hat"></i></span>
                        <span class="hide-menu">TBM</span>
                    </a>
                </li>
            @endif
        </ul>
    </nav>
</aside>
