<?php
// sidebar.php

// Get user role and department from session
$role = $_SESSION['role'] ?? '';
$department = $_SESSION['department'] ?? '';

// Define sidebar content based on role and department
function getSidebarContent($role, $department) {
    $sidebarContent = '';

    // Common sidebar for all users
    $sidebarContent .= '<nav class="sidebar bg-dark text-white" style="max-height: 100vh; overflow-y: auto;">';
    $sidebarContent .= '<div class="sidebar-header d-flex justify-content-start p-3">';
    $sidebarContent .= '<img src="uploads/logo/smartsync_logo.svg" alt="Logo" class="sidebar-logo img-fluid" style="max-width: 150px;">';
    $sidebarContent .= '</div>';
    $sidebarContent .= '<ul class="nav flex-column">';

    // Default Dashboard link for all users
    $sidebarContent .= '<li class="nav-item"><a href="dashboard.php" class="nav-link text-white">Dashboard</a></li>';

    // Check for specific role and department combinations for Planning Department
    if ($role == 'Confidential' && $department == 'Planning') {
        // Confidential role in Planning department
      
        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#clubs" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="clubs">Club Registration</a>';
        $sidebarContent .= '<ul class="collapse" id="clubs">';
        $sidebarContent .= '<li><a href="clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cdfApplications" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">CDF Applications</a>';
        $sidebarContent .= '<ul class="collapse" id="cdfApplications">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Cash for Work</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Accounting</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Inventory</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Clients</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Projects</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Reports</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Documents</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Suppliers</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Permits</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';

        $sidebarContent .= '<li class="nav-item">';
        $sidebarContent .= '<a href="#cashforwork" class="nav-link text-white" data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="cdfApplications">Settings</a>';
        $sidebarContent .= '<ul class="collapse" id="cashforwork">';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/clubs.php" class="nav-link text-white ps-3">Clubs</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';
    }

    if ($role == 'Initiator' && $department == 'Planning') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="business_permits.php" class="nav-link text-white">CDF Applications</a></li>';
    }

    if ($role == 'Auditor' && $department == 'Institutional') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="business_permits.php" class="nav-link text-white">Business Levies</a></li>';
    }
    if ($role == 'Approver' && $department == 'Institutional') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="approve_permits.php" class="nav-link text-white">Business Levies</a></li>';
    }

    if ($role == 'Legal' && $department == 'Institutional') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="business_permits.php" class="nav-link text-white">Business Levies</a></li>';
    }
    if ($role == 'Initiator' && $department == 'Finance') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="business_permits.php" class="nav-link text-white">Business Registration</a></li>';
    }

    if ($role == 'Initiator' && $department == 'Engineering') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="health_permits.php" class="nav-link text-white">Health Permits</a></li>';
    }
















    if ($role == 'Availability' && $department == 'Planning') {
        // Availability role in Planning department
        $sidebarContent .= '<li class="nav-item dropdown">';
        $sidebarContent .= '<a href="#" class="nav-link text-white dropdown-toggle" id="planningDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Planning</a>';
        $sidebarContent .= '<ul class="dropdown-menu bg-dark" aria-labelledby="planningDropdown">';
        $sidebarContent .= '<li><a href="planning/approve_clubs.php" class="dropdown-item text-white">Approve Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/approve_grants.php" class="dropdown-item text-white">Approve Grants</a></li>';
        $sidebarContent .= '<li><a href="planning/approve_loans.php" class="dropdown-item text-white">Approve Loans</a></li>';
        $sidebarContent .= '<li><a href="planning/approve_projects.php" class="dropdown-item text-white">Approve Projects</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';
    }

    if ($role == 'Integrity' && $department == 'Planning') {
        // Integrity role in Planning department
        $sidebarContent .= '<li class="nav-item dropdown">';
        $sidebarContent .= '<a href="#" class="nav-link text-white dropdown-toggle" id="planningDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Planning</a>';
        $sidebarContent .= '<ul class="dropdown-menu bg-dark" aria-labelledby="planningDropdown">';
        $sidebarContent .= '<li><a href="planning/review_clubs.php" class="dropdown-item text-white">Review Clubs</a></li>';
        $sidebarContent .= '<li><a href="planning/review_grants.php" class="dropdown-item text-white">Review Grants</a></li>';
        $sidebarContent .= '<li><a href="planning/review_loans.php" class="dropdown-item text-white">Review Loans</a></li>';
        $sidebarContent .= '<li><a href="planning/review_projects.php" class="dropdown-item text-white">Review Projects</a></li>';
        $sidebarContent .= '</ul>';
        $sidebarContent .= '</li>';
    }

    if ($role == 'Confidential' && $department == 'Finance') {
        // Confidential role in Finance department
        $sidebarContent .= '<li class="nav-item"><a href="business_permits.php" class="nav-link text-white">Business Registration</a></li>';
    }
    

    // Logout link for all users
    $sidebarContent .= '<li class="nav-item"><a href="logout.php" class="nav-link text-white">Logout</a></li>';

    // Close the unordered list
    $sidebarContent .= '</ul>';
    // Close the sidebar container
    $sidebarContent .= '</div>';
    // Close the sidebar
    $sidebarContent .= '</nav>';

    return $sidebarContent;
}

// Output the sidebar content based on the user's role and department
echo getSidebarContent($role, $department);
?>

<!-- Add these script tags to enable the dropdown functionality -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-beta2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>


<!-- Add the custom CSS to style the scrollbar -->
<style>
/* Style the scrollbar */
.sidebar {
    max-height: 100vh;
    overflow-y: auto;
}

/* Custom scrollbar */
.sidebar::-webkit-scrollbar {
    width: 8px; /* Width of the scrollbar */
}

.sidebar::-webkit-scrollbar-track {
    background: #333; /* Dark background for the track */
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: #555; /* Lighter dark color for the thumb */
    border-radius: 10px; /* Rounded corners for the thumb */
    border: 2px solid #333; /* Match border to the track color */
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: #888; /* Lighter color on hover */
}

/* For Firefox */
.sidebar {
    scrollbar-width: thin; /* Thin scrollbar */
    scrollbar-color: #555 #333; /* thumb color and track color */
}
</style>

