<?php
/**
 * FRAG HOSTING — SPA entry with dynamic OpenGraph meta per route
 */

$path = $_SERVER['REQUEST_URI'] ?? '/';
$path = parse_url($path, PHP_URL_PATH) ?: '/';
$path = rtrim($path, '/');
if ($path === '') $path = '/';

$domain = 'https://fraghost.xyz';
$logo = $domain . '/favicon.svg';

$pages = [
    '/' => [
        'title' => 'FRAG HOSTING — Premium Game Server Hosting',
        'description' => 'FRAG HOSTING — Premium Game Server Hosting. Lightning-fast servers with DDoS protection, instant setup, and 24/7 support. Host Minecraft, CS2, Rust, ARK, Valheim, and FiveM servers.',
    ],
    '/attack-status' => [
        'title' => 'Network & Attack Status | FRAG HOSTING',
        'description' => 'Real-time monitoring of the FragHost website, game panel and all host IPs. Check status, latency and attack protection.',
    ],
    '/game-panel' => [
        'title' => 'Custom Game Panel | FRAG HOSTING',
        'description' => 'Learn about our custom Pterodactyl game panel, roadmap and features.',
    ],
    '/pricing' => [
        'title' => 'Pricing | FRAG HOSTING',
        'description' => 'Affordable game server hosting plans in EUR. Minecraft, FiveM, CS2, Rust and more.',
    ],
    '/games' => [
        'title' => 'Game Servers | FRAG HOSTING',
        'description' => 'Browse all supported game servers and start your own in minutes.',
    ],
    '/login' => [
        'title' => 'Login | FRAG HOSTING',
        'description' => 'Log in to your FragHost account and manage your game servers.',
    ],
    '/register' => [
        'title' => 'Register | FRAG HOSTING',
        'description' => 'Create a FragHost account and start hosting your game server today.',
    ],
    '/ryzennet' => [
        'title' => 'RyzenNet Discord Community',
        'description' => 'Join the RyzenNet Discord community. Gaming, tech and support.',
    ],
];

$meta = $pages[$path] ?? $pages['/'];

$html = file_get_contents(__DIR__ . '/index.html');

// Replace title and description
$html = preg_replace('/<title>.*?<\/title>/s', '<title>' . htmlspecialchars($meta['title']) . '</title>', $html, 1);
$html = preg_replace('/<meta name="description" content=".*?"\s*\/?>/s', '<meta name="description" content="' . htmlspecialchars($meta['description']) . '" />', $html, 1);

// Build OpenGraph tags
$og = [
    '<meta property="og:site_name" content="FRAG HOSTING" />',
    '<meta property="og:title" content="' . htmlspecialchars($meta['title']) . '" />',
    '<meta property="og:description" content="' . htmlspecialchars($meta['description']) . '" />',
    '<meta property="og:url" content="' . htmlspecialchars($domain . $path) . '" />',
    '<meta property="og:image" content="' . htmlspecialchars($logo) . '" />',
    '<meta property="og:type" content="website" />',
    '<meta name="twitter:card" content="summary" />',
    '<meta name="twitter:title" content="' . htmlspecialchars($meta['title']) . '" />',
    '<meta name="twitter:description" content="' . htmlspecialchars($meta['description']) . '" />',
];

// Insert before </head>
$html = str_replace('</head>', implode("\n  ", $og) . "\n  </head>", $html);

echo $html;
