<?php

$route = $_GET['route'] ?? '';
$route = trim($route, '/');

if ($route === '' || $route === 'home') {
    require 'pages/home.php';
} elseif ($route === 'login') {
    require 'pages/login.php';
} elseif ($route === 'register') {
    require 'pages/register.php';
} elseif ($route === 'games') {
    require 'pages/games.php';
} elseif ($route === 'play') {
    require 'pages/play.php';
} elseif ($route === 'game') {
    require 'pages/game.php';
} elseif ($route === 'game-live') {
    require 'pages/game-live.php';
} elseif ($route === 'matchmaking') {
    require 'pages/matchmaking.php';
} elseif ($route === 'bots') {
    require 'pages/bots.php';
} elseif ($route === 'profile') {
    require 'pages/profile.php';
} elseif ($route === 'leaderboard') {
    require 'pages/leaderboard.php';
} elseif ($route === 'friends') {
    require 'pages/friends.php';
} elseif ($route === 'tournaments') {
    require 'pages/tournaments.php';
} elseif ($route === 'tournament') {
    require 'pages/tournament.php';
} elseif ($route === 'shop') {
    require 'pages/shop.php';
} elseif ($route === 'achievements') {
    require 'pages/achievements.php';
} elseif ($route === 'analysis') {
    require 'pages/analysis.php';
} elseif ($route === 'puzzles') {
    require 'pages/puzzles.php';
} elseif ($route === 'notifications') {
    require 'pages/notifications.php';
} elseif ($route === 'settings') {
    require 'pages/settings.php';
} elseif ($route === 'orgs') {
    require 'pages/orgs.php';
} elseif ($route === 'org') {
    require 'pages/org.php';
} elseif ($route === 'ludo') {
    require 'pages/ludo.php';
} elseif ($route === 'ludo-game') {
    require 'pages/ludo-game.php';
} elseif ($route === 'ludo-live') {
    require 'pages/ludo-live.php';
} elseif ($route === 'ludo-matchmaking') {
    require 'pages/ludo-matchmaking.php';
} elseif ($route === 'domino') {
    require 'pages/domino.php';
} elseif ($route === 'domino-game') {
    require 'pages/domino-game.php';
} elseif ($route === 'domino-live') {
    require 'pages/domino-live.php';
} elseif ($route === 'domino-matchmaking') {
    require 'pages/domino-matchmaking.php';
} elseif ($route === 'backgammon') {
    require 'pages/backgammon.php';
} elseif ($route === 'backgammon-game') {
    require 'pages/backgammon-game.php';
} elseif ($route === 'backgammon-live') {
    require 'pages/backgammon-live.php';
} elseif ($route === 'backgammon-matchmaking') {
    require 'pages/backgammon-matchmaking.php';
} elseif ($route === 'admin/theme') {
    require 'pages/admin-theme.php';
} elseif (str_starts_with($route, 'api/')) {
    $apiFile = str_replace('api/', '', $route);
    $apiPath = __DIR__ . '/api/' . basename($apiFile) . '.php';
    if (file_exists($apiPath)) {
        require $apiPath;
    } else {
        http_response_code(404);
        echo json_encode(['error' => 'endpoint not found']);
    }
} else {
    http_response_code(404);
    require 'pages/404.php';
}
