<?php

// Cek apakah user sudah login
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
    // Jika belum login, redirect ke halaman login
    header("Location: login.php");
    exit();
}

$nama = isset($_SESSION['nama']) ? $_SESSION['nama'] : 'User'; // Jika belum login, tampilkan 'User' sebagai default
$user = isset($_SESSION['user']) ? $_SESSION['user'] : 'warehouse'; // Jika belum login, tampilkan 'User' sebagai default
$jenis = isset($_SESSION['jenis']) ? $_SESSION['jenis'] : 'Coba'; // Jika belum login, tampilkan 'User' sebagai default
$aom = isset($_SESSION['aom']) ? $_SESSION['aom'] : 'Coba'; // Jika belum login, tampilkan 'User' sebagai default

function setActive($current_page, $menu_page)
{
  return $current_page == $menu_page ? 'nav-link' : 'nav-link collapsed';
}
?>


<aside id="sidebar" class="sidebar">
  <ul class="sidebar-nav" id="sidebar-nav">

    <!-- Jika jenis adalah 'Business Head' atau 'Superadmin', tampilkan semua menu -->
    <?php if ($jenis == 'Superadmin'): ?>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'dashboard'); ?>" href="index.php">
          <i class="uil uil-estate"></i>
          <span>Dashboard</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'allocation'); ?>" href="allocation.php">
          <i class="uil uil-share-alt"></i>
          <span>Allocation</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'shipping'); ?>" href="shipping.php">
          <i class="uil uil-share"></i>
          <span>Shipping</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history'); ?>" href="history.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li> -->
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history'); ?>" href="history_detail.php">
          <i class="uil uil-history-alt"></i>
          <span>Shipping History</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history2'); ?>" href="history2.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'key_sd'); ?>" href="key_sd.php">
          <i class="uil uil-key-skeleton-alt"></i>
          <span>Key Stock Days</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'key_ratio'); ?>" href="key_ratio.php">
          <i class="uil uil-balance-scale"></i>
          <span>Key Ratio</span>
        </a>
      </li> -->

    <!-- Jika jenis adalah 'Business Head', tampilkan hanya shipping dan history -->
    <?php elseif ($jenis == 'Business Head'): ?>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'dashboard'); ?>" href="index.php">
          <i class="uil uil-estate"></i>
          <span>Dashboard</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history'); ?>" href="history.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li> -->
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history2'); ?>" href="history2.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'key_sd'); ?>" href="key_sd.php">
          <i class="uil uil-key-skeleton-alt"></i>
          <span>Key Stock Days</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'key_ratio'); ?>" href="key_ratio.php">
          <i class="uil uil-balance-scale"></i>
          <span>Key Ratio</span>
        </a>
      </li> -->

    <!-- Jika jenis adalah 'aom', tampilkan hanya shipping dan history -->
    <?php elseif ($jenis == 'aom'): ?>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'dashboard'); ?>" href="index.php">
          <i class="uil uil-estate"></i>
          <span>Dashboard</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'allocation'); ?>" href="allocation.php">
          <i class="uil uil-share-alt"></i>
          <span>Allocation</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history'); ?>" href="history.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li> -->
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history2'); ?>" href="history2.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li>

    <!-- Jika jenis adalah 'warehouse', tampilkan hanya allocation dan shipping -->
    <?php elseif ($jenis == 'warehouse'): ?>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'dashboard'); ?>" href="index.php">
          <i class="uil uil-estate"></i>
          <span>Dashboard</span>
        </a>
      </li>
      <!-- <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'shipping'); ?>" href="shipping.php">
          <i class="uil uil-share"></i>
          <span>Shipping</span>
        </a>
      </li> -->
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history'); ?>" href="history_detail.php">
          <i class="uil uil-history-alt"></i>
          <span>Shipping History</span>
        </a>
      </li>
      <li class="nav-item">
        <a class="<?php echo setActive($activeMenu, 'history2'); ?>" href="history2.php">
          <i class="uil uil-history"></i>
          <span>History</span>
        </a>
      </li>
    
    <?php endif; ?>
    
  </ul>
</aside><!-- End Sidebar -->