<?php
global $pdo;
$siteName = getSetting($pdo, 'site_name', SITE_NAME);
$siteLogo = getSetting($pdo, 'site_logo', '');
$seoDesc  = getSetting($pdo, 'seo_description', 'Flexi Access Bank – secure online banking.');
$seoKw    = getSetting($pdo, 'seo_keywords', 'online banking, secure bank');
$favicon  = getSetting($pdo, 'site_favicon', '');
$pageTitle = ($pageTitle ?? $siteName);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="<?= htmlspecialchars($seoDesc) ?>">
<meta name="keywords" content="<?= htmlspecialchars($seoKw) ?>">
<meta property="og:title" content="<?= htmlspecialchars($pageTitle) ?>">
<meta property="og:description" content="<?= htmlspecialchars($seoDesc) ?>">
<title><?= htmlspecialchars($pageTitle) ?> | <?= htmlspecialchars($siteName) ?></title>
<link rel="icon" href="<?= $favicon ? '/uploads/' . $favicon : '/assets/img/logo.png' ?>" type="image/png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<link rel="stylesheet" href="/assets/css/style.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark portal-nav sticky-top">
  <div class="container">
    <a class="navbar-brand d-flex align-items-center gap-2" href="/dashboard.php">
      <img src="/assets/img/logo.png" alt="<?= htmlspecialchars($siteName) ?>" height="38">
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#portalNav">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="portalNav">
      <ul class="navbar-nav ms-auto align-items-lg-center gap-lg-1">
        <li class="nav-item"><a class="nav-link" href="/dashboard.php"><i class="fa fa-home me-1"></i>Dashboard</a></li>
        <li class="nav-item"><a class="nav-link" href="/transfer.php"><i class="fa fa-paper-plane me-1"></i>Transfer</a></li>
        <li class="nav-item"><a class="nav-link" href="/transactions.php"><i class="fa fa-list me-1"></i>History</a></li>
        <li class="nav-item"><a class="nav-link" href="/cards.php"><i class="fa fa-credit-card me-1"></i>Cards</a></li>
        <li class="nav-item"><a class="nav-link" href="/loans.php"><i class="fa fa-hand-holding-usd me-1"></i>Loans</a></li>
        <li class="nav-item"><a class="nav-link" href="/investments.php"><i class="fa fa-chart-line me-1"></i>Invest</a></li>
        <li class="nav-item"><a class="nav-link" href="/support.php"><i class="fa fa-headset me-1"></i>Support</a></li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle d-flex align-items-center gap-2" href="#" data-bs-toggle="dropdown">
            <?php if (!empty($currentUser['avatar'])): ?>
              <img src="/uploads/avatars/<?= htmlspecialchars($currentUser['avatar']) ?>" class="rounded-circle" width="28" height="28" style="object-fit:cover">
            <?php else: ?>
              <i class="fa fa-user-circle fa-lg"></i>
            <?php endif; ?>
            <?= htmlspecialchars($currentUser['first_name'] ?? 'Account') ?>
          </a>
          <ul class="dropdown-menu dropdown-menu-end">
            <li><a class="dropdown-item" href="/profile.php"><i class="fa fa-user me-2"></i>Profile</a></li>
            <li><a class="dropdown-item" href="/kyc.php"><i class="fa fa-id-card me-2"></i>KYC Verification</a></li>
            <li><a class="dropdown-item" href="/notifications.php"><i class="fa fa-bell me-2"></i>Notifications</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item text-danger" href="/logout.php"><i class="fa fa-sign-out-alt me-2"></i>Logout</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>
<?php if ($flash = get_flash('success')): ?>
<div class="alert alert-success alert-dismissible fade show mx-3 mt-2 mb-0" role="alert">
  <i class="fa fa-check-circle me-2"></i><?= htmlspecialchars($flash) ?>
  <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<?php if ($flash = get_flash('error')): ?>
<div class="alert alert-danger alert-dismissible fade show mx-3 mt-2 mb-0" role="alert">
  <i class="fa fa-exclamation-circle me-2"></i><?= htmlspecialchars($flash) ?>
  <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
