<?php
/**
 * Expects these variables to be set by the calling page before include:
 * $page_title       - string, required
 * $page_description - string, required
 * $page_url         - string, canonical URL of current page
 * $page_image       - string, absolute image URL for social sharing (optional)
 * $page_type        - 'website' | 'article' (optional, default website)
 * $json_ld          - string, pre-built JSON-LD script contents (optional)
 */
if (!isset($page_title)) $page_title = SITE_NAME . ' - ' . SITE_TAGLINE;
if (!isset($page_description)) $page_description = SITE_TAGLINE;
if (!isset($page_url)) $page_url = SITE_URL . $_SERVER['REQUEST_URI'];
if (!isset($page_image)) $page_image = SITE_URL . '/assets/icons/icon-512.png';
if (!isset($page_type)) $page_type = 'website';
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title><?= e($page_title) ?></title>
<meta name="description" content="<?= e($page_description) ?>">
<link rel="canonical" href="<?= e($page_url) ?>">

<!-- Open Graph -->
<meta property="og:site_name" content="<?= e(SITE_NAME) ?>">
<meta property="og:title" content="<?= e($page_title) ?>">
<meta property="og:description" content="<?= e($page_description) ?>">
<meta property="og:type" content="<?= e($page_type) ?>">
<meta property="og:url" content="<?= e($page_url) ?>">
<meta property="og:image" content="<?= e($page_image) ?>">

<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="<?= e($page_title) ?>">
<meta name="twitter:description" content="<?= e($page_description) ?>">
<meta name="twitter:image" content="<?= e($page_image) ?>">

<!-- Robots / indexing -->
<meta name="robots" content="index, follow, max-image-preview:large">
<?php if (GOOGLE_SITE_VERIFICATION): ?>
<meta name="google-site-verification" content="<?= e(GOOGLE_SITE_VERIFICATION) ?>">
<?php endif; ?>

<!-- PWA -->
<link rel="manifest" href="<?= SITE_URL ?>/manifest.json">
<meta name="theme-color" content="#0B0F19">
<link rel="apple-touch-icon" href="<?= SITE_URL ?>/assets/icons/icon-192.png">
<link rel="icon" type="image/svg+xml" href="<?= SITE_URL ?>/assets/icons/icon.svg">

<link rel="stylesheet" href="<?= SITE_URL ?>/assets/css/style.css">
<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=Chakra+Petch:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">

<?php if (ADSENSE_CLIENT_ID): ?>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=<?= e(ADSENSE_CLIENT_ID) ?>" crossorigin="anonymous"></script>
<?php endif; ?>

<?php if (GA_MEASUREMENT_ID): ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= e(GA_MEASUREMENT_ID) ?>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', '<?= e(GA_MEASUREMENT_ID) ?>');
</script>
<?php endif; ?>

<?php if (!empty($json_ld)): ?>
<script type="application/ld+json"><?= $json_ld ?></script>
<?php endif; ?>
</head>
<body>

<!-- Point 9: blinking link to gamesji.com homepage, present on every page -->
<div class="top-strip">
  <a href="<?= e(MAIN_SITE_URL) ?>" class="blink-link"><?= e(MAIN_SITE_TEXT) ?></a>
</div>

<header class="site-header">
  <div class="container header-inner">
    <a href="<?= SITE_URL ?>/index.php" class="brand">
      <span class="brand-mark">GJ</span>
      <span class="brand-text">GamesJi <em>Updates</em></span>
    </a>

    <form class="global-search" action="<?= SITE_URL ?>/games.php" method="get" role="search">
      <input type="text" name="q" placeholder="Search any game... e.g. Free Fire, PUBG, Ludo"
             value="<?= isset($_GET['q']) ? e($_GET['q']) : '' ?>" aria-label="Search games">
      <button type="submit" aria-label="Search">
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M21 21l-4.35-4.35M11 19a8 8 0 100-16 8 8 0 000 16z" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
      </button>
    </form>

    <nav class="main-nav" id="mainNav">
      <a href="<?= SITE_URL ?>/index.php">Home</a>
      <a href="<?= SITE_URL ?>/news.php">News &amp; Updates</a>
      <a href="<?= SITE_URL ?>/games.php">All Games</a>
      <a href="<?= e(MAIN_SITE_URL) ?>" class="nav-cta"><?= e(MAIN_SITE_TEXT) ?></a>
    </nav>
    <button class="nav-toggle" id="navToggle" aria-label="Toggle menu" aria-expanded="false">
      <span></span><span></span><span></span>
    </button>
  </div>
</header>
