<?php
session_start();
$scriptDir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '/'));
$basePath = rtrim($scriptDir, '/');

define('BASE_URL', ($basePath === '' || $basePath === '.') ? '/' : $basePath . '/');
$page = isset($_GET['page']) ? $_GET['page'] : 'home';

$allowed_pages = [
    'home',
    'results',
    'tracking',
    'rules',
    'contact',
    'about',
    'registration',
    'merchandise'
];

if (!in_array($page, $allowed_pages, true)) {
    $page = 'home';
}

include __DIR__ . '/template/lang.php';
include __DIR__ . '/template/header.php';
include __DIR__ . '/template/navbar.php';

switch ($page) {
    case 'results':
    include __DIR__ . '/template/results.php';
    break;

    case 'tracking':
    include __DIR__ . '/template/tracking.php';
    break;

    case 'rules':
    include __DIR__ . '/template/rules.php';
    break;

    case 'contact':
    include __DIR__ . '/template/contact.php';
    break;

    case 'about':
    include __DIR__ . '/template/about.php';
    break;

    case 'registration':
    include __DIR__ . '/template/registration.php';
    break;

    case 'merchandise':
    include __DIR__ . '/template/merchandise.php';
    break;

    case 'home':
    default:
    include __DIR__ . '/template/home.php';
    break;
}

include __DIR__ . '/template/footer.php';
