<?php
include(__DIR__ . '/auth.php');
require_login();
date_default_timezone_set('Asia/Kolkata');
?>
<style>
  .logo {
    display: inline-block;
    margin: auto;
    vertical-align: middle;
  }
  .welcome-text {
    padding: 15px;
    color: #FFF;
    display: inline-block;
  }
  .navbar-right {
    display: flex;
    align-items: center;
  }

  /* Mobile-specific styles */
  @media (max-width: 767px) {
    .mobile-welcome,
    .mobile-profile {
      display: inline-block;
    }
    .desktop-welcome,
    .desktop-profile,
    .navbar-right {
      display: none !important; /* hide right side in mobile */
    }
  }

  /* Desktop styles */
  @media (min-width: 768px) {
    .mobile-welcome,
    .mobile-profile {
      display: none !important; /* hide mobile items in desktop */
    }
    .desktop-welcome {
      display: inline-block;
    }
  }
</style>

<!-- nav start -->
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

      <!-- Mobile profile + welcome -->
       
       <?php
        $imagePath = '';
        if(isset($_SESSION['profile_pic']) && !empty($_SESSION['profile_pic'])){
          $imagePath = "/CONTENT/ROOT_URI/Admin/".$_SESSION['profile_pic'];
        }else{
          $imagePath = "/CONTENT/ROOT_URI/Admin/default.svg";
        }

       ?>

      <img class="mobile-profile" 
           src="<?php echo $imagePath; ?>" 
           width="40" height="40" 
           style="border-radius:50%; object-fit:cover;" 
           alt="Profile">
      <span class="mobile-welcome">Welcome! <?php echo htmlspecialchars($_SESSION['name'] ?? ''); ?></span>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <?php 
          $userType = $_SESSION['type'] ?? '';

          if ($userType === 'admin') {
        ?>
              <li><a href="/Admin/Create_AC_Recurring">New Recurring</a></li>
              <li><a href="/Admin/Create_AC_FD">New FD</a></li>
              <li><a href="/Admin/Create_AC_Loan">New Loan</a></li>
              <li><a href="/Admin/Add_group">Add New Group</a></li>
              <li><a href="/Admin/Trans_New">Transaction</a></li>
              <li><a href="/Admin/agent-targets">Agent Targets</a></li>
              <!-- <li><a href="/Admin/agent_View_report">Commission</a></li> -->
              <li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
              <li><a href="/Admin/Report">Report</a></li>
              <li><a href="/Admin/Due">Deemand Sheet</a></li>
              <li><a href="/Admin/Settings_Agent">Agent Settings</a></li>
              <?php
          } elseif ($userType === 'bm') {
              ?>
              <li><a href="/Admin/Create_AC_Recurring">New Recurring</a></li>
              <li><a href="/Admin/Create_AC_FD">New FD</a></li>
              <li><a href="/Admin/Create_AC_Loan">New Loan</a></li>
              <li><a href="/Admin/Add_group">Add New Group</a></li>
              <li><a href="/Admin/Trans_New">Transaction</a></li>
              <li><a href="/Admin/agent-targets">Agent Targets</a></li>
              <li><a href="/Admin/agent_View_report">Commission</a></li>
              <?php
          } elseif ($userType === 'agent') {
              ?>
              <li><a href="/Admin/View_AC?Type=Recurring">View A/C</a></li>
              <li><a href="/Admin/Due">Deemand Sheet</a></li>
              <li><a href="/Admin/Report">Report</a></li>
              <!-- <li><a href="/Admin/agent_View_report">Commission</a></li> -->
              <?php
          }
        ?>
      </ul>

      <!-- Desktop right side -->
      <ul class="nav navbar-nav navbar-right">
        <li class="desktop-welcome">
          <span class="welcome-text">Welcome! <?php echo htmlspecialchars($_SESSION['name'] ?? ''); ?></span>
        </li>
        <li class="desktop-profile">
          <img src="<?php echo $imagePath; ?>" 
               width="40" height="40" 
               style="border-radius:50%; object-fit:cover;" 
               alt="Profile">
        </li>
        <li><a href="/Admin/Signout">Signout</a></li>
      </ul>
    </div>
  </div>
</nav>
