<?php
if (!isset($brandingData)) {
    require_once 'db.php';
    $stmt = $pdo->query("SELECT * FROM branding LIMIT 1");
    $brandingData = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>

<link rel="stylesheet" href="assets/css/themes/<?php echo htmlspecialchars($brandingData['theme_stylesheet'] ?? 'theme-orange.css'); ?>">

<?php
if (!isset($brandingData)) {
    require_once 'db.php';
    $stmt = $pdo->query("SELECT * FROM branding LIMIT 1");
    $brandingData = $stmt->fetch(PDO::FETCH_ASSOC);
    }
$logoImage = $brandingData['logo_image'] ?? '';
?>

<nav class="navbar navbar-expand-lg navbar-dark">
  <div class="container-fluid">
    <a class="navbar-brand" href="user-dashboard.php">
      <?php if (!empty($logoImage)): ?>
        <img src="<?php echo htmlspecialchars($logoImage); ?>" alt="Logo">
      <?php else: ?>
        <span>Your Logo</span>
      <?php endif; ?>
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ms-auto">
        <?php if (!empty($brandingData['facebook_group_url'])): ?>
        <li class="nav-item">
          <a class="nav-link" href="<?= htmlspecialchars($brandingData['facebook_group_url']) ?>" target="_blank">
            <i class="fab fa-facebook"></i> Facebook Group
          </a>
        </li>
        <?php endif; ?>
        <li class="nav-item">
          <a class="nav-link" href="referrals.php">
            <i class="fas fa-users"></i> My Referrals
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="profile.php">
            <i class="fa fa-user-circle"></i> Profile
          </a>
        </li>
      </ul>
    </div>
  </div>
</nav>
