<?php
$page = isset($_GET['page']) ? basename($_GET['page']) : 'index';
$jsonFile = $_SERVER['DOCUMENT_ROOT'] . "/rss/json/pages/{$page}.json";
$pageData = file_exists($jsonFile) ? json_decode(file_get_contents($jsonFile), true) : [
    'title' => 'Stella Amor',
    'long_desc' => 'Free online dating with advanced filters for lifestyle, finance, kinks, and more.',
    'robots' => 'index, follow'
];

// Set default values
$siteUrl = 'https://stellaamor.com';
$pageUrl = $page === 'index' ? $siteUrl . '/' : $siteUrl . '/' . $page . '/';
$title = $pageData['title'] ?? 'Stella Amor';
$description = $pageData['long_desc'] ?? 'Free online dating with advanced filters for lifestyle, finance, kinks, and more.';
$keywords = 'free dating, online dating, match filters, financial compatibility, kink-friendly dating, lifestyle matching';
$robots = $pageData['robots'] ?? 'index, follow';
$menu = [
    'Home' => '/',
    'Create account' => '/register/',
    'Login' => '/login/',
    'About us' => '/about-us/'
];

$links = [
    'Our Filters' => '/filters/',
    'Success Stories' => '/success-stories/',
    'How It Works' => '/how-it-works/',
    'FAQ' => '/faq/',
    'About us' => '/about-us/'
];
$currentPage = $page === 'index' ? 'Home' : ucwords(str_replace('-', ' ', $page));
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Defaults -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stella Amor | <?php echo htmlspecialchars($pageData['title'], ENT_QUOTES, 'UTF-8'); ?></title>
    <meta name="description" content="<?php echo htmlspecialchars($description, ENT_QUOTES, 'UTF-8'); ?>">
    <meta name="author" content="Stella Amor">
    <meta name="keywords" content="<?php echo htmlspecialchars($keywords, ENT_QUOTES, 'UTF-8'); ?>">
    <meta name="robots" content="<?php echo htmlspecialchars($robots, ENT_QUOTES, 'UTF-8'); ?>">
    <link rel="canonical" href="<?php echo htmlspecialchars($pageUrl, ENT_QUOTES, 'UTF-8'); ?>">

    <!-- Open Graph -->
    <meta property="og:title" content="<?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>">
    <meta property="og:description" content="<?php echo htmlspecialchars($description, ENT_QUOTES, 'UTF-8'); ?>">
    <meta property="og:type" content="website">
    <meta property="og:url" content="<?php echo htmlspecialchars($pageUrl, ENT_QUOTES, 'UTF-8'); ?>">
    <meta property="og:image" content="<?php echo $siteUrl; ?>/rss/img/stella.png">

    <!-- Twitter Card -->
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="<?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?>">
    <meta name="twitter:description" content="<?php echo htmlspecialchars($description, ENT_QUOTES, 'UTF-8'); ?>">
    <meta name="twitter:image" content="<?php echo $siteUrl; ?>/rss/img/stella.png">

    <!-- Favicon -->
    <link rel="icon" href="/rss/img/favicon/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon" href="/rss/img/favicon/apple-touch-icon.png">

    <!-- Stylesheets -->
    <link rel="preload" href="/rss/css/main.css" as="style">
    <link href="/rss/3rd-party/mdi/css/materialdesignicons.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/rss/css/main.css">
    <link rel="stylesheet" href="/rss/css/theme.css">

    <!-- JavaScript -->
    <script src="/rss/js/main.js" defer></script>

    <!-- Structured Data (JSON-LD) -->
<!-- Dynamic Structured Data -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebPage",
  "name": "<?php echo htmlspecialchars($pageInfo['title'], ENT_QUOTES, 'UTF-8'); ?>",
  "url": "<?php echo htmlspecialchars($pageUrl, ENT_QUOTES, 'UTF-8'); ?>",
  "description": "<?php echo htmlspecialchars($pageInfo['long_desc'] ?? $pageInfo['short_desc'], ENT_QUOTES, 'UTF-8'); ?>",
  "isPartOf": {
    "@type": "WebSite",
    "name": "Stella Amor",
    "url": "https://stellaamor.com/"
  }
  <?php if (!empty($pageInfo['rich_service_type'])): ?>,
  "mainEntity": {
    "@type": "Service",
    "serviceType": "<?php echo htmlspecialchars($pageInfo['rich_service_type'], ENT_QUOTES, 'UTF-8'); ?>",
    "name": "<?php echo htmlspecialchars($pageInfo['title'], ENT_QUOTES, 'UTF-8'); ?>",
    "description": "<?php echo htmlspecialchars($pageInfo['long_desc'] ?? $pageInfo['short_desc'], ENT_QUOTES, 'UTF-8'); ?>",
    "provider": {
      "@type": "Organization",
      "name": "Stella Amor",
      "url": "https://stellaamor.com"
    },
    "areaServed": "Worldwide",
    "offers": {
      "@type": "Offer",
      "name": "Free Membership",
      "price": "0",
      "priceCurrency": "USD",
      "description": "Full access to all filters during the free membership period"
    }
    <?php if (!empty($pageInfo['rich_faq'])): ?>,
    "faqPage": {
      "@type": "FAQPage",
      "mainEntity": [
        <?php foreach ($pageInfo['rich_faq'] as $i => $faq): ?>
        {
          "@type": "Question",
          "name": "<?php echo htmlspecialchars($faq['question'], ENT_QUOTES, 'UTF-8'); ?>",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "<?php echo htmlspecialchars($faq['answer'], ENT_QUOTES, 'UTF-8'); ?>"
          }
        }<?php echo $i < count($pageInfo['rich_faq'])-1 ? ',' : ''; ?>
        <?php endforeach; ?>
      ]
    }
    <?php endif; ?>
  }
  <?php endif; ?>
}
</script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7LSPWJ1YKX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-7LSPWJ1YKX');
</script>
</head>
<body>
<header>
    <div class="logo">
        <a href="/">
            <img src="/rss/img/logo.png" alt="Stella Amor Logo" width="150" height="50" loading="lazy">
        </a>
    </div>
    <button class="mobile-toggler" aria-label="Toggle navigation" id="menu-toggler">☰</button>
    <nav id="mainMenu">
        <?php foreach ($menu as $label => $url): ?>
            <a href="<?php echo $url; ?>" class="menu-item<?php echo $label === $currentPage ? ' active" aria-current="page' : ''; ?>">
                <?php echo htmlspecialchars($label, ENT_QUOTES, 'UTF-8'); ?>
            </a>
        <?php endforeach; ?>
    </nav>
</header>