<?php
// ============================================================
// FILE: includes/header.php
// Navbar + <head> untuk semua halaman publik
// Set $pageTitle dan $activePage sebelum include ini
// ============================================================
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/db.php';
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/auth.php';

$pageTitle = $pageTitle ?? NAMA_TOKO;
?>
<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?= e($pageTitle) ?> — <?= NAMA_TOKO ?></title>
  <meta name="description" content="Toko Kusen &amp; Gypsum terpercaya di Bekasi. Tersedia kusen kayu, kusen aluminium, gypsum board, dan aksesori. Pesan online, bayar transfer.">

  <!-- Google Fonts: Playfair Display + Nunito -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;900&family=Nunito:wght@400;500;600;700&display=swap" rel="stylesheet">

  <!-- Bootstrap 5 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  <!-- Bootstrap Icons -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
  <!-- Custom CSS -->
  <link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/style.css">
</head>
<body>

<!-- ===== TOPBAR ===== -->
<div class="topbar d-none d-md-block">
  <div class="container d-flex justify-content-between align-items-center py-1">
    <small>
      <i class="bi bi-geo-alt-fill me-1"></i><?= ALAMAT_TOKO ?>
    </small>
    <small>
      <i class="bi bi-clock me-1"></i>Sen–Sab: 08.00–17.00
      &nbsp;|&nbsp;
      <i class="bi bi-telephone-fill me-1"></i>
      
    </small>
  </div>
</div>

<!-- ===== NAVBAR ===== -->
<nav class="navbar navbar-expand-lg sticky-top main-navbar shadow-sm">
  <div class="container">
    <!-- Brand -->
    <a class="navbar-brand d-flex align-items-center gap-2" href="<?= BASE_URL ?>">
      <div class="brand-icon">
        <i class="bi bi-house-door-fill"></i>
      </div>
      <div>
        <div class="brand-name">Budi Jaya</div>
        <div class="brand-sub">Kusen &amp; Gypsum</div>
      </div>
    </a>

    <button class="navbar-toggler" type="button"
            data-bs-toggle="collapse" data-bs-target="#mainNav"
            aria-controls="mainNav" aria-expanded="false">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="mainNav">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link <?= ($activePage??'')==='home'    ? 'active' : '' ?>"
             href="<?= BASE_URL ?>">Beranda</a>
        </li>
        <li class="nav-item">
          <a class="nav-link <?= ($activePage??'')==='katalog' ? 'active' : '' ?>"
             href="<?= BASE_URL ?>/katalog.php">Katalog</a>
        </li>
        <li class="nav-item">
          <a class="nav-link <?= ($activePage??'')==='tracking' ? 'active' : '' ?>"
             href="<?= BASE_URL ?>/tracking.php">Cek Pesanan</a>
        </li>
        <li class="nav-item">
          <a class="nav-link <?= ($activePage??'')==='chat' ? 'active' : '' ?>"
             href="<?= BASE_URL ?>/chat.php">
            <i class="bi bi-chat-dots me-1"></i>Chat
          </a>
        </li>
      </ul>

      <!-- Search -->
      <form class="d-flex me-3" action="<?= BASE_URL ?>/katalog.php" method="GET">
        <div class="input-group input-group-sm">
          <input class="form-control search-input" type="search" name="q"
                 placeholder="Cari produk kusen, gypsum…"
                 value="<?= e($_GET['q'] ?? '') ?>">
          <button class="btn btn-search" type="submit">
            <i class="bi bi-search"></i>
          </button>
        </div>
      </form>

      <!-- Cart & Auth -->
      <div class="d-flex align-items-center gap-2">
        <a href="<?= BASE_URL ?>/keranjang.php" class="btn btn-cart position-relative">
          <i class="bi bi-cart3 fs-5"></i>
          <?php $jml = jumlahKeranjang(); if ($jml > 0): ?>
            <span class="badge-cart"><?= $jml ?></span>
          <?php endif; ?>
        </a>

        <?php if (isLoggedIn()): ?>
          <div class="dropdown">
            <button class="btn btn-outline-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown">
              <i class="bi bi-person-circle me-1"></i><?= e($_SESSION['user_nama']) ?>
            </button>
            <ul class="dropdown-menu dropdown-menu-end">
              <li><a class="dropdown-item" href="<?= BASE_URL ?>/tracking.php">
                <i class="bi bi-box-seam me-2"></i>Pesanan Saya</a></li>
              <?php if (isAdmin()): ?>
              <li><a class="dropdown-item text-warning" href="<?= BASE_URL ?>/admin/">
                <i class="bi bi-speedometer2 me-2"></i>Admin Panel</a></li>
              <?php endif; ?>
              <li><hr class="dropdown-divider"></li>
              <li><a class="dropdown-item text-danger" href="<?= BASE_URL ?>/logout.php">
                <i class="bi bi-box-arrow-right me-2"></i>Logout</a></li>
            </ul>
          </div>
        <?php else: ?>
          <a href="<?= BASE_URL ?>/login.php" class="btn btn-primary btn-sm">
            <i class="bi bi-person me-1"></i>Masuk
          </a>
        <?php endif; ?>
      </div>
    </div>
  </div>
</nav>
<!-- ===== END NAVBAR ===== -->