<?php
// Admin authentication check
include __DIR__ . '/../../connect/db.php';
if (!isset($_SESSION['man'])) {
    header("Location: index.php");
    exit();
}

// Active page detection
$currentPage = basename($_SERVER['SCRIPT_NAME']);

function adminActive($page) {
    global $currentPage;
    return $currentPage === $page ? ' active' : '';
}

$adminName = $_SESSION['man'] ?? 'Administrator';
?>
<div class="sidebar">
  <div class="user-panel mt-3 pb-3 mb-3 d-flex">
    <div class="image">
      <div class="img-circle elevation-2 bg-primary d-flex align-items-center justify-content-center text-white fw-bold" style="width:35px;height:35px;font-size:0.85rem;">
        <?=strtoupper(substr($adminName, 0, 2))?>
      </div>
    </div>
    <div class="info">
      <a href="#" class="d-block"><?=htmlspecialchars($adminName)?></a>
    </div>
  </div>

  <nav class="mt-2">
    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu">

      <li class="nav-header">CUSTOMERS</li>
      <li class="nav-item">
        <a href="main.php" class="nav-link<?=adminActive('main.php')?>">
          <i class="nav-icon fas fa-users"></i><p>All Users</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="create-account.php" class="nav-link<?=adminActive('create-account.php')?>">
          <i class="nav-icon fas fa-user-plus"></i><p>Create Account</p>
        </a>
      </li>

      <li class="nav-header">BANKING</li>
      <li class="nav-item">
        <a href="linked-cards.php" class="nav-link<?=adminActive('linked-cards.php')?>">
          <i class="nav-icon fas fa-credit-card"></i><p>Linked Cards</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="card-applications.php" class="nav-link<?=adminActive('card-applications.php')?>">
          <i class="nav-icon fas fa-id-card"></i><p>Virtual Cards</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="transaction.php" class="nav-link<?=adminActive('transaction.php')?>">
          <i class="nav-icon fas fa-exchange-alt"></i><p>Transactions</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="tickets.php" class="nav-link<?=adminActive('tickets.php')?>">
          <i class="nav-icon fas fa-ticket-alt"></i><p>Support Tickets</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="loan.php" class="nav-link<?=adminActive('loan.php')?>">
          <i class="nav-icon fas fa-hand-holding-usd"></i><p>Loans</p>
        </a>
      </li>

      <li class="nav-header">WEBSITE</li>
      <li class="nav-item">
        <a href="settings.php" class="nav-link<?=adminActive('settings.php')?>">
          <i class="nav-icon fas fa-cog"></i><p>Site Settings</p>
        </a>
      </li>

      <li class="nav-header">ACCOUNT</li>
      <li class="nav-item">
        <a href="change-password.php" class="nav-link<?=adminActive('change-password.php')?>">
          <i class="nav-icon fas fa-lock"></i><p>Change Password</p>
        </a>
      </li>
      <li class="nav-item">
        <a href="../apps/login/logout.php" class="nav-link">
          <i class="nav-icon fas fa-sign-out-alt"></i><p>Logout</p>
        </a>
      </li>

    </ul>
  </nav>
</div>
