<?

if (isset($_GET['debug'])) {
	// error_reporting(E_ALL);
	// ini_set('display_errors', 1);
} else {
	// Отключаем warnings для production, показываем только критические ошибки
	error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR);
	ini_set('display_errors', 0);
	ini_set('log_errors', 1);
}

error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR);
ini_set('display_errors', 0);
ini_set('log_errors', 1);

session_start();
if (empty($_SESSION['csrf_token'])) {
    if (function_exists('openssl_random_pseudo_bytes')) {
        $_SESSION['csrf_token'] = bin2hex(openssl_random_pseudo_bytes(32));
    } else {
        $_SESSION['csrf_token'] = md5(uniqid(mt_rand(), true));
    }
}

// Сохраняем UTM-метки из GET в сессию
$utm_keys = ['utm_campaign', 'utm_content', 'utm_medium', 'utm_source', 'utm_term'];
foreach ($utm_keys as $utm) {
    if (isset($_GET[$utm])) {
        $_SESSION[$utm] = $_GET[$utm];
    }
}

include 'libs/functions.php';
include 'libs/head.php';

$url = isset($_GET['url']) ? $_GET['url'] : '';
$url = preg_replace('#\/$#Usi', '', $url);

$map = [
	"" => "pages/home.php",
	"team" => "pages/team.php",
	"services" => "pages/services.php",
	"projects" => "pages/projects.php",
	"blog" => "pages/blog.php",
	"clients" => "clients.php",
	"services/ai" => "pages/services/ai.php",
	"services/mcp-tools" => "pages/services/mcp-tools.php",
	"services/solutions" => "pages/services/solutions.php",
	"services/mobile" => "pages/services/mobile.php",
	"services/backend" => "pages/services/backend.php",
	"services/ai-audit" => "pages/services/ai-audit.php",
	// "services/support" => "pages/services/support.php",
	"projects/ai-assistent" => "pages/projects/ai-assistent.php",
	"projects/git-ai" => "pages/projects/git-ai.php",
	"projects/staywalk" => "pages/projects/staywalk.php",
	"projects/ai-rss" => "pages/projects/ai-rss.php",
	"projects/gos-is" => "pages/projects/gos-is.php",
	"projects/iot" => "pages/projects/iot.php",
	"projects/telecom-bank" => "pages/projects/telecom-bank.php",
	"projects/invest" => "pages/projects/invest.php",
	"solutions/confidant-ai" => "pages/solutions/confidant-ai.php",
	"solutions/codes-git-ai" => "pages/solutions/codes-git-ai.php",
	// "solutions/codes-expert" => "pages/solutions/codes-expert.php",
	// "solutions/bot-tools" => "pages/solutions/bot-tools.php",
	// Новые специализированные лендинги
	"llm-solutions" => "pages/llm-solutions.php",
	"ai-agents-solutions" => "pages/landing/ai-agents-solutions/ai-agents-solutions.php",
	"ai-agents-analytics" => "pages/landing/ai-agents-analytics/ai-agents-analytics.php",
	"mobile-apps-solutions" => "pages/landing/mobile-apps-solutions/mobile-apps-solutions.php",
	"asr-solutions" => "pages/asr-solutions.php",
	"articles/backend-ipad" => "pages/articles/backend-ipad.php",
	"articles/offline-data-access" => "pages/articles/offline-data-access.php",
	"articles/gemma3-vs-gemini2" => "pages/articles/gemma3-vs-gemini2.php",
	"articles/git-ai" => "pages/articles/git-ai.php",
	"articles/ai-rss" => "pages/articles/ai-rss.php",
	"articles/how-to-avoid-ai-mistakes" => "pages/articles/how-to-avoid-ai-mistakes.php",
	"articles/ai-telecom" => "pages/articles/ai-telecom.php",
	"articles/sber500-git-ai" => "pages/articles/sber500-git-ai.php",
	"articles/conversations-2025" => "pages/articles/conversations-2025.php",
	"articles/moscow-startup-summit-2025" => "pages/articles/moscow-startup-summit-2025.php",
	"articles/kreativny-kod-russia-2025" => "pages/articles/kreativny-kod-russia-2025.php",
	"articles/bezopasnost-chatgpt-korporativnye-dannye" => "pages/articles/bezopasnost-chatgpt-korporativnye-dannye.php",
	"articles/ai-coding-efficiency" => "pages/articles/ai-coding-efficiency.php",
	"articles/grok-code-fast-1-experience" => "pages/articles/grok-code-fast-1-experience.php",
	"articles/mcp-tools-business-automation" => "pages/articles/mcp-tools-business-automation.php",
	"terms" => "pages/terms.php",
	"sitemap" => "sitemap.php",
	"demo" => "pages/articles/demo.php"
];

foreach ($map as $key => $file) {
	if ($url == $key) {
		include $file;
		exit();
	}
}

include 'error404.php';

?>