<?php
$level   = $_SESSION['ss_LEVEL'] ?? 0;
$isLogin = ($_SESSION['ss_LOGIN'] ?? 0) == 1;
$userName = $_SESSION['ss_NAME'] ?? '';

// ---- Level Groups ----
$isAdmin        = in_array($level, [1, 5]);
$isManager      = in_array($level, [1, 5]);
$isAccounting   = ($level == 6);
$isMarketing    = ($level == 7); // cannot order
$isInstallDriver= ($level == 8);
$isUcoDriver    = ($level == 9);
$isCustomerOnly = ($level == 10);
$canExport      = in_array($level, [1, 5, 6, 7]);
?>
<body>

<header id="header" class="header fixed-top d-flex align-items-center">
  <div class="container d-flex align-items-center justify-content-between">

    <!-- Logo -->
    <a href="/index_intranet.php" class="logo d-flex align-items-center me-auto me-lg-0">
      <img src="assets/img/green-oil-logo-dark.jpg">
    </a>

    <!-- Navigation -->
    <nav id="navbar" class="navbar">
      <ul>
      <?php if ($isCustomerOnly): ?>
        <!-- Level 10: CUSTOMER only -->
        <li><a href="/index_intranet.php?view=customer_list">CUSTOMER</a></li>
      <?php else: ?>

        <?php if ($isManager): ?>
          <li class="dropdown">
            <a href="#"><span>PLANNING</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
              <li><a href="/index_intranet.php?view=forecast">FORECAST</a></li>
              <li><a href="/index_intranet.php?view=install_wait_list">INSTALL WAIT LIST</a></li>
            </ul>
          </li>
        <?php endif; ?>

        <?php if ($isUcoDriver): ?>          
          <li><a href="/index_intranet.php?view=forecast">FORECAST</a></li>
        <?php endif; ?>

        <?php if ($isManager || $isAccounting): ?>
          <li class="dropdown">
            <a href="#"><span>ORDER</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
              <li><a href="/index_intranet.php?view=order_list">UCO ORDER</a></li>
              <li><a href="/index_intranet.php?view=install_order">INSTALL ORDER</a></li>
            </ul>
          </li>
        <?php endif; ?>

        <?php if ($isUcoDriver): ?>
          <li><a href="/index_intranet.php?view=order_list">ORDER</a></li>
        <?php endif; ?>

        <?php if ($isInstallDriver): ?>
          <li><a href="/index_intranet.php?view=install_order">ORDER</a></li>
        <?php endif; ?>

        <?php if ($isManager || $isUcoDriver): ?>
          <li><a href="/index_intranet.php?view=map">MAP</a></li>
        <?php endif; ?>

        <li><a href="/index_intranet.php?view=customer_list">CUSTOMER</a></li>
        <li><a href="/index_intranet.php?view=oilhistory_list">OIL HISTORY</a></li>
        <li><a href="/index_intranet.php?view=receipt_list">RECEIPT</a></li>

        <?php if ($canExport): ?>
          <li class="dropdown">
            <a href="#"><span>EXPORT</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
              <li><a href="/index_intranet.php?view=export_customer">CUSTOMER DATA</a></li>
              <li><a href="/index_intranet.php?view=export_oilhistory">OIL HISTORY DATA</a></li>
            </ul>
          </li>
        <?php endif; ?>

        <?php if ($canExport || $isUcoDriver): ?>
          <li class="dropdown">
            <a href="#"><span>REPORT</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
                <li><a href="/index_intranet.php?view=report_expense">EXPENSE</a></li>
                <li><a href="/index_intranet.php?view=report_iscccorsia">ISCC/CORSIA</a></li>
                <li><a href="/index_intranet.php?view=report_yearly">YEARLY</a></li>
                <li><a href="/index_intranet.php?view=report_monthly">MONTHLY-AREA</a></li>
                <li><a href="/index_intranet.php?view=report_monthly_driver">MONTHLY-DRIVER</a></li>
                <li><a href="/index_intranet.php?view=report_daily">DAILY</a></li>
                <li><a href="#">------------------</a></li>
                <li><a href="/index_intranet.php?view=report_monthly_2024">MONTHLY-AREA(~2023)</a></li>
                <li><a href="/index_intranet.php?view=report_daily_2024">DAILY(~2023)</a></li>
            </ul>
          </li>
        <?php endif; ?>

        <?php if ($isAdmin): ?>
          <li class="dropdown">
            <a href="#"><span>CONFIGURATION</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
            <ul>
              <li><a href="/index_intranet.php?view=member_list">MEMBER</a></li>
              <li><a href="/index_intranet.php?view=driver_list">DRIVER</a></li>
              <li><a href="/index_intranet.php?view=configure">CONFIGURATION</a></li>
            </ul>
          </li>
        <?php endif; ?>

      <?php endif; ?>

      </ul>
    </nav>

    <!-- User Info -->
    <?php if ($isLogin): ?>
      <a class="txt-user" data-toggle="modal" data-target="#member-detail-modal" style="cursor:pointer;">
        User: <span class="txt-user-name"><?=htmlspecialchars($userName)?></span>
      </a>
      <a class="txt-logout" href="/lib/login_process.php?action=logout">Logout</a>
    <?php endif; ?>

    <!-- Mobile -->
    <i class="mobile-nav-toggle mobile-nav-show bi bi-list"></i>
    <i class="mobile-nav-toggle mobile-nav-hide d-none bi bi-x"></i>

  </div>
</header>
