<header class="sticky-top main-navbar">
    <div class="container">
        <!-- Sidebar Toggle Button in Header for Large Screens -->
        <button class="btn btn-primary sidebar-toggle d-none d-lg-block" aria-label="Toggle sidebar">
            <i class="fa fa-chevron-left"></i>
        </button>

        <nav class="navbar navbar-expand-lg navbar-light">
            <div class="container-fluid">
                <!-- Sidebar Toggle Button in Header for Small Screens -->
                <button class="btn btn-primary sidebar-toggle d-none d-lg-none" aria-label="Toggle sidebar">
                    <i class="fa fa-chevron-left"></i>
                </button>
                <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas"
                    data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar" aria-expanded="false"
                    aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <a class="navbar-brand" href="index.php">
                    <img src="./assets/image/logo.png" alt="" class="img-fluid">
                </a>
                <div class="collapse navbar-collapse d-none d-lg-block" id="navbarNav">
                    <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link p-0" href="index.php">
                                <i class="fa fa-home text-center"
                                    style="padding: 5px 10px; font-size: 20px; width: 40px;color: #fff;"></i>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link p-0" href="profile.php">
                                <i class="fa fa-user text-center"
                                    style="background: #fff; padding: 5px; border: 2px solid #0b5990; border-radius: 50%; font-size: 16px; width: 30px;color: #1d7a85;"></i>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link p-0" href="#logoutModal" data-bs-toggle="modal">
                                <i class="fa fa-sign-out"
                                    style="background: #fff;padding: 5px;border: 2px solid #0b5990;border-radius: 50%;/* font-size: 16px; *//* width: 30px; */color: #1d7a85;"></i>
                            </a>
                        </li>
                    </ul>
                </div>
                <!-- Offcanvas Navbar (for small screens) -->
                <div class="offcanvas offcanvas-start d-lg-none" tabindex="-1" id="offcanvasNavbar"
                    aria-labelledby="offcanvasNavbarLabel">
                    <div class="offcanvas-body">
                        <button type="button" class="btn-close btn-nav-close" data-bs-dismiss="offcanvas"
                            aria-label="Close"></button>
                        <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                            <!--<li class="nav-item">
                                <a class="nav-link active" aria-current="page" href="index.php">Home</a>
                            </li>-->
                            <li class="nav-item">
                                <a class="nav-link" href="view-admin.php">Admin</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="view-teacher.php">Teacher</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="view-student.php">Student</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#logoutModal" data-bs-toggle="modal"> Exit Recycle <i
                                        class="fa fa-sign-out"></i></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <!-- Placeholder for User Profile Icon in Mobile View -->
                <a class="navbar-brand d-block d-md-none" href="profile.php" style="width: 0;">
                    <i class="fa fa-user text-center"
                        style="background: #fff; padding: 5px; border: 2px solid #0b5990; border-radius: 50%; font-size: 16px; width: 30px;"></i>
                </a>
            </div>
        </nav>
    </div>
</header>

<!-- Sidebar (Desktop View) -->
<div class="sidebar d-none d-lg-block">
    <ul class="sidebar-menu">
        <li class="sidebar-item">
            <a href="index.php" class="sidebar-link">
                <i class="fa fa-home"></i>
                <span class="sidebar-text">Home</span>
            </a>
        </li>
        <li class="sidebar-item">
            <a href="view-admin.php" class="sidebar-link">
                <i class="fa fa-user"></i>
                <span class="sidebar-text">Admin</span>
            </a>
        </li>
        <li class="sidebar-item">
            <a href="view-teacher.php" class="sidebar-link">
                <i class="fa fa-chalkboard-teacher"></i>
                <span class="sidebar-text">Teacher</span>
            </a>
        </li>
        <li class="sidebar-item">
            <a href="view-student.php" class="sidebar-link">
                <i class="fa fa-graduation-cap"></i>
                <span class="sidebar-text">Student</span>
            </a>
        </li>
        <li class="sidebar-item">
            <a href="view-ad.php" class="sidebar-link">
                <i class="fa fa-ad"></i>
                <span class="sidebar-text">AD</span>
            </a>
        </li>
        <li class="sidebar-item">
            <a href="view-notice.php" class="sidebar-link">
                <i class="fa fa-bell"></i>
                <span class="sidebar-text">Notice</span>
            </a>
        </li>
    </ul>
</div>

<!-- Logout Modal -->
<div class="modal fade" id="logoutModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Leave Recycle?</h5>
                <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Select "Exit" below if you are ready to leav recycle.
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-bs-dismiss="modal">Cancel</button>
                <a class="btn btn-primary" href="../index.php">Exit</a>
            </div>
        </div>
    </div>
</div>




<script>
document.addEventListener('DOMContentLoaded', function() {
    const sidebar = document.querySelector('.sidebar');
    const sidebarToggle = document.querySelectorAll('.sidebar-toggle');

    // Toggle sidebar expand/collapse
    sidebarToggle.forEach(button => {
        button.addEventListener('click', function() {
            sidebar.classList.toggle('expanded');
            adjustInnerBody(); // Adjust inner-body size when sidebar expands or collapses
        });
    });

    // Close sidebar when navbar toggler is clicked (on smaller screens)
    const navbarToggle = document.querySelector('.navbar-toggler');
    navbarToggle.addEventListener('click', function() {
        sidebar.classList.remove('expanded');
        adjustInnerBody(); // Adjust inner-body size when sidebar is collapsed via navbar toggler
    });

    // Handle sidebar dropdowns on hover (desktop only)
    const sidebarItems = document.querySelectorAll('.sidebar-item');
    sidebarItems.forEach(item => {
        const submenu = item.querySelector('.sidebar-submenu');
        item.addEventListener('mouseenter', function() {
            if (window.innerWidth >= 992) { // Only for desktop view
                submenu.style.display = 'block';
                adjustInnerBody(); // Adjust inner-body size when submenu opens
            }
        });
        item.addEventListener('mouseleave', function() {
            if (window.innerWidth >= 992) { // Only for desktop view
                submenu.style.display = 'none';
                adjustInnerBody(); // Adjust inner-body size when submenu closes
            }
        });
    });

    // Function to adjust inner-body size based on sidebar's expanded state
    function adjustInnerBody() {
        const innerBody = document.getElementById('inner-body');
        const sidebarWidth = sidebar.offsetWidth;
        const windowWidth = window.innerWidth;
        const gap = 10;

        if (windowWidth >= 992) { // Only adjust for desktop view
            if (sidebar.classList.contains('expanded')) {
                innerBody.style.marginLeft = `${sidebarWidth}px`;
            } else {
                innerBody.style.marginLeft = `${sidebarWidth}px`;
            }
        } else {
            // Reset margin-left for smaller screens
            innerBody.style.marginLeft = '0';
        }
    }

    // Call adjustInnerBody initially and on window resize
    adjustInnerBody(); // Initial adjustment
    window.addEventListener('resize', adjustInnerBody); // Adjust on resize
});
</script>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const dropdowns = document.querySelectorAll('.navbar-nav .dropdown-toggle');

    // Function to handle opening and closing of dropdowns on mobile
    const handleDropdownClick = function(e) {
        if (window.innerWidth < 992) { // Check if the viewport is less than 992px
            e.preventDefault();
            const menu = this.nextElementSibling;
            const isOpen = menu.classList.contains('show');

            // Close all other open dropdowns
            document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach(openDropdown => {
                if (openDropdown !== menu) {
                    openDropdown.classList.remove('show');
                    openDropdown.previousElementSibling.setAttribute('aria-expanded', 'false');
                }
            });

            // Toggle the current dropdown
            menu.classList.toggle('show', !isOpen);
            this.setAttribute('aria-expanded', !isOpen);
        }
    };

    dropdowns.forEach(dropdown => {
        dropdown.addEventListener('click', handleDropdownClick);
    });

    // Close dropdowns when clicking outside on mobile
    document.addEventListener('click', function(e) {
        if (window.innerWidth < 992 && !e.target.closest('.dropdown-toggle')) {
            document.querySelectorAll('.navbar-nav .dropdown-menu.show').forEach(openDropdown => {
                openDropdown.classList.remove('show');
                openDropdown.previousElementSibling.setAttribute('aria-expanded', 'false');
            });
        }
    });
});
</script>