@php
    $payrollCompanyId = auth()->user()->company_id;
    $usePayrollModule = \App\Models\Setting::get($payrollCompanyId, 'use_payroll_module', '0') === '1';
    $canViewPayroll = auth()->user()->hasPermission('payroll', 'view');
    $canViewEmployees = auth()->user()->hasPermission('masters', 'view');

    $payrollMenuItems = [];
    if ($canViewEmployees) {
        $payrollMenuItems[] = ['route' => 'masters.employees.index', 'pattern' => 'masters.employees.*', 'icon' => 'bi-people', 'label' => 'Employees'];
    }
    if ($canViewPayroll) {
        $payrollMenuItems = array_merge($payrollMenuItems, [
            ['route' => 'payroll.departments.index', 'pattern' => 'payroll.departments.*', 'icon' => 'bi-diagram-3', 'label' => 'Departments'],
            ['route' => 'payroll.designations.index', 'pattern' => 'payroll.designations.*', 'icon' => 'bi-person-badge', 'label' => 'Designations'],
            ['route' => 'payroll.projects.index', 'pattern' => 'payroll.projects.*', 'icon' => 'bi-kanban', 'label' => 'Projects'],
            ['route' => 'payroll.branches.index', 'pattern' => 'payroll.branches.*', 'icon' => 'bi-building', 'label' => 'Branches'],
            ['route' => 'payroll.salary-components.index', 'pattern' => 'payroll.salary-components.*', 'icon' => 'bi-cash-coin', 'label' => 'Salary Components'],
            ['route' => 'payroll.payroll-sheet.index', 'pattern' => 'payroll.payroll-sheet.*', 'icon' => 'bi-table', 'label' => 'Payroll Sheet'],
            ['route' => 'payroll.journal.index', 'pattern' => 'payroll.journal.*', 'icon' => 'bi-journal-text', 'label' => 'Payroll Journal'],
            ['route' => 'payroll.pay-slip.index', 'pattern' => 'payroll.pay-slip.*', 'icon' => 'bi-receipt', 'label' => 'Pay Slip'],
            ['route' => 'payroll.bank-transfer-letter.index', 'pattern' => 'payroll.bank-transfer-letter.*', 'icon' => 'bi-envelope-paper', 'label' => 'Bank Transfer Letter'],
        ]);
    }
@endphp

@if($usePayrollModule)
    @if(($variant ?? 'sidebar') === 'dropdown')
        @foreach($payrollMenuItems as $item)
        <li>
            <a class="dropdown-item {{ request()->routeIs($item['pattern']) ? 'active' : '' }}" href="{{ route($item['route']) }}">
                <i class="bi {{ $item['icon'] }} me-2"></i>{{ $item['label'] }}
            </a>
        </li>
        @endforeach
    @else
        @foreach($payrollMenuItems as $item)
        <a href="{{ route($item['route']) }}"
           class="nav-item-link {{ request()->routeIs($item['pattern']) ? 'active' : '' }}">
            <i class="bi {{ $item['icon'] }}"></i><span>{{ $item['label'] }}</span>
        </a>
        @endforeach
    @endif
@endif
