<?php 
    // Ambil level user sekali saja di awal untuk efisiensi
    $userLevel = session()->get('level');
    $isTSM = in_array($userLevel, [0, 1, 2]); // Super user / TSM
    $isPS  = ($userLevel == '4');             // PS
?>
<aside class="left-sidebar">
    <div class="scroll-sidebar">
        <nav class="sidebar-nav">
            <ul id="sidebarnav">
                
                <li class="nav-small-cap">--- MAIN MENU</li>
                <li> <a class="waves-effect waves-dark" href='<?=base_url();?>' aria-expanded="false"> <i class="fas fa-tachometer-alt"></i> <span class='hide-menu'>Dashboard</span></a></li>
                
                <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fas fa-cow"></i> <span class="hide-menu">Activity</span></a>
                    <ul aria-expanded="true" class="collapse">
                        <li><a href="<?=base_url();?>activities/create">New Activity</a></li>
                        <li><a href="<?=base_url();?>activities">Activity List</a></li>
                        <li><a href="<?=base_url();?>activities/count">Activity Count</a></li>
                        <li><a href="<?=base_url();?>activities/export">Activity Export</a></li>
                    </ul>
                </li>
                
                <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-cart-flatbed"></i> <span class="hide-menu"> Inventory</span></a>
                    <ul aria-expanded="true" class="collapse">
                        <li><a href="<?=base_url();?>invtrans/create">New Transactions</a></li>
                        <li><a href="<?=base_url();?>invtrans/user/<?=$_SESSION['userid'];?>">Transactions</a></li>
                        <?php if ($isTSM): // Hanya TSM yang bisa melihat Sparepart Usage ?>
                            <li><a href="<?=base_url();?>invtrans/reportusage/">Sparepart Usage</a></li>
                        <?php endif; ?>
                    </ul>
                </li>
                
                <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-bug"></i><span class='hide-menu'>Bug N Feature</span> </a> 
                    <ul aria-expanded="false" class="collapse">
                        <li><a href="<?=base_url();?>bugs">Bug List</a></li>
                        <li><a href="<?=base_url();?>bugs/count">Bug Count</a></li>
                    </ul>
                </li>

				<li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-certificate"></i><span class='hide-menu'>Certificates</span> </a> 
                    <ul aria-expanded="false" class="collapse">
                        <li><a href="<?=base_url();?>certificates/maintenance">Maintenance</a></li>
                        <!-- <li><a href="<?=base_url();?>certificates/installation">Installation</a></li>
                        <li><a href="<?=base_url();?>certificates/training">Training</a></li>
                        <li><a href="<?=base_url();?>certificates/calibration">Callibration</a></li>
                        <li><a href="<?=base_url();?>certificates/official-report">Official Report</a></li> -->
                    </ul>
                </li>
                
                <li> <a class="waves-effect waves-dark" href='<?=base_url();?>guidebook' aria-expanded="false"> <i class="fa-solid fa-book"></i><span class='hide-menu'>Guidebook</span> </a> </li>
                <li> <a class="waves-effect waves-dark" href='https://clqms.services-summit.my.id/' aria-expanded="false"> <i class="fa-solid fa-microscope"></i><span class='hide-menu'>CLQMS</span> </a> </li>

                <?php if ($isTSM || $isPS): ?>
                    <li class="nav-small-cap">--- Master Data</li>
                    
                    <?php if ($isTSM): ?>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fas fa-user"></i><span class="hide-menu">User</span></a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>userposition">Position</a></li>
                                <li><a href="<?=base_url();?>userdepartment">Department</a></li>
                                <li><a href="#">Role</a></li>
                                <li><a href="<?=base_url();?>users">Users</a></li>
                                <li><a href="<?=base_url();?>mailgroups">Mail Group</a></li>
                                <li><a href="<?=base_url();?>offices">Offices</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-store"></i><span class="hide-menu">Vendor</span></a>
                            <ul aria-expanded="true" class="collapse">
                                <li><a href="<?=base_url();?>vendors">Vendor</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fas fa-boxes"></i><span class="hide-menu">Product</span></a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>producttype">Product Type</a></li>
                                <li><a href="<?=base_url();?>productservice">Product Service</a></li>
                                <li><a href="<?=base_url();?>productcatalog">Product Catalog</a></li>
                                <li><a href="<?=base_url();?>productalias">Product Alias</a></li>
                                <li><a href="<?=base_url();?>producttemp">Product Temp</a></li>
                                <li><a href="<?=base_url();?>unitgroup">Unit Group</a></li>
                                <li><a href="<?=base_url();?>products">Products</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-map-location-dot"></i><span class="hide-menu">Area</span></a>
                            <ul aria-expanded="true" class="collapse">
                                <li><a href="<?=base_url();?>zones">Geographical Area</a></li>
                                <li><a href="<?=base_url();?>areas">User Defined Area</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-address-book"></i><span class="hide-menu">Contact</span></a>
                            <ul aria-expanded="true" class="collapse">
                                <li><a href="<?=base_url();?>contacts">Contact</a></li>
                                <li><a href="<?=base_url();?>emails">Email</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="far fa-hospital"></i><span class="hide-menu"> Account</span></a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>accounts">Accounts</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fa-solid fa-house-user"></i><span class="hide-menu">Sites</span> </a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>sites">Sites</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fa-solid fa-warehouse"></i><span class="hide-menu"> Inventory</span></a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>invcounters">Counters</a></li>
                                <li><a href="<?=base_url();?>invtrans">Transactions</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fas fa-paw"></i><span class="hide-menu">Activity</span></a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>acttype">Activity Type</a></li>
                                <li><a href="<?=base_url();?>acttext">Activity Text</a></li>
                            </ul>
                        </li>

                    <?php elseif ($isPS): ?>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fas fa-user"></i><span class="hide-menu">User</span> </a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>contacts">Contacts</a></li>
                                <li><a href="<?=base_url();?>mailgroups">Mail Group</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="fas fa-boxes"></i><span class="hide-menu">Product</span> </a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>vendors">Vendor</a></li>
                                <li><a href="<?=base_url();?>producttype">Product Type</a></li>
                                <li><a href="<?=base_url();?>productalias">Product Alias</a></li>
                                <li><a href="<?=base_url();?>productservice">Product Service</a></li>
                                <li><a href="<?=base_url();?>productcatalog">Product Catalog</a></li>
                                <li><a href="<?=base_url();?>products">Products</a></li>
                            </ul>
                        </li>
                        <li> <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false"> <i class="far fa-hospital"></i><span class="hide-menu">Sites</span> </a>
                            <ul aria-expanded="false" class="collapse">
                                <li><a href="<?=base_url();?>accounts">Accounts</a></li>
                                <li><a href="<?=base_url();?>sites">Sites</a></li>
                            </ul>
                        </li>
                    <?php endif; ?>
                <?php endif; ?>
            </ul>
        </nav>
    </div>
</aside>