<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lang.php';

$currentPage = basename($_SERVER['PHP_SELF'], '.php');
$dir = $isRTL ? 'rtl' : 'ltr';
?>

<!DOCTYPE html>
<html lang="<?= $LANG ?>" dir="<?= $dir ?>">

<head>
  <meta charset="UTF-8">

  <meta name="viewport"
        content="width=device-width, initial-scale=1.0">

  <title>
    <?= e(SITE_NAME) ?> — <?= t($pageTitle ?? 'tagline') ?>
  </title>

  <meta name="description"
        content="<?= t('footer_desc') ?>">

  <!-- CSS -->
  <link rel="stylesheet" href="assets/css/style.css">
</head>

<body>

<!-- ── Navbar ───────────────────────────────────────── -->
<nav class="nav" id="mainNav">

  <div class="container nav-inner">

    <!-- Logo -->
    <a href="index.php" class="nav-logo">
      SAVORIA
    </a>

    <!-- Links -->
    <div class="nav-links">

      <a href="index.php"
         <?= $currentPage === 'index' ? 'class="active"' : '' ?>>
        <?= t('home') ?>
      </a>

      <a href="menu.php"
         <?= $currentPage === 'menu' ? 'class="active"' : '' ?>>
        <?= t('menu') ?>
      </a>

      <a href="delivery.php"
         class="delivery-link <?= $currentPage === 'delivery' ? 'active' : '' ?>">
        🚚 <?= t('delivery') ?>
      </a>

      <a href="reservations.php"
         <?= $currentPage === 'reservations' ? 'class="active"' : '' ?>>
        <?= t('reservations') ?>
      </a>

    </div>

    <!-- Right Side -->
    <div class="nav-right">

      <!-- Language -->
      <a href="?lang=<?= $LANG === 'en' ? 'ar' : 'en' ?>&<?= http_build_query(array_diff_key($_GET, ['lang' => ''])) ?>"
         class="lang-btn">

        <?= $LANG === 'en' ? 'عربي' : 'EN' ?>

      </a>

      <!-- Cart -->
      <a href="order.php"
         class="nav-cart"
         title="<?= t('order') ?>">

        🛒

        <?php
        $cartCount = 0;

        if (isset($_SESSION['cart']) && is_array($_SESSION['cart'])) {
            $cartCount = array_sum(array_column($_SESSION['cart'], 'quantity'));
        }

        if ($cartCount > 0):
        ?>
          <span class="cart-badge">
            <?= $cartCount ?>
          </span>
        <?php endif; ?>

      </a>

      <!-- Admin -->
      <a href="admin/index.php"
         style="color:var(--fg40);font-size:18px;"
         title="<?= t('admin') ?>">

         ⚙

      </a>

    </div>

  </div>

</nav>

<!-- ── Navbar Scroll Effect ─────────────────────────── -->
<script>
window.addEventListener('scroll', function () {

  const nav = document.getElementById('mainNav');

  if (window.scrollY > 50) {
    nav.classList.add('scrolled');
  } else {
    nav.classList.remove('scrolled');
  }

});
</script>